[vtkusers] Displaying 3D RT Structure contours
mbcx9rb9
richard.j.brown at live.co.uk
Wed Apr 29 04:23:25 EDT 2015
Hi,
I want to create a surface of my RT Structure file, but the output is
unsatisfactory.
Below, I have attached an image containing the eyes and optic nerves
segmented in a third party program. The left is the individual 2D RT
Structure contours all stacked on top of each other and rendered. The slices
are not joined together, so I perform a surface reconstruction, which
results in the image on the right. The resulting image, whilst being 3D (as
opposed to stacked 2D slices), looks nothing like the original!
Any ideas on how I can create a 3D surface, which resembles the individual
2D slices more closely?
<http://vtk.1045678.n5.nabble.com/file/n5731669/Screen_Shot_2015-04-29_at_10.png>
Here is my code:
// vtk
#include <vtkMath.h>
#include <vtkSmartPointer.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkAppendPolyData.h>
#include <vtkSurfaceReconstructionFilter.h>
#include <vtkContourFilter.h>
#include <vtkReverseSense.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindowInteractor.h>
// gdcm
#include <vtkGDCMPolyDataReader.h>
#include <vtkRTStructSetProperties.h>
int main()
{
// need this for random numbers
vtkMath::RandomSeed(time(NULL));
// read RT Struct file
vtkSmartPointer<vtkGDCMPolyDataReader> reader =
vtkSmartPointer<vtkGDCMPolyDataReader>::New();
reader->SetFileName("/Users/CRCT_Richard/Documents/PhD/Scan_Data/Laure/TDMGLIO/RS.1.3.6.1.4.1.33868.20150218162450.311249");
reader->Update();
// create renderers and link to their qvtkwidgets
vtkSmartPointer<vtkRenderer> renderer1 =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderer> renderer2 =
vtkSmartPointer<vtkRenderer>::New();
// iterate through each contour
for (int i=1;
i<reader->GetRTStructSetProperties()->GetNumberOfStructureSetROIs(); i++) {
// create surface from points
vtkSmartPointer<vtkAppendPolyData> append =
vtkSmartPointer<vtkAppendPolyData>::New();
append->SetInputConnection(reader->GetOutputPort(i));
vtkSmartPointer<vtkSurfaceReconstructionFilter> surf =
vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
surf->SetInputConnection(append->GetOutputPort());
vtkSmartPointer<vtkContourFilter> contourFilter =
vtkSmartPointer<vtkContourFilter>::New();
contourFilter->SetInputConnection(surf->GetOutputPort());
contourFilter->SetValue(0, 0.0);
vtkSmartPointer<vtkReverseSense> reverse =
vtkSmartPointer<vtkReverseSense>::New();
reverse->SetInputConnection(contourFilter->GetOutputPort());
reverse->ReverseCellsOn();
reverse->ReverseNormalsOn();
reverse->Update();
// random colour for each contour
double RGB[3] = { vtkMath::Random(0.3,1), vtkMath::Random(0.3,1),
vtkMath::Random(0.3,1) };
// render output from vtkAppendPolyData
vtkSmartPointer<vtkPolyDataMapper> mapper1 =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper1->SetInputConnection(append->GetOutputPort());
mapper1->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> actor1 = vtkSmartPointer<vtkActor>::New();
actor1->SetMapper(mapper1);
actor1->GetProperty()->SetRepresentationToSurface();
actor1->GetProperty()->SetOpacity(0.5);
actor1->GetProperty()->SetColor(RGB);
actor1->GetProperty()->SetDiffuse(0);
actor1->GetProperty()->SetAmbient(1);
renderer1->AddActor(actor1);
// render output from vtkReverseSense
vtkSmartPointer<vtkPolyDataMapper> mapper2 =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper2->SetInputConnection(reverse->GetOutputPort());
mapper2->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> actor2 = vtkSmartPointer<vtkActor>::New();
actor2->SetMapper(mapper2);
actor2->GetProperty()->SetRepresentationToSurface();
actor2->GetProperty()->SetOpacity(0.5);
actor2->GetProperty()->SetColor(RGB);
actor2->GetProperty()->SetDiffuse(0);
actor2->GetProperty()->SetAmbient(1);
renderer2->AddActor(actor2);
}
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer1);
renderWindow->AddRenderer(renderer2);
renderer1->SetViewport(0,0,0.5,1);
renderer2->SetViewport(0.5,0,1,1);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindow->SetInteractor(interactor);
interactor->Start();
return 0;
}
--
View this message in context: http://vtk.1045678.n5.nabble.com/Displaying-3D-RT-Structure-contours-tp5731669.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list