1 // Created on: 2011-06-02
2 // Created by: Oleg AGASHIN
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BRepMesh_VertexTool.ixx>
18 #include <Precision.hxx>
19 #include <BRepMesh_Vertex.hxx>
20 #include <BRepMesh_VertexInspector.hxx>
21 #include <BRepMesh_BaseAllocator.hxx>
23 //=======================================================================
24 //function : BRepMesh_VertexTool
26 //=======================================================================
27 BRepMesh_VertexTool::BRepMesh_VertexTool(const BRepMesh_BaseAllocator& theAlloc)
28 : myAllocator(theAlloc),
29 myCellFilter(0., myAllocator),
30 mySelector(64,myAllocator),
33 SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() );
34 SetTolerance( Precision::Confusion(), Precision::Confusion() );
37 //=======================================================================
38 //function : BRepMesh_VertexTool
40 //=======================================================================
41 BRepMesh_VertexTool::BRepMesh_VertexTool(const Standard_Integer nbComp,
42 const BRepMesh_BaseAllocator& theAlloc)
43 : myAllocator(theAlloc),
44 myCellFilter(0., myAllocator),
45 mySelector(Max(nbComp,64),myAllocator),
48 SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() );
49 SetTolerance( Precision::Confusion(), Precision::Confusion() );
52 //=======================================================================
53 //function : SetCellSize
55 //=======================================================================
56 void BRepMesh_VertexTool::SetCellSize(const Standard_Real theSize)
58 myCellFilter.Reset(theSize, myAllocator);
62 //=======================================================================
63 //function : SetCellSize
65 //=======================================================================
66 void BRepMesh_VertexTool::SetCellSize(const Standard_Real theXSize,
67 const Standard_Real theYSize)
69 Standard_Real aCellSize[2];
70 aCellSize[0] = theXSize;
71 aCellSize[1] = theYSize;
73 myCellFilter.Reset(aCellSize, myAllocator);
77 //=======================================================================
78 //function : SetTolerance
80 //=======================================================================
81 void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTol)
83 mySelector.SetTolerance( theTol );
88 //=======================================================================
89 //function : SetTolerance
91 //=======================================================================
92 void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTolX, const Standard_Real theTolY)
94 mySelector.SetTolerance( theTolX, theTolY );
99 //=======================================================================
102 //=======================================================================
103 Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex)
105 Standard_Integer anIndex = FindIndex(theVertex);
108 BRepMesh_ListOfInteger thelist(myAllocator);
109 anIndex = Add(theVertex, thelist);
114 //=======================================================================
117 //=======================================================================
118 Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex,
119 const BRepMesh_ListOfInteger& theParams)
121 Standard_Integer anIndex = mySelector.Add(theVertex);
122 myLinksMap.Bind(anIndex, theParams);
123 gp_XY aMinPnt, aMaxPnt;
124 ExpandPoint(theVertex.Coord(), aMinPnt, aMaxPnt);
125 myCellFilter.Add(anIndex, aMinPnt, aMaxPnt);
129 //=======================================================================
132 //=======================================================================
133 void BRepMesh_VertexTool::Delete(const Standard_Integer theIndex)
135 BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex);
136 gp_XY aMinPnt, aMaxPnt;
137 ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
138 myCellFilter.Remove (theIndex, aMinPnt, aMaxPnt);
139 mySelector.Delete(theIndex);
142 //=======================================================================
143 //function : RemoveLast
145 //=======================================================================
146 void BRepMesh_VertexTool::RemoveLast()
148 Standard_Integer aIndex = mySelector.GetNbVertices();
152 //=======================================================================
153 //function : GetListOfDelNodes
155 //=======================================================================
156 const BRepMesh_ListOfInteger& BRepMesh_VertexTool::GetListOfDelNodes() const
158 return mySelector.GetListOfDelNodes();
161 //=======================================================================
162 //function : FindIndex
164 //=======================================================================
165 Standard_Integer BRepMesh_VertexTool::FindIndex(const BRepMesh_Vertex& theVertex)
167 mySelector.SetCurrent(theVertex.Coord(),Standard_False);
168 myCellFilter.Inspect (theVertex.Coord(), mySelector);
169 return mySelector.GetCoincidentInd();
172 //=======================================================================
175 //=======================================================================
176 const BRepMesh_Vertex& BRepMesh_VertexTool::FindKey(const Standard_Integer theIndex)
178 return mySelector.GetVertex(theIndex);
181 //=======================================================================
182 //function : Substitute
184 //=======================================================================
185 void BRepMesh_VertexTool::Substitute(const Standard_Integer Index,
186 const BRepMesh_Vertex& theVertex,
187 const BRepMesh_ListOfInteger& theData)
189 BRepMesh_Vertex& aV = mySelector.GetVertex(Index);
190 gp_XY aMinPnt, aMaxPnt;
191 ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
192 myCellFilter.Remove (Index, aMinPnt, aMaxPnt);
194 ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
195 myCellFilter.Add(Index, aMinPnt, aMaxPnt);
196 FindFromIndex(Index) = theData;
199 //=======================================================================
202 //=======================================================================
203 Standard_Integer BRepMesh_VertexTool::Extent() const
205 return mySelector.GetNbVertices();
208 //=======================================================================
211 //=======================================================================
212 Standard_Boolean BRepMesh_VertexTool::IsEmpty() const
214 return mySelector.GetNbVertices() == 0;
217 //=======================================================================
218 //function : FindFromIndex
220 //=======================================================================
221 BRepMesh_ListOfInteger& BRepMesh_VertexTool::FindFromIndex(const Standard_Integer theIndex) const
223 return (BRepMesh_ListOfInteger&) myLinksMap.Find(theIndex);
226 //=======================================================================
229 //=======================================================================
230 void BRepMesh_VertexTool::ExpandPoint(const gp_XY& thePnt, gp_XY& theMinPnt, gp_XY& theMaxPnt)
232 theMinPnt.SetX(thePnt.X() - myTol(0));
233 theMinPnt.SetY(thePnt.Y() - myTol(1));
234 theMaxPnt.SetX(thePnt.X() + myTol(0));
235 theMaxPnt.SetY(thePnt.Y() + myTol(1));
238 //=======================================================================
239 //function : Statistics
241 //=======================================================================
242 void BRepMesh_VertexTool::Statistics(Standard_OStream& S) const
244 S <<"\nStructure Statistics\n---------------\n\n";
245 S <<"This structure has "<<mySelector.GetNbVertices()<<" Nodes\n\n";