player.h

00001 /* -- 2007-05-07 -- 
00002  *  ardev - an augmented reality library for robot developers
00003  *  Copyright 2005-2007 - Toby Collett (ardev _at_ plan9.net.nz)
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Lesser General Public
00016  *  License along with this library; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00018  *
00019  */
00020 //
00021 // File: ./include/ardev/player.h
00022 // Created by: User <Email>
00023 // Created on: Mon May 10 16:36:21 2004
00024 //
00025 
00026 #ifndef _ARDEV_PLAYER_H_
00027 #define _ARDEV_PLAYER_H_
00028 
00029 #include <ardev/ardevconfig.h>
00030 #include <ardev/ardev.h>
00031 
00032 #ifdef HAVE_PLAYER
00033 
00034 #undef signals
00035 #include <libplayerc++/playerc++.h>
00036 
00037 #include <deque>
00038 
00039 using namespace PlayerCc;
00040 using namespace std;
00041 
00042 
00050 class PlayerObject
00051 {
00052         public:
00053                 PlayerObject() {};
00054                 virtual ~PlayerObject() {};
00055         
00056                 virtual void PlayerInit(PlayerClient * pci) = 0;
00057                 virtual void PlayerTerm() = 0;
00058 };
00059 
00060 
00066 class PlayerClientInterface : public ARObject
00067 {
00068         public:
00070                 PlayerClientInterface(const char * PlayerServer="localhost", int PlayerPort=6665);
00071         
00073                 ~PlayerClientInterface();
00074         
00076                 int Initialise(bool Active = true);
00077         
00079                 void Terminate();
00080                 
00082                 void * Main();
00083         
00085                 PlayerClient * GetPlayerClient() {return Robot;};
00086         
00088                 void AddChild(PlayerObject & NewChild);
00089                 
00091                 void RemoveChild(PlayerObject & Child);
00092                 
00093         protected:
00094                 bool Connecting;
00095                 char * PlayerServer;
00096                 int PlayerPort;
00097                 PlayerClient * Robot;
00098                 list<PlayerObject *> Children;
00099                 //bool Connected;
00100 };
00101 
00102 
00103 
00106 class PositionPlayer3d : public PositionObject, public PlayerObject
00107 {
00108         public:
00110                 PositionPlayer3d(PlayerClientInterface & pci);
00112                 virtual ~PositionPlayer3d();
00113                 
00115                 int Initialise(bool Active = true);
00116                  
00118                 void Terminate();
00119         
00121                 ARPosition GetPosition();
00122         
00124                 void PlayerInit(PlayerClient * pci);
00126                 void PlayerTerm();
00127         
00128         protected:
00129                 // PositionPlayer variables
00130         
00131                 PlayerClientInterface * PlayerInterface; 
00132                 Position3dProxy * Position;     
00133                 ARPosition Pos; 
00134 };
00135 
00138 class PositionPlayer : public PositionObject, public PlayerObject
00139 {
00140         public:
00142                 PositionPlayer(PlayerClientInterface & pci);
00144                 virtual ~PositionPlayer();
00146                 int Initialise(bool Active = true);
00148                 void Terminate();
00150                 ARPosition GetPosition();
00151 
00153                 void PlayerInit(PlayerClient * pci);
00155                 void PlayerTerm();
00156         
00157         protected:
00158                 // PositionPlayer variables
00159         
00160                 PlayerClientInterface * PlayerInterface; 
00161                 Position2dProxy * Position; 
00162                 ARPosition Pos; 
00163 };
00164 
00165 
00172 class PositionPlayerPTZ : public PositionObject, public PlayerObject
00173 {
00174         public:
00176                 PositionPlayerPTZ(PlayerClientInterface & pci);
00178                 virtual ~PositionPlayerPTZ();
00180                 int Initialise(bool Active = true);
00182                 void Terminate();
00183 
00185                 ARPosition GetPosition();
00186 
00188                 void PlayerInit(PlayerClient * pci);
00190                 void PlayerTerm();
00191         
00192         protected:
00193                 PlayerClientInterface * PlayerInterface; 
00194                 PtzProxy * Position; 
00195                 ARPosition Pos; 
00196 };
00197 
00198 
00201 class RenderPlayerActArray : public RenderObject, public PlayerObject
00202 {
00203         public:
00205                 RenderPlayerActArray(PlayerClientInterface & pci, const ARColour & aColour, int Index = 0, double Width = 0.05);
00207                 virtual ~RenderPlayerActArray();
00208 
00210                 int Initialise(bool Active = true);
00212                 void Terminate();
00213 
00215                 void PlayerInit(PlayerClient * pci);
00217                 void PlayerTerm();
00218 
00220                 void Render();
00221                 
00223                 void RenderTransparent();
00224                 
00225         private:
00226                 PlayerClientInterface * PlayerInterface; 
00227                 ActArrayProxy * Proxy; 
00228                 int Index; 
00229                 
00230                 double Width; 
00231 };
00232 
00235 class RenderPlayerBumper : public RenderObject, public PlayerObject
00236 {
00237         public:
00239                 RenderPlayerBumper(PlayerClientInterface & pci, int Index = 0, double Height = 0.1);
00241                 virtual ~RenderPlayerBumper();
00242 
00244                 int Initialise(bool Active = true);
00246                 void Terminate();
00247 
00249                 void PlayerInit(PlayerClient * pci);
00251                 void PlayerTerm();
00252 
00254                 void RenderTransparent();
00255                 
00256         private:
00257                 PlayerClientInterface * PlayerInterface; 
00258                 BumperProxy * Bumper; 
00259                 player_bumper_geom_t BumperGeom; 
00260                 
00261                 double Height; 
00262 };
00263 
00264 
00267 class RenderPlayerIr : public RenderObject, public PlayerObject
00268 {
00269         public:
00271                 RenderPlayerIr(PlayerClientInterface & pci);
00273                 virtual ~RenderPlayerIr();
00274 
00276                 int Initialise(bool Active = true);
00278                 void Terminate();
00279 
00281                 void PlayerInit(PlayerClient * pci);
00283                 void PlayerTerm();
00284 
00285                 void RenderTransparent(); 
00286                 
00287         private:
00288                 PlayerClientInterface * PlayerInterface; 
00289                 IrProxy * Ir; 
00290 };
00291 
00294 class RenderPlayerLaser : public RenderObject, public PlayerObject
00295 {
00296         public:
00301                 RenderPlayerLaser(PlayerClientInterface & pci, const ARColour & aColour, int aRayInterval = 20, bool aWithOutline = true);
00302                 virtual ~RenderPlayerLaser(); 
00303 
00305                 int Initialise(bool Active = true);
00307                 void Terminate();
00308 
00310                 void PlayerInit(PlayerClient * pci);
00312                 void PlayerTerm();
00313 
00314 
00315                 void RenderTransparent(); 
00316 
00317                 void Render(); 
00318 
00319                 virtual double TraceDistance(const Ray & Offset, const Ray & R, const ARPoint & Rotation);
00320         
00321                 
00322         private:
00323                 PlayerClientInterface * PlayerInterface; 
00324                 LaserProxy * Laser; 
00325 
00326                 double MaxRange;
00327                 player_pose_t pose;
00328                 
00329                 bool WithOutline;
00330                 int RayInterval;
00331 };
00332 
00335 class RenderPlayerLimb : public RenderObject, public PlayerObject
00336 {
00337         public:
00339                 RenderPlayerLimb(PlayerClientInterface & pci, const ARColour & aColour, int Index = 0, double Radius = 0.05);
00341                 virtual ~RenderPlayerLimb();
00342 
00344                 int Initialise(bool Active = true);
00346                 void Terminate();
00347 
00349                 void PlayerInit(PlayerClient * pci);
00351                 void PlayerTerm();
00352 
00354                 void Render();
00355                 
00357                 void RenderTransparent();
00358                 
00359         private:
00360                 PlayerClientInterface * PlayerInterface; 
00361                 LimbProxy * Proxy; 
00362                 int Index; 
00363                 player_limb_geom_req_t Geom; 
00364                 
00365                 double Radius; 
00366 };
00367 
00372 class RenderPlayerLocalise : public RenderObject, public PlayerObject
00373 {
00374         public:
00376                 RenderPlayerLocalise(PlayerClientInterface & pci);
00377                 virtual ~RenderPlayerLocalise(); 
00378 
00380                 int Initialise(bool Active = true);
00382                 void Terminate();
00383 
00385                 void PlayerInit(PlayerClient * pci);
00387                 void PlayerTerm();
00388         
00389                 //void Render(); ///< Render the map in GL
00390                 void RenderTransparent(); 
00391         
00392         protected:
00393                 PlayerClientInterface * PlayerInterface; 
00394                 LocalizeProxy * Proxy; 
00395 
00396 };
00397 
00402 class RenderPlayerMap : public RenderObject, public PlayerObject
00403 {
00404         public:
00406                 RenderPlayerMap(PlayerClientInterface & pci, double _Height = 0);
00407                 virtual ~RenderPlayerMap(); 
00408 
00410                 int Initialise(bool Active = true);
00412                 void Terminate();
00413 
00415                 void PlayerInit(PlayerClient * pci);
00417                 void PlayerTerm();
00418 
00419         
00420                 //void Render(); ///< Render the map in GL
00421                 void RenderTransparent(); 
00422         
00423         protected:
00424                 PlayerClientInterface * PlayerInterface; 
00425                 MapProxy * Proxy; 
00426                 double Height; 
00427                 int GlList;
00428 };
00429 
00434 class RenderPlayerPath : public RenderObject, public PlayerObject
00435 {
00436         public:
00438                 RenderPlayerPath(PlayerClientInterface & pci,ARColour & _Colour);
00439                 virtual ~RenderPlayerPath(); 
00440 
00442                 int Initialise(bool Active = true);
00444                 void Terminate();
00445 
00447                 void PlayerInit(PlayerClient * pci);
00449                 void PlayerTerm();
00450 
00452                 unsigned int GetHistoryLength() const {return HistoryLength;};
00454                 void SetHistoryLength(const unsigned int NewHistoryLength) {HistoryLength = NewHistoryLength;};
00455         
00456                 void Render(); 
00457                 void RenderTransparent(); 
00458         
00459         protected:
00460                 PlayerClientInterface * PlayerInterface; 
00461                 Position2dProxy * Position; 
00462 
00463                 deque<ARPoint> Points; 
00464         
00465                 unsigned int HistoryLength; 
00466         
00467 };
00468 
00473 class RenderPlayerPTZ : public RenderObject, public PlayerObject
00474 {
00475         public:
00477                 RenderPlayerPTZ(PlayerClientInterface & pci,double _aspect=1.333, double _fov=0);
00478                 virtual ~RenderPlayerPTZ(); 
00479 
00481                 int Initialise(bool Active = true);
00483                 void Terminate();
00484 
00486                 void PlayerInit(PlayerClient * pci);
00488                 void PlayerTerm();
00489 
00490         
00491                 void Render(); 
00492                 void RenderTransparent(); 
00493         
00494         protected:
00495                 PlayerClientInterface * PlayerInterface; 
00496                 PtzProxy * Proxy; 
00497 
00498                 double aspect; 
00499                 double fov; 
00500         
00501 };
00502 
00505 class RenderPlayerSonar : public RenderObject, public PlayerObject
00506 {
00507         public:
00509                 RenderPlayerSonar(PlayerClientInterface & pci, int Index = 0);
00511                 virtual ~RenderPlayerSonar();
00512 
00514                 int Initialise(bool Active = true);
00516                 void Terminate();
00517 
00519                 void PlayerInit(PlayerClient * pci);
00521                 void PlayerTerm();
00522 
00524                 void RenderTransparent();
00525                 
00526         private:
00527                 PlayerClientInterface * PlayerInterface; 
00528                 SonarProxy * Sonar; 
00529 };
00530 
00536 class CaptureStage : public CaptureObject, public PlayerObject
00537 {
00538         public:
00539                 //CaptureStage() {pCamera = NULL; Position = NULL; Open=false; TheMap = -1;};
00541                 CaptureStage(const char * RobotName, CameraObject * camera, PositionObject * CameraPosition, PlayerClientInterface & _PlayerInterface);
00543                 virtual ~CaptureStage();
00544 
00546                 int Initialise(bool Active = true);
00548                 void Terminate();
00549 
00551                 void PlayerInit(PlayerClient * pci);
00553                 void PlayerTerm();
00554 
00556                 virtual const ARImage & GetFrame();
00558                 int GetMaxWidth();
00560                 int GetMaxHeight();
00561                         
00562         protected:
00564                 bool Open;
00565                 ARImage Frame; 
00566                 CameraObject * pCamera; 
00567                 PositionObject * pCameraPosition; 
00568                 int TheMap; 
00569                 void drawMap(); 
00570                 char * RobotName;
00571                 
00572                 // player client objects
00573                 PlayerClientInterface * PlayerInterface; 
00574                 SimulationProxy * Position; 
00575                 MapProxy * Map; 
00576 };
00577 
00578 
00584 class CapturePlayer : public CaptureObject
00585 {
00586         public:
00589                 CapturePlayer(const char * PlayerServer="localhost", int PlayerPort=6665, int CameraIndex = 0);
00591                 virtual ~CapturePlayer();
00592 
00594                 void * Main();
00595 
00597                 int Initialise(bool Active = true);
00599                 void Terminate();
00600 
00602                 void PlayerInit(PlayerClient * pci);
00604                 void PlayerTerm();
00605 
00607                 virtual const ARImage & GetFrame();
00609                 int GetMaxWidth();
00611                 int GetMaxHeight();
00612                         
00613         protected:
00615                 bool Open;
00616                 ARImage Frame; 
00617                 bool fresh;
00618                 
00619                 // player client objects
00620                 PlayerClient * Robot; 
00621                 CameraProxy * Camera; 
00622 };
00623 
00625 // The classes needed for the graphics2d render object
00627 class GraphicsElement
00628 {
00629         public:
00630                 GraphicsElement() {Type = 0;Filled = false;};
00631         
00632                 uint32_t Type;
00633                 double r,g,b,a;
00634                 double fr,fg,fb,fa;
00635                 bool Filled;
00636                 vector<player_point_2d_t> Points;
00637 };
00638 
00639 class Graphics2DRenderer : public RenderObject
00640 {
00641         public:
00642                 Graphics2DRenderer() {;};
00643                 ~Graphics2DRenderer() {;};
00644         
00645                 void Render();
00646                 void RenderTransparent();
00647                 
00648                 vector<GraphicsElement> Elements;
00649                 
00650 
00651 };
00652 
00653 class Graphics3DRenderer : public RenderObject
00654 {
00655         public:
00656                 Graphics3DRenderer() {;};
00657                 ~Graphics3DRenderer() {Clear();};
00658         
00659                 void Clear()
00660                 {
00661                         for (vector<player_graphics3d_cmd_draw_t *>::const_iterator itr = Elements.begin(); itr != Elements.end(); ++itr)
00662                         {
00663                                 delete *itr;    
00664                         }
00665                         Elements.clear();
00666                 }
00667         
00668                 void RenderOne(player_graphics3d_cmd_draw_t & item);
00669 
00670                 void Render();
00671                 void RenderTransparent();
00672                 
00673                 vector<player_graphics3d_cmd_draw_t *> Elements;
00674                 
00675 
00676 };
00677 
00678 #endif  // HAVE_PLAYER
00679 #endif  // _ARDEV_PLAYER_H_

SourceForge.net Logo Generated on Sat May 12 15:25:43 2007 for ardev by doxygen 1.5.1