AIS_PointCloud Point Selection and get the information

waldeinsamkeit05

CAD practitioner
Hi,
Is there any way to select some points in AIS_PointCloud(Selection mode is SM_SubsetOfPoints)? Actually, AIS_PointCloudOwner::SelectedPoints() method should work but I couldn't get the information when I select a point with mouseClick.

Can you help me?

Thanks,
Emre
 

natalia

Moderator
Staff member
Hi waldeinsamkeit05,

To select points on AIS_PointCloud you should activate this presentation in SM_SubsetOfPoints selection mode. We may check how it works using the next DRAW script:
Code:
pload ALL

# create sphere
sphere ss 10
mkface s ss
incmesh s 0.01

# draw sphere
vinit View1
vclear
vsetdispmode 1
vpointcloud p s -nonormals
vselmode p 2 0
vselmode p 1 1
vfit

Click in the viewer gives a point selected:
pointCloud.png
The selected/detected points are stored in the owner of this presentation(AIS_PointCloudOwner). So, to get this information we may use the selected/detected owner information. Selected and detected owners of the application present in AIS_InteractiveContext. So, we may get them, like this:
Code:
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
  {
    const Handle(SelectMgr_EntityOwner) owner = aContext->SelectedOwner();
    if (owner.IsNull())
      continue;
    Handle(AIS_PointCloudOwner) pcOwner = Handle(AIS_PointCloudOwner)::DownCast(owner);
    if (pcOwner.IsNull() || pcOwner->SelectedPoints().IsNull())
      continue;
    std::cout << "Selected Points count: " << pcOwner->SelectedPoints()->Map().Extent() << std::endl;
  }
 

waldeinsamkeit05

CAD practitioner
Hi natalia,
Thanks for reply. I really appreciate. To get the coordinates from the map, I add some codes. I hope it is useful for those who face the problem.

C++:
for (m_context->InitSelected(); m_context->MoreSelected(); m_context->NextSelected())
{
    const Handle(SelectMgr_EntityOwner) owner = m_context->SelectedOwner();
    if (owner.IsNull())
        continue;
    Handle(AIS_PointCloudOwner) pcOwner = Handle(AIS_PointCloudOwner)::DownCast(owner);
    if (pcOwner.IsNull() || pcOwner->SelectedPoints().IsNull())
        continue;
    //std::cout << "Selected Points count: " << pcOwner->SelectedPoints()->Map().Extent() << std::endl;
    Handle(Graphic3d_ArrayOfPoints) points3d = m_pointCloud->GetPoints();
    TColStd_PackedMapOfInteger map = pcOwner->SelectedPoints()->Map();
    for (TColStd_PackedMapOfInteger::Iterator mapIterator(map); mapIterator.More(); mapIterator.Next())
    {
        gp_Pnt selectedPoint = points3d->Vertice(mapIterator.Key());
        std::cout << selectedPoint.X() << " " << selectedPoint.Y() << " " << selectedPoint.Z() << std::endl;
    }
}


Extent function gives number of selected points. But it seems that more than 1 point can't be selected when I trying to select.
 
Last edited:

waldeinsamkeit05

CAD practitioner
Hi again natalia,
I tried but did not really focus on that because selecting points is not user friendly as I imagined. If I find anything that will help ones who are reading this thread, I will post the code.
 
Top