Set highlight style on a GLB object is not changing the highlight

I am using this code in the initviewer function to try to load the model and set the highlight style.

  // Create AIS context
  myContext = new AIS_InteractiveContext (myViewer);
  myContext->SetDisplayMode ((int )AIS_DisplayMode::AIS_Shaded, false);
    myContext->DefaultDrawer ()->SetFaceBoundaryDraw(true);
    myContext->DefaultDrawer ()->FaceBoundaryAspect()->SetColor(Quantity_NameOfColor::Quantity_NOC_BLACK);
    myContext->DefaultDrawer ()->FaceBoundaryAspect()->SetWidth(1.2);
    Handle(Prs3d_Drawer) highlightStyle = new Prs3d_Drawer();
    highlightStyle->SetColor(Quantity_NOC_CYAN);
    myContext->SetHighlightStyle(Prs3d_TypeOfHighlight_LocalDynamic, highlightStyle);
    myContext->SetHighlightStyle(Prs3d_TypeOfHighlight_LocalSelected, highlightStyle);
    myContext->SetHighlightStyle(Prs3d_TypeOfHighlight_Dynamic, highlightStyle);
    myContext->SetHighlightStyle(Prs3d_TypeOfHighlight_Selected, highlightStyle);

  myView = myViewer->CreateView();
  myView->TriedronDisplay (Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.20, V3d_ZBUFFER);

Any advice on how to set the highlight style for when a part is selected? Thanks

gkv311 n's picture

What you expect/want to see and what you actually see? Any screenshots?

Jeff Foster's picture

It doesn't appear to be setting the color of the highlight. With that code I would expect the highlight color to be a cyan color. What is see is a dark gray highlight color. See the attached photo with the bolt in the the red circle is the selected part of the model and it is just a slightly darker gray than the rest of the model. So I was trying to get the selection to stand out with this code.

Attachments: 
gkv311 n's picture

On your screenshot it looks like your objects have highlight mode AIS_Shaded instead of default AIS_Wireframe, but this is not specified in the code snippet. How do you set it? If you doing something like AIS_Shape::SetHilightMode() then beware that this method creates a custom Prs3d_Drawer for highlighting of specific object, and fills it with default values - e.g. Quantity_NOC_GRAY80:

void PrsMgr_PresentableObject::SetHilightMode (const Standard_Integer theMode)
{
  if (myHilightDrawer.IsNull())
  {
    myHilightDrawer = new Prs3d_Drawer();
    myHilightDrawer->Link (myDrawer);
    myHilightDrawer->SetAutoTriangulation (Standard_False);
    myHilightDrawer->SetColor (Quantity_NOC_GRAY80);
    myHilightDrawer->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
  }
  if (myDynHilightDrawer.IsNull())
  {
    myDynHilightDrawer = new Prs3d_Drawer();
    myDynHilightDrawer->Link (myDrawer);
    myDynHilightDrawer->SetColor (Quantity_NOC_CYAN1);
    myDynHilightDrawer->SetAutoTriangulation (Standard_False);
    myDynHilightDrawer->SetZLayer(Graphic3d_ZLayerId_Top);
  }
  myHilightDrawer   ->SetDisplayMode (theMode);
  myDynHilightDrawer->SetDisplayMode (theMode);
}

If you want to change default highlight mode for all objects in AIS_InteractiveContext you might want to change Prs3d_Drawer::SetDisplayMode() of related style in it. -1 means to use active display mode of main presentation.

pload MODELING VISUALIZATION
box b 150 0 0 100 100 100
pcone c 100 0 100
vinit View1
vdisplay b c -dispMode 1
vaspects -faceBoundaryDraw 1 -faceBoundaryWidth 2 -faceBoundaryColor BLACK
vselprops selHighlight -color CYAN -dispMode -1

Extra notes:

    myContext->DefaultDrawer ()->FaceBoundaryAspect()->SetWidth(1.2);

using fractional line width is probably not a good idea - it will be either ignored or will produce extra aliasing/smashing effect on lines in most cases.

Default highlight style sets more properties than just a color, so that these lines will have more side effects on Viewer behavior than you might expect:

    Handle(Prs3d_Drawer) highlightStyle = new Prs3d_Drawer();
    highlightStyle->SetColor(Quantity_NOC_CYAN);
    myContext->SetHighlightStyle(Prs3d_TypeOfHighlight_LocalDynamic, highlightStyle);

Default style would also link to main presentation Prs3d_Drawer instance (so that there is no need to duplicate exactly same customizations) and configure different Z-Layers.

I would suggest to change existing drawers in context like:

myContext->HighlightStyle(Prs3d_TypeOfHighlight_Selected)->SetColor(Quantity_NOC_CYAN);
myContext->HighlightStyle(Prs3d_TypeOfHighlight_Selected)->SetDisplayMode(-1);

instead of assigning a new Prs3d_Drawer instance.

draw_sel_cyan.png

Attachments: 
Jeff Foster's picture

This is the sample code from the IOS project found here https://github.com/Open-Cascade-SAS/OCCT/blob/master/samples/ios/UIKitSample/UIKitSample/OcctViewer.mm#L84

I had added a the extra indented code around the highlighting trying to get it to work. Removing that code and adding the suggested two lines didn't solve the problem entirely. From some of your comments I think the sample project is setting the highlight mode as AIS_Shaded instead of the AIS_Wireframe like you mentioned.

https://github.com/Open-Cascade-SAS/OCCT/blob/master/samples/ios/UIKitSample/UIKitSample/OcctViewer.mm#L336

Handle(TCollection_HAsciiString) anId       = new TCollection_HAsciiString (anEntry);
    Handle(AIS_ConnectedInteractive) aConnected = new AIS_ConnectedInteractive();
    aConnected->Connect (anAis, theParentTrsf.Transformation());
    aConnected->SetOwner (anId);
    aConnected->SetLocalTransformation (theParentTrsf.Transformation());
    aConnected->SetHilightMode(1);
    myContext->Display  (aConnected, Standard_False);

Commenting out //aConnected->SetHilightMode(1); got the highlighting showing as I was expecting with the cyan color.