0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / BRepMesh / BRepMesh_FaceAttribute.cxx
CommitLineData
b311480e 1// Created by: Ekaterina SMIRNOVA
973c2be1 2// Copyright (c) 2008-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
7fd59977 14
fc9b36d6 15#include <BRepMesh_FaceAttribute.hxx>
ceb418e1 16#include <TopoDS_Vertex.hxx>
17#include <BRepAdaptor_HSurface.hxx>
18#include <BRepMesh_ShapeTool.hxx>
19#include <BRepMesh_Classifier.hxx>
20#include <BRepTools.hxx>
e71669c6 21#include <TopExp_Explorer.hxx>
22#include <TopoDS_Wire.hxx>
23#include <TopoDS_Edge.hxx>
24#include <TopoDS.hxx>
25#include <TopoDS_Iterator.hxx>
26#include <BRep_Tool.hxx>
fc9b36d6 27
7fd59977 28
92efcf78 29IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_FaceAttribute,Standard_Transient)
30
7fd59977 31//=======================================================================
ceb418e1 32//function : Constructor
7fd59977 33//purpose :
34//=======================================================================
848fa7e3 35BRepMesh_FaceAttribute::BRepMesh_FaceAttribute()
36 : myDefFace (0.),
37 myUMin (0.),
38 myUMax (0.),
39 myVMin (0.),
40 myVMax (0.),
41 myDeltaX (1.),
42 myDeltaY (1.),
e71669c6 43 myMinStep (-1.),
44 myStatus (BRepMesh_NoError),
45 myAdaptiveMin (Standard_False)
848fa7e3 46{
47 init();
48}
49
50//=======================================================================
51//function : Constructor
52//purpose :
53//=======================================================================
ceb418e1 54BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
848fa7e3 55 const TopoDS_Face& theFace,
56 const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
e71669c6 57 const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints,
58 const Standard_Boolean theAdaptiveMin)
ceb418e1 59 : myDefFace (0.),
60 myUMin (0.),
61 myUMax (0.),
62 myVMin (0.),
63 myVMax (0.),
64 myDeltaX (1.),
65 myDeltaY (1.),
e71669c6 66 myMinStep (-1.),
ceb418e1 67 myStatus (BRepMesh_NoError),
e71669c6 68 myAdaptiveMin (theAdaptiveMin),
ceb418e1 69 myBoundaryVertices(theBoundaryVertices),
70 myBoundaryPoints (theBoundaryPoints),
2caff0b3 71 myFace (theFace)
7fd59977 72{
848fa7e3 73 init();
ceb418e1 74}
75
76//=======================================================================
77//function : Destructor
78//purpose :
79//=======================================================================
80BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
81{
ceb418e1 82}
83
84//=======================================================================
848fa7e3 85//function : init
86//purpose :
87//=======================================================================
88void BRepMesh_FaceAttribute::init()
89{
90 myVertexEdgeMap = new BRepMesh::IMapOfInteger;
91 myInternalEdges = new BRepMesh::DMapOfShapePairOfPolygon;
2caff0b3 92 myLocation2D = new BRepMesh::DMapOfIntegerListOfXY;
848fa7e3 93 myClassifier = new BRepMesh_Classifier;
94
2caff0b3 95 if (myFace.IsNull())
96 return;
848fa7e3 97
2caff0b3 98 BRepTools::Update(myFace);
99 myFace.Orientation(TopAbs_FORWARD);
100 BRepTools::UVBounds(myFace, myUMin, myUMax, myVMin, myVMax);
848fa7e3 101
e71669c6 102 if (myAdaptiveMin)
103 {
104 // compute minimal UV distance
105 // between vertices
106
107 myMinStep = RealLast();
108 for (TopExp_Explorer anExp(myFace, TopAbs_WIRE); anExp.More(); anExp.Next())
109 {
110 TopoDS_Wire aWire = TopoDS::Wire(anExp.Current());
111
112 for (TopoDS_Iterator aWireExp(aWire); aWireExp.More(); aWireExp.Next())
113 {
114 TopoDS_Edge anEdge = TopoDS::Edge(aWireExp.Value());
115 if (BRep_Tool::IsClosed(anEdge))
116 continue;
117
118 // Get end points on 2d curve
119 gp_Pnt2d aFirst2d, aLast2d;
120 BRep_Tool::UVPoints(anEdge, myFace, aFirst2d, aLast2d);
121 Standard_Real aDist =aFirst2d.Distance(aLast2d);
122 if (aDist < myMinStep)
123 myMinStep = aDist;
124 }
125 }
126 }
127
2caff0b3 128 BRepAdaptor_Surface aSurfAdaptor(myFace, Standard_False);
129 mySurface = new BRepAdaptor_HSurface(aSurfAdaptor);
848fa7e3 130}
131
132//=======================================================================
fcf15f5c 133//function : Clear
ceb418e1 134//purpose :
135//=======================================================================
2caff0b3 136void BRepMesh_FaceAttribute::Clear()
ceb418e1 137{
fcf15f5c 138 myStructure.Nullify();
2caff0b3 139 myLocation2D->Clear();
140 myInternalEdges->Clear();
141 myVertexEdgeMap->Clear();
ceb418e1 142}
143
144//=======================================================================
145//function : computeParametricTolerance
146//purpose :
147//=======================================================================
148Standard_Real BRepMesh_FaceAttribute::computeParametricTolerance(
149 const Standard_Real theFirstParam,
150 const Standard_Real theLastParam) const
151{
152 const Standard_Real aDeflectionUV = 1.e-05;
e71669c6 153 Standard_Real aPreci = (theLastParam - theFirstParam) * aDeflectionUV;
154 if(myAdaptiveMin && myMinStep < aPreci)
155 aPreci = myMinStep;
156
157 return Max(Precision::PConfusion(), aPreci);
ceb418e1 158}
159
160//=======================================================================
161//function : getVertexIndex
162//purpose :
163//=======================================================================
164Standard_Boolean BRepMesh_FaceAttribute::getVertexIndex(
165 const TopoDS_Vertex& theVertex,
166 Standard_Integer& theVertexIndex) const
167{
848fa7e3 168 if (!myBoundaryVertices.IsNull() && myBoundaryVertices->IsBound(theVertex))
169 theVertexIndex = myBoundaryVertices->Find(theVertex);
2caff0b3 170 else if (!mySurfaceVertices.IsNull() && mySurfaceVertices->IsBound(theVertex))
171 theVertexIndex = mySurfaceVertices->Find(theVertex);
ceb418e1 172 else
173 return Standard_False;
174
175 return Standard_True;
176}
177
178//=======================================================================
179//function : AddNode
180//purpose :
181//=======================================================================
182void BRepMesh_FaceAttribute::AddNode(
183 const Standard_Integer theIndex,
184 const gp_XY& theUV,
185 const BRepMesh_DegreeOfFreedom theMovability,
186 Standard_Integer& theNodeIndex,
187 Standard_Integer& theNodeOnEdgeIndex)
188{
189 BRepMesh_Vertex aNode(theUV, theIndex, theMovability);
190 theNodeIndex = myStructure->AddNode(aNode);
191 theNodeOnEdgeIndex = myVertexEdgeMap->FindIndex(theNodeIndex);
192 if (theNodeOnEdgeIndex == 0)
193 theNodeOnEdgeIndex = myVertexEdgeMap->Add(theNodeIndex);
194}
195
196//=======================================================================
197//function : Scale
198//purpose :
199//=======================================================================
200gp_XY BRepMesh_FaceAttribute::Scale(const gp_XY& thePoint2d,
201 const Standard_Boolean isToFaceBasis)
202{
203 return isToFaceBasis ?
204 gp_XY((thePoint2d.X() - myUMin) / myDeltaX, (thePoint2d.Y() - myVMin) / myDeltaY) :
205 gp_XY(thePoint2d.X() * myDeltaX + myUMin, thePoint2d.Y() * myDeltaY + myVMin);
7fd59977 206}
848fa7e3 207
208//=======================================================================
209//function : ToleranceU
210//purpose :
211//=======================================================================
212Standard_Real BRepMesh_FaceAttribute::ToleranceU() const
213{
214 return computeParametricTolerance(myUMin, myUMax);
215}
216
217//=======================================================================
218//function : ToleranceV
219//purpose :
220//=======================================================================
221Standard_Real BRepMesh_FaceAttribute::ToleranceV() const
222{
223 return computeParametricTolerance(myVMin, myVMax);
224}