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

prabhat246 prabhat246 at yahoo.com
Fri Feb 13 13:24:06 EST 2009


Hi... Have you got your problem resolved. I am also facing the same problem.


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;
> }
> 
> 
>      
> _____________________________________________________________________________ 
> Envoyez avec Yahoo! Mail. Une boite mail plus intelligente
> http://mail.yahoo.fr
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-with-vtk-RayCasting%3A-volume-to-be-of-pixel-type-unsigned-char-or-unsigned-short-tp19048994p22002198.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list