Point Cloud TopoDS_Shape Distance Calculation


I have a body and an aligned point cloud. I need to color every points. I used BRepExtrema_DistShapeShape class but distance calculation of 225k points took lots of time. Is there any other option to calculate?

Thank you.


Handle(Graphic3d_ArrayOfPoints) points = aisPC->GetPoints();
Handle(Graphic3d_ArrayOfPoints) distPoints = new Graphic3d_ArrayOfPoints(points->VertexNumber(), Graphic3d_ArrayFlags_VertexColor);

for (Standard_Integer i = 1; i <= points->VertexNumber(); i++)
            gp_Pnt point = points->Vertice(i);
            BRep_Builder aBuilder;
            TopoDS_Vertex aVertex;
            aBuilder.MakeVertex(aVertex, point, Precision::Confusion());

            TopExp_Explorer anEdgeExplorer(m_shapes[0], TopAbs_FACE);
            TopoDS_Shape shape = anEdgeExplorer.Current();
            BRepExtrema_DistShapeShape dist(aVertex, shape);
            Standard_Real value = dist.Value();
            while (anEdgeExplorer.More())
                TopoDS_Shape shapeFace = anEdgeExplorer.Current();
                BRepExtrema_DistShapeShape fDist(aVertex, shapeFace);
                if (fDist.Value() < value)
                    value = fDist.Value();

            if (value < 1)
                distPoints->AddVertex(points->Vertice(i), Quantity_NOC_GREEN);
                distPoints->AddVertex(points->Vertice(i), Quantity_NOC_RED);
Kirill Gavrilov's picture

Normally, such task is done not via expensive extrema between topological shapes, but by computing distance/projection between triangulation and points.

Emre Demir's picture

Thank you Kirill.