[vtkusers] How to extract area of (triangle) Cells?
David Doria
daviddoria+vtk at gmail.com
Wed Dec 16 19:19:40 EST 2009
On Wed, Dec 16, 2009 at 5:16 PM, <lynx.abraxas at freenet.de> wrote:
> Hello!
>
>
> I'd need to get the area of the cells (triangle) to weight the cell normals
> (as discussed in the thread below).
> My research on this lead me to http://www.cmake.org/Wiki/VTK_Examples where it
> says that CellData needs an associated data (eg. area of triangle). Would that
> be GetCellData().GetScalars()? Or would I need to apply a filter first that
> actually calculates the cell area or would I have to do that my self?
> I also found this example:
> http://www.cmake.org/Wiki/Add_Miscellaneous_Data_to_Cells_in_a_Polydata
> but the area there seems to me very arbritrary;-)
>
> Thanks for any help or hints.
> Lynx
I think you want something like this:
for(unsigned int i = 0; i < polydata->GetNumberOfCells(); i++)
{
vtkCell* triangle = polydata->GetCell(0);
cout << "tri: " << *triangle << endl;
//vtkTriangle* triangle = dynamic_cast<vtkTriangle*>(cell);
double area =
vtkTriangle::TriangleArea(triangle->GetPoints()->GetPoint(0),
triangle->GetPoints()->GetPoint(1),
triangle->GetPoints()->GetPoint(2));
cout << "area of triangle " << i << ": " << area << endl;
}
I tried it quickly and it says the area of the demo triangles I made
was 0, so there is something wrong, but it may help you get started.
I'll play with it more later tonight if you don't get it by then.
Does anyone know if there is a more direct way like
triangle->ComputeArea(), or if not, can we add one?
Thanks,
David
More information about the vtkusers
mailing list