source: branches/pixel-map-branch/src/PixelMap/Scan.hh

Last change on this file was 253, checked in by Matthew Whiting, 17 years ago
  • Added a mergeList(vector<Scan>) function to the PixelMap? namespace. This is usefu

l for combining lists of Scans into a set of independent ones.

  • Wrote a new spectralSelection function to deal with selection of a spectrum for development applications.
File size: 3.2 KB
Line 
1#ifndef SCAN_H
2#define SCAN_H
3
4#include <iostream>
5#include <vector>
6
7/**
8 * This namespace will store all the classes and functions necessary
9 * to encode shapes and objects in 1-, 2- and 3-dimensions.
10 */
11namespace PixelInfo
12{
13
14  /**
15   * A class to store the basic unit of pixel information, a scan
16   * encoded by an (x,y) starting point, and a length (in the
17   * x-direction).
18   *
19   * This class is used by other classes to store objects in 2- and
20   * 3-dimensions.
21   */
22
23  class Scan
24  {
25  public:
26    Scan(){itsY=-1;itsX=-1;itsXLen=0;};
27    Scan(long y, long x, long xl){itsY=y; itsX=x; itsXLen=xl;};
28    Scan(const Scan& s){itsY=s.itsY; itsX=s.itsX; itsXLen=s.itsXLen;};
29    Scan& operator= (const Scan& s){itsY=s.itsY; itsX=s.itsX; itsXLen=s.itsXLen;};
30    virtual ~Scan(){};
31
32    /** Define a Scan by providing the three key parameters. */
33    void define(long y, long x, long xl){itsY=y; itsX=x; itsXLen=xl;};
34
35    /** Set the Scan to the null values, with the length=0. */
36    void clear(){itsY=-1;itsX=-1;itsXLen=0;};
37
38    // Accessor functions -- obvious.
39    long getY(){return itsY;};
40    void setY(long l){itsY=l;};
41    long getX(){return itsX;};
42    void setX(long l){itsX=l;};
43    long getXlen(){return itsXLen;};
44    void setXlen(long l){itsXLen=l;};
45
46    /** An easy way to get the maximum x-value */
47    long getXmax(){return itsX+itsXLen-1;};
48
49    /** A way of setting the length by proxy, giving the maximum x-value. */
50    void setXmax(long l){itsXLen = l-itsX+1;};
51
52    /** Add a point to the left of the scan (ie.\ add the point itsX-1).*/
53    void growLeft(){itsX--;itsXLen++;};
54
55    /** Add a point to the right of the scan (ie.\ add the point xmax+1).*/
56    void growRight(){itsXLen++;};
57
58    /** Add values to the x- and y-axes. */
59    void addOffsets(long xoff, long yoff){itsY+=yoff; itsX+=xoff;};
60
61    /** Tests whether a given (x,y) point is in the scan.*/
62    bool isInScan(long x, long y);
63
64    /** Stream output operator for the Scan */
65    friend std::ostream& operator<< ( std::ostream& theStream, Scan& scan);
66
67    /** Less-than operator for Scans */
68    friend bool operator< (Scan lhs, Scan rhs);
69
70    /** Test whether one scan is equal to another. */
71    friend bool operator== (Scan lhs, Scan rhs);
72
73    friend class Object2D; ///< Enable Object2D to see the private members.
74
75  private:
76    long itsY;    ///< The y-value of each point in the scan.
77    long itsX;    ///< The x-value of the start (left-hand end) of the scan.
78    long itsXLen; ///< The length of the scan (number of pixels in the scan).
79
80  };
81
82  /** Combine two scans into one. */
83  Scan unite(Scan &s1, Scan &s2);
84
85  /** Keep only the pixels in both the two scans. */
86  Scan intersect(Scan &s1, Scan &s2);
87
88  /** Test whether two scans either overlap or are adjacent. */
89  bool touching(Scan &s1, Scan &s2);
90
91  /** Test whether two scans have pixels in common */
92  bool overlap(Scan &s1, Scan &s2);
93
94  /** Test whether two scans lie adjacent to each other (but not
95      overlapping).*/
96  bool adjacent(Scan &scan1, Scan &scan2);
97
98  /** Return the null scan, y=-1, x=-1, xlen=0.*/
99  Scan nullScan();
100
101  /** Examine a vector list of Scans and merge any that are touching. */
102  void mergeList(std::vector<Scan> scanlist);
103
104}
105
106#endif //SCAN_H
Note: See TracBrowser for help on using the repository browser.