43e5dceb1d6b5b0c1643dd129d5e3b4ecc7989da
[occt.git] / src / BRepMesh / BRepMesh_FaceAttribute.cxx
1 // Created by: Ekaterina SMIRNOVA
2 // Copyright (c) 2008-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License 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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <BRepMesh_FaceAttribute.hxx>
16 #include <TopoDS_Vertex.hxx>
17 #include <BRepAdaptor_HSurface.hxx>
18 #include <BRepMesh_ShapeTool.hxx>
19 #include <BRepMesh_Classifier.hxx>
20 #include <BRepTools.hxx>
21
22 IMPLEMENT_STANDARD_HANDLE (BRepMesh_FaceAttribute, Standard_Transient)
23 IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_FaceAttribute, Standard_Transient)
24
25 //=======================================================================
26 //function : Constructor
27 //purpose  : 
28 //=======================================================================
29 BRepMesh_FaceAttribute::BRepMesh_FaceAttribute()
30   : myDefFace         (0.),
31     myUMin            (0.),
32     myUMax            (0.),
33     myVMin            (0.),
34     myVMax            (0.),
35     myDeltaX          (1.),
36     myDeltaY          (1.),
37     myStatus          (BRepMesh_NoError)
38 {
39   init();
40 }
41
42 //=======================================================================
43 //function : Constructor
44 //purpose  : 
45 //=======================================================================
46 BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
47   const TopoDS_Face&                    theFace,
48   const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
49   const BRepMesh::HDMapOfIntegerPnt&    theBoundaryPoints)
50   : myDefFace         (0.),
51     myUMin            (0.),
52     myUMax            (0.),
53     myVMin            (0.),
54     myVMax            (0.),
55     myDeltaX          (1.),
56     myDeltaY          (1.),
57     myStatus          (BRepMesh_NoError),
58     myBoundaryVertices(theBoundaryVertices),
59     myBoundaryPoints  (theBoundaryPoints),
60     myFace            (theFace)
61 {
62   init();
63 }
64
65 //=======================================================================
66 //function : Destructor
67 //purpose  : 
68 //=======================================================================
69 BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
70 {
71 }
72
73 //=======================================================================
74 //function : init
75 //purpose  : 
76 //=======================================================================
77 void BRepMesh_FaceAttribute::init()
78 {
79   myVertexEdgeMap = new BRepMesh::IMapOfInteger;
80   myInternalEdges = new BRepMesh::DMapOfShapePairOfPolygon;
81   myLocation2D    = new BRepMesh::DMapOfIntegerListOfXY;
82   myClassifier    = new BRepMesh_Classifier;
83
84   if (myFace.IsNull())
85     return;
86
87   BRepTools::Update(myFace);
88   myFace.Orientation(TopAbs_FORWARD);
89   BRepTools::UVBounds(myFace, myUMin, myUMax, myVMin, myVMax);
90
91   BRepAdaptor_Surface aSurfAdaptor(myFace, Standard_False);
92   mySurface = new BRepAdaptor_HSurface(aSurfAdaptor);
93 }
94
95 //=======================================================================
96 //function : Clear
97 //purpose  : 
98 //=======================================================================
99 void BRepMesh_FaceAttribute::Clear()
100 {
101   myStructure.Nullify();
102   myLocation2D->Clear();
103   myInternalEdges->Clear();
104   myVertexEdgeMap->Clear();
105 }
106
107 //=======================================================================
108 //function : computeParametricTolerance
109 //purpose  : 
110 //=======================================================================
111 Standard_Real BRepMesh_FaceAttribute::computeParametricTolerance(
112   const Standard_Real theFirstParam,
113   const Standard_Real theLastParam) const
114 {
115   const Standard_Real aDeflectionUV = 1.e-05;
116   return Max(Precision::PConfusion(), (theLastParam - theFirstParam) * aDeflectionUV);
117 }
118
119 //=======================================================================
120 //function : getVertexIndex
121 //purpose  : 
122 //=======================================================================
123 Standard_Boolean BRepMesh_FaceAttribute::getVertexIndex(
124   const TopoDS_Vertex& theVertex,
125   Standard_Integer&    theVertexIndex) const
126 {
127   if (!myBoundaryVertices.IsNull() && myBoundaryVertices->IsBound(theVertex))
128     theVertexIndex = myBoundaryVertices->Find(theVertex);
129   else if (!mySurfaceVertices.IsNull() && mySurfaceVertices->IsBound(theVertex))
130     theVertexIndex = mySurfaceVertices->Find(theVertex);
131   else
132     return Standard_False;
133
134   return Standard_True;
135 }
136
137 //=======================================================================
138 //function : AddNode
139 //purpose  : 
140 //=======================================================================
141 void BRepMesh_FaceAttribute::AddNode(
142   const Standard_Integer         theIndex,
143   const gp_XY&                   theUV,
144   const BRepMesh_DegreeOfFreedom theMovability,
145   Standard_Integer&              theNodeIndex,
146   Standard_Integer&              theNodeOnEdgeIndex)
147 {
148   BRepMesh_Vertex aNode(theUV, theIndex, theMovability);
149   theNodeIndex = myStructure->AddNode(aNode);
150   theNodeOnEdgeIndex = myVertexEdgeMap->FindIndex(theNodeIndex);
151   if (theNodeOnEdgeIndex == 0)
152     theNodeOnEdgeIndex = myVertexEdgeMap->Add(theNodeIndex);
153 }
154
155 //=======================================================================
156 //function : Scale
157 //purpose  : 
158 //=======================================================================
159 gp_XY BRepMesh_FaceAttribute::Scale(const gp_XY&           thePoint2d,
160                                     const Standard_Boolean isToFaceBasis)
161 {
162   return isToFaceBasis ?
163     gp_XY((thePoint2d.X() - myUMin) / myDeltaX, (thePoint2d.Y() - myVMin) / myDeltaY) :
164     gp_XY(thePoint2d.X() * myDeltaX + myUMin, thePoint2d.Y() * myDeltaY + myVMin);
165 }
166
167 //=======================================================================
168 //function : ToleranceU
169 //purpose  : 
170 //=======================================================================
171 Standard_Real BRepMesh_FaceAttribute::ToleranceU() const
172 {
173   return computeParametricTolerance(myUMin, myUMax);
174 }
175
176 //=======================================================================
177 //function : ToleranceV
178 //purpose  : 
179 //=======================================================================
180 Standard_Real BRepMesh_FaceAttribute::ToleranceV() const
181 {
182   return computeParametricTolerance(myVMin, myVMax);
183 }