source: trunk/src/PixelMap/Object3D.hh @ 418

Last change on this file since 418 was 418, checked in by MatthewWhiting, 16 years ago

A range of changes from CONRAD development:

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