Displaying Poly_Triangulations


I'm trying to display a Poly_Triangulation (extracted from an STL-file using the RWSTL-module). I've currently found 2 ways that work but for each solution I'm facing a (different) problem. Note that I'm using the pythonocc wrapper, but the steps should be the same.

Using AIS_Triangulation:
ais_shape = AIS_Triangulation(polyTriangulation)

Setting the color won't work (figure 1):

Using AIS_Shape:
shape = TopoDS_Face()
CompoundBuilder = BRep_Builder()
CompoundBuilder.MakeFace(shape, polyTriangulation)

ais_shape = AIS_Shape(shape)

The color is darker at places with more triangles (figure 2).

The visualization result from method 1 (figure 1) is perfect, only the color should be changed (instead of the standard brown one). The color of method 2 is fine (figure 2), but the visualization result is not optimal. Any ideas? One solution will suffice.

Kind Regards,

Kirill Gavrilov's picture

STL is very simple file format that doesn't preserve topological information of original mesh. By default RWStl would merge all nodes having the same coordinates in input STL mesh. But for proper visualization, nodes on surface boundaries should be split.

RWStl (OCCT 7.6.0) has an option RWStl_Reader::MergeAngle() that could be set to split such nodes by angle criterion.

Alternatively, you might display your mesh without smoothing using Graphic3d_TypeOfShadingModel_PhongFacet shading model. In this case triangles will appear flat-shaded and distinguishable even on smooth surfaces (you wouldn't see that on a box). I guess the result should be similar to what you currently see with AIS_Triangulation.

Thieme Vandeput's picture

Unfortunately, both options are not available in the pythonocc wrapper...

Shouldn't it be able to give a color to AIS_Triangulation, as it is apparently no problem to give it the brown color (which is done by default)?

Kirill Gavrilov's picture

Option for RWStl_Reader has been added to OCCT 7.6.0, but shading models have been available earlier:

#!/usr/bin/env python

import sys,os

from OCC.Display.SimpleGui import init_display
from OCC.Core.AIS import *
from OCC.Core.Aspect import *
from OCC.Core.BRep import *
from OCC.Core.Geom import *
from OCC.Core.gp import *
from OCC.Core.Graphic3d import *
from OCC.Core.Prs3d import *
from OCC.Core.RWStl import *
from OCC.Core.TopoDS import *
from OCC.Core.Quantity import *

from OCC.Display.SimpleGui import init_display

# read STL file
aTris    = rwstl_ReadFile('/occt-7.5.2.git/data/stl/bearing.stl')
aShape   = TopoDS_Face()
aBuilder = BRep_Builder()
aBuilder.MakeFace (aShape, aTris)

# initialize built-in viewer
aDisplay, start_display, add_menu, add_function_to_menu = init_display()

# display shape
aShapePrs = AIS_Shape (aShape)
aShapePrs.SetColor (Quantity_Color (Quantity_NOC_CADETBLUE))
aFillAspect = aShapePrs.Attributes().ShadingAspect().Aspect()
aFillAspect.SetShadingModel (Graphic3d_TypeOfShadingModel.Graphic3d_TOSM_FACET)
aDisplay.Context.Display (aShapePrs, False)

# show viewer
Thieme Vandeput's picture

Amazing, that works perfectly. Thanks a lot!!