1 // Copyright (C) 2007-2010 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
23 // File: GEOMAlgo_BuilderTools.cxx
25 // Author: Peter KURNEV
28 #include <GEOMAlgo_BuilderTools.ixx>
30 #include <TColStd_Array1OfReal.hxx>
32 #include <gp_Pnt2d.hxx>
37 #include <TColgp_Array1OfPnt.hxx>
39 #include <Poly_Triangulation.hxx>
40 #include <Poly_Array1OfTriangle.hxx>
41 #include <Poly_Triangle.hxx>
43 #include <Geom2d_Curve.hxx>
44 #include <Geom2dInt_Geom2dCurveTool.hxx>
46 #include <TopLoc_Location.hxx>
47 #include <TopAbs_Orientation.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <TopoDS_Iterator.hxx>
51 #include <TopoDS_Wire.hxx>
53 #include <TopoDS_Edge.hxx>
54 #include <TopExp_Explorer.hxx>
56 #include <BRep_Tool.hxx>
57 #include <BRepBndLib.hxx>
58 #include <BRepMesh_FastDiscret.hxx>
59 #include <Bnd_Box.hxx>
60 #include <BRepAdaptor_Curve2d.hxx>
63 Standard_Integer ComputeProps(const TopoDS_Face& aF,
67 void BuildTriangulation(const TopoDS_Face& aF);
69 //=======================================================================
72 //=======================================================================
73 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aW,
74 const TopoDS_Shape& aFace)
76 Standard_Boolean bIsHole;
77 Standard_Integer i, aNbS;
78 Standard_Real aT1, aT2, aS;
79 Standard_Real aU1, aU2, aU, dU;
80 Standard_Real aX1, aY1, aX0, aY0;
81 TopAbs_Orientation aOr;
83 gp_Pnt2d aP2D0, aP2D1;
84 Handle(Geom2d_Curve) aC2D;
88 bIsHole=Standard_False;
90 aF=TopoDS::Face(aFace);
92 aFF.Orientation(TopAbs_FORWARD);
96 for (; aItW.More(); aItW.Next()) {
97 const TopoDS_Edge& aE=TopoDS::Edge(aItW.Value());
99 if (!(aOr==TopAbs_FORWARD ||
100 aOr==TopAbs_REVERSED)) {
104 aC2D=BRep_Tool::CurveOnSurface(aE, aFF, aT1, aT2);
109 BRepAdaptor_Curve2d aBAC2D(aE, aFF);
110 aNbS=Geom2dInt_Geom2dCurveTool::NbSamples(aBAC2D);
115 dU=(aT2-aT1)/(Standard_Real)(aNbS-1);
119 if (aOr==TopAbs_REVERSED) {
127 for(i=2; i<=aNbS; i++) {
130 aP2D0.Coord(aX0, aY0);
131 aP2D1.Coord(aX1, aY1);
133 aS=aS+(aY0+aY1)*(aX1-aX0);
137 }//for (; aItW.More(); aItW.Next()) {
141 //=======================================================================
144 //=======================================================================
145 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aShell)
147 Standard_Boolean bIsHole;
148 Standard_Integer iRet;
149 Standard_Real aAi, aA, aV, aVi;
150 TopExp_Explorer aExp;
154 aExp.Init(aShell, TopAbs_FACE);
155 for (; aExp.More(); aExp.Next()) {
156 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
157 iRet=ComputeProps(aF, aAi, aVi);
167 //=======================================================================
168 //function : ComputeProps
170 //=======================================================================
171 Standard_Integer ComputeProps(const TopoDS_Face& aF,
175 Standard_Integer j, i, i1, i2, aNbNodes, aNbTrigs, n[3];
176 Standard_Real aAi, aVi;
177 gp_Pnt aP[3], aGC, aGC1;
178 TopLoc_Location aLoc;
179 TopAbs_Orientation aOr;
180 Handle(Poly_Triangulation) aTri;
185 aTri=BRep_Tool::Triangulation(aF, aLoc);
187 BuildTriangulation(aF);
188 aTri=BRep_Tool::Triangulation(aF, aLoc);
190 return 1;// a face is without triangulation
194 aNbNodes=aTri->NbNodes();
195 aNbTrigs=aTri->NbTriangles();
197 return 2;//no triangles
200 aOr=aF.Orientation();
202 const TColgp_Array1OfPnt& aNodes=aTri->Nodes();
203 const Poly_Array1OfTriangle& aTriangles=aTri->Triangles();
205 i1=aTriangles.Lower();
206 i2=aTriangles.Upper();
208 for (i=i1; i<=i2; ++i){
209 const Poly_Triangle& aTriangle=aTriangles.Value(i);
210 aTriangle.Get(n[0], n[1], n[2]);
211 aGC.SetCoord(0.,0.,0.);
212 for (j=0; j<3; ++j) {
213 aP[j]=aNodes.Value(n[j]);
214 aGC.ChangeCoord()+=aP[j].XYZ();
216 aGC.ChangeCoord()*=0.333333333333;
219 gp_Vec aV01(aP[0], aP[1]);
220 gp_Vec aV12(aP[1], aP[2]);
221 gp_Vec aVN=aV01^aV12;
226 Standard_Real aSx, aZx;
228 if (aOr==TopAbs_REVERSED) {
240 //=======================================================================
241 //function : BuildTriangulation
243 //=======================================================================
244 void BuildTriangulation(const TopoDS_Face& aF)
246 Standard_Boolean bWithShare;
247 Standard_Real aDiscret, aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
248 Standard_Real dX, dY, dZ, dMax, aCoeff, aAngle;
251 bWithShare=Standard_False;
254 BRepBndLib::Add(aF, aBox);
257 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
270 aDiscret=aCoeff*dMax;
272 BRepMesh_FastDiscret aMesher(aDiscret,