[vtkusers] Marching cubes rendering

khaled danwar khaled.danwar53 at gmail.com
Mon Aug 29 13:01:24 EDT 2011


Hello vtk users

The program I am writing has a mixture of itk and vtk procedures, my problem
is when I make use of vtkMarchingCubes.

>From my understanding, I can use vtkMarchingCubes to render a 3D image in
the viewing window (and effectively interact with it).

I have a series of dicom files. I went through each and every one of them to
select seeds for a region based segmentation procedure
(itkConfidenceConnectedFilter), I then write segmented output into a new
dicom file (I simply use itkImageWriter and filename to originalName.dcm and
save it in another directory). The last task I need to do is to give a 3D
visualisation of segmented dicom files (preferably using MarchingCubes).
When I try the code below out, it complains about the files not being in 3D
format when Im sure (I think Im sure, I'm anew user to vtk and itk) I saved
it in 3D format.


Code:


typedef float InputPixelType;
typedef unsigned short OutputPixelType;

//define the image type that will read from the input DICOM file
typedef itk::Image<InputPixelType,InputDimension> InputImageType;
typedef itk::ImageFileReader<InputImageType> ReaderType;


//Load the data
ReaderType3D::Pointer reader = ReaderType3D::New();
//we need to make use of GDCMImageIO to assist with reading a series of
DICOM files in a different directory
ImageIOType::Pointer dicomReadIO = ImageIOType::New();
reader->SetImageIO( dicomReadIO );
//get the directory whilst instructing to make use of as much information to
distinguish between DICOM files
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
nameGenerator->SetUseSeriesDetails( true );
nameGenerator->SetInputDirectory( outputDirectory );
//extraxt the filenames
    SeriesIdContainer seriesUID = nameGenerator->GetSeriesUIDs();
    FileNamesContainer fileNames = nameGenerator->GetFileNames(
seriesUID.begin()->c_str() );

    reader->SetFileNames( fileNames );
    try
      {
      reader->Update();
      }
    catch (itk::ExceptionObject &ex)
      {
      std::cout << ex << std::endl;
      }

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);


//Smoothing the edges with gaussian
vtkSmartPointer<vtkImageGaussianSmooth> gaussianSmoothFilter =
vtkSmartPointer<vtkImageGaussianSmooth>::New();
gaussianSmoothFilter->SetInput(threshold->GetOutput());
//gaussianSmoothFilter->SetInputConnection(vtkImporter->GetOutputPort());
gaussianSmoothFilter->SetRadiusFactor(2);

vtkImageToStructuredPoints
*toStructuredPoints=vtkImageToStructuredPoints::New();
 toStructuredPoints->SetInput(gaussianSmoothFilter->GetOutput());

//Marching Cubes
vtkSmartPointer<vtkDiscreteMarchingCubes> surface =
vtkSmartPointer<vtkDiscreteMarchingCubes>::New();
surface->SetInput(toStructuredPoints->GetOutput());
//surface->SetInputConnection(gaussianSmoothFilter->GetOutputPort());
surface->ComputeNormalsOn();
surface->ComputeGradientsOn();

//Create a mapper
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(surface->GetOutput());
mapper->SetInputConnection(surface->GetOutputPort());

// Visualize
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();

renderer->AddActor(actor);
renderWindow->AddRenderer(renderer);
interactor->SetRenderWindow(renderWindow);

renderWindow->SetSize(800,600);
renderWindow->Render();
interactor->Start();







Error:

ERROR: In C:.....\vtkMarchingCubes.cxx, line 415
vtkMarchingCubes (0000000002F58D40): Cannot contour data of dimension != 3



Any help would be appreciated including any insight on these vtk classes I
may be using wrongly, Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110829/7a5ac21a/attachment.htm>


More information about the vtkusers mailing list