Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

MREngine.h

Go to the documentation of this file.
00001 
00057 #ifndef _AMIRE_COMPONENT_MR_ENGINE_H
00058 #define _AMIRE_COMPONENT_MR_ENGINE_H
00059 
00060 #include <amire/common/Defines.h>
00061 #include <amire/common/Tracker.h>
00062 #include <amire/common/ProjectionVideoImage.h>
00063 #include <amire/common/MarkerDetector.h>
00064 #include <amire/common/LogWriter.h>
00065 #include <amire/common/Viewport.h>
00066 #include <amire/component/ComponentManager.h>
00067 #include <amire/component/CallbackHandlers.h>
00068 #include <amire/common/FrameRateStatistics.h>
00069 
00070 #ifdef USE_OSG
00071 #include <osg/Node>
00072 #include <osg/Matrix>
00073 #include <osg/Transform>
00074 #include <osgGLUT/Viewer>
00075 #endif
00076 
00077 namespace amire {
00078   namespace component {
00124 #ifdef USE_OSG
00125     class AMIRE_EXPORT_API MREngine : protected virtual osgGLUT::Viewer {
00126 #else
00127     class AMIRE_EXPORT_API MREngine {
00128 #endif
00129     private:
00130       ComponentManager *componentManager;
00131       osg::ref_ptr<amire::common::ProjectionVideoImage> videoImage;
00132       osg::ref_ptr<amire::common::Tracker> cameraTracker;
00133       osg::ref_ptr<amire::common::MarkerDetector> markerDetector;
00134       std::vector<osg::ref_ptr<OccluderHandler> > occluderCallbackHandlers;
00135       std::vector<osg::ref_ptr<DisplayHandler> > displayCallbackHandlers;
00136       std::vector<osg::ref_ptr<KeyHandler> > keyHandlers;
00137       std::vector<osg::ref_ptr<MouseHandler> > mouseHandlers;
00138       std::vector<osg::ref_ptr<Position2DPickingHandler> > position2DPickingHandlers;
00139       std::vector<osg::ref_ptr<Position3DPickingHandler> > position3DPickingHandlers;
00140       std::vector<osg::ref_ptr<DirectionPointerPickingHandler> > directionPointerPickingHandlers;
00141       std::vector<long> position2DPickingMasks;
00142       std::vector<long> position3DPickingMasks;
00143       std::vector<long> directionPointerPickingMasks;
00144       std::vector<osg::ref_ptr<Component> > componentList;
00145       bool mouseBroadcast;
00146       bool running;
00147       bool lighting;
00148       bool fullScreen;
00149       amire::common::Viewport viewport;
00150       osg::ref_ptr<amire::common::LogWriter> logWriter;
00151       amire::property::StringToConstPropertyMap configuration;
00152 
00153       long buttons;
00154       bool drawVideo;
00155       std::string title;
00156       bool showFramerate;
00157       std::string text;
00158       amire::common::FrameRateStatistics frameRateStatistics;
00159       bool initFrameRate;
00160       osg::ref_ptr<amire::common::ImageBackground> background;
00161       bool convertToRGB;
00162 #ifdef USE_OSG
00163       osg::ref_ptr<osg::RefMatrix> projectionMatrix;
00164       osg::ref_ptr<osg::RefMatrix> modelviewMatrix;
00165 #ifdef _DEBUG
00166       bool drawOsgOccluderNodes;
00167       bool drawOsgDisplayNodes;
00168 #endif
00169 #endif
00170       int backupWidth;
00171       int backupHeight;
00172       bool currentFullScreen;
00173       int exitCode;
00174       std::vector<std::string> pluginLibraries;
00175 
00176 #ifdef USE_OSG
00177       std::vector<osg::ref_ptr<osg::RefMatrix> > transformations;
00178       std::vector<osg::ref_ptr<osg::Node> > occluderSceneNodes;
00179       std::vector<osg::ref_ptr<osg::Node> > displaySceneNodes;
00180       osg::ref_ptr<osg::Node> occluderSceneGraph;
00181       osg::ref_ptr<osg::Node> displaySceneGraph;
00182       osg::ref_ptr<osg::RefMatrix> cameraMatrix;
00183       bool invalidSceneGraphs;
00184 #endif
00185 
00186     public:
00193       class SelectionHandler {
00194       public:
00195         virtual ~SelectionHandler();
00200         virtual int select(const std::vector<osg::ref_ptr<Handler> > &selection, const std::vector<double> &distances) const;
00201       };
00202 
00203       MREngine(int &argc, char** &argv, const char* cameraConfigFile);
00204 
00205       virtual ~MREngine();
00206 
00211       int init(int &argc, char** &argv, const char* cameraConfigFile);
00212 
00217       virtual bool run();
00218 
00230       void addPluginLibrary(const std::string &filename);
00231 
00235       const std::vector<std::string> &getPluginLibraries();
00236 
00243       void setConfig(const std::string &name, const osg::ref_ptr<const amire::property::Property> &value);
00244 
00248       osg::ref_ptr<const amire::property::Property> getConfig(const std::string &name) const;
00249 
00253       const amire::property::StringToConstPropertyMap &getConfig() const;
00254 
00259       int getExitCode() const;
00260 
00267       void setComponentManager(ComponentManager *componentManager);
00268 
00269 #ifdef USE_OSG
00270 
00277       void setTransformation(const osg::ref_ptr<Component> &component, osg::ref_ptr<osg::RefMatrix> transformation);
00278 
00288       void setOccluderSceneNode(const osg::ref_ptr<Component> &component, osg::ref_ptr<osg::Node> node);
00289 
00298       void setDisplaySceneNode(const osg::ref_ptr<Component> &component, osg::ref_ptr<osg::Node> node);
00299 #endif
00300 
00305       const osg::ref_ptr<amire::common::ProjectionVideoImage> &getVideoImage();
00306 
00311       const osg::ref_ptr<amire::common::MarkerDetector> &getMarkerDetector();
00312 
00317       const osg::ref_ptr<amire::common::Tracker> &getCameraTracker();
00318 
00324       void setFreeze(bool freeze = true);
00325 
00330       bool isFreezed();
00331 
00336       void setLogWriter(const osg::ref_ptr<amire::common::LogWriter> &logWriter);
00337 
00341       osg::ref_ptr<amire::common::LogWriter> getLogWriter() const;
00342 
00348       void setFullScreen(bool fullScreen = true);
00349 
00353       bool getFullScreen() const;
00354 
00359       void setLighting(bool lighting = true);
00360 
00364       bool getLighting() const;
00365 
00372       void setMouseBroadcast(bool mouseBroadcast = true);
00373 
00380       bool getMouseBroadcast() const;
00381 
00387       void reinitializeEngine();
00388 
00389 #ifdef USE_OSG
00390 
00393       void setCameraMatrix(const osg::ref_ptr<osg::RefMatrix> &cameraMatrix);
00394 
00398       const osg::ref_ptr<osg::RefMatrix> &getCameraMatrix() const;
00399 #endif
00400 
00404       amire::common::Viewport getViewport(const osg::ref_ptr<Component> &component = NULL);
00405 
00412       void exit(int exitCode = 0);
00413 
00418       bool directionPointerPickingHandlerAvailable(long pickingMode) const;
00419 
00424       bool position2DPickingHandlerAvailable(long pickingMode) const;
00425 
00430       bool position3DPickingHandlerAvailable(long pickingMode) const;
00431 
00435       bool fireAction(long modifier, int key, const osg::ref_ptr<Action> &action = NULL);
00436 
00446       bool fireAction(double x, double y, long pickingMode = NORMAL_PICK, bool broadcast = false, const osg::ref_ptr<Action> &action = NULL, const SelectionHandler *selectionHandler = NULL);
00447 
00457       bool fireAction(const amire::common::Vector &point, long pickingMode = NORMAL_PICK, bool broadcast = false, const osg::ref_ptr<Action> &action = NULL, const SelectionHandler *selectionHandler = NULL);
00458 
00468       bool fireAction(const amire::common::Vector &point, const amire::common::Vector &direction, long pickingMode = NORMAL_PICK, bool broadcast = false, const osg::ref_ptr<Action> &action = NULL, const SelectionHandler *selectionHandler = NULL);
00469 
00476       osg::ref_ptr<Component> pick(double x, double y, long pickingMode = NORMAL_PICK, const SelectionHandler *selectionHandler = NULL);
00477 
00484       osg::ref_ptr<Component> pick(const amire::common::Vector &point, long pickingMode = NORMAL_PICK, const SelectionHandler *selectionHandler = NULL);
00485 
00492       osg::ref_ptr<Component> pick(const amire::common::Vector &point, const amire::common::Vector &direction, long pickingMode = NORMAL_PICK, const SelectionHandler *selectionHandler = NULL);
00493 
00501       std::vector<osg::ref_ptr<Component> > select(double x, double y, std::vector<double> &distance, long pickingMode = NORMAL_PICK);
00502 
00510       std::vector<osg::ref_ptr<Component> > select(const amire::common::Vector &point, std::vector<double> &distance, long pickingMode = NORMAL_PICK);
00511 
00519       std::vector<osg::ref_ptr<Component> > select(const amire::common::Vector &point, const amire::common::Vector &direction, std::vector<double> &distance, long pickingMode = NORMAL_PICK);
00520 
00527       void addOccluderHandler(const osg::ref_ptr<OccluderHandler> &handler);
00528 
00534       void addDisplayHandler(const osg::ref_ptr<DisplayHandler> &handler);
00535 
00540       void addKeyHandler(const osg::ref_ptr<KeyHandler> &handler);
00541 
00546       void addMouseHandler(const osg::ref_ptr<MouseHandler> &handler);
00547 
00554       void addPosition2DPickingHandler(const osg::ref_ptr<Position2DPickingHandler> &handler, long pickingMask = PICK_EVERYTHING);
00555 
00562       void addPosition3DPickingHandler(const osg::ref_ptr<Position3DPickingHandler> &handler, long pickingMask = PICK_EVERYTHING);
00563 
00570       void addDirectionPointerPickingHandler(const osg::ref_ptr<DirectionPointerPickingHandler> &handler, long pickingMask = PICK_EVERYTHING);
00571 
00578       void setPosition2DPickingMask(const osg::ref_ptr<Position2DPickingHandler> &handler, long pickingMask);
00579 
00586       void setPosition3DPickingMask(const osg::ref_ptr<Position3DPickingHandler> &handler, long pickingMask);
00587 
00594       void setDirectionPointerPickingMask(const osg::ref_ptr<DirectionPointerPickingHandler> &handler, long pickingMask);
00595 
00602       void removeOccluderHandler(const osg::ref_ptr<OccluderHandler> &handler);
00603 
00609       void removeDisplayHandler(const osg::ref_ptr<DisplayHandler> &handler);
00610 
00615       void removeKeyHandler(const osg::ref_ptr<KeyHandler> &handler);
00616 
00621       void removeMouseHandler(const osg::ref_ptr<MouseHandler> &handler);
00622 
00628       void removePosition2DPickingHandler(const osg::ref_ptr<Position2DPickingHandler> &handler);
00629 
00635       void removePosition3DPickingHandler(const osg::ref_ptr<Position3DPickingHandler> &handler);
00636 
00642       void removeDirectionPointerPickingHandler(const osg::ref_ptr<DirectionPointerPickingHandler> &handler);
00643 
00648       void setVideoImage(const osg::ref_ptr<amire::common::ProjectionVideoImage> &videoImage);
00649 
00654       void setCameraTracker(const osg::ref_ptr<amire::common::Tracker> &tracker);
00655 
00660       void setMarkerDetector(const osg::ref_ptr<amire::common::MarkerDetector> &markerDetector);
00661 
00665       ComponentManager *getComponentManager();
00666 
00670       bool isRunning() const;
00671 
00679       virtual void display();
00680 
00686       virtual void reshape(GLint w, GLint h);
00687 
00694       virtual void mouseMotion(int x, int y);
00695 
00702       virtual void mousePassiveMotion(int x, int y);
00703 
00709       virtual void mouse(int button, int state, int x, int y);
00710 
00716       virtual void keyboard(unsigned char key, int x, int y);
00717 
00718       // public  methods for internal use
00719     private:
00720       std::vector<osg::ref_ptr<Handler> > selectHandlers(double x, double y, std::vector<double> &distance, long pickingMode = NORMAL_PICK);
00721       std::vector<osg::ref_ptr<Handler> > selectHandlers(const amire::common::Vector &point, std::vector<double> &distance, long pickingMode = NORMAL_PICK);
00722       std::vector<osg::ref_ptr<Handler> > selectHandlers(const amire::common::Vector &point, const amire::common::Vector &direction, std::vector<double> &distance, long pickingMode = NORMAL_PICK);
00723 
00724 #ifdef USE_OSG
00725       bool validateSceneGraph();
00726 #endif
00727 
00728       void validate();
00729     };
00730 
00737     class AMIRE_EXPORT_API ExitCommand {
00738     public:
00742       int exitCode;
00743 
00744       ExitCommand(int exitCode) {
00745         this->exitCode = exitCode;
00746       }
00747 
00748       virtual ~ExitCommand() {
00749       }
00750     };
00751   }
00752 }
00753 
00754 #endif

Generated on Tue May 20 17:23:53 2003 for AMIRE-Framework by doxygen1.3