1、显示所有的点云数据
#include <AIS_PointCloud.hxx>包能够找到想要的内容
2、获取某一选中曲面的法向量
BRepClass3d_SolidExplorer aBSE(t_Shape);//t_shape是选中的TopoDS_Shape
TopoDS_Face aTFace = TopoDS::Face(t_Shape);
//Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aTFace);
BRepAdaptor_Surface aBSurf(aTFace,Standard_True);
Standard_Real U = 0.0,V = 0.0;
BRepLProp_SLProps theProp(aBSurf,1,Precision::Confusion());
theProp.SetParameters(U,V);//初始化U,V两个参数
gp_Vec theNormal;//曲面法向量
if (theProp.IsNormalDefined())
{
theNormal = theProp.Normal();
}
3、计算点云到选中曲面的距离的大小
//方法1 采用 GeomAPI_ProjectPointOnSurf
//获取最小距离的大小和交点
TopoDS_Face aTFace = TopoDS::Face(t_Shape);//选中的TopoDS_Shape
Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aTFace);
gp_Pnt p(1,1,1);//将要计算的点
GeomAPI_ProjectPointOnSurf aGeomPp(p,aSurface,Extrema_ExtAlgo_Grad);
Standard_Real minDistance = 0.0;//定义最短的距离
Standard_Real PSdistance = 0.0;
Standard_Integer minPIndex = 0;//定义最短距离的点的index
if (aGeomPp.IsDone() && aGeomPp.NbPoints()>0)
{
minDistance = aGeomPp.Distance(1);
minPIndex = 1;
for(Standard_Integer i = 2; i <= aGeomPp.NbPoints();i++)
{
PSdistance = aGeomPp.Distance(i);
if (minDistance > PSdistance)
{
minDistance = PSdistance;
minPIndex = i;
}
}
gp_Pnt interPnt = aGeomPp.Point(minPIndex);//与平面最短的那个距离的交点
gp_Vec PntToPnt(p,interPnt);//定义交点和p的向量
Standard_Real aReal = aGeomPp.LowerDistance();//自带的函数计算最短距离
//来判断交点在所选曲面的正向还是反向
//获取曲面的U,V参数
aGeomPp.LowerDistanceParameters(U,V);
aGeomPp.Parameters(minPIndex,U,V);
gp_Pnt pnt;
gp_Vec D1U,D1V;
//计算交点对应的U,V的一阶微分
GeomLProp_SurfaceTool::D1(aSurface,U,V,pnt,D1U,D1V);
//计算交点的法向量 = U,V一阶微分的叉乘
gp_Vec PntNormal = D1U.Crossed(D1V);
PntNormal.Normalize();
Standard_Real pangle = PntNormal.Angle(PntToPnt);
//判断是否同向,区分正负值
if (pangle > PI/2 && pangle <= PI)
{
Standard_Real d = -minDistance;
minDistance = d;
}
testdata.push_back(minDistance);
}
//方法2 采用 Extrema_ExtPS
BRepClass3d_SolidExplorer aBSE(t_Shape);
TopoDS_Face aTFace = TopoDS::Face(t_Shape);
Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aTFace);
BRepAdaptor_Surface aBSurf(aTFace,Standard_True);
Extrema_ExtPS aEEps(p,aBSurf,1e-6,1e-6,Extrema_ExtFlag_MINMAX,Extrema_ExtAlgo_Grad);
if (aEEps.IsDone()&&aEEps.NbExt()>0)
{
minDistance = sqrt(aEEps.SquareDistance(1));
minPIndex = 1;
for(Standard_Integer i = 2;i<=aEEps.NbExt();i++)
{
PSdistance = sqrt(aEEps.SquareDistance(i));
if (minDistance > PSdistance)
{
minDistance = PSdistance;
minPIndex = i;
}
}
}
4、判断一个点是否在选中的面上
//采用两种方法显示
BRepClass3d_SClassifier aBSC(aBSE,p,Precision::PConfusion());
BRepClass3d_SolidClassifier aBSCF(t_Shape,p,Precision::PConfusion());
TopAbs_Orientation aTopOri= t_Shape.Orientation();
TopAbs_State mstate = aBSCF.State();
TopAbs_State astate = aBSC.State();