[Insight-users] Fast pipeline VTK-ITK-VTK for 3D segmentation
Luigi Gallo
luigi.gallo at na.icar.cnr.it
Tue May 4 07:24:24 EDT 2010
Hi all,
I found many others threads in this list concerning the pipeline
vtkImageData -> ITK segmentation -> VTK for visualization.
However, I was unable to set up an effective working pipeline.
This is my first attempt:
template <typename VTK_Exporter, typename ITK_Importer>
void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)
{
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallbac
k());
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback(
));
importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
importer->SetSpacingCallback(exporter->GetSpacingCallback());
importer->SetOriginCallback(exporter->GetOriginCallback());
importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallb
ack());
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExten
tCallback());
importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
importer->SetCallbackUserData(exporter->GetCallbackUserData());
}
template <typename ITK_Exporter, typename VTK_Importer>
void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
{
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallbac
k());
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback(
));
importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
importer->SetSpacingCallback(exporter->GetSpacingCallback());
importer->SetOriginCallback(exporter->GetOriginCallback());
importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallb
ack());
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExten
tCallback());
importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
importer->SetCallbackUserData(exporter->GetCallbackUserData());
}
vtkVolume *volumeRenderingFilter::computeTextures3Dsegmented(long wl, long
ww, int clut, int minPixel, float sampleDistance, double seedPosition[3])
{
vtkVolume *volume = NULL;
int shiftValue = 0;
if( minPixel < 0 )
shiftValue =(-1)*(minPixel);
vtkImageShiftScale *shiftScale = vtkImageShiftScale::New();
shiftScale->SetInput( ... vtkImageData source );
shiftScale->SetScale(1);
shiftScale->SetShift(shiftValue);
shiftScale->ClampOverflowOn();
shiftScale->SetOutputScalarTypeToFloat();
/***************************************************************************
***********
VTK -> ITK connection
****************************************************************************
**********/
typedef itk::Image< float, 3 > ImageType;
typedef itk::VTKImageImport< ImageType > ImportFilterType;
ImportFilterType::Pointer itkImporter = ImportFilterType::New();
vtkImageExport* vtkExporter = vtkImageExport::New();
vtkExporter->SetInput( shiftScale->GetOutput() );
ConnectPipelines(vtkExporter, itkImporter);
typedef float InternalPixelType;
const unsigned int Dimension = 3;
typedef itk::Image< InternalPixelType, Dimension >
InternalImageType;
typedef unsigned short OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::CastImageFilter< InternalImageType, OutputImageType >
CastingFilterType;
CastingFilterType::Pointer caster = CastingFilterType::New();
typedef itk::CurvatureFlowImageFilter< InternalImageType,
InternalImageType > CurvatureFlowImageFilterType;
CurvatureFlowImageFilterType::Pointer smoothing =
CurvatureFlowImageFilterType::New();
typedef itk::ConnectedThresholdImageFilter< InternalImageType,
InternalImageType > ConnectedFilterType;
ConnectedFilterType::Pointer connectedThreshold =
ConnectedFilterType::New();
smoothing->SetInput( itkImporter->GetOutput() );
smoothing->SetNumberOfIterations( 5 );
smoothing->SetTimeStep( 0.125 );
connectedThreshold->SetInput( smoothing->GetOutput() );
const InternalPixelType lowerThreshold = atof( "1100" );
const InternalPixelType upperThreshold = atof( "1200" );
connectedThreshold->SetLower( lowerThreshold );
connectedThreshold->SetUpper( upperThreshold );
connectedThreshold->SetReplaceValue( 255 );
InternalImageType::IndexType index;
index[0] = atoi( "256" );
index[1] = atoi( "256" );
index[2] = atoi( "16" );
connectedThreshold->SetSeed( index );
caster->SetInput( connectedThreshold->GetOutput() );
/***************************************************************************
***********
ITK -> VTK connection
****************************************************************************
**********/
typedef itk::VTKImageExport< ImageType > ExportFilterType;
ExportFilterType::Pointer itkExporter = ExportFilterType::New();
itkExporter->SetInput( connectedThreshold->GetOutput() );
vtkImageImport* vtkImporter = vtkImageImport::New();
vtkImporter->SetDataScalarTypeToUnsignedShort();
ConnectPipelines(itkExporter, vtkImporter);
vtkPiecewiseFunction *opacityTransferFunction =
vtkPiecewiseFunction::New();
vtkColorTransferFunction *colorTransferFunction =
vtkColorTransferFunction::New();
float start = shiftValue + wl - ww/2, end = shiftValue + wl + ww/2;
opacityTransferFunction->AddPoint(start, 0);
opacityTransferFunction->AddPoint(end, 1);
double table[256][3];
if(clut == 0) ...
... color lookup table
colorTransferFunction->BuildFunctionFromTable(shiftValue + wl-ww/2,
shiftValue + wl+ww/2, 255, (double*)&table);
vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
volumeProperty->SetScalarOpacity(opacityTransferFunction);
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetInterpolationTypeToLinear();
vtkVolumeTextureMapper3D *volume3DTextureMapper =
vtkVolumeTextureMapper3D::New();
volume3DTextureMapper->SetPreferredMethodToNVidia();
volume3DTextureMapper->SetSampleDistance(sampleDistance);
volume3DTextureMapper->SetInput(vtkImporter->GetOutput());
volume = vtkVolume::New();
volume->SetProperty(volumeProperty);
volume->SetMapper(volume3DTextureMapper);
volume3DTextureMapper->Delete();
volumeProperty->Delete();
colorTransferFunction->Delete();
opacityTransferFunction->Delete();
shiftScale->Delete();
return volume;
}
Unfortunately, the whole process returns a null volume.
Any help would be appreciated.
Best regards,
Luigi
More information about the Insight-users
mailing list