1 | #ifndef OBJECT3D_H |
---|
2 | #define OBJECT3D_H |
---|
3 | |
---|
4 | #include <PixelMap/Voxel.hh> |
---|
5 | #include <PixelMap/Scan.hh> |
---|
6 | #include <PixelMap/Object2D.hh> |
---|
7 | #include <vector> |
---|
8 | #include <algorithm> |
---|
9 | #include <iostream> |
---|
10 | |
---|
11 | namespace PixelInfo |
---|
12 | { |
---|
13 | |
---|
14 | /** |
---|
15 | * A class to store a channel+Object2D map. |
---|
16 | * This represents a 2-dimensional set of pixels that has an |
---|
17 | * associated channel number. Sets of these will form a three |
---|
18 | * dimensional object. |
---|
19 | */ |
---|
20 | |
---|
21 | class ChanMap |
---|
22 | { |
---|
23 | public: |
---|
24 | ChanMap(){itsZ=-1;}; |
---|
25 | ChanMap(long z){itsZ=z;}; |
---|
26 | ChanMap(long z, Object2D obj){itsZ=z; itsObject=obj;}; |
---|
27 | ChanMap(const ChanMap& m); |
---|
28 | ChanMap& operator= (const ChanMap& m); |
---|
29 | virtual ~ChanMap(){}; |
---|
30 | |
---|
31 | /** Define the ChanMap using a channel number and Object2D. */ |
---|
32 | void define(long z, Object2D obj){itsZ=z; itsObject=obj;}; |
---|
33 | |
---|
34 | /** Return the value of the channel number. */ |
---|
35 | long getZ(){return itsZ;}; |
---|
36 | |
---|
37 | /** Set the value of the channel number. */ |
---|
38 | void setZ(long l){itsZ=l;}; |
---|
39 | |
---|
40 | /** Return the Object2D set of scans. */ |
---|
41 | Object2D getObject(){return itsObject;}; |
---|
42 | |
---|
43 | /** Return the i-th scan of the Object2D .*/ |
---|
44 | Scan getScan(int i){return itsObject.scanlist[i];}; |
---|
45 | |
---|
46 | /** The number of scans in the Object2D set. */ |
---|
47 | long getNumScan(){return itsObject.scanlist.size();}; |
---|
48 | |
---|
49 | void addOffsets(long xoff, long yoff, long zoff){ |
---|
50 | /** |
---|
51 | * Add constant offsets to each of the coordinates. |
---|
52 | */ |
---|
53 | itsZ += zoff; |
---|
54 | itsObject.addOffsets(xoff,yoff); |
---|
55 | }; |
---|
56 | |
---|
57 | friend bool operator< (ChanMap lhs, ChanMap rhs){ |
---|
58 | /** The less-than operator: only acting on the channel number. */ |
---|
59 | return (lhs.itsZ<rhs.itsZ); |
---|
60 | }; |
---|
61 | |
---|
62 | friend ChanMap operator+ (ChanMap lhs, ChanMap rhs){ |
---|
63 | /** |
---|
64 | * Add two ChanMaps together. |
---|
65 | * If they are the same channel, add the Objects, otherwise |
---|
66 | * return a blank ChanMap. |
---|
67 | */ |
---|
68 | |
---|
69 | ChanMap newmap; |
---|
70 | if(lhs.itsZ==rhs.itsZ){ |
---|
71 | newmap.itsZ = lhs.itsZ; |
---|
72 | newmap.itsObject = lhs.itsObject + rhs.itsObject; |
---|
73 | } |
---|
74 | return newmap; |
---|
75 | }; |
---|
76 | |
---|
77 | friend class Object3D; |
---|
78 | |
---|
79 | private: |
---|
80 | long itsZ; ///< The channel number. |
---|
81 | Object2D itsObject; ///< The set of scans of object pixels. |
---|
82 | |
---|
83 | }; |
---|
84 | |
---|
85 | |
---|
86 | //===================================== |
---|
87 | |
---|
88 | /** |
---|
89 | * A set of pixels in 3D. |
---|
90 | * This stores the pixels in a list of ChanMap objects -- ie. a set |
---|
91 | * of Object2Ds, each with a different channel number. |
---|
92 | * Also recorded are the average x-, y- and z-values (via their |
---|
93 | * sums), as well as their extrema. |
---|
94 | */ |
---|
95 | |
---|
96 | class Object3D |
---|
97 | { |
---|
98 | public: |
---|
99 | Object3D(){numVox=0;}; |
---|
100 | Object3D(const Object3D& o); |
---|
101 | Object3D& operator= (const Object3D& o); |
---|
102 | virtual ~Object3D(){}; |
---|
103 | |
---|
104 | /** Is a 3-D voxel in the Object? */ |
---|
105 | bool isInObject(long x, long y, long z); |
---|
106 | /** Is a 3-D voxel in the Object? */ |
---|
107 | bool isInObject(Voxel v){return this->isInObject(v.getX(),v.getY(),v.getZ());}; |
---|
108 | |
---|
109 | /** Add a single 3-D voxel to the Object. */ |
---|
110 | void addPixel(long x, long y, long z); |
---|
111 | /** Add a single 3-D voxel to the Object. */ |
---|
112 | void addPixel(Voxel v){this->addPixel(v.getX(),v.getY(),v.getZ());}; |
---|
113 | /** Add a full channel map to the Object. */ |
---|
114 | void addChannel(ChanMap channel); |
---|
115 | /** Add a full channel map to the Object. */ |
---|
116 | void addChannel(long z, Object2D obj){ |
---|
117 | ChanMap channel(z,obj); |
---|
118 | this->addChannel(channel); |
---|
119 | } |
---|
120 | |
---|
121 | /** Sort the list of channel maps by their channel number. */ |
---|
122 | void order(){ |
---|
123 | // for(int i=0;i<maplist.size();i++) maplist[i].itsObject.order(); |
---|
124 | std::stable_sort(maplist.begin(),maplist.end()); |
---|
125 | }; |
---|
126 | |
---|
127 | /** Calculate the averages and extrema of the three coordinates. */ |
---|
128 | void calcParams(); |
---|
129 | /** Return the average x-value.*/ |
---|
130 | float getXcentre(){return xSum/float(numVox);}; |
---|
131 | /** Return the average y-value.*/ |
---|
132 | float getYcentre(){return ySum/float(numVox);}; |
---|
133 | /** Return the average z-value.*/ |
---|
134 | float getZcentre(){return zSum/float(numVox);}; |
---|
135 | /** Return the minimum x-value.*/ |
---|
136 | long getXmin(){return xmin;}; |
---|
137 | /** Return the minimum y-value.*/ |
---|
138 | long getYmin(){return ymin;}; |
---|
139 | /** Return the minimum z-value.*/ |
---|
140 | long getZmin(){return zmin;}; |
---|
141 | /** Return the maximum x-value.*/ |
---|
142 | long getXmax(){return xmax;}; |
---|
143 | /** Return the maximum y-value.*/ |
---|
144 | long getYmax(){return ymax;}; |
---|
145 | /** Return the maximum z-value.*/ |
---|
146 | long getZmax(){return zmax;}; |
---|
147 | |
---|
148 | /** Return the number of distinct voxels in the Object. */ |
---|
149 | long getSize(){return numVox;}; |
---|
150 | |
---|
151 | /** Return the number of distinct channels in the Object. */ |
---|
152 | long getNumDistinctZ(); |
---|
153 | |
---|
154 | /** Return the number of channels in the Object. */ |
---|
155 | long getNumChanMap(){return this->maplist.size();}; |
---|
156 | |
---|
157 | /** Return the number of spatial pixels -- ie. the number of |
---|
158 | distinct (x,y) sets in the Object. */ |
---|
159 | long getSpatialSize(); |
---|
160 | |
---|
161 | /** Get the pixNum-th voxel */ |
---|
162 | Voxel getPixel(int pixNum); |
---|
163 | |
---|
164 | /** Return a vector set of all voxels in the Object. */ |
---|
165 | std::vector<Voxel> getPixelSet(); |
---|
166 | |
---|
167 | /** Get the i-th channel map. */ |
---|
168 | ChanMap getChanMap(int i){return this->maplist[i];}; |
---|
169 | |
---|
170 | /** Get the channel number of the i-th channel map. */ |
---|
171 | long getZ(int i){return this->maplist[i].itsZ;}; |
---|
172 | |
---|
173 | /** Return an Object2D showing the spatial (x,y) distribution of |
---|
174 | voxels in the Object */ |
---|
175 | Object2D getSpatialMap(); |
---|
176 | |
---|
177 | void addOffsets(long xoff, long yoff, long zoff){ |
---|
178 | /** |
---|
179 | * Add constant offsets to each of the dimensions, changing the |
---|
180 | * parameters at the same time. |
---|
181 | */ |
---|
182 | for(int i=0;i<maplist.size();i++) maplist[i].addOffsets(xoff,yoff,zoff); |
---|
183 | xSum += xoff*numVox; |
---|
184 | xmin += xoff; xmax += xoff; |
---|
185 | ySum += yoff*numVox; |
---|
186 | ymin += yoff; ymax += yoff; |
---|
187 | zSum += zoff*numVox; |
---|
188 | zmin += zoff; zmax += zoff; |
---|
189 | }; |
---|
190 | |
---|
191 | /** Output operator for the Object3D. */ |
---|
192 | friend std::ostream& operator<< ( std::ostream& theStream, Object3D& obj); |
---|
193 | |
---|
194 | /** Add two Object3Ds. |
---|
195 | Overlapping channels are combined using addChannel(). */ |
---|
196 | friend Object3D operator+ (Object3D lhs, Object3D rhs){ |
---|
197 | Object3D output = lhs; |
---|
198 | for(int m=0;m<rhs.maplist.size();m++) output.addChannel(rhs.maplist[m]); |
---|
199 | return output; |
---|
200 | } |
---|
201 | |
---|
202 | private: |
---|
203 | std::vector<ChanMap> maplist; ///< The list of channel maps |
---|
204 | long numVox; ///< How many voxels in the Object? |
---|
205 | float xSum; ///< Sum of the x-values |
---|
206 | float ySum; ///< Sum of the y-values |
---|
207 | float zSum; ///< Sum of the z-values |
---|
208 | long xmin,xmax; ///< min and max x-values of object |
---|
209 | long ymin,ymax; ///< min and max y-values of object |
---|
210 | long zmin,zmax; ///< min and max z-values of object |
---|
211 | }; |
---|
212 | |
---|
213 | } |
---|
214 | |
---|
215 | #endif //OBJECT3D_H |
---|