[vtk-developers] Bug 0003941 -- vtkImageData DeepCopy and ShallowCopy

Xenophon Papademetris xenophon.papademetris at yale.edu
Mon Jan 21 15:48:04 EST 2008


Hi,

 

Over the last week or so we have been porting our old code from VTK 4.4 to
VTK 5 (CVS). While trying to run some of the image registration code I came
across a bug which appears to be related to the open VTK bug 0003941 i.e.

 

"0003941: vtkImageData DeepCopy and ShallowCopy incomplete. Description
vtkImageData::InternalImageDataCopy does not copy SPACING and ORIGIN
pipeline information entries. These entries should be copied as other enties
(e.g. WHOLE_EXTENT) are in the vtkDataObject subclass method."  [ I don't
claim to understand all of this but .. ]

 

The problem, in our code, appears to be that while shallow copy correctly
copies the spacing (and origin although this is fixed in our case)
correctly, a subsequent call to GetPointData()->GetScalars()->GetRange()on
the image reverts the spacing back to its original value.

 

For example

 

1.       Take an original image (img) with spacing 2x2x2 mm

2.       Smooth (vtkImageGaussianSmooth)

3.       Reslice the output of Smooth to 3x3x3 mm (using vtkImageResample in
this case)

4.       ShallowCopy the output of ImageResample into img i.e.
img->ShallowCopy(ImageResample->GetOutput())

 

At the end of this process img->GetSpacing returns the correct value (3,3,3)
but a subsequent call to GetRange reverts the spacing back to 2x2x2 mm. 

A quick debugging revealed that this false value of spacing (2,2,2) is
stored in the PipelineInformation of img and is used to overwrite the true
value upon GetRange somehow. 

 

The following addition in vtkImageData appears to fix this at first look
(our registration code appears to work fine with this), but given how deep
this is in the pipeline, and how little I understand the new pipeline setup,
I am not sure what else it might break or if this is completely the wrong
track to be on.

 

Xenios

 

//--------------------------------------------------------------------------
--

// This copies all the local variables (but not objects).

void vtkImageData::InternalImageDataCopy(vtkImageData *src)

{

  int idx;

 

  this->DataDescription = src->DataDescription;

  this->SetScalarType(src->GetScalarType());

  this->SetNumberOfScalarComponents(src->GetNumberOfScalarComponents());

  for (idx = 0; idx < 3; ++idx)

    {

    this->Dimensions[idx] = src->Dimensions[idx];

    this->Increments[idx] = src->Increments[idx];

    this->Origin[idx] = src->Origin[idx];

    this->Spacing[idx] = src->Spacing[idx];

    }

  memcpy(this->Extent, src->GetExtent(), 6*sizeof(int));

 

  // Additions

  if (this->Information->Has(SPACING()))

 
this->Information->Set(SPACING(),this->Spacing[0],this->Spacing[1],this->Spa
cing[2]);

 

  if (this->PipelineInformation->Has(SPACING()))

 
this->PipelineInformation->Set(SPACING(),this->Spacing[0],this->Spacing[1],t
his->Spacing[2]);

 

 

  if (this->Information->Has(ORIGIN()))

 
this->Information->Set(ORIGIN(),this->Origin[0],this->Origin[1],this->Origin
[2]);

 

  if (this->PipelineInformation->Has(ORIGIN()))

 
this->PipelineInformation->Set(ORIGIN(),this->Origin[0],this->Origin[1],this
->Origin[2]);

  // End of Additions

}

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20080121/b2fb5b03/attachment.html>


More information about the vtk-developers mailing list