1 // Copyright (C) 2007-2012 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
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_BuilderTools.hxx>
28 #include <Basics_OCCTVersion.hxx>
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 #if OCC_VERSION_LARGE > 0x06050100 // for OCC-6.5.2 and higher version
58 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
61 #include <BRep_Tool.hxx>
62 #include <BRepBndLib.hxx>
63 #include <BRepMesh_FastDiscret.hxx>
64 #include <Bnd_Box.hxx>
65 #include <BRepAdaptor_Curve2d.hxx>
68 Standard_Integer ComputeProps(const TopoDS_Face& aF,
72 void BuildTriangulation(const TopoDS_Face& aF);
74 //=======================================================================
77 //=======================================================================
78 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aW,
79 const TopoDS_Shape& aFace)
81 Standard_Boolean bIsHole;
82 Standard_Integer i, aNbS;
83 Standard_Real aT1, aT2, aS;
84 Standard_Real aU1, aU2, aU, dU;
85 Standard_Real aX1, aY1, aX0, aY0;
86 TopAbs_Orientation aOr;
88 gp_Pnt2d aP2D0, aP2D1;
89 Handle(Geom2d_Curve) aC2D;
93 bIsHole=Standard_False;
95 aF=TopoDS::Face(aFace);
97 aFF.Orientation(TopAbs_FORWARD);
101 for (; aItW.More(); aItW.Next()) {
102 const TopoDS_Edge& aE=TopoDS::Edge(aItW.Value());
103 aOr=aE.Orientation();
104 if (!(aOr==TopAbs_FORWARD ||
105 aOr==TopAbs_REVERSED)) {
109 aC2D=BRep_Tool::CurveOnSurface(aE, aFF, aT1, aT2);
114 BRepAdaptor_Curve2d aBAC2D(aE, aFF);
115 aNbS=Geom2dInt_Geom2dCurveTool::NbSamples(aBAC2D);
120 dU=(aT2-aT1)/(Standard_Real)(aNbS-1);
124 if (aOr==TopAbs_REVERSED) {
132 for(i=2; i<=aNbS; i++) {
135 aP2D0.Coord(aX0, aY0);
136 aP2D1.Coord(aX1, aY1);
138 aS=aS+(aY0+aY1)*(aX1-aX0);
142 }//for (; aItW.More(); aItW.Next()) {
146 //=======================================================================
149 //=======================================================================
150 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aShell)
152 Standard_Boolean bIsHole;
153 Standard_Integer iRet;
154 Standard_Real aAi, aA, aV, aVi;
155 TopExp_Explorer aExp;
159 aExp.Init(aShell, TopAbs_FACE);
160 for (; aExp.More(); aExp.Next()) {
161 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
162 iRet=ComputeProps(aF, aAi, aVi);
172 //=======================================================================
173 //function : ComputeProps
175 //=======================================================================
176 Standard_Integer ComputeProps(const TopoDS_Face& aF,
180 Standard_Integer j, i, i1, i2, aNbNodes, aNbTrigs, n[3];
181 Standard_Real aAi, aVi;
182 gp_Pnt aP[3], aGC, aGC1;
183 TopLoc_Location aLoc;
184 TopAbs_Orientation aOr;
185 Handle(Poly_Triangulation) aTri;
190 aTri=BRep_Tool::Triangulation(aF, aLoc);
192 BuildTriangulation(aF);
193 aTri=BRep_Tool::Triangulation(aF, aLoc);
195 return 1;// a face is without triangulation
199 aNbNodes=aTri->NbNodes();
200 aNbTrigs=aTri->NbTriangles();
202 return 2;//no triangles
205 aOr=aF.Orientation();
207 const TColgp_Array1OfPnt& aNodes=aTri->Nodes();
208 const Poly_Array1OfTriangle& aTriangles=aTri->Triangles();
210 i1=aTriangles.Lower();
211 i2=aTriangles.Upper();
213 for (i=i1; i<=i2; ++i){
214 const Poly_Triangle& aTriangle=aTriangles.Value(i);
215 aTriangle.Get(n[0], n[1], n[2]);
216 aGC.SetCoord(0.,0.,0.);
217 for (j=0; j<3; ++j) {
218 aP[j]=aNodes.Value(n[j]);
219 aGC.ChangeCoord()+=aP[j].XYZ();
221 aGC.ChangeCoord()*=0.333333333333;
224 gp_Vec aV01(aP[0], aP[1]);
225 gp_Vec aV12(aP[1], aP[2]);
226 gp_Vec aVN=aV01^aV12;
231 Standard_Real aSx, aZx;
233 if (aOr==TopAbs_REVERSED) {
245 //=======================================================================
246 //function : BuildTriangulation
248 //=======================================================================
249 void BuildTriangulation(const TopoDS_Face& aF)
251 Standard_Boolean bWithShare;
252 Standard_Real aDiscret, aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
253 Standard_Real dX, dY, dZ, dMax, aCoeff, aAngle;
256 bWithShare=Standard_False;
259 BRepBndLib::Add(aF, aBox);
262 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
275 aDiscret=aCoeff*dMax;
277 BRepMesh_FastDiscret aMesher(aDiscret,
285 #if OCC_VERSION_LARGE > 0x06050100 // for OCC-6.5.2 and higher version
286 TopTools_IndexedDataMapOfShapeListOfShape anAncestors;
287 TopExp::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, anAncestors);
288 aMesher.Add(aF, anAncestors);