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>
22 IMPLEMENT_STANDARD_HANDLE (BRepMesh_FaceAttribute, Standard_Transient)
23 IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_FaceAttribute, Standard_Transient)
25 //=======================================================================
26 //function : Constructor
28 //=======================================================================
29 BRepMesh_FaceAttribute::BRepMesh_FaceAttribute()
37 myStatus (BRepMesh_NoError)
42 //=======================================================================
43 //function : Constructor
45 //=======================================================================
46 BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
47 const TopoDS_Face& theFace,
48 const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
49 const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints)
57 myStatus (BRepMesh_NoError),
58 myBoundaryVertices(theBoundaryVertices),
59 myBoundaryPoints (theBoundaryPoints),
65 //=======================================================================
66 //function : Destructor
68 //=======================================================================
69 BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
73 //=======================================================================
76 //=======================================================================
77 void BRepMesh_FaceAttribute::init()
79 myVertexEdgeMap = new BRepMesh::IMapOfInteger;
80 myInternalEdges = new BRepMesh::DMapOfShapePairOfPolygon;
81 myLocation2D = new BRepMesh::DMapOfIntegerListOfXY;
82 myClassifier = new BRepMesh_Classifier;
87 BRepTools::Update(myFace);
88 myFace.Orientation(TopAbs_FORWARD);
89 BRepTools::UVBounds(myFace, myUMin, myUMax, myVMin, myVMax);
91 BRepAdaptor_Surface aSurfAdaptor(myFace, Standard_False);
92 mySurface = new BRepAdaptor_HSurface(aSurfAdaptor);
95 //=======================================================================
98 //=======================================================================
99 void BRepMesh_FaceAttribute::Clear()
101 myStructure.Nullify();
102 myLocation2D->Clear();
103 myInternalEdges->Clear();
104 myVertexEdgeMap->Clear();
107 //=======================================================================
108 //function : computeParametricTolerance
110 //=======================================================================
111 Standard_Real BRepMesh_FaceAttribute::computeParametricTolerance(
112 const Standard_Real theFirstParam,
113 const Standard_Real theLastParam) const
115 const Standard_Real aDeflectionUV = 1.e-05;
116 return Max(Precision::PConfusion(), (theLastParam - theFirstParam) * aDeflectionUV);
119 //=======================================================================
120 //function : getVertexIndex
122 //=======================================================================
123 Standard_Boolean BRepMesh_FaceAttribute::getVertexIndex(
124 const TopoDS_Vertex& theVertex,
125 Standard_Integer& theVertexIndex) const
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);
132 return Standard_False;
134 return Standard_True;
137 //=======================================================================
140 //=======================================================================
141 void BRepMesh_FaceAttribute::AddNode(
142 const Standard_Integer theIndex,
144 const BRepMesh_DegreeOfFreedom theMovability,
145 Standard_Integer& theNodeIndex,
146 Standard_Integer& theNodeOnEdgeIndex)
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);
155 //=======================================================================
158 //=======================================================================
159 gp_XY BRepMesh_FaceAttribute::Scale(const gp_XY& thePoint2d,
160 const Standard_Boolean isToFaceBasis)
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);
167 //=======================================================================
168 //function : ToleranceU
170 //=======================================================================
171 Standard_Real BRepMesh_FaceAttribute::ToleranceU() const
173 return computeParametricTolerance(myUMin, myUMax);
176 //=======================================================================
177 //function : ToleranceV
179 //=======================================================================
180 Standard_Real BRepMesh_FaceAttribute::ToleranceV() const
182 return computeParametricTolerance(myVMin, myVMax);