[vtkusers] Odd vtk normals calculation behavior

Tarcísio Fischer tarcisio.fischer.cco at gmail.com
Thu Mar 26 00:19:19 EDT 2015


I think I found my mistake.

tl;dr: Avoid passing vtkPolyhedrons polydatas directly to algorithms. Copy
the data before instead.


The problem was in this part of the code:


   1. cell = unstructured_grid.GetCell(0)
   2. normals = vtk.vtkPolyDataNormals()
   3. normals.SetInputData(cell.GetPolyData())


The cell variable here is not a vtkCell, but a vtkPolyhedron. The problem
is that by doing this downcast it loses information when trying to copy the
vtkPolyData with a DeepCopy(polys) (this is done inside the normals
algorithm), I think this is because by construction all vtkPolyhedron uses
the first element of the ID as the number of elements to come, and the last
element has not been correctly allocated.

It is easy to reproduce the DeepCopy bug. But lesson learned: Never get the
PolyData directly from an vtkPolyhedron.

2015-03-05 18:20 GMT-03:00 Tarcísio Fischer <tarcisio.fischer.cco at gmail.com>
:

> Hello.
>
> I'm trying to get the normals of my 3D cube (a VTK_POLYHEDRON cell) with
> vtk6.1 in python.
> I know that there is many questions about the normals orientation, but
> this is not the case. The problem is that it seems one of the normals is
> completely wrong, as I will show in my example code.
> To try to keep it simple, I'll separate the code in three parts:
>
> 1- Only the part where I think the problem is:
> http://pastebin.com/2SW5q4n2
>
> 2- The full code so that everyone can run:
> http://pastebin.com/DH3ei1XD
>
> 3- Extended code with some internals exposed (with odd results!):
> (Take a look at Trying to view data internals)
> http://pastebin.com/BYEkhiqc
>
> Can someone help me? What am I missing here?
> Thanks.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150326/34099012/attachment.html>


More information about the vtkusers mailing list