summaryrefslogtreecommitdiffstats
path: root/include/astra/VolumeGeometry3D.h
blob: d5c8fff52dbad694c232753b004d6750c7430d47 (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
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
/*
-----------------------------------------------------------------------
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_VOLUMEGEOMETRY3D
#define _INC_ASTRA_VOLUMEGEOMETRY3D

#include "Globals.h"
#include "Config.h"
#include "VolumeGeometry2D.h"

namespace astra
{

/** 
 * This class represents a 3D pixel grid that is placed in the geometry. It defines a rectangular volume window.
 *
 * \par XML Configuration
 * \astra_xml_item{GridColCount, integer, Number of columns in this geometry.}
 * \astra_xml_item{GridRowCount, integer, Number of rows in this geometry.}
 * \astra_xml_item{GridSliceCount, integer, Number of slices in this geometry.}
 * \astra_xml_item_option{WindowMinX, float, -GridColCount/2, Minimal X-coordinate in the volume window.}
 * \astra_xml_item_option{WindowMaxX, float, GridColCount/2, Maximal X-coordinate in the volume window.}
 * \astra_xml_item_option{WindowMinY, float, -GridRowCount/2, Minimal Y-coordinate in the volume window.}
 * \astra_xml_item_option{WindowMaxY, float, GridRowCount/2, Maximal Y-coordinate in the volume window.}
 * \astra_xml_item_option{WindowMinZ, float, -GridSliceCount/2, Minimal Z-coordinate in the volume window.}
 * \astra_xml_item_option{WindowMaxZ, float, GridSliceCount/2, Maximal Z-coordinate in the volume window.}
 *
 * \par MATLAB example
 * \astra_code{
 *		vol_geom = struct();\n
 *		vol_geom.GridColCount = 1024;\n
 *		vol_geom.GridRowCount = 768;\n
 * 		vol_geom.GridSliceCount = 300;\n
 *		vol_geom.option.WindowMinX = -512;\n
 *		vol_geom.option.WindowMaxX = -384;\n
 *		vol_geom.option.WindowMinY = 512;\n 
 *		vol_geom.option.WindowMaxY = 384;\n
 *		vol_geom.option.WindowMinZ = -150;\n 
 *		vol_geom.option.WindowMaxZ = 150;\n
 * }
 */
class _AstraExport CVolumeGeometry3D {

protected:
	bool m_bInitialized;        ///< Has this object been initialized?

	int m_iGridColCount;		///< number of columns in the volume grid.
	int m_iGridRowCount;		///< number of rows in the volume grid.
	int m_iGridSliceCount;		///< number of slices in the volume grid.
	int m_iGridTotCount;		///< total number of pixels in the volume grid (= m_iGridColCount * m_iGridRowCount * m_iGridSliceCount).

	/** Width of the volume window, in unit lengths.
	 *
	 * Note that this width is independent of the number of pixels in the X-direction, as the width of a pixel can 
	 * be different from 1.
	 */
	float32 m_fWindowLengthX;      

	/** Height of the volume window, in unit lengths.
	 *
	 * Note that this height is independent of the number of pixels in the Y-direction, as the height of a pixel can 
	 * be different from 1.
	 */
	float32 m_fWindowLengthY; 

	/** Depth of the volume window, in unit lengths.
	 *
	 * Note that this depth is independent of the number of pixels in the Z-direction, as the depth of a pixel can 
	 * be different from 1.
	 */
	float32 m_fWindowLengthZ; 

	/** Total area of the volume window, in unit lengths squared.
	 */
	float32 m_fWindowArea;      

	float32 m_fPixelLengthX;	///< Width of a single pixel, in unit lengths.
	float32 m_fPixelLengthY;    ///< Height of a single pixel, in unit lengths.
	float32 m_fPixelLengthZ;    ///< Depth of a single pixel, in unit lengths.
	float32 m_fPixelArea;       ///< Area of a single pixel, in unit lengths squared.

	float32 m_fDivPixelLengthX; ///< 1/m_fPixelLengthX, used for fast division.
	float32 m_fDivPixelLengthY; ///< 1/m_fPixelLengthY, used for fast division.
	float32 m_fDivPixelLengthZ; ///< 1/m_fPixelLengthZ, used for fast division.

	float32 m_fWindowMinX;		///< Minimal X-coordinate in the volume window.
	float32 m_fWindowMinY;      ///< Minimal Y-coordinate in the volume window.
	float32 m_fWindowMinZ;      ///< Minimal Z-coordinate in the volume window.
	float32 m_fWindowMaxX;      ///< Maximal X-coordinate in the volume window.
	float32 m_fWindowMaxY;      ///< Maximal Y-coordinate in the volume window. 
	float32 m_fWindowMaxZ;      ///< Maximal Z-coordinate in the volume window. 

	/** 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, columns and slices is larger than zero
	 * - window minima is smaller than window maxima
	 * - m_iGridTotCount, m_fWindowLengthX, m_fWindowLengthY, m_fWindowLengthZ, m_fWindowArea, m_fPixelLengthX, 
	 *   m_fPixelLengthY, m_fPixelLengthZ, m_fPixelArea, m_fDivPixelLengthX, m_fDivPixelLengthY 
	 *   and m_fDivPixelLengthZ are initialized ok
	 */
	bool _check();

public:

	/** 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 init() methods before the object can be used. Any use before calling init() is not allowed,
	 * except calling the member function isInitialized().
	 */
	CVolumeGeometry3D();

	/** Constructor. Create an instance of the CVolumeGeometry2D class. 
	 * The minimal and coordinates values of the geometry will be set to -/+ the number of rows/columns.
	 *
	 * @param _iGridCountX Number of columns in the volume grid.
	 * @param _iGridCountY Number of rows in the volume grid.
	 * @param _iGridCountZ Number of slices in the volume grid.
	 */
	CVolumeGeometry3D(int _iGridCountX, int _iGridCountY, int _iGridCountZ);

	/** Constructor. Create an instance of the CVolumeGeometry2D class.
	 *
	 * @param _iGridCountX Number of columns in the volume grid.
	 * @param _iGridCountY Number of rows in the volume grid.
	 * @param _iGridCountZ Number of slices in the volume grid.
	 * @param _fWindowMinX Minimal X-coordinate in the volume window.
	 * @param _fWindowMinY Minimal Y-coordinate in the volume window.
	 * @param _fWindowMinZ Minimal Z-coordinate in the volume window.
	 * @param _fWindowMaxX Maximal X-coordinate in the volume window.
	 * @param _fWindowMaxY Maximal Y-coordinate in the volume window.
	 * @param _fWindowMaxZ Maximal Z-coordinate in the volume window.
	 */
	CVolumeGeometry3D(int _iGridCountX, 
					  int _iGridCountY, 
					  int _iGridCountZ, 
					  float32 _fWindowMinX, 
					  float32 _fWindowMinY, 
					  float32 _fWindowMinZ, 
					  float32 _fWindowMaxX, 
					  float32 _fWindowMaxY,
					  float32 _fWindowMaxZ);

	/**
	 * Copy constructor
	 */
	CVolumeGeometry3D(const CVolumeGeometry3D& _other);

	/**
	 * Assignment operator
	 */
	CVolumeGeometry3D& operator=(const CVolumeGeometry3D& _other);

	/** Destructor.
	 */
	virtual ~CVolumeGeometry3D();

	/** Clear all member variables, setting all numeric variables to 0 and all pointers to NULL. 
	*/
	void clear();

	/** Create a hard copy. 
	*/
	CVolumeGeometry3D* clone() const;

	/** Initialize the volume geometry with a config object.
	 *
	 * @param _cfg Configuration Object.
	 * @return initialization successful?
	 */
	virtual bool initialize(const Config& _cfg);

	/** Initialization. Initializes an instance of the CVolumeGeometry3D class.
	 * The minimal and maximal coordinates of the geometry will be set to -/+ half the number of rows/columns/slices.
	 *
	 * If the object has been initialized before, the object is reinitialized and 
	 * memory is freed and reallocated if necessary.
	 *
	 * @param _iGridColCount Number of columns in the volume grid.
	 * @param _iGridRowCount Number of rows in the volume grid.
	 * @param _iGridSliceCount Number of slices in the volume grid.
	 * @return initialization successful
	 */
	bool initialize(int _iGridColCount, int _iGridRowCount, int _iGridSliceCount);

	/** Initialization. Initializes an instance of the CVolumeGeometry3D class.
	 *
	 * If the object has been initialized before, the object is reinitialized and 
	 * memory is freed and reallocated if necessary.
	 *
	 * @param _iGridColCount Number of columns in the volume grid.
	 * @param _iGridRowCount Number of rows in the volume grid.
	 * @param _iGridSliceCount Number of slices in the volume grid.
	 * @param _fWindowMinX Minimal X-coordinate in the volume window.
	 * @param _fWindowMinY Minimal Y-coordinate in the volume window.
	 * @param _fWindowMinZ Minimal Z-coordinate in the volume window.
	 * @param _fWindowMaxX Maximal X-coordinate in the volume window.
	 * @param _fWindowMaxY Maximal Y-coordinate in the volume window.
	 * @param _fWindowMaxZ Maximal Z-coordinate in the volume window.
	 * @return initialization successful
	 */
	bool initialize(int _iGridColCount, 
					int _iGridRowCount, 
					int _iGridSliceCount, 
					float32 _fWindowMinX, 
					float32 _fWindowMinY, 
					float32 _fWindowMinZ,
					float32 _fWindowMaxX, 
					float32 _fWindowMaxY,
					float32 _fWindowMaxZ);

	/** 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 CVolumeGeometry3D*) const;

	/** Get the number of columns in the volume grid.
	 *
	 * @return Number of columns in the volume grid.
	 */
	int getGridColCount() const;
	
	/** Get the number of rows in the volume grid.
	 *
	 * @return Number of rows in the volume grid.
	 */
	int getGridRowCount() const;

	/** Get the number of slices in the volume grid.
	 *
	 * @return Number of slices in the volume grid.
	 */
	int getGridSliceCount() const;

	/** Get the total number of pixels in the volume grid.
	 *
	 * @return Total number of pixels.
	 */
	int getGridTotCount() const;

	/** Get the horizontal length of the volume window, in unit lengths.
	 *
	 * @return Horizontal length of the volume window.
	 */
	float32 getWindowLengthX() const;

	/** Get the vertical length of the volume window, in unit lengths.
	 *
	 * @return Vertical length of the volume window.
	 */
	float32 getWindowLengthY() const;

	/** Get the depth of the volume window, in unit lengths.
	 *
	 * @return Depth of the volume window.
	 */
	float32 getWindowLengthZ() const;

	/** Get the total area of the volume window, in unit lengths squared.
	 *
	 * @return Total area of the volume window.
	 */
	float32 getWindowArea() const;

	/** Get the horizontal length of a single pixel (i.e., width), in unit lengths.
	 *
	 * @return Horizontal length of a single pixel.
	 */
	float32 getPixelLengthX() const;

	/** Get the vertical length of a single pixel (i.e., height), in unit lengths.
	 *
	 * @return Vertical length of a single pixel.
	 */
	float32 getPixelLengthY() const;

	/** Get the depth of a single pixel in unit lengths.
	 *
	 * @return Depth of a single pixel.
	 */
	float32 getPixelLengthZ() const;

	/** Get the area of a single pixel (width*height*depth), in unit lengths squared.
	 *
	 * @return Area of a single pixel.
	 */
	float32 getPixelArea() const;

	/** Get the minimal X-coordinate in the volume window.
	 *
	 * @return Minimal X-coordinate in the volume window.
	 */
	float32 getWindowMinX() const;

	/** Get the minimal Y-coordinate in the volume window.
	 *
	 * @return Minimal Y-coordinate in the volume window.
	 */
	float32 getWindowMinY() const;

	/** Get the minimal Z-coordinate in the volume window.
	 *
	 * @return Minimal Z-coordinate in the volume window.
	 */
	float32 getWindowMinZ() const;

	/** Get the maximal X-coordinate in the volume window.
	 *
	 * @return Maximal X-coordinate in the volume window.
	 */
	float32 getWindowMaxX() const;

	/** Get the maximal Y-coordinate in the volume window.
	 *
	 * @return Maximal Y-coordinate in the volume window.
	 */
	float32 getWindowMaxY() const;

	/** Get the maximal Z-coordinate in the volume window.
	 *
	 * @return Maximal Z-coordinate in the volume window.
	 */
	float32 getWindowMaxZ() const;

	/** Convert row, column and slice index of a pixel to a single index in the interval [0..getGridTotCount()-1].
	 * 
	 * @param _iPixelRow Row index of the pixel, in the interval [0..getGridRowCount()-1].
	 * @param _iPixelCol Column index of the pixel, in the interval [0..getGridColCount()-1].
	 * @param _iPixelSlice Slice index of the pixel, in the interval [0..getGridSliceCount()-1].
	 * @return Computed index of the pixel, in the interval [0..getGridTotCount()-1].
	 */
	int pixelRowColSliceToIndex(int _iPixelRow, int _iPixelCol, int _iPixelSlice) const;

	/** Convert a pixel index (from the interval [0..getGridTotCount()-1] to row, column and slice index.
	 *
	 * @param _iPixelIndex Index of the pixel, in the interval [0..getGridTotCount()-1].
	 * @param _iPixelRow Computed row index of the pixel, in the interval [0..getGridRowCount()-1].
	 * @param _iPixelCol Computed column index of the pixel, in the interval [0..getGridColCount()-1].
	 * @param _iPixelSlice Computed slice index of the pixel, in the interval [0..getGridSliceCount()-1].
	 */
	void pixelIndexToRowColSlice(int _iPixelIndex, int &_iPixelRow, int &_iPixelCol, int &_iPixelSlice) const;

	/** Convert a pixel column index to the X-coordinate of its center.
	 *
	 * @param _iPixelCol Column index of the pixel.
	 * @return X-coordinate of the pixel center.
	 */
	float32 pixelColToCenterX(int _iPixelCol) const;

	/** Convert a pixel column index to the minimum X-coordinate of points in that column.
	 *
	 * @param _iPixelCol Column index of the pixel.
	 * @return Minimum X-coordinate.
	 */
	float32 pixelColToMinX(int _iPixelCol) const;

	/** Convert a pixel column index to the maximum X-coordinate of points in that column.
	 *
	 * @param _iPixelCol Column index of the pixel.
	 * @return Maximum X-coordinate.
	 */
	float32 pixelColToMaxX(int _iPixelCol) const;

	/** Convert a pixel row index to the Y-coordinate of its center.
	 *
	 * @param _iPixelRow Row index of the pixel.
	 * @return Y-coordinate of the pixel center.
	 */
	float32 pixelRowToCenterY(int _iPixelRow) const;

	/** Convert a pixel row index to the minimum Y-coordinate of points in that row.
	 *
	 * @param _iPixelRow Row index of the pixel.
	 * @return Minimum Y-coordinate.
	 */
	float32 pixelRowToMinY(int _iPixelRow) const;

	/** Convert a pixel row index to the maximum Y-coordinate of points in that row.
	 *
	 * @param _iPixelRow Row index of the pixel.
	 * @return Maximum Y-coordinate.
	 */
	float32 pixelRowToMaxY(int _iPixelRow) const;

	/** Convert a pixel slice index to the Z-coordinate of its center.
	 *
	 * @param _iPixelSlice Slice index of the pixel.
	 * @return Z-coordinate of the pixel center.
	 */
	float32 pixelSliceToCenterZ(int _iPixelSlice) const;

	/** Convert a pixel slice index to the minimum Z-coordinate of points in that slice.
	 *
	 * @param _iPixelSlice Slice index of the pixel.
	 * @return Minimum Z-coordinate.
	 */
	float32 pixelSliceToMinZ(int _iPixelSlice) const;

	/** Convert a pixel slice index to the maximum Z-coordinate of points in that slice.
	 *
	 * @param _iPixelSlice Slice index of the pixel.
	 * @return Maximum Z-coordinate.
	 */
	float32 pixelSliceToMaxZ(int _iPixelSlice) const;

	/** Convert an X-coordinate to a column index in the volume grid.
	 *
	 * @param _fCoordX X-coordinate.
	 * @return If the X-coordinate falls within a column of the volume grid, the column index is returned. 
	 * Otherwise, a value of -1 is returned.
	 */
	int coordXToCol(float32 _fCoordX) const;

	/** Convert a Y-coordinate to a row index in the volume grid.
	 *
	 * @param _fCoordY Y-coordinate 
	 * @return If the Y-coordinate falls within a row of the volume grid, the row index is returned. 
	 * Otherwise, a value of -1 is returned.
	 */
	int coordYToRow(float32 _fCoordY) const;

	/** Convert a Z-coordinate to a slice index in the volume grid.
	 *
	 * @param _fCoordZ Z-coordinate 
	 * @return If the Z-coordinate falls within a slice of the volume grid, the slice index is returned. 
	 * Otherwise, a value of -1 is returned.
	 */
	int coordZToSlice(float32 _fCoordZ) const;

	/** Convert an X-coordinate to a column index in the volume grid.
	 *
	 * @param _fCoordX X-coordinate.
	 * @return If the X-coordinate falls within a column of the volume grid, the column index is returned. 
	 * Otherwise, a value of -1 is returned.
	 */
	float32 coordXToColFloat(float32 _fCoordX) const;

	/** Convert a Y-coordinate to a row index in the volume grid.
	 *
	 * @param _fCoordY Y-coordinate 
	 * @return If the Y-coordinate falls within a row of the volume grid, the row index is returned. 
	 * Otherwise, a value of -1 is returned.
	 */
	float32 coordYToRowFloat(float32 _fCoordY) const;

	/** Convert a Z-coordinate to a slice index in the volume grid.
	 *
	 * @param _fCoordZ Z-coordinate 
	 * @return If the Z-coordinate falls within a slice of the volume grid, the slice index is returned. 
	 * Otherwise, a value of -1 is returned.
	 */
	float32 coordZToSliceFloat(float32 _fCoordZ) const;

	CVolumeGeometry2D * createVolumeGeometry2D() const;


	//< For Config unused argument checking
	ConfigCheckData* configCheckData;
	friend class ConfigStackCheck<CVolumeGeometry3D>;
};


//----------------------------------------------------------------------------------------
// Get the initialization state of the object.
inline bool CVolumeGeometry3D::isInitialized() const
{
	return m_bInitialized;
}

//----------------------------------------------------------------------------------------
// Get the number of columns in the volume grid.
inline int CVolumeGeometry3D::getGridColCount() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_iGridColCount;
}
	
//----------------------------------------------------------------------------------------
// Get the number of rows in the volume grid.
inline int CVolumeGeometry3D::getGridRowCount() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_iGridRowCount;
}

//----------------------------------------------------------------------------------------
// Get the number of rows in the volume grid.
inline int CVolumeGeometry3D::getGridSliceCount() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_iGridSliceCount;
}

//----------------------------------------------------------------------------------------
// Get the total number of pixels in the volume window.
inline int CVolumeGeometry3D::getGridTotCount() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_iGridTotCount;
}

//----------------------------------------------------------------------------------------
// Get the horizontal length of the volume window, in unit lengths.
inline float32 CVolumeGeometry3D::getWindowLengthX() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowLengthX;
}

//----------------------------------------------------------------------------------------
// Get the vertical length of the volume window, in unit lengths.
inline float32 CVolumeGeometry3D::getWindowLengthY() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowLengthY;
}

//----------------------------------------------------------------------------------------
// Get the vertical length of the volume window, in unit lengths.
inline float32 CVolumeGeometry3D::getWindowLengthZ() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowLengthZ;
}

//----------------------------------------------------------------------------------------
// Get the total area of the volume window, in unit lengths squared.
inline float32 CVolumeGeometry3D::getWindowArea() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowArea;
}

//----------------------------------------------------------------------------------------
// Get the horizontal length of a single pixel (i.e., width), in unit lengths.
inline float32 CVolumeGeometry3D::getPixelLengthX() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fPixelLengthX;
}

//----------------------------------------------------------------------------------------
// Get the vertical length of a single pixel (i.e., height), in unit lengths.
inline float32 CVolumeGeometry3D::getPixelLengthY() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fPixelLengthY;
}

//----------------------------------------------------------------------------------------
// Get the depth of a single pixel in unit lengths.
inline float32 CVolumeGeometry3D::getPixelLengthZ() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fPixelLengthZ;
}

//----------------------------------------------------------------------------------------
// Get the area of a single pixel (width*height), in unit lengths squared.
inline float32 CVolumeGeometry3D::getPixelArea() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fPixelArea;
}

//----------------------------------------------------------------------------------------
// Get the minimal X-coordinate in the volume window.
inline float32 CVolumeGeometry3D::getWindowMinX() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowMinX;
}

//----------------------------------------------------------------------------------------
// Get the minimal Y-coordinate in the volume window.
inline float32 CVolumeGeometry3D::getWindowMinY() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowMinY;
}

//----------------------------------------------------------------------------------------
// Get the minimal Y-coordinate in the volume window.
inline float32 CVolumeGeometry3D::getWindowMinZ() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowMinZ;
}

//----------------------------------------------------------------------------------------
// Get the maximal X-coordinate in the volume window.
inline float32 CVolumeGeometry3D::getWindowMaxX() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowMaxX;
}

//----------------------------------------------------------------------------------------
// Get the maximal Y-coordinate in the volume window.
inline float32 CVolumeGeometry3D::getWindowMaxY() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowMaxY;
}

//----------------------------------------------------------------------------------------
// Get the maximal Z-coordinate in the volume window.
inline float32 CVolumeGeometry3D::getWindowMaxZ() const
{
	ASTRA_ASSERT(m_bInitialized);
	return m_fWindowMaxZ;
}

//----------------------------------------------------------------------------------------
// Convert row, column and slice index of a pixel to a single index in the interval [0..getGridCountTot()-1].
inline int CVolumeGeometry3D::pixelRowColSliceToIndex(int _iPixelRow, int _iPixelCol, int _iPixelSlice) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelCol >= 0);
	ASTRA_ASSERT(_iPixelCol < m_iGridColCount);
	ASTRA_ASSERT(_iPixelRow >= 0);
	ASTRA_ASSERT(_iPixelRow < m_iGridRowCount);
	ASTRA_ASSERT(_iPixelSlice >= 0);
	ASTRA_ASSERT(_iPixelSlice < m_iGridSliceCount);

	return (m_iGridColCount*m_iGridRowCount*_iPixelSlice + _iPixelRow * m_iGridColCount + _iPixelCol);
}

//----------------------------------------------------------------------------------------
// Convert a pixel index (from the interval [0..getGridCountTot()-1] to a row, column and slice index.
inline void CVolumeGeometry3D::pixelIndexToRowColSlice(int _iPixelIndex, int &_iPixelRow, int &_iPixelCol, int &_iPixelSlice) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelIndex >= 0);
	ASTRA_ASSERT(_iPixelIndex < m_iGridTotCount);

	_iPixelSlice = _iPixelIndex / (m_iGridRowCount*m_iGridColCount);
	_iPixelRow = (_iPixelIndex-_iPixelSlice*m_iGridRowCount*m_iGridColCount) / m_iGridColCount;
	_iPixelCol = (_iPixelIndex-_iPixelSlice*m_iGridRowCount*m_iGridColCount) % m_iGridColCount;
}

//----------------------------------------------------------------------------------------
// Convert a pixel column index to the X-coordinate of its center
inline float32 CVolumeGeometry3D::pixelColToCenterX(int _iPixelCol) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelCol >= 0);
	ASTRA_ASSERT(_iPixelCol < m_iGridColCount);

	return (m_fWindowMinX + (float32(_iPixelCol) + 0.5f) * m_fPixelLengthX);
}

//----------------------------------------------------------------------------------------
// Convert a pixel column index to the minimum X-coordinate of points in that column
inline float32 CVolumeGeometry3D::pixelColToMinX(int _iPixelCol) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelCol >= 0);
	ASTRA_ASSERT(_iPixelCol < m_iGridColCount);

	return (m_fWindowMinX + float32(_iPixelCol) * m_fPixelLengthX);
}

//----------------------------------------------------------------------------------------
// Convert a pixel column index to the maximum X-coordinate of points in that column
inline float32 CVolumeGeometry3D::pixelColToMaxX(int _iPixelCol) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelCol >= 0);
	ASTRA_ASSERT(_iPixelCol < m_iGridColCount);

	return (m_fWindowMaxX + (float32(_iPixelCol) + 1.0f) * m_fPixelLengthX);
}

//----------------------------------------------------------------------------------------
// Convert a pixel row index to the Y-coordinate of its center
inline float32 CVolumeGeometry3D::pixelRowToCenterY(int _iPixelRow) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelRow >= 0);
	ASTRA_ASSERT(_iPixelRow < m_iGridRowCount);

	return (m_fWindowMaxY - (float32(_iPixelRow) + 0.5f) * m_fPixelLengthY);
}

//----------------------------------------------------------------------------------------
// Convert a pixel row index to the minimum Y-coordinate of points in that row
inline float32 CVolumeGeometry3D::pixelRowToMinY(int _iPixelRow) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelRow >= 0);
	ASTRA_ASSERT(_iPixelRow < m_iGridRowCount);

	return (m_fWindowMaxY - (float32(_iPixelRow) + 1.0f) * m_fPixelLengthY);
}

//----------------------------------------------------------------------------------------
// Convert a pixel row index to the maximum Y-coordinate of points in that row
inline float32 CVolumeGeometry3D::pixelRowToMaxY(int _iPixelRow) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelRow >= 0);
	ASTRA_ASSERT(_iPixelRow < m_iGridRowCount);

	return (m_fWindowMaxY - (float32(_iPixelRow) * m_fPixelLengthY));
}

//----------------------------------------------------------------------------------------
// Convert a pixel slice index to the Z-coordinate of its center
inline float32 CVolumeGeometry3D::pixelSliceToCenterZ(int _iPixelSlice) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelSlice >= 0);
	ASTRA_ASSERT(_iPixelSlice < m_iGridSliceCount);

	return (m_fWindowMaxZ - (float32(_iPixelSlice) + 0.5f) * m_fPixelLengthZ);
}

//----------------------------------------------------------------------------------------
// Convert a pixel row index to the minimum Y-coordinate of points in that row
inline float32 CVolumeGeometry3D::pixelSliceToMinZ(int _iPixelSlice) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelSlice >= 0);
	ASTRA_ASSERT(_iPixelSlice < m_iGridSliceCount);

	return (m_fWindowMaxZ - (float32(_iPixelSlice) + 1.0f) * m_fPixelLengthZ);
}

//----------------------------------------------------------------------------------------
// Convert a pixel row index to the maximum Y-coordinate of points in that row
inline float32 CVolumeGeometry3D::pixelSliceToMaxZ(int _iPixelSlice) const
{
	ASTRA_ASSERT(m_bInitialized);
	ASTRA_ASSERT(_iPixelSlice >= 0);
	ASTRA_ASSERT(_iPixelSlice < m_iGridSliceCount);

	return (m_fWindowMaxZ - (float32(_iPixelSlice) * m_fPixelLengthZ));
}

//----------------------------------------------------------------------------------------
// Convert an X-coordinate to a column index in the volume grid
inline int CVolumeGeometry3D::coordXToCol(float32 _fCoordX) const
{
	if (_fCoordX < m_fWindowMinX) return -1;
	if (_fCoordX > m_fWindowMaxX) return -1;
	
	int iCol = int((_fCoordX - m_fWindowMinX) * m_fDivPixelLengthX);
	ASTRA_ASSERT(iCol >= 0);
	ASTRA_ASSERT(iCol < m_iGridColCount);

	return iCol;
}

//----------------------------------------------------------------------------------------
// Convert a Y-coordinate to a row index in the volume grid
inline int CVolumeGeometry3D::coordYToRow(float32 _fCoordY) const
{
	if (_fCoordY < m_fWindowMinY) return -1;
	if (_fCoordY > m_fWindowMaxY) return -1;
	
	int iRow = int((m_fWindowMaxY - _fCoordY) * m_fDivPixelLengthY);
	ASTRA_ASSERT(iRow >= 0);
	ASTRA_ASSERT(iRow < m_iGridRowCount);

	return iRow;
}

//----------------------------------------------------------------------------------------
// Convert a Z-coordinate to a slice index in the volume grid
inline int CVolumeGeometry3D::coordZToSlice(float32 _fCoordZ) const
{
	if (_fCoordZ < m_fWindowMinZ) return -1;
	if (_fCoordZ > m_fWindowMaxZ) return -1;
	
	int iSlice = int((m_fWindowMaxZ - _fCoordZ) * m_fDivPixelLengthZ);
	ASTRA_ASSERT(iSlice >= 0);
	ASTRA_ASSERT(iSlice < m_iGridSliceCount);

	return iSlice;
}

//----------------------------------------------------------------------------------------
// Convert an X-coordinate to a column index in the volume grid
inline float32 CVolumeGeometry3D::coordXToColFloat(float32 _fCoordX) const
{
	ASTRA_ASSERT(m_bInitialized);
	return (_fCoordX - m_fWindowMinX) * m_fDivPixelLengthX;
}

//----------------------------------------------------------------------------------------
// Convert a Y-coordinate to a row index in the volume grid
inline float32 CVolumeGeometry3D::coordYToRowFloat(float32 _fCoordY) const
{
	ASTRA_ASSERT(m_bInitialized);
	return (m_fWindowMaxY - _fCoordY) * m_fDivPixelLengthY;
}

//----------------------------------------------------------------------------------------
// Convert a Z-coordinate to a slice index in the volume grid
inline float32 CVolumeGeometry3D::coordZToSliceFloat(float32 _fCoordZ) const
{
	ASTRA_ASSERT(m_bInitialized);
	return (m_fWindowMaxZ - _fCoordZ) * m_fDivPixelLengthZ;
}
//----------------------------------------------------------------------------------------

} // end namespace astra

#endif /* _INC_ASTRA_VOLUMEGEOMETRY2D */