OpenCasCade中判断三维点在正则三维曲面片的ON_IN_OUT状态

类BRepClass_FaceClassifier(它的基类是 BRepClass_FClassifier )提供有构造方法,提供一个ToppDS_Face F和一个该三维正则曲面上的点P(或者一个gp_Pnt2d通过u,v坐标指定的三维点),通过State() 返回值判断点是在边界上TopAbs_ON,在F里面TopAbs_IN,在F外TopAbs_OUT,如果点在F边界上,Edge()还返回该点所在的边。

它的实现经过review后分布在src/brepclass和src/topclass中,会用到很多2d line和2dcurve求交计算,调试时有intana2d intres2d geom2dint intcurve目录中实现代码的这类连续的调用堆栈。

基本上是平面射线法求和轮廓的交点,但是轮廓是有向的,轮廓边的left side right side是指示了轮廓的in side或者out side,可以通过沿着射线靠近P的最近交点和最近轮廓边判断点是否在polygon2d的in或者out,传统平面算法的通过射线交点总数的奇偶判断点在多边形里面,是由于polygon并没有要求保证手相性,即轮廓edge并没有指示哪边是in side,但是边界表达法的是拓扑上精确的,可以通过edge知道哪边是inside。

由于拓扑学上正则参数曲面F(u,v)和他的参数平面u-v是同胚的,它可以理解为像CGAL一样u-v参数平面点P,正则参数曲面的边界Loop在u-v参数平面对应的平面多边形Polygon,点集拓扑观点是所有的三维正则曲面上的一个点(x,y,z)和它的参数曲面上的点(u,v)是一一映射的,不仅如此,uv面上和领域内相邻点的关系这种拓扑性质在三维曲面上并没有被改变,所以我们虽然是在求一个三维点和一个三维曲面片的位置关系,其实只将三维轮廓变换为二维polygon,就可以去求该三维问题。

变换成一种point2d_polygon2d_side case分类问题,只不过这时的平面polygon 不像CGAL中都是由直线段组成的,它还有平面二次曲线例如圆弧或者平面样条曲线,二次曲线和直线求交点有代数解析方法,或者多项式曲线和直线求交的数值迭代法。实现的开始也是计算了平面多边形的AABB以尽快发现out side的情况。


class BRepClass_FClassifier 
{
...
  Standard_EXPORT BRepClass_FClassifier();
  
  //! Returns the result of the classification.
  Standard_EXPORT TopAbs_State State() const;
  
  //! Returns  True when  the   state was computed by  a
  //! rejection. The state is OUT.
    Standard_Boolean Rejected() const;
  
  //! Returns True if  the face  contains  no wire.  The
  //! state is IN.
    Standard_Boolean NoWires() const;
  
  //! Returns   the    Edge  used   to    determine  the
  //! classification. When the State is ON  this  is the
  //! Edge containing the point.
  Standard_EXPORT const BRepClass_Edge& Edge() const;
  
  //! Returns the parameter on Edge() used to determine  the
  //! classification.
  Standard_EXPORT Standard_Real EdgeParameter() const;
  
  //! Returns the  position of  the   point on the  edge
  //! returned by Edge.
    IntRes2d_Position Position() const;
...
};

//! Provides Constructors with a Face.
class BRepClass_FaceClassifier  : public BRepClass_FClassifier
{
public:

  DEFINE_STANDARD_ALLOC

  
  //! Empty constructor, undefined algorithm.
  Standard_EXPORT BRepClass_FaceClassifier();
  
  //! Creates an algorithm to classify the Point  P with
  //! Tolerance <T> on the face described by <F>.
  Standard_EXPORT BRepClass_FaceClassifier(BRepClass_FaceExplorer& F, const gp_Pnt2d& P, const Standard_Real Tol);
  
  //! Creates an algorithm to classify the Point  P with
  //! Tolerance <T> on the face <F>.
  //! Recommended to use Bnd_Box if the number of edges > 10
  //! and the geometry is mostly spline
  Standard_EXPORT BRepClass_FaceClassifier(const TopoDS_Face& theF, const gp_Pnt2d& theP, const Standard_Real theTol, 
                   const Standard_Boolean theUseBndBox = Standard_False, const Standard_Real theGapCheckTol = 0.1);

  //! Classify  the Point  P  with  Tolerance <T> on the
  //! face described by <F>.
  //! Recommended to use Bnd_Box if the number of edges > 10
  //! and the geometry is mostly spline
  Standard_EXPORT void Perform (const TopoDS_Face& theF, const gp_Pnt2d& theP, const Standard_Real theTol, 
                   const Standard_Boolean theUseBndBox = Standard_False, const Standard_Real theGapCheckTol = 0.1);
  
  //! Creates an algorithm to classify the Point  P with
  //! Tolerance <T> on the face <F>.
  //! Recommended to use Bnd_Box if the number of edges > 10
  //! and the geometry is mostly spline
  Standard_EXPORT BRepClass_FaceClassifier(const TopoDS_Face& theF, const gp_Pnt& theP, const Standard_Real theTol,
                   const Standard_Boolean theUseBndBox = Standard_False, const Standard_Real theGapCheckTol = 0.1);
  
  //! Classify  the Point  P  with  Tolerance <T> on the
  //! face described by <F>.
  //! Recommended to use Bnd_Box if the number of edges > 10
  //! and the geometry is mostly spline
  Standard_EXPORT void Perform (const TopoDS_Face& theF, const gp_Pnt& theP, const Standard_Real theTol,
                   const Standard_Boolean theUseBndBox = Standard_False, const Standard_Real theGapCheckTol = 0.1);
...
};

在使用 OpenCASCADE 库进行几何计算时,可以使用 BRepClass3d_SolidClassifier 类来判断在模型内外。 以下是一个示例代码,展示了如何使用 OpenCASCADE 判断在模型内外: ```cpp #include <BRepBuilderAPI_MakeVertex.hxx> #include <BRepPrimAPI_MakeBox.hxx> #include <BRepClass3d_SolidClassifier.hxx> int main() { // 创建一个简单的模型 - 此处以立方体为例 double boxX = 10.0; double boxY = 10.0; double boxZ = 10.0; gp_Pnt boxCenter(0, 0, 0); BRepPrimAPI_MakeBox boxMaker(boxCenter, boxX, boxY, boxZ); TopoDS_Shape solid = boxMaker.Shape(); // 创建待判断 gp_Pnt pointToTest(5, 5, 5); BRepBuilderAPI_MakeVertex vertexMaker(pointToTest); TopoDS_Vertex vertex = vertexMaker.Vertex(); // 使用 BRepClass3d_SolidClassifier 判断在模型内外 BRepClass3d_SolidClassifier classifier(solid, vertex); classifier.Perform(); if (classifier.State() == TopAbs_IN) std::cout << "Point is inside the solid." << std::endl; else if (classifier.State() == TopAbs_OUT) std::cout << "Point is outside the solid." << std::endl; else if (classifier.State() == TopAbs_ON) std::cout << "Point is on the boundary of the solid." << std::endl; return 0; } ``` 上述代码创建了一个简单的立方体模型,并判断了一个是否在该模型内部。根据判断结果,输出相应的信息。 注意:在使用 OpenCASCADE 进行几何计算时,需要正确设置和引入相关的头文件和库文件,并进行正确的编译和链接操作。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值