1 | // ----------------------------------------------------------------------- |
---|
2 | // Object3D.hh: Definition of the Object3D class that holds |
---|
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 | // ----------------------------------------------------------------------- |
---|
29 | #ifndef OBJECT3D_H |
---|
30 | #define OBJECT3D_H |
---|
31 | |
---|
32 | #include <duchamp/PixelMap/Voxel.hh> |
---|
33 | #include <duchamp/PixelMap/Scan.hh> |
---|
34 | #include <duchamp/PixelMap/Object2D.hh> |
---|
35 | #include <vector> |
---|
36 | #include <algorithm> |
---|
37 | #include <map> |
---|
38 | #include <iostream> |
---|
39 | |
---|
40 | namespace PixelInfo |
---|
41 | { |
---|
42 | |
---|
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. |
---|
49 | |
---|
50 | class Object3D |
---|
51 | { |
---|
52 | public: |
---|
53 | Object3D(); |
---|
54 | Object3D(const Object3D& o); |
---|
55 | Object3D& operator= (const Object3D& o); |
---|
56 | virtual ~Object3D(){}; |
---|
57 | |
---|
58 | /// @brief Is a 3-D voxel in the Object? |
---|
59 | bool isInObject(long x, long y, long z); |
---|
60 | /// @brief Is a 3-D voxel in the Object? |
---|
61 | bool isInObject(Voxel v){return isInObject(v.getX(),v.getY(),v.getZ());}; |
---|
62 | |
---|
63 | /// @brief Add a single 3-D voxel to the Object. |
---|
64 | virtual void addPixel(long x, long y, long z); |
---|
65 | /// @brief Add a single 3-D voxel to the Object. |
---|
66 | virtual void addPixel(Voxel v){addPixel(v.getX(),v.getY(),v.getZ());}; |
---|
67 | /// @brief Add a scan to the object |
---|
68 | void addScan(Scan s, long z); |
---|
69 | /// @brief Add a full channel map to the Object. |
---|
70 | void addChannel(const long &z, Object2D &obj); |
---|
71 | |
---|
72 | /// @brief Calculate the averages and extrema of the three coordinates. |
---|
73 | void calcParams(); |
---|
74 | // /// @brief Return the average x-value. |
---|
75 | // float getXaverage(){if(numVox>0) return xSum/float(numVox); else return 0.;}; |
---|
76 | // /// @brief Return the average y-value. |
---|
77 | // float getYaverage(){if(numVox>0) return ySum/float(numVox); else return 0.;}; |
---|
78 | // /// @brief Return the average z-value. |
---|
79 | // float getZaverage(){if(numVox>0) return zSum/float(numVox); else return 0.;}; |
---|
80 | /// @brief Return the average x-value. |
---|
81 | float getXaverage(); |
---|
82 | /// @brief Return the average y-value. |
---|
83 | float getYaverage(); |
---|
84 | /// @brief Return the average z-value. |
---|
85 | float getZaverage(); |
---|
86 | /// @brief Return the minimum x-value. |
---|
87 | long getXmin(){return xmin;}; |
---|
88 | /// @brief Return the minimum y-value. |
---|
89 | long getYmin(){return ymin;}; |
---|
90 | /// @brief Return the minimum z-value. |
---|
91 | long getZmin(){return zmin;}; |
---|
92 | /// @brief Return the maximum x-value. |
---|
93 | long getXmax(){return xmax;}; |
---|
94 | /// @brief Return the maximum y-value. |
---|
95 | long getYmax(){return ymax;}; |
---|
96 | /// @brief Return the maximum z-value. |
---|
97 | long getZmax(){return zmax;}; |
---|
98 | |
---|
99 | /// @brief Return the number of distinct voxels in the Object. |
---|
100 | unsigned int getSize(){return numVox;}; |
---|
101 | |
---|
102 | /// @brief Return the number of distinct channels in the Object. |
---|
103 | long getNumDistinctZ(){return chanlist.size();}; |
---|
104 | |
---|
105 | /// @brief Return the number of channels in the Object. |
---|
106 | long getNumChanMap(){return chanlist.size();}; |
---|
107 | |
---|
108 | /// @brief Return the number of spatial pixels -- ie. the number of distinct (x,y) sets in the Object. |
---|
109 | long getSpatialSize(); |
---|
110 | |
---|
111 | /// @brief Return a vector set of all voxels in the Object. |
---|
112 | std::vector<Voxel> getPixelSet(); |
---|
113 | |
---|
114 | /// @brief Return a vector list of the channel numbers in the Object |
---|
115 | std::vector<long> getChannelList(); |
---|
116 | |
---|
117 | /// @brief Return the largest number of adjacent channels in the Object. |
---|
118 | int getMaxAdjacentChannels(); |
---|
119 | |
---|
120 | /// @brief Get the channel map for channel z. |
---|
121 | Object2D getChanMap(long z); |
---|
122 | |
---|
123 | /// @brief Return an Object2D showing the spatial (x,y) distribution of voxels in the Object |
---|
124 | Object2D getSpatialMap(); |
---|
125 | |
---|
126 | /// @brief Add constant offsets to each of the dimensions, changing the parameters at the same time. |
---|
127 | virtual void addOffsets(long xoff, long yoff, long zoff); |
---|
128 | |
---|
129 | /// @brief Output operator for the Object3D. |
---|
130 | friend std::ostream& operator<< ( std::ostream& theStream, Object3D& obj); |
---|
131 | |
---|
132 | /// @brief Add two Object3Ds. Overlapping channels are combined using addChannel(). |
---|
133 | friend Object3D operator+ (Object3D lhs, Object3D rhs); |
---|
134 | |
---|
135 | protected: |
---|
136 | std::map<long,Object2D> chanlist; ///< The list of 2D channel maps |
---|
137 | long numVox; ///< How many voxels in the Object? |
---|
138 | float xSum; ///< Sum of the x-values |
---|
139 | float ySum; ///< Sum of the y-values |
---|
140 | float zSum; ///< Sum of the z-values |
---|
141 | long xmin,xmax; ///< min and max x-values of object |
---|
142 | long ymin,ymax; ///< min and max y-values of object |
---|
143 | long zmin,zmax; ///< min and max z-values of object |
---|
144 | }; |
---|
145 | |
---|
146 | } |
---|
147 | |
---|
148 | #endif //OBJECT3D_H |
---|