Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Modules/ImageProcessor/ImageProcessorTools/BresenhamLineScan.cpp

Go to the documentation of this file.
00001 /**
00002 * @file BresenhamLineScan.cpp
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 #include "BresenhamLineScan.h"
00012 
00013 void BresenhamLineScan::setup(const Vector2<int>& start, const Vector2<int>& end)
00014 {
00015   int dx(end.x - start.x);
00016   int dy(end.y - start.y);
00017   int incX = ((dx>0) ? 1:-1);
00018   int incY = ((dy>0) ? 1:-1);
00019   int absDx(abs(dx));
00020   int absDy(abs(dy));
00021   alongX = (absDy < absDx);
00022   if(alongX)
00023   {
00024     baseError = -absDx;
00025     delta = 2*absDy;
00026     standardOffset.x = incX;
00027     standardOffset.y = 0;
00028     correctionOffset.x = 0;
00029     correctionOffset.y = incY;
00030     numberOfPixels = absDx;
00031   }
00032   else
00033   {
00034     baseError = -absDy;
00035     delta = 2*absDx;
00036     standardOffset.x = 0;
00037     standardOffset.y = incY;
00038     correctionOffset.x = incX;
00039     correctionOffset.y = 0;
00040     numberOfPixels = absDy;
00041   }
00042   resetError = 2*baseError;
00043 }
00044 
00045 BresenhamLineScan::BresenhamLineScan(const Vector2<int>& start, const Vector2<int>& end)
00046 {
00047   setup(start, end);
00048 }
00049 
00050 BresenhamLineScan::BresenhamLineScan(const double& direction, const CameraInfo& cameraInfo)
00051 {
00052   const Vector2<int> frameUpperLeft(0,0);
00053   const Vector2<int> frameLowerRight(cameraInfo.resolutionWidth-1, cameraInfo.resolutionHeight-1);
00054   Geometry::Line scanLine(frameLowerRight/2, Vector2<double>(cos(direction), sin(direction)));
00055   Vector2<int> lineStart, lineEnd;
00056   Geometry::getIntersectionPointsOfLineAndRectangle(
00057                                       frameUpperLeft,
00058                                       frameLowerRight,
00059                                       scanLine, lineStart, lineEnd);
00060   setup(lineStart, lineEnd);
00061 }
00062 
00063 BresenhamLineScan::BresenhamLineScan(const Vector2<int>& start, const double& direction, const CameraInfo& cameraInfo)
00064 {
00065   const Vector2<int> frameUpperLeft(0,0);
00066   const Vector2<int> frameLowerRight(cameraInfo.resolutionWidth-1, cameraInfo.resolutionHeight-1);
00067   Geometry::Line scanLine(start, Vector2<double>(cos(direction), sin(direction)));
00068   Vector2<int> lineStart, lineEnd;
00069   Geometry::getIntersectionPointsOfLineAndRectangle(
00070                                       frameUpperLeft,
00071                                       frameLowerRight,
00072                                       scanLine, lineStart, lineEnd);
00073   Vector2<double> delta((lineEnd - start).x, (lineEnd - start).y);
00074   Vector2<double> directionVector(cos(direction), sin(direction));
00075   if (delta*directionVector >= 0)
00076     setup(start, lineEnd);
00077   else
00078     setup(start, lineStart); 
00079 }
00080 
00081 BresenhamLineScan::BresenhamLineScan(const Vector2<double>& direction, const CameraInfo& cameraInfo)
00082 {
00083   const Vector2<int> frameUpperLeft(0,0);
00084   const Vector2<int> frameLowerRight(cameraInfo.resolutionWidth-1, cameraInfo.resolutionHeight-1);
00085   Geometry::Line scanLine(frameLowerRight/2, direction);
00086   Vector2<int> lineStart, lineEnd;
00087   Geometry::getIntersectionPointsOfLineAndRectangle(
00088                                       frameUpperLeft,
00089                                       frameLowerRight,
00090                                       scanLine, lineStart, lineEnd);
00091   setup(lineStart, lineEnd);
00092 }
00093 
00094 /*
00095 * $Log: BresenhamLineScan.cpp,v $
00096 * Revision 1.4  2004/09/08 14:39:02  wachter
00097 * - Fixed some doxygen-errors
00098 *
00099 * Revision 1.3  2004/07/09 14:13:13  nistico
00100 * New constructor added
00101 *
00102 * Revision 1.2  2004/06/12 18:32:49  nistico
00103 * Mean and nasty warning removed :-)
00104 *
00105 * Revision 1.1  2004/06/12 17:37:00  nistico
00106 * Eventually, would be nice to have only one Bresenham on the whole
00107 * GT2004ImageProcessor
00108 *
00109 *
00110 */

Generated on Thu Sep 23 19:57:29 2004 for GT2004 by doxygen 1.3.6