[vtkusers] surface from contours
Carsten Barkow
carsten.barkow at googlemail.com
Wed Apr 23 11:08:59 EDT 2008
Hi,
we've implemented a 3D segmentation algorithm and want to evaluate it.
Due to this we get some manual segmented data, but those are only 2D
contours for each section of the volume. So we want to generate a 3D
surface from this contours.
In VTK there are classes for this purpose like vtkVoxelContoursToSurface
or vtkRuledSurfaceFilter. Unfortunately we can not make it show us a
surface. Has anybody an idea where the fault is? Here is the code:
vtkPoints *points = vtkPoints::New();
vtkCellArray *cells = vtkCellArray::New();
int index = 0;
int temp;
VoxelXYZ v;
double x, y, z;
std::vector<VoxelXYZ> contour;
// --- writing points and lines
----------------------------------------------------------------
for(int sec = 0; sec < borderPoints->getZRes(); ++sec){
if(borderPoints->getContour(sec, contour)){
//remember first point index of actual contour
temp = index;
for(std::vector<VoxelXYZ>::iterator it =
contour.begin(); it!=contour.end(); ++it){
v = *it;
x = static_cast<double>(v.getX());
y = static_cast<double>(v.getY());
z = static_cast<double>(v.getZ());
points->InsertPoint(index, v.getX(), v.getY(),
v.getZ());
vtkLine *line = vtkLine::New();
line->GetPointIds()->SetId(0, index);
if((index-temp) == contour.size()-1)
//reached last point of actual contour and
close contour
line->GetPointIds()->SetId(1, temp);
else
line->GetPointIds()->SetId(1, index+1);
cells->InsertNextCell(line);
line->Delete();
++index;
}
}
}
//
--------------------------------------------------------------------------------------------
// Insert points and cells
vtkPolyData *pointCloud = vtkPolyData::New();
pointCloud->SetPoints(points);
pointCloud->SetPolys(cells); // it also doesn't work with
pointCloud->SetLines(cells);
// --- just show contours for testing and this works fine we guess
--------------------------------------
vtkPolyDataMapper *contourMapper = vtkPolyDataMapper::New();
contourMapper->SetInput(pointCloud);
vtkActor *contourActor = vtkActor::New();
contourActor->SetMapper(contourMapper);
contourActor->GetProperty()->SetColor(1, 0, 0);
contourActor->GetProperty()->SetAmbient(1);
contourActor->GetProperty()->SetDiffuse(0);
contourActor->GetProperty()->SetRepresentationToWireframe();
renSurface->AddActor(contourActor);
contourMapper->Delete();
contourActor->Delete();
//
------------------------------------------------------------------------------------------------
// vtkRuledSurfaceFilter approach
/*vtkRuledSurfaceFilter *ruledSurfaceFilter =
vtkRuledSurfaceFilter::New();
ruledSurfaceFilter->SetInput(pointCloud);
ruledSurfaceFilter->CloseSurfaceOn();*/
// vtkVoxelContoursToSurfaceFilter approach
vtkVoxelContoursToSurfaceFilter *contourToSurfaceFilter =
vtkVoxelContoursToSurfaceFilter::New();
contourToSuraceFilter->SetInput(pointCloud);
vtkPolyDataMapper *surfaceMapper = vtkPolyDataMapper::New();
//surfaceMapper->SetInputConnection(ruledSurfaceFilter->GetOutputPort());
surfaceMapper->SetInputConnection(contourToSurfaceFilter->GetOutputPort());
vtkActor *surfaceActor = vtkActor::New();
surfaceActor->SetMapper(surfaceMapper);
surfaceActor->GetProperty()->SetDiffuseColor(1.0000, 0.3882, 0.2784);
surfaceActor->GetProperty()->SetSpecularColor(1, 1, 1);
surfaceActor->GetProperty()->SetSpecular(.4);
surfaceActor->GetProperty()->SetSpecularPower(50);
renSurface->AddActor(surfaceActor);
points->Delete();
cells->Delete();
pointCloud->Delete();
surfaceMapper->Delete();
surfaceActor->Delete();
renSurface->Delete();
***thx for any hints/help***
More information about the vtkusers
mailing list