Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

SfLps.h

00001 //
00002 // SfLps.h
00003 //
00004 // object class definitions for the Local Perceptual Space
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 //
00034 // Artifact abstract class
00035 //
00036 
00037 #ifndef SFLPS_H
00038 #define SFLPS_H
00039 
00040 #undef SFEXPORT
00041 #if defined(MS_WINDOWS) && !defined(SF_STATIC)
00042 #ifdef MAKE_LIBRARY
00043 #define _declspec( dllexport )
00044 #else
00045 #define _declspec( dllimport )
00046 #endif
00047 #else
00048 #define SFEXPORT
00049 #endif
00050 
00053 
00064 class SfArtifact : public SfDrawable // abstract class
00065 {
00066  public:
00068   ArPose p;                     // where the point is
00069 
00070   typedef enum                  // what we are
00071     { 
00072       Robot, 
00073       Point, 
00074       Wall,  
00075       Wallset, 
00076       Corridor, 
00077       Goal 
00078     } Type;
00079   Type type;
00080   
00081   int id;                       // ID for general access
00082   int newflags;                 // new flags, for routines that need to know
00084   void draw(SfWin *w) {}        // by default we don't draw
00085   void print() {}
00086                                 // move incrementally using a pose
00087   void moveObj(ArPose *q) { p.setX(q->getX() + p.getX()); p.setY(q->getY() + p.getY()); 
00088                          p.setTh(p.getTh() + q->getTh()); 
00089                          newflags = -1; }
00090                                 // move incrementally using three numbers
00091   void moveObj(double x, double y, double th) 
00092     { p.setX(p.getX()+x); p.setY(p.getY()+y); 
00093       p.setTh(p.getTh() + th); newflags = -1; }
00095   SfArtifact(); // constructor, should add to arts
00097   virtual ~SfArtifact(); // deconstructor, removes from list
00098  private:
00099  static int newid;
00100 };
00101 
00102 //
00103 // Artifacts of different types
00104 //
00105 
00106 
00109 //  has size, should add color
00110 //
00111 class SfRobot : public ArRobot, public SfArtifact
00112 {
00113  public:
00114   SfRobot();            // constructor with no arguments 
00115   virtual ~SfRobot() {}
00116 
00117   void print() {}
00118   void draw(SfWin *w);  // draws the robot
00119 
00120 };
00121 
00122 
00125 class SfPoint : public SfArtifact
00126 {
00127  public:
00129   SfPoint(double x, double y, double th)  // constructor
00130     { p.setX(x); p.setY(y); p.setTh(th);  type = Point; }
00132   SfPoint()                     // constructor with no arguments
00133     { p.setX(0); p.setY(0); p.setTh(0);  type = Point; }
00134   void print() {}
00135   void draw(SfWin *w);          // draws a circle
00137   virtual ~SfPoint() {}
00138 };
00139 
00142 class SfGoal : public SfArtifact
00143 {
00144  public:
00146   SfGoal(double x, double y, double th, const char *name, bool useHeading)  // constructor
00147     { p.setX(x); p.setY(y); p.setTh(th);  type = Goal; myName = name; myUseHeading = useHeading; }
00149   SfGoal()                      // constructor with no arguments
00150     { p.setX(0); p.setY(0); p.setTh(0);  type = Goal; myUseHeading = false; }
00151   void print() {}
00152   ArPose getPose(void) { return p; }
00153   bool useHeading(void) { return myUseHeading; }
00154   const char *getName(void) { return myName.c_str(); };
00155   void draw(SfWin *w);          // draws a circle
00157   virtual ~SfGoal() {}
00158 private:
00159   std::string myName;
00160   bool myUseHeading;
00161 };
00162 
00163 
00165 class SfCorridor : public SfArtifact
00166 {
00167  public:
00169   SfCorridor(double x, double y, double th, double w, double l) // constructor
00170     { p.setX(x); p.setY(y); p.setTh(th); width = w; length = l; type = Corridor; }
00172   SfCorridor()                  // constructor with no arguments
00173     { p.setX(0); p.setY(0); p.setTh(0); width = 0; length = 0; type = Corridor; }
00175   virtual ~SfCorridor() {}
00177   double width, length;         // width and length of corridor
00178   void print() {}
00179   void draw(SfWin *w);
00180 };
00181 
00182 
00183 
00185 class SfWall : public SfArtifact
00186 {
00187  public:
00189   SfWall(double x1, double y1, double x2, double y2) // constructor using vector
00190     { 
00191       v.x1 = x1; v.x2 = x2; v.y1 = y1; v.y2 = y2;
00192       length = makeWall(&p,x1,y1,x2,y2);
00193       type = Wall;
00194     }
00196   SfWall()                      // constructor with no arguments
00197     { 
00198       v.x1 = v.x2 = v.y1 = v.y2 = 0;
00199       length = makeWall(&p,0,0,0,0);
00200       type = Wall;
00201     }
00203   virtual ~SfWall() {}
00205   double length;                // length of wall
00207   SfVector v;                   // vector representation
00208   void print() { }
00209   void draw(SfWin *w); 
00210 
00211  private:
00212   double makeWall(ArPose *p, double x1, double y1, double x2, double y2);
00213 };
00214 
00215 
00216 //
00217 // Wall set: point is moment center, maybe?
00218 //
00219 
00220 class SfWallset : public SfArtifact
00221 {
00222  public:
00223   SfVector *walls;              // wall vectors
00224   int n;                        // length
00225   virtual ~SfWallset () {}
00226   SfWallset(double x, double y, double th, int n) // constructor
00227     { p.setX(x); p.setY(y); p.setTh(th); walls = new SfVector[n]; type = Wallset; }
00228   SfWallset(int n)                      // constructor with no arguments
00229     { p.setX(0); p.setY(0); p.setTh(0); walls = new SfVector[n]; type = Wallset; }
00230   void print() {}
00231   void draw(SfWin *w) 
00232     { 
00233     }
00234 };
00235 
00236 
00237 //
00238 // Artifact lists
00239 // First one created is default, but can be reset
00240 //
00241 
00243 #define SfARTIFACTS SfArtifactList::current()
00244 
00245 
00247 
00256 class SfArtifactList : public SfDrawable
00257 {
00258  public:
00260   static SfArtifactList *current(); // returns default list
00261   static void current(SfArtifactList *a); // sets default list
00262   SfArtifactList();// constructor
00263   virtual  ~SfArtifactList() {};        // destructor
00264   void draw(SfWin *w);          // drawing fn
00265   void add(SfArtifact *a)       // add onto list
00266     { arts->push_front(a); }
00267   void remove(SfArtifact *a)    // remove from list
00268     { arts->remove(a); }
00269   void RemoveWalls();  // remove all walls, i.e., remove a world
00270   void SetOrigin(double x, double y); // keep the same width, height
00271   void SetWidth(double w)
00272     { bounds.x2 = bounds.x1+w; }
00273   void SetHeight(double h)
00274   { bounds.y2 = bounds.y1+h; }
00277   SfVector &Bounds(void)
00278     { return bounds; }
00279   std::list<SfArtifact *> *Artifacts() // returns artifact list
00280     { return arts; }
00281 
00282  private:
00283   static SfArtifactList *_current; // pointer to current default
00284   std::list<SfArtifact *> *arts;        // list of artifacts
00285   SfVector bounds;              // bounding box of artifacts
00286 };
00287 
00288 
00291 ArPose *sfLoadWorldFile(char *name);  
00293 void sfRemoveWorld();   
00294 
00295 //
00296 // Geometry classes, useful for working with artifacts
00297 //
00298 
00299 // general coordinate system transform
00300 // can be set by two points or an origin and angle
00301 // transforms between global coordinate system and itself
00302 // not sure what this is going to be used for...
00303 //
00304 
00305 class SfVectorSystem : public SfVector, public ArPose
00306 
00307 {
00308  public:
00309   SfVectorSystem(SfVector &v) { Set(v); };
00310   SfVectorSystem(ArPose &p) { Set(p); };
00311   void Set(SfVector &v);
00312   void Set(ArPose &p);
00313   void ToLocal(double &x, double &y) 
00314     { x-=x1; y-=y1; double temp = x; x = cs*x + sn*y; y = cs*y - sn*temp;};
00315   void ToGlobal(double &x, double &y)
00316     { double temp = x; x = cs*x - sn*y; y = cs*y + sn*temp; x+=x1; y+=y1;};
00317  private:
00318   double sn, cs;
00319 };
00320 
00321 
00322 #endif // SFLPS_H

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