00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef __FAST_MARCHING_2D_H
00036 #define __FAST_MARCHING_2D_H
00037
00038 #include <stdlib.h>
00039 #include <math.h>
00040
00041 #include <valarray>
00042 using std::valarray;
00043
00044 #include "OFELI_Config.h"
00045 #include "Vect.h"
00046 #include "Point2D.h"
00047 #include "Grid.h"
00048
00053 namespace OFELI {
00054
00055 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00056 struct Pt
00057 {
00058 size_t ix, iy;
00059 double val;
00060 Pt & operator=(double a) { ix = iy = 0; val = a; return *this; }
00061 };
00062 #endif
00063
00064 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00065 struct ErrorInFastMarching2D {
00066 void Message(const char *file, size_t line, int code);
00067 };
00068 #endif
00069
00070
00080 class FastMarching2D
00081 {
00082 public:
00083
00085 FastMarching2D();
00086
00094 FastMarching2D(const Grid &g, Vect<double> &ls);
00095
00105 FastMarching2D(const Grid &g, Vect<double> &ls, Vect<double> &F);
00106
00108 ~FastMarching2D();
00109
00114 void execute();
00115
00117 void Check();
00118
00119 private:
00120 bool _ext;
00121 size_t _nx, _ny;
00122 int _bw, _current;
00123 double _hx, _hy;
00124 Grid _g;
00125 const Grid *_cg;
00126 Vect<size_t> _pos;
00127 Vect<double> *_A, *_v;
00128 Vect<double> _ls, _f, _u, _sol;
00129 Vect<Pt> _heap;
00130 ErrorInFastMarching2D _e;
00131
00132 void Init();
00133
00134
00135 double Obstacle(Point2D<double> a);
00136
00137
00138 double Dist(const Point2D<double> &x, const Point2D<double> &y, const Point2D<double> &z);
00139
00140
00141 void Add(double Uij, size_t a, size_t b);
00142
00143
00144 void Modify(double Uij, size_t a, size_t b);
00145
00146
00147 Pt Delete();
00148
00149
00150 inline double PositiveSol(double a, double b, double c)
00151 {
00152 double delta = b*b - 4*a*c;
00153 if (delta == 0)
00154 return(-0.5*b/a);
00155 else {
00156 if (delta < 0) {
00157 cerr << "Error in FastMarching2D: No positive solution found." << endl;
00158 exit(1);
00159 }
00160 else
00161 return (0.5*(sqrt(delta)-b)/a);
00162 }
00163 }
00164
00165
00166 void ExtendLocalVelocity(Vect<double> &dis);
00167
00168 void Int(size_t k, size_t l, Vect<double> &a, Point2D<double> &x1, Point2D<double> &x2);
00169
00170
00171 double Interp(Point2D<double> &xx);
00172
00173
00174 void setGray(size_t i, size_t j);
00175 void setGrayWithObstacle(size_t i, size_t j);
00176 };
00177
00178 }
00179
00180 #endif