[301] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // Scan.hh: Definition of the Scan class, used to store row |
---|
| 3 | // information as part of a 2D 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 SCAN_H |
---|
| 30 | #define SCAN_H |
---|
| 31 | |
---|
| 32 | #include <iostream> |
---|
[253] | 33 | #include <vector> |
---|
[238] | 34 | |
---|
[528] | 35 | /// This namespace will store all the classes and functions necessary |
---|
| 36 | /// to encode shapes and objects in 1-, 2- and 3-dimensions. |
---|
[252] | 37 | namespace PixelInfo |
---|
[238] | 38 | { |
---|
| 39 | |
---|
[528] | 40 | /// A class to store the basic unit of pixel information, a scan |
---|
| 41 | /// encoded by an (x,y) starting point, and a length (in the |
---|
| 42 | /// x-direction). |
---|
| 43 | /// |
---|
| 44 | /// This class is used by other classes to store objects in 2- and |
---|
| 45 | /// 3-dimensions. |
---|
[240] | 46 | |
---|
[252] | 47 | class Scan |
---|
| 48 | { |
---|
| 49 | public: |
---|
[365] | 50 | Scan(); |
---|
[770] | 51 | Scan(long y, long x, long xl); |
---|
[270] | 52 | Scan(const Scan& s); |
---|
[770] | 53 | Scan& operator= (const Scan& s); |
---|
[252] | 54 | virtual ~Scan(){}; |
---|
[238] | 55 | |
---|
[528] | 56 | /// @brief Define a Scan by providing the three key parameters. |
---|
[252] | 57 | void define(long y, long x, long xl){itsY=y; itsX=x; itsXLen=xl;}; |
---|
[238] | 58 | |
---|
[528] | 59 | /// @brief Set the Scan to the null values, with the length=0. |
---|
[252] | 60 | void clear(){itsY=-1;itsX=-1;itsXLen=0;}; |
---|
[527] | 61 | bool isNull(); |
---|
[238] | 62 | |
---|
[773] | 63 | /// @brief Combine scans |
---|
| 64 | bool addScan(const Scan &other); |
---|
| 65 | |
---|
[252] | 66 | // Accessor functions -- obvious. |
---|
| 67 | long getY(){return itsY;}; |
---|
| 68 | void setY(long l){itsY=l;}; |
---|
| 69 | long getX(){return itsX;}; |
---|
| 70 | void setX(long l){itsX=l;}; |
---|
| 71 | long getXlen(){return itsXLen;}; |
---|
| 72 | void setXlen(long l){itsXLen=l;}; |
---|
[238] | 73 | |
---|
[528] | 74 | /// @brief An easy way to get the maximum x-value |
---|
[252] | 75 | long getXmax(){return itsX+itsXLen-1;}; |
---|
[238] | 76 | |
---|
[528] | 77 | /// @brief A way of setting the length by proxy, giving the maximum x-value. |
---|
[252] | 78 | void setXmax(long l){itsXLen = l-itsX+1;}; |
---|
| 79 | |
---|
[528] | 80 | /// @brief Add a point to the left of the scan (ie.\ add the point itsX-1). |
---|
[252] | 81 | void growLeft(){itsX--;itsXLen++;}; |
---|
| 82 | |
---|
[528] | 83 | /// @brief Add a point to the right of the scan (ie.\ add the point xmax+1). |
---|
[252] | 84 | void growRight(){itsXLen++;}; |
---|
| 85 | |
---|
[528] | 86 | /// @brief Add values to the x- and y-axes. |
---|
[252] | 87 | void addOffsets(long xoff, long yoff){itsY+=yoff; itsX+=xoff;}; |
---|
| 88 | |
---|
[528] | 89 | /// @brief Tests whether a given (x,y) point is in the scan. |
---|
[252] | 90 | bool isInScan(long x, long y); |
---|
| 91 | |
---|
[773] | 92 | bool touches(const Scan &other); |
---|
| 93 | bool overlaps(const Scan &other); |
---|
| 94 | bool isAdjacentTo(const Scan &other); |
---|
[770] | 95 | |
---|
[528] | 96 | /// @brief Stream output operator for the Scan |
---|
[252] | 97 | friend std::ostream& operator<< ( std::ostream& theStream, Scan& scan); |
---|
| 98 | |
---|
[528] | 99 | /// @brief Less-than operator for Scans |
---|
[252] | 100 | friend bool operator< (Scan lhs, Scan rhs); |
---|
| 101 | |
---|
[528] | 102 | /// @brief Test whether one scan is equal to another. |
---|
[252] | 103 | friend bool operator== (Scan lhs, Scan rhs); |
---|
| 104 | |
---|
| 105 | friend class Object2D; ///< Enable Object2D to see the private members. |
---|
[773] | 106 | friend class Object3D; |
---|
| 107 | protected: |
---|
[252] | 108 | long itsY; ///< The y-value of each point in the scan. |
---|
| 109 | long itsX; ///< The x-value of the start (left-hand end) of the scan. |
---|
| 110 | long itsXLen; ///< The length of the scan (number of pixels in the scan). |
---|
| 111 | |
---|
| 112 | }; |
---|
| 113 | |
---|
[528] | 114 | /// @brief Combine two scans into one. |
---|
[252] | 115 | Scan unite(Scan &s1, Scan &s2); |
---|
| 116 | |
---|
[528] | 117 | /// @brief Keep only the pixels in both the two scans. |
---|
[252] | 118 | Scan intersect(Scan &s1, Scan &s2); |
---|
| 119 | |
---|
[528] | 120 | /// @brief Test whether two scans either overlap or are adjacent. |
---|
[252] | 121 | bool touching(Scan &s1, Scan &s2); |
---|
| 122 | |
---|
[528] | 123 | /// @brief Test whether two scans have pixels in common |
---|
[252] | 124 | bool overlap(Scan &s1, Scan &s2); |
---|
| 125 | |
---|
[528] | 126 | /// @brief Test whether two scans lie adjacent to each other (but not overlapping). |
---|
[252] | 127 | bool adjacent(Scan &scan1, Scan &scan2); |
---|
| 128 | |
---|
[528] | 129 | /// @brief Return the null scan, y=-1, x=-1, xlen=0. |
---|
[252] | 130 | Scan nullScan(); |
---|
| 131 | |
---|
[528] | 132 | /// @brief Examine a vector list of Scans and merge any that are touching. |
---|
[253] | 133 | void mergeList(std::vector<Scan> scanlist); |
---|
| 134 | |
---|
[528] | 135 | /// @brief Get the minimum separation, in pixels, between two scans. |
---|
[505] | 136 | float minSep(Scan &s1, Scan &s2); |
---|
| 137 | |
---|
[252] | 138 | } |
---|
| 139 | |
---|
[238] | 140 | #endif //SCAN_H |
---|