[vtkusers] Marching cubes rendering

Bill Lorensen bill.lorensen at gmail.com
Tue Aug 30 08:01:12 EDT 2011


Please post all of the code including all of the typedef's.

On Mon, Aug 29, 2011 at 1:01 PM, khaled danwar <khaled.danwar53 at gmail.com>wrote:

> 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.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110830/ef23ed56/attachment.htm>


More information about the vtkusers mailing list