I tried out the itk vtk import/export connections to load a 3d image in itk and then 3d render it in vtk but the same problem reappeared. Below is my adjusted code and the specific error I get:<div><br></div><div>Code:</div>
<div><br></div><div><div>const unsigned int<span class="Apple-tab-span" style="white-space:pre">        </span>InputDimension3D = 3;</div><div>typedef unsigned short OutputPixelType;</div></div><div><br></div><div><div>typedef itk::Image<OutputPixelType, InputDimension3D><span class="Apple-tab-span" style="white-space:pre">        </span>InputImageType3D;</div>
<div>typedef itk::ImageSeriesReader<InputImageType3D><span class="Apple-tab-span" style="white-space:pre">        </span>ReaderType3D;</div></div><div><br></div><div><div>typedef itk::VTKImageExport< InputImageType3D > ExportFilterType;</div>
<div>typedef itk::VTKImageImport< InputImageType3D > ImportFilterType;</div></div><div><br></div><div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//Load the data</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ReaderType3D::Pointer reader = ReaderType3D::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//we need to make use of GDCMImageIO to assist with reading a series of DICOM files in a different directory</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ImageIOType::Pointer dicomReadIO = ImageIOType::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>reader->SetImageIO( dicomReadIO );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//get the directory whilst instructing to make use of as much information to distinguish between DICOM files</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>nameGenerator->SetUseSeriesDetails( true );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>nameGenerator->SetInputDirectory( outputDirectory );</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//extraxt the filenames</div>
<div> SeriesIdContainer seriesUID = nameGenerator->GetSeriesUIDs();</div><div> FileNamesContainer fileNames = nameGenerator->GetFileNames( seriesUID.begin()->c_str() );</div><div><br></div><div> reader->SetFileNames( fileNames );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div> try</div><div> {</div><div> reader->Update();</div><div> }</div><div> catch (itk::ExceptionObject &ex)</div><div> {</div>
<div> std::cout << ex << std::endl;</div><div> }</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ExportFilterType::Pointer itkExporter = ExportFilterType::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>itkExporter->SetInput( reader->GetOutput() );</div><div> //Create the vtkImageImport and connect it to the itk::VTKImageExport instance.</div><div>
vtkImageImport* vtkImporter = vtkImageImport::New(); </div><div> ConnectPipelines(itkExporter, vtkImporter);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//Smoothing the edges with gaussian</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkImageGaussianSmooth> gaussianSmoothFilter = vtkSmartPointer<vtkImageGaussianSmooth>::New(); </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gaussianSmoothFilter->SetInput(vtkImporter->GetOutput());</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//gaussianSmoothFilter->SetInputConnection(vtkImporter->GetOutputPort()); </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gaussianSmoothFilter->SetRadiusFactor(2); </div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//Marching Cubes</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkMarchingCubes> surface = vtkSmartPointer<vtkMarchingCubes>::New(); </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>surface->SetInput(gaussianSmoothFilter->GetOutput());</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//surface->SetInputConnection(gaussianSmoothFilter->GetOutputPort());</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>surface->ComputeNormalsOn();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>surface->ComputeGradientsOn();</div><div><br></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>//Create a mapper</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>mapper->SetInput(surface->GetOutput());</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>mapper->SetInputConnection(surface->GetOutputPort());</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// Visualize</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>actor->SetMapper(mapper);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); </div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>renderer->AddActor(actor); </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>renderWindow->AddRenderer(renderer); </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>interactor->SetRenderWindow(renderWindow); </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>renderWindow->SetSize(800,600); </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>renderWindow->Render(); </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>interactor->Start(); </div><div><br></div><div><br></div>
<div><br></div><div>Error:</div><div><br></div><div><div>ERROR: In C:.....\vtkMarchingCubes.cxx, line 415</div><div>vtkMarchingCubes (0000000002F58D40): Cannot contour data of dimension != 3</div></div><div><br></div><div>
<br></div><div>Thanks for any help</div><div><br></div><div><br></div><div><br></div><br><div class="gmail_quote">On Sun, Aug 28, 2011 at 1:24 AM, Richard Beare <span dir="ltr"><<a href="mailto:richard.beare@gmail.com">richard.beare@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">You can use ITK to load the segmented series as a 3D image and either<br>
save it to a 3d format and load in vtk, or use the itk to vtk<br>
connector so to transfer the 3d image object to the vtk part of your<br>
code. There are examples of this in the InsightApplications suite.<br>
<br>
It is also likely, although I haven't checked, that vtk has a dicom<br>
series reader, enabling it to read all of the dicoms into a 3d object<br>
<div><div></div><div class="h5"><br>
On Sun, Aug 28, 2011 at 1:07 AM, khaled danwar<br>
<<a href="mailto:khaled.danwar53@gmail.com">khaled.danwar53@gmail.com</a>> wrote:<br>
> Hello,<br>
> I wasn't not sure if this request for help was better suited for itk users<br>
> or vtk users, so I just went with itk since most of my code uses itk,<br>
> hopefully nobody objects and I could still get help from any of you<br>
> (including vtk users).<br>
> The lay out of the land is this:<br>
> 1) for each dicom image I use the confidence connected image filter from itk<br>
> to employ a region based segmentation. Note that I do this for each image in<br>
> turn (ie click on seed points on original image, get it segmented, save the<br>
> file as a new dicom file in a folder) becasue I simply need to for this<br>
> particular project.<br>
> 2) once I have all my segmented dicom files in that folder, I intend to<br>
> (more like 'need to') use the marching cubes algorithm given by vtk so that<br>
> I can render a 3D image of the skull (I'm segmenting ct scans to get the<br>
> bones alone). This is where my problem is.<br>
> For this particular 3d Rendering, my code looks a little something like<br>
> this:<br>
><br>
> //Load the data<br>
> vtkSmartPointer<vtkDICOMImageReader> reader =<br>
> vtkSmartPointer<vtkDICOMImageReader>::New();<br>
> reader->SetDirectoryName(outputDirectory.c_str());<br>
> reader->Update();<br>
> //Smoothing the edges with gaussian<br>
> vtkSmartPointer<vtkImageGaussianSmooth> gaussianSmoothFilter =<br>
> vtkSmartPointer<vtkImageGaussianSmooth>::New();<br>
> gaussianSmoothFilter->SetInputConnection(reader->GetOutputPort());<br>
> gaussianSmoothFilter->SetRadiusFactor(2);<br>
> //Marching Cubes<br>
> vtkSmartPointer<vtkMarchingCubes> surface =<br>
> vtkSmartPointer<vtkMarchingCubes>::New();<br>
> surface->SetInputConnection(gaussianSmoothFilter->GetOutputPort());<br>
> surface->ComputeNormalsOn();<br>
> surface->ComputeGradientsOn();<br>
> //surface->SetInputConnection(reader->GetOutputPort());<br>
> //Create a mapper<br>
> vtkSmartPointer<vtkPolyDataMapper> mapper =<br>
> vtkSmartPointer<vtkPolyDataMapper>::New();<br>
> mapper->SetInputConnection(surface->GetOutputPort());<br>
> // Visualize<br>
> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();<br>
> actor->SetMapper(mapper);<br>
> vtkSmartPointer<vtkRenderer> renderer =<br>
> vtkSmartPointer<vtkRenderer>::New();<br>
><br>
> vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
> vtkSmartPointer<vtkRenderWindow>::New();<br>
> renderWindow->AddRenderer(renderer);<br>
> vtkSmartPointer<vtkRenderWindowInteractor> interactor =<br>
> vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
> interactor->SetRenderWindow(renderWindow);<br>
> renderer->AddActor(actor);<br>
><br>
> renderWindow->SetSize(800,600);<br>
> renderWindow->Render();<br>
> interactor->Start();<br>
><br>
> The problem is that the marching cubes algorithm is complaining that the<br>
> dicom files holding the segmented images are not of 3D format and so it cant<br>
> render an output that I need. So can anyone help me sort out my need to use<br>
> vtk marching cubes algorithm after I've used itk segmentation on multiple<br>
> files in turn.<br>
> Thanks for any help,<br>
> Khaled<br>
</div></div>> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
><br>
><br>
</blockquote></div><br></div>