# Normal problem with vtk Boolean Operation PolyData Filter

**URL:** <https://discourse.vtk.org/t/normal-problem-with-vtk-boolean-operation-polydata-filter/8634>\
**Category:** Development\
**Created:** [May 31, 2022, 12:37am UTC](https://discourse.vtk.org/t/normal-problem-with-vtk-boolean-operation-polydata-filter/8634 "2022-05-31T00:37:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)\
**Post date:** [May 31, 2022, 12:37am UTC](https://discourse.vtk.org/t/normal-problem-with-vtk-boolean-operation-polydata-filter/8634/1 "2022-05-31T00:37:43Z")

</div>

Apologies up front for this being rather long and possibly somewhat difficult to understand.

I hope that someone can suggest a course of action for this.

I’ve been trying to model and render various geometric bodies with boolean operations using vtkBooleanOperationPolyDataFilter and have run into a problem with the normals not being right in the final object.

I have 2 objects, a sphere that is built using vtkSphereSource and a cube using a modification that I made to vtkCubeSource. When rendered individually, everything appears fine, but when I use vtkBooleanOperationPolyDataFilter and take a bite out of the cube with the sphere, a good number of the normals aren’t right as can be seen in the picture.

 ![bad_normals_on_cube](https://discourse.vtk.org/uploads/default/original/2X/b/bf22c1c2ea4fb335b4e75bac9d00121ce18c36ba.png)

The black indicates where the normals aren’t correct. My opinion is that the system didn’t copy them over correctly from the original bodies. When one looks at just the mesh, it appears correct.

Because vtkBooleanOperationPolyDataFilter is based upon the work at  
[https://www.vtkjournal.org/browse/publication/797](https://www.vtkjournal.org/browse/publication/797)  
and this article discusses the steps that are needed under the hood, I decided to look at the individual steps to see what was causing the problem. The following code is what generated the picture above.

[Cube2.cxx](https://discourse.vtk.org/uploads/short-url/g22M4qa97sfPvMG2bKGfP6vOUPe.cxx) (2.6 KB)

In the several steps (filters) that the journal paper discusses in building the vtkBooleanOperationPolyDataFilter, it appears that with the vtkIntersectionPolyDataFilter the normals aren’t being handled correctly. From the code listing one can see that I needed the step with vtkDistancePolyDataFilter in order to setup the mapper, but vtkIntersectionPolyDataFilter appears to be responsible for the heavy lifting for the triangle intersections, etc. and processing of the polydata.

It appears to me that vtkIntersectionPolyDataFilter isn’t re-calculating the normals, but I suspect that because there is so much inheritance going on that something up the chain is responsible for handling the normals in the new body. I not sure how to debug this to find the culprit.

I’m hoping that someone with more experience with these routines and the inheritance can shed some light on this. Its possible that one of the inherited routines is messing up (and I don’t know which) or I need to somehow further process what I have. But, I had expected vtkBooleanOperationPolyDataFilter to handle this correctly without an further manipulation needed on my part.

Am open to suggestions as to what to try next.

BK

---

<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:** [June 1, 2022, 7:11am UTC](https://discourse.vtk.org/t/normal-problem-with-vtk-boolean-operation-polydata-filter/8634/2 "2022-06-01T07:11:35Z")

</div>

Maybe you need to apply `vtkPolyDataNormals` to the output from your `sssSuperCubeSource`. Check some of the online examples in the documentation for `vtkPolyDataNormals` for its usage.

---

<div class="post-metadata">

**Author:** ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)\
**Post date:** [June 2, 2022, 12:39am UTC](https://discourse.vtk.org/t/normal-problem-with-vtk-boolean-operation-polydata-filter/8634/3 "2022-06-02T00:39:29Z")

</div>

Hi Andrew,

Your suggestion worked, but not on the direct output from the cube. In the source file (Cube2.cxx), this is what I added / changed:

**vtkNew\<vtkPolyDataNormals\> normals1;**  
**normals1-\>SetInputConnection(distance-\>GetOutputPort( 0 ));**

**mapper-\>SetInputConnection(normals1-\>GetOutputPort( ));**

The normals were okay before the vtkIntersectionPolyDataFilter worked its magic. Sending the cube’s output channel from vtkIntersectionPolyDataFilter to the vtkPolyDataNormals filter was all I needed to do. (Or, at least it appears so.)

Thanks a bunch!

BK

---

<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:** [June 2, 2022, 5:50am UTC](https://discourse.vtk.org/t/normal-problem-with-vtk-boolean-operation-polydata-filter/8634/4 "2022-06-02T05:50:19Z")

</div>

Glad to see it worked for you.

---

<div class="post-metadata">

**Author:** ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)\
**Post date:** [June 2, 2022, 9:46pm UTC](https://discourse.vtk.org/t/normal-problem-with-vtk-boolean-operation-polydata-filter/8634/5 "2022-06-02T21:46:09Z")

</div>

I want to clarify one point on this for anyone who runs across this item in the future.

The code I posted went to all of the trouble to dissect vtkBooleanOperationPolyDataFilter (based on the paper cited) so that I could see (more or less) where the problem was occurring. As I found out, one can take the output from vtkBooleanOperationPolyDataFilter and run it through the vtkPolyDataNormals filter and solve the problem. I’m glad to see that worked.
