point inside a shape speedup hints?


I have to perform a lot of "is point inside a shape" queries in my application. Currently I am doing the query through the BRepClass3d_SolidClassifier with some preliminary filtering (bounding box) but the code is quite slow so I am looking for some hints how to speed it up.

The points (x,y,z) that I have to check can be divided into large subsets satisfying condition z=const. So I think that the problem can be reduced to 2D by checking if the point (x,y) is inside a face obtained by cutting the shape by the plane z=const. Can I expect some speedup by replacing the BRepClass3d_SolidClassifier by the BRepClass_FaceClassifier? Or should I do the test via some other OCC package/classes? Any other ideas?

Another note: the test need not to be accurate. The original problem is to query if a small solid cube is inside (more than 50% of its mass) a shape. This was approximated by querying if several points of the cube (center and neighbourhood) are inside the shape. So I think that e.g. using tesselation of the shape is an option?

To give you an idea about the problem size: there are tens of shapes and 10-100s of thousands of cubes (points).

Any hints will be appreciated.

Best regards, Petr


Cauchy Ding's picture

Hi Petr,

  I think it's better to convert your problem into point inside watertight mesh. Then use multi-threads to solve batch points inside mesh problem. Before calculating, you can also use the mesh's AABB or OOBB bounding box to filter some points. 


Petr Matousek's picture

Dear Ding,

thank you for your answer. Can you (or anyone else) point me to OCCT API that can be used to build mentioned "watertight mesh" from a TopoDS_Shape? Then what API calls can I use for answering the question whether a point is inside such mesh?

Another question related to mesh approximation: Is there an API that is able to calculate intersection of the meshed solid with a ray (edge)? Can one expect it to be faster than the classic BRepAlgoAPI_Common algorithm?

Regards, Petr