[vtkusers] THIS MAPPER IS UNSURPPORTED ON THIS PLATFORM?
landscapemoon
landscapemoon at 126.com
Mon Apr 11 05:08:32 EDT 2011
Hi:
I am a beginner.Now I do a CT series Image processing(DICOM).
Source codes as follow:
*************************************************************
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif
// ITK include
#include "itkBinaryThresholdImageFilter.h"
#include "itkCannySegmentationLevelSetImageFilter.h"
#include "itkCastImageFilter.h"
#include "itkConfidenceConnectedImageFilter.h"
#include "itkCurvatureAnisotropicDiffusionImageFilter.h"
#include "itkFastMarchingImageFilter.h"
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"
#include "itkImageFileWriter.h"
#include "itkImageSeriesReader.h"
#include "itkImageToVTKImageFilter.h"
#include "itkImportImageFilter.h"
#include "itkIntensityWindowingImageFilter.h"
#include "itkOrientedImage.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkSigmoidImageFilter.h"
// VTK include
#include "vtkActor.h"
#include "vtkBoxWidget.h"
#include "vtkCamera.h"
#include "vtkCommand.h"
#include "vtkColorTransferFunction.h"
#include "vtkContourFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkDICOMImageReader.h"
#include "vtkGeometryFilter.h"
#include "vtkGPUVolumeRayCastMapper.h"
#include "vtkImageData.h"
#include "vtkImageResample.h"
#include "vtkImageViewer.h"
#include "vtkMetaImageReader.h"
#include "vtkPiecewiseFunction.h"
#include "vtkPlanes.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
#include "vtkXMLImageDataReader.h"
//#include "vvITKFilterModuleBase.h"
//#include "vtkVVPluginAPI.h"
//#include "vvITKCannySegmentationLevelSetModule.cxx"
#define VTI_FILETYPE 1
#define MHA_FILETYPE 2
class vtkBoxWidgetCallback : public vtkCommand
{
public:
static vtkBoxWidgetCallback *New()
{
return new vtkBoxWidgetCallback;
}
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
if (this->Mapper)
{
vtkPlanes *planes = vtkPlanes::New();
widget->GetPlanes(planes);
this->Mapper->SetClippingPlanes(planes);
planes->Delete();
}
}
void SetMapper(vtkGPUVolumeRayCastMapper* m)
{
this->Mapper = m;
}
protected:
vtkBoxWidgetCallback()
{
this->Mapper = 0;
}
vtkGPUVolumeRayCastMapper *Mapper;
};
int main(int argc, char *argv[])
{
// reader and connector
typedef signed short PixelType;
const unsigned int Dimension = 3;
typedef itk::OrientedImage< PixelType, Dimension > ImageType;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
typedef itk::ImageToVTKImageFilter< ImageType > ConnectType;
ReaderType::Pointer reader = ReaderType::New();
ConnectType::Pointer connector = ConnectType::New();
// set reader to DICOM
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer dicomIO = ImageIOType::New();
reader->SetImageIO( dicomIO );
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
nameGenerator->SetUseSeriesDetails( true );
nameGenerator->AddSeriesRestriction( "0008|0021" );
nameGenerator->SetDirectory( "dicom4" );
/*
//typedef unsigned char MaskPixelType;
typedef signed short MaskPixelType;
typedef itk::OrientedImage< MaskPixelType, Dimension > MaskImageType;
typedef itk::ConfidenceConnectedImageFilter< ImageType, MaskImageType > SegmentationFilterType;
SegmentationFilterType::Pointer filter = SegmentationFilterType::New();
*/
try
{
std::cout << std::endl << "The directory: " << std::endl;
std::cout << std::endl << "dicom4" << std::endl << std::endl;
std::cout << "Contains the following DICOM Series: ";
std::cout << std::endl << std::endl;
typedef std::vector< std::string > SeriesIdContainer;
const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
while( seriesItr != seriesEnd )
{
std::cout << seriesItr->c_str() << std::endl;
seriesItr++;
}
std::string seriesIdentifier;
seriesIdentifier = seriesUID.begin()->c_str();
std::cout << std::endl << std::endl;
std::cout << "Now reading series: " << std::endl << std::endl;
std::cout << seriesIdentifier << std::endl;
std::cout << std::endl << std::endl;
typedef std::vector< std::string > FileNamesContainer;
FileNamesContainer fileNames;
fileNames = nameGenerator->GetFileNames( seriesIdentifier );
reader->SetFileNames( fileNames );
try
{
reader->Update();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
////////////////////////////////////////////////////////////
/* filter->SetInput( reader->GetOutput() );
filter->SetNumberOfIterations(0);
filter->SetReplaceValue(255);
filter->SetMultiplier(2.5);
ImageType::IndexType seed;
seed[0]=50;
seed[1]=50;
seed[2]=50;
filter->SetSeed(seed); */
//filter->Update();
// Fast Marching started...
typedef float RealPixelType;
typedef itk::OrientedImage< RealPixelType,3 > RealImageType;
typedef unsigned char OutputPixelType;
typedef itk::OrientedImage< OutputPixelType, 3 > OutputImageType;
typedef itk::BinaryThresholdImageFilter< RealImageType, RealImageType> ThresholdingFilterType;
ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
const PixelType timeThreshold = 130;
// Threshold setting
thresholder->SetLowerThreshold( 0.0 );
thresholder->SetUpperThreshold( timeThreshold );
// Value setting
thresholder->SetOutsideValue( 0 );
thresholder->SetInsideValue( 255 );
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
typedef itk::RescaleIntensityImageFilter<
ImageType,
OutputImageType > CastFilterType;
typedef itk::CurvatureAnisotropicDiffusionImageFilter<
RealImageType,
RealImageType > SmoothingFilterType;
SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
RealImageType,
RealImageType > GradientFilterType;
typedef itk::SigmoidImageFilter< RealImageType,
RealImageType > SigmoidFilterType;
GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
sigmoid->SetOutputMinimum( 0 );
sigmoid->SetOutputMaximum( 1 );
typedef itk::FastMarchingImageFilter< RealImageType,
RealImageType > FastMarchingFilterType;
FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
typedef itk::CastImageFilter< ImageType,RealImageType> Image_to_Real_Type;
Image_to_Real_Type::Pointer image_to_real_Filter = Image_to_Real_Type::New();
image_to_real_Filter->SetInput(reader->GetOutput() );
smoothing->SetInput( image_to_real_Filter->GetOutput());
//real_to_image_Filter->SetInput(smoothing->GetOutput());
gradientMagnitude->SetInput( smoothing->GetOutput() );
sigmoid->SetInput( gradientMagnitude->GetOutput() );
fastMarching->SetInput( sigmoid->GetOutput() );
//fastMarching->SetInput( gradientMagnitude->GetOutput() );
thresholder->SetInput( fastMarching->GetOutput() );
smoothing->SetTimeStep( 0.0625 );
smoothing->SetNumberOfIterations( 3 );
smoothing->SetConductanceParameter( 3 );
const double sigma = 3;
gradientMagnitude->SetSigma( sigma );
sigmoid->SetAlpha( 20 );
sigmoid->SetBeta( 170 );
typedef FastMarchingFilterType::NodeContainer NodeContainer;
typedef FastMarchingFilterType::NodeType NodeType;
NodeContainer::Pointer seeds = NodeContainer::New();
ImageType::IndexType seedPosition;
seedPosition[0] = 250;
seedPosition[1] = 250;
seedPosition[2] = 50;
NodeType node;
const double seedValue = 0.0;
node.SetValue( seedValue );
node.SetIndex( seedPosition );
seeds->Initialize();
seeds->InsertElement( 0, node );
fastMarching->SetTrialPoints( seeds );
fastMarching->SetOutputSize( reader->GetOutput()->GetBufferedRegion().GetSize() );
reader->Update();
fastMarching->SetStoppingValue( 100 );
typedef itk::CastImageFilter< RealImageType,ImageType> Real_to_Image_Type;
Real_to_Image_Type::Pointer real_to_image_Filter = Real_to_Image_Type::New();
real_to_image_Filter->SetInput(fastMarching->GetOutput());
//connector->SetInput(real_to_image_Filter->GetOutput());
//connector->SetInput(thresholder->GetOutput());
connector->SetInput(reader->GetOutput());
connector->Update();
// Fast Marching Ends.
/*
image_to_real_Filter->SetInput( reader->GetOutput() );
typedef itk::FastMarchingImageFilter< RealImageType,RealImageType > FastMarchingFilterType;
FastMarchingFilterType::Pointer m_FastMarchingImageFilter = FastMarchingFilterType::New();
m_FastMarchingImageFilter->SetSpeedConstant( 1.0 );
m_FastMarchingImageFilter->SetInput(image_to_real_Filter->GetOutput());
typedef itk::CannySegmentationLevelSetImageFilter<itk::Image< RealPixelType, 3 >,itk::Image< RealPixelType, 3 >> CannySegmentationLevelSetFilterType;
CannySegmentationLevelSetFilterType::Pointer m_CannySegmentationLevelSetFilter = CannySegmentationLevelSetFilterType::New();
m_CannySegmentationLevelSetFilter->SetInput( m_FastMarchingImageFilter->GetOutput() );
m_CannySegmentationLevelSetFilter->SetFeatureImage( image_to_real_Filter ->GetOutput() );
real_to_image_Filter->SetInput(m_CannySegmentationLevelSetFilter->GetOutput());
connector->SetInput(real_to_image_Filter->GetOutput());
*/
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
// Parse the parameters
int count = 1;
char *dirname = NULL;
double opacityWindow = 4096;
double opacityLevel = 2048;
int blendType = 0;
int clip = 0;
double reductionFactor = 1.0;
double frameRate = 10.0;
char *fileName = 0;
int fileType = 0;
bool independentComponents = true;
// Create the renderer, render window and interactor
vtkRenderer *renderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
// Connect it all. Note that funny arithmatic on the
// SetDesiredUpdateRate - the vtkRenderWindow divides it
// allocated time across all renderers, and the renderer
// divides it time across all props. If clip is
// true then there are two props
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetDesiredUpdateRate(frameRate / (1+clip));
iren->GetInteractorStyle()->SetDefaultRenderer(renderer);
// Read the data
//typedef itk::VTKImageExport< MaskImageType > ExportFilter2Type;
//ExportFilter2Type::Pointer itkExporter2 = ExportFilter2Type::New();
//itkExporter2->SetInput( filter->GetOutput() );
vtkDataSetMapper* geom = vtkDataSetMapper::New();
geom->SetInput(connector->GetOutput());
geom->Update();
vtkContourFilter * contour = vtkContourFilter::New();
contour->SetInput( connector->GetOutput() );
contour->SetValue(0, 128); // edges of a binary image with values 0,255
vtkPolyDataMapper * polyMapper = vtkPolyDataMapper::New();
vtkActor * polyActor = vtkActor::New();
//polyActor->SetMapper( polyMapper );
//polyMapper->SetInput( contour->GetOutput() );
//polyMapper->SetInput( geom->GetOutput() );
//polyMapper->ScalarVisibilityOff();
// Set the scene
polyActor->SetMapper( geom );
vtkProperty * vtkproperty = vtkProperty::New();
vtkproperty->SetAmbient(0.5);
vtkproperty->SetDiffuse(0.1);
vtkproperty->SetSpecular(0.5);
vtkproperty->SetColor(0.5,0.4,0.0);
vtkproperty->SetLineWidth(2.0);
vtkproperty->SetRepresentationToWireframe();
vtkproperty->SetOpacity(0.1);
polyActor->SetProperty( vtkproperty );
//renderer->AddActor( polyActor );
vtkImageData *input = 0;
input = connector->GetOutput();
vtkImageResample *resample = vtkImageResample::New();
if ( reductionFactor < 1.0 )
{
resample->SetInput(input);
resample->SetAxisMagnificationFactor(0, reductionFactor);
resample->SetAxisMagnificationFactor(1, reductionFactor);
resample->SetAxisMagnificationFactor(2, reductionFactor);
}
// Create our volume and mapper
vtkVolume *volume = vtkVolume::New();
vtkGPUVolumeRayCastMapper *mapper = vtkGPUVolumeRayCastMapper::New();
// Add a box widget if the clip option was selected
vtkBoxWidget *box = vtkBoxWidget::New();
if (clip)
{
box->SetInteractor(iren);
box->SetPlaceFactor(1.01);
if ( reductionFactor < 1.0 )
{
box->SetInput(resample->GetOutput());
}
else
{
box->SetInput(input);
}
box->SetDefaultRenderer(renderer);
box->InsideOutOn();
box->PlaceWidget();
vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
callback->SetMapper(mapper);
box->AddObserver(vtkCommand::InteractionEvent, callback);
callback->Delete();
box->EnabledOn();
box->GetSelectedFaceProperty()->SetOpacity(0.0);
}
if ( reductionFactor < 1.0 )
{
mapper->SetInputConnection( resample->GetOutputPort() );
}
else
{
mapper->SetInput(input);
//mapper->SetInputConnection( read->GetOutputPort() );
}
// Set the sample distance on the ray to be 1/2 the average spacing
double spacing[3];
if ( reductionFactor < 1.0 )
{
resample->GetOutput()->GetSpacing(spacing);
}
else
{
input->GetSpacing(spacing);
}
// mapper->SetSampleDistance( (spacing[0]+spacing[1]+spacing[2])/6.0 );
// mapper->SetMaximumImageSampleDistance(10.0);
// Create our transfer function
vtkColorTransferFunction *colorFun = vtkColorTransferFunction::New();
vtkPiecewiseFunction *opacityFun = vtkPiecewiseFunction::New();
// Create the property and attach the transfer functions
vtkVolumeProperty *property = vtkVolumeProperty::New();
property->SetIndependentComponents(independentComponents);
property->SetColor( colorFun );
property->SetScalarOpacity( opacityFun );
property->SetInterpolationTypeToLinear();
// connect up the volume to the property and the mapper
volume->SetProperty( property );
volume->SetMapper( mapper );
// Depending on the blend type selected as a command line option,
// adjust the transfer function
switch ( blendType )
{
// MIP
// Create an opacity ramp from the window and level values.
// Color is white. Blending is MIP.
case 0:
colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0 );
opacityFun->AddSegment( opacityLevel - 0.5*opacityWindow, 0.0,
opacityLevel + 0.5*opacityWindow, 1.0 );
mapper->SetBlendModeToMaximumIntensity();
break;
// CompositeRamp
// Create a ramp from the window and level values. Use compositing
// without shading. Color is a ramp from black to white.
case 1:
colorFun->AddRGBSegment( opacityLevel - 0.5*opacityWindow, 0.0, 0.0, 0.0,
opacityLevel + 0.5*opacityWindow, 1.0, 1.0, 1.0 );
opacityFun->AddSegment( opacityLevel - 0.5*opacityWindow, 0.0,
opacityLevel + 0.5*opacityWindow, 1.0 );
mapper->SetBlendModeToComposite();
property->ShadeOff();
break;
// CompositeShadeRamp
// Create a ramp from the window and level values. Use compositing
// with shading. Color is white.
case 2:
colorFun->AddRGBSegment( 0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0 );
opacityFun->AddSegment( opacityLevel - 0.5*opacityWindow, 0.0,
opacityLevel + 0.5*opacityWindow, 1.0 );
mapper->SetBlendModeToComposite();
property->ShadeOn();
break;
// CT_Skin
// Use compositing and functions set to highlight skin in CT data
// Not for use on RGB data
case 3:
colorFun->AddRGBPoint( -3024, 0, 0, 0, 0.5, 0.0 );
colorFun->AddRGBPoint( -1000, .62, .36, .18, 0.5, 0.0 );
colorFun->AddRGBPoint( -500, .88, .60, .29, 0.33, 0.45 );
colorFun->AddRGBPoint( 3071, .83, .66, 1, 0.5, 0.0 );
opacityFun->AddPoint(-3024, 0, 0.5, 0.0 );
opacityFun->AddPoint(-1000, 0, 0.5, 0.0 );
opacityFun->AddPoint(-500, 1.0, 0.33, 0.45 );
opacityFun->AddPoint(3071, 1.0, 0.5, 0.0);
mapper->SetBlendModeToComposite();
property->ShadeOn();
property->SetAmbient(0.1);
property->SetDiffuse(0.9);
property->SetSpecular(0.2);
property->SetSpecularPower(10.0);
property->SetScalarOpacityUnitDistance(0.8919);
break;
// CT_Bone
// Use compositing and functions set to highlight bone in CT data
// Not for use on RGB data
case 4:
colorFun->AddRGBPoint( -3024, 0, 0, 0, 0.5, 0.0 );
colorFun->AddRGBPoint( -16, 0.73, 0.25, 0.30, 0.49, .61 );
colorFun->AddRGBPoint( 641, .90, .82, .56, .5, 0.0 );
colorFun->AddRGBPoint( 3071, 1, 1, 1, .5, 0.0 );
opacityFun->AddPoint( -3024, 0, 0.5, 0.0 );
opacityFun->AddPoint( -16, 0, .49, .61 );
opacityFun->AddPoint( 641, .72, .5, 0.0 );
opacityFun->AddPoint( 3071, .71, 0.5, 0.0 );
mapper->SetBlendModeToComposite();
property->ShadeOn();
property->SetAmbient(0.1);
property->SetDiffuse(0.9);
property->SetSpecular(0.2);
property->SetSpecularPower(10.0);
property->SetScalarOpacityUnitDistance(0.8919);
break;
// CT_Muscle
// Use compositing and functions set to highlight muscle in CT data
// Not for use on RGB data
case 5:
colorFun->AddRGBPoint(-3024, 0, 0, 0, 0.5, 0.0);
colorFun->AddRGBPoint(-155, .55, .25, .15, 0.5, .92);
colorFun->AddRGBPoint(217, .88, .60, .29, 0.33, 0.45);
colorFun->AddRGBPoint(420, 1, .94, .95, 0.5, 0.0);
colorFun->AddRGBPoint(3071, .83, .66, 1, 0.5, 0.0);
opacityFun->AddPoint(-3024, 0, 0.5, 0.0);
opacityFun->AddPoint(-155, 0, 0.5, 0.92);
opacityFun->AddPoint(217, .68, 0.33, 0.45);
opacityFun->AddPoint(420,.83, 0.5, 0.0);
opacityFun->AddPoint(3071, .80, 0.5, 0.0);
mapper->SetBlendModeToComposite();
property->ShadeOn();
property->SetAmbient(0.1);
property->SetDiffuse(0.9);
property->SetSpecular(0.2);
property->SetSpecularPower(10.0);
property->SetScalarOpacityUnitDistance(0.8919);
break;
// RGB_Composite
// Use compositing and functions set to highlight red/green/blue regions
// in RGB data. Not for use on single component data
case 6:
opacityFun->AddPoint(0, 0.0);
opacityFun->AddPoint(5.0, 0.0);
opacityFun->AddPoint(30.0, 0.05);
opacityFun->AddPoint(31.0, 0.0);
opacityFun->AddPoint(90.0, 0.0);
opacityFun->AddPoint(100.0, 0.3);
opacityFun->AddPoint(110.0, 0.0);
opacityFun->AddPoint(190.0, 0.0);
opacityFun->AddPoint(200.0, 0.4);
opacityFun->AddPoint(210.0, 0.0);
opacityFun->AddPoint(245.0, 0.0);
opacityFun->AddPoint(255.0, 0.5);
mapper->SetBlendModeToComposite();
property->ShadeOff();
property->SetScalarOpacityUnitDistance(1.0);
break;
default:
vtkGenericWarningMacro("Unknown blend type.");
break;
}
// Set the default window size
renWin->SetSize(600,600);
renWin->Render();
if ( !mapper->IsRenderSupported(renWin, property) )
{
cout << "This mapper is unsupported on this platform" << endl;
exit(EXIT_FAILURE);
}
// Add the volume to the scene
renderer->AddVolume( volume );
renderer->ResetCamera();
// interact with data
renWin->Render();
iren->Start();
opacityFun->Delete();
colorFun->Delete();
property->Delete();
box->Delete();
volume->Delete();
mapper->Delete();
//reader->Delete();
resample->Delete();
renderer->Delete();
renWin->Delete();
iren->Delete();
contour->Delete();
geom->Delete();
polyMapper->Delete();
polyActor->Delete();
vtkproperty->Delete();
return 0;
}
***********************************************************************************************
But when I do theexecutable program( Navogation.exe )
Picture a flash,then disappear.
system prompt:<This mapper is unsurpported on this paltform>
my graphics card as:ATI Radeon HD 4350
Need I change my graphics card ?
thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110411/6aed2884/attachment.htm>
More information about the vtkusers
mailing list