00001 /** 00002 * @file Modules/ImageProcessor/ImageProcessorTools/BresenhamLineScan.h 00003 * 00004 * Utility class which performs the Bresenham algorithm 00005 * for line scanning 00006 * 00007 * @author <a href="mailto:timlaue@tzi.de">Tim Laue</a> 00008 * @author <a href="mailto:walter.nistico@uni-dortmund.de">Walter Nistico</a> 00009 */ 00010 00011 #ifndef __BresenhamLineScan_h_ 00012 #define __BresenhamLineScan_h_ 00013 00014 #include "Tools/Math/Geometry.h" 00015 #include "Representations/Perception/CameraInfo.h" 00016 #include "Tools/Debugging/Debugging.h" 00017 00018 #define DEG2RAD(x) x/180.0*3.1415926535897 00019 00020 class BresenhamLineScan 00021 { 00022 public: 00023 /** Constructor: Computes parameters for a line 00024 * @param start The start point of the line 00025 * @param end The end point of the line 00026 */ 00027 BresenhamLineScan(const Vector2<int>& start, const Vector2<int>& end); 00028 00029 /** Constructor: Computes parameters for a line 00030 * @param direction The direction vector of the line 00031 * @param cameraInfo Contains image related parameters 00032 */ 00033 BresenhamLineScan(const Vector2<double>& direction, const CameraInfo& cameraInfo); 00034 00035 /** Constructor: Computes parameters for a line 00036 * @param direction The direction (angle) of the line, expressed in radians 00037 * @param cameraInfo Contains image related parameters 00038 */ 00039 BresenhamLineScan(const double& direction, const CameraInfo& cameraInfo); 00040 00041 /** Constructor: Computes parameters for a line, numberOfPixels can be used as a termination 00042 * condition to prevent scans outside of the image space 00043 * @param start The start point of the line 00044 * @param direction The direction (angle) of the line, expressed in radians 00045 * @param cameraInfo Contains image related parameters 00046 */ 00047 BresenhamLineScan(const Vector2<int>& start, const double& direction, const CameraInfo& cameraInfo); 00048 00049 /** initializes the error counter */ 00050 inline void init() 00051 { 00052 error = baseError; 00053 } 00054 00055 /** 00056 * Increments the coordinates to the next point on the line. 00057 * @param pos The position of the current pixel on the line, which is incremented by the Bresenham algorithm 00058 */ 00059 inline void getNext(Vector2<int>& pos) 00060 { 00061 pos += standardOffset; 00062 error += delta; 00063 if(error > 0) 00064 { 00065 pos += correctionOffset; 00066 error += resetError; 00067 } 00068 } 00069 00070 /** The numberOfPixels, can be used as a termination condition for the scan, 00071 * but only if the first constructor has been used (the other 2 constructors 00072 * are in fact meant for infinite/unbounded scans, so it doesn't make sense) 00073 */ 00074 int numberOfPixels; 00075 00076 private: 00077 00078 /** Increase x-values, if true*/ 00079 bool alongX; 00080 /** The error per step*/ 00081 int delta; 00082 /** The initial error value*/ 00083 int baseError; 00084 /** Resets the error to a value less than zero*/ 00085 int resetError; 00086 /** The standard offset per step*/ 00087 Vector2<int> standardOffset; 00088 /** The additional offset, if the error is above zero*/ 00089 Vector2<int> correctionOffset; 00090 /** The current error counter*/ 00091 int error; 00092 /** Computes the Bresenham parameters*/ 00093 void setup(const Vector2<int>& start, const Vector2<int>& end); 00094 }; 00095 00096 00097 #endif //__BresenhamLineScan_h_ 00098 00099 /* 00100 * $Log: BresenhamLineScan.h,v $ 00101 * Revision 1.3 2004/07/09 14:13:13 nistico 00102 * New constructor added 00103 * 00104 * Revision 1.2 2004/06/12 18:32:49 nistico 00105 * Mean and nasty warning removed :-) 00106 * 00107 * Revision 1.1 2004/06/12 17:37:00 nistico 00108 * Eventually, would be nice to have only one Bresenham on the whole 00109 * GT2004ImageProcessor 00110 * 00111 * 00112 */