[301] | 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 | // ----------------------------------------------------------------------- |
---|
[237] | 28 | #include <iostream> |
---|
[238] | 29 | #include <iomanip> |
---|
[393] | 30 | #include <duchamp/PixelMap/Voxel.hh> |
---|
[237] | 31 | |
---|
[252] | 32 | namespace PixelInfo |
---|
[237] | 33 | { |
---|
| 34 | |
---|
[742] | 35 | Voxel::Voxel(long x, long y, long z, float f) : |
---|
| 36 | itsX(x), itsY(y), itsZ(z), itsF(f) |
---|
[270] | 37 | { |
---|
| 38 | } |
---|
| 39 | //-------------------------------------------------------------------- |
---|
| 40 | |
---|
[742] | 41 | Voxel::Voxel(long x, long y, long z) : |
---|
| 42 | itsX(x), itsY(y), itsZ(z) |
---|
| 43 | { |
---|
| 44 | this->itsF=0.; |
---|
| 45 | } |
---|
| 46 | //-------------------------------------------------------------------- |
---|
| 47 | |
---|
[270] | 48 | Voxel::Voxel(const Voxel& v) |
---|
| 49 | { |
---|
[365] | 50 | operator=(v); |
---|
[270] | 51 | } |
---|
| 52 | //-------------------------------------------------------------------- |
---|
| 53 | |
---|
| 54 | Voxel& Voxel::operator= (const Voxel& v) |
---|
| 55 | { |
---|
| 56 | if(this == &v) return *this; |
---|
| 57 | this->itsX=v.itsX; |
---|
| 58 | this->itsY=v.itsY; |
---|
| 59 | this->itsZ=v.itsZ; |
---|
| 60 | this->itsF=v.itsF; |
---|
| 61 | return *this; |
---|
| 62 | } |
---|
| 63 | //-------------------------------------------------------------------- |
---|
| 64 | |
---|
[252] | 65 | std::ostream& operator<< ( std::ostream& theStream, Voxel& vox) |
---|
| 66 | { |
---|
[528] | 67 | /// A convenient way of printing the coordinate and flux values of |
---|
| 68 | /// a voxel. They are all printed to a single line (with no |
---|
| 69 | /// carriage-return), with the flux to precision of 4. |
---|
[237] | 70 | |
---|
[252] | 71 | theStream << std::setw(4) << vox.itsX ; |
---|
| 72 | theStream << " " << std::setw(4) << vox.itsY; |
---|
| 73 | theStream << " " << std::setw(4) << vox.itsZ; |
---|
| 74 | theStream << std::setprecision(4); |
---|
| 75 | theStream << " " << vox.itsF; |
---|
[270] | 76 | return theStream; |
---|
[252] | 77 | |
---|
| 78 | } |
---|
[418] | 79 | //------------------------------------------------------ |
---|
| 80 | |
---|
| 81 | bool operator== (Voxel lhs, Voxel rhs) |
---|
| 82 | { |
---|
[528] | 83 | /// For two voxels to be equal, all four parameters must be equal. |
---|
| 84 | |
---|
[418] | 85 | return (lhs.itsX == rhs.itsX) && |
---|
| 86 | (lhs.itsY == rhs.itsY) && |
---|
| 87 | (lhs.itsZ == rhs.itsZ) && |
---|
| 88 | (lhs.itsF == rhs.itsF); |
---|
| 89 | } |
---|
| 90 | //------------------------------------------------------ |
---|
| 91 | |
---|
[858] | 92 | bool operator< (Voxel lhs, Voxel rhs) |
---|
| 93 | { |
---|
| 94 | /// Do comparison on position, z then y then x. Last f. |
---|
| 95 | if(lhs.itsZ!=rhs.itsZ) return lhs.itsZ<rhs.itsZ; |
---|
| 96 | else if(lhs.itsY!=rhs.itsY) return lhs.itsY<rhs.itsY; |
---|
| 97 | else if(lhs.itsX!=rhs.itsX) return lhs.itsX<rhs.itsX; |
---|
| 98 | else return lhs.itsF < rhs.itsF; |
---|
| 99 | } |
---|
| 100 | //------------------------------------------------------ |
---|
| 101 | |
---|
[418] | 102 | bool Voxel::match(Voxel other) |
---|
| 103 | { |
---|
[528] | 104 | /// This function just tests for equality of position. The flux is ignored. |
---|
| 105 | |
---|
[418] | 106 | return (this->itsX == other.itsX) && |
---|
| 107 | (this->itsY == other.itsY) && |
---|
| 108 | (this->itsZ == other.itsZ); |
---|
| 109 | } |
---|
[252] | 110 | //-------------------------------------------------------------------- |
---|
[472] | 111 | |
---|
[884] | 112 | size_t Voxel::arrayIndex(size_t *dim) |
---|
[472] | 113 | { |
---|
[528] | 114 | /// Return the index value corresponding to the Voxel for an array with dimensions given by dim. |
---|
| 115 | /// \param dim Array of dimension values (ie. lengths of x, y and z dimensions) |
---|
| 116 | /// \return Index value for an array with dimensions of dim |
---|
| 117 | |
---|
[884] | 118 | size_t ind = itsX + dim[0]*itsY + dim[0]*dim[1]*itsZ; |
---|
[472] | 119 | return ind; |
---|
| 120 | |
---|
| 121 | } |
---|
| 122 | |
---|
[270] | 123 | //-------------------------------------------------------------------- |
---|
[472] | 124 | //-------------------------------------------------------------------- |
---|
[252] | 125 | |
---|
[270] | 126 | Pixel::Pixel(long x, long y, float f) |
---|
| 127 | { |
---|
| 128 | this->itsX=x; |
---|
| 129 | this->itsY=y; |
---|
| 130 | this->itsF=f; |
---|
| 131 | } |
---|
| 132 | //-------------------------------------------------------------------- |
---|
| 133 | |
---|
| 134 | Pixel::Pixel(const Pixel& p) |
---|
| 135 | { |
---|
[365] | 136 | operator=(p); |
---|
[270] | 137 | } |
---|
| 138 | //-------------------------------------------------------------------- |
---|
| 139 | |
---|
| 140 | Pixel& Pixel::operator= (const Pixel& p) |
---|
| 141 | { |
---|
| 142 | if(this == &p) return *this; |
---|
| 143 | this->itsX=p.itsX; |
---|
| 144 | this->itsY=p.itsY; |
---|
| 145 | this->itsF=p.itsF; |
---|
| 146 | return *this; |
---|
| 147 | } |
---|
| 148 | //-------------------------------------------------------------------- |
---|
| 149 | |
---|
[237] | 150 | } |
---|