Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

SfGrid.h

00001 //
00002 // SfGrid.h
00003 //
00004 // grid class definitions
00005 
00006 //
00007 // Copyright 1999 by Kurt Konolige
00008 //
00009 // The author hereby grants to SRI permission to use this software.
00010 // The author also grants to SRI permission to distribute this software
00011 // to schools for non-commercial educational use only.
00012 //
00013 // The author hereby grants to other individuals or organizations
00014 // permission to use this software for non-commercial
00015 // educational use only.  This software may not be distributed to others
00016 // except by SRI, under the conditions above.
00017 //
00018 // Other than these cases, no part of this software may be used or
00019 // distributed without written permission of the author.
00020 //
00021 // Neither the author nor SRI make any representations about the 
00022 // suitability of this software for any purpose.  It is provided 
00023 // "as is" without express or implied warranty.
00024 //
00025 // Kurt Konolige
00026 // Senior Computer Scientist
00027 // SRI International
00028 // 333 Ravenswood Avenue
00029 // Menlo Park, CA 94025
00030 // E-mail:  konolige@ai.sri.com
00031 //
00032 
00033 #ifndef SFGRID_H
00034 #define SFGRID_H
00035 
00036 #undef SFEXPORT
00037 #if defined(MS_WINDOWS) && !defined(SF_STATIC)
00038 #ifdef MAKE_LIBRARY
00039 #define _declspec( dllexport )
00040 #else
00041 #define _declspec( dllimport )
00042 #endif
00043 #else
00044 #define SFEXPORT
00045 #endif
00046 
00047 
00048 
00049 // SfCellIndex class
00050 // This class forms the basis for any grid class, with indexing services
00051 //   for 2D cell arrays
00052 //
00053 
00054 class SfCellIndex
00055 {
00056  public:
00057   SfCellIndex();
00058   virtual ~SfCellIndex();
00059 
00060   int getGridRes()              // return grid resolution (mm)
00061     { return (int)gridres; }
00062   virtual bool setGridRes(int res); // set grid resolution (mm) 
00063 
00064   bool InBounds(double, double); // return TRUE if we're in bounds of the grid
00065 
00066   void setSize(SfVector &s); // sets the size of the grid area
00067   int xsize, ysize;             // number of cells in each dimension
00068   SfVector size;                // RW area of grid space, as rectangle
00069   double gridres, igridres;     // grid cell size, in mm, plus inverse; should be private
00070 
00071   int grid_index(double, double); // returns index of RW point
00072   bool grid_coords(double, double, int *, int *); // sets grid coords from RW
00073 
00074   bool rw_coords(int, int, double *, double *); // sets RW coords from grid 
00075   bool in_bounds(int, int); // returns TRUE if in bounds, else FALSE
00076 };
00077 
00078 // Ray class
00079 
00080 class SfRay
00081 {
00082 public:
00083   SfRay(double angle, double gridres, double len, int width); 
00084   // ray angle, length, resolution; width of grid in pixels
00085   int num;                      // number of cell addresses
00086   int *addr;                    // relative addresses for this ray
00087   double *dd;                   // distance to this index
00088 };
00089 
00090 // Point array class
00091 
00092 class SfPtArray
00093 {
00094 public:
00095   SfPtArray(double angle, int n);
00096   void SfPtArray::Set(double *xb, double *yb, int np, double gridres, int width);
00097   double cs, sn;                // rotation angle of this pt array (rads)
00098   int num;                      // number of cell addresses
00099   int *addr;                    // relative addresses for this pt array
00100 };
00101 
00102 
00103 //
00104 // Grid class
00105 // Grids are 2D byte arrays; nominally, a value of 100 represents 
00106 //   a probability of 1.0
00107 //
00108 
00109 class SfGrid : public SfDrawable, public SfCellIndex
00110 {
00111 public:
00112   SfGrid();             // default constructor
00113   virtual ~SfGrid();    // destructor
00114   void CreateGrid(double res, SfVector *size = NULL,
00115                            SfArtifactList * = NULL, double margin = 0.0);
00116   void AddSegment(SfWall *w);   // add a wall segment to the grid map
00117    void AddSegments(SfArtifactList *);  // add all wall segments in a list
00118    void EraseGrid();            // erases the grid
00119    void SmearGrid(double smear = -1); // does grid smearing 
00120    void Threshold(int thresh);  // threshold the grid
00121    void MoveGrid(double gx, double gy); // move grid to this lower-left position
00122 
00123   int GridSmearDist()           // return grid smear distance (mm)
00124     { return (int)gridsmear; }
00125   bool GridSmearDist(int smear); // set grid smear distance (mm) and smear it
00126 
00127   virtual bool setGridRes(int res); // set grid resolution (mm) and recreate it
00128   int GridMaxVal()              // return max grid value
00129     { return gridmax; }
00130   bool GridMaxVal(int v);       // set max value
00131 
00132   unsigned char GridVal(double, double); // grid value at these RW coords
00133   void GridVal(double, double, int v); // set value at these coords
00134   void IncGridVal(double, double, int v); // increment grid value at these coords
00135   bool SetBounds(ArPose &p, double near, double place); // reset to in bounds
00136 
00137   void CreateRays(int num, double len); // create ray addresses
00138   double NearDist(double x, double y, double th); // distance to nearest wall
00139   void CreatePtArrays(int num, int np); 
00140   void SetPtArrays(double *xb, double *yb, int np); 
00141   unsigned char *grid, *ogrid;  // holds map grid
00142 
00144 
00145   bool displaySmear, displayGrid, displayArtifacts; // whether we display these
00146 
00147   // drawing 
00148   void draw(SfWin *w);  // draw artifacts and smear 
00149   double tx, ty, tth;           // test pt array drawing
00150 
00151   // loading a scanstudio map file
00152   void LoadScanMap(char *name);
00153 
00154 protected:
00155   SfArtifactList *alist;        // current artifact list for grid creation
00156   int msize;                    // margin size, for accesses out of bounds
00157   double gridsmear;             // how much we smear out the map
00158   int gridmax;                  // max value for grid, nominally 100
00159   
00160   // ray storage
00161   double angleres;              // ray angle resolution, in rads
00162   int anglenum;
00163   SfRay **angles;               // ray angle buffers
00164 
00165   // rotated point array storage
00166   double rotres;                // rotation angle resolution (rads)
00167   int rotnum;                   // number of angles
00168   SfPtArray **pts;              // point arrays
00169 };
00170 
00171 #endif  // SFGRID_H

Generated on Tue Nov 12 17:49:34 2002 for Saphira by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001