AGX Dynamics  2.35.0.1
ExampleApplication.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #ifdef __clang__
20 #pragma clang diagnostic push
21 #pragma clang diagnostic ignored "-Wconversion"
22 #endif
23 
24 #include <agx/config/AGX_USE_OPENGL.h>
25 #include <agx/config/AGX_USE_FFMPEG.h>
26 #include <agx/config/AGX_USE_PYTHON.h>
27 
28 #include <agx/config.h>
29 
30 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
31 #include <osg/Switch>
32 #include <osgViewer/Viewer>
33 #include <osg/Version>
34 #include <osg/ref_ptr>
35 #include <osg/MatrixTransform>
36 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
37 
38 #include <agxOSG/DepthPeeling.h>
39 #include <agxOSG/export.h>
40 #include <agxOSG/GuiEventAdapter.h>
41 #include <agxOSG/PickHandler.h>
42 #include <agxOSG/RenderTarget.h>
43 #include <agxOSG/RenderToTexture.h>
45 
46 #if AGX_USE_WEBSOCKETS()
48 #endif
49 
50 #include <agxSDK/Simulation.h>
54 #include <agxOSG/ImageCapture.h>
55 #include <agxCFG/ConfigScript.h>
56 
57 #include <agx/Timer.h>
59 
60 #include <agxIO/ArgumentParser.h>
61 #include <agx/HighAccuracyTimer.h>
62 
63 #include <cstddef>
64 
65 #if AGX_USE_OPENGL()
66 #include <agxGL/Camera.h>
67 #include <agxGL/Lights.h>
68 #endif
69 
70 #if AGX_USE_PYTHON()
71 # include <agxPython/ScriptManager.h>
72 # include <agxPython/ScriptContext.h>
73 # include <agx/config/AGX_PYTHON_VERSION.h>
74 #endif
75 
76 #ifdef __clang__
77 #pragma clang diagnostic pop
78 #endif
79 
80 namespace osgGA
81 {
82  class StandardManipulator;
83  class MatrixManipulator;
84 }
85 
86 namespace agxFMI2
87 {
88  namespace Export
89  {
90  class Module;
91  }
92 }
93 
94 
95 namespace agxSDK
96 {
97  class Assembly;
98 }
99 
100 namespace agxNet
101 {
102  class CoSimulationServer;
103 }
104 
105 namespace agxOSG {
106  class ExampleApplication;
107  class SceneDecorator;
108  class RenderProxyFactory;
109  class GeometryNode;
110 #if AGX_USE_WEBSOCKETS()
111  class ExampleApplicationController;
112 #endif
113 
114  typedef osg::Group * (*BuildScenePtr)(agxSDK::Simulation *simulation, ExampleApplication *application);
115 
118 
121 
123  SceneDescription(BuildScenePtr sc, bool isTest = false, float stop = float(), bool isSlowUnittest = false);
124 
126  SceneDescription(const std::string& scriptFileName, const std::string& scriptFunctionName, bool isTest = false, float stop = float(), bool isSlowUnittest = false);
127 
129  SceneDescription(const std::string& sceneFile, bool isTest = false, float stop = float(), bool isSlowUnittest = false);
130 
131  bool isValid() const { return valid; }
132 
133 
135  bool unittest;
136  float stopAfter;
138  bool valid;
139  std::string scriptFunction;
140  std::string fileName;
141  };
142 
143 
144 #if defined(OSG_VERSION_GREATER_OR_EQUAL)
145 # if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
146  typedef osgGA::StandardManipulator CameraManipulatorType;
147 # else
148  typedef osgGA::MatrixManipulator CameraManipulatorType;
149 # endif
150 #else
151  typedef osgGA::MatrixManipulator CameraManipulatorType;
152 #endif
153 
154 
155 
156 #if AGX_USE_OPENGL()
157  class CameraSynchronization : public osg::Camera::DrawCallback
158  {
159  public:
160  CameraSynchronization(osg::Camera *mainCamera, agxGL::Camera *glCamera) : m_mainCamera(mainCamera), m_glCamera(glCamera)
161  {
162  }
163 
165  {
166  }
167 
168  virtual void operator () (osg::RenderInfo& /* renderInfo */) const
169  {
170  // Explicit support for Real=float agx with Real=double osg
171  agxData::Val<agx::Matrix4x4d> projection(agx::Matrix4x4d(m_mainCamera->getProjectionMatrix().ptr()));
172  agx::Matrix4x4 m = projection.transform<agx::Matrix4x4 > ();
173 
174  if (m != m_glCamera->getProjectionMatrix())
175  m_glCamera->setProjectionMatrix(m);
176 
177  agxData::Val<agx::Matrix4x4d> view(agx::Matrix4x4d(m_mainCamera->getViewMatrix().ptr()));
178  agx::Matrix4x4 m2 = view.transform<agx::Matrix4x4 > ();
179 
180  if (m2 != m_glCamera->getViewMatrix())
181  m_glCamera->setViewMatrix(m2);
182 
183  auto viewport = m_mainCamera->getViewport();
184  m_glCamera->setViewPort(static_cast<int>(viewport->width()), static_cast<int>(m_mainCamera->getViewport()->height()));
185  }
186  using osg::Camera::DrawCallback::operator();
187 
188  private:
189  osg::Camera *m_mainCamera;
190  agxGL::Camera *m_glCamera;
191  };
192 
193  class LightsSynchronization : public osg::Camera::DrawCallback
194  {
195  public:
197  : m_glLights(mainLights),
198  m_decorator(decorator)
199  {
200  }
201 
203  {
204  }
205 
206  virtual void operator () (osg::RenderInfo& /* renderInfo */) const
207  {
208 
209  auto updateLight = [this](size_t index, agxOSG::LightSource l)
210  {
211  m_glLights->setLightPosition(index, l.getPosition());
212  m_glLights->setLightDirection(index, l.getDirection());
213  };
214 
215  updateLight(0, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT0));
216  updateLight(1, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT1));
217  updateLight(2, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT2));
218  }
219 
220  using osg::Camera::DrawCallback::operator();
221 
222  private:
223  agxGL::Lights *m_glLights;
224  SceneDecorator *m_decorator;
225  };
226 #endif
227 
229  {
230  public:
231  enum Types { TRACKBALL,
232 #if defined(OSG_VERSION_GREATER_OR_EQUAL)
233 # if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
234  FPS,
235 # endif
236 #endif
237  NUM_TYPES };
238 
240 
242 
243  CameraManipulatorType* next( osgViewer::Viewer* viewer = nullptr );
244  CameraManipulatorType* next( osgViewer::GraphicsWindow* window = nullptr );
245  CameraManipulatorType* create( osgViewer::Viewer* viewer = nullptr );
246  CameraManipulatorType* create( Types type, osgViewer::Viewer* viewer = nullptr );
247  CameraManipulatorType* create( Types type, osgViewer::GraphicsWindow* window = nullptr );
248  CameraManipulatorType* create( osgViewer::GraphicsWindow* window = nullptr );
249 
250  void setType( Types type ) { m_currentType = type; }
251  Types getType() const { return m_currentType; }
252 
253  protected:
254  SINGLETON_CLASSNAME_METHOD();
255  virtual void shutdown() override { s_instance = nullptr; }
256  osgViewer::GraphicsWindow* getWindow( osgViewer::Viewer* viewer, size_t num = 0 ) const;
257 
260  };
261 
263  {
267  CameraData( const osg::Camera* camera );
268 
272  CameraData( const osgViewer::Viewer* viewer );
273 
277  void applyTo( osg::Camera* camera ) const;
278 
282  void applyTo( osgViewer::Viewer* viewer ) const;
283 
286  double fieldOfView;
287  double aspectRatio;
288  bool valid;
289  double nearFarRatio;
290 
294 
295  private:
296  CameraData();
297  void initialize( const osg::Camera* camera );
298  };
299 
302 
303  public:
304  virtual void preFrame(ExampleApplication* app);
305  virtual void postFrame(ExampleApplication* app);
306 
307  protected:
308  virtual ~ExampleApplicationListener() override;
309  };
310 
311 
313 
318  {
319  public:
322 
329  {
330  MAIN_SCENE_MASK = 1 << 1,
331  DEBUG_RENDER_MASK = 1 << 2,
332  OSG_RENDER_MASK = 1 << 3,
333  HUD_MASK = 1 << 4,
334  DECORATOR_MASK = 1 << 5,
335  };
336 
338  {
339  MULTI, // New.
340  ITERATIVE, // New forced to iterative.
341  NUM_SOLVERS
342  };
343 
344 
345  void setSolverType( SolverType t ) { m_solverType = t; }
346  SolverType getSolverType() const { return m_solverType; }
347 
348  std::string getSolverName( SolverType t ) const;
349  SolverType getSolverType( const std::string& name ) const;
350 
354  void addAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2);
355  void addAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2);
356  void removeAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2);
357  void removeAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2);
358 
362  void setEnableAutoPausing(bool flag);
364 
366  ExampleApplication( agxSDK::Simulation *simulation=nullptr );
367 
368  bool init( agxIO::ArgumentParser* arguments, bool agxOnly = false );
369 
371 
372 #ifndef SWIG
373  bool init( int argc, char** argv );
374 #endif
375 
376  agxIO::ArgumentParser* getArguments() { return m_arguments.get(); }
377 
378  agxOSG::RenderProxyFactory *getRenderProxyFactory() { return m_renderProxyFactory; }
379 
380  void setTimeStep( agx::Real dt );
382 
383  bool addScene( const std::string& scriptFile, const std::string& scriptFunction, int key, bool isPartofUnitTest=true, float stopAfter=float(), bool isSlowUnittest=false );
384  bool addScene( const std::string& scriptFile, const std::string& scriptFunction, bool isPartofUnitTest=true, float stopAfter=float(), bool isSlowUnittest=false );
385 
386  bool addScene( BuildScenePtr sceneFunction, int key, bool isPartofUnitTest=true, float stopAfter=float(), bool isSlowUnittest=false );
387  bool addScene( BuildScenePtr sceneFunction, bool isPartofUnitTest=true, float stopAfter=float(), bool isSlowUnittest=false );
388 
389  bool addScene( SceneDescription sceneDescription, int key);
390  bool addScene( SceneDescription sceneDescription);
391 
393  void clearAddedScenes() { m_keybindingVector.clear(); }
394 
395  agx::Callback getStepCallback() const { return m_stepCallback; }
396  void setStepCallback(agx::Callback callback) { m_stepCallback = callback; }
397 
398  bool initialized() const { return m_initialized; }
399 
400  agxOSG::SceneDecorator *getSceneDecorator() { return m_decorator; }
401 
402  virtual int run();
403 
404  void setOsgNotifyLevel(osg::NotifySeverity severity) const;
405 
410  void stop(int exitCode = 0) { m_shouldStop = true; m_exitCode = exitCode; }
411 
413  void cancelStop() { m_shouldStop = false; }
414 
416  bool shouldStop() const { return m_shouldStop; }
417 
418 
425  bool setWindowRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height);
426 
432  bool setWindowTitle(const std::string& title);
433 
435  bool breakRequested() const;
436 
437  virtual void setupViewer( bool lightingEnabled = true, bool visibleWindow = true );
438 
440 
441  //void initScene();
442 
443  osg::Group *getScene() { return m_scene.get(); }
444  void setScene(osg::Group *scene ) { m_scene = scene; }
445  osg::Group *getSceneRoot() { return m_sceneRoot.get(); }
446  osg::Group* getSceneAgxOSGRoot();
447  osg::Group *getSceneSwitch() { return m_sceneSwitch.get(); }
448 
449 #ifdef AGX_HAVE_DEPTHPEELING
450  void setEnableDepthPeeling( bool flag );
451  bool getEnableDepthPeeling() const;
452  agxOSG::DepthPeeling* getDepthPeeling();
453 #endif
454 
462  bool setEnableDebugRenderer( bool flag );
463 
466 
467  void setEnableTextDebugRendering( bool flag );
469 
470  void setEnableCaptureSyncWithSimulation( bool enableSync );
472 
473  void setEnableOSGRenderer( bool flag );
475 
476  void setEnableVSync( bool flag, bool forceUpdate = false );
477  bool getEnableVSync() const;
478 
479  void getCameraHome( agx::Vec3& eye, agx::Vec3& center, agx::Vec3& up);
480  void setCameraHome( const agx::Vec3& eye, const agx::Vec3& center, const agx::Vec3& up=agx::Vec3(0,0,1) );
481 
487  void addRenderTarget(agxOSG::RenderTarget* rtt, osg::Node *targetSceneNode=nullptr);
488 
494 
501 
502 #if defined(OSG_VERSION_GREATER_OR_EQUAL)
503 # if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
504  osgGA::CameraManipulator* getCameraManipulator();
505  const osgGA::CameraManipulator* getCameraManipulator() const;
506 #else
507  osgGA::MatrixManipulator* getCameraManipulator();
508  const osgGA::MatrixManipulator* getCameraManipulator() const;
509 #endif
510 #else
511  osgGA::MatrixManipulator* getCameraManipulator();
512  const osgGA::MatrixManipulator* getCameraManipulator() const;
513 #endif
514  agxSDK::Simulation *getSimulation() { return m_simulation.get(); }
515 
516  bool restoreFromFile( const std::string& filename );
517  void journalRenderLoader(agxSDK::Assembly *assembly, bool keyFrame);
518 
519 
521  void setAutoStepping( bool flag );
522 
524  bool getAutoStepping( ) const;
525 
526 
527  void setEnablePauseUpdate( bool flag ) { m_pauseUpdate = flag; }
528  bool getEnablePauseUpdate( ) const { return m_pauseUpdate; }
529 
535  void setRealTimeSync(bool flag);
536  bool getRealTimeSync() const;
537 
539  const std::string& getJournalConfigurationPath() const;
540  const std::string& getJournalPlaybackPath() const;
541 
543 
546 
548 
550  bool createSceneFromKey( int key );
551  bool createSceneFromIndex( int idx, bool firstStartUp = false );
552 
553 
554  void reloadScene();
557 
558  size_t getNumScenes() const;
559 
560  void step();
561 
562  void changeSolver();
563 
564  const std::string& getSaveSceneFilename() const { return m_sceneFilename; }
565 
566  osg::Group *getRoot() { return m_root.get(); }
567 
569  void initSimulation(agxSDK::Simulation *simulation = nullptr, bool initializeGraphics = true);
570  void initViewer(int width, int height, bool osgWindow = true);
571 
572  void initGraphics();
573  void initRpc();
574  bool readCFGFile();
575 
581  void stopAfter(const agx::Real stopTime);
582 
583  osgViewer::Viewer *getViewer() { return m_viewer.get(); }
584  osg::Camera *getCamera() { if (m_viewer.valid()) return m_viewer->getCamera(); else return nullptr; }
585 
586  bool hasOffscreenWindow() const;
587 
592 
596  void applyCameraData( const agxOSG::CameraData& cameraData );
597 
598  intptr_t getHWND() const;
599 
601 
602  PickHandler* getPickHandler() { return m_pickHandler; }
603  const PickHandler* getPickHandler() const { return m_pickHandler; }
604 
605  std::string getScriptFile() const { return m_scriptFile; }
606 
608  std::string getLuaFilePath() const
609  {
610  return m_luaFilePath;
611  }
612 
613  void handleReactiveScriptErrors( bool abortSimulation = true );
614 
616 
617  void clearScene();
618 
619  void setEnableSimulationDump( bool flag );
620  bool getEnableSimulationDump( ) const;
621 
623  bool updatePythonCoSimulationServer(const agx::String& filename, std::stringstream& buffer);
625 
627  void centerScene();
629 
630  bool useCoSimulation() const {return m_useCoSimulation;}
631 
632  agx::Vec3 getGravity() const { return m_gravity; }
633 
634 
635  agxOSG::ImageCapture *getImageCapture() { return m_imageCapture; }
636  const agxOSG::ImageCapture *getImageCapture() const { return m_imageCapture; }
637 
639 
640  osg::Camera *getTextureCamera() { return m_textureCamera; }
641 
642 
643  bool isCameraHomeSet() const { return m_cameraHomeSet; }
644 
646 
649 
651  void listSessionNames(const std::string& journalToList);
652 
662  double heading, double elevation, double distance,
663  int trackerMode = 0);
664 
674  const agx::Vec3& eye, const agx::Vec3& center, const agx::Vec3& up = agx::Vec3::Z_AXIS(),
675  int trackerMode = 0);
676 
679 
681 
682 
687  bool done() const;
688 
689 
694  void setQuitEventSetsDone(bool flag);
695  bool getQuitEventSetsDone() const;
696 
701 
705  void setAllowWindowResizing(bool flag);
706 
711  void takeScreenShot(const agx::String& filename="");
712 
713  void synchronizedStep(bool blocking = false);
714 
715  void stepWrapper();
716 
717  void initScene();
718  void initScene(osg::Group *root);
719 
720 
723 
725  void setJournalFormat(agx::UInt journalFormat);
726 
728  void setEnableJournal32bitMode(bool enable);
729 
731  void setEnableJournalRecord(bool enable);
732 
735 
737  void setJournalRecordPath(const agx::String& journalPath);
738 
740  void setCoordinateSystemTransform( const agx::AffineMatrix4x4& coordinateSystemTransform);
741 
744 
746  void setGridSize(const agx::Vec2& gridSize);
747 
750 
752  void setGridResolution(const agx::Vec2u gridResolution);
753 
756 
758  void setEnableGrid(bool flag);
759 
761  bool getEnableGrid() const;
762 
764  void setEnableCoordinateSystem(bool flag);
765 
768 
769  // Throttle calls to avoid excessive CPU usage
770  // Is automatically called from `executeWithoutGraphics`
772 
773  agxOSG::RenderToTexture * getVideoCaptureRendertoTexture() { return m_videoCaptureRenderToTexture; }
774 
775  std::string getProfilingJournalPath() const;
776 
777 #if AGX_USE_WEBSOCKETS()
778  agxOSG::ExampleApplicationController *getController();
779 
780  agx::UInt16 getControlChannelPort();
781  void pushParametersToControlChannel();
782  void setEnableControlChannelTickSignals(bool flag);
783  void pushFrameToRemoteViewer();
784 #endif
785 
787  void setEnableThreadTimeline(bool flag);
788  void setEnableTaskProfile(bool flag);
789  int getExitCode() { return m_exitCode; }
790 
791 #if AGX_USE_PYTHON()
792  agxPython::ScriptContextInterface* initPythonContext(agxPython::ScriptManager *scriptManager);
793 #endif
794 
795  void createVisual(agxSDK::Simulation *simulation, float detailRatio = 1.0f, bool createAxes = false);
796  void createVisual(agxSDK::Assembly *assembly, float detailRatio = 1.0f, bool createAxes = false);
797  agx::Mutex& getFrameMutex() { return m_frameMutex; }
798 
799  protected:
800 
802 
803  void drawGrid();
805 
808 
809  protected:
810  class SimulationListener;
811 
812  void execute();
814  bool executeOneStepWithoutGraphics(bool& saveAfterEnabled, agx::Real saveAfterTime, agx::HighAccuracyTimer& timer);
815 
816 
818  bool executeOneStepWithGraphics(bool& saveAfterEnabled, agx::Real saveAfterTime, agx::HighAccuracyTimer& timer);
819 
821  void journalSceneLoader(const agx::String& path);
823  void setArgumentsPostSceneCreation(); // This function will override a number of settings with their command line argument specifications
825  void applyInitialParameters(const std::string& filePath);
828 
831 
832  bool attachScripts( osg::Group* root );
833  osg::Group *executeLuaScript( const agx::String& file, const agx::String& function, bool& success );
834  osg::Group *executePythonScript( const agx::String& file, const agx::String& function, bool& success );
835  osg::Group *loadBrickModel( const agx::String& file, const agx::String& model, bool& success );
836  osg::Group *executeMPyScript(const agx::String& file, bool& success);
837 
838  osg::Group *createScene( const SceneDescription& desc, bool &success );
839 
840  osg::ref_ptr<agxOSG::SceneDecorator> m_decorator;
842  osg::ref_ptr<agxOSG::GuiEventAdapter> m_eventAdapter;
843  osg::ref_ptr<osgViewer::Viewer> m_viewer;
844 
846 
847  osg::ref_ptr<osg::Group> m_root;
848  osg::ref_ptr<osg::Group> m_sceneRoot;
849  osg::ref_ptr<osg::Group> m_scene;
850  osg::ref_ptr<osg::Switch> m_sceneSwitch;
851 
853 
855 
857 
859 
862 
865 
866  std::string m_sceneFilename;
867  std::string m_parameterFilePath;
868 
870  std::string m_cfgFileName;
871 
873 
881  bool m_agxOnly;
883  // std::string m_exportMayaAnimationPath;
884 
885 #if AGX_USE_WEBSOCKETS()
886  friend class ExampleApplicationController;
887 #endif
888  friend class AutoPauseListener;
892 
894 
895  agxCFG::ConfigScriptRef m_settings;
896 
897  std::string m_xmlPlotFile;
899 
900  std::string m_scriptFile;
905 
907 #if AGX_USE_OPENGL()
910 #endif
917  std::string m_profilingRoot;
925  bool m_vSync;
926  std::string m_luaFilePath;
927  std::string m_pythonFilePath;
934  std::string m_journalEofMode;
935  std::string m_journalRecordPath;
936  std::string m_journalSessionName;
939  // agx::UInt m_journalStride;
943 
946 
948 
949 #ifdef AGX_HAVE_DEPTHPEELING
950  osg::ref_ptr<DepthPeeling> m_depthPeeling;
951 #endif
956  osg::ref_ptr<osg::Camera> m_textureCamera;
966  bool m_didStep;
968  osg::ref_ptr<osg::GraphicsContext> m_pBuffer;
969  osg::ref_ptr<osg::Camera> m_pBufferCamera;
971 
972  public:
975  bool m_isFMU;
977  std::string m_hostName;
978 
979  protected:
985  osg::ref_ptr<osg::Geode> m_grid;
986  osg::ref_ptr<osg::MatrixTransform> m_coordinateSystem;
993 
994  std::string m_videoName;
998 
999  };
1000 
1001 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXOSG_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Only use as member allocated variable.
Definition: Value.h:279
T transform() const
Definition: Value.h:333
void setViewMatrix(const agx::Matrix4x4 &matrix)
Set the view matrix.
void setViewPort(unsigned width, unsigned height)
void setProjectionMatrix(const agx::Matrix4x4 &matrix)
Set the projection matrix.
const agx::Matrix4x4 & getViewMatrix() const
Get the view matrix.
Definition: Camera.h:188
const agx::Matrix4x4 & getProjectionMatrix() const
Get the projection matrix.
Definition: Camera.h:187
Container class for lights that is used for synchronizing light data with shaders,...
Definition: Lights.h:31
bool setLightDirection(agx::UInt index, const agx::Vec3 &direction)
bool setLightPosition(agx::UInt index, const agx::Vec4 &position)
A small argument parser class.
Class for sending serialized agxSDK::Simulation over to a client.
static CameraManipulatorFactory * s_instance
CameraManipulatorType * next(osgViewer::Viewer *viewer=nullptr)
CameraManipulatorType * create(Types type, osgViewer::GraphicsWindow *window=nullptr)
CameraManipulatorType * next(osgViewer::GraphicsWindow *window=nullptr)
CameraManipulatorType * create(osgViewer::GraphicsWindow *window=nullptr)
static CameraManipulatorFactory * instance()
CameraManipulatorType * create(Types type, osgViewer::Viewer *viewer=nullptr)
virtual void shutdown() override
Implement this method to cleanup your Singleton class.
osgViewer::GraphicsWindow * getWindow(osgViewer::Viewer *viewer, size_t num=0) const
CameraManipulatorType * create(osgViewer::Viewer *viewer=nullptr)
virtual void operator()(osg::RenderInfo &) const
CameraSynchronization(osg::Camera *mainCamera, agxGL::Camera *glCamera)
virtual ~ExampleApplicationListener() override
virtual void postFrame(ExampleApplication *app)
virtual void preFrame(ExampleApplication *app)
Class that encapsulates rendering and simulation using OpenSceneGraph.
agx::Real getTimeStamp() const
KeyBindingsVector m_keybindingVector
agxOSG::RenderProxyFactory * m_renderProxyFactory
bool init(int argc, char **argv)
RenderTargetRefVector m_renderTargetSet
agxSDK::Simulation * getSimulation()
osg::ref_ptr< osg::GraphicsContext > m_pBuffer
SceneDescription getCallback(int key)
bool getEnableSimulationDump() const
agxJson::Value extractSimulationStructureToJson()
agx::Vector< agx::String > m_timelineFormats
agxOSG::RenderProxyFactory * getRenderProxyFactory()
bool executeOneStepWithoutGraphics(bool &saveAfterEnabled, agx::Real saveAfterTime, agx::HighAccuracyTimer &timer)
bool addScene(const std::string &scriptFile, const std::string &scriptFunction, int key, bool isPartofUnitTest=true, float stopAfter=float(), bool isSlowUnittest=false)
agx::HashSet< agxCollide::GeometryPair > m_autoPausePairs
osg::Group * createScene(const SceneDescription &desc, bool &success)
void removeAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2)
bool getEnableJournalIncrementalStructure() const
bool getEnableCoordinateSystem() const
Is the visual coordinate system enabled/disabled?
agx::Vec2u getGridResolution() const
Gets the grid resolution for the visual grid.
osg::Group * loadBrickModel(const agx::String &file, const agx::String &model, bool &success)
osg::ref_ptr< osg::Switch > m_sceneSwitch
void setEnableJournal32bitMode(bool enable)
Set to true if journal should save data in 32bit float.
agxCFG::ConfigScriptRef m_settings
agxOSG::ImageCaptureRef m_imageCapture
agx::RealVector m_coSimulationOutputData
static void registerRemovedGeometry(GeometryNode *node)
void stopAfter(const agx::Real stopTime)
Lets the application stop after a certain simulation time.
void setSolverType(SolverType t)
osg::ref_ptr< osgViewer::Viewer > m_viewer
void getCameraHome(agx::Vec3 &eye, agx::Vec3 &center, agx::Vec3 &up)
osg::ref_ptr< osg::Geode > m_grid
void setOsgNotifyLevel(osg::NotifySeverity severity) const
agx::Journal * getJournal()
agx::ref_ptr< agx::Referenced > m_debugClient
StatisticsRendererRef m_statisticsRenderer
void cancelStop()
Will cancel the stop if possible. Continue the ::run loop.
bool done() const
If no graphics is used, this method always return false.
osg::ref_ptr< osg::Camera > m_pBufferCamera
std::string getProfilingJournalPath() const
void initScene(osg::Group *root)
void synchronizedStep(bool blocking=false)
bool getAutoStepping() const
Should the application step automatically? False for 'pause', true for 'play'.
SolverType getSolverType(const std::string &name) const
void setAutoStepping(bool flag)
Should the application step automatically? False for 'pause', true for 'play'.
agx::RealModeEnum m_journalRealMode
agx::Real getTimeStep() const
const agxOSG::ImageCapture * getImageCapture() const
bool attachScripts(osg::Group *root)
bool addScene(BuildScenePtr sceneFunction, int key, bool isPartofUnitTest=true, float stopAfter=float(), bool isSlowUnittest=false)
void addAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2)
Add/remove a pair of bodies/geometries that when colliding will cause the simulation to pause.
osg::Group * getSceneAgxOSGRoot()
bool addScene(SceneDescription sceneDescription)
void createVisual(agxSDK::Assembly *assembly, float detailRatio=1.0f, bool createAxes=false)
void initSimulation(agxSDK::Simulation *simulation=nullptr, bool initializeGraphics=true)
bool getEnableTextDebugRendering() const
void setEnablePauseUpdate(bool flag)
void setOrbitCamera(agxOSG::GeometryNode *node, double heading, double elevation, double distance, int trackerMode=0)
Sets an orbit camera following an node.
void createVisual(agxSDK::Simulation *simulation, float detailRatio=1.0f, bool createAxes=false)
void setOrbitCamera(agxOSG::GeometryNode *node, const agx::Vec3 &eye, const agx::Vec3 &center, const agx::Vec3 &up=agx::Vec3::Z_AXIS(), int trackerMode=0)
Sets an orbit camera following an node.
bool hasOffscreenWindow() const
void setEnableVSync(bool flag, bool forceUpdate=false)
VideoFFMPEGPipeCaptureRef m_videoCapture
void setEnableCoordinateSystem(bool flag)
Enables/disables the visual coordinate system.
osgViewer::Viewer * getViewer()
bool updatePythonCoSimulationServer(const agx::String &filename, std::stringstream &buffer)
bool getAllowWindowResizing() const
Is window resizing allowed?
void initViewer(int width, int height, bool osgWindow=true)
osg::ref_ptr< agxOSG::SceneDecorator > m_decorator
void journalRenderLoader(agxSDK::Assembly *assembly, bool keyFrame)
void setEnableTextDebugRendering(bool flag)
void listSessionNames(const std::string &journalToList)
void removeAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2)
void setEnableSimulationDump(bool flag)
agx::Vec2 getGridSize() const
Gets the grid size for the visual grid.
agx::ref_ptr< agx::Referenced > m_journal
void setScene(osg::Group *scene)
void setEnableJournalRecord(bool enable)
Set if a journal should be recorded from the simulation.
CameraMask
Specifies node masks for different parts of the rendering scene.
void journalSceneLoader(const agx::String &path)
agxSDK::ContactEventListenerRef m_autoPauseListener
agx::UInt getJournalFormat() const
Gets journal format.
bool executeOneStepWithGraphics(bool &saveAfterEnabled, agx::Real saveAfterTime, agx::HighAccuracyTimer &timer)
void handleReactiveScriptErrors(bool abortSimulation=true)
void setEnableThreadTimeline(bool flag)
std::string getScriptFile() const
osg::ref_ptr< osg::Camera > m_textureCamera
void setEnableJournalIncrementalStructure(bool enable)
bool coSimulationCallPython(agxNet::CoSimulationServer *server)
void setQuitEventSetsDone(bool flag)
If set to true (default) pressing the ESC key will exit the run loop and application will shut down.
agxOSG::SceneDecorator * getSceneDecorator()
const std::string & getJournalConfigurationPath() const
std::string m_extractSimulationStructureToJsonPath
agxOSG::CameraData getCameraData() const
osg::Group * executeLuaScript(const agx::String &file, const agx::String &function, bool &success)
osg::ref_ptr< osg::Group > m_scene
bool getEnableGrid() const
Is the visual grid enabled/disabled?
bool getQuitEventSetsDone() const
bool addScene(SceneDescription sceneDescription, int key)
void setDebugRenderInverseMatrix(const agx::AffineMatrix4x4 &m)
Transform the debug rendering AND pick handler origin by this matrix.
void setGridResolution(const agx::Vec2u gridResolution)
Sets the grid resolution for the visual grid.
ExampleApplication(agxSDK::Simulation *simulation=nullptr)
Constructor.
std::string getLuaFilePath() const
Get file path to most recent lua file.
void setCameraHome(const agx::Vec3 &eye, const agx::Vec3 &center, const agx::Vec3 &up=agx::Vec3(0, 0, 1))
agx::AffineMatrix4x4 m_coordinateSystemTransform
void setJournalConfigurationPath(const agx::String &path)
void setGridSize(const agx::Vec2 &gridSize)
Sets the grid size for the visual grid.
const PickHandler * getPickHandler() const
void applyInitialParameters(const std::string &filePath)
bool addScene(BuildScenePtr sceneFunction, bool isPartofUnitTest=true, float stopAfter=float(), bool isSlowUnittest=false)
void setStepCallback(agx::Callback callback)
void setTimeStep(agx::Real dt)
osg::ref_ptr< osg::Group > m_root
osg::ref_ptr< osg::Group > m_sceneRoot
const std::string & getJournalPlaybackPath() const
void addRenderTarget(agxOSG::RenderTarget *rtt, osg::Node *targetSceneNode=nullptr)
Add a render target to the current viewer.
void granularCreated(agxSDK::Simulation *sim, agx::RigidBody *body)
agxOSG::VideoFFMPEGPipeCapture * getVideoServerCapture()
bool init(agxIO::ArgumentParser *arguments, bool agxOnly=false)
void setEnableTaskProfile(bool flag)
bool setEnableDebugRenderer(bool flag)
Set enabling the debug renderer.
void addListener(ExampleApplicationListener *listener)
agx::ref_ptr< agx::Referenced > m_controller
void setEnableGrid(bool flag)
Enables/disables the visual grid.
bool setWindowRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
Set the position and size of the window.
size_t getNumScenes() const
osg::Group * executePythonScript(const agx::String &file, const agx::String &function, bool &success)
void applyCameraData(const agxOSG::CameraData &cameraData)
Apply camera data.
std::string getSolverName(SolverType t) const
bool createSceneFromIndex(int idx, bool firstStartUp=false)
SceneDescription getCallbackIdx(size_t idx)
virtual void setupViewer(bool lightingEnabled=true, bool visibleWindow=true)
agx::RealVector m_coSimulationInputData
agx::Vector< ExampleApplicationListenerRef > m_listeners
agxSDK::Simulation::RigidBodyEvent::CallbackType m_addBodyCallback
void setRequestedJournalFrequency(agx::Real freq)
Set the requested recording frequency for attached journal.
osg::Group * executeMPyScript(const agx::String &file, bool &success)
void removeGeometryNode(agxSDK::Simulation *, agxCollide::Geometry *)
agx::Callback getStepCallback() const
void addAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2)
agx::Vector< SceneDescription > KeyBindingsVector
void setEnableAutoPausing(bool flag)
Enable/disable auto-pausing.
osg::ref_ptr< osg::MatrixTransform > m_coordinateSystem
void setRealTimeSync(bool flag)
Should ExampleApplication try to hold simulation in real time? Will wait for wall clock if going to f...
void takeScreenShot(const agx::String &filename="")
Takes a screen shot of the scene.
const std::string & getSaveSceneFilename() const
void setJournalFormat(agx::UInt journalFormat)
Sets journal format. Only valid before starting journal recording/playback.
agx::AffineMatrix4x4 getCoordinateSystemTransform() const
Gets the transformation for the visual coordinate system and grid.
osg::ref_ptr< agxOSG::GuiEventAdapter > m_eventAdapter
void setEnableOSGRenderer(bool flag)
agx::HashTable< int, int > KeyBindings
SolverType getSolverType() const
agxOSG::ImageCapture * getImageCapture()
void setAllowWindowResizing(bool flag)
Set if window resizing should be allowed.
bool setWindowTitle(const std::string &title)
Set the title of the window.
void clearAddedScenes()
Remove all added scenes.
agxSDK::Simulation::GeometryEvent::CallbackType m_removeGeometryCallback
agx::Event1< bool > AutoStepEvent
agxIO::ArgumentParserRef m_arguments
void setCoordinateSystemTransform(const agx::AffineMatrix4x4 &coordinateSystemTransform)
Sets the transformation for the visual coordinate system and grid.
osgGA::MatrixManipulator * getCameraManipulator()
void stop(int exitCode=0)
Stop (=exit) the application at next opportunity.
agxOSG::RenderToTexture * getVideoCaptureRendertoTexture()
void setJournalRecordPath(const agx::String &journalPath)
Set the path for the recorded journal.
agxSDK::SimulationRef m_simulation
agx::ref_ptr< agx::Referenced > m_coSimulationServer
bool getEnableDebugRenderer() const
Is the debug renderer enabled? Will also return false if no simulation exists.
bool createSceneFromKey(int key)
agxIO::ArgumentParser * getArguments()
bool removeRenderTarget(agxOSG::RenderTarget *rtt)
Remove a specified renderTarget.
void setEnableCaptureSyncWithSimulation(bool enableSync)
bool restoreFromFile(const std::string &filename)
agx::Vector< std::pair< std::string, int > > m_attachedScripts
bool getEnableCaptureSyncWithSimulation() const
const osgGA::MatrixManipulator * getCameraManipulator() const
intptr_t getHWND() const
RenderToTextureRef m_videoCaptureRenderToTexture
bool addScene(const std::string &scriptFile, const std::string &scriptFunction, bool isPartofUnitTest=true, float stopAfter=float(), bool isSlowUnittest=false)
A node that can be associated with a collision geometry so that the transformation of this node is up...
Definition: GeometryNode.h:42
LightsSynchronization(agxGL::Lights *mainLights, agxOSG::SceneDecorator *decorator)
virtual void operator()(osg::RenderInfo &) const
Implementation of the abstract class from the agxRender namespace, this class is responsible for crea...
Render target is used for rendering camera content to a buffer, either a DEPTH or COLOR target.
Definition: RenderTarget.h:41
Decorates a scene with a specific AGX Rendering Style.
agxOSG::LightSource getLightSource(Lights l)
Get a wrapper for a LightSource with only AGX types.
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:67
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Block synchronization primitive.
Generalized callback, using std::function.
Definition: Callback.h:54
T CallbackType
Definition: Event.h:37
An event with no arguments.
Definition: Event.h:90
The HighAccurayTimer class can replace the regular Timer class in high level applications where the n...
Inheritance with partial specialization due to bug with ref_ptr containers.
Matrix class for affine transformations.
Definition: Matrix4x4.h:56
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:31
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:75
static Vec3T Z_AXIS()
Definition: Vec3Template.h:789
This namespace contains functionality for using AGX together with version 2 of the Functional Mockup ...
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition: MacUtil.h:23
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
AGXOSG_EXPORT osg::MatrixTransform * createAxes(agxCollide::Geometry *geometry, agx::Frame *relativeTransform, osg::Group *root, float scale=1, const agx::Vec4f &color=agx::Vec4f())
Creates osg axes relative a geometry given relative transform.
osgGA::MatrixManipulator CameraManipulatorType
osg::Group *(* BuildScenePtr)(agxSDK::Simulation *simulation, ExampleApplication *application)
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
uint16_t UInt16
Definition: Integer.h:39
RealModeEnum
The data type for basic floating point representation.
Definition: Real.h:36
std::mutex Mutex
Definition: Referenced.h:93
AGXCORE_EXPORT Component * root()
uint32_t UInt
Definition: Integer.h:34
double Real
Definition: Real.h:42
void applyTo(osgViewer::Viewer *viewer) const
Apply current settings to a viewer which assigns home position of the camera manipulator.
CameraData(const osg::Camera *camera)
Uses camera view matrix for eye, center and up.
CameraData(const osgViewer::Viewer *viewer)
Uses camera manipulator for eye, center and up.
void applyTo(osg::Camera *camera) const
Apply current settings to a camera.
A pod-struct for holding information about scenes to load by the application.
SceneDescription(const std::string &scriptFileName, const std::string &scriptFunctionName, bool isTest=false, float stop=float(), bool isSlowUnittest=false)
Creates a scene from a script file and a function within the file.
SceneDescription(BuildScenePtr sc, bool isTest=false, float stop=float(), bool isSlowUnittest=false)
Creates a scene from a function pointer.
SceneDescription()
A non-valid scene.
SceneDescription(const std::string &sceneFile, bool isTest=false, float stop=float(), bool isSlowUnittest=false)
Creates a scene from any kind of agx-readable file.