[vtkusers] Convert ITK image to VTK volume keeping proper orientation and position

Dženan Zukić dzenanz at gmail.com
Tue Jul 5 08:43:43 EDT 2011


OK, I will create an example employing this and put it in VTK wiki.

Dženan

2011/7/5 David Doria <daviddoria at gmail.com>

> 2011/7/5 Dženan Zukić <dzenanz at gmail.com>:
> > I hope this function can save someone a lot of time and headaches. It
> takes
> > an itk::Image and converts it into a vtkVolume, keeping it in DICOM's
> > patient physical world space. Its main usage is combining it with
> segmented
> > structures (vtkPolyData) whose vertices are in DICOM patient space, that
> is,
> > vertex coordinates were obtained using
> > visualizing->TransformIndexToPhysicalPoint().
> > typedef itk::Image<unsigned char, 3> VisualizingImageType
> > void showITKimageInVTKqwidget(VisualizingImageType::Pointer visualizing)
> > {
> >     typedef itk::ImageToVTKImageFilter<VisualizingImageType>
> > itkVtkConverter;
> >     itkVtkConverter::Pointer conv=itkVtkConverter::New();
> >     conv->SetInput(visualizing);
> >
> >     vtkGPUVolumeRayCastMapper *mapper = vtkGPUVolumeRayCastMapper::New();
> >     mapper->SetInput(conv->GetOutput());
> >     vtkVolume *volume=vtkVolume::New();
> >     volume->SetProperty( myTransferFunction );
> >     volume->SetMapper( mapper );
> >     // vtkVolume only manages spacing by itself.
> >     // Here we take care of position and orientation so it is in DICOM
> > physical space
> > VisualizingImageType::DirectionType d=visualizing->GetDirection();
> > vtkMatrix4x4 *mat=vtkMatrix4x4::New(); //identity matrix
> > for (int i=0; i<3; i++)
> > for (int k=0; k<3; k++)
> > mat->SetElement(i,k, d(i,k));
> > VisualizingImageType::PointType origin=visualizing->GetOrigin();
> > volume->SetOrigin(-origin[0], -origin[1], -origin[2]);
> > volume->SetPosition(-origin[0], -origin[1], -origin[2]);
> > for (int i=0; i<3; i++)
> > mat->SetElement(i,3, origin[i]);
> > volume->SetUserMatrix(mat);
> >     vtkRenderer *renderer =
> > myQWidget->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
> >     renderer->AddVolume( volume );
> >     myQWidget->GetRenderWindow()->Render();
> >     renderer->ResetCamera();
> > }
> >
> > Dženan
>
> Dženan,
>
> Thanks for sharing. I would put something like this on the examples
> wiki in a section called "Bridge" or "Glue" or something like that
> (these are names that have been previously used to describe
> interactions between ITK and VTK). This will make it much easier to
> find in the future instead of having to dig through old mailing list
> archives.
>
> David D.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110705/00e51859/attachment.htm>


More information about the vtkusers mailing list