1 // Created on: 2011-06-02
2 // Created by: Oleg AGASHIN
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <BRepMesh_VertexTool.ixx>
23 #include <Precision.hxx>
24 #include <BRepMesh_Vertex.hxx>
25 #include <BRepMesh_VertexInspector.hxx>
26 #include <BRepMesh_BaseAllocator.hxx>
28 //=======================================================================
29 //function : BRepMesh_VertexTool
31 //=======================================================================
32 BRepMesh_VertexTool::BRepMesh_VertexTool(const BRepMesh_BaseAllocator& theAlloc)
33 : myAllocator(theAlloc),
34 myCellFilter(0., myAllocator),
35 mySelector(64,myAllocator),
38 SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() );
39 SetTolerance( Precision::Confusion(), Precision::Confusion() );
42 //=======================================================================
43 //function : BRepMesh_VertexTool
45 //=======================================================================
46 BRepMesh_VertexTool::BRepMesh_VertexTool(const Standard_Integer nbComp,
47 const BRepMesh_BaseAllocator& theAlloc)
48 : myAllocator(theAlloc),
49 myCellFilter(0., myAllocator),
50 mySelector(Max(nbComp,64),myAllocator),
53 SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() );
54 SetTolerance( Precision::Confusion(), Precision::Confusion() );
57 //=======================================================================
58 //function : SetCellSize
60 //=======================================================================
61 void BRepMesh_VertexTool::SetCellSize(const Standard_Real theSize)
63 myCellFilter.Reset(theSize, myAllocator);
67 //=======================================================================
68 //function : SetCellSize
70 //=======================================================================
71 void BRepMesh_VertexTool::SetCellSize(const Standard_Real theXSize,
72 const Standard_Real theYSize)
74 Standard_Real aCellSize[2];
75 aCellSize[0] = theXSize;
76 aCellSize[1] = theYSize;
78 myCellFilter.Reset(aCellSize, myAllocator);
82 //=======================================================================
83 //function : SetTolerance
85 //=======================================================================
86 void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTol)
88 mySelector.SetTolerance( theTol );
93 //=======================================================================
94 //function : SetTolerance
96 //=======================================================================
97 void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTolX, const Standard_Real theTolY)
99 mySelector.SetTolerance( theTolX, theTolY );
104 //=======================================================================
107 //=======================================================================
108 Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex)
110 Standard_Integer anIndex = FindIndex(theVertex);
113 BRepMesh_ListOfInteger thelist(myAllocator);
114 anIndex = Add(theVertex, thelist);
119 //=======================================================================
122 //=======================================================================
123 Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex,
124 const BRepMesh_ListOfInteger& theParams)
126 Standard_Integer anIndex = mySelector.Add(theVertex);
127 myLinksMap.Bind(anIndex, theParams);
128 gp_XY aMinPnt, aMaxPnt;
129 ExpandPoint(theVertex.Coord(), aMinPnt, aMaxPnt);
130 myCellFilter.Add(anIndex, aMinPnt, aMaxPnt);
134 //=======================================================================
137 //=======================================================================
138 void BRepMesh_VertexTool::Delete(const Standard_Integer theIndex)
140 BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex);
141 gp_XY aMinPnt, aMaxPnt;
142 ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
143 myCellFilter.Remove (theIndex, aMinPnt, aMaxPnt);
144 mySelector.Delete(theIndex);
147 //=======================================================================
148 //function : RemoveLast
150 //=======================================================================
151 void BRepMesh_VertexTool::RemoveLast()
153 Standard_Integer aIndex = mySelector.GetNbVertices();
157 //=======================================================================
158 //function : GetListOfDelNodes
160 //=======================================================================
161 const BRepMesh_ListOfInteger& BRepMesh_VertexTool::GetListOfDelNodes() const
163 return mySelector.GetListOfDelNodes();
166 //=======================================================================
167 //function : FindIndex
169 //=======================================================================
170 Standard_Integer BRepMesh_VertexTool::FindIndex(const BRepMesh_Vertex& theVertex)
172 mySelector.SetCurrent(theVertex.Coord(), Standard_False);
173 myCellFilter.Inspect (theVertex.Coord(), mySelector);
174 return mySelector.GetCoincidentInd();
177 //=======================================================================
180 //=======================================================================
181 const BRepMesh_Vertex& BRepMesh_VertexTool::FindKey(const Standard_Integer theIndex)
183 return mySelector.GetVertex(theIndex);
186 //=======================================================================
187 //function : Substitute
189 //=======================================================================
190 void BRepMesh_VertexTool::Substitute(const Standard_Integer Index,
191 const BRepMesh_Vertex& theVertex,
192 const BRepMesh_ListOfInteger& theData)
194 BRepMesh_Vertex& aV = mySelector.GetVertex(Index);
195 gp_XY aMinPnt, aMaxPnt;
196 ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
197 myCellFilter.Remove (Index, aMinPnt, aMaxPnt);
199 ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
200 myCellFilter.Add(Index, aMinPnt, aMaxPnt);
201 FindFromIndex(Index) = theData;
204 //=======================================================================
207 //=======================================================================
208 Standard_Integer BRepMesh_VertexTool::Extent() const
210 return mySelector.GetNbVertices();
213 //=======================================================================
216 //=======================================================================
217 Standard_Boolean BRepMesh_VertexTool::IsEmpty() const
219 return mySelector.GetNbVertices() == 0;
222 //=======================================================================
223 //function : FindFromIndex
225 //=======================================================================
226 BRepMesh_ListOfInteger& BRepMesh_VertexTool::FindFromIndex(const Standard_Integer theIndex) const
228 return (BRepMesh_ListOfInteger&) myLinksMap.Find(theIndex);
231 //=======================================================================
234 //=======================================================================
235 void BRepMesh_VertexTool::ExpandPoint(const gp_XY& thePnt, gp_XY& theMinPnt, gp_XY& theMaxPnt)
237 theMinPnt.SetX(thePnt.X() - myTol(0));
238 theMinPnt.SetY(thePnt.Y() - myTol(1));
239 theMaxPnt.SetX(thePnt.X() + myTol(0));
240 theMaxPnt.SetY(thePnt.Y() + myTol(1));
243 //=======================================================================
244 //function : Statistics
246 //=======================================================================
247 void BRepMesh_VertexTool::Statistics(Standard_OStream& S) const
249 S <<"\nStructure Statistics\n---------------\n\n";
250 S <<"This structure has "<<mySelector.GetNbVertices()<<" Nodes\n\n";