[vtkusers] How to extract area of (triangle) Cells?

Bill Lorensen bill.lorensen at gmail.com
Wed Dec 16 19:58:33 EST 2009


It's 4 lines of code:
triangle->GetPoints()->GetPoint(0, p0);
triangle->GetPoints()->GetPoint(1, p1);
triangle->GetPoints()->GetPoint(2, p2);
double area = vtkTriangle::TriangleArea(p0, p1, p2);


On Wed, Dec 16, 2009 at 7:32 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> On Wed, Dec 16, 2009 at 7:19 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
>> 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
>>
>
> There is something wrong with the GetPoint() function that returns a
> pointer (or at least my understanding of how it works).
>
> It works when you do it like this:
> http://www.cmake.org/Wiki/VTK/Examples/Triangle_Area
>
> Let me know if this is what you were trying to do. If there is not a
> cleaner way to do this, there definitely should be. I couldn't imagine
> trying to teach a new user how to use VTK and them asking me something
> as simple as finding the area of a triangle and it is 50 lines of code
> to demonstrate.
>
> Thanks,
>
> David
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list