[vtkusers] problem with vtkvolume16reader->GetOutput()->GetScalarPointer()??
Dumont Nicolas
NIC.Dumont at student.ulg.ac.be
Sat May 1 06:06:12 EDT 2004
Hello users!!
I wish to make a copy of my volume data in a new vtkimagedata object, so
after that i could modify the scalar data at the voxels (for example to
make a spherical hole inside the volume).
The code I wrote works well with
vtkPNGreader->GetOutput()->GetScalarPointer();
but the same code adapted for
vtkVolume16reader->GetOutput()->GetScalarPointer();
returns me the error that GetScalarPointer() points to memory 0x0000000000
and so cant be read.
Any body has an idea why it is so ?
Nicolas D.
Ulg, Belgium
Here are both pieces of code:
****************************************************
vtkPNGReader * reader = vtkPNGReader::New();
reader->SetFilePattern("MR/%d.png");
reader->SetDataExtent(1,256,1,256,0,126);
reader->SetDataSpacing(1,1,1.5);
reader->SetDataOrigin(0,0,0);
reader->UpdateWholeExtent();
vtkImageData *imageData = vtkImageData::New();
imageData->SetDimensions(256,256,126);
imageData->SetSpacing(1,1,1.5);
imageData->SetOrigin(0.0,0.0,0.0);
imageData->SetScalarTypeToUnsignedChar();
imageData->SetNumberOfScalarComponents(1);
imageData->AllocateScalars();
imageData->GetPointData()->CopyScalarsOn();
unsigned char *ptrReader =
(unsigned char *) reader->GetOutput()->GetScalarPointer();
unsigned char *ptrData =
(unsigned char *) imageData->GetScalarPointer();
for (int i=0; i<256*256*126; i++)
{
*ptrData = *ptrReader;
ptrData++;
ptrReader++;
}
//...
volumeMapper->SetInput(imageData);
//...
***********************************************************************
vtkVolume16Reader *v16 = vtkVolume16Reader::New();
v16->SetDataDimensions(64,64);
v16->SetDataByteOrderToLittleEndian();
v16->SetFilePrefix ("quarter");
v16->SetImageRange(1, 93);
v16->SetDataSpacing (3.2, 3.2, 1.5);
vtkImageData *imageData = vtkImageData::New();
imageData->SetDimensions(64,64,93);
imageData->SetSpacing(3.2,3.2,1.5);
imageData->SetOrigin(0.0,0.0,0.0);
imageData->SetScalarTypeToUnsignedChar();
imageData->SetNumberOfScalarComponents(1);
imageData->AllocateScalars();
imageData->GetPointData()->CopyScalarsOn();
unsigned char *ptr2 =
(unsigned char *) v16->GetOutput()->GetScalarPointer();
unsigned char *ptr =
(unsigned char *) imageData->GetScalarPointer();
for (int i=0; i<64*64*93; i++)
{
*ptr = *ptr2;
ptr++;
ptr2++;
}
//...
volumeMapper->SetInput(imageData);
//...
More information about the vtkusers
mailing list