[vtkusers] How to extract the average normal from vtkPolyDataNormals ?

Yaroslav Tenzer krakadil.gena at gmail.com
Wed Sep 24 09:32:15 EDT 2008


Hello Vtk Users,

I have seen a post by Amy in 2005 on how to access the normals of each
polygon ... but vtkPolyDataNormals calculates the average normal for all
normals as well ... how do I extract the averaged one from the filter ?

Is there any way to show the normals on the screen ?

I have four polygons ... and I want to find the average normal for them ...
and show it on the screen ... and I do not want to reinvent the wheel :)

thank you,
yaroslav
[vtkusers] How should I get the right normal of a polygon defined in
vtkCellArray?*Amy Squillacote* amy.squillacote at kitware.com
<vtkusers%40vtk.org?Subject=%5Bvtkusers%5D%20How%20should%20I%20get%20the%20right%20normal%20of%20a%20polygon%0A%09defined%20in%20vtkCellArray%3F&In-Reply-To=BAY109-F32A78622FBED72BAF2794BB88C0%40phx.gbl>
*Thu Sep 29 08:59:36 EDT 2005*


   - Previous message: [vtkusers] How should I get the right normal of a
   polygon defined in vtkCellArray?
   <http://www.vtk.org/pipermail/vtkusers/2005-September/081956.html>
   - Next message: [vtkusers] Is it a VTK bug of vtkDelaunay2D ?
   <http://www.vtk.org/pipermail/vtkusers/2005-September/081958.html>
   - *Messages sorted by:* [ date
]<http://www.vtk.org/pipermail/vtkusers/2005-September/date.html#81957>
[
   thread ]<http://www.vtk.org/pipermail/vtkusers/2005-September/thread.html#81957>
[
   subject ]<http://www.vtk.org/pipermail/vtkusers/2005-September/subject.html#81957>
[
   author ]<http://www.vtk.org/pipermail/vtkusers/2005-September/author.html#81957>

------------------------------

The normals created by this filter are in a float array in CellData,
not in a vtkCellArray (which only provides information about how
points are connected to form each cell). To apply the filter to your
data and then access the normal of each polygon, do the following.

vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
normals->SetInput(yourData);
normals->ComputeCellNormalsOn();
normals->ComputePointNormalsOff();
normals->Update();

vtkFloatArray *normArray =
vtkFloatArray::SafeDownCast(normals->GetOutput()->GetCellData()->GetNormals());
int i;

float point[3];
for (i = 0; i < normArray->GetNumberOfTuples(); i++)
{
     point[0] = normArray->GetValue(i, 0);  // x-component of normal
     point[1] = normArray->GetValue(i, 1);  // y-component of normal
     point[2] = normArray->GetValue(i, 2);  // z-component of normal

// Do whatever you need to do to write this value to a file here.
}

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


More information about the vtkusers mailing list