1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <BRepMesh_ShapeTool.ixx>
20 #include <Geom2d_Curve.hxx>
21 #include <BRep_Tool.hxx>
23 #include <BRepAdaptor_Surface.hxx>
24 #include <BRepAdaptor_Curve.hxx>
25 #include <Adaptor3d_CurveOnSurface.hxx>
26 #include <Adaptor2d_HCurve2d.hxx>
27 #include <BRepBndLib.hxx>
28 #include <Extrema_POnCurv.hxx>
29 #include <Extrema_LocateExtPC.hxx>
31 #include <Precision.hxx>
32 #include <gp_Trsf.hxx>
33 #include <BRep_Builder.hxx>
35 Standard_Integer debug=0;
37 BRepMesh_ShapeTool::BRepMesh_ShapeTool() {}
39 Standard_Boolean BRepMesh_ShapeTool::MoreInternalVertex()
41 while (theVIterator.More()) {
42 if (theVIterator.Current().Orientation() == TopAbs_INTERNAL)
46 return Standard_False;
50 TopoDS_Vertex BRepMesh_ShapeTool::FirstVertex(const TopoDS_Edge& E)
52 TopExp_Explorer Ex(E,TopAbs_VERTEX);
54 if (Ex.Current().Orientation() == TopAbs_FORWARD)
55 return TopoDS::Vertex(Ex.Current());
58 Standard_NoSuchObject::Raise("non existent first vertex");
59 return TopoDS_Vertex();
62 TopoDS_Vertex BRepMesh_ShapeTool::LastVertex(const TopoDS_Edge& E)
64 TopExp_Explorer Ex(E,TopAbs_VERTEX);
66 if (Ex.Current().Orientation() == TopAbs_REVERSED)
67 return TopoDS::Vertex(Ex.Current());
70 Standard_NoSuchObject::Raise("non existent last vertex");
71 return TopoDS_Vertex();
74 void BRepMesh_ShapeTool::Vertices(const TopoDS_Edge& E,
75 TopoDS_Vertex& Vfirst,
78 TopExp::Vertices(E, Vfirst, Vlast);
81 Bnd_Box BRepMesh_ShapeTool::Bound(const TopoDS_Face& F)
84 BRepBndLib::Add(F, Bf);
88 Bnd_Box BRepMesh_ShapeTool::Bound(const TopoDS_Edge& E)
91 BRepBndLib::Add(E, Be);
95 void BRepMesh_ShapeTool::Parameters(const TopoDS_Edge& E,
97 const Standard_Real W,
101 Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,a,b);
105 void BRepMesh_ShapeTool::Locate(const BRepAdaptor_Curve& C,
106 const Standard_Real W,
107 Standard_Real& wFound,
111 gp_Pnt plocal(p3d.Transformed(C.Trsf().Inverted()));
113 pcos(plocal, C.CurveOnSurface(), W, Precision::PConfusion());
115 wFound=pcos.Point().Parameter();
116 C.CurveOnSurface().GetCurve()->D0(wFound, UV);
118 if (pcos.SquareDistance()>(4.* C.Tolerance()* C.Tolerance())) {
119 cout << " ShapeTool :LocateExtPCOnS Done but (Distance "<<
120 sqrt(pcos.SquareDistance()) << ")(Tolerance "<<C.Tolerance()<<")" << endl;
121 cout << " W given : "<< W<< " W calculated : "<<
125 cout << " ShapeTool : LocateExtPCOnS OK ! "<<endl;
126 cout << " W given : "<< W<< " W calculated : "<<
134 cout << " ShapeTool : LocateExtPCOnS Not Done ! " << endl;
135 C.CurveOnSurface().GetCurve()->D0(W, UV);
140 void BRepMesh_ShapeTool::AddInFace(const TopoDS_Face& F,
141 Handle(Poly_Triangulation)& T)
143 static BRep_Builder B1;
144 TColgp_Array1OfPnt& Nodes = T->ChangeNodes();
145 gp_Trsf tr = F.Location().Transformation();
147 for (Standard_Integer i = Nodes.Lower(); i <= Nodes.Upper(); i++)
148 Nodes(i).Transform(tr);