You can visualize and compare the mesh quality of different shapes in a Jupyter notebook using the JupyterRenderer. By adjusting the quality parameter in DisplayShape, you can control the density of the mesh.
When creating multiple shapes from a single base shape (e.g., using translate_shp), ensure you set copy=True to prevent all shapes from sharing the same underlying mesh data, which would make independent quality adjustments impossible.
To control how normals are rendered:
- Use
NORMAL.CLIENT_SIDE to see individual faces clearly (useful for inspecting mesh density). - Use
NORMAL.SERVER_SIDE for smooth rendering (vertex normals).
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.Core.gp import gp_Vec
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer, NORMAL
from OCC.Extend.ShapeFactory import translate_shp
# Create base shape
torus_shp1 = BRepPrimAPI_MakeTorus(20, 5).Shape()
# Create copies with different translations to allow independent mesh quality
torus_shp2 = translate_shp(torus_shp1, gp_Vec(60, 0, 0), copy=True)
torus_shp3 = translate_shp(torus_shp1, gp_Vec(-60, 0, 0), copy=True)
# Initialize renderer with CLIENT_SIDE normals to inspect faces
my_renderer = JupyterRenderer(compute_normals_mode=NORMAL.CLIENT_SIDE)
# Display shapes with varying mesh quality levels
my_renderer.DisplayShape(torus_shp1, shape_color="blue", topo_level="Face", quality=1.0)
my_renderer.DisplayShape(torus_shp2, shape_color="red", quality=4.0) # Lower quality
my_renderer.DisplayShape(torus_shp3, shape_color="green", quality=0.5) # Higher quality
my_renderer.Display()