1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: GEOMAlgo_BuilderTools.cxx
24 // Author: Peter KURNEV
27 #include <GEOMAlgo_BuilderTools.ixx>
29 #include <TColStd_Array1OfReal.hxx>
31 #include <gp_Pnt2d.hxx>
36 #include <TColgp_Array1OfPnt.hxx>
38 #include <Poly_Triangulation.hxx>
39 #include <Poly_Array1OfTriangle.hxx>
40 #include <Poly_Triangle.hxx>
42 #include <Geom2d_Curve.hxx>
43 #include <Geom2dInt_Geom2dCurveTool.hxx>
45 #include <TopLoc_Location.hxx>
46 #include <TopAbs_Orientation.hxx>
48 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Iterator.hxx>
50 #include <TopoDS_Wire.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopExp_Explorer.hxx>
55 #include <BRep_Tool.hxx>
56 #include <BRepBndLib.hxx>
57 #include <BRepMesh_FastDiscret.hxx>
58 #include <Bnd_Box.hxx>
59 #include <BRepAdaptor_Curve2d.hxx>
62 Standard_Integer ComputeProps(const TopoDS_Face& aF,
66 void BuildTriangulation(const TopoDS_Face& aF);
68 //=======================================================================
71 //=======================================================================
72 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aW,
73 const TopoDS_Shape& aFace)
75 Standard_Boolean bIsHole;
76 Standard_Integer i, aNbS;
77 Standard_Real aT1, aT2, aS;
78 Standard_Real aU1, aU2, aU, dU;
79 Standard_Real aX1, aY1, aX0, aY0;
80 TopAbs_Orientation aOr;
82 gp_Pnt2d aP2D0, aP2D1;
83 Handle(Geom2d_Curve) aC2D;
87 bIsHole=Standard_False;
89 aF=TopoDS::Face(aFace);
91 aFF.Orientation(TopAbs_FORWARD);
95 for (; aItW.More(); aItW.Next()) {
96 const TopoDS_Edge& aE=TopoDS::Edge(aItW.Value());
98 if (!(aOr==TopAbs_FORWARD ||
99 aOr==TopAbs_REVERSED)) {
103 aC2D=BRep_Tool::CurveOnSurface(aE, aFF, aT1, aT2);
108 BRepAdaptor_Curve2d aBAC2D(aE, aFF);
109 aNbS=Geom2dInt_Geom2dCurveTool::NbSamples(aBAC2D);
114 dU=(aT2-aT1)/(Standard_Real)(aNbS-1);
118 if (aOr==TopAbs_REVERSED) {
126 for(i=2; i<=aNbS; i++) {
129 aP2D0.Coord(aX0, aY0);
130 aP2D1.Coord(aX1, aY1);
132 aS=aS+(aY0+aY1)*(aX1-aX0);
136 }//for (; aItW.More(); aItW.Next()) {
140 //=======================================================================
143 //=======================================================================
144 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aShell)
146 Standard_Boolean bIsHole;
147 Standard_Integer iRet;
148 Standard_Real aAi, aA, aV, aVi;
149 TopExp_Explorer aExp;
153 aExp.Init(aShell, TopAbs_FACE);
154 for (; aExp.More(); aExp.Next()) {
155 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
156 iRet=ComputeProps(aF, aAi, aVi);
166 //=======================================================================
167 //function : ComputeProps
169 //=======================================================================
170 Standard_Integer ComputeProps(const TopoDS_Face& aF,
174 Standard_Integer j, i, i1, i2, aNbNodes, aNbTrigs, n[3];
175 Standard_Real aAi, aVi;
176 gp_Pnt aP[3], aGC, aGC1;
177 TopLoc_Location aLoc;
178 TopAbs_Orientation aOr;
179 Handle(Poly_Triangulation) aTri;
184 aTri=BRep_Tool::Triangulation(aF, aLoc);
186 BuildTriangulation(aF);
187 aTri=BRep_Tool::Triangulation(aF, aLoc);
189 return 1;// a face is without triangulation
193 aNbNodes=aTri->NbNodes();
194 aNbTrigs=aTri->NbTriangles();
196 return 2;//no triangles
199 aOr=aF.Orientation();
201 const TColgp_Array1OfPnt& aNodes=aTri->Nodes();
202 const Poly_Array1OfTriangle& aTriangles=aTri->Triangles();
204 i1=aTriangles.Lower();
205 i2=aTriangles.Upper();
207 for (i=i1; i<=i2; ++i){
208 const Poly_Triangle& aTriangle=aTriangles.Value(i);
209 aTriangle.Get(n[0], n[1], n[2]);
210 aGC.SetCoord(0.,0.,0.);
211 for (j=0; j<3; ++j) {
212 aP[j]=aNodes.Value(n[j]);
213 aGC.ChangeCoord()+=aP[j].XYZ();
215 aGC.ChangeCoord()*=0.333333333333;
218 gp_Vec aV01(aP[0], aP[1]);
219 gp_Vec aV12(aP[1], aP[2]);
220 gp_Vec aVN=aV01^aV12;
225 Standard_Real aSx, aZx;
227 if (aOr==TopAbs_REVERSED) {
239 //=======================================================================
240 //function : BuildTriangulation
242 //=======================================================================
243 void BuildTriangulation(const TopoDS_Face& aF)
245 Standard_Boolean bWithShare;
246 Standard_Real aDiscret, aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
247 Standard_Real dX, dY, dZ, dMax, aCoeff, aAngle;
250 bWithShare=Standard_False;
253 BRepBndLib::Add(aF, aBox);
256 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
269 aDiscret=aCoeff*dMax;
271 BRepMesh_FastDiscret aMesher(aDiscret,