0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / BRepMesh / BRepMesh_VertexTool.cxx
CommitLineData
b311480e 1// Created on: 2011-06-02
2// Created by: Oleg AGASHIN
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
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.
9//
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.
12//
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.
19
51c3cc5f
O
20
21#include <BRepMesh_VertexTool.ixx>
22#include <gp_XY.hxx>
23#include <Precision.hxx>
24#include <BRepMesh_Vertex.hxx>
25#include <BRepMesh_VertexInspector.hxx>
26#include <BRepMesh_BaseAllocator.hxx>
27
28//=======================================================================
29//function : BRepMesh_VertexTool
30//purpose :
31//=======================================================================
32BRepMesh_VertexTool::BRepMesh_VertexTool(const BRepMesh_BaseAllocator& theAlloc)
33: myAllocator(theAlloc),
34 myCellFilter(0., myAllocator),
35 mySelector(64,myAllocator),
36 myTol(0,1)
37{
38 SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() );
39 SetTolerance( Precision::Confusion(), Precision::Confusion() );
40}
41
42//=======================================================================
43//function : BRepMesh_VertexTool
44//purpose :
45//=======================================================================
46BRepMesh_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),
51 myTol(0,1)
52{
53 SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() );
54 SetTolerance( Precision::Confusion(), Precision::Confusion() );
55}
56
57//=======================================================================
58//function : SetCellSize
59//purpose :
60//=======================================================================
61void BRepMesh_VertexTool::SetCellSize(const Standard_Real theSize)
62{
63 myCellFilter.Reset(theSize, myAllocator);
64 mySelector.Clear();
65}
66
67//=======================================================================
68//function : SetCellSize
69//purpose :
70//=======================================================================
71void BRepMesh_VertexTool::SetCellSize(const Standard_Real theXSize,
72 const Standard_Real theYSize)
73{
74 Standard_Real aCellSize[2];
75 aCellSize[0] = theXSize;
76 aCellSize[1] = theYSize;
77
78 myCellFilter.Reset(aCellSize, myAllocator);
79 mySelector.Clear();
80}
81
82//=======================================================================
83//function : SetTolerance
84//purpose :
85//=======================================================================
86void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTol)
87{
88 mySelector.SetTolerance( theTol );
89 myTol(0) = theTol;
90 myTol(1) = theTol;
91}
92
93//=======================================================================
94//function : SetTolerance
95//purpose :
96//=======================================================================
97void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTolX, const Standard_Real theTolY)
98{
99 mySelector.SetTolerance( theTolX, theTolY );
100 myTol(0) = theTolX;
101 myTol(1) = theTolY;
102}
103
104//=======================================================================
105//function : Add
106//purpose :
107//=======================================================================
108Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex)
109{
110 Standard_Integer anIndex = FindIndex(theVertex);
111 if ( anIndex == 0 )
112 {
113 BRepMesh_ListOfInteger thelist(myAllocator);
114 anIndex = Add(theVertex, thelist);
115 }
116 return anIndex;
117}
118
119//=======================================================================
120//function : Add
121//purpose :
122//=======================================================================
123Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex,
124 const BRepMesh_ListOfInteger& theParams)
125{
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);
131 return anIndex;
132}
133
134//=======================================================================
135//function : Delete
136//purpose :
137//=======================================================================
138void BRepMesh_VertexTool::Delete(const Standard_Integer theIndex)
139{
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);
145}
146
147//=======================================================================
148//function : RemoveLast
149//purpose :
150//=======================================================================
151void BRepMesh_VertexTool::RemoveLast()
152{
153 Standard_Integer aIndex = mySelector.GetNbVertices();
154 Delete( aIndex );
155}
156
157//=======================================================================
158//function : GetListOfDelNodes
159//purpose :
160//=======================================================================
161const BRepMesh_ListOfInteger& BRepMesh_VertexTool::GetListOfDelNodes() const
162{
163 return mySelector.GetListOfDelNodes();
164}
165
166//=======================================================================
167//function : FindIndex
168//purpose :
169//=======================================================================
170Standard_Integer BRepMesh_VertexTool::FindIndex(const BRepMesh_Vertex& theVertex)
171{
35e08fe8 172 mySelector.SetCurrent(theVertex.Coord(),Standard_False);
51c3cc5f
O
173 myCellFilter.Inspect (theVertex.Coord(), mySelector);
174 return mySelector.GetCoincidentInd();
175}
176
177//=======================================================================
178//function : FindKey
179//purpose :
180//=======================================================================
181const BRepMesh_Vertex& BRepMesh_VertexTool::FindKey(const Standard_Integer theIndex)
182{
183 return mySelector.GetVertex(theIndex);
184}
185
186//=======================================================================
187//function : Substitute
188//purpose :
189//=======================================================================
190void BRepMesh_VertexTool::Substitute(const Standard_Integer Index,
191 const BRepMesh_Vertex& theVertex,
192 const BRepMesh_ListOfInteger& theData)
193{
194 BRepMesh_Vertex& aV = mySelector.GetVertex(Index);
195 gp_XY aMinPnt, aMaxPnt;
196 ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
197 myCellFilter.Remove (Index, aMinPnt, aMaxPnt);
198 aV = theVertex;
199 ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
200 myCellFilter.Add(Index, aMinPnt, aMaxPnt);
201 FindFromIndex(Index) = theData;
202}
203
204//=======================================================================
205//function : Extent
206//purpose :
207//=======================================================================
208Standard_Integer BRepMesh_VertexTool::Extent() const
209{
210 return mySelector.GetNbVertices();
211}
212
213//=======================================================================
214//function : IsEmpty
215//purpose :
216//=======================================================================
217Standard_Boolean BRepMesh_VertexTool::IsEmpty() const
218{
219 return mySelector.GetNbVertices() == 0;
220}
221
222//=======================================================================
223//function : FindFromIndex
224//purpose :
225//=======================================================================
226BRepMesh_ListOfInteger& BRepMesh_VertexTool::FindFromIndex(const Standard_Integer theIndex) const
227{
228 return (BRepMesh_ListOfInteger&) myLinksMap.Find(theIndex);
229}
230
231//=======================================================================
232//function :
233//purpose :
234//=======================================================================
235void BRepMesh_VertexTool::ExpandPoint(const gp_XY& thePnt, gp_XY& theMinPnt, gp_XY& theMaxPnt)
236{
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));
241}
242
243//=======================================================================
244//function : Statistics
245//purpose :
246//=======================================================================
247void BRepMesh_VertexTool::Statistics(Standard_OStream& S) const
248{
249 S <<"\nStructure Statistics\n---------------\n\n";
250 S <<"This structure has "<<mySelector.GetNbVertices()<<" Nodes\n\n";
251}