00001
00029 #ifndef DijkstraVectors_h
00030 #define DijkstraVectors_h
00031
00032 #ifdef WIN32
00033 #pragma warning(disable:4786) //necessary because stl generates longer
00034
00035 #endif
00036
00037 #include "DistanceTransform.h"
00038 #include <set>
00039 #include <vector>
00040
00041 using namespace std;
00042
00044 class DijkstraVectors : public DistanceTransform {
00045
00046 public:
00048
00052 DijkstraVectors ( const int xSize, const int ySize,
00053 const bool unload=true )
00054 : DistanceTransform(xSize, ySize, unload)
00055 {
00056 }
00057
00058 void doTransform ( const unsigned char* const I );
00059
00060 virtual inline bool getP ( const int x, const int y, int& px, int& py )
00061 const { return getP(x, y, px, py, 0); }
00062
00063 inline bool getP ( const int x, const int y, int& px, int& py,
00064 const int which ) const
00065 {
00066 if (this->p == NULL) {
00067 px = py = -1;
00068 return false;
00069 }
00070
00071 const int i = sub(x,y);
00072 if (which < (int)p[i].size()) {
00073 px = p[i][which]->x;
00074 py = p[i][which]->y;
00075
00076
00077
00078
00079 return true;
00080 }
00081
00082 px = py = -1;
00083 return false;
00084 }
00085
00086 private:
00092 class SetElement {
00093 public:
00094 double d;
00095 int x;
00096 int y;
00097 SetElement ( const double d, const int x, const int y ) {
00098 this->d = d;
00099 this->x = x;
00100 this->y = y;
00101 }
00102 };
00103
00105 struct ltSetElement {
00108 bool operator() ( const SetElement* s1, const SetElement* s2 ) const {
00109 if (s1->d < s2->d) return true;
00110 if (s1->d > s2->d) return false;
00111
00112 if (s1->x < s2->x) return true;
00113 if (s1->x > s2->x) return false;
00114
00115 if (s1->y < s2->y) return true;
00116 if (s1->y > s2->y) return false;
00117 return false;
00118 }
00119 };
00120
00123 vector<SetElement*>* p;
00124
00125 inline void check ( double* d, const int center, const int X, const int Y,
00126 set< SetElement*, ltSetElement > &s );
00127
00128 };
00129
00130 #endif
00131
00132