OCCT7: recommended approach to draw an on-screen crosshair (without old "Overlay API")

Hi,

I already replaced my own RubberBand solution (implemented with Visual3d_Layer) by the new AIS_RubberBand. I want to follow the same approach with my on-screen crosshair (following the mouse cursor...) but there is certainly no AIS_CrossHair or something else.

My question is: what is the recommended approach to draw an on-screen crosshair in OCCT 7 with minimal latency (without redrawing entire 3D viewer content)?

 

Best regards

Thorsten

Forum supervisor's picture

Dear Thorsten,

If the issue is critical for you you contact us via the Contact Form - http://www.opencascade.com/contact.
We will try to help you.

Best regards
FSR
 

ronaldmiura's picture

Thanks,
3D Power Visualization pvt. Ltd
http://threedpower.com

3D Power is an architectural Visualization Studio, expert in 3D Photorealistic Rendering, 3D Architectural Walkthrough & 3D Interior Designing.
Our Services:

-3D Architectural designs
-3D House architectural design
-3D Architectural elevations
-3D Architectural house plans
-3D Architectural floor plans
-3D Architectural Model
-3D Modeling services
- Elevation & Interior Designing
- Media, Brochure & Campaign Design

Thorsten H.'s picture

This issue isn't critical for me. I chose this as an example for the new "immediate mode rendering features". I would really like to understand how this works for newer OCCT versions.

Forum supervisor's picture

Dear Thorsten,
If you want to learn OCCT features more deeply you can consider
OCCT E-Learning courses (Fundamentals for example).

Best regards
FSR

Forum supervisor's picture

Besides some hints can be found in this article: : http://dev.opencascade.org/index.php?q=node/1080

Best regards
FSR

 

Thorsten H.'s picture

Ok, I think i got it working.

1) Create a new Class "AIS_CrossCursor", inherit from AIS_InteractiveObject.

2) Set Layer and TransformPersistence in the constructor

myDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0));
SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt(-1, 1, 0));
SetZLayer (Graphic3d_ZLayerId_TopOSD);

3) Declare a new member variables for the drawing

Handle(Graphic3d_ArrayOfPolylines) myLines;
int myXAxisLeftPntIndex;
int my​XAxisRightPntIndex;
int my​YAxisTopPntIndex;
int my​YAxisBottomPntIndex;

4) Setup the Drawing in the constructor:

myLines = new Graphic3d_ArrayOfPolylines(4, 2);

// arbitrarily chosen values:

double centerX = 500.0;
double centerY = 500.0;
double width = 200.0;
double height = 100.0;
double halfWidth = width / 2.0;
double halfHeight = height / 2.0;

myLines->AddBound(2);
myXAxisLeftPntIndex = myLines->AddVertex(centerX - halfWidth, -centerY, 0.0);
myXAxisRightPntIndex = myLines->AddVertex(centerX + halfWidth, -centerY, 0.0);
myLines->AddEdge(myXAxisRightPntIndex);

myLines->AddBound(2);
myYAxisTopPntIndex = myLines->AddVertex(centerX, -centerY + halfHeight, 0.0);
myYAxisBottomPntIndex = myLines->AddVertex(centerX, -centerY - halfHeight, 0.0);
myLines->AddEdge(myYAxisBottomPntIndex);

5) Create a new method to set the cross center (width/height are width/height of your View in px, centerX, centerY is the mouse pos)

void AIS_CrossCursor::setPosAndSize(const double & width, const double & height, const double & centerX, const double & centerY)
{
    myLines->SetVertice(myXAxisLeftPntIndex, 0, -centerY, 0.0);
    myLines->SetVertice(myXAxisRightPntIndex, width, -centerY, 0.0);
    myLines->SetVertice(myYAxisTopPntIndex, centerX, -0, 0.0);
    myLines->SetVertice(myYAxisBottomPntIndex, centerX, -height, 0.0);
}

6) Override the "Compute" Method

void AIS_CrossCursor::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
    const Handle(Prs3d_Presentation)& thePresentation,
    const Standard_Integer /*theMode*/)
{
    Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
    aGroup->SetGroupPrimitivesAspect(myDrawer->LineAspect()->Aspect());
    aGroup->AddPrimitiveArray(myLines);
}

That's it.

Usage:

  1. In "OnMouseMove" of your widget (I am using Qt) remember the mouse position.
  2. In "OnPaint" call "setPosAndSize", "display" or "redisplay", followed by "context->CurrentViewer()->RedrawImmediate();"

To extend your Class (LineType, LineColor, etc.) have a look at the source code of AIS_RubberBand (AIS_RubberBand.cxx).

Best regards

Thorsten