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

Last change on this file since 1441 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: 4.4 KB
Line 
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// -----------------------------------------------------------------------
29#ifndef SCAN_H
30#define SCAN_H
31
32#include <iostream>
33#include <vector>
34
35/**
36 * This namespace will store all the classes and functions necessary
37 * to encode shapes and objects in 1-, 2- and 3-dimensions.
38 */
39namespace PixelInfo
40{
41
42  /**
43   * A class to store the basic unit of pixel information, a scan
44   * encoded by an (x,y) starting point, and a length (in the
45   * x-direction).
46   *
47   * This class is used by other classes to store objects in 2- and
48   * 3-dimensions.
49   */
50
51  class Scan
52  {
53  public:
54    Scan();
55    Scan(long y, long x, long xl){itsY=y; itsX=x; itsXLen=xl;};
56    Scan(const Scan& s);
57    Scan& operator= (const Scan& s);
58    virtual ~Scan(){};
59
60    /** Define a Scan by providing the three key parameters. */
61    void define(long y, long x, long xl){itsY=y; itsX=x; itsXLen=xl;};
62
63    /** Set the Scan to the null values, with the length=0. */
64    void clear(){itsY=-1;itsX=-1;itsXLen=0;};
65
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;};
73
74    /** An easy way to get the maximum x-value */
75    long getXmax(){return itsX+itsXLen-1;};
76
77    /** A way of setting the length by proxy, giving the maximum x-value. */
78    void setXmax(long l){itsXLen = l-itsX+1;};
79
80    /** Add a point to the left of the scan (ie.\ add the point itsX-1).*/
81    void growLeft(){itsX--;itsXLen++;};
82
83    /** Add a point to the right of the scan (ie.\ add the point xmax+1).*/
84    void growRight(){itsXLen++;};
85
86    /** Add values to the x- and y-axes. */
87    void addOffsets(long xoff, long yoff){itsY+=yoff; itsX+=xoff;};
88
89    /** Tests whether a given (x,y) point is in the scan.*/
90    bool isInScan(long x, long y);
91
92    /** Stream output operator for the Scan */
93    friend std::ostream& operator<< ( std::ostream& theStream, Scan& scan);
94
95    /** Less-than operator for Scans */
96    friend bool operator< (Scan lhs, Scan rhs);
97
98    /** Test whether one scan is equal to another. */
99    friend bool operator== (Scan lhs, Scan rhs);
100
101    friend class Object2D; ///< Enable Object2D to see the private members.
102
103  private:
104    long itsY;    ///< The y-value of each point in the scan.
105    long itsX;    ///< The x-value of the start (left-hand end) of the scan.
106    long itsXLen; ///< The length of the scan (number of pixels in the scan).
107
108  };
109
110  /** Combine two scans into one. */
111  Scan unite(Scan &s1, Scan &s2);
112
113  /** Keep only the pixels in both the two scans. */
114  Scan intersect(Scan &s1, Scan &s2);
115
116  /** Test whether two scans either overlap or are adjacent. */
117  bool touching(Scan &s1, Scan &s2);
118
119  /** Test whether two scans have pixels in common */
120  bool overlap(Scan &s1, Scan &s2);
121
122  /** Test whether two scans lie adjacent to each other (but not
123      overlapping).*/
124  bool adjacent(Scan &scan1, Scan &scan2);
125
126  /** Return the null scan, y=-1, x=-1, xlen=0.*/
127  Scan nullScan();
128
129  /** Examine a vector list of Scans and merge any that are touching. */
130  void mergeList(std::vector<Scan> scanlist);
131
132}
133
134#endif //SCAN_H
Note: See TracBrowser for help on using the repository browser.