For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

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

Thorsten's picture
Forums: 

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
 

Thorsten'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'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

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.