00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARIDE_PLAYERHANDLERS_H
00021 #define ARIDE_PLAYERHANDLERS_H
00022
00023 #include <ardev/player.h>
00024
00025 #include "cm_objecthandler.h"
00026 #include "cm_parameter_ardev.h"
00027
00028
00029
00030
00031 class CaptureStage;
00032 class Position3dPlayerHandler;
00033 class PositionPlayerPTZHandler;
00034
00035
00036 class PlayerClientInterfaceHandler : public ArideObjectHandler<PlayerClientInterface>
00037 {
00038 public:
00039 PlayerClientInterfaceHandler() :
00040 ServerName("PlayerServer","Player Server Address","localhost"),
00041 ServerPort("PlayerPort","Player Server Port","6665")
00042 {
00043 PlayerInterface=NULL;
00044 Parameters.push_back(&ServerName);
00045 Parameters.push_back(&ServerPort);
00046 };
00047
00048 virtual ~PlayerClientInterfaceHandler() {delete PlayerInterface;};
00049
00050 PlayerClientInterface & GetObject()
00051 {
00052 if (PlayerInterface == NULL)
00053 {
00054 PlayerInterface = new PlayerClientInterface(ServerName.Value.toAscii(), ServerPort.Value);
00055 if (PlayerInterface == NULL)
00056 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00057 }
00058 CurrentProject->InitialiseObject(PlayerInterface);
00059 return *PlayerInterface;
00060 };
00061 void RemoveObject() { delete PlayerInterface; PlayerInterface = NULL;};
00062
00063 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new PlayerClientInterfaceHandler);};
00064
00065 protected:
00066 StringParameter ServerName;
00067 IntParameter ServerPort;
00068 PlayerClientInterface * PlayerInterface;
00069 };
00070
00071
00072 class CapturePlayerHandler : public CaptureObjectHandler
00073 {
00074 public:
00075 CapturePlayerHandler() :
00076 ServerName("PlayerServer","Player Server Address","localhost"),
00077 ServerPort("PlayerPort","Player Server Port","6665"),
00078 CameraIndex("CameraIndex","Player Camera Index","0")
00079 {
00080 Parameters.push_back(&ServerName);
00081 Parameters.push_back(&ServerPort);
00082 Parameters.push_back(&CameraIndex);
00083 Obj=NULL;
00084 };
00085
00086 virtual ~CapturePlayerHandler() {delete Obj;};
00087
00088 CaptureObject & GetObject()
00089 {
00090 if (Obj == NULL)
00091 {
00092 Obj = new CapturePlayer(ServerName.Value.toAscii(), ServerPort.Value, CameraIndex.Value);
00093 if (Obj == NULL)
00094 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00095 }
00096 CurrentProject->InitialiseObject(Obj);
00097 return *Obj;
00098 };
00099 void RemoveObject() { delete Obj; Obj = NULL;};
00100
00101 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new CapturePlayerHandler);};
00102
00103 protected:
00104 StringParameter ServerName;
00105 IntParameter ServerPort;
00106 IntParameter CameraIndex;
00107 CapturePlayer * Obj;
00108
00109 };
00110
00111
00112 class PlayerClientInterfaceParameter : public ARObjectParameterBase
00113 {
00114 public:
00115 PlayerClientInterfaceParameter(QString _Name, QString _Description, QString _DefaultValue="") : ARObjectParameterBase(_Name,_Description,_DefaultValue) {Type="PlayerClientInterface";};
00116 virtual ~PlayerClientInterfaceParameter() {};
00117
00118 PlayerClientInterfaceHandler * GetClass()
00119 {
00120 if (Value == "")
00121 throw aride_exception(ARDEV_CLASS_NOT_FOUND, __FILE__, __LINE__);
00122 aride_object * temp = CurrentProject->GetObjectByGUID(Value);
00123 if (temp == NULL)
00124 throw aride_exception(ARDEV_CLASS_NOT_FOUND, __FILE__, __LINE__);
00125 if (temp->Section == ARIDE_MISC && temp->Type == "PlayerClientInterface")
00126 return reinterpret_cast<PlayerClientInterfaceHandler *> (temp->Handler);
00127 throw aride_exception(ARDEV_CLASS_NOT_FOUND, __FILE__, __LINE__);
00128 };
00129 };
00130
00131
00132 class PlayerPosition3dParameter : public ARObjectParameterBase
00133 {
00134 public:
00135 PlayerPosition3dParameter(QString _Name, QString _Description, QString _DefaultValue="") : ARObjectParameterBase(_Name,_Description,_DefaultValue) {Type="Position3dPlayer";};
00136 virtual ~PlayerPosition3dParameter() {};
00137
00138 Position3dPlayerHandler * GetClass()
00139 {
00140 if (Value == "")
00141 throw aride_exception(ARDEV_CLASS_NOT_FOUND, __FILE__, __LINE__);
00142 aride_object * temp = CurrentProject->GetObjectByGUID(Value);
00143 if (temp == NULL)
00144 throw aride_exception(ARDEV_CLASS_NOT_FOUND, __FILE__, __LINE__);
00145 if (temp->Section == ARIDE_POSITION && temp->Type == "Position3dPlayer")
00146 return reinterpret_cast<Position3dPlayerHandler *> (temp->Handler);
00147 throw aride_exception(ARDEV_CLASS_NOT_FOUND, __FILE__, __LINE__);
00148 };
00149 };
00150
00151
00152 template<class Base>
00153 class PlayerHandlerBase : public Base
00154 {
00155 public:
00156 PlayerHandlerBase() : PlayerClient("PlayerClient","Player Client Object","")
00157 {
00158 Base::Parameters.push_back(&PlayerClient);
00159 };
00160
00161 virtual ~PlayerHandlerBase() {};
00162
00163 protected:
00164 PlayerClientInterfaceParameter PlayerClient;
00165 };
00166
00167 template <class T, class Base>
00168 class PlayerHandler : public PlayerHandlerBase<Base>
00169 {
00170 public:
00171 PlayerHandler() {Obj=NULL;};
00172 ~PlayerHandler() {delete Obj;};
00173
00174 void RemoveObject() {delete Obj; Obj=NULL;};
00175
00176 protected:
00177 T * Obj;
00178 };
00179
00180
00181 class PositionPlayerHandler : public PlayerHandlerBase<PositionObjectHandler>
00182 {
00183 public:
00184 PositionPlayerHandler() {Obj=NULL;};
00185 ~PositionPlayerHandler() {delete Obj;};
00186
00187 PositionObject & GetObject()
00188 {
00189 if (Obj == NULL)
00190 {
00191 if ((Obj = new PositionPlayer(PlayerClient.GetClass()->GetObject())) == NULL)
00192 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00193 }
00194
00195 CurrentProject->InitialiseObject(Obj);
00196 return *Obj;
00197 }
00198
00199 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new PositionPlayerHandler);};
00200
00201 protected:
00202 PositionPlayer * Obj;
00203 };
00204
00205 class Position3dPlayerHandler : public PlayerHandlerBase<PositionObjectHandler>
00206 {
00207 public:
00208 Position3dPlayerHandler() {Obj=NULL;};
00209 ~Position3dPlayerHandler() {delete Obj;};
00210
00211 PositionObject & GetObject()
00212 {
00213 if (Obj == NULL)
00214 if ((Obj = new PositionPlayer3d(PlayerClient.GetClass()->GetObject())) == NULL)
00215 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00216
00217 CurrentProject->InitialiseObject(Obj);
00218
00219 return *Obj;
00220 }
00221
00222 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new Position3dPlayerHandler);};
00223
00224 protected:
00225 PositionPlayer3d * Obj;
00226
00227 };
00228
00229 class PositionPlayerPTZHandler : public PlayerHandlerBase<PositionObjectHandler>
00230 {
00231 public:
00232 PositionPlayerPTZHandler() {Obj=NULL;};
00233 ~PositionPlayerPTZHandler() {delete Obj;};
00234
00235 PositionObject & GetObject()
00236 {
00237 if (Obj == NULL)
00238 if ((Obj = new PositionPlayerPTZ(PlayerClient.GetClass()->GetObject())) == NULL)
00239 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00240
00241 CurrentProject->InitialiseObject(Obj);
00242
00243 return *Obj;
00244 }
00245
00246 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new PositionPlayerPTZHandler);};
00247
00248 protected:
00249 PositionPlayerPTZ * Obj;
00250
00251 };
00252
00253
00254
00255 class RenderPlayerActArrayHandler : public PlayerHandler<RenderPlayerActArray,RenderObjectHandler>
00256 {
00257 public:
00258 RenderPlayerActArrayHandler() :
00259 Colour("Colour", "Colour","1 0 0 1"),
00260 Index("Index","Index","0")
00261 {
00262 Obj=NULL;
00263 Parameters.push_back(&Colour);
00264 Parameters.push_back(&Index);
00265 };
00266 ~RenderPlayerActArrayHandler()
00267 {
00268 delete Obj;
00269 };
00270
00271
00272 RenderPlayerActArray & GetObject()
00273 {
00274 if (Obj == NULL)
00275 {
00276 if ((Obj = new RenderPlayerActArray(PlayerClient.GetClass()->GetObject(), Colour.Value, Index.Value)) == NULL)
00277 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00278 }
00279
00280 CurrentProject->InitialiseObject(Obj);
00281 BaseObject = Obj;
00282 return *Obj;
00283 };
00284 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00285 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerActArrayHandler);};
00286 protected:
00287 ARColourParameter Colour;
00288 IntParameter Index;
00289
00290 };
00291
00292
00293 class RenderPlayerBumperHandler : public PlayerHandler<RenderPlayerBumper,RenderObjectHandler>
00294 {
00295 public:
00296 RenderPlayerBumperHandler() :
00297 Index("Index","Interface Index","0"),
00298 Height("Height","Bumper Panel Height","0.1")
00299 {
00300 Obj=NULL;
00301 Parameters.push_back(&Index);
00302 Parameters.push_back(&Height);
00303 };
00304 ~RenderPlayerBumperHandler()
00305 {
00306 delete Obj;
00307 };
00308
00309 RenderPlayerBumper & GetObject()
00310 {
00311 if (Obj == NULL)
00312 {
00313 if ((Obj = new RenderPlayerBumper(PlayerClient.GetClass()->GetObject(),Index.Value, Height.Value)) == NULL)
00314 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00315 }
00316
00317 CurrentProject->InitialiseObject(Obj);
00318 BaseObject = Obj;
00319 return *Obj;
00320 };
00321 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00322 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerBumperHandler);};
00323
00324 protected:
00325 IntParameter Index;
00326 DoubleParameter Height;
00327 };
00328
00329
00330
00331 class RenderPlayerIrHandler : public PlayerHandler<RenderPlayerIr,RenderObjectHandler>
00332 {
00333 public:
00334 RenderPlayerIr & GetObject()
00335 {
00336 if (Obj == NULL)
00337 if ((Obj = new RenderPlayerIr(PlayerClient.GetClass()->GetObject())) == NULL)
00338 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00339
00340 CurrentProject->InitialiseObject(Obj);
00341 BaseObject = Obj;
00342 return *Obj;
00343 };
00344 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00345 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerIrHandler);};
00346 };
00347
00348
00349
00350 class RenderPlayerLaserHandler : public PlayerHandler<RenderPlayerLaser,RenderObjectHandler>
00351 {
00352 public:
00353 RenderPlayerLaserHandler() :
00354 Colour("Colour", "Colour","1 0 0 1"),
00355 RayInterval("RayInterval","Ray Interval","20"),
00356 WithOutline("WithOutline","With Outline","true")
00357 {
00358 Obj=NULL;
00359 Parameters.push_back(&Colour);
00360 Parameters.push_back(&RayInterval);
00361 Parameters.push_back(&WithOutline);
00362 };
00363 ~RenderPlayerLaserHandler()
00364 {
00365 delete Obj;
00366 };
00367
00368
00369 RenderPlayerLaser & GetObject()
00370 {
00371 if (Obj == NULL)
00372 {
00373 if ((Obj = new RenderPlayerLaser(PlayerClient.GetClass()->GetObject(), Colour.Value, RayInterval.Value, WithOutline.Value)) == NULL)
00374 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00375 }
00376
00377 CurrentProject->InitialiseObject(Obj);
00378 BaseObject = Obj;
00379 return *Obj;
00380 };
00381 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00382 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerLaserHandler);};
00383 protected:
00384 ARColourParameter Colour;
00385 IntParameter RayInterval;
00386 BooleanParameter WithOutline;
00387
00388 };
00389
00390 class RenderPlayerLimbHandler : public PlayerHandler<RenderPlayerLimb,RenderObjectHandler>
00391 {
00392 public:
00393 RenderPlayerLimbHandler() :
00394 Colour("Colour", "Colour","1 0 0 1"),
00395 Index("Index","Index","0"),
00396 Radius("Radius","Radius","0.05")
00397 {
00398 Obj=NULL;
00399 Parameters.push_back(&Colour);
00400 Parameters.push_back(&Index);
00401 Parameters.push_back(&Radius);
00402 };
00403 ~RenderPlayerLimbHandler()
00404 {
00405 delete Obj;
00406 };
00407
00408
00409 RenderPlayerLimb & GetObject()
00410 {
00411 if (Obj == NULL)
00412 {
00413 if ((Obj = new RenderPlayerLimb(PlayerClient.GetClass()->GetObject(), Colour.Value, Index.Value, Radius.Value)) == NULL)
00414 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00415 }
00416
00417 CurrentProject->InitialiseObject(Obj);
00418 BaseObject = Obj;
00419 return *Obj;
00420 };
00421 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00422 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerLimbHandler);};
00423 protected:
00424 ARColourParameter Colour;
00425 IntParameter Index;
00426 DoubleParameter Radius;
00427
00428 };
00429
00430
00431 class RenderPlayerLocaliseHandler : public PlayerHandler<RenderPlayerLocalise,RenderObjectHandler>
00432 {
00433 public:
00434 RenderPlayerLocalise & GetObject()
00435 {
00436 if (Obj == NULL)
00437 if ((Obj = new RenderPlayerLocalise(PlayerClient.GetClass()->GetObject())) == NULL)
00438 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00439
00440 CurrentProject->InitialiseObject(Obj);
00441 BaseObject = Obj;
00442 return *Obj;
00443 };
00444 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00445 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerLocaliseHandler);};
00446 };
00447
00448
00449 class RenderPlayerMapHandler : public PlayerHandlerBase<RenderObjectHandler>
00450 {
00451 public:
00452 RenderPlayerMapHandler() : Height("Height","Height of map blocks, 0 for 2d","0") {Obj=NULL;Parameters.push_back(&Height);};
00453 ~RenderPlayerMapHandler() {delete Obj;};
00454
00455 RenderPlayerMap & GetObject()
00456 {
00457 if (Obj == NULL)
00458 if ((Obj = new RenderPlayerMap(PlayerClient.GetClass()->GetObject(), Height.Value)) == NULL)
00459 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00460
00461 CurrentProject->InitialiseObject(Obj);
00462 BaseObject = Obj;
00463 return *Obj;
00464 };
00465 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00466 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerMapHandler);};
00467 protected:
00468 RenderPlayerMap * Obj;
00469 DoubleParameter Height;
00470 };
00471
00472
00473 class RenderPlayerPathHandler : public PlayerHandlerBase<RenderObjectHandler>
00474 {
00475 public:
00476 RenderPlayerPathHandler() : Colour("Colour","Path Colour","1 0 0 ") {Obj=NULL;Parameters.push_back(&Colour);};
00477 ~RenderPlayerPathHandler() {delete Obj;};
00478
00479 RenderObject & GetObject()
00480 {
00481 if (Obj == NULL)
00482 if ((Obj = new RenderPlayerPath(PlayerClient.GetClass()->GetObject(),Colour.Value)) == NULL)
00483 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00484
00485 CurrentProject->InitialiseObject(Obj);
00486 BaseObject = Obj;
00487 return *Obj;
00488 }
00489
00490 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00491 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerPathHandler);};
00492
00493 protected:
00494 RenderPlayerPath * Obj;
00495 ARColourParameter Colour;
00496 };
00497
00498 class RenderPlayerPTZHandler : public PlayerHandlerBase<RenderObjectHandler>
00499 {
00500 public:
00501 RenderPlayerPTZHandler() :
00502 Aspect("Aspect","Aspect Ratio","1.3333"),
00503 FOV("FOV","FOV (deg). 0 to read from player","0")
00504 {Obj=NULL;Parameters.push_back(&Aspect);Parameters.push_back(&FOV);};
00505 ~RenderPlayerPTZHandler() {delete Obj;};
00506
00507 RenderObject & GetObject()
00508 {
00509 if (Obj == NULL)
00510 if ((Obj = new RenderPlayerPTZ(PlayerClient.GetClass()->GetObject(),Aspect.Value, FOV.Value*M_PI/180.0)) == NULL)
00511 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00512
00513 CurrentProject->InitialiseObject(Obj);
00514 BaseObject = Obj;
00515 return *Obj;
00516 }
00517
00518 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00519 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerPTZHandler);};
00520
00521 protected:
00522 RenderPlayerPTZ * Obj;
00523 DoubleParameter Aspect;
00524 DoubleParameter FOV;
00525 };
00526
00527 class RenderPlayerSonarHandler : public PlayerHandler<RenderPlayerSonar,RenderObjectHandler>
00528 {
00529 public:
00530 RenderPlayerSonar & GetObject()
00531 {
00532 if (Obj == NULL)
00533 if ((Obj = new RenderPlayerSonar(PlayerClient.GetClass()->GetObject())) == NULL)
00534 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00535
00536 CurrentProject->InitialiseObject(Obj);
00537 BaseObject = Obj;
00538 return *Obj;
00539 };
00540 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00541 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderPlayerSonarHandler);};
00542
00543 };
00544
00545 class RenderGraphics2DHandler : public RenderObjectHandler
00546 {
00547 public:
00548 RenderGraphics2DHandler() {Obj=NULL;};
00549 ~RenderGraphics2DHandler() {delete Obj;};
00550
00551 RenderObject & GetObject()
00552 {
00553 if (Obj == NULL)
00554 if ((Obj = new Graphics2DRenderer) == NULL)
00555 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00556
00557 CurrentProject->InitialiseObject(Obj);
00558 BaseObject = Obj;
00559 return *Obj;
00560 }
00561
00562 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00563 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderGraphics2DHandler);};
00564
00565 protected:
00566 Graphics2DRenderer * Obj;
00567 };
00568
00569 class RenderGraphics3DHandler : public RenderObjectHandler
00570 {
00571 public:
00572 RenderGraphics3DHandler() {Obj=NULL;};
00573 ~RenderGraphics3DHandler() {delete Obj;};
00574
00575 RenderObject & GetObject()
00576 {
00577 if (Obj == NULL)
00578 if ((Obj = new Graphics3DRenderer) == NULL)
00579 throw aride_exception(ARDEV_ALLOC_ERROR,__FUNCTION__,__LINE__);
00580
00581 CurrentProject->InitialiseObject(Obj);
00582 BaseObject = Obj;
00583 return *Obj;
00584 }
00585
00586 void RemoveObject() { delete Obj; Obj = NULL; BaseObject = Obj;};
00587 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderGraphics3DHandler);};
00588
00589 protected:
00590 Graphics3DRenderer * Obj;
00591 };
00592
00593
00594
00595 class CaptureStageHandler : public PlayerHandlerBase<CaptureObjectHandler>
00596 {
00597 public:
00598 CaptureStageHandler();
00599 ~CaptureStageHandler();
00600
00601 CaptureObject & GetObject();
00602 void RemoveObject();
00603
00604 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new CaptureStageHandler);};
00605 protected:
00606 CaptureStage * Capture;
00607 CameraObjectParameter *CameraObject;
00608 PositionObjectParameter *CameraPositionObject;
00609 StringParameter *RobotName;
00610 };
00611
00612
00613
00614
00615 void RegisterPlayerObjectHandlers();
00616
00617 #endif