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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
/*
-----------------------------------------------------------------------
Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp
2014-2015, CWI, Amsterdam
Contact: astra@uantwerpen.be
Website: http://sf.net/projects/astra-toolbox
This file is part of the ASTRA Toolbox.
The ASTRA Toolbox is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The ASTRA Toolbox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------
$Id$
*/
#ifndef _INC_ASTRA_PROJECTIONGEOMETRY3D
#define _INC_ASTRA_PROJECTIONGEOMETRY3D
#include "Globals.h"
#include "Config.h"
#include "Vector3D.h"
#include <string>
#include <cmath>
#include <vector>
namespace astra
{
class XMLNode;
/**
* This class defines the interface for each 3D projection geometry.
* It has a number of data fields, such as width and height of detector
* pixels, projection angles and number of rows and columns of detector pixels.
*
* \par XML Configuration
* \astra_xml_item{DetectorRowCount, int, Number of detectors for each projection.}
* \astra_xml_item{DetectorColCount, int, Number of detectors for each projection.}
* \astra_xml_item{DetectorWidth, float, Width of each detector.}
* \astra_xml_item{DetectorHeight, float, Width of each detector.}
* \astra_xml_item{ProjectionAngles, vector of float, projection angles in radians.}
*/
class _AstraExport CProjectionGeometry3D
{
protected:
/** Has the object been intialized with acceptable values?
*/
bool m_bInitialized;
/** Number of projection angles.
*/
int m_iProjectionAngleCount;
/** Number of rows of detectors.
*/
int m_iDetectorRowCount;
/** Number of columns of detectors.
*/
int m_iDetectorColCount;
/** Total number of detectors.
*/
int m_iDetectorTotCount;
/** The x-distance between projected rays on the detector plate (or width of projected strips).
*/
float32 m_fDetectorSpacingX;
/** The y-distance between projected rays on the detector plate (or height of projected strips).
*/
float32 m_fDetectorSpacingY;
/** Dynamically allocated array of projection angles. All angles are represented in radians and lie in
* the [0,2pi[ interval.
*/
float32* m_pfProjectionAngles;
/** Default constructor. Sets all numeric member variables to 0 and all pointer member variables to NULL.
*
* If an object is constructed using this default constructor, it must always be followed by a call
* to one of the initialize() methods before the object can be used. Any use before calling initialize()
* is not allowed, except calling the member function isInitialized().
*
*/
CProjectionGeometry3D();
/** Constructor. Create an instance of the CProjectionGeometry3D class.
*
* @param _iProjectionAngleCount Number of projection angles.
* @param _iDetectorRowCount Number of rows of detectors.
* @param _iDetectorColCount Number of columns detectors.
* @param _fDetectorSpacingX Spacing between the detector points on the X-axis, in unit lengths. Assumed to be constant throughout the entire detector plate.
* @param _fDetectorSpacingY Spacing between the detector points on the Y-axis, in unit lengths. Assumed to be constant throughout the entire detector plate.
* @param _pfProjectionAngles Pointer to an array of projection angles. The angles will be copied from this array. All angles
* are represented in radians and lie in the [0,2pi[ interval.
*/
CProjectionGeometry3D(int _iProjectionAngleCount,
int _iDetectorRowCount,
int _iDetectorColCount,
float32 _fDetectorSpacingX,
float32 _fDetectorSpacingY,
const float32* _pfProjectionAngles);
/** Copy constructor.
*/
CProjectionGeometry3D(const CProjectionGeometry3D& _projGeom);
/** Check the values of this object. If everything is ok, the object can be set to the initialized state.
* The following statements are then guaranteed to hold:
* - number of rows and columns is larger than zero
* - detector spacing is larger than zero
* - number of angles is larger than zero
* - (autofix) each angle lies in [0,2pi[
*/
bool _check();
/** Clear all member variables, setting all numeric variables to 0 and all pointers to NULL.
* Should only be used by constructors. Otherwise use the clear() function.
*/
void _clear();
/** Initialize the geometry. If the object has been initialized before, the object is reinitialized
* and memory is freed and reallocated if necessary.
*
* @param _iProjectionAngleCount Number of projection angles.
* @param _iDetectorRowCount Number of rows of detectors.
* @param _iDetectorColCount Number of columns detectors.
* @param _fDetectorSpacingX Spacing between the detector points on the X-axis, in unit lengths. Assumed to be constant throughout the entire detector plate.
* @param _fDetectorSpacingY Spacing between the detector points on the Y-axis, in unit lengths. Assumed to be constant throughout the entire detector plate.
* @param _pfProjectionAngles Pointer to an array of projection angles. The angles will be copied from this array. All angles
* are represented in radians and lie in the [0,2pi[ interval.
*/
bool _initialize(int _iProjectionAngleCount,
int _iDetectorRowCount,
int _iDetectorColCount,
float32 _fDetectorSpacingX,
float32 _fDetectorSpacingY,
const float32* _pfProjectionAngles);
public:
/** Destructor
*/
virtual ~CProjectionGeometry3D();
/** Clear all member variables, setting all numeric variables to 0 and all pointers to NULL.
*/
virtual void clear();
/** Create a hard copy.
*/
virtual CProjectionGeometry3D* clone() const = 0;
/** Initialize the geometry with a config object.
*
* @param _cfg Configuration Object
* @return initialization successful?
*/
virtual bool initialize(const Config& _cfg);
/** Get the initialization state of the object.
*
* @return true iff the object has been initialized
*/
bool isInitialized() const;
/** Return true if this geometry instance is the same as the one specified.
*
* @return true if this geometry instance is the same as the one specified.
*/
virtual bool isEqual(const CProjectionGeometry3D *) const = 0;
/** Get the number of projections.
*
* @return Number of projections
*/
int getProjectionCount() const;
/** Get the number of rows of detectors.
*
* @return Number of rows of detectors.
*/
int getDetectorRowCount() const;
/** Get the number of columns of detectors.
*
* @return Number of columns of detectors.
*/
int getDetectorColCount() const;
/** Get the total number of detectors.
*
* @return Total number of detectors.
*/
int getDetectorTotCount() const;
/** Get the width of a detector.
*
* @return Width of a detector, in unit lengths
*/
float32 getDetectorSpacingX() const;
/** Get the height of a detector.
*
* @return Height of a detector, in unit lengths
*/
float32 getDetectorSpacingY() const;
/** Get a projection angle, given by its index. The angle is represented in Radians.
*
* @return Projection angle with index _iProjectionIndex
*/
float32 getProjectionAngle(int _iProjectionIndex) const;
/** Get a projection angle, given by its index. The angle is represented in degrees.
*
* @return Projection angle with index _iProjectionIndex
*/
// float32 getProjectionAngleDegrees(int _iProjectionIndex) const;
/** Returns a buffer containing all projection angles. The element count of the buffer is equal
* to the number given by getProjectionAngleCount.
*
* The angles are in radians.
*
* @return Pointer to buffer containing the angles.
*/
const float32* getProjectionAngles() const;
/** Get the column index coordinate of a point on a detector array.
*
* @param _fOffsetX Distance between the center of the detector array and a certain point (both on the X-axis).
* @return The location of the point in index X-coordinates (still float, not rounded)
*/
virtual float32 detectorOffsetXToColIndexFloat(float32 _fOffsetX) const;
/** Get the row index coordinate of a point on a detector array.
*
* @param _fOffsetY Distance between the center of the detector array and a certain point (both on the Y-axis).
* @return The location of the point in index Y-coordinates (still float, not rounded)
*/
virtual float32 detectorOffsetYToRowIndexFloat(float32 _fOffsetY) const;
/** Get the offset of a detector on the X-axis based on its index coordinate.
*
* @param _iIndex the index of the detector.
* @return the offset from the center of the detector array on the X-axis.
*/
virtual float32 indexToDetectorOffsetX(int _iIndex) const;
/** Get the offset of a detector on the Y-axis based on its index coordinate.
*
* @param _iIndex the index of the detector.
* @return the offset from the center of the detector array on the Y-axis.
*/
virtual float32 indexToDetectorOffsetY(int _iIndex) const;
/** Get the offset of a detector on the X-axis based on its column index coordinate.
*
* @param _iIndex the index of the detector.
* @return the offset from the center of the detector array on the X-axis.
*/
virtual float32 colIndexToDetectorOffsetX(int _iIndex) const;
/** Get the offset of a detector on the Y-axis based on its row index coordinate.
*
* @param _iIndex the index of the detector.
* @return the offset from the center of the detector array on the Y-axis.
*/
virtual float32 rowIndexToDetectorOffsetY(int _iIndex) const;
/** Get the row and column index of a detector based on its index.
*
* @param _iDetectorIndex in: the index of the detector.
* @param _iDetectorRow out: the row index of the detector.
* @param _iDetectorCol out: the column index of the detector.
*/
virtual void detectorIndexToRowCol(int _iDetectorIndex, int& _iDetectorRow, int& _iDetectorCol) const;
/** Get the angle and detector index of a detector
*
* @param _iIndex the index of the detector.
* @param _iAngleIndex output: index of angle
* @param _iDetectorIndex output: index of detector
*/
virtual void indexToAngleDetectorIndex(int _iIndex, int& _iAngleIndex, int& _iDetectorIndex) const;
/** Project a point onto the detector. The 3D point coordinates
* are in units. The output fU,fV are the (unrounded) indices of the
* detector column and row.
* This may fall outside of the actual detector.
*
* @param fX,fY,fZ coordinates of the point to project
* @param iAngleIndex the index of the angle to use
* @param fU,fV the projected point.
*/
virtual void projectPoint(float32 fX, float32 fY, float32 fZ,
int iAngleIndex,
float32 &fU, float32 &fV) const = 0;
/** Returns true if the type of geometry defined in this class is the one specified in _sType.
*
* @param _sType geometry type to compare to.
* @return true if the type of geometry defined in this class is the one specified in _sType.
*/
virtual bool isOfType(const std::string& _sType) const = 0;
/** Turn this object into an XML object.
*
* @param _sNode The XML object to fill.
*/
virtual void toXML(XMLNode* _sNode) const = 0;
/**
* Returns a vector giving the projection direction for a projection and detector index
*/
virtual CVector3D getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) const = 0;
//< For Config unused argument checking
ConfigCheckData* configCheckData;
friend class ConfigStackCheck<CProjectionGeometry3D>;
};
//----------------------------------------------------------------------------------------
// Inline member functions
//----------------------------------------------------------------------------------------
// Get the initialization state.
inline bool CProjectionGeometry3D::isInitialized() const
{
return m_bInitialized;
}
//----------------------------------------------------------------------------------------
// Get the number of detectors.
inline int CProjectionGeometry3D::getDetectorRowCount() const
{
ASTRA_ASSERT(m_bInitialized);
return m_iDetectorRowCount;
}
//----------------------------------------------------------------------------------------
// Get the number of detectors.
inline int CProjectionGeometry3D::getDetectorColCount() const
{
ASTRA_ASSERT(m_bInitialized);
return m_iDetectorColCount;
}
//----------------------------------------------------------------------------------------
// Get the number of detectors.
inline int CProjectionGeometry3D::getDetectorTotCount() const
{
ASTRA_ASSERT(m_bInitialized);
return m_iDetectorTotCount;
}
//----------------------------------------------------------------------------------------
// Get the width of a single detector (in unit lengths).
inline float32 CProjectionGeometry3D::getDetectorSpacingX() const
{
ASTRA_ASSERT(m_bInitialized);
return m_fDetectorSpacingX;
}
//----------------------------------------------------------------------------------------
// Get the width of a single detector (in unit lengths).
inline float32 CProjectionGeometry3D::getDetectorSpacingY() const
{
ASTRA_ASSERT(m_bInitialized);
return m_fDetectorSpacingY;
}
//----------------------------------------------------------------------------------------
// Get the number of projection angles.
inline int CProjectionGeometry3D::getProjectionCount() const
{
ASTRA_ASSERT(m_bInitialized);
return m_iProjectionAngleCount;
}
//----------------------------------------------------------------------------------------
// Get a projection angle, represented in Radians.
inline float32 CProjectionGeometry3D::getProjectionAngle(int _iProjectionIndex) const
{
// basic checks
ASTRA_ASSERT(m_bInitialized);
ASTRA_ASSERT(_iProjectionIndex >= 0);
ASTRA_ASSERT(_iProjectionIndex < m_iProjectionAngleCount);
return m_pfProjectionAngles[_iProjectionIndex];
}
/*
//----------------------------------------------------------------------------------------
// Get a projection angle, represented in degrees.
inline float32 CProjectionGeometry3D::getProjectionAngleDegrees(int _iProjectionIndex) const
{
// basic checks
ASTRA_ASSERT(m_bInitialized);
ASTRA_ASSERT(_iProjectionIndex >= 0);
ASTRA_ASSERT(_iProjectionIndex < m_iProjectionAngleCount);
return (m_pfProjectionAngles[_iProjectionIndex] * 180.0f / PI32);
}
*/
//----------------------------------------------------------------------------------------
// Get pointer to buffer used to store projection angles.
inline const float32* CProjectionGeometry3D::getProjectionAngles() const
{
// basic checks
ASTRA_ASSERT(m_bInitialized);
return m_pfProjectionAngles;
}
//----------------------------------------------------------------------------------------
// detector offset X -> detector column index (float)
inline float32 CProjectionGeometry3D::detectorOffsetXToColIndexFloat(float32 _fOffsetX) const
{
// basic checks
ASTRA_ASSERT(m_bInitialized);
return (_fOffsetX / m_fDetectorSpacingX) + ((m_iDetectorColCount-1.0f) / 2.0f);
}
//----------------------------------------------------------------------------------------
// detector offset Y -> detector row index (float)
inline float32 CProjectionGeometry3D::detectorOffsetYToRowIndexFloat(float32 _fOffsetY) const
{
// basic checks
ASTRA_ASSERT(m_bInitialized);
return (_fOffsetY / m_fDetectorSpacingY) + ((m_iDetectorRowCount-1.0f) / 2.0f);
}
//----------------------------------------------------------------------------------------
// detector index -> detector offset X
inline float32 CProjectionGeometry3D::indexToDetectorOffsetX(int _iIndex) const
{
// basic checks
ASTRA_ASSERT(m_bInitialized);
ASTRA_ASSERT(_iIndex >= 0);
ASTRA_ASSERT(_iIndex < m_iDetectorTotCount);
_iIndex = _iIndex % m_iDetectorColCount;
return (_iIndex - (m_iDetectorColCount-1.0f) / 2.0f) * m_fDetectorSpacingX;
}
//----------------------------------------------------------------------------------------
// detector index -> detector offset Y
inline float32 CProjectionGeometry3D::indexToDetectorOffsetY(int _iIndex) const
{
// basic checks
ASTRA_ASSERT(m_bInitialized);
ASTRA_ASSERT(_iIndex >= 0);
ASTRA_ASSERT(_iIndex < m_iDetectorTotCount);
_iIndex = _iIndex / m_iDetectorColCount;
return -(_iIndex - (m_iDetectorRowCount-1.0f) / 2.0f) * m_fDetectorSpacingY;
}
//----------------------------------------------------------------------------------------
// detector index -> detector offset X
inline float32 CProjectionGeometry3D::colIndexToDetectorOffsetX(int _iIndex) const
{
// basic checks
ASTRA_ASSERT(m_bInitialized);
ASTRA_ASSERT(_iIndex >= 0);
ASTRA_ASSERT(_iIndex < m_iDetectorColCount);
return (_iIndex - (m_iDetectorColCount-1.0f) / 2.0f) * m_fDetectorSpacingX;
}
//----------------------------------------------------------------------------------------
// detector index -> detector offset Y
inline float32 CProjectionGeometry3D::rowIndexToDetectorOffsetY(int _iIndex) const
{
// basic checks
ASTRA_ASSERT(m_bInitialized);
ASTRA_ASSERT(_iIndex >= 0);
ASTRA_ASSERT(_iIndex < m_iDetectorRowCount);
return (_iIndex - (m_iDetectorRowCount-1.0f) / 2.0f) * m_fDetectorSpacingY;
}
//----------------------------------------------------------------------------------------
// detector index -> row index & column index
inline void CProjectionGeometry3D::detectorIndexToRowCol(int _iDetectorIndex, int& _iDetectorRow, int& _iDetectorCol) const
{
ASTRA_ASSERT(m_bInitialized);
ASTRA_ASSERT(_iDetectorIndex >= 0);
ASTRA_ASSERT(_iDetectorIndex < m_iDetectorTotCount);
_iDetectorRow = _iDetectorIndex / m_iDetectorColCount;
_iDetectorCol = _iDetectorIndex % m_iDetectorColCount;
}
//----------------------------------------------------------------------------------------
inline void CProjectionGeometry3D::indexToAngleDetectorIndex(int _iIndex, int& _iAngleIndex, int& _iDetectorIndex) const
{
ASTRA_ASSERT(m_bInitialized);
ASTRA_ASSERT(_iIndex >= 0);
ASTRA_ASSERT(_iIndex < m_iDetectorTotCount * m_iProjectionAngleCount);
// int det_row = _iIndex / (m_iDetectorColCount*m_iProjectionAngleCount);
// int det_col = _iIndex % m_iDetectorColCount;
//
// _iAngleIndex = _iIndex % (m_iDetectorColCount*m_iProjectionAngleCount) / m_iDetectorColCount;
// _iDetectorIndex = det_row * m_iDetectorColCount + det_col;
_iAngleIndex = (_iIndex % (m_iDetectorColCount*m_iProjectionAngleCount)) / m_iDetectorColCount;
_iDetectorIndex = _iIndex / m_iProjectionAngleCount + (_iIndex % m_iDetectorColCount);
}
//----------------------------------------------------------------------------------------
} // end namespace astra
#endif /* _INC_ASTRA_PROJECTIONGEOMETRY2D */
|