source: trunk/src/PixelMap/Voxel.cc

Last change on this file was 1290, checked in by MatthewWhiting, 11 years ago

Removing the Pixel class, as we never use it. Will use Voxels if we ever need to, so adding a constructor for Voxels that just takes an x & a y value. Preparation for ticket #200

File size: 4.2 KB
RevLine 
[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]32namespace PixelInfo
[237]33{
34
[742]35  Voxel::Voxel(long x, long y, long z, float f) :
[1290]36      itsX(x), itsY(y), itsZ(z), itsF(f)
[270]37  {
38  }
39  //--------------------------------------------------------------------
40
[742]41  Voxel::Voxel(long x, long y, long z) :
[1290]42      itsX(x), itsY(y), itsZ(z), itsF(0.)
[742]43  {
44  }
45  //--------------------------------------------------------------------
46
[1290]47  Voxel::Voxel(long x, long y) :
48      itsX(x), itsY(y), itsZ(0), itsF(0.)
49  {
50  }
51  //--------------------------------------------------------------------
52
[270]53  Voxel::Voxel(const Voxel& v)
54  {
[365]55    operator=(v);
[270]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
[252]70  std::ostream& operator<< ( std::ostream& theStream, Voxel& vox)
71  {
[528]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.
[237]75
[252]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;
[270]81    return theStream;
[252]82
83  }
[418]84  //------------------------------------------------------
85
86  bool operator== (Voxel lhs, Voxel rhs)
87  {
[528]88    /// For two voxels to be equal, all four parameters must be equal.
89
[418]90    return (lhs.itsX == rhs.itsX) &&
91      (lhs.itsY == rhs.itsY) &&
92      (lhs.itsZ == rhs.itsZ) &&
93      (lhs.itsF == rhs.itsF);
94  }
95  //------------------------------------------------------
96
[858]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
[418]107  bool Voxel::match(Voxel other)
108  {
[528]109    /// This function just tests for equality of position. The flux is ignored.
110
[418]111    return (this->itsX == other.itsX) &&
112      (this->itsY == other.itsY) &&
113      (this->itsZ == other.itsZ);
114  }
[252]115  //--------------------------------------------------------------------
[472]116
[1155]117  size_t Voxel::arrayIndex(const size_t *dim)
[472]118  {
[528]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
[884]123    size_t ind = itsX + dim[0]*itsY + dim[0]*dim[1]*itsZ;
[472]124    return ind;
125
126  }
127
[237]128}
Note: See TracBrowser for help on using the repository browser.