source: trunk/src/PixelMap/Object2D.hh @ 770

Last change on this file since 770 was 770, checked in by MatthewWhiting, 14 years ago

A large bunch of changes related to #102. The starting point was fixing the way the merging worked, to avoid using erase() and do the addition of sources in-place. This led on to optimising the testing functions that look at whether objects should be merged, and a number of new in-class functions were created to do this more transparently. The file areClose.cc now doesn't contain anything useful, and can be deleted. Code is a lot quicker now :)

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