[vtkusers] How to do 3D reconstruction by a series of DICOM Files?

陳鼎元 r.chen.dk at gmail.com
Fri Mar 18 00:34:38 EDT 2016


Hello Everyone:

    I am a Beginner using VTK for DICOM Image application, I successfully
read the DICOM Image by vtkDICOMReader, I tried to find out the 3D
rendering methods: MarchingCubes, I just copy the codes on the example and
change the Directory Folder to in which my DICOM Files are saved, and it
ended up to an error(as the snapshot_1), here is my code:

    I really want to realize where the error comes from, since it's similar
as the least one, is there some knowledge I should take care before using
VTK libraries? Also do you recommend the other 3D reconstruction methods?


#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkMarchingCubes.h>
#include <vtkVoxelModeller.h>
#include <vtkSphereSource.h>
#include <vtkImageData.h>
#include <vtkDICOMImageReader.h>
#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>

#include <vtkAutoInit.h>
#include <vtkInteractionStyleModule.h>
#include <vtkInteractionStyleObjectFactory.h>
#include <vtkRenderingOpenGL2Module.h>
#include <vtkRenderingOpenGL2ObjectFactory.h>
#include <vtkInteractionStyleModule.h>
#include <vtkInteractionStyleObjectFactory.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkInteractionStyle);

int main(int argc, char *argv[])
{
vtkSmartPointer<vtkImageData> volume =
vtkSmartPointer<vtkImageData>::New();
double isoValue;

vtkSmartPointer<vtkDICOMImageReader> reader =
vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetDirectoryName("D:/Ralf/VTK/DICOM/case2009.04.15.12.07.26/MR");
reader->Update();
volume->DeepCopy(reader->GetOutput());
isoValue = atof(argv[2]);

vtkSmartPointer<vtkMarchingCubes> surface =
vtkSmartPointer<vtkMarchingCubes>::New();

#if VTK_MAJOR_VERSION <= 5
surface->SetInput(volume);
#else
surface->SetInputData(volume);
#endif
surface->ComputeNormalsOn();
surface->SetValue(0, isoValue);

vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->SetBackground(.1, .2, .3);

vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);

vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(surface->GetOutputPort());
mapper->ScalarVisibilityOff();

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

renderer->AddActor(actor);

renderWindow->Render();
interactor->Start();
return EXIT_SUCCESS;
}


                                                              Sincerely,
Ralf.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160318/1900313f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: snapshot_1.JPG
Type: image/jpeg
Size: 29726 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160318/1900313f/attachment.jpe>


More information about the vtkusers mailing list