Go to the documentation of this file.00001 #include "brip_line_generator.h"
00002
00003 #include <vcl_iostream.h>
00004 #include <vcl_cmath.h>
00005
00006 bool brip_line_generator::generate(bool& init, float xs, float ys,
00007 float xe, float ye,
00008 float& x, float& y)
00009 {
00010 static float dx, dy, mag, xinc, yinc;
00011 static int x1, y1;
00012 if (init)
00013 {
00014 dx = xe-xs;
00015 dy = ye-ys;
00016 mag = (float)vcl_sqrt(dx*dx + dy*dy);
00017 if (mag<1)
00018 return false;
00019 xinc = dx/mag;
00020 yinc = dy/mag;
00021 x1 = int(xe);
00022 y1 = int(ye);
00023 x = xs;
00024 y = ys;
00025 init = false;
00026
00027 return true;
00028 }
00029
00030
00031 int xp = int(x);
00032 int yp = int(y);
00033
00034 for (int i = 0; i<5; i++)
00035 {
00036 x += (float)0.5*xinc;
00037 y += (float)0.5*yinc;
00038
00039 int xc = int(x), yc = int(y);
00040 bool passed_xe = ((xinc>=0)&&(xc>x1))||((xinc<0)&&(xc<x1));
00041 bool passed_ye = ((yinc>=0)&&(yc>y1))||((yinc<0)&&(yc<y1));
00042 if (passed_xe||passed_ye)
00043 return false;
00044
00045 if (vcl_fabs(static_cast<float>(xc-xp))>=1||vcl_fabs(static_cast<float>(yc-yp))>=1)
00046 return true;
00047 }
00048 vcl_cout << "In brip_line_generator: - shouldn't happen - "
00049 << "xs="<<xs<<" ys="<<ys<<" xe="<<xe<<" ye="<< ye << vcl_endl;
00050 return false;
00051 }