[vtk-developers] How to assign a specific color to a region during surface reconstruction using vtkDiscreteMarchingCubes
lf
liuf_2001 at 163.com
Fri Apr 10 22:31:24 EDT 2015
Hello, everyone,
I got a problem when I do surface reconstruction using vtkDiscreteMarchingCubes. Can somebody give me a help?
Thank you very much.
Fei Liu
-----------------
Objective:
we want to do surface reconstruction for some segmented CT images.
For each segmented image, we have got four differentiated regions: kidney (gray value 220), tumor (gray value 230), vessels (gray value 240), and spine (gray value 250). The left area has a gray value of 0.
When we do surface reconstruction for these segmented CT images, we want to get the following result:
each of the four regions (kidney, tumor, vesels and spine) is displayed with a different color given by lookuptake.
-----------------
Current problem:
However, it does not work using the following codes, that is, the selected colors in the lookuptable are not assigned to the four regions.
Here are the codes:
{
vtkSmartPointer<vtkImageAppend > append = vtkSmartPointer<vtkImageAppend >::New();
//then I put images in append
//using vtkDiscreteMarchingCubes for reconstruction
vtkSmartPointer<vtkDiscreteMarchingCubes> dmc = vtkSmartPointer<vtkDiscreteMarchingCubes>::New();
dmc->SetInputConnection(append->GetOutputPort());
dmc->SetValue(0, 220);
dmc->SetValue(1, 230);
dmc->SetValue(2, 240);
dmc->SetValue(3, 250);
dmc->Update();
//optimization
vtkSmartPointer<vtkDecimatePro> deci = vtkSmartPointer<vtkDecimatePro>::New(); //减少数据读取点,以牺牲数据量加速交互
deci->SetTargetReduction(0.3);
deci->SetInputConnection(dmc->GetOutputPort());
vtkSmartPointer<vtkSmoothPolyDataFilter> smooth = vtkSmartPointer<vtkSmoothPolyDataFilter>::New(); //使图像更加光滑
smooth->SetInputConnection(deci->GetOutputPort());
smooth->SetNumberOfIterations(200);
vtkSmartPointer<vtkPolyDataNormals> skinNormals = vtkSmartPointer<vtkPolyDataNormals>::New(); //求法线
skinNormals->SetInputConnection(smooth->GetOutputPort());
skinNormals->SetFeatureAngle(60.0);
vtkSmartPointer<vtkStripper> stripper = vtkSmartPointer<vtkStripper>::New(); //将三角形连接起来
stripper->SetInputConnection(skinNormals->GetOutputPort());
// Map the scalar values in the image to colors with a lookup table:
vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
lookupTable->SetNumberOfTableValues(4);
lookupTable->SetTableValue(0, 0.8900, 0.8100, 0.3400, 1); // Banana
lookupTable->SetTableValue(1, 1.0000, 0.3882, 0.2784, 1); // Tomato
lookupTable->SetTableValue(2, 0.7400, 0.9900, 0.7900, 1); // Mint
lookupTable->SetTableValue(3, 0.2000, 0.6300, 0.7900, 1); // Peacock
lookupTable->Build();
//define a new actor and vtkPolyDataMapper mapper
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(stripper->GetOutputPort());
mapper->ScalarVisibilityOn();
mapper->SetScalarRange(220, 250);
mapper->SetScalarModeToUseCellData();
mapper->SetLookupTable(lookupTable);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
//add actor to a render and display the result
m_StaticSurface1.GetvtkRenderer()->AddActor(actor);
m_StaticSurface1.GetvtkRenderer()->ResetCamera();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20150411/69dfb0a9/attachment.html>
More information about the vtk-developers
mailing list