How to Set Different Colors for Local Highlight Elements

Content:

I am working with OCCT in C# and trying to set different colors for edges and faces when using SetHighlightStyle(LocalDynamic). Below is the Prs3d_Drawer setup I am using:

var drawer = new Prs3d_Drawer();
drawer.SetZLayer(-2);
drawer.SetupOwnDefaults();
drawer.SetDisplayMode(1);
drawer.SetColor(Color.Yellow.To_quantity_color());

var line_aspect = new Prs3d_LineAspect(Color.Red.To_quantity_color(), Aspect_TypeOfLine.SOLID, local_hovered.Edge.Thickness);
drawer.SetWireAspect(line_aspect);
drawer.SetFaceBoundaryAspect(line_aspect);
drawer.SetUnFreeBoundaryAspect(line_aspect);

var shading_aspect = new Prs3d_ShadingAspect();
shading_aspect.SetColor(Color.Green.To_quantity_color());
shading_aspect.SetTransparency(0);
shading_aspect.Aspect().SetPolygonOffsets((int)Aspect_PolygonOffsetMode.Fill, 0.99f, 0.0f);
drawer.SetShadingAspect(shading_aspect);

return drawer;

Observations:

  1. When setting
var line_aspect = new Prs3d_LineAspect(Color.Red.To_quantity_color(), Aspect_TypeOfLine.SOLID, local_hovered.Edge.Thickness);
  • The thickness of the edge is correctly applied.
  • However, the edge color does not change to red.
  1. When setting
var shading_aspect = new Prs3d_ShadingAspect();
shading_aspect.SetColor(Color.Green.To_quantity_color());
  • The face color does not change to green as expected.

Question:

Is there a way to display different colors for individual local elements (edges and faces) when using LocalDynamic highlight mode? How can I properly set different colors for edges and faces on hover?

Any insights or alternative methods would be appreciated.

Dario Dura Armadans's picture

Some image may help understand your question better.

It is possible to show different colors for edges than for faces, for default or hilight or selection drawing (using AIS_InteractiveContext is quite easy):

myAISContext()->DefaultDrawer()->SetFaceBoundaryDraw(Standard_True);
myAISContext()->DefaultDrawer()->SetFaceBoundaryAspect(new Prs3d_LineAspect(Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));

myAISContext()->HighlightStyle(theType)->ShadingAspect()->SetColor(theColor);
myAISContext()->HighlightStyle(theType)->SetFaceBoundaryDraw(Standard_True);
myAISContext()->HighlightStyle(theType)->FaceBoundaryAspect()->SetColor(theColor);

Hope it helps.

이 수현's picture

I have modified the drawer settings based on the comment that viewer.Graphic.Occt is an AIS_InteractiveContext.

Here is my updated code:

viewer.Graphic.Occt.DefaultDrawer().SetFaceBoundaryDraw(true);
var line_aspect = new Prs3d_LineAspect(Color.White.To_quantity_color(), Aspect_TypeOfLine.SOLID, 3.0);
viewer.Graphic.Occt.DefaultDrawer().SetFaceBoundaryAspect(line_aspect);

viewer.Graphic.Occt.HighlightStyle(Aspect_TOH_Type.Dynamic).ShadingAspect().SetColor(Color.Blue.To_quantity_color());
viewer.Graphic.Occt.HighlightStyle(Aspect_TOH_Type.Dynamic).SetFaceBoundaryDraw(true);
viewer.Graphic.Occt.HighlightStyle(Aspect_TOH_Type.Dynamic).FaceBoundaryAspect().SetColor(Color.Green.To_quantity_color());

Expected Behavior:

When I run the program:

  • Faces appear yellow.
  • Edges appear green.

I expected that when hovering the mouse in Edge or Face selection mode:

  • Edge selection mode → Edges should appear green.
  • Face selection mode → Faces should appear blue.

Issue:

However, this is not happening as expected. The DisplayMode of AIS_InteractiveContext is set to 1.

Did I miss something or make a mistake in my implementation? Any guidance would be appreciated!

Additional Screenshots:

  • 1.PNG → The default box rendering.
  • 2.PNG → When hovering the mouse in Edge selection mode.
  • 3.PNG → When hovering the mouse in Face selection mode.
Attachments: 
gkv311 n's picture

I am working with OCCT in C# and trying to set different colors for edges and faces when using SetHighlightStyle(LocalDynamic)

AIS handles highlighting in a special way - by default, it doesn't (re)compute presentation, but modulates/overrides its properties like color. The behavior is managed by class Graphic3d_PresentationAttributes, which is the base of Prs3d_Drawer. Other properties of subclass Prs3d_Drawer are ignored when highlighting entire AIS_Shape, but some of them could take effect within local selection of subshapes (but color will be overridden anyway).

You would need customizing AIS_Shape to achieve highlighting of lines and triangles having different color (and/or probably improving OCCT itself).

There is trick, though. You may assign material for highlighting triangles Prs3d_Drawer::SetBasicFillAreaAspect() and color Prs3d_Drawer::SetColor() which will affect lines:

pload MODELING VISUALIZATION
box b 2 0 0 1 2 3
psphere s 1
vinit View1
vdisplay -dispMode 1 b s
vfit
vaspects b s -faceBoundaries 1 -faceBoundaryColor RED
vselprops dynHighlight -dispMode 1 -color BLUE -material PLASTIC
# now lines and triangles are highlighted in BLUE
vselprops dynHighlight -dispMode 1 -color GREEN
# now lines highlighted in GREEN and triangles in BLUE

box_highlight

This wouldn't affect line thickness though.

Attachments: 
이 수현's picture

Thank you for the detailed explanation.

Your insights on AIS highlighting behavior and possible customization approaches were really helpful.