1 | // ----------------------------------------------------------------------- |
---|
2 | // Voxel.cc: Member functions for the Voxel class. |
---|
3 | // ----------------------------------------------------------------------- |
---|
4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
5 | // |
---|
6 | // This program is free software; you can redistribute it and/or modify it |
---|
7 | // under the terms of the GNU General Public License as published by the |
---|
8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
9 | // option) any later version. |
---|
10 | // |
---|
11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
14 | // for more details. |
---|
15 | // |
---|
16 | // You should have received a copy of the GNU General Public License |
---|
17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
19 | // |
---|
20 | // Correspondence concerning Duchamp may be directed to: |
---|
21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
22 | // Postal address: Dr. Matthew Whiting |
---|
23 | // Australia Telescope National Facility, CSIRO |
---|
24 | // PO Box 76 |
---|
25 | // Epping NSW 1710 |
---|
26 | // AUSTRALIA |
---|
27 | // ----------------------------------------------------------------------- |
---|
28 | #include <iostream> |
---|
29 | #include <iomanip> |
---|
30 | #include <duchamp/PixelMap/Voxel.hh> |
---|
31 | |
---|
32 | namespace PixelInfo |
---|
33 | { |
---|
34 | |
---|
35 | Voxel::Voxel(long x, long y, long z, float f) : |
---|
36 | itsX(x), itsY(y), itsZ(z), itsF(f) |
---|
37 | { |
---|
38 | } |
---|
39 | //-------------------------------------------------------------------- |
---|
40 | |
---|
41 | Voxel::Voxel(long x, long y, long z) : |
---|
42 | itsX(x), itsY(y), itsZ(z), itsF(0.) |
---|
43 | { |
---|
44 | } |
---|
45 | //-------------------------------------------------------------------- |
---|
46 | |
---|
47 | Voxel::Voxel(long x, long y) : |
---|
48 | itsX(x), itsY(y), itsZ(0), itsF(0.) |
---|
49 | { |
---|
50 | } |
---|
51 | //-------------------------------------------------------------------- |
---|
52 | |
---|
53 | Voxel::Voxel(const Voxel& v) |
---|
54 | { |
---|
55 | operator=(v); |
---|
56 | } |
---|
57 | //-------------------------------------------------------------------- |
---|
58 | |
---|
59 | Voxel& Voxel::operator= (const Voxel& v) |
---|
60 | { |
---|
61 | if(this == &v) return *this; |
---|
62 | this->itsX=v.itsX; |
---|
63 | this->itsY=v.itsY; |
---|
64 | this->itsZ=v.itsZ; |
---|
65 | this->itsF=v.itsF; |
---|
66 | return *this; |
---|
67 | } |
---|
68 | //-------------------------------------------------------------------- |
---|
69 | |
---|
70 | std::ostream& operator<< ( std::ostream& theStream, Voxel& vox) |
---|
71 | { |
---|
72 | /// A convenient way of printing the coordinate and flux values of |
---|
73 | /// a voxel. They are all printed to a single line (with no |
---|
74 | /// carriage-return), with the flux to precision of 4. |
---|
75 | |
---|
76 | theStream << std::setw(4) << vox.itsX ; |
---|
77 | theStream << " " << std::setw(4) << vox.itsY; |
---|
78 | theStream << " " << std::setw(4) << vox.itsZ; |
---|
79 | theStream << std::setprecision(4); |
---|
80 | theStream << " " << vox.itsF; |
---|
81 | return theStream; |
---|
82 | |
---|
83 | } |
---|
84 | //------------------------------------------------------ |
---|
85 | |
---|
86 | bool operator== (Voxel lhs, Voxel rhs) |
---|
87 | { |
---|
88 | /// For two voxels to be equal, all four parameters must be equal. |
---|
89 | |
---|
90 | return (lhs.itsX == rhs.itsX) && |
---|
91 | (lhs.itsY == rhs.itsY) && |
---|
92 | (lhs.itsZ == rhs.itsZ) && |
---|
93 | (lhs.itsF == rhs.itsF); |
---|
94 | } |
---|
95 | //------------------------------------------------------ |
---|
96 | |
---|
97 | bool operator< (Voxel lhs, Voxel rhs) |
---|
98 | { |
---|
99 | /// Do comparison on position, z then y then x. Last f. |
---|
100 | if(lhs.itsZ!=rhs.itsZ) return lhs.itsZ<rhs.itsZ; |
---|
101 | else if(lhs.itsY!=rhs.itsY) return lhs.itsY<rhs.itsY; |
---|
102 | else if(lhs.itsX!=rhs.itsX) return lhs.itsX<rhs.itsX; |
---|
103 | else return lhs.itsF < rhs.itsF; |
---|
104 | } |
---|
105 | //------------------------------------------------------ |
---|
106 | |
---|
107 | bool Voxel::match(Voxel other) |
---|
108 | { |
---|
109 | /// This function just tests for equality of position. The flux is ignored. |
---|
110 | |
---|
111 | return (this->itsX == other.itsX) && |
---|
112 | (this->itsY == other.itsY) && |
---|
113 | (this->itsZ == other.itsZ); |
---|
114 | } |
---|
115 | //-------------------------------------------------------------------- |
---|
116 | |
---|
117 | size_t Voxel::arrayIndex(const size_t *dim) |
---|
118 | { |
---|
119 | /// Return the index value corresponding to the Voxel for an array with dimensions given by dim. |
---|
120 | /// \param dim Array of dimension values (ie. lengths of x, y and z dimensions) |
---|
121 | /// \return Index value for an array with dimensions of dim |
---|
122 | |
---|
123 | size_t ind = itsX + dim[0]*itsY + dim[0]*dim[1]*itsZ; |
---|
124 | return ind; |
---|
125 | |
---|
126 | } |
---|
127 | |
---|
128 | } |
---|