source: tags/release-1.1.4/src/PixelMap/Object2D.hh @ 1441

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

Minor changes to remove compilation warnings.

File size: 5.3 KB
Line 
1// -----------------------------------------------------------------------
2// Object2D.hh: Definition of Object2D, a class to hold pixel
3//              information for a 2-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 OBJECT2D_H
30#define OBJECT2D_H
31
32#include <iostream>
33#include <algorithm>
34#include <vector>
35#include <duchamp/PixelMap/Scan.hh>
36#include <duchamp/PixelMap/Voxel.hh>
37
38namespace PixelInfo
39{
40
41  /**
42   * A class to store the pixel information for an object defined in a
43   * 2-dimensional plane.
44   *
45   * The object consists of a set of Scans (stored as a std::vector),
46   * together with basic information on the maximum, minimum, and
47   * average values (actually stored as xSum, ySum) for the x and y
48   * pixel values.
49   */
50
51  class Object2D
52  {
53  public:
54    Object2D();
55    Object2D(const Object2D& o);
56    Object2D& operator= (const Object2D& o); 
57    virtual ~Object2D(){};
58 
59    /** Clear the Object and set the number of pixels to zero.*/
60    void  clear(){scanlist.clear(); numPix=0;};
61
62    /** Make sure there are no overlapping or adjacent scans in the
63        Scan list. */
64    void  cleanup();
65
66    /** Add a pixel to the Object, making sure no scans overlap
67        afterwards. */
68    void  addPixel(long x, long y);
69    /** Add the (x,y) part of a Voxel to the Object, using
70        addPixel(long,long)*/
71    void  addPixel(Voxel v){this->addPixel(v.getX(),v.getY());};
72    /** Add a Pixel to the Object, using addPixel(long,long)*/
73    void  addPixel(Pixel p){this->addPixel(p.getX(),p.getY());};
74
75    /** Add a full Scan to the Object, making sure there are no
76        overlapping scans afterwards. */
77    void  addScan(Scan scan);
78
79    /** Test whether a pixel (x,y) is in the Object. */
80    bool  isInObject(long x, long y);
81    /** Test whether the (x,y) part of a Voxel is in the Object.*/
82    bool  isInObject(Voxel v){return this->isInObject(v.getX(),v.getY());};
83    /** Test whether a Pixel is in the Object.*/
84    bool  isInObject(Pixel p){return this->isInObject(p.getX(),p.getY());};
85
86    /** Test whether a given Scan overlaps with any pixels in the Object. */
87    bool  scanOverlaps(Scan scan);
88
89    /** Return the number of pixels in the Object. */
90    long  getSize(){return numPix;};
91
92    /** Return the number of Scans in the Object. */
93    long  getNumScan(){return scanlist.size();};
94
95    /** Get the i-th Scan in the Scan list. */
96    Scan  getScan(int i){return scanlist[i];};
97
98    /** Order the Scans in the list, using the < operator for Scans. */
99    void  order(){std::stable_sort(scanlist.begin(),scanlist.end());};
100
101    /** Add values to the x- and y-axes, making sure to add the
102        offsets to the sums and min/max values. */
103    void  addOffsets(long xoff, long yoff);
104
105    /** Calculate the sums, mins, maxs for x&y -- should not be
106        necessary as these are done when pixels & Scans are added. */
107    void  calcParams();
108
109    /** Return the average x-value. */
110    float getXcentre(){return xSum/float(numPix);};
111
112    /** Return the average y-value. */
113    float getYcentre(){return ySum/float(numPix);};
114
115    long  getXmin(){return xmin;};
116    long  getYmin(){return ymin;};
117    long  getXmax(){return xmax;};
118    long  getYmax(){return ymax;};
119
120    /** Return the number of distinct y-values.*/
121    long  getNumDistinctY();
122    /** Return the number of distinct x-values.*/
123    long  getNumDistinctX();
124 
125    /** A stream output operator. */
126    friend std::ostream& operator<< ( std::ostream& theStream, Object2D& obj);
127
128    /** Adding two Objects together. */
129    friend Object2D operator+ (Object2D lhs, Object2D rhs){
130      Object2D output = lhs;
131      for(unsigned int s=0;s<rhs.scanlist.size();s++) output.addScan(rhs.scanlist[s]);
132      return output;
133    }
134
135    friend class Object3D;
136    friend class ChanMap;
137
138  private:
139    std::vector<Scan> scanlist;       ///< The list of Scans
140    long              numPix;         ///< Number of pixels in the Object
141    float             xSum;           ///< Sum of x values
142    float             ySum;           ///< Sum of y values
143    long              xmin,xmax;      ///< min and max x-values of object
144    long              ymin,ymax;      ///< min and max y-values of object
145  };
146
147}
148
149#endif //OBJECT2D_H
Note: See TracBrowser for help on using the repository browser.