00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ESTAR_FACADE_HPP
00022 #define ESTAR_FACADE_HPP
00023
00024
00025 #include <estar/FacadeWriteInterface.hpp>
00026 #include <estar/FacadeReadInterface.hpp>
00027 #include <estar/CSpace.hpp>
00028 #include <estar/Grid.hpp>
00029 #include <boost/shared_ptr.hpp>
00030 #include <string>
00031 #include <iosfwd>
00032
00033
00034 namespace pnf {
00035 class Flow;
00036 }
00037
00038
00039 namespace estar {
00040
00041
00042 class Region;
00043
00044
00045 class GridOptions
00046 {
00047 public:
00048 GridOptions(ssize_t xbegin, ssize_t xend,
00049 ssize_t ybegin, ssize_t yend,
00050 double init_meta = 0,
00051 Grid::neighborhood_t neighborhood = Grid::FOUR);
00052
00053 ssize_t xbegin, xend, ybegin, yend;
00054 double init_meta;
00055
00058 Grid::neighborhood_t neighborhood;
00059 };
00060
00061
00062 class AlgorithmOptions
00063 {
00064 public:
00067 AlgorithmOptions();
00068
00069 AlgorithmOptions(bool check_upwind,
00070 bool check_local_consistency,
00071 bool check_queue_key,
00072 bool auto_reset,
00073 bool auto_flush);
00074
00078 bool check_upwind;
00079
00084 bool check_local_consistency;
00085
00090 bool check_queue_key;
00091
00098 bool auto_reset;
00099
00107 bool auto_flush;
00108 };
00109
00110
00126 class Facade
00127 : public FacadeWriteInterface,
00128 public FacadeReadInterface
00129 {
00130 public:
00135 typedef FacadeReadInterface::node_status_t node_status_t;
00136
00137
00138 const double scale;
00139
00140
00176 static Facade *
00177 Create(
00180 const std::string & kernel_name,
00181 double scale,
00182 GridOptions const & grid_options,
00183 AlgorithmOptions const & algo_options,
00187 FILE * dbgstream);
00188
00192 static Facade *
00193 CreateDefault(ssize_t xsize, ssize_t ysize, double scale);
00194
00195
00204 Facade(boost::shared_ptr<Algorithm> algo,
00205 boost::shared_ptr<Grid> grid,
00206 boost::shared_ptr<Kernel> kernel);
00207
00208
00212 virtual double GetScale() const { return scale; }
00213
00217 virtual double GetFreespaceMeta() const;
00218
00222 virtual double GetObstacleMeta() const;
00223
00227 virtual double GetValue(ssize_t ix, ssize_t iy) const;
00228
00233 virtual double GetMeta(ssize_t ix, ssize_t iy) const;
00234
00239 virtual bool SetMeta(ssize_t ix, ssize_t iy, double meta);
00240
00247 virtual bool AddGoal(ssize_t ix, ssize_t iy, double value);
00248
00257 void AddGoal(const Region & goal);
00258
00265 void RemoveGoal(ssize_t ix, ssize_t iy);
00266
00272 void RemoveGoal(const Region & goal);
00273
00277 virtual void RemoveAllGoals();
00278
00282 virtual bool IsGoal(ssize_t ix, ssize_t iy) const;
00283
00287 virtual bool HaveWork() const;
00288
00292 virtual void ComputeOne();
00293
00297 virtual void Reset();
00298
00302 virtual node_status_t GetStatus(ssize_t ix, ssize_t iy) const;
00303
00307 virtual node_status_t GetStatus(vertex_t vertex) const;
00308
00312 virtual bool IsValidIndex(ssize_t ix, ssize_t iy) const;
00313
00317 virtual bool GetLowestInconsistentValue(double & value) const;
00318
00324 void DumpGrid(FILE * stream) const;
00325
00331 void DumpQueue(FILE * stream,
00335 size_t limit) const;
00336
00342 void DumpPointers(FILE * stream) const;
00343
00347 virtual const Algorithm & GetAlgorithm() const { return * m_algo; }
00348
00349 protected:
00350 friend class pnf::Flow;
00351
00355 virtual boost::shared_ptr<Grid const> GetGrid() const;
00356 public:
00357
00361 virtual const Kernel & GetKernel() const { return * m_kernel; }
00362
00366 virtual int TraceCarrot(double robot_x, double robot_y,
00367 double distance, double stepsize,
00368 size_t maxsteps,
00369 carrot_trace & trace) const;
00370
00374 virtual boost::shared_ptr<GridCSpace const> GetCSpace() const;
00375
00376
00384 Algorithm & GetAlgorithm() { return * m_algo; }
00385
00393 Kernel & GetKernel() { return * m_kernel; }
00394
00395 private:
00396 boost::shared_ptr<GridCSpace const> m_cspace;
00397 boost::shared_ptr<Algorithm> m_algo;
00398 boost::shared_ptr<Grid> m_grid;
00399 boost::shared_ptr<Kernel> m_kernel;
00400
00401 node_status_t DoGetStatus(ssize_t ix, ssize_t iy, vertex_t vertex) const;
00402 };
00403
00404 }
00405
00406 #endif // ESTAR_FACADE_HPP