gkv311 / occt-samples-qopenglwidget

Open CASCADE Technology sample - 3D Viewer within Qt Widgets window
Other
50 stars 14 forks source link

How to get the selected points from an ais_pointcloud object? #13

Closed zjuzhh closed 1 year ago

zjuzhh commented 1 year ago

Hello @gkv311 , I ues your example to display some cad model(ais_shape) and pointcloud model(ais_pointcloud)succesfully, but when i want to select some points from an ais_pointcloud,it's not the same as selecting TopAbs_Face from the AIS_Slection. The schematic diagram is as follows: test The code I select TopAbs_Face from an ais_shape object is as follows:

   if (!myOccView->getContext()->Selection()->IsEmpty()) {
        const Handle(AIS_Selection) selection = myOccView->getContext()->Selection();
        for (selection->Init(); selection->More(); selection->Next()) {
            Handle(SelectMgr_EntityOwner) entity = selection->Value();
            TopoDS_Shape shape = Handle(StdSelect_BRepOwner)::DownCast(entity)->Shape();

            // Create an explorer to iterate over all faces in the shape.
            TopExp_Explorer explorer_face(shape, TopAbs_FACE);
            ......
            }
    }
 The code I select points from an ais_shape object is as follows:
       Handle(AIS_Selection) selection = myOccView->getContext()->Selection();       
       Handle(AIS_PointCloud) myPointCloud = Handle(AIS_PointCloud)::DownCast(aisObj);
       for (selection->Init(); selection->More(); selection->Next()) {
                Handle(SelectMgr_EntityOwner) entity = selection->Value();
                Handle(AIS_PointCloudOwner) owner = Handle(AIS_PointCloudOwner)::DownCast(entity);
                Handle(TColStd_HPackedMapOfInteger) selectedPoints = owner->SelectedPoints();
                ......
       }
 I don't how to use the selectedPoints(TColStd_HPackedMapOfInteger object) to get every gp_pnt point,could you give me some advice or some sample code?Thanks in advance.
gkv311 commented 1 year ago

TColStd_HPackedMapOfInteger holds a collection of indices pointing to points in AIS_PointCloud.

Handle(AIS_PointCloud) aCloud = ...;
Handle(AIS_PointCloudOwner) anOwner = ...;
Handle(Graphic3d_ArrayOfPoints) aPoints = aCloud->GetPoints();
Handle(TColStd_HPackedMapOfInteger)& aSelPoints = anOwner->SelectedPoints();
for (TColStd_PackedMapOfInteger::Iterator aPntIter (aSelPoints->Map(); aPntIter.More(); aPntIter.Next())
{
  int aPntIndex = aPntIter.Key();
  gp_Pnt aPnt = aPoints->Vertice (aPntIndex + 1);
  ...
}