How to query intersection point of selected shape and cursor line in selection system

Hi guys,

I'm working with OpenCascade picking system. I can perform well a point/rectangle/polyline selection and query out the selected shapes. But how do I get the intersection point of selected shape (in point selection mode)?
My code is very simple following what is written in: https://dev.opencascade.org/doc/overview/html/occt_user_guides__visualiz...

Thank you.

Hoong Dang's picture

Hi guys,

Now I can answer this question myself.
It is the AIS_InteractiveContext::MainPicker that helps to query picked information.

Cheers.

Kirill Gavrilov's picture

StdSelect_ViewerSelector3d provides an extended information about picking results - including 3D point on picked object.
In C++ the code may look like this:

Handle(AIS_InteractiveContext) theCtx;

// get the topmost detected owner first of all
const Handle(SelectMgr_EntityOwner) aDetOwner = theCtx->DetectedOwner();
if (aDetOwner.IsNull())
{
  return;
}

// find the owner within StdSelect_ViewerSelector3d picking results
// (elements are sorted in descending order - from topmost to farthest,
//  before AIS_InteractiveContext::Filters() applied)
int aResPickIndex = 0;
for (int aPickIter = 1; aPickIter <= theCtx->MainSelector()->NbPicked(); ++aPickIter)
{
  const SelectMgr_SortCriterion& aPickData = theCtx->MainSelector()->PickedData (aPickIter);
  if (aPickData.Entity->OwnerId() == aDetOwner)
  {
    aResPickIndex = aPickIter;
    break;
  }
}
if (aResPickIndex == 0)
{
  return;
}

// retrieve extended information from SelectMgr_SortCriterion class
Handle(SelectMgr_SelectableObject) anObj = aDetOwner->Selectable().get();
const SelectMgr_SortCriterion& aPickedData = theCtx->MainSelector()->PickedData (aResPickIndex);

// point on the picked object
if (aPickedData.HasPickedPoint())
{
  gp_Pnt aPnt = aPickedData.Point();
}

// triangle normal at the picked point
if (aPickedData.SurfaceNormal().Modulus() > 0.0f)
{
  Graphic3d_Vec3 aSurfNorm = aPickedData.SurfaceNormal();
}

// depth from the eye camera position along the picking ray
double aDepth = aPickedData.Depth();

Draw Harness has a commands vmoveto and vstate which implementations in C++ might be used as a code samples:

pload MODELING VISUALIZATION
psphere s 100
vinit View1
vdisplay s -dispMode 1
vfit
set aPnt [vmoveto 100 100]
vpoint p {*}$aPnt
Hoong Dang's picture

Hi Kirill,
Thanks for answering. That's great. I managed to play with OCC picking system now.
Cheers,