Why doesn't cell normal changed after cell points reversed?

Hello,I have a cude.obj which has a cell with reversed normal like this:


# Blender 3.4.1
# www.blender.org
o Cube.001
v 1.000000 1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
s 1
f 1 2 3 4
f 5 4 3 6
f 6 3 2 7
f 7 8 5 6
f 8 5 4 1
f 7 2 1 8

The face with point 8 5 4 1 has reversed normal,and I have a test code like this:

i

mport vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer,
    vtkProperty
)
from vtkmodules.vtkIOGeometry import (
    vtkBYUReader,
    vtkOBJReader,
    vtkSTLReader
)
from vtkmodules.vtkCommonDataModel import (
    # vtkCellArray,
    # vtkCellLocator,
    vtkPolyData,
    vtkIterativeClosestPointTransform,
    # vtkTriangle,
)
from vtkmodules.vtkFiltersCore import (
    vtkPolyDataNormals,
)

def computeCellNormals(polyData):
    normalCompute = vtkPolyDataNormals()
    normalCompute.SetInputData(polyData);
    # compute cell normal
    normalCompute.ComputeCellNormalsOn();
    normalCompute.ComputePointNormalsOn();
    normalCompute.Update();

    polyData.GetCellData().SetNormals(normalCompute.GetOutput().GetCellData().GetNormals());

    return polyData.GetCellData().GetNormals()

def printNormals(normals, normals_2):
    print("Cell Normals ------------------------")
    for i in range(0, normals.GetNumberOfTuples()):
        n = normals.GetTuple(i)
        print("{}th - {} , {} , {}".format(i, n[0], n[1], n[2]))
        n_2 = normals_2.GetTuple(i)
        print("{}th - {} , {} , {}".format(i, n_2[0], n_2[1], n_2[2]))
        print("\n")

def main():
    fileName = "/home/alex/workspace/Geometry-Python/files/cube_with_reversed_normal_full.obj"
    colors = vtkNamedColors()
    
    reader = vtkOBJReader()
    reader.SetFileName(fileName)
    reader.Update()
    data = reader.GetOutput()
    
    originalData=vtkPolyData()
    originalData.DeepCopy(data)

    mapper = vtkPolyDataMapper()
    mapper.SetInputData(data)

    actor = vtkActor()
    actor.SetMapper(mapper)

    normals_1 = computeCellNormals(data)
    
    data.ReverseCell(4);#----------------------------Reversing the 5th cell
    
    normals_2 = computeCellNormals(data)
    printNormals(normals_1, normals_2)
    
    actor.GetProperty().BackfaceCullingOn()

    renderer = vtkRenderer()
    window = vtkRenderWindow()
    window.SetWindowName("Sphere")
    window.AddRenderer(renderer)
    interactor = vtkRenderWindowInteractor()
    interactor.SetRenderWindow(window)

    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d("DarkGreen"))

    window.Render()
    interactor.Start()


if __name__ == '__main__':
    main()

But the cell normals before/after cell reversing have not be changed like this:


Cell Normals ------------------------

0th - 0.0 , 1.0 , 0.0
0th - 0.0 , 1.0 , 0.0

1th - 0.0 , 0.0 , 1.0
1th - 0.0 , 0.0 , 1.0

2th - -1.0 , 0.0 , 0.0
2th - -1.0 , 0.0 , 0.0

3th - 0.0 , -1.0 , 0.0
3th - 0.0 , -1.0 , 0.0

4th - 1.0 , 0.0 , 0.0  // Cell normal before reversing
4th - 1.0 , 0.0 , 0.0// Cell normal after reversing, it should be different from above one,but it isn't 

5th - 0.0 , 0.0 , -1.0
5th - 0.0 , 0.0 , -1.0

Why doesn’t cell normal changed after cell points reversed?

Hello,

Try allowing changes (some performance penalty ensues) in your dataset object:

(...)
data = reader.GetOutput()
data.EditableOn()
(...)

best,
PC

Thanks,tried,but still got same normals

Seems set:

normalCompute.->ConsistencyOff();

It works as expected.