OpenIG  2.0.4
cross-platform open-source OpenSceneGraph Image Generator
Engine.h
1 //#******************************************************************************
2 //#*
3 //#* Copyright (C) 2015 Compro Computer Services
4 //#* http://openig.compro.net
5 //#*
6 //#* Source available at: https://github.com/CCSI-CSSI/MuseOpenIG
7 //#*
8 //#* This software is released under the LGPL.
9 //#*
10 //#* This software is free software; you can redistribute it and/or modify
11 //#* it under the terms of the GNU Lesser General Public License as published
12 //#* by the Free Software Foundation; either version 2.1 of the License, or
13 //#* (at your option) any later version.
14 //#*
15 //#* This software is distributed in the hope that it will be useful,
16 //#* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 //#* the GNU Lesser General Public License for more details.
19 //#*
20 //#* You should have received a copy of the GNU Lesser General Public License
21 //#* along with this library; if not, write to the Free Software
22 //#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //#*
24 //#* Please direct any questions or comments to the OpenIG Forums
25 //#* Email address: openig@compro.net
26 //#*
27 //#*
28 //#* Please direct any questions or comments to the OpenIG Forums
29 //#* Email address: openig@compro.net
30 //#*
31 //#*
32 //#*****************************************************************************
33 #ifndef OPENIG_H
34 #define OPENIG_H
35 
36 #if defined(OPENIG_SDK)
37  #include <OpenIG-Engine/Export.h>
38  #include <OpenIG-Engine/Keypad.h>
39 
40  #include <OpenIG-Base/ImageGenerator.h>
41  #include <OpenIG-Base/Types.h>
42 
43  #include <OpenIG-PluginBase/PluginHost.h>
44  #include <OpenIG-PluginBase/PluginContext.h>
45 #else
46  #include <Core-OpenIG/Export.h>
47  #include <Core-OpenIG/Keypad.h>
48 
49  #include <Core-Base/ImageGenerator.h>
50  #include <Core-Base/Types.h>
51 
52  #include <Core-PluginBase/PluginHost.h>
53  #include <Core-PluginBase/PluginContext.h>
54 #endif
55 
56 #include <OpenThreads/Mutex>
57 #include <OpenThreads/ScopedLock>
58 #include <osgUtil/IntersectVisitor>
59 
60 namespace OpenIG
61 {
62 
69 class OPENIG_EXPORT Engine:
72  public osg::Referenced
73 {
74 public:
81  Engine();
82 
83 protected:
87  virtual ~Engine();
88 
89 public:
97  virtual void loadScript(const std::string& fileName);
98 
106  virtual std::string version();
107 
115  {
116  None = 0x00,
117  WithTerminal = 0x01,
118  WithSplashScreen = 0x02,
119  WithOnscreenHelp = 0x04,
120  Standard = WithTerminal | WithSplashScreen | WithOnscreenHelp
121  };
122 
130  virtual void setupInitFlags(unsigned int mask);
131 
150  virtual void init(osgViewer::CompositeViewer* viewer, const std::string& xmlFileName = "openig.xml", const ViewIdentifiers& ids = ViewIdentifiers());
151 
160  enum ViewType
161  {
162  OTW = 1,
163  EO = 2,
164  IR = 3
165  };
166 
178  virtual void initView(osgViewer::View* view, ViewType options = OTW);
179 
190  virtual void setViewType(osgViewer::View* view, ViewType options);
191 
192 
199  virtual void cleanup();
200 
238  virtual void frame(bool usePlugins = true);
239 
249  virtual void setReadNodeImplementationCallback(ReadNodeImplementationCallback* cb);
250 
258  virtual ReadNodeImplementationCallback* getReadNodeImplementationCallback();
259 
269  virtual void setReadFileCallback(osgDB::Registry::ReadFileCallback* cb);
270 
278  virtual osgDB::Registry::ReadFileCallback* getReadFileCallback();
279 
280 
299  virtual void addEntity(unsigned int id, const std::string& fileName, const osg::Matrixd& mx, const osgDB::Options* options = 0);
300 
315  virtual void addEntity(unsigned int id, const osg::Node* node, const osg::Matrixd& mx, const osgDB::Options* options = 0);
316 
328  virtual void removeEntity(unsigned int id);
329 
340  virtual void updateEntity(unsigned int id, const osg::Matrixd& mx);
341 
351  virtual void showEntity(unsigned int id, bool show);
352 
364  virtual void bindToEntity(unsigned int id, unsigned int toEntityId);
365 
376  virtual void unbindFromEntity(unsigned int id);
377 
387  virtual void bindEntityToCamera(unsigned int id, const osg::Matrixd& mx, unsigned int cameraID = 0);
388 
399  virtual void bindEntityToCameraUpdate(unsigned int id, const osg::Matrixd& mx);
400 
407  virtual void unbindEntityFromCamera(unsigned int id);
408 
418  virtual void reloadEntity(unsigned int id, const std::string& fileName, const osgDB::Options* options = 0);
419 
429  virtual void setEntityName(unsigned int id, const std::string& name);
430 
439  virtual std::string getEntityName(unsigned int id);
440 
450  virtual unsigned int getEntityId(unsigned int parentEntityId, const std::string& subEntityName);
451 
470  virtual void playAnimation(unsigned int entityId, const std::string& animationName);
471 
482  virtual void playAnimation(unsigned int entityId, const OpenIG::Base::StringUtils::StringList& animations);
483 
500  virtual void playAnimation(unsigned int entityId, const std::string& animationName, OpenIG::Base::RefAnimationSequenceCallbacks* cbs);
501 
510  virtual void stopAnimation(unsigned int entityId, const std::string& animationName);
511 
520  virtual void stopAnimation(unsigned int entityId, const OpenIG::Base::StringUtils::StringList& animations);
521 
531  virtual void resetAnimation(unsigned int entityId, const std::string& animationName);
532 
542  virtual void resetAnimation(unsigned int entityId, const OpenIG::Base::StringUtils::StringList& animations);
543 
553  virtual void changeAnimationStatus(unsigned int entityId, AnimationStatus status, const OpenIG::Base::StringUtils::StringList& animations);
554 
555  // Effects
567  virtual void addEffect(unsigned int id, const std::string& name, const osg::Matrixd& mx, const std::string& attributes);
568 
576  virtual void removeEffect(unsigned int id);
577 
587  virtual void bindEffect(unsigned int id, unsigned int entityID, const osg::Matrixd& mx);
588 
596  virtual void unbindEffect(unsigned int id);
597 
606  virtual void updateEffect(unsigned int id, const osg::Matrixd& mx);
607 
617  virtual void setEffectImplementationCallback(OpenIG::Base::GenericImplementationCallback* cb);
618 
619 
630  virtual void setCameraPosition(const osg::Matrixd& mx, bool viewMatrix = false, unsigned int cameraID = 0);
631 
641  virtual void bindCameraToEntity(unsigned int id, const osg::Matrixd& mx, unsigned int cameraID = 0);
642 
652  virtual void bindCameraUpdate(const osg::Matrixd& mx, unsigned int cameraID = 0);
653 
660  virtual void unbindCameraFromEntity(unsigned int cameraID = 0);
661 
669  virtual bool isCameraBoundToEntity(unsigned int cameraID = 0);
670 
683  virtual void bindCameraSetFixedUp(bool fixedUp, bool freezeOrientation = false, unsigned int cameraID = 0);
684 
695  virtual void setFog(double visibility);
696 
708  virtual void setDate(unsigned int month,int day, int year);
709 
720  virtual void setTimeOfDay(unsigned int hour, unsigned int minutes);
721 
732  virtual void setRain(double factor);
733 
744  virtual void setSnow(double factor);
745 
758  virtual void setWind(float speed, float direction = 0.f);
759 
780  virtual void addCloudLayer(unsigned int id, int type, double altitude, double thickness=0, double density=0.3, bool enable=true);
781 
791  virtual void removeCloudLayer(unsigned int id);
792 
807  virtual void updateCloudLayer(unsigned int id, double altitude, double thickness, double density);
808 
817  virtual void removeAllCloudlayers();
818 
840  virtual void createCloudLayerFile(unsigned int id, int type, double altitude, double thickness=0, double density=0.3, bool enable=true, std::string filename="");
841 
852  virtual void enableCloudLayer(unsigned int id, bool enableIn=true);
853 
864  virtual void removeCloudLayerFile(unsigned int id);
865 
878  virtual void loadCloudLayerFile(unsigned int id, int type, std::string filename);
879 
896  virtual void addLight(unsigned int id, const OpenIG::Base::LightAttributes& lightAttributes, const osg::Matrixd& mx);
897 
905  virtual void removeLight(unsigned int id);
906 
917  virtual void updateLight(unsigned int id, const osg::Matrixd& mx);
918 
927  virtual void setLightUserData(unsigned int id, osg::Referenced* data);
928 
938  virtual void bindLightToEntity(unsigned int id, unsigned int entityId);
939 
948  virtual void unbindLightFromEntity(unsigned int id);
949 
961  virtual void enableLight(unsigned int id, bool enable, bool hard = true);
962 
975  virtual void bindLightToCamera(unsigned int id, const osg::Matrixd& offset = osg::Matrixd::identity());
976 
984  virtual void unbindLightFromcamera(unsigned int id);
985 
995  virtual bool isLightEnabled(unsigned int id);
996 
1005  virtual LightAttributesMap& getLightAttributesMap();
1006 
1016  virtual OpenIG::Base::LightAttributes getLightAttributes(unsigned int id);
1017 
1029  virtual void updateLightAttributes(unsigned int id, const OpenIG::Base::LightAttributes& attribs);
1030 
1037  virtual void preRender();
1038 
1045  virtual void postRender();
1046 
1054  void setUpdateViewerCameraManipulator(bool update);
1055 
1062  typedef osg::ref_ptr<osg::MatrixTransform> LightEntity;
1063  typedef std::map<unsigned int, LightEntity > LightsMap;
1064  typedef std::map<unsigned int, LightEntity >::iterator LightsMapIterator;
1065  typedef std::map<unsigned int, LightEntity >::const_iterator LightsMapConstIterator;
1066 
1074  virtual OpenIG::Base::LightImplementationCallback* getLightImplementationCallback();
1075 
1086  virtual void setLightImplementationCallback( OpenIG::Base::LightImplementationCallback* cb);
1087 
1097  virtual osgViewer::CompositeViewer* getViewer();
1098 
1109  virtual osg::Node* getScene();
1110 
1120  virtual EntityMap& getEntityMap();
1121 
1130  virtual float getTerrainHeight( const osg::Vec3& position );
1131 
1142  virtual float getIntersect( const osg::Vec3& pos, const osg::Vec3& angles,float angle );
1143 
1154  virtual osg::Vec3 getIntersectPos( const osg::Vec3& pos, const osg::Vec3& angles, float angle, float height=100000 );
1155 
1156 
1164  virtual osg::LightSource* getSunOrMoonLight();
1165 
1173  virtual osg::Fog* getFog();
1174 
1182  OpenIG::PluginBase::PluginContext& getPluginContext();
1183 
1191  LightsMap& getLightsMap();
1192 
1200  const OpenIG::Base::StringUtils::StringList& getFilesToBeCached() const;
1201 
1209  void addFilesToBeCached(const OpenIG::Base::StringUtils::StringList& files);
1210 
1218  bool isFileCached(const std::string& fileName);
1219 
1220 protected:
1221 
1223  EntityMap _entities;
1224 
1225  osg::ref_ptr<osgUtil::IntersectVisitor> _intersect;
1226 
1228  osg::observer_ptr<osgViewer::CompositeViewer> _viewer;
1230  osg::ref_ptr<osg::LightSource> _sunOrMoonLight;
1232  osg::ref_ptr<osg::Fog> _fog;
1234  osg::ref_ptr<osg::Group> _scene;
1236  osg::observer_ptr<OpenIG::Base::LightImplementationCallback> _lightImplementationCallback;
1240 
1242  LightsMap _lights;
1244  osg::ref_ptr<osg::Group> _lightsGroup;
1246  osg::ref_ptr<KeyPadEventHandler> _keypad;
1248  osg::ref_ptr<KeyPadCameraManipulator> _keypadCameraManipulator;
1250  osg::ref_ptr<osgGA::CameraManipulator> _viewerCameraManipulator;
1257  osg::ref_ptr<osg::Camera> _splashCamera;
1261  osg::ref_ptr<osg::Group> _effectsRoot;
1263  osg::ref_ptr<OpenIG::Base::GenericImplementationCallback> _effectsImplementationCallback;
1264 
1266  typedef osg::ref_ptr<osg::MatrixTransform> Effect;
1267  typedef std::map< unsigned int, Effect > EffectMap;
1268  EffectMap _effects;
1269 
1271  LightAttributesMap _lightAttributes;
1272 
1274  osg::ref_ptr<ReadNodeImplementationCallback> _readFileCallback;
1275 
1277  typedef std::map< std::string, osg::ref_ptr<osg::Node> > EntityCache;
1278  EntityCache _entityCache;
1279 
1281  OpenIG::Base::StringUtils::StringList _filesToBeCached;
1282 
1284  unsigned int _setupMask;
1285 
1287  osg::ref_ptr<osgDB::Registry::ReadFileCallback> _userReadFileCallback;
1288 
1299  void initViewer(osgViewer::CompositeViewer* viewer, const ViewIdentifiers& ids = ViewIdentifiers());
1300 
1307  void initTerminal();
1308 
1316  void initCommands();
1317 
1325  void initPluginContext();
1326 
1334  void initScene();
1335 
1344  void initOnScreenHelp();
1352  void initSplashScreen();
1353 
1360  void initEffects();
1361 
1368  void createSunMoonLight();
1369 };
1370 
1371 } // namespace
1372 
1373 #endif // OPENIG_H
Definition: ImageGenerator.h:62
bool _splashOn
Switch set to true when the splash screen is on.
Definition: Engine.h:1259
OpenIG::PluginBase::PluginContext _context
The OpenIG::PluginBase::PluginContext to pass Attributes, ex: OpenIG::Base::FogAttributes to plugins...
Definition: Engine.h:1239
osg::ref_ptr< OpenIG::Base::GenericImplementationCallback > _effectsImplementationCallback
The effect implementation callback.
Definition: Engine.h:1263
SetupFlags
OpenIG specific flags for how to setup the Viewer.
Definition: Engine.h:114
osg::ref_ptr< osg::Fog > _fog
Handle of Fog attribute.
Definition: Engine.h:1232
osg::ref_ptr< osgDB::Registry::ReadFileCallback > _userReadFileCallback
user ReadFileCallback
Definition: Engine.h:1287
osg::ref_ptr< osg::LightSource > _sunOrMoonLight
Handle of the sun/moon light source with reserved ID of 0.
Definition: Engine.h:1230
LightsMap _lights
ID based std::map of lights. See addLight.
Definition: Engine.h:1242
The PluginHost class.
Definition: PluginHost.h:61
osg::observer_ptr< OpenIG::Base::LightImplementationCallback > _lightImplementationCallback
Handle of the light implementation callback. See setLightImplementationCallback.
Definition: Engine.h:1236
unsigned int _setupMask
setup mask
Definition: Engine.h:1284
ViewType
Setup a View with OpenIG with rendering options.
Definition: Engine.h:160
osg::ref_ptr< osg::Group > _effectsRoot
The root of the effects.
Definition: Engine.h:1261
osg::observer_ptr< osgViewer::CompositeViewer > _viewer
Handle of the viewer you have passed in init.
Definition: Engine.h:1228
The Image Generator abstract interface. This is base class for openig::OpenIG.
Definition: ImageGenerator.h:74
std::vector< unsigned int > ViewIdentifiers
One might want to have the Image Generator only in some views, so this typedef holds the IDs of the v...
Definition: ImageGenerator.h:111
osg::ref_ptr< osgGA::CameraManipulator > _viewerCameraManipulator
Handle of any CameraManipulator that was attached on the Viewer you provided in init.
Definition: Engine.h:1250
osg::ref_ptr< ReadNodeImplementationCallback > _readFileCallback
The read file callback.
Definition: Engine.h:1274
std::map< std::string, osg::ref_ptr< osg::Node > > EntityCache
The file cache map.
Definition: Engine.h:1277
osg::ref_ptr< KeyPadEventHandler > _keypad
Build-in Keypad Event Handler. See the onscreen help available on F7 for the keypad command...
Definition: Engine.h:1246
EntityMap _entities
The current added in the scene Entity es, ID based std::map.
Definition: Engine.h:1223
osg::ref_ptr< osg::MatrixTransform > LightEntity
Represntation of LightEntity.
Definition: Engine.h:1062
The PluginContext class.
Definition: PluginContext.h:59
osg::ref_ptr< osg::Group > _lightsGroup
Root of the lights in the scene. This is passed in the OpenIG::Base::LightImplementationCallback.
Definition: Engine.h:1244
bool _updateViewerCameraMainpulator
If true with setUpdateViewerCameraManipulator then the provided CameraManipulator is updated as well ...
Definition: Engine.h:1255
The OpenIG class.
Definition: Engine.h:69
osg::ref_ptr< osg::MatrixTransform > Effect
Our Effect.
Definition: Engine.h:1266
osg::ref_ptr< KeyPadCameraManipulator > _keypadCameraManipulator
Build-in Keypad Camera manipulator. See the onscreen help available on F7 for the keypad command...
Definition: Engine.h:1248
bool _sceneCreatedByOpenIG
Set to true if there was no scene created with your Viewer.
Definition: Engine.h:1252
osg::ref_ptr< osg::Group > _scene
The managed scene, which is osgShadow::Shadowed scene.
Definition: Engine.h:1234
OpenIG::Base::StringUtils::StringList _filesToBeCached
The files to be cached.
Definition: Engine.h:1281
LightAttributesMap _lightAttributes
The Light Attributes.
Definition: Engine.h:1271
osg::ref_ptr< osg::Camera > _splashCamera
Handle of the splash screen.
Definition: Engine.h:1257