# vtkGeometryFilter problem

**URL:** https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037
**Category:** Support
**Created:** [January 20, 2021, 1:26pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037 "2021-01-20T13:26:41Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [January 20, 2021, 1:26pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/1 "2021-01-20T13:26:41Z")

</div>

I don’t understand the behavior of `vtkGeometryFilter` in the case of a hexahedron - I would expect it to extract 6 faces and I get zero:

```python
import vtk

reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName('a.vtu')
# a.vtu has:
# pts= [[1., 0., 0.], #0
# [0., 0., 0.], #1
# [0., 1., 0.], #2
# [1., 1., 0.], #3
# [0., 0., 1.], #4
# [1., 0., 1.], #5
# [0., 1., 1.], #6
# [1., 1., 1.], #7
# ]
# connectivity = [[1, 4, 6, 2, 0, 5, 7, 3]]
reader.Update()
ug = reader.GetOutput()
print('ug ', ug.GetNumberOfPoints(), ug.GetNumberOfCells())

gf = vtk.vtkGeometryFilter()
gf.SetInputData(ug)
gf.Update()
out = gf.GetOutput()
print('out', out.GetNumberOfPoints(), out.GetNumberOfCells())

```

yields:

```auto
ug 8 1
out 8 0

```

[a.zip](https://discourse.vtk.org/uploads/short-url/8GNDT5JMRjVbbhM9E01rgqYlNcN.zip) (449 Bytes)  
the file visualizes correctly in paraview:  
 ![Screenshot from 2021-01-20 14-11-18](https://discourse.vtk.org/uploads/default/original/2X/9/92c23ac52e587cdfb81d00611007cf42cc75edc5.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [January 20, 2021, 3:17pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/2 "2021-01-20T15:17:34Z")

</div>

Probably the order of points in the cell is incorrect (e.g., the cell is turned inside out or invalid in some other way). This works well:

```python
numberOfVertices = 8
points = vtk.vtkPoints()
points.InsertNextPoint(0.0, 0.0, 0.0)
points.InsertNextPoint(1.0, 0.0, 0.0)
points.InsertNextPoint(1.0, 1.0, 0.0)
points.InsertNextPoint(0.0, 1.0, 0.0)
points.InsertNextPoint(0.0, 0.0, 1.0)
points.InsertNextPoint(1.0, 0.0, 1.0)
points.InsertNextPoint(1.0, 1.0, 1.0)
points.InsertNextPoint(0.0, 1.0, 1.0)

hex = vtk.vtkHexahedron()
for i in range(numberOfVertices):
    hex.GetPointIds().SetId(i, i)

ug = vtk.vtkUnstructuredGrid()
ug.SetPoints(points);
ug.InsertNextCell(hex.GetCellType(), hex.GetPointIds())

print('ug ', ug.GetNumberOfPoints(), ug.GetNumberOfCells())

gf = vtk.vtkGeometryFilter()
gf.SetInputData(ug)
gf.Update()
out = gf.GetOutput()
print('out', out.GetNumberOfPoints(), out.GetNumberOfCells())

```

output:

```auto
ug 8 1
out 8 6

```

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [January 20, 2021, 4:32pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/3 "2021-01-20T16:32:41Z")

</div>

Thanks Andras,  
you’re right (as usual :)) in saying that the order was not correct… in my case order is:  
 ![](https://discourse.vtk.org/uploads/default/original/2X/1/1c1bc06fad18e2e3319b725a9e7ca4d0887b25f0.png)

while in yours script:  
 ![](https://discourse.vtk.org/uploads/default/original/2X/7/750756abc8a4f6ca4fa5088bcce6f119c9cd7fbb.png)  
…and the `vtkGeometryFIlter` operates just fine.

It’s funny though that paraview can handle the incorrect one too (?), also other filters like `vtkDataSetTriangleFilter` seem not to care…

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 20, 2021, 5:50pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/4 "2021-01-20T17:50:24Z")

</div>

vtkDataSetTriangleFilter simply inserts faces into a hash table and counts uses of the faces. This is strictly not speaking consistent with the topology of the cell/dataset hence the different results.

Also, vtkDataSetTriangleFilter is now slower than vtkGeometryFilter (especially when building VTK threaded) and uses much more memory. At some point PV will switch to using vtkGeometryFilter - this switch is harder than it might seem because vtkDataSetTriangleFilter produces different/incorrect output in some situations. However, vtkDataSetSurfaceFilter handles certain types of higher order cells (e.g., Bezier) while vtkGeometryFilter currently does not.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [January 20, 2021, 6:21pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/5 "2021-01-20T18:21:15Z")

</div>

Hello,

Here’s a C++ comment if you wish to keep the order documented:

```cpp
/**
 * The ids of the vertexes forming the geometry of a cell.
 *
 * Vertex id elements in the vId[8] array forming the geometry of a cell:
 *
 * J
 * |
 * |
 *
 * 3-----------2 face 0 = 0 1 2 3
 * /| /| face 1 = 4 7 6 5
 * / | / | face 2 = 0 3 7 4
 * / | / | face 3 = 1 5 6 2
 * 7--------- 6 | face 4 = 0 4 5 1
 * | | | | face 5 = 3 2 6 7
 * | 0----|------1 --- I
 * | / | /
 * | / | /
 * |/ | /
 * 4--------- 5
 *
 * /
 * /
 * K
 *
 *
 *
 */

```

cheers,

Paulo

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 20, 2021, 10:33pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/6 "2021-01-20T22:33:07Z")

</div>

Here is an example that uses `vtkUnstructuredGrid` for eight different cell types, once again the point order is critical: [Cell3DDemonstration](https://kitware.github.io/vtk-examples/site/Python/GeometricObjects/Cell3DDemonstration/)

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [January 20, 2021, 10:57pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/7 "2021-01-20T22:57:12Z")

</div>

Thanks! Maybe paraview picks first the connectivity and then uses it to insert the points (?) so that it still manages to define cell the orientation…

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 20, 2021, 11:36pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/8 "2021-01-20T23:36:25Z")

</div>

It is always better to specify the points in the correct order, as Will pointed out:

> [@will.schroeder](#):
>
> vtkDataSetTriangleFilter simply inserts faces into a hash table and counts uses of the faces. This is strictly not speaking consistent with the topology of the cell/dataset hence the different results.

That example also provides the correct orientation for a variety of shapes which may also be useful.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 21, 2021, 11:34am UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/9 "2021-01-21T11:34:33Z")

</div>

Andrew, this is a good resource for VTK file formats:  
[https://lorensen.github.io/VTKExamples/site/VTKFileFormats/](https://lorensen.github.io/VTKExamples/site/VTKFileFormats/)

Remind us again, is this now incorporated into the VTK Examples work that you just completed?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [January 21, 2021, 1:15pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/10 "2021-01-21T13:15:25Z")

</div>

Paraview is a end-user software, so it likely does a preprocessing to ensure “clockwiseness” of faces, etc.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 21, 2021, 6:56pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/11 "2021-01-21T18:56:14Z")

</div>

Sure is, see: [https://kitware.github.io/vtk-examples/site/VTKFileFormats/](https://kitware.github.io/vtk-examples/site/VTKFileFormats/) everything from that site is in the new site.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 25, 2021, 12:34pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/12 "2021-01-25T12:34:22Z")

</div>

I’m wondering if we should place some links from the documentation in the C++ header files pointing to the examples (including examples-related resources like VTK file formats). I’m a little leery about adding this kind of dependency, but with VTK examples now in great shape, maybe it’s time to think about doing so. Comments?

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 25, 2021, 9:24pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/13 "2021-01-25T21:24:52Z")

</div>

In the VTK Examples I have a script which runs for each language producing a list of vtk classes and the examples, see: [Cxx classes with examples](https://kitware.github.io/vtk-examples/site/Cxx/Coverage/CxxVTKClassesUsed/) and [Python classes with examples](https://kitware.github.io/vtk-examples/site/Python/Coverage/PythonVTKClassesUsed/) for example.

This is the script: [VTKClassesUsedInExamples.py](https://gitlab.kitware.com/vtk/vtk-examples/-/blob/master/src/Admin/VTKClassesUsedInExamples.py), it currently produces markdown files and is run automatically when the VTK examples site is updated.

My initial thought would be to rewrite this (using pandas) to produce a JSON file that would live in [https://github.com/Kitware/vtk-examples/tree/gh-pages/src](https://github.com/Kitware/vtk-examples/tree/gh-pages/src) that the VTK documentation process could read.

What do you think @ben.boeckel @sankhesh? Would it be easy to parse this JSON file to produce a list of relevant VTK Examples for each VTK class? It would be a largish file as it would contain the links to the vtk class and the vtk examples classes. Of course some cells will be empty.

---

<div class="post-metadata">

### Author: ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)
#### Post date: [January 26, 2021, 2:10pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/14 "2021-01-26T14:10:29Z")

</div>

@amaclean The cross-reference between the doxygen documentation and vtk-examples would be a great addition. Currently, the perl script [doc\_class2example.pl](https://gitlab.kitware.com/vtk/vtk/-/blob/beae1994feab4090157c5b470b9bda76a5b3e645/Utilities/Doxygen/doc_class2example.pl) does the cross-referencing between in-source examples and classes in doxygen documentation. We could modify it to include parsing of this new JSON file as well. I am not adept at perl and if required, we can make it a python script.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 26, 2021, 2:41pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/15 "2021-01-26T14:41:04Z")

</div>

+1 python script

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 27, 2021, 12:46am UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/16 "2021-01-27T00:46:40Z")

</div>

@will.schroeder, @sankhesh, @ben.boeckel if we can get rid of Perl great.

Ok here is a json file [vtk\_vtk-examples\_xref.zip](https://discourse.vtk.org/uploads/short-url/egeGXMaHjuSYDxlVuq7qtLu6Bp3.zip) (118.0 KB) containing the VTK class and corresponding example by language. Just unzip it and you can play around with it using [xref.py](https://discourse.vtk.org/uploads/short-url/5zXZ52iKAHsVR4Z4rVyDNV4AEMr.py) (1021 Bytes). If you think it is acceptable and easy to use from the VTK end, I’ll commit it.

Data layout:

- Columns are the VTK classes.
- Indexes are the languages: `CSharp`, `Cxx`, `Java`, `Python`; for these rows, each cell contains the comma separated list of relevant examples or None.  
The index `VTKLink` contains the relevant link to the VTK class description.

In each cell the links are in the usual markdown format:

- [AffineWidget](https://kitware.github.io/vtk-examples/site/Cxx/Widgets/AffineWidget)
- [vtkAppendPolyData](https://vtk.org/doc/nightly/html/classvtkAppendPolyData.html#details)

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 29, 2021, 6:39am UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/17 "2021-01-29T06:39:04Z")

</div>

Been thinking about this, a better json file is this [vtk\_vtk-examples\_xref.zip](https://discourse.vtk.org/uploads/short-url/8bHbMkQBJWDOMBuhx2fLrsrZ9OB.zip) (225.2 KB) the data layout is the same as above however the markdown has been replaced by (key, value) pairs and all classes used in the examples are included now so the file is a bit larger. The markdown format is easily created, namely `[key](value)`.

This layout makes it easier to get statistics from the file like this:

```nohighlight
Number of classes with examples 868
Number of classes with examples by language:
CSharp 188
Cxx 860
Java 264
Python 403
Largest number of examples by language and class
CSharp Cxx Java Python                       
vtkRenderWindow 102 vtkNew 985 vtkRenderWindowInteractor 183 vtkNamedColors 316
vtkRenderer 101 vtkRenderWindow 854 vtkRenderer 177 vtkRenderer 303
vtkActor 83 vtkRenderer 850 vtkRenderWindow 177 vtkRenderWindowInteractor 302
vtkPolyDataMapper 72 vtkNamedColors 843 vtkNamedColors 164 vtkRenderWindow 295
vtkPolyData 35 vtkRenderWindowInteractor 842 vtkActor 157 vtkActor 280
vtkSphereSource 31 vtkActor 682 vtkPolyDataMapper 140 vtkPolyDataMapper 239
vtkPoints 29 vtkProperty 643 vtkSphereSource 76 vtkSphereSource 83
vtkCellArray 18 vtkPolyDataMapper 580 vtkPoints 35 vtkPoints 76
vtkDataSetMapper 14 vtkPolyData 471 vtkPolyData 33 vtkPolyData 62
vtkImageViewer2 11 vtkCamera 408 vtkDataSetMapper 18 vtkDataSetMapper 59

```

---

<div class="post-metadata">

### Author: ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)
#### Post date: [January 29, 2021, 4:10pm UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/18 "2021-01-29T16:10:29Z")

</div>

@amaclean The json file looks good. I’ll take a first stab at doxygen integration next week.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [January 30, 2021, 5:04am UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/19 "2021-01-30T05:04:55Z")

</div>

@sankesh The JSON file is now on the web: [vtk\_vtk-examples\_xref.json](https://github.com/Kitware/vtk-examples/tree/gh-pages/src/Coverage/vtk_vtk-examples_xref.json). This will be automatically updated whenever the vtk-examples web pages are updated.

This program [xref.py](https://discourse.vtk.org/uploads/short-url/6ppV5hDn7cl7d0vlXLdrmUK1c8v.py) (4.3 KB), when run with no parameters will automatically download the file from the web. It will produce the statistics as above. I hope you will find it useful both as a check of the file and it also how to download the url. It is a bit kludgy but it works!

When thinking about the examples and given that some classes (e.g. `VTKNew`) have over 900 examples, it is essential to limit the examples to say just five or less for each language. It might be nice to randomly select five examples when there are more than five for a given class. Thus the examples will change whenever the documentation is updated. What do you and others think?

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [February 1, 2021, 3:33am UTC](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037/20 "2021-02-01T03:33:55Z")

</div>

@sankesh Here is an update to [xref.py](https://discourse.vtk.org/uploads/short-url/80r2J9PiUCk38WrbSY08H14yrAg.py) (5.9 KB) , I have added a function to randomly select five examples for a given VTK class and language see:

```python
def ramdom_sample(d, vtk_class, lang, num=5):
    """
    For the given keys provide a random sample of examples.

    :param d: The dictionary.
    :param vtk_class: The VTK Class e.g. vtkActor.
    :param lang: The language, e.g. Cxx.
    :param num: The number of values.
    :return: A markdown formatted list of examples or None.
    """

```

Actually this JSON file is really useful (to me at least), so I will put a Python script into `vtk_examples` for users to query on VTK Class and language.

[Next page](https://discourse.vtk.org/t/vtkgeometryfilter-problem/5037.md?page=2)
