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