But, how could I get the polygon out of a contour?? I mean applying the contour widget lets you define points and you can close that to forma a 2D contour. Once that's finished how to get the polygon out of that contour??<div class="gmail_extra">
<br><br><div class="gmail_quote">2012/12/3 David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This also has nothing to do with the widget. You can produce the same<br>
error with much simpler code (see below).<br>
<br>
You can see from here:<br>
<a href="http://www.vtk.org/doc/nightly/html/vtkCellType_8h_source.html" target="_blank">http://www.vtk.org/doc/nightly/html/vtkCellType_8h_source.html</a><br>
<br>
that "3" means VTK_LINE, which makes sense, because you added lines to<br>
the polydata. The vtkTriangleFilter doesn't sound like it triangulates<br>
the area inside the contour, but rather only divides existing polygons<br>
into triangles:<br>
<a href="http://www.vtk.org/doc/nightly/html/classvtkTriangleFilter.html#details" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkTriangleFilter.html#details</a><br>
<br>
So what you have to do instead is make a polygon from your points,<br>
then it seems to work:<br>
<br>
#include <vtkSmartPointer.h><br>
#include <vtkPolygon.h><br>
<div class="im">#include <vtkPolyData.h><br>
#include <vtkCellArray.h><br>
#include <vtkPoints.h><br>
#include <vtkMath.h><br>
</div>#include <vtkTriangleFilter.h><br>
#include <vtkMassProperties.h><br>
<br>
int main()<br>
{<br>
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();<br>
<div class="im"> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();<br>
</div> vtkSmartPointer<vtkCellArray> cellArray =<br>
vtkSmartPointer<vtkCellArray>::New();<br>
<br>
const unsigned int numberOfPoints = 21;<br>
// Create the polygon<br>
vtkSmartPointer<vtkPolygon> polygon =<br>
vtkSmartPointer<vtkPolygon>::New();<br>
polygon->GetPointIds()->SetNumberOfIds(numberOfPoints);<br>
<br>
vtkIdType* lineIndices = new vtkIdType[numberOfPoints];<br>
for (int i = 0; i < numberOfPoints; i++)<br>
{<br>
polygon->GetPointIds()->SetId(i, i);<br>
<br>
const double angle =<br>
2.0*vtkMath::Pi()*i/static_cast<double>(numberOfPoints);<br>
<div class="im"> points->InsertPoint(static_cast<vtkIdType>(i), 0.1*cos(angle),<br>
0.1*sin(angle), 0.0 );<br>
lineIndices[i] = static_cast<vtkIdType>(i);<br>
}<br>
<br>
</div> cellArray->InsertNextCell(polygon);<br>
polydata->SetPoints(points);<br>
polydata->SetPolys(cellArray);<br>
<div class="im"><br>
vtkSmartPointer< vtkTriangleFilter > triangles =<br>
vtkSmartPointer< vtkTriangleFilter >::New();<br>
</div> triangles->SetInputData(polydata);<br>
triangles->Update();<br>
<div class="im"><br>
vtkSmartPointer< vtkMassProperties > massProp =<br>
vtkSmartPointer< vtkMassProperties >::New();<br>
</div> massProp->SetInputConnection(triangles->GetOutputPort());<br>
massProp->Update();<br>
double area = massProp->GetSurfaceArea();<br>
<br>
std::cout << area;<br>
<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
David<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><b><font face="'comic sans ms', sans-serif" color="#000066">Rodrigo aka WarHearT</font></b><br>
</div>