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

Last change on this file since 365 was 365, checked in by MatthewWhiting, 17 years ago
  • Mainly fixing up copy constructors & assignment operators
  • Improved the testing of whether there is a spectral or third axis, including giving FitsHeader? a new function. Also improved the tabular output of VEL/WVEL.
  • Improved the F_int column -- made sure its width is always calculated, and gave it default units
  • Improved the printSpace etc functions, to accept an arbitrary stream
  • Removed some unnecessary comments
File size: 8.1 KB
RevLine 
[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
32#include <PixelMap/Voxel.hh>
33#include <PixelMap/Scan.hh>
34#include <PixelMap/Object2D.hh>
35#include <vector>
[244]36#include <algorithm>
37#include <iostream>
[238]38
[252]39namespace PixelInfo
[238]40{
41
[253]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
[252]49  class ChanMap
50  {
51  public:
[365]52    ChanMap();
[252]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(){};
[253]58
59    /** Define the ChanMap using a channel number and Object2D. */
[252]60    void     define(long z, Object2D obj){itsZ=z; itsObject=obj;};
[253]61
62    /** Return the value of the channel number. */
[252]63    long     getZ(){return itsZ;};
[253]64
65    /** Set the value of the channel number. */
[252]66    void     setZ(long l){itsZ=l;};
[253]67
68    /** Return the Object2D set of scans. */
[252]69    Object2D getObject(){return itsObject;};
[253]70
71    /** Return the i-th scan of the Object2D .*/
[252]72    Scan     getScan(int i){return itsObject.scanlist[i];};
[253]73
74    /** The number of scans in the Object2D set. */
[252]75    long     getNumScan(){return itsObject.scanlist.size();};
[240]76
[252]77    void     addOffsets(long xoff, long yoff, long zoff){
[253]78      /**
79       * Add constant offsets to each of the coordinates.
80       */
[252]81      itsZ += zoff;
82      itsObject.addOffsets(xoff,yoff);
83    };
[238]84
[252]85    friend bool operator< (ChanMap lhs, ChanMap rhs){
[253]86      /** The less-than operator: only acting on the channel number. */
[252]87      return (lhs.itsZ<rhs.itsZ);
88    };
[244]89
[252]90    friend ChanMap operator+ (ChanMap lhs, ChanMap rhs){
[253]91      /**
92       *  Add two ChanMaps together.
93       *  If they are the same channel, add the Objects, otherwise
94       *  return a blank ChanMap.
95       */
96
[252]97      ChanMap newmap;
98      if(lhs.itsZ==rhs.itsZ){
99        newmap.itsZ = lhs.itsZ;
100        newmap.itsObject = lhs.itsObject + rhs.itsObject;
101      }
102      return newmap;
103    };
[238]104
[252]105    friend class Object3D;
[238]106
[252]107  private:
[253]108    long     itsZ;      ///< The channel number.
109    Object2D itsObject; ///< The set of scans of object pixels.
[238]110
[252]111  };
[238]112
113
[252]114  //=====================================
[238]115
[253]116  /**
117   * A set of pixels in 3D.
118   * This stores the pixels in a list of ChanMap objects -- ie. a set
119   * of Object2Ds, each with a different channel number.
120   * Also recorded are the average x-, y- and z-values (via their
121   * sums), as well as their extrema.
122   */
[238]123
[252]124  class Object3D
125  {
126  public:
[365]127    Object3D();
[252]128    Object3D(const Object3D& o);
129    Object3D& operator= (const Object3D& o); 
130    virtual ~Object3D(){};
131
[253]132    /** Is a 3-D voxel in the Object? */
[252]133    bool     isInObject(long x, long y, long z);
[253]134    /** Is a 3-D voxel in the Object? */
[252]135    bool     isInObject(Voxel v){return this->isInObject(v.getX(),v.getY(),v.getZ());};
[238]136 
[253]137    /** Add a single 3-D voxel to the Object. */
[252]138    void     addPixel(long x, long y, long z);
[253]139    /** Add a single 3-D voxel to the Object. */
[252]140    void     addPixel(Voxel v){this->addPixel(v.getX(),v.getY(),v.getZ());};
[253]141    /** Add a full channel map to the Object. */
[252]142    void     addChannel(ChanMap channel);
[253]143    /** Add a full channel map to the Object. */
[252]144    void     addChannel(long z, Object2D obj){
145      ChanMap channel(z,obj);
146      this->addChannel(channel);
147    }
[238]148
[253]149    /** Sort the list of channel maps by their channel number. */
[252]150    void     order(){
151      //     for(int i=0;i<maplist.size();i++) maplist[i].itsObject.order();
152      std::stable_sort(maplist.begin(),maplist.end());
153    };
[238]154
[253]155    /** Calculate the averages and extrema of the three coordinates. */
[252]156    void     calcParams();
[253]157    /** Return the average x-value.*/
[252]158    float    getXcentre(){return xSum/float(numVox);};
[253]159    /** Return the average y-value.*/
[252]160    float    getYcentre(){return ySum/float(numVox);};
[253]161    /** Return the average z-value.*/
[252]162    float    getZcentre(){return zSum/float(numVox);};
[253]163    /** Return the minimum x-value.*/
164    long     getXmin(){return xmin;};
165    /** Return the minimum y-value.*/
[252]166    long     getYmin(){return ymin;};
[253]167    /** Return the minimum z-value.*/
[252]168    long     getZmin(){return zmin;};
[253]169    /** Return the maximum x-value.*/
[252]170    long     getXmax(){return xmax;};
[253]171    /** Return the maximum y-value.*/
[252]172    long     getYmax(){return ymax;};
[253]173    /** Return the maximum z-value.*/
[252]174    long     getZmax(){return zmax;};
[238]175
[253]176    /** Return the number of distinct voxels in the Object. */
[252]177    long     getSize(){return numVox;};
[253]178
179    /** Return the number of distinct channels in the Object. */
[252]180    long     getNumDistinctZ();
[253]181
182    /** Return the number of channels in the Object. */
[252]183    long     getNumChanMap(){return this->maplist.size();};
[253]184
185    /** Return the number of spatial pixels -- ie. the number of
186        distinct (x,y) sets in the Object. */
[252]187    long     getSpatialSize();
[240]188 
[253]189    /** Get the pixNum-th voxel */
[252]190    Voxel    getPixel(int pixNum);
[253]191
192    /** Return a vector set of all voxels in the Object. */
[252]193    std::vector<Voxel> getPixelSet();
[241]194
[253]195    /** Get the i-th channel map. */
[252]196    ChanMap  getChanMap(int i){return this->maplist[i];};
[253]197
198    /** Get the channel number of the i-th channel map. */
[252]199    long     getZ(int i){return this->maplist[i].itsZ;};
[238]200
[253]201    /** Return an Object2D showing the spatial (x,y) distribution of
202        voxels in the Object */
[252]203    Object2D getSpatialMap();
[238]204
[252]205    void     addOffsets(long xoff, long yoff, long zoff){
[253]206      /**
207       *  Add constant offsets to each of the dimensions, changing the
208       *  parameters at the same time.
209       */
[252]210      for(int i=0;i<maplist.size();i++) maplist[i].addOffsets(xoff,yoff,zoff);
211      xSum += xoff*numVox;
212      xmin += xoff; xmax += xoff;
213      ySum += yoff*numVox;
214      ymin += yoff; ymax += yoff;
215      zSum += zoff*numVox;
216      zmin += zoff; zmax += zoff;
217    };
[240]218
[253]219    /** Output operator for the Object3D. */
[252]220    friend std::ostream& operator<< ( std::ostream& theStream, Object3D& obj);
[238]221
[253]222    /** Add two Object3Ds.
223        Overlapping channels are combined using addChannel(). */
[252]224    friend Object3D operator+ (Object3D lhs, Object3D rhs){
225      Object3D output = lhs;
226      for(int m=0;m<rhs.maplist.size();m++) output.addChannel(rhs.maplist[m]);
227      return output;
228    }
[240]229
[252]230  private:
231    std::vector<ChanMap> maplist;   ///< The list of channel maps
232    long                 numVox;    ///< How many voxels in the Object?
233    float                xSum;      ///< Sum of the x-values
234    float                ySum;      ///< Sum of the y-values
235    float                zSum;      ///< Sum of the z-values
236    long                 xmin,xmax; ///< min and max x-values of object
237    long                 ymin,ymax; ///< min and max y-values of object
238    long                 zmin,zmax; ///< min and max z-values of object
239  };
[240]240
[252]241}
[238]242
243#endif //OBJECT3D_H
Note: See TracBrowser for help on using the repository browser.