码迷,mamicode.com
首页 > 其他好文 > 详细

Opencascad 判断点在图形内外

时间:2018-03-01 23:35:32      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:contex   tor   ret   ons   explorer   pods   normal   blog   .cpp   

程序摘自OccTry中:

二维情况:

在kcgBRepLib.cpp中

 1 BRepTopAdaptor_FClass2d fcls(aNF,Precision::PConfusion());
 2 
 3     TopExp_Explorer ex;
 4     for(ex.Init(aW2,TopAbs_VERTEX);ex.More();ex.Next())
 5     {
 6         TopoDS_Vertex aV = TopoDS::Vertex(ex.Current());
 7         gp_Pnt pnt = BRep_Tool::Pnt(aV);
 8 
 9         GeomAPI_ProjectPointOnSurf pp(pnt,fpln.Plane());
10         if(pp.IsDone() && pp.NbPoints() > 0)
11         {
12             gp_Pnt2d uv;
13             double u,v;
14             pp.LowerDistanceParameters(u,v);
15             uv.SetCoord(u,v);
16             //验证是否在aW1内部
17             TopAbs_State sta = fcls.Perform(uv);///该状态量只能用在二维中。。。
18             if(sta == TopAbs_IN)
19             {
20                 bIN = TRUE;
21                 break;
22             }
23         }
24         else
25         {
26             nC ++;
27             if(nC > 3)
28                 break;
29         }
30     }

三维情况:

kcmShapeAnalysis.cpp中

 1 BOOL    kcmShapeAnalysisFaceOrient::CalcNormal()
 2 {
 3     ClearArrowDisp();
 4 
 5     //
 6     TopoDS_Face aFace;
 7     TopExp_Explorer ex;
 8     kcDispFrameArrow *pArrow = NULL;
 9     kPoint3 p;
10     kVector3 norm;
11     int ix,nbShape = m_pInputFace->NbSelectedShape();
12     for(ix = 0;ix < nbShape;ix ++)
13     {
14         aFace = TopoDS::Face(m_pInputFace->SelectedShape(ix));
15         //
16         if(kcgSurfLib::CalcFaceNormal(aFace,m_bTopoNormal,p,norm))
17         {
18             pArrow = new kcDispFrameArrow(m_pModel->GetAISContext());
19             pArrow->SetColor(kColor(0.0,1.0,1.0));
20             pArrow->SetPixelLen(50,20,15);
21             pArrow->Set(p,norm);
22             pArrow->Display(TRUE);
23 
24             m_arrowList.push_back(pArrow);
25         }
26         // calc wire
27         TopoDS_Iterator ite;
28         for(ite.Initialize(aFace);ite.More();ite.Next())
29         {
30             TopoDS_Wire aWire = TopoDS::Wire(ite.Value());
31             TopoDS_Iterator wite;
32             for(wite.Initialize(aWire);wite.More();wite.Next())
33             {
34                 TopoDS_Edge aE = TopoDS::Edge(wite.Value());
35                 //
36                 if(kcgCurvLib::CalcTangent(aE,aFace,m_bTopoNormal,p,norm))
37                 {
38                     pArrow = new kcDispFrameArrow(m_pModel->GetAISContext());
39                     pArrow->SetColor(kColor(1.0,0.0,1.0));
40                     pArrow->SetPixelLen(50,20,15);
41                     pArrow->Set(p,norm);
42                     pArrow->Display(TRUE);
43 
44                     m_arrowList.push_back(pArrow);
45                 }
46             }
47         }
48     }
49 
50     return TRUE;
51 }

 

Opencascad 判断点在图形内外

标签:contex   tor   ret   ons   explorer   pods   normal   blog   .cpp   

原文地址:https://www.cnblogs.com/jeasonliu/p/8490558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!