0024428: Implementation of LGPL license
[occt.git] / src / BRepMesh / BRepMesh_ShapeTool.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
973c2be1 6// This library is free software; you can redistribute it and / or modify it
7// under the terms of the GNU Lesser General Public version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15#include <BRepMesh_ShapeTool.ixx>
16#include <Geom2d_Curve.hxx>
17#include <BRep_Tool.hxx>
18#include <TopoDS.hxx>
19#include <BRepAdaptor_Surface.hxx>
20#include <BRepAdaptor_Curve.hxx>
21#include <Adaptor3d_CurveOnSurface.hxx>
22#include <Adaptor2d_HCurve2d.hxx>
23#include <BRepBndLib.hxx>
24#include <Extrema_POnCurv.hxx>
25#include <Extrema_LocateExtPC.hxx>
26#include <TopExp.hxx>
27#include <Precision.hxx>
28#include <gp_Trsf.hxx>
29#include <BRep_Builder.hxx>
30
31Standard_Integer debug=0;
32
33BRepMesh_ShapeTool::BRepMesh_ShapeTool() {}
34
35Standard_Boolean BRepMesh_ShapeTool::MoreInternalVertex()
36{
37 while (theVIterator.More()) {
38 if (theVIterator.Current().Orientation() == TopAbs_INTERNAL)
39 return Standard_True;
40 theVIterator.Next();
41 }
42 return Standard_False;
43}
44
45
46TopoDS_Vertex BRepMesh_ShapeTool::FirstVertex(const TopoDS_Edge& E)
47{
48 TopExp_Explorer Ex(E,TopAbs_VERTEX);
49 while (Ex.More()) {
50 if (Ex.Current().Orientation() == TopAbs_FORWARD)
51 return TopoDS::Vertex(Ex.Current());
52 Ex.Next();
53 }
54 Standard_NoSuchObject::Raise("non existent first vertex");
55 return TopoDS_Vertex();
56}
57
58TopoDS_Vertex BRepMesh_ShapeTool::LastVertex(const TopoDS_Edge& E)
59{
60 TopExp_Explorer Ex(E,TopAbs_VERTEX);
61 while (Ex.More()) {
62 if (Ex.Current().Orientation() == TopAbs_REVERSED)
63 return TopoDS::Vertex(Ex.Current());
64 Ex.Next();
65 }
66 Standard_NoSuchObject::Raise("non existent last vertex");
67 return TopoDS_Vertex();
68}
69
70void BRepMesh_ShapeTool::Vertices(const TopoDS_Edge& E,
71 TopoDS_Vertex& Vfirst,
72 TopoDS_Vertex& Vlast)
73{
74 TopExp::Vertices(E, Vfirst, Vlast);
75}
76
77Bnd_Box BRepMesh_ShapeTool::Bound(const TopoDS_Face& F)
78{
79 Bnd_Box Bf;
80 BRepBndLib::Add(F, Bf);
81 return Bf;
82}
83
84Bnd_Box BRepMesh_ShapeTool::Bound(const TopoDS_Edge& E)
85{
86 Bnd_Box Be;
87 BRepBndLib::Add(E, Be);
88 return Be;
89}
90
91void BRepMesh_ShapeTool::Parameters(const TopoDS_Edge& E,
92 const TopoDS_Face& F,
93 const Standard_Real W,
94 gp_Pnt2d& UV)
95{
96 Standard_Real a,b;
97 Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,a,b);
98 C->D0(W,UV);
99}
100
101void BRepMesh_ShapeTool::Locate(const BRepAdaptor_Curve& C,
102 const Standard_Real W,
103 Standard_Real& wFound,
104 const gp_Pnt& p3d,
105 gp_Pnt2d& UV)
106{
107 gp_Pnt plocal(p3d.Transformed(C.Trsf().Inverted()));
108 Extrema_LocateExtPC
109 pcos(plocal, C.CurveOnSurface(), W, Precision::PConfusion());
110 if (pcos.IsDone()) {
111 wFound=pcos.Point().Parameter();
112 C.CurveOnSurface().GetCurve()->D0(wFound, UV);
113 if (debug!=0) {
114 if (pcos.SquareDistance()>(4.* C.Tolerance()* C.Tolerance())) {
115 cout << " ShapeTool :LocateExtPCOnS Done but (Distance "<<
116 sqrt(pcos.SquareDistance()) << ")(Tolerance "<<C.Tolerance()<<")" << endl;
117 cout << " W given : "<< W<< " W calculated : "<<
118 wFound << endl;
119 }
120 else if (debug>1) {
121 cout << " ShapeTool : LocateExtPCOnS OK ! "<<endl;
122 cout << " W given : "<< W<< " W calculated : "<<
123 wFound << endl;
124 }
125 }
126 }
127 else {
128 wFound=W;
129 if (debug!=0)
130 cout << " ShapeTool : LocateExtPCOnS Not Done ! " << endl;
131 C.CurveOnSurface().GetCurve()->D0(W, UV);
132 }
133}
134
135
136void BRepMesh_ShapeTool::AddInFace(const TopoDS_Face& F,
137 Handle(Poly_Triangulation)& T)
138{
139 static BRep_Builder B1;
140 TColgp_Array1OfPnt& Nodes = T->ChangeNodes();
141 gp_Trsf tr = F.Location().Transformation();
142 tr.Invert();
143 for (Standard_Integer i = Nodes.Lower(); i <= Nodes.Upper(); i++)
144 Nodes(i).Transform(tr);
145 B1.UpdateFace(F, T);
146}