AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
ExampleApplication.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or
9having been advised so by Algoryx Simulation AB for a time limited evaluation,
10or having purchased a valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
28
29#include <agx/config.h>
30
31#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
32#include <osg/Switch>
33#include <osgViewer/Viewer>
34#include <osg/Version>
35#include <osg/ref_ptr>
36#include <osg/MatrixTransform>
37#include <agx/PopDisableWarnings.h> // End of disabled warnings.
38
39#include <agxOSG/DepthPeeling.h>
40#include <agxOSG/export.h>
42#include <agxOSG/PickHandler.h>
43#include <agxOSG/RenderTarget.h>
48
49#if AGX_USE_WEBSOCKETS()
51#endif
52
53#include <agxCFG/ConfigScript.h>
55#include <agxOSG/ImageCapture.h>
58#include <agxSDK/Simulation.h>
59
60#include <agx/Timer.h>
61#include <agx/Journal.h>
63
66
67#include <cstddef>
68
69#if AGX_USE_OPENGL()
70#include <agxGL/Camera.h>
71#include <agxGL/Lights.h>
72#endif
73
74#if AGX_USE_PYTHON()
78#endif
79
81#if AGX_USE_OPENPLX()
83namespace agxopenplx {
84 class OsgClickAdapter;
85 class LoadResult;
86}
87namespace openplx::Core {
88 class Object;
89}
90#endif
91
92#ifdef __clang__
93#pragma clang diagnostic pop
94#endif
95
96namespace osgGA
97{
98 class StandardManipulator;
99 class MatrixManipulator;
100}
101
102namespace agxFMI2
103{
104 namespace Export
105 {
106 class Module;
107 }
108}
109
110
111namespace agxSDK
112{
113 class Assembly;
114}
115
116namespace agxNet
117{
118 class CoSimulationServer;
119}
120
121namespace agxOSG {
122 class ExampleApplication;
123 class SceneDecorator;
124 class RenderProxyFactory;
125 class GeometryNode;
126#if AGX_USE_WEBSOCKETS()
127 class ExampleApplicationController;
128#endif
129
130 typedef osg::Group * (*BuildScenePtr)(agxSDK::Simulation *simulation, ExampleApplication *application);
131
134
137
139 SceneDescription(BuildScenePtr sc, bool isTest = false, float stop = -1, bool isSlowUnittest = false);
140
142 SceneDescription(const std::string& scriptFileName, const std::string& scriptFunctionName, bool isTest = false, float stop = -1, bool isSlowUnittest = false);
143
145 SceneDescription(const std::string& sceneFile, bool isTest = false, float stop = -1, bool isSlowUnittest = false);
146
147 bool isValid() const { return valid; }
148
149
154 bool valid;
155 std::string scriptFunction;
156 std::string fileName;
157 };
158
159
160#if defined(OSG_VERSION_GREATER_OR_EQUAL)
161# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
162 typedef osgGA::StandardManipulator CameraManipulatorType;
163# else
164 typedef osgGA::MatrixManipulator CameraManipulatorType;
165# endif
166#else
167 typedef osgGA::MatrixManipulator CameraManipulatorType;
168#endif
169
170
171
172#if AGX_USE_OPENGL()
173 class CameraSynchronization : public osg::Camera::DrawCallback
174 {
175 public:
176 CameraSynchronization(osg::Camera *mainCamera, agxGL::Camera *glCamera) : m_mainCamera(mainCamera), m_glCamera(glCamera)
177 {
178 }
179
181 {
182 }
183
184 virtual void operator () (osg::RenderInfo& /* renderInfo */) const
185 {
186 // Explicit support for Real=float agx with Real=double osg
187 agxData::Val<agx::Matrix4x4d> projection(agx::Matrix4x4d(m_mainCamera->getProjectionMatrix().ptr()));
188 agx::Matrix4x4 m = projection.transform<agx::Matrix4x4 > ();
189
190 if (m != m_glCamera->getProjectionMatrix())
191 m_glCamera->setProjectionMatrix(m);
192
193 agxData::Val<agx::Matrix4x4d> view(agx::Matrix4x4d(m_mainCamera->getViewMatrix().ptr()));
195
196 if (m2 != m_glCamera->getViewMatrix())
197 m_glCamera->setViewMatrix(m2);
198
199 auto viewport = m_mainCamera->getViewport();
200 m_glCamera->setViewPort(static_cast<int>(viewport->width()), static_cast<int>(m_mainCamera->getViewport()->height()));
201 }
202 using osg::Camera::DrawCallback::operator();
203
204 private:
205 osg::Camera *m_mainCamera;
206 agxGL::Camera *m_glCamera;
207 };
208
209 class LightsSynchronization : public osg::Camera::DrawCallback
210 {
211 public:
213 : m_glLights(mainLights),
214 m_decorator(decorator)
215 {
216 }
217
219 {
220 }
221
222 virtual void operator () (osg::RenderInfo& /* renderInfo */) const
223 {
224
225 auto updateLight = [this](size_t index, agxOSG::LightSource l)
226 {
227 m_glLights->setLightPosition(index, l.getPosition());
228 m_glLights->setLightDirection(index, l.getDirection());
229 };
230
231 updateLight(0, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT0));
232 updateLight(1, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT1));
233 updateLight(2, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT2));
234 }
235
236 using osg::Camera::DrawCallback::operator();
237
238 private:
239 agxGL::Lights *m_glLights;
240 SceneDecorator *m_decorator;
241 };
242#endif
243
245 {
246 public:
248#if defined(OSG_VERSION_GREATER_OR_EQUAL)
249# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
250 FPS,
251# endif
252#endif
253 NUM_TYPES };
254
256
258
259 CameraManipulatorType* next( osgViewer::Viewer* viewer = nullptr );
260 CameraManipulatorType* next( osgViewer::GraphicsWindow* window = nullptr );
261 CameraManipulatorType* create( osgViewer::Viewer* viewer = nullptr );
262 CameraManipulatorType* create( Types type, osgViewer::Viewer* viewer = nullptr );
263 CameraManipulatorType* create( Types type, osgViewer::GraphicsWindow* window = nullptr );
264 CameraManipulatorType* create( osgViewer::GraphicsWindow* window = nullptr );
265
266 void setType( Types type ) { m_currentType = type; }
267 Types getType() const { return m_currentType; }
268
269 protected:
270 SINGLETON_CLASSNAME_METHOD();
271 virtual void shutdown() override { s_instance = nullptr; }
272 osgViewer::GraphicsWindow* getWindow( osgViewer::Viewer* viewer, size_t num = 0 ) const;
273
276 };
277
279 {
283 CameraData( const osg::Camera* camera );
284
288 CameraData( const osgViewer::Viewer* viewer );
289
293 void applyTo( osg::Camera* camera ) const;
294
298 void applyTo( osgViewer::Viewer* viewer ) const;
299
304 bool valid;
306
310
311 private:
312 CameraData();
313 void initialize( const osg::Camera* camera );
314 };
315
318
319 public:
320 virtual void preFrame(ExampleApplication* app);
321 virtual void postFrame(ExampleApplication* app);
322
323 protected:
324 virtual ~ExampleApplicationListener() override;
325 };
326
327
329
334 {
335 public:
338
345 {
346 MAIN_SCENE_MASK = 1 << 1,
347 DEBUG_RENDER_MASK = 1 << 2,
348 OSG_RENDER_MASK = 1 << 3,
349 HUD_MASK = 1 << 4,
350 DECORATOR_MASK = 1 << 5,
351 CASTS_SHADOWS_MASK = 1 << 6,
352 RECIEVES_SHADOWS_MASK = 1 << 7
353 };
354
356 {
357 MULTI, // New.
358 ITERATIVE, // New forced to iterative.
359 NUM_SOLVERS
360 };
361
362
363 void setSolverType( SolverType t ) { m_solverType = t; }
364 SolverType getSolverType() const { return m_solverType; }
365
366 std::string getSolverName( SolverType t ) const;
367 SolverType getSolverType( const std::string& name ) const;
368
372 void addAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2);
373 void addAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2);
374 void removeAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2);
375 void removeAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2);
376
380 void setEnableAutoPausing(bool flag);
382
385
386 bool init( agxIO::ArgumentParser* arguments, bool agxOnly = false );
387
389
390#ifndef SWIG
391 bool init( int argc, char** argv );
392#endif
393
394 agxIO::ArgumentParser* getArguments() { return m_arguments.get(); }
395
396 agxOSG::RenderProxyFactory *getRenderProxyFactory() { return m_renderProxyFactory; }
397
400
401 bool addScene( const std::string& scriptFile, const std::string& scriptFunction, int key, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
402 bool addScene( const std::string& scriptFile, const std::string& scriptFunction, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
403
404 bool addScene( BuildScenePtr sceneFunction, int key, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
405 bool addScene( BuildScenePtr sceneFunction, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
406
407 bool addScene( SceneDescription sceneDescription, int key);
408 bool addScene( SceneDescription sceneDescription);
409
412 #if AGX_USE_OPENPLX()
413 m_openplxSceneVector.clear();
414 #endif
415 m_keybindingVector.clear();
416 }
417
418 agx::Callback getStepCallback() const { return m_stepCallback; }
419 void setStepCallback(agx::Callback callback) { m_stepCallback = callback; }
420
421 bool initialized() const { return m_initialized; }
422
423 agxOSG::SceneDecorator *getSceneDecorator() { return m_decorator; }
424
425 virtual int run();
426
427 void setOsgNotifyLevel(osg::NotifySeverity severity) const;
428
440 osg::Group* executePythonScript(const agx::String& file, const agx::String& function, bool& success);
441
446 void stop(int exitCode = 0) { m_shouldStop = true; m_exitCode = exitCode; }
447
449 void cancelStop() { m_shouldStop = false; }
450
452 bool shouldStop() const { return m_shouldStop; }
453
460 bool setWindowRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height);
461
467 bool setWindowTitle(const std::string& title);
468
470 bool breakRequested() const;
471
472 virtual void setupViewer( bool lightingEnabled = true, bool visibleWindow = true );
473
476
477 //void initScene();
478
479 osg::Group *getScene() { return m_scene.get(); }
480 void setScene(osg::Group *scene ) { m_scene = scene; }
481 osg::Group *getSceneRoot() { return m_sceneRoot.get(); }
482 osg::Group* getSceneAgxOSGRoot();
483 osg::Group *getSceneSwitch() { return m_sceneSwitch.get(); }
484
485#ifdef AGX_HAVE_DEPTHPEELING
486 void setEnableDepthPeeling( bool flag );
487 bool getEnableDepthPeeling() const;
488 agxOSG::DepthPeeling* getDepthPeeling();
489#endif
490
498 bool setEnableDebugRenderer( bool flag );
499
502
505
506 void setEnableCaptureSyncWithSimulation( bool enableSync );
508
509 void setEnableOSGRenderer( bool flag );
511
512 void setEnableVSync( bool flag, bool forceUpdate = false );
513 bool getEnableVSync() const;
514
515 void getCameraHome( agx::Vec3& eye, agx::Vec3& center, agx::Vec3& up);
516 void setCameraHome( const agx::Vec3& eye, const agx::Vec3& center, const agx::Vec3& up=agx::Vec3(0,0,1) );
517
523 bool hasRenderContext() const;
524
530 void addRenderTarget(agxOSG::RenderTarget* rtt, osg::Node *targetSceneNode=nullptr);
531
537
544
545#if defined(OSG_VERSION_GREATER_OR_EQUAL)
546# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
547 osgGA::CameraManipulator* getCameraManipulator();
548 const osgGA::CameraManipulator* getCameraManipulator() const;
549#else
550 osgGA::MatrixManipulator* getCameraManipulator();
551 const osgGA::MatrixManipulator* getCameraManipulator() const;
552#endif
553#else
554 osgGA::MatrixManipulator* getCameraManipulator();
555 const osgGA::MatrixManipulator* getCameraManipulator() const;
556#endif
557 agxSDK::Simulation *getSimulation() { return m_simulation.get(); }
558
559 bool restoreFromFile( const std::string& filename );
560 void journalRenderLoader(agxSDK::Assembly *assembly, bool keyFrame);
561
562
569 void setAutoStepping( bool flag, bool resetTimer = true );
570
572 bool getAutoStepping( ) const;
573
574
575 void setEnablePauseUpdate( bool flag ) { m_pauseUpdate = flag; }
576 bool getEnablePauseUpdate( ) const { return m_pauseUpdate; }
577
583 void setRealTimeSync(bool flag);
584 bool getRealTimeSync() const;
585
587 const std::string& getJournalConfigurationPath() const;
588 const std::string& getJournalPlaybackPath() const;
589
591
594
596
598 bool createSceneFromKey( int key );
599 bool createSceneFromIndex( int idx, bool firstStartUp = false );
600
601
605
606 size_t getNumScenes() const;
607
608 void step();
609
611
612 const std::string& getSaveSceneFilename() const { return m_sceneFilename; }
613
614 osg::Group *getRoot() { return m_root.get(); }
615
617 void initSimulation(agxSDK::Simulation *simulation = nullptr, bool initializeGraphics = true);
618 void initViewer(int width, int height, bool osgWindow = true);
619
621 void initRpc();
622
628 void stopAfter(const agx::Real stopTime);
629
630 osgViewer::Viewer *getViewer() { return m_viewer.get(); }
631 osg::Camera *getCamera() { if (m_viewer.valid()) return m_viewer->getCamera(); else return nullptr; }
632
633 bool hasOffscreenWindow() const;
634
639
643 void applyCameraData( const agxOSG::CameraData& cameraData );
644
645 intptr_t getHWND() const;
646
648
649 PickHandler* getPickHandler() { return m_pickHandler; }
650 const PickHandler* getPickHandler() const { return m_pickHandler; }
651
652 std::string getScriptFile() const { return m_scriptFile; }
653
654 void handleReactiveScriptErrors( bool abortSimulation = true );
655
657
659
660 void setEnableSimulationDump( bool flag );
662
664 bool updatePythonCoSimulationServer(const agx::String& filename, std::stringstream& buffer);
666
670
671 bool useCoSimulation() const {return m_useCoSimulation;}
672
673 agx::Vec3 getGravity() const { return m_gravity; }
674
675
676 agxOSG::ImageCapture *getImageCapture() { return m_imageCapture; }
677 const agxOSG::ImageCapture *getImageCapture() const { return m_imageCapture; }
678
680
681 osg::Camera *getTextureCamera() { return m_textureCamera; }
682
683
684 bool isCameraHomeSet() const { return m_cameraHomeSet; }
685
687
691
693 void listSessionNames(const std::string& journalToList);
694
704 double heading, double elevation, double distance,
705 int trackerMode = 0);
706
716 const agx::Vec3& eye, const agx::Vec3& center, const agx::Vec3& up = agx::Vec3::Z_AXIS(),
717 int trackerMode = 0);
718
726
728
730
731
736 bool done() const;
737
738
743 void setQuitEventSetsDone(bool flag);
745
750
754 void setAllowWindowResizing(bool flag);
755
760 void takeScreenShot(const agx::String& filename="");
761
762 void synchronizedStep(bool blocking = false);
763
765
766 void initScene();
767 void initScene(osg::Group *root);
768
769
772
774 void setJournalFormat(agx::UInt journalFormat);
775
777 void setEnableJournal32bitMode(bool enable);
778
780 void setEnableJournalRecord(bool enable);
781
784
786 void setJournalRecordPath(const agx::String& journalPath);
787
789 void setCoordinateSystemTransform( const agx::AffineMatrix4x4& coordinateSystemTransform);
790
793
795 void setGridSize(const agx::Vec2& gridSize);
796
799
801 void setGridResolution(const agx::Vec2u gridResolution);
802
805
807 void setEnableGrid(bool flag);
808
810 bool getEnableGrid() const;
811
814
817
818 // Throttle calls to avoid excessive CPU usage
819 // Is automatically called from `executeWithoutGraphics`
821
822 agxOSG::RenderToTexture * getVideoCaptureRendertoTexture() { return m_videoCaptureRenderToTexture; }
823
824 std::string getProfilingJournalPath() const;
825
826#if AGX_USE_WEBSOCKETS()
827 agxOSG::ExampleApplicationController *getController();
828
829 agx::UInt16 getControlChannelPort();
830 void pushParametersToControlChannel();
831 void setEnableControlChannelTickSignals(bool flag);
832 void pushFrameToRemoteViewer();
833#endif
834
836 void setEnableThreadTimeline(bool flag);
837 void setEnableTaskProfile(bool flag);
838 int getExitCode() { return m_exitCode; }
839
840#if AGX_USE_PYTHON()
841 agxPython::ScriptContextInterface* initPythonContext(agxPython::ScriptManager *scriptManager);
842#endif
843
844 void createVisual(agxSDK::Simulation *simulation, float detailRatio = 1.0f, bool createAxes = false);
845 void createVisual(agxSDK::Assembly *assembly, float detailRatio = 1.0f, bool createAxes = false);
846 agx::Mutex& getFrameMutex() { return m_frameMutex; }
847
852 void setTargetFPS(double fps);
853
857 double getTargetFPS();
858
859#if AGX_USE_OPENPLX()
866 agxopenplx::LoadResult loadOpenPlxFile(std::string filePath, osg::Group* root, agxopenplx::OptParams optionalParameters = agxopenplx::OptParams());
867
873 std::vector<std::string> getOpenPlxBundlePaths(const std::vector<std::string>& extraBundlePaths = {});
874
878 std::string getOpenPlxModelName();
879
884 void setOpenPlxModelName(std::string modelName);
885
889 bool getOpenPlxDebugRenderFrames();
890
894 bool getOpenPlxUseClick();
895
899 std::string getOpenPlxClickServerAddr();
900#endif
901
902 protected:
903
904 bool initArguments(agxIO::ArgumentParser* arguments, bool agxOnly);
906
908
909 void drawGrid();
911
915
916 protected:
917 class SimulationListener;
918
922 bool timeToStop() const;
923
924
925 void execute();
927 bool executeOneStepWithoutGraphics(bool& saveAfterEnabled, agx::Real saveAfterTime, agx::HighAccuracyTimer& timer);
928
929
931 bool executeOneStepWithGraphics(bool& saveAfterEnabled, agx::Real saveAfterTime, agx::HighAccuracyTimer& timer);
932
936 void setArgumentsPostSceneCreation(); // This function will override a number of settings with their command line argument specifications
938 void applyInitialParameters(const std::string& filePath);
940
943
944 bool attachScripts( osg::Group* root );
945 osg::Group *executeMPyScript(const agx::String& file, bool& success);
946
947 osg::Group *createScene( const SceneDescription& desc, bool &success );
948
950
951 osg::ref_ptr<agxOSG::SceneDecorator> m_decorator;
953 osg::ref_ptr<agxOSG::GuiEventAdapter> m_eventAdapter;
954 osg::ref_ptr<osgViewer::Viewer> m_viewer;
955
957
958 osg::ref_ptr<osg::Group> m_root;
959 osg::ref_ptr<osg::Group> m_sceneRoot;
960 osg::ref_ptr<osg::Group> m_scene;
961 osg::ref_ptr<osg::Switch> m_sceneSwitch;
962#if AGX_USE_AGXSENSOR()
963 osg::ref_ptr<osg::Group> m_cameraSubRoot;
964#endif
965
967
969
971
973
976
979
980 std::string m_sceneFilename;
982
984
986
997 // std::string m_exportMayaAnimationPath;
998
999#if AGX_USE_WEBSOCKETS()
1000 friend class ExampleApplicationController;
1001#endif
1002 friend class AutoPauseListener;
1006
1008
1009 agxCFG::ConfigScriptRef m_settings;
1010
1011 std::string m_xmlPlotFile;
1013
1014 std::string m_scriptFile;
1019
1021#if AGX_USE_OPENGL()
1024#endif
1031 std::string m_profilingRoot;
1040 std::string m_pythonFilePath;
1047 std::string m_journalEofMode;
1052 // agx::UInt m_journalStride;
1056
1059
1061
1063
1064#ifdef AGX_HAVE_DEPTHPEELING
1065 osg::ref_ptr<DepthPeeling> m_depthPeeling;
1066#endif
1071 osg::ref_ptr<osg::Camera> m_textureCamera;
1083 osg::ref_ptr<osg::GraphicsContext> m_pBuffer;
1084 osg::ref_ptr<osg::Camera> m_pBufferCamera;
1086
1087 // OpenPLX cmdline
1088 bool m_openplxUseClick = false;
1089 std::string m_openplxClickServerAddr = "tcp://*:5555";
1090 std::vector<std::string> m_openplxAddBundlePath;
1091 bool m_openplxDebugRenderFrames = false;
1092 bool m_openplxEnableDebugLogs = false;
1093 bool m_openplxSnapReport = false;
1094 bool m_openplxSnapReportMermaid = false;
1097 std::string m_openplxUuidv5;
1098#if AGX_USE_OPENPLX()
1099 std::vector<std::shared_ptr<openplx::Core::Object>> m_openplxSceneVector;
1100 std::unique_ptr<agxopenplx::OsgClickAdapter> m_openplxClickAdapter;
1101#endif
1102
1103 public:
1108 std::string m_hostName;
1109
1110 protected:
1116 osg::ref_ptr<osg::Geode> m_grid;
1117 osg::ref_ptr<osg::MatrixTransform> m_coordinateSystem;
1126
1127 std::string m_videoName;
1132
1137 };
1138
1139}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXOSG_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Only use as member allocated variable.
Definition: Value.h:285
T transform() const
Definition: Value.h:339
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: agxGL/Camera.h:188
const agx::Matrix4x4 & getProjectionMatrix() const
Get the projection matrix.
Definition: agxGL/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 * create(Types type, osgViewer::GraphicsWindow *window=nullptr)
CameraManipulatorType * next(osgViewer::GraphicsWindow *window=nullptr)
CameraManipulatorType * next(osgViewer::Viewer *viewer=nullptr)
CameraManipulatorType * create(osgViewer::GraphicsWindow *window=nullptr)
osgViewer::GraphicsWindow * getWindow(osgViewer::Viewer *viewer, size_t num=0) const
virtual void shutdown() override
Implement this method to cleanup your Singleton class.
CameraManipulatorType * create(osgViewer::Viewer *viewer=nullptr)
CameraManipulatorType * create(Types type, osgViewer::Viewer *viewer=nullptr)
static CameraManipulatorFactory * instance()
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
agx::Real calculateStopTime(const SceneDescription &desc)
agxOSG::RenderProxyFactory * m_renderProxyFactory
osgGA::MatrixManipulator * getCameraManipulator()
bool init(int argc, char **argv)
RenderTargetRefVector m_renderTargetSet
osg::ref_ptr< osg::GraphicsContext > m_pBuffer
SceneDescription getCallback(int key)
bool getEnableSimulationDump() const
agxJson::Value extractSimulationStructureToJson()
agx::Vector< agx::String > m_timelineFormats
bool executeOneStepWithoutGraphics(bool &saveAfterEnabled, agx::Real saveAfterTime, agx::HighAccuracyTimer &timer)
agx::HashSet< agxCollide::GeometryPair > m_autoPausePairs
osg::ref_ptr< osg::Group > m_cameraSubRoot
void removeAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2)
bool getEnableJournalIncrementalStructure() const
bool getEnableCoordinateSystem() const
Is the visual coordinate system enabled/disabled?
RenderToTextureRef m_imageCaptureRenderToTexture
agx::Vec2u getGridResolution() const
Gets the grid resolution for the visual grid.
agxOSG::RenderProxyFactory * getRenderProxyFactory()
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::Journal * getJournal()
void initRemoteCommandServer(agxIO::ArgumentParser *arguments)
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)
agxSDK::Simulation * getSimulation()
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::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 setTargetFPS(double fps)
Specify number of graphic window updates per second.
agx::RealModeEnum m_journalRealMode
const PickHandler * getPickHandler() const
agx::Real getTimeStep() const
osg::Group * executeMPyScript(const agx::String &file, bool &success)
bool attachScripts(osg::Group *root)
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.
bool hasRenderContext() const
This is will return false if -a / –agxOnly is specified.
osgViewer::Viewer * getViewer()
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.
osg::Group * createScene(const SceneDescription &desc, bool &success)
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 foundIncrementalArchive(agx::Journal *journal)
void setEnableTextDebugRendering(bool flag)
void listSessionNames(const std::string &journalToList)
void removeAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2)
agxOSG::VideoFFMPEGPipeCapture * getVideoServerCapture()
void setEnableSimulationDump(bool flag)
agx::Vec2 getGridSize() const
Gets the grid size for the visual grid.
agxOSG::SceneDecorator * getSceneDecorator()
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)
bool addScene(const std::string &scriptFile, const std::string &scriptFunction, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false)
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)
agxOSG::RigidBodyRenderCacheRef m_cache
void setQuitEventSetsDone(bool flag)
If set to true (default) pressing the ESC key will exit the run loop and application will shut down.
agxOSG::RenderToTexture * getVideoCaptureRendertoTexture()
std::string m_extractSimulationStructureToJsonPath
agxOSG::CameraData getCameraData() const
osg::ref_ptr< osg::Group > m_scene
bool getEnableGrid() const
Is the visual grid enabled/disabled?
const std::string & getJournalPlaybackPath() const
bool getQuitEventSetsDone() const
double getTargetFPS()
Retrieve current number of graphic window updates per second, if <= 0 no throttling is done.
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.
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.
osg::Group * getSceneAgxOSGRoot()
std::vector< std::string > m_openplxAddBundlePath
const agxOSG::ImageCapture * getImageCapture() const
void setAutoStepping(bool flag, bool resetTimer=true)
Should the application step automatically? False for 'pause', true for 'play'.
void applyInitialParameters(const std::string &filePath)
void setStepCallback(agx::Callback callback)
void setTimeStep(agx::Real dt)
osg::ref_ptr< osg::Group > m_root
osg::ref_ptr< osg::Group > m_sceneRoot
bool addScene(BuildScenePtr sceneFunction, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false)
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)
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 addScene(const std::string &scriptFile, const std::string &scriptFunction, int key, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false)
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
agxIO::ArgumentParser * getArguments()
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
const osgGA::MatrixManipulator * getCameraManipulator() const
agxSDK::Simulation::RigidBodyEvent::CallbackType m_addBodyCallback
void setRequestedJournalFrequency(agx::Real freq)
Set the requested recording frequency for attached journal.
agxSDK::GraphicsThrottler m_gfxThrottler
void removeGeometryNode(agxSDK::Simulation *, agxCollide::Geometry *)
agx::Journal::FrameJumpEvent::CallbackType m_foundIncrementalArchiveCallback
osg::Group * executePythonScript(const agx::String &file, const agx::String &function, bool &success)
Execute a python script file with a named function.
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.
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
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
const std::string & getSaveSceneFilename() const
bool executeOneStepWithGraphics(agx::HighAccuracyTimer &timer)
This method will take a whole step in AGX, update graphics (but only if target FPS is met based on el...
agx::Event1< bool > AutoStepEvent
bool addScene(BuildScenePtr sceneFunction, int key, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false)
agxIO::ArgumentParserRef m_arguments
void setCoordinateSystemTransform(const agx::AffineMatrix4x4 &coordinateSystemTransform)
Sets the transformation for the visual coordinate system and grid.
void stop(int exitCode=0)
Stop (=exit) the application at next opportunity.
void setJournalRecordPath(const agx::String &journalPath)
Set the path for the recorded journal.
agxSDK::SimulationRef m_simulation
agxOSG::ImageCapture * getImageCapture()
agx::ref_ptr< agx::Referenced > m_coSimulationServer
bool getEnableDebugRenderer() const
Is the debug renderer enabled? Will also return false if no simulation exists.
bool initArguments(agxIO::ArgumentParser *arguments, bool agxOnly)
bool createSceneFromKey(int key)
const std::string & getJournalConfigurationPath() const
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
agx::HighAccuracyTimer m_stepTimer
bool getEnableCaptureSyncWithSimulation() const
intptr_t getHWND() const
RenderToTextureRef m_videoCaptureRenderToTexture
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:70
Class to throttle a task to a specific frequency (fps).
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Block synchronization primitive.
Generalized callback, using std::function.
Definition: Callback.h:54
An event with one argument.
Definition: Event.h:103
T CallbackType
Definition: Event.h:37
An event with no arguments.
Definition: Event.h:90
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: agx/HashSet.h:670
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:58
Base class providing referencing counted objects.
Definition: Referenced.h:120
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:49
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:62
static Vec3T Z_AXIS()
Definition: Vec3Template.h:783
Templated vector class.
Definition: agx/Vector.h:53
The return type of functions that load a .openplx file.
Definition: AgxOpenPlxApi.h:45
modelName - if set a specific model from the source/file will be loaded instead of the default uuidv5...
Definition: OptParams.h:25
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.
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:31
RealModeEnum
The data type for basic floating point representation.
Definition: Real.h:35
std::mutex Mutex
Definition: Referenced.h:99
uint64_t UInt
Definition: Integer.h:27
double Real
Definition: Real.h:41
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 &sceneFile, bool isTest=false, float stop=-1, bool isSlowUnittest=false)
Creates a scene from any kind of agx-readable file.
SceneDescription(const std::string &scriptFileName, const std::string &scriptFunctionName, bool isTest=false, float stop=-1, bool isSlowUnittest=false)
Creates a scene from a script file and a function within the file.
SceneDescription()
A non-valid scene.
SceneDescription(BuildScenePtr sc, bool isTest=false, float stop=-1, bool isSlowUnittest=false)
Creates a scene from a function pointer.