[vtkusers] Calculating the area of a polygon

polys_poly at hotmail.com polys_poly at hotmail.com
Thu May 8 08:16:13 EDT 2008


Thanks Michael. That worked


From: Michael Rice 
Sent: Wednesday, May 07, 2008 3:35 PM
To: polys_poly at hotmail.compolys_poly@hotmail.com
Subject: Re: [vtkusers] Calculating the area of a polygon


Did you call polygonProperties->Update() before trying to use the polygonProperties->SurfaceArea? 


Michael



On May 6, 2008, at 8:00 AM, <polys_poly at hotmail.com> <polys_poly at hotmail.com> wrote:

  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

  _______________________________________________
  This is the private VTK discussion list.
  Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
  Follow this link to subscribe/unsubscribe:
  http://www.vtk.org/mailman/listinfo/vtkusers


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080508/d7473fad/attachment.htm>


More information about the vtkusers mailing list