[vtkusers] Calculating the area of a polygon

polys_poly at hotmail.com polys_poly at hotmail.com
Tue May 6 09:00:36 EDT 2008


Hello,

I am using the following code to create a polygon in 3D.


vtkPolygon* polygon1 = vtkPolygon::New(); 
vtkPoints* polygonPoints1  = vtkPoints::New();
vtkPolyData* polyData1 = vtkPolyData::New();
vtkPolyDataMapper* polygonMapper1 = vtkPolyDataMapper::New(); 
vtkTriangleFilter* tri1= vtkTriangleFilter::New();

polygonPoints1->SetNumberOfPoints(4);
polygon1->GetPointIds()->SetNumberOfIds(4);

polygonPoints1->InsertPoint(0, x1, y1, z1);
polygon1->GetPointIds()->SetId(0, 0);

polygonPoints1->InsertPoint(1, x2, y2, z2);
polygon1->GetPointIds()->SetId(1, 1);

polygonPoints1->InsertPoint(2, x3, y3, z3);
polygon1->GetPointIds()->SetId(2, 2);

polygonPoints1->InsertPoint(3, x4, y4, z4);
polygon1->GetPointIds()->SetId(3, 3);

polyData1->Allocate();
polyData1->InsertNextCell(polygon1->GetCellType(),polygon1->GetPointIds());
polyData1->SetPoints(polygonPoints1);

tri1->SetInput(polyData1);
polygonMapper1->SetInput(tri1->GetOutput());

What i am trying to do is get the area of the polygon.

I am using the following code but i get 0 for the area

vtkMassProperties* polygonProperties = vtkMassProperties::New(); 
polygonProperties->SetInputConnection(tri1->GetOutputPort());
double area = polygonProperties->SurfaceArea;

Can someone tell me what i am doing wrong or is there any other way to compute the area of a polygon.

Maybe there is a way to find the number of pixels that a polygon has on the screen and multiply that number with the pixel size?

Thanks in advance,
Polys
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080506/9efe8e2d/attachment.htm>


More information about the vtkusers mailing list