-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComparisons.h
281 lines (248 loc) · 6.54 KB
/
Comparisons.h
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/**
* @file Comparisons.h
* @author Dan R. Lipsa
* @date 25 March 2010
* @brief Comparison functors
* @ingroup utils
*/
#ifndef __COMPARISONS_H__
#define __COMPARISONS_H__
class Foam;
class Face;
class Edge;
class Vertex;
class AdjacentOrientedFace;
#include "SystemDifferences.h"
/**
* @brief Compares two C strings ignoring the case
*/
struct LessThanNoCase : binary_function<const char*, const char*, bool>
{
/**
* Compares two character pointers
* @param s1 first C string
* @param s2 second C string
* @return true if the first argument is less than the second argument.
*/
bool operator()(const char* s1, const char* s2) const
{
return strcasecmp(s1, s2) < 0;
}
bool operator () (const string& s1, const string& s2) const
{
return operator () (s1.c_str (), s2.c_str ());
}
};
/**
* @brief Compares two Vector3int16
*/
struct Vector3int16LessThan
{
bool operator () (const G3D::Vector3int16& first,
const G3D::Vector3int16& second)
{
return
first.x < second.x ||
(first.x == second.x && first.y < second.y) ||
(first.x == second.x && first.y == second.y && first.z < second.z);
}
};
/**
* @brief Compares two vertices based on ID, X, Y, Z coordinates
*/
struct VertexPtrLessThan
{
bool operator () (const boost::shared_ptr<const Vertex>& first,
const boost::shared_ptr<const Vertex>& second) const;
};
/**
* @brief Compares two vertices along one of the X, Y or Z axes
*/
class VertexPtrLessThanAlong
{
public:
/**
* Constructor
* Stores the axis we want to do the comparison on.
*/
VertexPtrLessThanAlong(G3D::Vector3::Axis axis) :
m_axis(axis) {}
/**
* Compares two vertices
* @param first the first vertex
* @param second the second vertex
* @return true if first is less than second false otherwise
*/
bool operator() (const boost::shared_ptr<Vertex>& first,
const boost::shared_ptr<Vertex>& second) const;
bool operator() (
const G3D::Vector3& first, const G3D::Vector3& second) const
{
return first[m_axis] < second[m_axis];
}
bool operator() (
const G3D::Vector3* first, const G3D::Vector3* second) const
{
return operator () (*first, *second);
}
double operator () (const G3D::Vector3& x) const
{
return x[m_axis];
}
double operator () (const G3D::Vector3* x) const
{
return operator () (*x);
}
double operator () (const boost::shared_ptr<Vertex>& x) const;
private:
/**
* Axis along which we make the comparison
*/
G3D::Vector3::Axis m_axis;
};
/**
* @brief Compares two edges based on ID and then first vertex.
*/
class EdgeLessThan
{
public:
bool operator () (const boost::shared_ptr<const Edge>& first,
const boost::shared_ptr<const Edge>& second) const;
};
/**
* @brief Compares two faces based on ID and then first edge
*/
class FaceLessThan
{
public:
bool operator () (const boost::shared_ptr<const Face>& first,
const boost::shared_ptr<const Face>& second) const;
};
/**
* @brief Compares two adjacent oriented faces based on ID
*/
class OrientedFaceIndexLessThan
{
public:
bool operator () (
const AdjacentOrientedFace& first,
const AdjacentOrientedFace& second) const;
};
/**
* @brief Compares two bounding boxes based on a corner, along an axis.
*/
template <typename BBObject>
class BBObjectLessThanAlong
{
public:
typedef const G3D::Vector3& (G3D::AABox::*BoxCorner) () const;
typedef boost::function<G3D::AABox (const BBObject& object)> GetAABox;
BBObjectLessThanAlong (G3D::Vector3::Axis axis, BoxCorner corner,
GetAABox getAABox) :
m_axis (axis), m_corner(corner), m_getAABox (getAABox)
{}
/**
* Functor that compares two data objects
* @param first first data object
* @param second second data object
*/
bool operator () (
const BBObject* first, const BBObject* second)
{
return operator () (*first, *second);
}
bool operator () (
boost::shared_ptr<BBObject> first,
boost::shared_ptr<BBObject> second)
{
return operator () (*first, *second);
}
bool operator() (const BBObject& first,
const BBObject& second);
double operator () (const BBObject& x);
double operator () (const boost::shared_ptr<BBObject>& x)
{
return operator () (*x);
}
private:
/**
* Along which axis to compare
*/
G3D::Vector3::Axis m_axis;
/**
* What corner of the AABox to compare
*/
BoxCorner m_corner;
GetAABox m_getAABox;
};
/**
* @brief Compares two bounding boxes based on the lower left corner,
* along an axis.
*/
template<typename BBObject>
class BBObjectLessThanAlongLow : public BBObjectLessThanAlong<BBObject>
{
public:
BBObjectLessThanAlongLow (G3D::Vector3::Axis axis) :
BBObjectLessThanAlong<BBObject> (
axis, &G3D::AABox::low,
boost::bind (&BBObject::GetBoundingBox, _1))
{
}
};
/**
* @brief Compares two torus boxes based on the lower left corner,
* along an axis.
*/
template<typename BBObject>
class BBObjectLessThanAlongLowTorus : public BBObjectLessThanAlong<BBObject>
{
public:
BBObjectLessThanAlongLowTorus (G3D::Vector3::Axis axis) :
BBObjectLessThanAlong<BBObject> (
axis, &G3D::AABox::low,
boost::bind (&BBObject::GetBoundingBoxTorus, _1))
{
}
};
/**
* @brief Compares two bounding boxes based on the upper right corner,
* along an axis.
*/
template<typename BBObject>
class BBObjectLessThanAlongHigh : public BBObjectLessThanAlong<BBObject>
{
public:
BBObjectLessThanAlongHigh (G3D::Vector3::Axis axis) :
BBObjectLessThanAlong<BBObject> (
axis, &G3D::AABox::high,
boost::bind (&BBObject::GetBoundingBox, _1))
{
}
};
/**
* @brief Compares two torus boxes based on the upper right corner,
* along an axis.
*/
template<typename BBObject>
class BBObjectLessThanAlongHighTorus : public BBObjectLessThanAlong<BBObject>
{
public:
BBObjectLessThanAlongHighTorus (G3D::Vector3::Axis axis) :
BBObjectLessThanAlong<BBObject> (
axis, &G3D::AABox::high,
boost::bind (&BBObject::GetBoundingBoxTorus, _1))
{
}
};
typedef set<boost::shared_ptr<Vertex>, VertexPtrLessThan> VertexSet;
typedef set<boost::shared_ptr<Edge>, EdgeLessThan> EdgeSet;
typedef set<boost::shared_ptr<Face>, FaceLessThan> FaceSet;
class Body;
bool BodyLessThan (const boost::shared_ptr<Body>& first,
const boost::shared_ptr<Body>& second);
bool BodyLessThanId (const boost::shared_ptr<Body>& first, size_t bodyId);
#endif //__COMPARISONS_H__
// Local Variables:
// mode: c++
// End: