[vtkusers] Problem with vtk RayCasting: volume to be of pixel type unsigned char or unsigned short
sara meghellati
sara_meghellati at yahoo.fr
Tue Aug 19 11:03:44 EDT 2008
Hi Amy
Thank you for your help. vtkFixedPointVolumeRayCastMapper is well working. Also I have tried keeping vtkVolumeRayCastMapper with the use of vtkImageShiftScale filter but I het the folloing error regarding the statment : shifter->SetInput(vtkImporter->GetOutput());
1>..\test_itk.cxx(129) : error C2664: 'void vtkImageAlgorithm::SetInput(vtkDataObject *)' : cannot convert parameter 1 from 'vtkImageData *' to 'vtkDataObject *'
Please do you know how to resolve this problem. I'm not expert; I’m just doing my first steps in vtk and itk.
Thank you
Sara
this this the modified code :
// The following example illustrates the use of the ConfidenceConnectedImageFilter. The criterion used by the
// ConfidenceConnectedImageFilter is based on simple statistics of the current region.
// 3D
// The following example illustrates the use of the ConfidenceConnectedImageFilter. The criterion used by the
// ConfidenceConnectedImageFilter is based on simple statistics of the current region.
// 3D
#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"
#include "vtkImageShiftScale.h"
#include "vtkFixedPointVolumeRayCastMapper.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/3DImages/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( 5);
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;
}
typedef itk::VTKImageExport< InputImageType > ExportFilterType;
ExportFilterType::Pointer itkExporter = ExportFilterType::New();
itkExporter->SetInput(reader->GetOutput());
// Create the vtkImageImport and connect it to the itk::VTKImageExport instance.
vtkImageImport* vtkImporter = vtkImageImport::New();
ConnectPipelines(itkExporter, vtkImporter);
vtkImageShiftScale* shifter = vtkImageShiftScale::New();
shifter->SetInput(vtkImporter->GetOutput());
//shifter->SetScale(256);
shifter->SetOutputScalarTypeToUnsignedChar();
// 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() );
VolumeMapper->SetInput(shifter->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->AddActor(volume);
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();
std::cout << "Code end !" << std::endl;
std::cin.get();
return 0;
}
--- En date de : Mar 19.8.08, Amy Squillacote <ahs at cfdrc.com> a écrit :
De: Amy Squillacote <ahs at cfdrc.com>
Objet: Re: [vtkusers] Problem with vtk RayCasting: volume to be of pixel type unsigned char or unsigned short
À: sara_meghellati at yahoo.fr
Cc: vtkusers at vtk.org
Date: Mardi 19 Août 2008, 15h21
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
_____________________________________________________________________________
Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080819/1a04e940/attachment.htm>
More information about the vtkusers
mailing list