Faces not triangulated for a simple part

sazuko

Looking around for some CAD
I am working in python, however, it should be consistent with C++ as well, using Incremental mesh, i am unable to get triangulation for the cones as shown in the picture, however, two of these are triangulated. Would appreciate if someone could point me in right direction, apparently, shape healing doesn't seem to fix it. I think something is odd with these faces as reexporting file from another cad software fixes it, but i am unable to figure it out
 

Attachments

  • part.step
    60.5 KB · Views: 4
  • Screenshot from 2024-01-17 19-11-02.png
    Screenshot from 2024-01-17 19-11-02.png
    35.7 KB · Views: 2

Quaoar

Administrator
Staff member
This shape looks fine; there's nothing to fix in it after import. What are you trying to do with it?

1705512506131.png
 

sazuko

Looking around for some CAD
do you do some preprocessing in Analysis Situs, apparently if you import it through pyocc and compute triangulation the cones as shown in the picture don’t get triangulated
 

Quaoar

Administrator
Staff member
You just call BRepMesh_IncrementalMesh on the entire shape with properly defined linear and angular deflections. The linear deflection is normally computed based on the dimensions of a part. E.g., your shape was triangulated with 0.0533512 as a linear deflection and 0.5 as an angular one. Which values do you use? Do you mesh the entire shape and not faces individually (which would be strange)?
 

sazuko

Looking around for some CAD
i plugged in same values to verify, it still shows those cones as untriangulated and yeah i am doing it on entire shape
BRepMesh_IncrementalMesh(
shape,
0.0533512,
False,
0.5,
True
)
 

Quaoar

Administrator
Staff member
Do you mind sharing the complete script? Although I'm a noob in Python, I can still try to reproduce your issue.
 

sazuko

Looking around for some CAD
The whole code is too long, but this is what the issue gets reduced to


from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.TopLoc import TopLoc_Location
from OCC.Core.TopoDS import topods_Face
from OCC.Core.BRep import BRep_Tool
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_FACE
from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_FACE

# Function to read a shape from a STEP file
def read_step_file(filename):
step_reader = STEPControl_Reader()
status = step_reader.ReadFile(filename)
if status == 1:
step_reader.TransferRoot()
shape = step_reader.OneShape()
return shape
else:
print("Error: Unable to read the STEP file.")
return None

# Replace 'your_step_file.step' with the path to your STEP file
shape = read_step_file('your_step_file.step')

if shape is not None:
# Apply meshing
BRepMesh_IncrementalMesh(
shape,
0.0533512,
False,
0.5,
True
)

a_location = TopLoc_Location()

# Check triangulation of faces
for current_item in TopExp_Explorer(shape, TopAbs_FACE):
face = topods_Face(current_item.Current())
myTriangulation = BRep_Tool.Triangulation(face, a_location)
if myTriangulation is None:
print("This is the problematic face, not being triangulated")
else:
print("Failed to load shape from STEP file.")
 

Quaoar

Administrator
Staff member
I made a little mix of your code with snippets from here: https://analysissitus.org/forum/index.php?threads/pythonocc-getting-started-guide.19/

Code:
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.TopLoc import TopLoc_Location
from OCC.Core.TopoDS import topods_Face
from OCC.Core.BRep import BRep_Tool
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_FACE
from OCC.Core.STEPControl import STEPControl_Reader
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_FACE
from OCC.Display.SimpleGui import init_display

# Function to read a shape from a STEP file
def read_step_file(filename):
    step_reader = STEPControl_Reader()
    status = step_reader.ReadFile(filename)
    if status == 1:
        step_reader.TransferRoot()
        shape = step_reader.OneShape()
    return shape

# Replace 'your_step_file.step' with the path to your STEP file
shape = read_step_file('C:/Users/serge/Desktop/part.step')

display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(shape, update=True)
start_display()

Here's what I get:

1705525901600.png

It was not necessary to mesh the shape explicitly as it was done on display.
 

sazuko

Looking around for some CAD
I ran exact same code on my linux machine and those cones appear to be not rendering (not triangulated), i wonder if its linux vs windows difference

Screenshot from 2024-01-18 02-25-38.png
 

sazuko

Looking around for some CAD
i think its the pyocc/occt version i am using 7.7.2, will move back to 7.6.2 to check if the problem is still there
 

sazuko

Looking around for some CAD
Nope 7.6.2 doesn't seem to work, can you share your environment details i.e pyocc version and python version, its odd that it behaves differently on my machine
 

sazuko

Looking around for some CAD
Ok it seems to work with 7.5.1, not sure whats up with other versions
One more thing, re-exporting the file from onshape fixes the issue in other versions as well.
 

Quaoar

Administrator
Staff member
1705560927546.png
Yep, 7.5.1 here. Not sure what's going on either. It might make sense to contact their devs on that matter maybe?
 
Top