INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

NONFRAMEWORK CODE
Driver Interfaces
Drivers
Libraries
Utilities

FRAMEWORK CODE
Interfaces
Components
Libraries
Utilities

Full Software Listings

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

oglostracer.h

00001 #ifndef HYDROOGMAP_OGLOSTRACER_H
00002 #define HYDROOGMAP_OGLOSTRACER_H
00003 
00004 #include <hydroogmap/ogmap.h>
00005 #include <hydroogmap/mapraytracer.h>
00006 
00007 namespace hydroogmap {
00008 
00014 class OgLosTracer
00015 {
00016 
00017 public: 
00018 
00019     OgLosTracer( const hydroogmap::OgMap &theMap,
00020                  unsigned char occupiedThreshold=hydroogmap::CELL_UNKNOWN )
00021         : theMap_(theMap),
00022           cellTracer_(theMap,occupiedThreshold),
00023           mapRayTracer_(theMap,cellTracer_)
00024         {}
00025 
00032     bool isClearCells( const GridIndices &start, const GridIndices &intendedEnd, GridIndices &actualEnd )
00033         {
00034             bool isLineOfSight = mapRayTracer_.traceCells( start, intendedEnd );
00035             if ( !isLineOfSight )
00036             {
00037                 actualEnd = GridIndices( cellTracer_.lastEndX(), cellTracer_.lastEndY() );
00038                 return isLineOfSight;
00039             }
00040             else
00041             {
00042                 actualEnd = intendedEnd;
00043                 return isLineOfSight;
00044             }
00045         }
00046     bool isClearCells( int x0,int y0,  int x1,int y1,  int &xEnd,int &yEnd )
00047         {
00048             GridIndices end;
00049             bool isClear = isClearCells( GridIndices(x0,y0), GridIndices(x1,y1), end );
00050             xEnd = end.x; yEnd = end.y;
00051             return isClear;
00052         }
00053 
00059     bool isClearCells( const GridIndices &start, const GridIndices &intendedEnd )
00060         {
00061             return mapRayTracer_.traceCells( start, intendedEnd );
00062         }
00063     bool isClearCells( int x0,int y0,  int x1,int y1 )
00064         { return isClearCells( GridIndices(x0,y0), GridIndices(x1,y1) ); }
00065 
00067     bool isClearWorld( const WorldCoords &start, const WorldCoords &intendedEnd, WorldCoords &actualEnd )
00068         {
00069             GridIndices actualEndIndices;
00070             bool clear = isClearCells( theMap_.gridIndices(start),
00071                                        theMap_.gridIndices(intendedEnd),
00072                                        actualEndIndices );
00073             actualEnd = theMap_.worldCoords( actualEndIndices );
00074             return clear;
00075         }
00076     bool isClearWorld( double x0,double y0,  double x1,double y1,  double &xEnd,double &yEnd )
00077         {
00078             WorldCoords end;
00079             bool isClear = isClearWorld( WorldCoords(x0,y0), WorldCoords(x1,y1), end );
00080             xEnd = end.x; yEnd = end.y;
00081             return isClear;
00082         }
00083 
00085     bool isClearWorld( const WorldCoords &start, const WorldCoords &intendedEnd )
00086         {
00087             return mapRayTracer_.traceCoords( start, intendedEnd );
00088         }
00089     bool isClearWorld( double x0,double y0,  double x1,double y1 )
00090         {
00091             return isClearWorld( WorldCoords(x0,y0), WorldCoords(x1,y1) );
00092         }
00093 
00094 private: 
00095 
00096     // Traces through the map, stops when it hits an occupied cell
00097     class CellTracer {
00098     public:
00099 
00100         CellTracer( const hydroogmap::OgMap &theMap,
00101                     unsigned char occupiedThreshold=hydroogmap::CELL_UNKNOWN )
00102             : theMap_(theMap),
00103               occupiedThreshold_(occupiedThreshold)
00104         {}
00105 
00106         inline bool traceCell(int x, int y)
00107             {
00108                 if ( theMap_.gridCell(x,y) > occupiedThreshold_ )
00109                 {
00110                     // Occupied: stop tracing.
00111                     lastEndX_ = x;
00112                     lastEndY_ = y;
00113                     return false;
00114                 }
00115                 // Keep tracing.
00116                 return true;
00117             }
00118 
00119         inline void traceSucceeded( int x, int y )
00120             { lastEndX_ = x; lastEndY_ = y; }
00121 
00122         inline void traceLeftMap( int x, int y )
00123             { lastEndX_ = x; lastEndY_ = y; }
00124 
00126         int lastEndX() const { return lastEndX_; }
00128         int lastEndY() const { return lastEndY_; }
00129 
00130     private:
00131 
00132         const hydroogmap::OgMap &theMap_;
00133         const unsigned char occupiedThreshold_;
00134 
00135         // The coordinates of the end of the last ray-trace.
00136         int lastEndX_;
00137         int lastEndY_;
00138     };
00139     
00140     const hydroogmap::OgMap &theMap_;
00141     mutable CellTracer       cellTracer_;
00142     MapRayTracer<const OgMap,CellTracer> mapRayTracer_;
00143 };
00144 
00145 }
00146 
00147 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5