1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_BuilderTools.cxx
22 // Author: Peter KURNEV
26 #include <GEOMAlgo_BuilderTools.ixx>
28 #include <TColStd_Array1OfReal.hxx>
30 #include <gp_Pnt2d.hxx>
35 #include <TColgp_Array1OfPnt.hxx>
37 #include <Poly_Triangulation.hxx>
38 #include <Poly_Array1OfTriangle.hxx>
39 #include <Poly_Triangle.hxx>
41 #include <Geom2d_Curve.hxx>
42 #include <Geom2dInt_Geom2dCurveTool.hxx>
44 #include <TopLoc_Location.hxx>
45 #include <TopAbs_Orientation.hxx>
47 #include <TopoDS_Face.hxx>
48 #include <TopoDS_Iterator.hxx>
49 #include <TopoDS_Wire.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <TopExp_Explorer.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRepBndLib.hxx>
56 #include <BRepMesh_FastDiscret.hxx>
57 #include <Bnd_Box.hxx>
58 #include <BRepAdaptor_Curve2d.hxx>
61 Standard_Integer ComputeProps(const TopoDS_Face& aF,
65 void BuildTriangulation(const TopoDS_Face& aF);
67 //=======================================================================
70 //=======================================================================
71 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aW,
72 const TopoDS_Shape& aFace)
74 Standard_Boolean bIsHole;
75 Standard_Integer i, aNbS;
76 Standard_Real aT1, aT2, aS;
77 Standard_Real aU1, aU2, aU, dU;
78 Standard_Real aX1, aY1, aX0, aY0;
79 TopAbs_Orientation aOr;
81 gp_Pnt2d aP2D0, aP2D1;
82 Handle(Geom2d_Curve) aC2D;
86 bIsHole=Standard_False;
88 aF=TopoDS::Face(aFace);
90 aFF.Orientation(TopAbs_FORWARD);
94 for (; aItW.More(); aItW.Next()) {
95 const TopoDS_Edge& aE=TopoDS::Edge(aItW.Value());
97 if (!(aOr==TopAbs_FORWARD ||
98 aOr==TopAbs_REVERSED)) {
102 aC2D=BRep_Tool::CurveOnSurface(aE, aFF, aT1, aT2);
107 BRepAdaptor_Curve2d aBAC2D(aE, aFF);
108 aNbS=Geom2dInt_Geom2dCurveTool::NbSamples(aBAC2D);
113 dU=(aT2-aT1)/(Standard_Real)(aNbS-1);
117 if (aOr==TopAbs_REVERSED) {
125 for(i=2; i<=aNbS; i++) {
128 aP2D0.Coord(aX0, aY0);
129 aP2D1.Coord(aX1, aY1);
131 aS=aS+(aY0+aY1)*(aX1-aX0);
135 }//for (; aItW.More(); aItW.Next()) {
139 //=======================================================================
142 //=======================================================================
143 Standard_Boolean GEOMAlgo_BuilderTools::IsHole(const TopoDS_Shape& aShell)
145 Standard_Boolean bIsHole;
146 Standard_Integer iRet;
147 Standard_Real aAi, aA, aV, aVi;
148 TopExp_Explorer aExp;
152 aExp.Init(aShell, TopAbs_FACE);
153 for (; aExp.More(); aExp.Next()) {
154 const TopoDS_Face& aF=TopoDS::Face(aExp.Current());
155 iRet=ComputeProps(aF, aAi, aVi);
165 //=======================================================================
166 //function : ComputeProps
168 //=======================================================================
169 Standard_Integer ComputeProps(const TopoDS_Face& aF,
173 Standard_Integer j, i, i1, i2, aNbNodes, aNbTrigs, n[3];
174 Standard_Real aAi, aVi;
175 gp_Pnt aP[3], aGC, aGC1;
176 TopLoc_Location aLoc;
177 TopAbs_Orientation aOr;
178 Handle(Poly_Triangulation) aTri;
183 aTri=BRep_Tool::Triangulation(aF, aLoc);
185 BuildTriangulation(aF);
186 aTri=BRep_Tool::Triangulation(aF, aLoc);
188 return 1;// a face is without triangulation
192 aNbNodes=aTri->NbNodes();
193 aNbTrigs=aTri->NbTriangles();
195 return 2;//no triangles
198 aOr=aF.Orientation();
200 const TColgp_Array1OfPnt& aNodes=aTri->Nodes();
201 const Poly_Array1OfTriangle& aTriangles=aTri->Triangles();
203 i1=aTriangles.Lower();
204 i2=aTriangles.Upper();
206 for (i=i1; i<=i2; ++i){
207 const Poly_Triangle& aTriangle=aTriangles.Value(i);
208 aTriangle.Get(n[0], n[1], n[2]);
209 aGC.SetCoord(0.,0.,0.);
210 for (j=0; j<3; ++j) {
211 aP[j]=aNodes.Value(n[j]);
212 aGC.ChangeCoord()+=aP[j].XYZ();
214 aGC.ChangeCoord()*=0.333333333333;
217 gp_Vec aV01(aP[0], aP[1]);
218 gp_Vec aV12(aP[1], aP[2]);
219 gp_Vec aVN=aV01^aV12;
224 Standard_Real aSx, aZx;
226 if (aOr==TopAbs_REVERSED) {
238 //=======================================================================
239 //function : BuildTriangulation
241 //=======================================================================
242 void BuildTriangulation(const TopoDS_Face& aF)
244 Standard_Boolean bWithShare;
245 Standard_Real aDiscret, aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
246 Standard_Real dX, dY, dZ, dMax, aCoeff, aAngle;
249 bWithShare=Standard_False;
252 BRepBndLib::Add(aF, aBox);
255 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
268 aDiscret=aCoeff*dMax;
270 BRepMesh_FastDiscret aMesher(aDiscret,