[Insight-users] Polydata volume calculation problem

Xiaopeng Yang yxp233 at postech.ac.kr
Wed Jan 19 04:29:06 EST 2011


Dear VTK and ITK users,

 

I tried to calculate polydata volume through vtkMassProperties. Firstly, the
polydata was generated from a set of 3D points. Then I applied
vtkSurfaceReconstructionFilter to generate a surface. And then a contour was
generated by vtkContourFilter. After several other steps, I got the volume
by vtkMassProperties.

 

The problem is:

1.       Whether my code is proper to calculate polydata volume?

2.       When I change the SetValue(0, 10) of vtkContourFilter to some value
else, for example, SetValue(0, 20), the calculated volumes under the two
conditions are very different. What value is proper to calculate volume?

3.       What is the correct way to calculate polydata volume?

 

Thanks very much! The following is the code:

 

        for (i = 0; i < spl_max; i++)

              {

                     points->InsertNextPoint(segment_point_list[i][0],
segment_point_list[i][1], segment_point_list[i][2]);

              }

 

        polydata->SetPoints(points);

 

        vtkSurfaceReconstructionFilter *surf =
vtkSurfaceReconstructionFilter::New(); 

        surf->SetInput(polydata); 

 

        vtkContourFilter *contours = vtkContourFilter::New(); 

        contours->SetInputConnection(surf->GetOutputPort()); 

        contours->SetValue(0,10); 

 

        // # Extract boundary edges 

        vtkFeatureEdges *boundary = vtkFeatureEdges::New(); 

        boundary->BoundaryEdgesOn(); 

        boundary->FeatureEdgesOff(); 

        boundary->ManifoldEdgesOff(); 

        boundary->NonManifoldEdgesOff(); 

        boundary->SetInputConnection(contours->GetOutputPort()); 

        

        // # Build a polyline from boundary edges 

        vtkStripper *stripper = vtkStripper::New(); 

        stripper->SetInputConnection(boundary->GetOutputPort()); 

        stripper->Update(); 

        vtkPolyData *holePoly = vtkPolyData::New(); 

        holePoly->SetPoints(stripper->GetOutput()->GetPoints()); 

        holePoly->SetPolys(stripper->GetOutput()->GetLines()); 

        

        // # Triangulate hole 

        vtkTriangleFilter *filler = vtkTriangleFilter::New(); 

        filler->SetInput(holePoly); 

 

        // # Combine into a single polydata 

        vtkAppendPolyData *apd = vtkAppendPolyData::New(); 

        apd->AddInputConnection(contours->GetOutputPort()); 

        apd->AddInputConnection(filler->GetOutputPort()); 

 

        // # Merge duplicate points 

        vtkCleanPolyData *cleaner = vtkCleanPolyData::New(); 

        cleaner->AddInputConnection(apd->GetOutputPort()); 

 

        // # Add normals 

        vtkPolyDataNormals *apdNormals = vtkPolyDataNormals::New(); 

        apdNormals->SetInputConnection(cleaner->GetOutputPort()); 

 

        vtkReverseSense *reverse = vtkReverseSense::New(); 

        reverse->SetInputConnection(apdNormals->GetOutputPort()); 

        reverse->ReverseCellsOn(); 

        reverse->ReverseNormalsOn(); 

 

        vtkTriangleFilter *triangle = vtkTriangleFilter::New(); 

        triangle->SetInputConnection(reverse->GetOutputPort()); 

        

        vtkMassProperties *massProperty = vtkMassProperties::New(); 

        massProperty->SetInputConnection(triangle->GetOutputPort()); 

 

       massProperty->Update();

       double vol = massProperty->GetVolume();

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110119/2cd0ec8b/attachment.htm>


More information about the Insight-users mailing list