[vtkusers] PolyDataExtractNormals example doers not work as expected with cell normals

David Doria daviddoria at gmail.com
Fri Aug 12 11:04:39 EDT 2011


On Thu, Aug 11, 2011 at 6:57 PM, Alex Malyushytskyy
<alexmalvtk at gmail.com> wrote:
> I needed to extract cell normals generated by vtkPolyDataNormals
> and tried to use code from
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataExtractNormals
> on two versions of vtk (5.4.2 and  5.6.1)
>
> On both cell normals were not working as expected from example.
>
> First of all vtkPolyDataNormals generates vtkFloatArray instead of
> vtkDoubleArray as an example,
> second name of cell array is "Normals" and not "cellNormals"
>
> I suggest to change example
>
> from:
>  ///////////////////////////////////////////////////////////////////////////////////
>  // Double cell normals
>  vtkSmartPointer<vtkDoubleArray> normalData4 =
>    vtkDoubleArray::SafeDownCast(polydata->GetCellData()->GetNormals("cellNormals"));
>
>  if(normalData4)
>    {
>    std::cout << "There are " << normalData4->GetNumberOfComponents()
>              << " components in NormalData4 (double Cell \"Cell
> Normals\")" << std::endl;
>    return true;
>    }
>
>
> to:
>  ///////////////////////////////////////////////////////////////////////////////////
>  // Float cell normals
>
>  vtkSmartPointer<vtkFloatArray > normalData4 =
>    vtkDoubleArray::SafeDownCast(polydata->GetCellData()->GetNormals("Normals"));
>
>  if(normalData4)
>    {
>    std::cout << "There are " << normalData4->GetNumberOfComponents()
>              << " components in NormalData4 (float Cell \"Cell
> Normals\")" << std::endl;
>    return true;
>    }
>
>
> Regards,
>  Alex

Alex,

I understand your confusion. The multiple ways normals can be stored
is indeed very confusing, and this is exactly what this example was
made to demonstrate. I have made some changes:

http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataExtractNormals

Basically there are 4 ways the normals could be stored (for both
pointData and cellData). You should not assume anything about how
someone has stored the normals, and check all of them. In two of the
methods, you also don't know for sure the name of the array!

Methods (1 and 2 would be preferred):

1) As floats, marked as normals explicitly (GetNormals())
2) As doubles, marked as normals explicitly (GetNormals())
3) As floats, as a regular array (here you'd need to know the name -
GetArray("name"))
4) As doubles, as a regular array (here you'd need to know the name -
GetArray("name"))

Does the updated example clear anything up?

David



More information about the vtkusers mailing list