[301] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // Object3D.hh: Definition of Object3D and ChanMap, classes that hold |
---|
| 3 | // pixel information for a three-dimensional object. |
---|
| 4 | // ----------------------------------------------------------------------- |
---|
| 5 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 6 | // |
---|
| 7 | // This program is free software; you can redistribute it and/or modify it |
---|
| 8 | // under the terms of the GNU General Public License as published by the |
---|
| 9 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 10 | // option) any later version. |
---|
| 11 | // |
---|
| 12 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 13 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 15 | // for more details. |
---|
| 16 | // |
---|
| 17 | // You should have received a copy of the GNU General Public License |
---|
| 18 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 19 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 20 | // |
---|
| 21 | // Correspondence concerning Duchamp may be directed to: |
---|
| 22 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 23 | // Postal address: Dr. Matthew Whiting |
---|
| 24 | // Australia Telescope National Facility, CSIRO |
---|
| 25 | // PO Box 76 |
---|
| 26 | // Epping NSW 1710 |
---|
| 27 | // AUSTRALIA |
---|
| 28 | // ----------------------------------------------------------------------- |
---|
[238] | 29 | #ifndef OBJECT3D_H |
---|
| 30 | #define OBJECT3D_H |
---|
| 31 | |
---|
[393] | 32 | #include <duchamp/PixelMap/Voxel.hh> |
---|
| 33 | #include <duchamp/PixelMap/Scan.hh> |
---|
| 34 | #include <duchamp/PixelMap/Object2D.hh> |
---|
[528] | 35 | #include <duchamp/PixelMap/ChanMap.hh> |
---|
[238] | 36 | #include <vector> |
---|
[244] | 37 | #include <algorithm> |
---|
| 38 | #include <iostream> |
---|
[238] | 39 | |
---|
[252] | 40 | namespace PixelInfo |
---|
[238] | 41 | { |
---|
| 42 | |
---|
[528] | 43 | /// @brief A set of pixels in 3D. |
---|
| 44 | /// |
---|
| 45 | /// @details This stores the pixels in a list of ChanMap objects -- |
---|
| 46 | /// ie. a set of Object2Ds, each with a different channel number. |
---|
| 47 | /// Also recorded are the average x-, y- and z-values (via their |
---|
| 48 | /// sums), as well as their extrema. |
---|
[253] | 49 | |
---|
[252] | 50 | class Object3D |
---|
| 51 | { |
---|
| 52 | public: |
---|
[365] | 53 | Object3D(); |
---|
[252] | 54 | Object3D(const Object3D& o); |
---|
| 55 | Object3D& operator= (const Object3D& o); |
---|
| 56 | virtual ~Object3D(){}; |
---|
| 57 | |
---|
[528] | 58 | /// @brief Is a 3-D voxel in the Object? |
---|
[252] | 59 | bool isInObject(long x, long y, long z); |
---|
[528] | 60 | /// @brief Is a 3-D voxel in the Object? |
---|
[252] | 61 | bool isInObject(Voxel v){return this->isInObject(v.getX(),v.getY(),v.getZ());}; |
---|
[238] | 62 | |
---|
[528] | 63 | /// @brief Add a single 3-D voxel to the Object. |
---|
[252] | 64 | void addPixel(long x, long y, long z); |
---|
[528] | 65 | /// @brief Add a single 3-D voxel to the Object. |
---|
[252] | 66 | void addPixel(Voxel v){this->addPixel(v.getX(),v.getY(),v.getZ());}; |
---|
[528] | 67 | /// @brief Add a scan to the object |
---|
[472] | 68 | void addScan(Scan s, long z); |
---|
[528] | 69 | /// @brief Add a full channel map to the Object. |
---|
[252] | 70 | void addChannel(ChanMap channel); |
---|
[528] | 71 | /// @brief Add a full channel map to the Object. |
---|
[252] | 72 | void addChannel(long z, Object2D obj){ |
---|
| 73 | ChanMap channel(z,obj); |
---|
| 74 | this->addChannel(channel); |
---|
| 75 | } |
---|
[238] | 76 | |
---|
[528] | 77 | /// @brief Sort the list of channel maps by their channel number. |
---|
[419] | 78 | void order(); |
---|
[238] | 79 | |
---|
[528] | 80 | /// @brief Calculate the averages and extrema of the three coordinates. |
---|
[252] | 81 | void calcParams(); |
---|
[528] | 82 | /// @brief Return the average x-value. |
---|
[252] | 83 | float getXcentre(){return xSum/float(numVox);}; |
---|
[528] | 84 | /// @brief Return the average y-value. |
---|
[252] | 85 | float getYcentre(){return ySum/float(numVox);}; |
---|
[528] | 86 | /// @brief Return the average z-value. |
---|
[252] | 87 | float getZcentre(){return zSum/float(numVox);}; |
---|
[528] | 88 | /// @brief Return the minimum x-value. |
---|
[253] | 89 | long getXmin(){return xmin;}; |
---|
[528] | 90 | /// @brief Return the minimum y-value. |
---|
[252] | 91 | long getYmin(){return ymin;}; |
---|
[528] | 92 | /// @brief Return the minimum z-value. |
---|
[252] | 93 | long getZmin(){return zmin;}; |
---|
[528] | 94 | /// @brief Return the maximum x-value. |
---|
[252] | 95 | long getXmax(){return xmax;}; |
---|
[528] | 96 | /// @brief Return the maximum y-value. |
---|
[252] | 97 | long getYmax(){return ymax;}; |
---|
[528] | 98 | /// @brief Return the maximum z-value. |
---|
[252] | 99 | long getZmax(){return zmax;}; |
---|
[238] | 100 | |
---|
[528] | 101 | /// @brief Return the number of distinct voxels in the Object. |
---|
[252] | 102 | long getSize(){return numVox;}; |
---|
[253] | 103 | |
---|
[528] | 104 | /// @brief Return the number of distinct channels in the Object. |
---|
[252] | 105 | long getNumDistinctZ(); |
---|
[253] | 106 | |
---|
[528] | 107 | /// @brief Return the number of channels in the Object. |
---|
[252] | 108 | long getNumChanMap(){return this->maplist.size();}; |
---|
[253] | 109 | |
---|
[528] | 110 | /// @brief Return the number of spatial pixels -- ie. the number of distinct (x,y) sets in the Object. |
---|
[252] | 111 | long getSpatialSize(); |
---|
[240] | 112 | |
---|
[528] | 113 | /// @brief Get the pixNum-th voxel |
---|
[252] | 114 | Voxel getPixel(int pixNum); |
---|
[253] | 115 | |
---|
[528] | 116 | /// @brief Return a vector set of all voxels in the Object. |
---|
[252] | 117 | std::vector<Voxel> getPixelSet(); |
---|
[241] | 118 | |
---|
[528] | 119 | /// @brief Get the i-th channel map. |
---|
[252] | 120 | ChanMap getChanMap(int i){return this->maplist[i];}; |
---|
[253] | 121 | |
---|
[528] | 122 | /// @brief Get the channel number of the i-th channel map. |
---|
[252] | 123 | long getZ(int i){return this->maplist[i].itsZ;}; |
---|
[238] | 124 | |
---|
[528] | 125 | /// @brief Return an Object2D showing the spatial (x,y) distribution of voxels in the Object |
---|
[252] | 126 | Object2D getSpatialMap(); |
---|
[238] | 127 | |
---|
[528] | 128 | /// @brief Add constant offsets to each of the dimensions, changing the parameters at the same time. |
---|
[399] | 129 | void addOffsets(long xoff, long yoff, long zoff); |
---|
[240] | 130 | |
---|
[528] | 131 | /// @brief Output operator for the Object3D. |
---|
[252] | 132 | friend std::ostream& operator<< ( std::ostream& theStream, Object3D& obj); |
---|
[238] | 133 | |
---|
[528] | 134 | /// @brief Add two Object3Ds. Overlapping channels are combined using addChannel(). |
---|
[252] | 135 | friend Object3D operator+ (Object3D lhs, Object3D rhs){ |
---|
| 136 | Object3D output = lhs; |
---|
[414] | 137 | for(unsigned int m=0;m<rhs.maplist.size();m++) output.addChannel(rhs.maplist[m]); |
---|
[252] | 138 | return output; |
---|
| 139 | } |
---|
[240] | 140 | |
---|
[252] | 141 | private: |
---|
| 142 | std::vector<ChanMap> maplist; ///< The list of channel maps |
---|
| 143 | long numVox; ///< How many voxels in the Object? |
---|
| 144 | float xSum; ///< Sum of the x-values |
---|
| 145 | float ySum; ///< Sum of the y-values |
---|
| 146 | float zSum; ///< Sum of the z-values |
---|
| 147 | long xmin,xmax; ///< min and max x-values of object |
---|
| 148 | long ymin,ymax; ///< min and max y-values of object |
---|
| 149 | long zmin,zmax; ///< min and max z-values of object |
---|
| 150 | }; |
---|
[240] | 151 | |
---|
[252] | 152 | } |
---|
[238] | 153 | |
---|
| 154 | #endif //OBJECT3D_H |
---|