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