-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBodySelector.h
229 lines (200 loc) · 4.94 KB
/
BodySelector.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
/**
* @file BodySelector.h
* @author Dan R. Lipsa
* @date 31 Aug. 2010
* @ingroup settings model
* @brief Functors that specify selected bubbles.
*/
#ifndef __BODY_SELECTOR_H__
#define __BODY_SELECTOR_H__
#include "Enums.h"
class Body;
/**
* @brief Specifies selected bubbles
*/
class BodySelector
{
public:
typedef vector<QwtDoubleInterval> ValueIntervals;
public:
virtual ~BodySelector ()
{
}
/**
* Returns true if this body is selected.
*/
virtual bool operator () (const boost::shared_ptr<Body>& body) const = 0;
virtual BodySelectorType::Enum GetType () const = 0;
boost::shared_ptr<BodySelector> Clone () const;
const BinRegions& GetBins () const;
private:
static const BinRegions ALL_BINS;
};
/**
* @brief Specifies selected bubbles (used in std libraries algorithms)
*/
class BodySelectorPredicate
{
public:
BodySelectorPredicate (const BodySelector& bs) :
m_bs (bs)
{
}
bool operator () (const boost::shared_ptr<Body>& body) const
{
return m_bs.operator () (body);
}
private:
const BodySelector& m_bs;
};
/**
* @brief Specifies that all bubbles are selected.
*/
class AllBodySelector : public BodySelector
{
public:
virtual bool operator () (const boost::shared_ptr<Body>& body) const
{
(void) body;
return true;
}
virtual BodySelectorType::Enum GetType () const
{
return BodySelectorType::ALL;
}
boost::shared_ptr<AllBodySelector> Clone () const
{
return SELECTOR;
}
public:
static boost::shared_ptr<AllBodySelector> Get ()
{
return SELECTOR;
}
private:
static boost::shared_ptr<AllBodySelector> SELECTOR;
};
/**
* @brief Specifies that bubbles with a scalar value in a specified
* list of intervals are selected.
*/
class ValueBodySelector : public BodySelector
{
public:
ValueBodySelector (BodyScalar::Enum scalar, bool is2D,
const ValueIntervals& valueIntervals,
const BinRegions& bins);
virtual ~ValueBodySelector ()
{
}
virtual bool operator () (const boost::shared_ptr<Body>& body) const;
virtual BodySelectorType::Enum GetType () const
{
return BodySelectorType::PROPERTY_VALUE;
}
boost::shared_ptr<ValueBodySelector> Clone () const;
string ToUserString () const;
const ValueIntervals& GetIntervals () const
{
return m_valueIntervals;
}
const BinRegions& GetBins () const
{
return m_bins;
}
BodyScalar::Enum GetScalar () const
{
return m_scalar;
}
private:
BodyScalar::Enum m_scalar;
const bool m_is2D;
ValueIntervals m_valueIntervals;
/**
* Useful for setting the selection on a histogram.
*/
BinRegions m_bins;
};
/**
* @brief Specifies that bubbles with given IDs are selected
*/
class IdBodySelector : public BodySelector
{
public:
IdBodySelector ();
IdBodySelector (size_t id);
IdBodySelector (const vector<size_t>& ids);
virtual ~IdBodySelector ()
{
}
virtual bool operator () (const boost::shared_ptr<Body>& body) const;
BodySelectorType::Enum GetType () const
{
return BodySelectorType::ID;
}
boost::shared_ptr<IdBodySelector> Clone () const;
void SetUnion (const vector<size_t>& idsToAdd);
void SetUnion (const IdBodySelector& idsToAdd);
void SetDifference (const vector<size_t>& idsToRemove);
const vector<size_t>& GetIds () const
{
return m_ids;
}
string ToString () const;
string ToUserString () const;
private:
/**
* Selected body ids ordered ascending.
*/
vector<size_t> m_ids;
};
/**
* @brief Specifies that bubbles with given IDs and scalar values are selected.
*/
class CompositeBodySelector : public BodySelector
{
public:
CompositeBodySelector (
boost::shared_ptr<IdBodySelector> idSelector,
boost::shared_ptr<ValueBodySelector> propertyValueSelector) :
m_idSelector (idSelector),
m_valueSelector (propertyValueSelector)
{
}
virtual ~CompositeBodySelector ()
{
}
boost::shared_ptr<CompositeBodySelector> Clone () const;
boost::shared_ptr<ValueBodySelector> GetValueSelector () const
{
return m_valueSelector;
}
boost::shared_ptr<IdBodySelector> GetIdSelector () const
{
return m_idSelector;
}
void SetSelector (boost::shared_ptr<ValueBodySelector> valueSelector)
{
m_valueSelector = valueSelector;
}
void SetSelector (boost::shared_ptr<IdBodySelector> idSelector)
{
m_idSelector = idSelector;
}
virtual bool operator () (const boost::shared_ptr<Body>& body) const;
BodySelectorType::Enum GetType () const
{
return BodySelectorType::COMPOSITE;
}
private:
boost::shared_ptr<IdBodySelector> m_idSelector;
boost::shared_ptr<ValueBodySelector> m_valueSelector;
};
inline ostream& operator<< (ostream& ostr, const IdBodySelector& selector)
{
return ostr << selector.ToString ();
}
#endif //__BODY_SELECTOR_H__
// Local Variables:
// mode: c++
// End: