c++ program to test whether or not a point belongs to a model.

Hello.

I need to write a simple test program in C++ and I would like to ask for some assistance.
The program should do the following:
given a list of points ( in 3d or 2d space ) and a model ( say, in STEP format ),
for each point determine whether or not it belongs to some part of the model,
i.e. whether or not the point lies somewhere in a space, occupied by the model.
( for the 2d case, a picture is attached )

Using an [url=http://www.opencascade.org/doc/occt-6.7.1/overview/html/occt_user_guides..., I have managed to read a STEP file.
Unfortunately, I don't know how to proceed further. I need some advice on the following questions:
1) What is the correct way to represent a point in 3d or 2d space in OCC?
2) How do I test whether or not this point belongs to a model?

I've tried to search [url=http://dev.opencascade.org/doc/refman/html/index.html]documentation[/url], but without much success.

Daniel Neander's picture

Hello Ab,

To represent a vertex in 3D space use BRepBuilderAPI_MakeVertex.
Example:
TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(outsidePoint);
Handle(AIS_Shape) vertexShape = new AIS_Shape(vertex);
AISContext->Display(vertexShape);

To test whether a point lies within a solid use BRepClass3d_SolidClassifier.
Example:

// Checking whether a point lies within or outside a solid.
void main()
{
TopoDS_Shape box = BRepPrimAPI_MakeBox(gp_Pnt(0,0,0), 100,100,100);
gp_Pnt outsidePoint(200,0,0);
gp_Pnt insidePoint(30,30,30);

if (pointLiesWithinShape(box, outsidePoint) == TopAbs_OUT)
{
qDebug() << "Outside point confirmed.";
}
if (pointLiesWithinShape(box, insidePoint) == TopAbs_IN)
{
qDebug() << "Inside point confirmed.";
}
}

TopAbs_State pointLiesWithinShape(TopoDS_Shape shape, gp_Pnt point)
{
if (shape.IsNull() || shape.ShapeType() != TopAbs_SOLID) {
return TopAbs_UNKNOWN;
}

BRepClass3d_SolidClassifier solidClassifier(shape, point, Precision::Confusion());
return solidClassifier.State();
}

Kind Regards
Daniel

noway's picture

Thanks for the answer. It's exactly what I've been looking for.