1 // Created by: Ekaterina SMIRNOVA
2 // Copyright (c) 2008-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
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 #include <TopExp_Explorer.hxx>
22 #include <TopoDS_Wire.hxx>
23 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Iterator.hxx>
26 #include <BRep_Tool.hxx>
29 //=======================================================================
30 //function : Constructor
32 //=======================================================================
33 BRepMesh_FaceAttribute::BRepMesh_FaceAttribute()
42 myStatus (BRepMesh_NoError),
43 myAdaptiveMin (Standard_False)
48 //=======================================================================
49 //function : Constructor
51 //=======================================================================
52 BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
53 const TopoDS_Face& theFace,
54 const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
55 const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints,
56 const Standard_Boolean theAdaptiveMin)
65 myStatus (BRepMesh_NoError),
66 myAdaptiveMin (theAdaptiveMin),
67 myBoundaryVertices(theBoundaryVertices),
68 myBoundaryPoints (theBoundaryPoints),
74 //=======================================================================
75 //function : Destructor
77 //=======================================================================
78 BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
82 //=======================================================================
85 //=======================================================================
86 void BRepMesh_FaceAttribute::init()
88 myVertexEdgeMap = new BRepMesh::IMapOfInteger;
89 myInternalEdges = new BRepMesh::DMapOfShapePairOfPolygon;
90 myLocation2D = new BRepMesh::DMapOfIntegerListOfXY;
91 myClassifier = new BRepMesh_Classifier;
96 BRepTools::Update(myFace);
97 myFace.Orientation(TopAbs_FORWARD);
98 BRepTools::UVBounds(myFace, myUMin, myUMax, myVMin, myVMax);
102 // compute minimal UV distance
105 myMinStep = RealLast();
106 for (TopExp_Explorer anExp(myFace, TopAbs_WIRE); anExp.More(); anExp.Next())
108 TopoDS_Wire aWire = TopoDS::Wire(anExp.Current());
110 for (TopoDS_Iterator aWireExp(aWire); aWireExp.More(); aWireExp.Next())
112 TopoDS_Edge anEdge = TopoDS::Edge(aWireExp.Value());
113 if (BRep_Tool::IsClosed(anEdge))
116 // Get end points on 2d curve
117 gp_Pnt2d aFirst2d, aLast2d;
118 BRep_Tool::UVPoints(anEdge, myFace, aFirst2d, aLast2d);
119 Standard_Real aDist =aFirst2d.Distance(aLast2d);
120 if (aDist < myMinStep)
126 BRepAdaptor_Surface aSurfAdaptor(myFace, Standard_False);
127 mySurface = new BRepAdaptor_HSurface(aSurfAdaptor);
130 //=======================================================================
133 //=======================================================================
134 void BRepMesh_FaceAttribute::Clear()
136 myStructure.Nullify();
137 myLocation2D->Clear();
138 myInternalEdges->Clear();
139 myVertexEdgeMap->Clear();
142 //=======================================================================
143 //function : computeParametricTolerance
145 //=======================================================================
146 Standard_Real BRepMesh_FaceAttribute::computeParametricTolerance(
147 const Standard_Real theFirstParam,
148 const Standard_Real theLastParam) const
150 const Standard_Real aDeflectionUV = 1.e-05;
151 Standard_Real aPreci = (theLastParam - theFirstParam) * aDeflectionUV;
152 if(myAdaptiveMin && myMinStep < aPreci)
155 return Max(Precision::PConfusion(), aPreci);
158 //=======================================================================
159 //function : getVertexIndex
161 //=======================================================================
162 Standard_Boolean BRepMesh_FaceAttribute::getVertexIndex(
163 const TopoDS_Vertex& theVertex,
164 Standard_Integer& theVertexIndex) const
166 if (!myBoundaryVertices.IsNull() && myBoundaryVertices->IsBound(theVertex))
167 theVertexIndex = myBoundaryVertices->Find(theVertex);
168 else if (!mySurfaceVertices.IsNull() && mySurfaceVertices->IsBound(theVertex))
169 theVertexIndex = mySurfaceVertices->Find(theVertex);
171 return Standard_False;
173 return Standard_True;
176 //=======================================================================
179 //=======================================================================
180 void BRepMesh_FaceAttribute::AddNode(
181 const Standard_Integer theIndex,
183 const BRepMesh_DegreeOfFreedom theMovability,
184 Standard_Integer& theNodeIndex,
185 Standard_Integer& theNodeOnEdgeIndex)
187 BRepMesh_Vertex aNode(theUV, theIndex, theMovability);
188 theNodeIndex = myStructure->AddNode(aNode);
189 theNodeOnEdgeIndex = myVertexEdgeMap->FindIndex(theNodeIndex);
190 if (theNodeOnEdgeIndex == 0)
191 theNodeOnEdgeIndex = myVertexEdgeMap->Add(theNodeIndex);
194 //=======================================================================
197 //=======================================================================
198 gp_XY BRepMesh_FaceAttribute::Scale(const gp_XY& thePoint2d,
199 const Standard_Boolean isToFaceBasis)
201 return isToFaceBasis ?
202 gp_XY((thePoint2d.X() - myUMin) / myDeltaX, (thePoint2d.Y() - myVMin) / myDeltaY) :
203 gp_XY(thePoint2d.X() * myDeltaX + myUMin, thePoint2d.Y() * myDeltaY + myVMin);
206 //=======================================================================
207 //function : ToleranceU
209 //=======================================================================
210 Standard_Real BRepMesh_FaceAttribute::ToleranceU() const
212 return computeParametricTolerance(myUMin, myUMax);
215 //=======================================================================
216 //function : ToleranceV
218 //=======================================================================
219 Standard_Real BRepMesh_FaceAttribute::ToleranceV() const
221 return computeParametricTolerance(myVMin, myVMax);