[vtk-developers] How do I reliably the origin of a vtkImageData in VTK 6?

David Gobbi david.gobbi at gmail.com
Thu Oct 11 10:46:24 EDT 2012


Hi Cory,

After you call extractor->Update(), it will have updated the whole
extent and nothing that occurs downstream should cause any changes to
the extractor's output.  None of the VTK 6 changes should have changed
this behavior.

I've looked through the code in both vtkExtractVOI and in
vtkMetaImageWriter.  The code in vtkExtractVOI looks fine.  But in
vtkMetaImageWriter I found this in the Write() method, around lines
114 and 148:

  double * origin = this->GetInput()->GetOrigin();
  ...

  origin[0] += ext[0] * spacing[0];
  origin[1] += ext[2] * spacing[1];
  origin[2] += ext[4] * spacing[2];

The writer is modifying the input's origin.  A "git blame" shows that
this bug was introduced in 2007, so it's been there for a long time.
The bug manifests itself any time that someone writes a metafile where
the Extent of the input doesn't start at zero.

 - David


On Thu, Oct 11, 2012 at 8:11 AM, Cory Quammen <cquammen at cs.unc.edu> wrote:
> [Reposting to the VTK developers list]
>
> I'm using VTK at commit 5754065bad83bf9cbcfbcfa72ecfbbed91f277db (July
> 13, 2012).
>
> Goal:
>
> I'm attempting to something with a vtkImageData object outside a VTK
> pipeline that I think should be straightforward (rasterizing a
> sphere). To do this properly, I need to know the origin and spacing of
> the vtkImageData object produced from a filter.
>
> Problem observed:
>
> When I ask a vtkImageData about it's origin, the answer I get depends
> on whether it has been processed by a downstream filter or not. Here's
> what I'm seeing.
>
> I have a short pipeline sketched here:
>
> vtkExtractVOI * extractor = vtkExtractVOI::New();
> extractor->SetInputData( image );
> extractor->SetVOI( voi ); // Assume voi[0] > image->GetExtent()[0]
> extractor->Update();
> // extractor->UpdateWholeExtent(); // using this makes no difference
>
> vtkImageData * subImage = extractor->GetOutput();
>
> // Ask subImage for it's origin
> double originBeforeWrite[3];
> subImage->GetOrigin( originBeforeWrite );
>
> // Save the extracted region to a file
> vtkMetaImageWriter * writer = vtkMetaImageWriter::New();
> writer->SetFileName( ... );
> writer->SetRAWFileName( ... );
> writer->SetInputData( subImage );
> writer->Write();
>
> // Ask subImage for it's origin again
> double originAfterWrite[3];
> subImage->GetOrigin( originAfterWrite );
>
> Now, when this code is executed, originAfterWrite[i] != originBeforeWrite[i].
>
> This is disturbing.
>
> I'm guessing writing subImage to a file triggers an update to the
> origin in the pipeline that then gets set back in subImage, and that
> explains why originAfterWrite[i] != originBeforeWrite[i]. Shouldn't
> the origin returned from subImage->GetOrigin() be updated when I
> invoke extractor->Update()?
>
> If not, could you please advise me on the proper way to get the origin
> from a vtkImageData that is produced as the output of a filter? I
> looked in the VTK 6 migration guide, but couldn't find anything
> pertaining to this question.
>
> Thank you,
> Cory
>
> --
> Cory Quammen
> Research Associate
> Department of Computer Science
> The University of North Carolina at Chapel Hill
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>



More information about the vtk-developers mailing list