1 // Copyright (C) 2007-2011 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
23 // Author: Peter KURNEV
25 #include <GEOMAlgo_BuilderTools.ixx>
27 #include <Basics_OCCTVersion.hxx>
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 #if OCC_VERSION_LARGE > 0x06050100 // for OCC-6.5.2 and higher version
57 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
60 #include <BRep_Tool.hxx>
61 #include <BRepBndLib.hxx>
62 #include <BRepMesh_FastDiscret.hxx>
63 #include <Bnd_Box.hxx>
64 #include <BRepAdaptor_Curve2d.hxx>
67 Standard_Integer ComputeProps(const TopoDS_Face& aF,
71 void BuildTriangulation(const TopoDS_Face& aF);
73 //=======================================================================
76 //=======================================================================
77 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aW,
78 const TopoDS_Shape& aFace)
80 Standard_Boolean bIsHole;
81 Standard_Integer i, aNbS;
82 Standard_Real aT1, aT2, aS;
83 Standard_Real aU1, aU2, aU, dU;
84 Standard_Real aX1, aY1, aX0, aY0;
85 TopAbs_Orientation aOr;
87 gp_Pnt2d aP2D0, aP2D1;
88 Handle(Geom2d_Curve) aC2D;
92 bIsHole=Standard_False;
94 aF=TopoDS::Face(aFace);
96 aFF.Orientation(TopAbs_FORWARD);
100 for (; aItW.More(); aItW.Next()) {
101 const TopoDS_Edge& aE=TopoDS::Edge(aItW.Value());
102 aOr=aE.Orientation();
103 if (!(aOr==TopAbs_FORWARD ||
104 aOr==TopAbs_REVERSED)) {
108 aC2D=BRep_Tool::CurveOnSurface(aE, aFF, aT1, aT2);
113 BRepAdaptor_Curve2d aBAC2D(aE, aFF);
114 aNbS=Geom2dInt_Geom2dCurveTool::NbSamples(aBAC2D);
119 dU=(aT2-aT1)/(Standard_Real)(aNbS-1);
123 if (aOr==TopAbs_REVERSED) {
131 for(i=2; i<=aNbS; i++) {
134 aP2D0.Coord(aX0, aY0);
135 aP2D1.Coord(aX1, aY1);
137 aS=aS+(aY0+aY1)*(aX1-aX0);
141 }//for (; aItW.More(); aItW.Next()) {
145 //=======================================================================
148 //=======================================================================
149 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aShell)
151 Standard_Boolean bIsHole;
152 Standard_Integer iRet;
153 Standard_Real aAi, aA, aV, aVi;
154 TopExp_Explorer aExp;
158 aExp.Init(aShell, TopAbs_FACE);
159 for (; aExp.More(); aExp.Next()) {
160 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
161 iRet=ComputeProps(aF, aAi, aVi);
171 //=======================================================================
172 //function : ComputeProps
174 //=======================================================================
175 Standard_Integer ComputeProps(const TopoDS_Face& aF,
179 Standard_Integer j, i, i1, i2, aNbNodes, aNbTrigs, n[3];
180 Standard_Real aAi, aVi;
181 gp_Pnt aP[3], aGC, aGC1;
182 TopLoc_Location aLoc;
183 TopAbs_Orientation aOr;
184 Handle(Poly_Triangulation) aTri;
189 aTri=BRep_Tool::Triangulation(aF, aLoc);
191 BuildTriangulation(aF);
192 aTri=BRep_Tool::Triangulation(aF, aLoc);
194 return 1;// a face is without triangulation
198 aNbNodes=aTri->NbNodes();
199 aNbTrigs=aTri->NbTriangles();
201 return 2;//no triangles
204 aOr=aF.Orientation();
206 const TColgp_Array1OfPnt& aNodes=aTri->Nodes();
207 const Poly_Array1OfTriangle& aTriangles=aTri->Triangles();
209 i1=aTriangles.Lower();
210 i2=aTriangles.Upper();
212 for (i=i1; i<=i2; ++i){
213 const Poly_Triangle& aTriangle=aTriangles.Value(i);
214 aTriangle.Get(n[0], n[1], n[2]);
215 aGC.SetCoord(0.,0.,0.);
216 for (j=0; j<3; ++j) {
217 aP[j]=aNodes.Value(n[j]);
218 aGC.ChangeCoord()+=aP[j].XYZ();
220 aGC.ChangeCoord()*=0.333333333333;
223 gp_Vec aV01(aP[0], aP[1]);
224 gp_Vec aV12(aP[1], aP[2]);
225 gp_Vec aVN=aV01^aV12;
230 Standard_Real aSx, aZx;
232 if (aOr==TopAbs_REVERSED) {
244 //=======================================================================
245 //function : BuildTriangulation
247 //=======================================================================
248 void BuildTriangulation(const TopoDS_Face& aF)
250 Standard_Boolean bWithShare;
251 Standard_Real aDiscret, aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
252 Standard_Real dX, dY, dZ, dMax, aCoeff, aAngle;
255 bWithShare=Standard_False;
258 BRepBndLib::Add(aF, aBox);
261 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
274 aDiscret=aCoeff*dMax;
276 BRepMesh_FastDiscret aMesher(aDiscret,
284 #if OCC_VERSION_LARGE > 0x06050100 // for OCC-6.5.2 and higher version
285 TopTools_IndexedDataMapOfShapeListOfShape anAncestors;
286 TopExp::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, anAncestors);
287 aMesher.Add(aF, anAncestors);