| 1 | #ifndef __BREZENHAM_H |
| 2 | #define __BREZENHAM_H |
| 3 | |
| 4 | #include <TooN/TooN.h> |
| 5 | #include <cvd/image_ref.h> |
| 6 | |
| 7 | namespace CVD |
| 8 | { |
| 9 | |
| 10 | /// Class to implement the Bresenham line-drawing algorithm. |
| 11 | /// This object does not draw directly into an image, it simply outputs the set |
| 12 | /// of image co-ordinates that should be visited to draw a line in a certain |
| 13 | /// direction. Pixels are generated in a 4-connected sense (i.e. there are |
| 14 | /// no diagonal steps--each step is either horizontal or vertical) |
| 15 | /// details of the algorithm. See also Brezenham8. |
| 16 | /// @ingroup gGraphics |
| 17 | class Brezenham |
| 18 | { |
| 19 | public: |
| 20 | /// Construct a line-drawing object |
| 21 | /// @param dir The (x,y) direction of the line |
| 22 | Brezenham(TooN::Vector<2> dir); |
| 23 | |
| 24 | /// Returns the next image co-ordinate along the line |
| 25 | ImageRef step(); |
| 26 | |
| 27 | private: |
| 28 | double residual; |
| 29 | double val1; |
| 30 | double val2; |
| 31 | ImageRef step1; |
| 32 | ImageRef step2; |
| 33 | }; |
| 34 | |
| 35 | /// Class to implement the Bresenham line-drawing algorithm. |
| 36 | /// This object does not draw directly into an image, it simply outputs the set |
| 37 | /// of image co-ordinates that should be visited to draw a line in a certain |
| 38 | /// direction. Pixels are generated in a 8-connected sense (i.e. diagonal steps |
| 39 | /// are possible). See also Brezenham. |
| 40 | /// @ingroup gGraphics |
| 41 | class Brezenham8 |
| 42 | { |
| 43 | public: |
| 44 | /// Construct a line-drawing object |
| 45 | /// @param dir The (x,y) direction of the line |
| 46 | Brezenham8(TooN::Vector<2> dir); |
| 47 | |
| 48 | /// Returns the next image co-ordinate along the line |
| 49 | ImageRef step(); |
| 50 | |
| 51 | /// Which compass position most orthogonal to the line's direction? |
| 52 | /// At each pixel given by |
| 53 | /// step() you are guaranteed to be able to walk in the direction given |
| 54 | /// by sideways and not walk on the line. |
| 55 | ImageRef sideways() { return my_sideways; } |
| 56 | |
| 57 | private: |
| 58 | double residual; |
| 59 | double val1; |
| 60 | double val2; |
| 61 | ImageRef step1; |
| 62 | ImageRef step2; |
| 63 | ImageRef my_sideways; |
| 64 | }; |
| 65 | |
| 66 | } |
| 67 | |
| 68 | #endif |