[vtkusers] Problem with vtk RayCasting: volume to be of pixel type unsigned char or unsigned short

Amy Squillacote ahs at cfdrc.com
Tue Aug 19 09:21:46 EDT 2008


Hi Sara,

The vtkFixedPointVolumeRayCastMapper can handle float data, so try using 
it instead of vtkVolumeRayCastMapper. If for some reason you need to use 
vtkVolumeRayCastMapper, you should pass your vtkImageData through a 
vtkImageShiftScale filter to convert it to unsigned char or unsigned 
short, and then pass the output of that filter to the mapper.

- Amy

sara meghellati wrote:
>  
> Hi all,
> I have segmented 3D image using region growing method (using itk) and 
> I want to display the original volume(float type) using vtk. I got an 
> error at run time stating that vtk raycasting requires the volume to 
> be of pixel type unsigned char or unsigned short. I'm converting the 
> vtkimport that I use to unsigned char using the function 
> SetDataScalarTypeToChar() but I still get the error.  The code is bellow.
> Any help is very appreciated.
> Thank you for  your time
> Sara
>  
>  
> #include "itkConfidenceConnectedImageFilter.h"
> #include "itkImage.h"
> #include "itkCastImageFilter.h"
> #include "itkCurvatureFlowImageFilter.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkVTKImageExport.h"
> #include "itkVTKImageImport.h"
> #include "vtkImageImport.h"
> #include "vtkImageExport.h"
> #include "vtkImageReader.h"
> #include "vtkPiecewiseFunction.h"
> #include "vtkVolumeProperty.h"
> #include "vtkVolumeRayCastMapper.h"
> #include "vtkVolumeTextureMapper3D.h"
> #include "vtkFixedPointVolumeRayCastMapper.h"
> #include "vtkVolumeRayCastCompositeFunction.h"
> #include "vtkVolume.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> // This function will connect the given itk::VTKImageExport filter to 
> the given vtkImageImport filter.
> template <typename ITK_Exporter, typename VTK_Importer>
> void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
> {
> importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
> importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
> importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
> importer->SetSpacingCallback(exporter->GetSpacingCallback());
> importer->SetOriginCallback(exporter->GetOriginCallback());
> importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
> importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
> importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
> importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
> importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
> importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
> importer->SetCallbackUserData(exporter->GetCallbackUserData());
> }
> int main( )
> {
> //typedef unsigned short InputPixelType;
> typedef float InputPixelType;
> typedef unsigned char OutputPixelType;
> const unsigned int Dimension = 3;
> typedef itk::Image< InputPixelType, Dimension > InputImageType;
> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
> typedef itk::CastImageFilter< InputImageType, OutputImageType > 
> CastingFilterType;
> typedef itk::ImageFileReader< InputImageType > ReaderType;
> typedef itk::ImageFileWriter< OutputImageType > WriterType;
> typedef itk::CurvatureFlowImageFilter< InputImageType, InputImageType 
> > CurvatureFlowImageFilterType;
> typedef itk::ConfidenceConnectedImageFilter<InputImageType, 
> InputImageType> ConnectedFilterType;
> CastingFilterType::Pointer caster = CastingFilterType::New();
> ReaderType::Pointer reader = ReaderType::New();
> WriterType::Pointer writer = WriterType::New();
> CurvatureFlowImageFilterType::Pointer smoothing = 
> CurvatureFlowImageFilterType::New();
> ConnectedFilterType::Pointer confidenceConnected = 
> ConnectedFilterType::New();
> reader->SetFileName( "c:/images/Patient01.mhd" );
> writer->SetFileName( "c:/images/3DConfidenceConnectedSegmImg.mhd" );
> smoothing->SetInput( reader->GetOutput() );
> confidenceConnected->SetInput( smoothing->GetOutput() );
> caster->SetInput( confidenceConnected->GetOutput() );
> writer->SetInput( caster->GetOutput() );
> smoothing->SetNumberOfIterations( 5 );
> smoothing->SetTimeStep( 0.125 );
> confidenceConnected->SetMultiplier( 2.5 );
> confidenceConnected->SetNumberOfIterations( 2 );
> confidenceConnected->SetReplaceValue( 255 );
> InputImageType::IndexType index;
> index[0] = atoi( "256" );
> index[1] = atoi( "256" );
> index[2] = atoi( "16" );
> confidenceConnected->SetSeed( index );
> confidenceConnected->SetInitialNeighborhoodRadius( 2 );
> try
> {
> writer->Update();
> }
> catch( itk::ExceptionObject & excep )
> {
> std::cerr << "Exception caught !" << std::endl;
> std::cerr << excep << std::endl;
> }
> //----------------------------------------------
> // -------------------- vtk Display----------------
> //----------------------------------------------
> typedef itk::VTKImageExport< InputImageType > ExportFilterType;
> ExportFilterType::Pointer itkExporter = ExportFilterType::New();
> itkExporter->SetInput(reader->GetOutput());
> vtkImageImport* vtkImporter = vtkImageImport::New();
> ConnectPipelines(itkExporter, vtkImporter);
> vtkImporter->SetDataScalarTypeToUnsignedChar();
> // Define opacity transfer function
> vtkPiecewiseFunction *opacityTransferFunction = 
> vtkPiecewiseFunction::New();
> vtkVolume *volume = vtkVolume::New();
> vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
> vtkVolumeRayCastMapper *VolumeMapper = vtkVolumeRayCastMapper::New();
> vtkVolumeRayCastCompositeFunction *RayCastFunction 
> =vtkVolumeRayCastCompositeFunction::New();
> // Volume property
> opacityTransferFunction->AddPoint(0,0.001);
> opacityTransferFunction->AddPoint(255,0.2);
> volumeProperty->SetScalarOpacity(opacityTransferFunction);
> volumeProperty->SetInterpolationTypeToLinear();
> volumeProperty->ShadeOff();
> // Volume mapper
> VolumeMapper->SetVolumeRayCastFunction(RayCastFunction);
> VolumeMapper->SetSampleDistance(1.0);
> VolumeMapper->SetBlendModeToMaximumIntensity();
> VolumeMapper->SetInput(vtkImporter->GetOutput() );
> // The volume
> volume->SetMapper(VolumeMapper);
> volume->SetProperty(volumeProperty);
> // Create a renderer, render window, and render window interactor to 
> display the results.
> vtkRenderer *Renderer = vtkRenderer::New();
> vtkRenderWindow *RenWin = vtkRenderWindow::New();
> vtkRenderWindowInteractor *RenWinInterc = 
> vtkRenderWindowInteractor::New();
> RenWin->AddRenderer(Renderer);
> RenWinInterc->SetRenderWindow(RenWin);
> Renderer->AddVolume(volume);
> Renderer->SetBackground(1,1,1);
> RenWin->Render();
> RenWinInterc->Initialize();
> RenWinInterc->Start();
> // Release all VTK components
> RenWinInterc->Delete();
> RenWin->Delete();
> Renderer->Delete();
> volume->Delete();
> VolumeMapper->Delete();
> volumeProperty->Delete();
> opacityTransferFunction->Delete();
>  
> return 0;
> }
>
>
> ------------------------------------------------------------------------
> Envoyé avec Yahoo! Mail 
> <http://us.rd.yahoo.com/mailuk/taglines/isp/control/*http://us.rd.yahoo.com/evt=52423/*http://fr.docs.yahoo.com/mail/overview/index.html>.
> Une boite mail plus intelligente.
> ------------------------------------------------------------------------
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>   

-- 
Amy Squillacote                    Phone: (256) 726-4839
Computer Scientist                 Fax: (256) 726-4806
CFD Research Corporation           Web: http://www.cfdrc.com
215 Wynn Drive, Suite 501
Huntsville, AL  35805





More information about the vtkusers mailing list