<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Hi all,</DIV>
<DIV>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.</DIV>
<DIV>Any help is very appreciated.</DIV>
<DIV>Thank you for your time</DIV>
<DIV>Sara</DIV>
<DIV> </DIV>
<DIV> </DIV><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"itkConfidenceConnectedImageFilter.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"itkImage.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"itkCastImageFilter.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"itkCurvatureFlowImageFilter.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"itkImageFileReader.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"itkImageFileWriter.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"itkVTKImageExport.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"itkVTKImageImport.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkImageImport.h"</FONT><FONT size=2> </DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkImageExport.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkImageReader.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkPiecewiseFunction.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkVolumeProperty.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkVolumeRayCastMapper.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkVolumeTextureMapper3D.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkFixedPointVolumeRayCastMapper.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkVolumeRayCastCompositeFunction.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkVolume.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkRenderer.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkRenderWindow.h"</DIV></FONT><FONT color=#0000ff size=2>
<DIV>#include</FONT><FONT size=2> </FONT><FONT color=#a31515 size=2>"vtkRenderWindowInteractor.h"</DIV></FONT><FONT color=#008000 size=2>
<DIV>// This function will connect the given itk::VTKImageExport filter to the given vtkImageImport filter.</DIV></FONT><FONT color=#0000ff size=2>
<DIV>template</FONT><FONT size=2> <</FONT><FONT color=#0000ff size=2>typename</FONT><FONT size=2> ITK_Exporter, </FONT><FONT color=#0000ff size=2>typename</FONT><FONT size=2> VTK_Importer></DIV></FONT><FONT color=#0000ff size=2>
<DIV>void</FONT><FONT size=2> ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)</DIV>
<DIV>{</DIV>
<DIV>importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());</DIV>
<DIV>importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());</DIV>
<DIV>importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());</DIV>
<DIV>importer->SetSpacingCallback(exporter->GetSpacingCallback());</DIV>
<DIV>importer->SetOriginCallback(exporter->GetOriginCallback());</DIV>
<DIV>importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());</DIV>
<DIV>importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());</DIV>
<DIV>importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());</DIV>
<DIV>importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());</DIV>
<DIV>importer->SetDataExtentCallback(exporter->GetDataExtentCallback());</DIV>
<DIV>importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());</DIV>
<DIV>importer->SetCallbackUserData(exporter->GetCallbackUserData());</DIV>
<DIV>}</DIV></FONT><FONT color=#0000ff size=2>
<DIV>int</FONT><FONT size=2> main( )</DIV>
<DIV>{</DIV>
<DIV></FONT><FONT color=#008000 size=2>//typedef unsigned short InputPixelType;</DIV></FONT><FONT size=2>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>float</FONT><FONT size=2> InputPixelType;</DIV>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2> OutputPixelType;</DIV>
<DIV></FONT><FONT color=#0000ff size=2>const</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> Dimension = 3;</DIV>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> itk::Image< InputPixelType, Dimension > InputImageType;</DIV>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> itk::Image< OutputPixelType, Dimension > OutputImageType;</DIV>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> itk::CastImageFilter< InputImageType, OutputImageType > CastingFilterType;</DIV>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> itk::ImageFileReader< InputImageType > ReaderType;</DIV>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> itk::ImageFileWriter< OutputImageType > WriterType;</DIV>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> itk::CurvatureFlowImageFilter< InputImageType, InputImageType > CurvatureFlowImageFilterType; </DIV>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> itk::ConfidenceConnectedImageFilter<InputImageType, InputImageType> ConnectedFilterType;</DIV>
<DIV>CastingFilterType::Pointer caster = CastingFilterType::New(); </DIV>
<DIV>ReaderType::Pointer reader = ReaderType::New();</DIV>
<DIV>WriterType::Pointer writer = WriterType::New();</DIV>
<DIV>CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New(); </DIV>
<DIV>ConnectedFilterType::Pointer confidenceConnected = ConnectedFilterType::New();</DIV>
<DIV></DIV>
<DIV>reader->SetFileName( </FONT><FONT color=#a31515 size=2>"c:/images/Patient01.mhd"</FONT><FONT size=2> );</DIV>
<DIV>writer->SetFileName( </FONT><FONT color=#a31515 size=2>"c:/images/3DConfidenceConnectedSegmImg.mhd"</FONT><FONT size=2> );</DIV>
<DIV>smoothing->SetInput( reader->GetOutput() );</DIV>
<DIV>confidenceConnected->SetInput( smoothing->GetOutput() );</DIV>
<DIV>caster->SetInput( confidenceConnected->GetOutput() );</DIV>
<DIV>writer->SetInput( caster->GetOutput() );</DIV>
<DIV></DIV>
<DIV>smoothing->SetNumberOfIterations( 5 );</DIV>
<DIV>smoothing->SetTimeStep( 0.125 );</DIV>
<DIV></DIV>
<DIV>confidenceConnected->SetMultiplier( 2.5 ); </DIV>
<DIV>confidenceConnected->SetNumberOfIterations( 2 );</DIV>
<DIV>confidenceConnected->SetReplaceValue( 255 ); </DIV>
<DIV>InputImageType::IndexType index; </DIV>
<DIV>index[0] = atoi( </FONT><FONT color=#a31515 size=2>"256"</FONT><FONT size=2> );</DIV>
<DIV>index[1] = atoi( </FONT><FONT color=#a31515 size=2>"256"</FONT><FONT size=2> );</DIV>
<DIV>index[2] = atoi( </FONT><FONT color=#a31515 size=2>"16"</FONT><FONT size=2> );</DIV>
<DIV>confidenceConnected->SetSeed( index ); </DIV>
<DIV>confidenceConnected->SetInitialNeighborhoodRadius( 2 );</DIV>
<DIV></FONT><FONT color=#0000ff size=2>try</DIV></FONT><FONT size=2>
<DIV>{</DIV>
<DIV>writer->Update();</DIV>
<DIV>}</DIV>
<DIV></FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>( itk::ExceptionObject & excep )</DIV>
<DIV>{</DIV>
<DIV>std::cerr << </FONT><FONT color=#a31515 size=2>"Exception caught !"</FONT><FONT size=2> << std::endl;</DIV>
<DIV>std::cerr << excep << std::endl;</DIV>
<DIV>}</DIV>
<DIV></FONT><FONT color=#008000 size=2>//----------------------------------------------</DIV></FONT><FONT size=2>
<DIV></FONT><FONT color=#008000 size=2>// -------------------- vtk Display----------------</DIV></FONT><FONT size=2>
<DIV></FONT><FONT color=#008000 size=2>//----------------------------------------------</DIV></FONT><FONT size=2>
<DIV></FONT><FONT color=#0000ff size=2>typedef</FONT><FONT size=2> itk::VTKImageExport< InputImageType > ExportFilterType;</DIV>
<DIV>ExportFilterType::Pointer itkExporter = ExportFilterType::New(); </DIV>
<DIV>itkExporter->SetInput(reader->GetOutput()); </DIV>
<DIV>vtkImageImport* vtkImporter = vtkImageImport::New(); </DIV>
<DIV>ConnectPipelines(itkExporter, vtkImporter);</DIV>
<DIV>vtkImporter->SetDataScalarTypeToUnsignedChar();</DIV>
<DIV></DIV>
<DIV></FONT><FONT color=#008000 size=2>// Define opacity transfer function</DIV></FONT><FONT size=2>
<DIV>vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();</DIV>
<DIV>vtkVolume *volume = vtkVolume::New();</DIV>
<DIV>vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();</DIV>
<DIV>vtkVolumeRayCastMapper *VolumeMapper = vtkVolumeRayCastMapper::New();</DIV>
<DIV>vtkVolumeRayCastCompositeFunction *RayCastFunction =vtkVolumeRayCastCompositeFunction::New();</DIV>
<DIV></DIV>
<DIV></FONT><FONT color=#008000 size=2>// Volume property </DIV></FONT><FONT size=2>
<DIV>opacityTransferFunction->AddPoint(0,0.001);</DIV>
<DIV>opacityTransferFunction->AddPoint(255,0.2);</DIV>
<DIV>volumeProperty->SetScalarOpacity(opacityTransferFunction);</DIV>
<DIV>volumeProperty->SetInterpolationTypeToLinear();</DIV>
<DIV>volumeProperty->ShadeOff();</DIV>
<DIV></FONT><FONT color=#008000 size=2>// Volume mapper</DIV></FONT><FONT size=2>
<DIV>VolumeMapper->SetVolumeRayCastFunction(RayCastFunction);</DIV>
<DIV>VolumeMapper->SetSampleDistance(1.0);</DIV>
<DIV>VolumeMapper->SetBlendModeToMaximumIntensity();</DIV>
<DIV>VolumeMapper->SetInput(vtkImporter->GetOutput() ); </DIV>
<DIV></DIV>
<DIV></FONT><FONT color=#008000 size=2>// The volume </DIV></FONT><FONT size=2>
<DIV>volume->SetMapper(VolumeMapper);</DIV>
<DIV>volume->SetProperty(volumeProperty);</DIV>
<DIV></DIV>
<DIV></FONT><FONT color=#008000 size=2>// Create a renderer, render window, and render window interactor to display the results.</DIV></FONT><FONT size=2>
<DIV>vtkRenderer *Renderer = vtkRenderer::New();</DIV>
<DIV>vtkRenderWindow *RenWin = vtkRenderWindow::New();</DIV>
<DIV>vtkRenderWindowInteractor *RenWinInterc = vtkRenderWindowInteractor::New();</DIV>
<DIV>RenWin->AddRenderer(Renderer);</DIV>
<DIV>RenWinInterc->SetRenderWindow(RenWin);</DIV>
<DIV>Renderer->AddVolume(volume);</DIV>
<DIV>Renderer->SetBackground(1,1,1);</DIV>
<DIV>RenWin->Render();</DIV>
<DIV>RenWinInterc->Initialize();</DIV>
<DIV>RenWinInterc->Start();</DIV>
<DIV></FONT><FONT color=#008000 size=2>// Release all VTK components</DIV></FONT><FONT size=2>
<DIV>RenWinInterc->Delete();</DIV>
<DIV>RenWin->Delete(); </DIV>
<DIV>Renderer->Delete();</DIV>
<DIV>volume->Delete();</DIV>
<DIV>VolumeMapper->Delete();</DIV>
<DIV>volumeProperty->Delete();</DIV>
<DIV>opacityTransferFunction->Delete();</DIV>
<DIV> </DIV>
<DIV></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> 0;</DIV>
<DIV>}</DIV></FONT></td></tr></table><br>
<hr size="1">
Envoyé avec <a href="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">Yahoo! Mail</a>.<br>Une boite mail plus intelligente. </a>