summaryrefslogtreecommitdiff
path: root/src/BRepMesh/BRepMesh_VertexTool.cxx
blob: b0346c8e924d4ae21421a277303a0f95a92943ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// File:        BRepMesh_VertexTool.cxx
// Created:     Jun 2 10:19:12 2011
// Author:      Oleg AGASHIN
// Copyright:   Open CASCADE SAS 2011

#include <BRepMesh_VertexTool.ixx>
#include <gp_XY.hxx>
#include <Precision.hxx>
#include <BRepMesh_Vertex.hxx>
#include <BRepMesh_VertexInspector.hxx>
#include <BRepMesh_BaseAllocator.hxx>

//=======================================================================
//function : BRepMesh_VertexTool
//purpose  : 
//=======================================================================
BRepMesh_VertexTool::BRepMesh_VertexTool(const BRepMesh_BaseAllocator& theAlloc)
: myAllocator(theAlloc),
  myCellFilter(0., myAllocator),
  mySelector(64,myAllocator),
  myTol(0,1)
{
  SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() );
  SetTolerance( Precision::Confusion(), Precision::Confusion() );
}

//=======================================================================
//function : BRepMesh_VertexTool
//purpose  : 
//=======================================================================
BRepMesh_VertexTool::BRepMesh_VertexTool(const Standard_Integer        nbComp,
                                         const BRepMesh_BaseAllocator& theAlloc)
                                         : myAllocator(theAlloc),
                                           myCellFilter(0., myAllocator),
                                           mySelector(Max(nbComp,64),myAllocator),
                                           myTol(0,1)
{
  SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() );
  SetTolerance( Precision::Confusion(), Precision::Confusion() );
}

//=======================================================================
//function : SetCellSize
//purpose  : 
//=======================================================================
void BRepMesh_VertexTool::SetCellSize(const Standard_Real theSize)
{
  myCellFilter.Reset(theSize, myAllocator);
  mySelector.Clear();
}

//=======================================================================
//function : SetCellSize
//purpose  : 
//=======================================================================
void BRepMesh_VertexTool::SetCellSize(const Standard_Real theXSize, 
                                      const Standard_Real theYSize)
{
  Standard_Real aCellSize[2];
  aCellSize[0] = theXSize;
  aCellSize[1] = theYSize;
  
  myCellFilter.Reset(aCellSize, myAllocator);
  mySelector.Clear();
}

//=======================================================================
//function : SetTolerance
//purpose  : 
//=======================================================================
void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTol)
{
  mySelector.SetTolerance( theTol );
  myTol(0) = theTol;
  myTol(1) = theTol;
}

//=======================================================================
//function : SetTolerance
//purpose  : 
//=======================================================================
void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTolX, const Standard_Real theTolY)
{
  mySelector.SetTolerance( theTolX, theTolY );
  myTol(0) = theTolX;
  myTol(1) = theTolY;
}

//=======================================================================
//function : Add
//purpose  : 
//=======================================================================
Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex)
{
  Standard_Integer anIndex = FindIndex(theVertex);
  if ( anIndex == 0 )
  {
    BRepMesh_ListOfInteger thelist(myAllocator);
    anIndex = Add(theVertex, thelist);
  }
  return anIndex;
}

//=======================================================================
//function : Add
//purpose  : 
//=======================================================================
Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex,
                                          const BRepMesh_ListOfInteger& theParams)
{
  Standard_Integer anIndex = mySelector.Add(theVertex);
  myLinksMap.Bind(anIndex, theParams);
  gp_XY aMinPnt, aMaxPnt;
  ExpandPoint(theVertex.Coord(), aMinPnt, aMaxPnt);
  myCellFilter.Add(anIndex, aMinPnt, aMaxPnt);
  return anIndex;
}

//=======================================================================
//function : Delete
//purpose  : 
//=======================================================================
void  BRepMesh_VertexTool::Delete(const Standard_Integer theIndex)
{
  BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex);
  gp_XY aMinPnt, aMaxPnt;
  ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
  myCellFilter.Remove (theIndex, aMinPnt, aMaxPnt);
  mySelector.Delete(theIndex);
}

//=======================================================================
//function : RemoveLast
//purpose  : 
//=======================================================================
void  BRepMesh_VertexTool::RemoveLast()
{
  Standard_Integer aIndex = mySelector.GetNbVertices();
  Delete( aIndex );
}

//=======================================================================
//function : GetListOfDelNodes
//purpose  : 
//=======================================================================
const BRepMesh_ListOfInteger& BRepMesh_VertexTool::GetListOfDelNodes() const
{
  return mySelector.GetListOfDelNodes();
}

//=======================================================================
//function : FindIndex
//purpose  : 
//=======================================================================
Standard_Integer BRepMesh_VertexTool::FindIndex(const BRepMesh_Vertex& theVertex)
{
  mySelector.SetCurrent(theVertex.Coord());
  myCellFilter.Inspect (theVertex.Coord(), mySelector);
  return mySelector.GetCoincidentInd();
}

//=======================================================================
//function : FindKey
//purpose  : 
//=======================================================================
const BRepMesh_Vertex& BRepMesh_VertexTool::FindKey(const Standard_Integer theIndex)
{
  return mySelector.GetVertex(theIndex);
}

//=======================================================================
//function : Substitute
//purpose  : 
//=======================================================================
void BRepMesh_VertexTool::Substitute(const Standard_Integer Index,
                                     const BRepMesh_Vertex& theVertex,
                                     const BRepMesh_ListOfInteger& theData)
{
  BRepMesh_Vertex& aV = mySelector.GetVertex(Index);
  gp_XY aMinPnt, aMaxPnt;
  ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
  myCellFilter.Remove (Index, aMinPnt, aMaxPnt);
  aV = theVertex;
  ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt);
  myCellFilter.Add(Index, aMinPnt, aMaxPnt);
  FindFromIndex(Index) = theData;
}

//=======================================================================
//function : Extent
//purpose  : 
//=======================================================================
Standard_Integer BRepMesh_VertexTool::Extent() const
{
  return mySelector.GetNbVertices();
}

//=======================================================================
//function : IsEmpty
//purpose  : 
//=======================================================================
Standard_Boolean BRepMesh_VertexTool::IsEmpty() const
{
  return mySelector.GetNbVertices() == 0;
}

//=======================================================================
//function : FindFromIndex
//purpose  : 
//=======================================================================
BRepMesh_ListOfInteger& BRepMesh_VertexTool::FindFromIndex(const Standard_Integer theIndex) const
{
  return (BRepMesh_ListOfInteger&) myLinksMap.Find(theIndex);
}

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
void BRepMesh_VertexTool::ExpandPoint(const gp_XY& thePnt, gp_XY& theMinPnt, gp_XY& theMaxPnt)
{
  theMinPnt.SetX(thePnt.X() - myTol(0));
  theMinPnt.SetY(thePnt.Y() - myTol(1));
  theMaxPnt.SetX(thePnt.X() + myTol(0));
  theMaxPnt.SetY(thePnt.Y() + myTol(1));
}

//=======================================================================
//function : Statistics
//purpose  : 
//=======================================================================
void BRepMesh_VertexTool::Statistics(Standard_OStream& S) const
{
  S <<"\nStructure Statistics\n---------------\n\n";
  S <<"This structure has "<<mySelector.GetNbVertices()<<" Nodes\n\n";
}