]>
Commit | Line | Data |
---|---|---|
8356cc1d | 1 | //////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // Author: Artur Szostak | |
4 | // Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com | |
5 | // | |
6 | //////////////////////////////////////////////////////////////////////////////// | |
7 | ||
8 | #ifndef dHLT_REGION_OF_INTEREST_HPP | |
9 | #define dHLT_REGION_OF_INTEREST_HPP | |
10 | ||
11 | #include "BasicTypes.hpp" | |
12 | #include "Utils.hpp" | |
13 | #include "Cluster.hpp" | |
14 | ||
15 | namespace dHLT | |
16 | { | |
17 | ||
18 | ||
19 | const Int NUMBER_OF_TRACKING_CHAMBERS = 10; | |
20 | ||
21 | typedef UInt ROI; | |
22 | ||
23 | enum | |
24 | { | |
25 | INVALID_ROI = 0xFFFFFFFF | |
26 | }; | |
27 | ||
28 | ||
29 | /* Identification numbers specifying the tracking chambers of the dimuon | |
30 | spectrometer. | |
31 | */ | |
32 | enum ChamberID | |
33 | { | |
34 | UnknownChamber = -1, | |
35 | Chamber1 = 0, | |
36 | Chamber2 = 1, | |
37 | Chamber3 = 2, | |
38 | Chamber4 = 3, | |
39 | Chamber5 = 4, | |
40 | Chamber6 = 5, | |
41 | Chamber7 = 6, | |
42 | Chamber8 = 7, | |
43 | Chamber9 = 8, | |
44 | Chamber10 = 9 | |
45 | }; | |
46 | ||
47 | ||
48 | /* The region of interest object is used to encode/decode and work with boundary | |
49 | box type regions of interest. The 32 bit ROI codes are used to communicate | |
50 | regions of interest between different parts of the dHLT system. This is more | |
51 | efficient than sending 20 byte long region of interest objects. | |
52 | */ | |
53 | class RegionOfInterest | |
54 | { | |
55 | public: | |
56 | ||
57 | RegionOfInterest() | |
58 | { | |
59 | chamber = Chamber1; | |
60 | left = right = top = bottom = 0.0; | |
cbee67e7 | 61 | } |
8356cc1d | 62 | |
63 | /* This constructor decodes the ROI bit pattern into a region of | |
64 | interest object. | |
65 | */ | |
66 | RegionOfInterest(const ROI& code) | |
67 | { | |
68 | Decode(code); | |
cbee67e7 | 69 | } |
8356cc1d | 70 | |
71 | /* Creates a region of interest around the given point for the | |
72 | specified chamber. | |
73 | */ | |
e33f3609 | 74 | RegionOfInterest(const ClusterPoint& point0, ChamberID chamber0) |
8356cc1d | 75 | { |
cbee67e7 | 76 | CreateToContain(point0, chamber0); |
77 | } | |
8356cc1d | 78 | |
79 | /* Creates a region of interest around all the given points and for the | |
80 | specified chamber. | |
81 | */ | |
e33f3609 | 82 | RegionOfInterest(const ClusterPoint* points0, UInt count0, ChamberID chamber0) |
8356cc1d | 83 | { |
cbee67e7 | 84 | CreateToContain(points0, count0, chamber0); |
85 | } | |
8356cc1d | 86 | |
87 | /* Creates a region of interest with the specified boundaries and for | |
88 | the specified chamber. | |
89 | */ | |
e33f3609 | 90 | RegionOfInterest(Float left0, Float right0, Float bottom0, Float top0, ChamberID chamber0) |
8356cc1d | 91 | { |
cbee67e7 | 92 | Assert( 0 <= chamber0 and chamber0 < NUMBER_OF_TRACKING_CHAMBERS ); |
93 | this->chamber = chamber0; | |
94 | this->left = left0; | |
95 | this->right = right0; | |
96 | this->bottom = bottom0; | |
97 | this->top = top0; | |
98 | } | |
8356cc1d | 99 | |
100 | ||
101 | /* Checks if the point is contained in this region of interest. | |
102 | */ | |
103 | bool Contains(const ClusterPoint& point) const | |
104 | { | |
105 | return left <= point.x and point.x <= right and | |
106 | bottom <= point.y and point.y <= top; | |
cbee67e7 | 107 | } |
8356cc1d | 108 | |
109 | ||
110 | /* Checks if the point is contained in this region of interest and the | |
111 | chamber number corresponds to this region object. | |
112 | */ | |
e33f3609 | 113 | bool Contains(const ClusterPoint& point, ChamberID chamber0) const |
8356cc1d | 114 | { |
115 | return left <= point.x and point.x <= right and | |
116 | bottom <= point.y and point.y <= top and | |
cbee67e7 | 117 | this->chamber == chamber0; |
118 | } | |
8356cc1d | 119 | |
120 | ||
121 | /* Checks if the specified region of interest is contained in this | |
122 | region of interest object. | |
123 | */ | |
124 | bool Contains(const RegionOfInterest& roi) const | |
125 | { | |
126 | return chamber == roi.chamber and | |
127 | left <= roi.left and right >= roi.right and | |
128 | bottom <= roi.bottom and top >= roi.top; | |
cbee67e7 | 129 | } |
8356cc1d | 130 | |
131 | ||
132 | /* Creates a region of interest around the given point for the | |
133 | specified chamber. | |
134 | */ | |
e33f3609 | 135 | void CreateToContain(const ClusterPoint& point, ChamberID chamber); |
8356cc1d | 136 | |
137 | /* Extends the region of interest to contain the specified point. | |
138 | */ | |
139 | void ExpandToContain(const ClusterPoint& point); | |
140 | ||
141 | /* Creates a region of interest around all the given points and for the | |
142 | specified chamber. | |
143 | */ | |
e33f3609 | 144 | void CreateToContain(const ClusterPoint* points, UInt count, ChamberID chamber); |
8356cc1d | 145 | |
146 | /* Checks if the region of interest is within the boundaries imposed on | |
147 | the specific chamber plane. This boundary is aproximately the square | |
148 | box around the chamber's detection region. | |
149 | */ | |
150 | bool InBounds(); | |
151 | ||
152 | /* Encodes the region of interest into a 32 bit code. | |
153 | */ | |
154 | ROI Encode() const; | |
155 | ||
156 | /* Encodes the region of interest into a 32 bit code, and returns the | |
157 | hierarchal level the region was encoded at and the left and right | |
158 | grid coordinate of the bottom left corner of the region boundary box. | |
159 | */ | |
160 | ROI Encode(UChar& level, UInt& l, UInt& b) const; | |
161 | ||
162 | /* Decodes a 32 bit region of interest code into this region of interest | |
163 | object. | |
164 | */ | |
e33f3609 | 165 | void Decode(ROI code); |
8356cc1d | 166 | |
167 | /* Decodes the chamber number of the region of interest 32 bit code. | |
168 | */ | |
e33f3609 | 169 | static ChamberID DecodeChamber(ROI code); |
8356cc1d | 170 | |
171 | /* Decodes the 32 bit region of interest code into the chamber number, | |
172 | hierarchal level, left and right grid coordinates of the region | |
173 | boundary box. | |
174 | */ | |
e33f3609 | 175 | static void Decode(ROI code, ChamberID& chamber, UChar& level, UInt& l, UInt& b); |
8356cc1d | 176 | |
177 | /* Returns the chamber number of the region of interest. | |
178 | */ | |
179 | ChamberID Chamber() const { return chamber; }; | |
180 | ||
181 | /* Returns the left hand boundary of the region of interest. | |
182 | */ | |
183 | Float Left() const { return left; }; | |
184 | ||
185 | /* Returns the right hand boundary of the region of interest. | |
186 | */ | |
187 | Float Right() const { return right; }; | |
188 | ||
189 | /* Returns the bottom boundary of the region of interest. | |
190 | */ | |
191 | Float Bottom() const { return bottom; }; | |
192 | ||
193 | /* Returns the top boundary of the region of interest. | |
194 | */ | |
195 | Float Top() const { return top; }; | |
196 | ||
197 | ||
198 | /* Typecast operator for implicit typecasing to 32 bit ROI codes. | |
199 | */ | |
200 | operator ROI () const { return Encode(); }; | |
201 | ||
202 | ||
203 | private: | |
204 | ||
205 | /* Converts the internal region of interest boundary box, which is | |
206 | specified in as floats, into a regular integer grid. | |
207 | l = left boundary, r = right boundary, b = bottom boundary, | |
208 | t = top boundary. | |
209 | */ | |
210 | inline void ConvertToGrid(UInt& l, UInt& r, UInt& b, UInt& t) const; | |
211 | ||
212 | /* Performs the inverse conversion of the method ConvertToGrid. | |
213 | That is converts from a regular integer grid back to the internal | |
214 | floating point boundary box specification. | |
215 | */ | |
e33f3609 | 216 | inline void ConvertBackFromGrid(register UInt l, register UInt r, register UInt b, register UInt t); |
8356cc1d | 217 | |
218 | /* Internal method for decoding 32 bit region codes. This method is | |
219 | called by the Decode methods. | |
220 | */ | |
e33f3609 | 221 | static void DecodeBits(ROI code, ChamberID& chamber, UChar& colevel, UInt& l, UInt& b); |
8356cc1d | 222 | |
223 | ||
224 | // Boundary box scale numbers for each chamber. These are the boundary | |
225 | // boxes around the chambers detection surface. | |
226 | static Float planescale[NUMBER_OF_TRACKING_CHAMBERS]; | |
227 | ||
228 | static UInt indexoffsets[13]; // Offset numbers used in the encoding and decoding process. | |
229 | ||
230 | ||
231 | ChamberID chamber; // Specifies the chamber the region of interest is on. | |
232 | Float left; // Left boundary of boundary box. | |
233 | Float right; // Right boundary of boundary box. | |
234 | Float bottom; // Bottom boundary of boundary box. | |
235 | Float top; // Top boundary of boundary box. | |
236 | }; | |
237 | ||
238 | ||
239 | } // dHLT | |
240 | ||
241 | #endif // dHLT_REGION_OF_INTEREST_HPP |