00001 /** 00002 * @file Modules/ImageProcessor/ImageProcessorTools/BresenhamLineScan.h 00003 * 00004 * Utility class which performs the Bresenham algorithm for line scanning. 00005 * Some constructors set numberOfPixels which can be used as a termination condition to 00006 * prevent scans outside the image boundaries. 00007 * 00008 * @author <a href="mailto:timlaue@tzi.de">Tim Laue</a> 00009 * @author <a href="mailto:walter.nistico@uni-dortmund.de">Walter Nistico</a> 00010 * @author <a href="mailto:oberlies@sim.tu-darmstadt.de">Tobias Oberlies</a> (revised constructors and commenting) 00011 */ 00012 00013 #ifndef __BresenhamLineScan_h_ 00014 #define __BresenhamLineScan_h_ 00015 00016 #include "Tools/Math/Geometry.h" 00017 #include "Representations/Perception/CameraInfo.h" 00018 #include "Tools/Debugging/Debugging.h" 00019 00020 #define DEG2RAD(x) x/180.0*3.1415926535897 00021 00022 class BresenhamLineScan 00023 { 00024 public: 00025 /** 00026 * Constructs a scanline through the two points. numberOfPixels can be used. 00027 * @param start The start point of the line segment. 00028 * @param end The end point of the line segment. 00029 */ 00030 BresenhamLineScan(const Vector2<int>& start, const Vector2<int>& end); 00031 00032 /** 00033 * Constructs a scanline with the given direction. 00034 * @param direction The direction vector of the scanline. 00035 */ 00036 BresenhamLineScan(const Vector2<double>& direction); 00037 00038 /** 00039 * Constructs a scanline with the given direction. 00040 * @param direction The direction (angle) of the line, expressed in radians. 00041 */ 00042 BresenhamLineScan(const double& direction); 00043 00044 /** 00045 * Constructs a scanline with the given direction starting at start and ending at the 00046 * image boundary. numberOfPixels can be used. 00047 * @param start The start point of the line. 00048 * @param direction The direction (angle) of the line, expressed in radians. 00049 * @param cameraInfo The cameraInfo object of the camera that captured the image. 00050 */ 00051 BresenhamLineScan(const Vector2<int>& start, const double& direction, const CameraInfo& cameraInfo); 00052 00053 /** 00054 * Constructs a scanline with the given direction starting at start and ending at the 00055 * image boundary. numberOfPixels can be used. 00056 * @param start The start point of the ray 00057 * @param direction The vector pointing in the direction of scanning. Must not be a null 00058 * vector. 00059 * @param cameraInfo The cameraInfo object of the camera that captured the image. 00060 * @author Tobias Oberlies 00061 */ 00062 BresenhamLineScan(const Vector2<int>& start, const Vector2<double>& direction, const CameraInfo& cameraInfo); 00063 00064 00065 00066 /** Resets the error counter */ 00067 inline void init() 00068 { 00069 error = baseError; 00070 } 00071 00072 /** 00073 * Increments the coordinates to the next point on the line. 00074 * @param pos The position of the current pixel on the line, which is incremented by the 00075 * Bresenham algorithm 00076 */ 00077 inline void getNext(Vector2<int>& pos) 00078 { 00079 pos += standardOffset; 00080 error += delta; 00081 if(error > 0) 00082 { 00083 pos += correctionOffset; 00084 error += resetError; 00085 } 00086 } 00087 00088 /** 00089 * In conjuction with certain constructors (see above), this value can be used as a 00090 * termination criterion for the scan. In those cases, getNext can be called 00091 * numberOfPixels times without leaving the image boundaries. 00092 */ 00093 int numberOfPixels; 00094 00095 private: 00096 00097 /** Increase x-values, if true. */ 00098 bool alongX; 00099 /** The error per step. */ 00100 int delta; 00101 /** The initial error value. */ 00102 int baseError; 00103 /** Resets the error to a value less than zero. */ 00104 int resetError; 00105 /** The standard offset per step. */ 00106 Vector2<int> standardOffset; 00107 /** The additional offset, if the error is above zero. */ 00108 Vector2<int> correctionOffset; 00109 /** The current error counter. */ 00110 int error; 00111 00112 /** Computes the Bresenham parameters. */ 00113 void setup(const Vector2<int>& diff); 00114 }; 00115 00116 00117 #endif //__BresenhamLineScan_h_
1.3.6