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 IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_FaceAttribute,Standard_Transient)
31 //=======================================================================
32 //function : Constructor
34 //=======================================================================
35 BRepMesh_FaceAttribute::BRepMesh_FaceAttribute()
44 myStatus (BRepMesh_NoError),
45 myAdaptiveMin (Standard_False)
50 //=======================================================================
51 //function : Constructor
53 //=======================================================================
54 BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
55 const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
56 const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints)
65 myStatus (BRepMesh_NoError),
66 myAdaptiveMin (Standard_False),
67 myBoundaryVertices(theBoundaryVertices),
68 myBoundaryPoints (theBoundaryPoints)
72 //=======================================================================
73 //function : Constructor
75 //=======================================================================
76 BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
77 const TopoDS_Face& theFace,
78 const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
79 const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints,
80 const Standard_Boolean theAdaptiveMin)
89 myStatus (BRepMesh_NoError),
90 myAdaptiveMin (theAdaptiveMin),
91 myBoundaryVertices(theBoundaryVertices),
92 myBoundaryPoints (theBoundaryPoints),
98 //=======================================================================
99 //function : Destructor
101 //=======================================================================
102 BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
106 //=======================================================================
109 //=======================================================================
110 void BRepMesh_FaceAttribute::SetFace (
111 const TopoDS_Face& theFace,
112 const Standard_Boolean theAdaptiveMin)
115 myAdaptiveMin = theAdaptiveMin;
120 //=======================================================================
123 //=======================================================================
124 void BRepMesh_FaceAttribute::init()
126 myVertexEdgeMap = new BRepMesh::IMapOfInteger;
127 myInternalEdges = new BRepMesh::DMapOfShapePairOfPolygon;
128 myLocation2D = new BRepMesh::DMapOfIntegerListOfXY;
129 myClassifier = new BRepMesh_Classifier;
134 BRepTools::Update(myFace);
135 myFace.Orientation(TopAbs_FORWARD);
136 BRepTools::UVBounds(myFace, myUMin, myUMax, myVMin, myVMax);
140 // compute minimal UV distance
143 myMinStep = RealLast();
144 for (TopExp_Explorer anExp(myFace, TopAbs_WIRE); anExp.More(); anExp.Next())
146 TopoDS_Wire aWire = TopoDS::Wire(anExp.Current());
148 for (TopoDS_Iterator aWireExp(aWire); aWireExp.More(); aWireExp.Next())
150 TopoDS_Edge anEdge = TopoDS::Edge(aWireExp.Value());
151 if (BRep_Tool::IsClosed(anEdge))
154 // Get end points on 2d curve
155 gp_Pnt2d aFirst2d, aLast2d;
156 BRep_Tool::UVPoints(anEdge, myFace, aFirst2d, aLast2d);
157 Standard_Real aDist =aFirst2d.Distance(aLast2d);
158 if (aDist < myMinStep)
164 BRepAdaptor_Surface aSurfAdaptor(myFace, Standard_False);
165 mySurface = new BRepAdaptor_HSurface(aSurfAdaptor);
168 //=======================================================================
171 //=======================================================================
172 void BRepMesh_FaceAttribute::Clear()
174 myStructure.Nullify();
175 myLocation2D->Clear();
176 myInternalEdges->Clear();
177 myVertexEdgeMap->Clear();
180 //=======================================================================
181 //function : computeParametricTolerance
183 //=======================================================================
184 Standard_Real BRepMesh_FaceAttribute::computeParametricTolerance(
185 const Standard_Real theFirstParam,
186 const Standard_Real theLastParam) const
188 const Standard_Real aDeflectionUV = 1.e-05;
189 Standard_Real aPreci = (theLastParam - theFirstParam) * aDeflectionUV;
190 if(myAdaptiveMin && myMinStep < aPreci)
193 return Max(Precision::PConfusion(), aPreci);
196 //=======================================================================
197 //function : getVertexIndex
199 //=======================================================================
200 Standard_Boolean BRepMesh_FaceAttribute::getVertexIndex(
201 const TopoDS_Vertex& theVertex,
202 Standard_Integer& theVertexIndex) const
204 if (!myBoundaryVertices.IsNull() && myBoundaryVertices->IsBound(theVertex))
205 theVertexIndex = myBoundaryVertices->Find(theVertex);
206 else if (!mySurfaceVertices.IsNull() && mySurfaceVertices->IsBound(theVertex))
207 theVertexIndex = mySurfaceVertices->Find(theVertex);
209 return Standard_False;
211 return Standard_True;
214 //=======================================================================
217 //=======================================================================
218 void BRepMesh_FaceAttribute::AddNode(
219 const Standard_Integer theIndex,
221 const BRepMesh_DegreeOfFreedom theMovability,
222 Standard_Integer& theNodeIndex,
223 Standard_Integer& theNodeOnEdgeIndex)
225 BRepMesh_Vertex aNode(theUV, theIndex, theMovability);
226 theNodeIndex = myStructure->AddNode(aNode);
227 theNodeOnEdgeIndex = myVertexEdgeMap->FindIndex(theNodeIndex);
228 if (theNodeOnEdgeIndex == 0)
229 theNodeOnEdgeIndex = myVertexEdgeMap->Add(theNodeIndex);
232 //=======================================================================
235 //=======================================================================
236 gp_XY BRepMesh_FaceAttribute::Scale(const gp_XY& thePoint2d,
237 const Standard_Boolean isToFaceBasis)
239 return isToFaceBasis ?
240 gp_XY((thePoint2d.X() - myUMin) / myDeltaX, (thePoint2d.Y() - myVMin) / myDeltaY) :
241 gp_XY(thePoint2d.X() * myDeltaX + myUMin, thePoint2d.Y() * myDeltaY + myVMin);
244 //=======================================================================
245 //function : ToleranceU
247 //=======================================================================
248 Standard_Real BRepMesh_FaceAttribute::ToleranceU() const
250 return computeParametricTolerance(myUMin, myUMax);
253 //=======================================================================
254 //function : ToleranceV
256 //=======================================================================
257 Standard_Real BRepMesh_FaceAttribute::ToleranceV() const
259 return computeParametricTolerance(myVMin, myVMax);