[vtkusers] Access the direct data values of 3D CT data, GetScalarPointer() problem!

Bill Lorensen bill.lorensen at gmail.com
Tue Feb 9 17:43:27 EST 2010


You must do
pvtkImageReader->Update();
before you access the data.

On Tue, Feb 9, 2010 at 1:44 PM, madness78 <madness78 at pusan.ac.kr> wrote:
>
> Hello,
> Can anybody help me? Please~~!!
> I’m in trouble to access the direct data values of 3D CT data.
> I tried many things, but it dosen’t work.
> Please, please help me.
> My code is,
>
> this->pvtkImageReader = vtkImageReader::New();
>               this->pvtkImageReader->SetFileName("Image.bin");
>
>               this->pvtkImageReader->SetDataExtent(0,255,0,255,0,255);
>               this->pvtkImageReader->SetDataSpacing(1,1,1);
>               this->pvtkImageReader->SetFileDimensionality(3);
>               this->pvtkImageReader->SetDataOrigin(0,0,0);
>               this->pvtkImageReader-> SetDataByteOrderToLittleEndian();
>
>               this->ImageData->SetScalarTypeToUnsignedShort();
>               this->ImageData->SetDimensions(256,256,256);
>               this->ImageData->SetSpacing(1,1,1);
>               this->ImageData->SetOrigin(0,0,0);
>               this->ImageData->AllocateScalars();
>               this->ImageData->SetNumberOfScalarComponents(1);
>               int* dims = this->ImageData->GetDimensions();
>
>               this->ImageData=pvtkImageReader->GetOutput();
>               unsigned short *ptr=(unsigned
> short*)(this->ImageData)->GetScalarPointer();
>
>                CString b;
>                b.Format("%d,", dims[2]);
>                ::MessageBox(NULL, b, "dims[0]", MB_OK |
> MB_ICONINFORMATION);
>
>               for(int k=0;k<dims[0];k++)
>               {
>                       for(int j=0;j<dims[1];j++)
>                       {
>                              for(int i=0;i<dims[2];i++)
>                              {
>                                      TempVolume[i] =
> ptr[256*256*i+256*j+k];
>                              }
>                       }
>               }
>
> If I put this code “TempVolume[i] = ptr[256*256*i+256*j+k];”
> The program stopped.
> What do I have to do??
> Did I made a mistake while using GetScalarPointer() method?
>
>
>
> --
> View this message in context: http://old.nabble.com/Access-the-direct-data-values-of-3D-CT-data%2C-GetScalarPointer%28%29-problem%21-tp27520065p27520065.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list