MantisBT - Community
View Issue Details
0030523Community[OCCT] OCCT:Visualizationpublic2019-02-26 13:152019-03-11 14:02
BenjaminBihler 
apn 
normalminor 
closedfixed 
Mingw-w64Windows7
[OCCT] 7.4.0 
[OCCT] 7.4.0[OCCT] 7.4.0 
Not needed
0030523: Visualization - Highlighting does not work anymore
The commit c29c0ad0a2052257e0bd42f3b9491e0a34328acd disturbs highlighting in our software.

Background: Our software contains a viewer that is very similar to the one from the Qt tutorial sample. Highlighting is done by a method that is very similar to the one from the sample. Here is the code with some debug output:

void View::MoveEvent(const int x, const int y)
{
interactiveContext->MoveTo(x, y, myView, Standard_True);

Handle(AIS_InteractiveObject) newHighlightedObject;

if (interactiveContext->HasDetected())
{
newHighlightedObject = interactiveContext->DetectedInteractive();

std::cout << "Has detected. Object is " << newHighlightedObject->DynamicType()->Name() << std::endl;
}
}

From the given commit on, the shape over which the user hovers with the mouse is not highlighted anymore. Still the debugging output "Has detected. Object is AIS_Shape" shows that a shape has been detected. As soon as I go back one commit (to cf152970e2a79e7d60ffffffe4389f3e4d2b1ef5) everything works as expected.

I have a serious problem: the Qt tutorial sample works as expected also with the new commit, both on Windows and on Linux. Therefore the issue is not easily reproducible. Is there still a chance to trace it and to fix it?
pload MODELING VISUALIZATION 
box b 1 2 3
vclear
vinit View1
vdisplay -dispMode 1 b
vfit
vselprops dynHighlight -layer -2 -dispMode -1
vmoveto 200 200
#if { [vreadpixel 200 200 rgb name] != "DARKTURQUOISE" } { puts "Error" }
# OK

vmoveto 0 0
vselprops dynHighlight -layer 0 -dispMode -1
vmoveto 200 200
#if { [vreadpixel 200 200 rgb name] != "DARKTURQUOISE" } { puts "Error" }
# KO on the screen (but vreadpixel will NOT return issue here)
No tags attached.
child of 0030450closed bugmaster Open CASCADE Visualization - AIS_InteractiveContext::MoveTo() never uses V3d_View::ImmediateRedraw() 
Issue History
2019-02-26 13:15BenjaminBihlerNew Issue
2019-02-26 13:15BenjaminBihlerAssigned To => kgv
2019-02-26 13:57kgvRelationship addedrelated to 0030450
2019-02-26 14:04kgvNote Added: 0082370
2019-02-26 17:11BenjaminBihlerNote Added: 0082382
2019-03-01 14:40kgvNote Added: 0082506
2019-03-01 14:40kgvAssigned Tokgv => bugmaster
2019-03-01 14:40kgvStatusnew => feedback
2019-03-01 14:40kgvResolutionopen => unable to reproduce
2019-03-04 12:46BenjaminBihlerNote Added: 0082577
2019-03-04 12:47BenjaminBihlerAssigned Tobugmaster => kgv
2019-03-04 14:22kgvNote Added: 0082582
2019-03-04 14:23kgvAssigned Tokgv => BenjaminBihler
2019-03-04 15:22gitNote Added: 0082589
2019-03-04 15:23BenjaminBihlerNote Added: 0082590
2019-03-04 15:23BenjaminBihlerAssigned ToBenjaminBihler =>
2019-03-04 15:23BenjaminBihlerAssigned To => kgv
2019-03-06 13:45gitNote Added: 0082727
2019-03-06 13:59kgvSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=20801#r20801
2019-03-06 14:41gitNote Added: 0082734
2019-03-06 14:51kgvStatusfeedback => resolved
2019-03-06 14:51kgvResolutionunable to reproduce => open
2019-03-06 14:51kgvProduct Version => 7.4.0
2019-03-06 15:08gitNote Added: 0082739
2019-03-06 16:23gitNote Added: 0082745
2019-03-06 16:24kgvNote Added: 0082746
2019-03-06 16:24kgvAssigned Tokgv => bugmaster
2019-03-06 16:24kgvStatusresolved => reviewed
2019-03-07 11:27apnTest case number => Not needed
2019-03-07 11:27apnNote Added: 0082756
2019-03-07 11:27apnStatusreviewed => tested
2019-03-07 12:14kgvRelationship replacedchild of 0030450
2019-03-10 18:17apnChangeset attached => occt master 55c8f0f7
2019-03-10 18:17apnAssigned Tobugmaster => apn
2019-03-10 18:17apnStatustested => verified
2019-03-10 18:17apnResolutionopen => fixed
2019-03-11 14:01gitNote Added: 0082820
2019-03-11 14:02gitNote Added: 0082822
2019-03-11 14:02gitNote Added: 0082826

Notes
(0082370)
kgv   
2019-02-26 14:04   
The referred patch only replaces V3d_View::Update() with V3d_View::RedrawImmediate() in context, when dynamic highlighting is performed and it is expected to be done within one of Immediate Layers (Graphic3d_ZLayerId_Top/Graphic3d_ZLayerId_Topmost/Graphic3d_ZLayerId_TopOSD).

So that easiest way to keep updates is just calling V3d_View::Update() manually and pass FALSE to ::MoveTo().

Why issue might happen within application?
In case if you are using some sub-classes of SelectMgr_EntityOwner/StdSelect_BRepOwner/AIS_InteractiveObject or override highlight styles in one or another way, some dynamic highlighting might be erroneously (or unexpectedly) put into non-immediate layer.
Actually, there might be reasons for application doing this, but in this case application should manually call V3d_View::Update()/Redraw() after ::MoveTo().

Other possible reasons - no immediate layer properly initialized within OpenGL window or specifics in integrating of OCCT 3D Viewer into Qt application.
(0082382)
BenjaminBihler   
2019-02-26 17:11   
Kirill, your hints have been valueable as always.

Indeed there seems to be a problem with immediate layer initialization. If during redraw I query the number of immediate layers, then there is one such layer in the sample while an object is highlighted, but always zero such layers in my application. It is hard for me to understand the reason, because my code is very close to the sample code except that I use an OCAF TPrsStd_AISViewer and have restructured the code. Does anything come to your mind what the reason could be?

Still your proposal with manual updates works for me. Therefore you may want to close the issue.
(0082506)
kgv   
2019-03-01 14:40   
I don't know what can be wrong, as long as application does not modify ZLayers / highlight styles, it should work by default.

I suggest closing the issue - fill free to reopen it when you will be able providing a reproducer.
(0082577)
BenjaminBihler   
2019-03-04 12:46   
You had mentioned it before, but just now I have realized that I do change highlight styles. And yes, this is the source of the error. If I omit highlight style changes, then highlighting works as expected.

My highlight style changing code is similar to this:

const Handle(Prs3d_Drawer) highlightStyle = new Prs3d_Drawer();
highlightStyle->SetColor(Quantity_NOC_CYAN1);
interactiveContext->SetHighlightStyle(highlightStyle);

I have found two ways to solve the problem.

1. Do not create a new Prs3d_Drawer, but modify the existing one instead:

interactiveContext->HighlightStyle()->SetColor(Quantity_NOC_CYAN1);

The idea to call the setter SetHighlightStyle() came from previous OCCT versions where SetHilightColor() was the suitable setter to modify highlight colors.

2. Set the ZLayer ID of the Prs3d_Drawer:

const Handle(Prs3d_Drawer) highlightStyle = new Prs3d_Drawer();
highlightStyle->SetColor(Quantity_NOC_CYAN1);
highlightStyle->SetZLayer(interactiveContext->HighlightStyle()->ZLayer());
interactiveContext->SetHighlightStyle(highlightStyle);

Could you answer three more questions?
- Is there a preferred way to set the highlight color?
- Would it be an option to change the default value of myZLayer in Graphic3d_PresentationAttributes to get working highlight styles by default even if the user doesn't know what he is doing?
- Would a hint in the documentation of the setter SetHighlightStyle help to prevent other users from doing the same mistake?

Thank you again for your help!
(0082582)
kgv   
2019-03-04 14:22   
> 1. Do not create a new Prs3d_Drawer, but modify the existing one instead:
> - Is there a preferred way to set the highlight color?
Yes, there is no use in creating a new Prs3d_Drawer instance here, so that modifying existing instance is more preferable and straightforward.

> - Would it be an option to change the default value of myZLayer
> in Graphic3d_PresentationAttributes to get working highlight styles by default
I don't think there is a safe way modifying default value within Graphic3d_PresentationAttributes.
Although AIS_IneractiveContext::MoveTo() might check if default highlight style has non-immediate Z-layer and perform full Redraw() instead of RedrawImmediate().

> - Would a hint in the documentation of the setter SetHighlightStyle
> help to prevent other users from doing the same mistake?
Yes, I think that a hint in documentation might be helpfuil.
(0082589)
git   
2019-03-04 15:22   
Branch CR30523 has been created by BenjaminBihler.

SHA-1: 1d35fefcbd03f6dbb6bb9bbe26f72f3d28e85599


Detailed log of new commits:

Author: Benjamin Bihler
Date: Mon Mar 4 13:16:10 2019 +0100

    0030523: Visualization - Highlighting does not work anymore
    
    Added hints about ZLayer consideration and changing highlight colors to
    the setter documentation.
(0082590)
BenjaminBihler   
2019-03-04 15:23   
Done.
(0082727)
git   
2019-03-06 13:45   
Branch CR30523_1 has been created by kgv.

SHA-1: b9e52590edbe0b7710e50237979d11271565a28a


Detailed log of new commits:

Author: Benjamin Bihler
Date: Mon Mar 4 13:16:10 2019 +0100

    0030523: Visualization - Highlighting does not work anymore
    
    Added hints about ZLayer consideration and changing highlight colors to documentation
    of AIS_InteractiveContext::SetHighlightStyle() method.
(0082734)
git   
2019-03-06 14:41   
Branch CR30523_2 has been created by kgv.

SHA-1: db5f0198777c7601902934391932d42329df3c8a


Detailed log of new commits:

Author: Benjamin Bihler
Date: Mon Mar 4 13:16:10 2019 +0100

    0030523: Visualization - Highlighting does not work anymore
    
    Added hints about ZLayer consideration and changing highlight colors to documentation
    of AIS_InteractiveContext::SetHighlightStyle() method.
    
    AIS_InteractiveContext::MoveTo() now checks if highlighting style does not use immediate layer
    and performs full Redraw() instead of RedrawImmediate().
    
    Improved parsing of ZLayer names within vdisplay, vzlayer and vselprops commands.
    vreadpixel now reports syntax errors on wrong input.
(0082739)
git   
2019-03-06 15:08   
Branch CR30523_2 has been updated forcibly by kgv.

SHA-1: 3258ab72385dbfe4c4622204862a453dd9add660
(0082745)
git   
2019-03-06 16:23   
Branch CR30523_2 has been updated forcibly by kgv.

SHA-1: 302ea67280048df9e89ca1b824d03c92c193cc4e
(0082746)
kgv   
2019-03-06 16:24   
Please raise the patch.
(0082756)
apn   
2019-03-07 11:27   
Tested with IR-WEEK10:
http://jenkins-test-12.nnov.opencascade.com/view/IR-WEEK10/view/COMPARE/ [^]
(0082820)
git   
2019-03-11 14:01   
Branch CR30523_2 has been deleted by inv.

SHA-1: 302ea67280048df9e89ca1b824d03c92c193cc4e
(0082822)
git   
2019-03-11 14:02   
Branch CR30523_1 has been deleted by inv.

SHA-1: b9e52590edbe0b7710e50237979d11271565a28a
(0082826)
git   
2019-03-11 14:02   
Branch CR30523 has been deleted by inv.

SHA-1: 1d35fefcbd03f6dbb6bb9bbe26f72f3d28e85599