cm_objecthandler.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 #include <ardev/ardevconfig.h>
00021 #include <stdlib.h>
00022 
00023 #ifndef ARIDE_OBJECTHANDLER_H
00024 #define ARIDE_OBJECTHANDLER_H
00025 
00026 #include <QString>
00027 
00028 #include <ardev/ardev.h>
00029 
00030 #include <vector>
00031 using namespace std;
00032 
00033 #include "cm_registry.h"
00034 #include "cm_parameter.h"
00035 #include "cm_parameter_ardev.h"
00036 
00037 
00038 
00039 class ObjectHandler
00040 {
00041         public:
00042                 ObjectHandler() : Name("Name","ObjectName",""),
00043                         Enabled("Enabled","Enable Object","True")
00044                 {
00045                         Parameters.push_back(&Name);
00046                         Parameters.push_back(&Enabled);
00047                 };
00048                 virtual ~ObjectHandler() {};
00049         
00050                 virtual void RemoveObject() {}; // destroys current object if it exists, re implement if the class supports the get object method
00051                 QString Type;   
00052                 list<Parameter * > Parameters;  
00053                 
00054                 NameParameter Name;
00055                 BooleanParameter Enabled;
00056                 virtual void SetEnabled (const bool) {};
00057 
00058                 virtual void update() 
00059                 {
00060                         for (list<Parameter * >::iterator itr = Parameters.begin(); itr != Parameters.end(); ++itr)
00061                         {
00062                                 (*itr)->update();
00063                         }       
00064                 };
00065 };
00066 
00067 
00068 template <class T>
00069 class ArideObjectHandler : public ObjectHandler
00070 {
00071         public:
00072                 ArideObjectHandler() {};
00073                 virtual ~ArideObjectHandler() {};
00074                 virtual T & GetObject()=0; // returns current object creates if necessary
00075 };
00076 
00077 typedef ArideObjectHandler<CameraObject> CameraObjectHandler;
00078 typedef ArideObjectHandler<CaptureObject> CaptureObjectHandler;
00079 typedef ArideObjectHandler<OutputObject> OutputObjectHandler;
00080 typedef ArideObjectHandler<PositionObject> PositionObjectHandler;
00081 //typedef ArideObjectHandler<RenderObject> RenderObjectHandler;
00082 typedef ArideObjectHandler<FrameProcessObject> FrameProcessObjectHandler;
00083 
00084 
00085 class RenderObjectHandler : public ArideObjectHandler<RenderObject>
00086 {
00087         public:
00088                 RenderObjectHandler() {BaseObject = NULL;};
00089                 virtual void SetEnabled (const bool state) {if(BaseObject) BaseObject->SetEnabled(state);};
00090                 
00091                 RenderObject * BaseObject;
00092 };
00093 
00094 /* ---------------------------------------------
00095     Handlers for environment and render pair
00096    --------------------------------------------- */
00097 
00098 /*class RenderPairObjectHandler : public ObjectHandler
00099 {
00100         public:
00101                 RenderPairObjectHandler();
00102                 ~RenderPairObjectHandler();     
00103                         
00104                 RenderObjectParameter *Render;
00105                 PositionObjectParameter *Pos;
00106 };*/
00107 
00108 class EnvironmentObjectHandler : public ObjectHandler
00109 {
00110         public:
00111                 EnvironmentObjectHandler();
00112                 ~EnvironmentObjectHandler();    
00113                         
00114                 OutputObjectParameter * Out;
00115                 CameraObjectParameter * Cam;
00116                 CaptureObjectParameter * Cap;
00117 };
00118 
00119 /* ---------------------------------------------
00120     Default Objects (such as constant and null)
00121    --------------------------------------------- */
00122 
00123 template<class T,class Base>
00124 class NullHandler : public Base
00125 {
00126         public:
00127                 NullHandler() {};
00128 
00129                 T & GetObject() {CurrentProject->InitialiseObject(&obj);return obj;};
00130                 void RemoveObject() {};
00131                 
00132                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new NullHandler<T,Base>);};
00133                 
00134         protected:
00135                 T obj;
00136 };
00137 
00138 //typedef NullHandler<CameraConstant,CameraObjectHandler> CameraConstantHandler;
00139 typedef NullHandler<CaptureNull,CaptureObjectHandler> CaptureNullHandler;
00140 //typedef NullHandler<OutputNull,OutputObjectHandler> OutputNullHandler;
00141 typedef NullHandler<PositionNull,PositionObjectHandler> PositionNullHandler;
00142 //typedef NullHandler<RenderNull,RenderObjectHandler> RenderNullHandler;
00143 
00144 
00145 /* -------------------------------------
00146     Camera Objects, ie file and v4l
00147    ------------------------------------- */
00148 class CameraConstant;
00149 
00150 class CameraConstantHandler : public CameraObjectHandler
00151 {
00152         public:
00153                 CameraConstantHandler();
00154                 ~CameraConstantHandler();
00155         
00156                 CameraObject & GetObject();
00157                 void RemoveObject();
00158         
00159                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new CameraConstantHandler);};
00160         protected:
00161                 CameraConstant * Camera;
00162                 DoubleParameter * y_fov;
00163                 DoubleParameter * aspect;
00164                 DoubleParameter * SensorWidth;
00165                 StringParameter * CalibrationFile;
00166                 ARPointParameter * Origin;
00167                 ARPointParameter * Direction;
00168                 ARPointParameter * Up;
00169 };
00170 
00171 /* --------------------------------------------
00172     Output (X11/mpeg) Object Handlers
00173    -------------------------------------------- */
00174 class OutputX11;
00175 class OutputMovie;
00176 
00177 class OutputX11Handler : public OutputObjectHandler
00178 {
00179         public:
00180                 OutputX11Handler();
00181                 ~OutputX11Handler();
00182         
00183                 OutputObject & GetObject();
00184                 void RemoveObject();
00185         
00186                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new OutputX11Handler);};
00187         protected:
00188                 OutputX11 * Obj;
00189         
00190                 CameraObjectParameter * Cam;
00191                 PositionObjectParameter * CamPos;
00192                 CaptureObjectParameter * Cap;
00193                 IntParameter * Width;
00194                 IntParameter * Height;
00195                 StringParameter * DisplayName;
00196                 BooleanParameter * FullScreen;
00197 };
00198 #ifdef HAVE_FFMPEG
00199 class OutputMovieHandler : public FrameProcessObjectHandler
00200 {
00201         public:
00202                 OutputMovieHandler();
00203                 ~OutputMovieHandler();
00204         
00205                 FrameProcessObject & GetObject();
00206                 void RemoveObject();
00207         
00208                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new OutputMovieHandler);};
00209         protected:
00210                 OutputMovie * Obj;
00211         
00212                 StringParameter Filename;
00213                 IntParameter Width;
00214                 IntParameter Height;
00215 };
00216 #endif
00217 /* -------------------------------------
00218     Capture Objects, ie file and v4l
00219    ------------------------------------- */
00220 class CaptureFile;
00221 class CaptureV4L;
00222 class CaptureDC1394;
00223 
00224 class CaptureFileHandler : public CaptureObjectHandler
00225 {
00226         public:
00227                 CaptureFileHandler();
00228                 ~CaptureFileHandler();
00229         
00230                 CaptureObject & GetObject();
00231                 void RemoveObject();
00232         
00233                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new CaptureFileHandler);};
00234         protected:
00235                 CaptureFile * Capture;
00236                 StringParameter *Filename;
00237                 IntParameter *Delay;
00238 };
00239 
00240 class CaptureV4LHandler : public CaptureObjectHandler
00241 {
00242         public:
00243                 CaptureV4LHandler();
00244                 ~CaptureV4LHandler();
00245         
00246                 CaptureObject & GetObject();
00247                 void RemoveObject();
00248         
00249                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new CaptureV4LHandler);};
00250         protected:
00251                 CaptureV4L * Capture;
00252                 StringParameter *Device;
00253                 IntParameter *Width, *Height, *Channel, *Format;
00254 };
00255 
00256 
00257 #ifdef HAVE_DC1394
00258 class CaptureDC1394Handler : public CaptureObjectHandler
00259 {
00260         public:
00261                 CaptureDC1394Handler();
00262                 ~CaptureDC1394Handler();
00263         
00264                 CaptureObject & GetObject();
00265                 void RemoveObject();
00266         
00267                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new CaptureDC1394Handler);};
00268         protected:
00269                 CaptureDC1394 * Capture;
00270 };
00271 #endif
00272 
00273 /* -------------------------------------
00274     Basic Render Objects, ie axes and teapot
00275    ------------------------------------- */
00276 class RenderTeapot;
00277 class RenderAxes;
00278 class RenderModel;
00279 #ifdef WITH_LIBFEP
00280 class RenderFace;
00281 #endif
00282 
00283 class RenderTeapotHandler : public RenderObjectHandler
00284 {
00285         public:
00286                 RenderTeapotHandler();
00287                 ~RenderTeapotHandler();
00288         
00289                 RenderObject & GetObject();
00290                 void RemoveObject();
00291         
00292                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderTeapotHandler);};
00293         protected:
00294                 RenderTeapot * obj;
00295                 ARColourParameter Colour;
00296                 DoubleParameter Size;
00297 };
00298 
00299 class RenderAxesHandler : public RenderObjectHandler
00300 {
00301         public:
00302                 RenderAxesHandler();
00303                 ~RenderAxesHandler();
00304         
00305                 RenderObject & GetObject();
00306                 void RemoveObject();
00307         
00308                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderAxesHandler);};
00309         protected:
00310                 RenderAxes * obj;
00311 };
00312 
00313 class RenderModelHandler : public RenderObjectHandler
00314 {
00315         public:
00316                 RenderModelHandler();
00317                 ~RenderModelHandler();
00318         
00319                 RenderObject & GetObject();
00320                 void RemoveObject();
00321         
00322                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderModelHandler);};
00323         protected:
00324                 RenderModel * obj;
00325                 StringParameter ModelName;
00326                 StringParameter TextureBase;
00327                 DoubleParameter Scale;
00328 };
00329 
00330 class RenderB21r;
00331 
00332 class RenderB21rHandler : public RenderObjectHandler
00333 {
00334         public:
00335                 RenderB21rHandler();
00336                 ~RenderB21rHandler();
00337         
00338                 RenderObject & GetObject();
00339                 void RemoveObject();
00340         
00341                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderB21rHandler);};
00342         protected:
00343                 RenderB21r * obj;
00344                 BooleanParameter Visible;
00345 };
00346 
00347 #ifdef HAVE_LIBFEP
00348 
00349 class RenderVirtualFaceHandler : public RenderObjectHandler
00350 {
00351         public:
00352                 RenderVirtualFaceHandler();
00353                 ~RenderVirtualFaceHandler();
00354         
00355                 RenderObject & GetObject();
00356                 void RemoveObject();
00357         
00358                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new RenderVirtualFaceHandler);};
00359         protected:
00360                 RenderFace * obj;
00361                 StringParameter ModelName;
00362 };
00363 #endif
00364 /* -------------------------------------
00365     Basic Position Objects, ie constant
00366    ------------------------------------- */
00367 class PositionConstant;
00368 class PositionRotate;
00369 
00370 class PositionConstantHandler : public PositionObjectHandler
00371 {
00372         public:
00373                 PositionConstantHandler();
00374                 ~PositionConstantHandler();
00375         
00376                 PositionObject & GetObject();
00377                 void RemoveObject();
00378         
00379                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new PositionConstantHandler);};
00380         protected:
00381                 PositionConstant * obj;
00382                 ARPositionParameter pos;
00383 };
00384 
00385 class PositionRotateHandler : public PositionObjectHandler
00386 {
00387         public:
00388                 PositionRotateHandler();
00389                 ~PositionRotateHandler();
00390         
00391                 PositionObject & GetObject();
00392                 void RemoveObject();
00393         
00394                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new PositionRotateHandler);};
00395         protected:
00396                 PositionRotate * obj;
00397                 ARPositionParameter pos;
00398                 ARPointParameter rate;
00399 };
00400 
00401 /* -------------------------------------
00402     Camera Objects, ie file and v4l
00403    ------------------------------------- */
00404 class CalibratedPositionHandler : public PositionObjectHandler
00405 {
00406         public:
00407                 CalibratedPositionHandler();
00408                 ~CalibratedPositionHandler();
00409         
00410                 PositionObject & GetObject();
00411                 void RemoveObject();
00412         
00413                 static ObjectHandler * CreateHandler() {return static_cast<ObjectHandler * > (new CalibratedPositionHandler);};
00414         protected:
00415                 PositionObject * obj;
00416                 StringParameter * CalibrationFile;
00417 };
00418 
00419 void RegisterDefaultObjectHandlers();
00420         
00421 #endif

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