AGX Dynamics 2.42.1.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
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>
41#include <agxOSG/PickHandler.h>
42#include <agxOSG/RenderTarget.h>
47
48#if AGX_USE_WEBSOCKETS()
50#endif
51
52#include <agxSDK/Simulation.h>
56#include <agxOSG/ImageCapture.h>
57#include <agxCFG/ConfigScript.h>
58
59#include <agx/Timer.h>
60#include <agx/Journal.h>
62
65
66#include <cstddef>
67
68#if AGX_USE_OPENGL()
69#include <agxGL/Camera.h>
70#include <agxGL/Lights.h>
71#endif
72
73#if AGX_USE_PYTHON()
77#endif
78
80#if AGX_USE_OPENPLX()
82namespace agxopenplx {
83 class OsgClickAdapter;
84 class LoadResult;
85}
86namespace openplx::Core {
87 class Object;
88}
89#endif
90
91#ifdef __clang__
92#pragma clang diagnostic pop
93#endif
94
95namespace osgGA
96{
97 class StandardManipulator;
98 class MatrixManipulator;
99}
100
101namespace agxFMI2
102{
103 namespace Export
104 {
105 class Module;
106 }
107}
108
109
110namespace agxSDK
111{
112 class Assembly;
113}
114
115namespace agxNet
116{
117 class CoSimulationServer;
118}
119
120namespace agxOSG {
121 class ExampleApplication;
122 class SceneDecorator;
123 class RenderProxyFactory;
124 class GeometryNode;
125#if AGX_USE_WEBSOCKETS()
126 class ExampleApplicationController;
127#endif
128
129 typedef osg::Group * (*BuildScenePtr)(agxSDK::Simulation *simulation, ExampleApplication *application);
130
133
136
138 SceneDescription(BuildScenePtr sc, bool isTest = false, float stop = -1, bool isSlowUnittest = false);
139
141 SceneDescription(const std::string& scriptFileName, const std::string& scriptFunctionName, bool isTest = false, float stop = -1, bool isSlowUnittest = false);
142
144 SceneDescription(const std::string& sceneFile, bool isTest = false, float stop = -1, bool isSlowUnittest = false);
145
146 bool isValid() const { return valid; }
147
148
153 bool valid;
154 std::string scriptFunction;
155 std::string fileName;
156 };
157
158
159#if defined(OSG_VERSION_GREATER_OR_EQUAL)
160# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
161 typedef osgGA::StandardManipulator CameraManipulatorType;
162# else
163 typedef osgGA::MatrixManipulator CameraManipulatorType;
164# endif
165#else
166 typedef osgGA::MatrixManipulator CameraManipulatorType;
167#endif
168
169
170
171#if AGX_USE_OPENGL()
172 class CameraSynchronization : public osg::Camera::DrawCallback
173 {
174 public:
175 CameraSynchronization(osg::Camera *mainCamera, agxGL::Camera *glCamera) : m_mainCamera(mainCamera), m_glCamera(glCamera)
176 {
177 }
178
180 {
181 }
182
183 virtual void operator () (osg::RenderInfo& /* renderInfo */) const
184 {
185 // Explicit support for Real=float agx with Real=double osg
186 agxData::Val<agx::Matrix4x4d> projection(agx::Matrix4x4d(m_mainCamera->getProjectionMatrix().ptr()));
187 agx::Matrix4x4 m = projection.transform<agx::Matrix4x4 > ();
188
189 if (m != m_glCamera->getProjectionMatrix())
190 m_glCamera->setProjectionMatrix(m);
191
192 agxData::Val<agx::Matrix4x4d> view(agx::Matrix4x4d(m_mainCamera->getViewMatrix().ptr()));
194
195 if (m2 != m_glCamera->getViewMatrix())
196 m_glCamera->setViewMatrix(m2);
197
198 auto viewport = m_mainCamera->getViewport();
199 m_glCamera->setViewPort(static_cast<int>(viewport->width()), static_cast<int>(m_mainCamera->getViewport()->height()));
200 }
201 using osg::Camera::DrawCallback::operator();
202
203 private:
204 osg::Camera *m_mainCamera;
205 agxGL::Camera *m_glCamera;
206 };
207
208 class LightsSynchronization : public osg::Camera::DrawCallback
209 {
210 public:
212 : m_glLights(mainLights),
213 m_decorator(decorator)
214 {
215 }
216
218 {
219 }
220
221 virtual void operator () (osg::RenderInfo& /* renderInfo */) const
222 {
223
224 auto updateLight = [this](size_t index, agxOSG::LightSource l)
225 {
226 m_glLights->setLightPosition(index, l.getPosition());
227 m_glLights->setLightDirection(index, l.getDirection());
228 };
229
230 updateLight(0, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT0));
231 updateLight(1, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT1));
232 updateLight(2, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT2));
233 }
234
235 using osg::Camera::DrawCallback::operator();
236
237 private:
238 agxGL::Lights *m_glLights;
239 SceneDecorator *m_decorator;
240 };
241#endif
242
244 {
245 public:
247#if defined(OSG_VERSION_GREATER_OR_EQUAL)
248# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
249 FPS,
250# endif
251#endif
252 NUM_TYPES };
253
255
257
258 CameraManipulatorType* next( osgViewer::Viewer* viewer = nullptr );
259 CameraManipulatorType* next( osgViewer::GraphicsWindow* window = nullptr );
260 CameraManipulatorType* create( osgViewer::Viewer* viewer = nullptr );
261 CameraManipulatorType* create( Types type, osgViewer::Viewer* viewer = nullptr );
262 CameraManipulatorType* create( Types type, osgViewer::GraphicsWindow* window = nullptr );
263 CameraManipulatorType* create( osgViewer::GraphicsWindow* window = nullptr );
264
265 void setType( Types type ) { m_currentType = type; }
266 Types getType() const { return m_currentType; }
267
268 protected:
269 SINGLETON_CLASSNAME_METHOD();
270 virtual void shutdown() override { s_instance = nullptr; }
271 osgViewer::GraphicsWindow* getWindow( osgViewer::Viewer* viewer, size_t num = 0 ) const;
272
275 };
276
278 {
282 CameraData( const osg::Camera* camera );
283
287 CameraData( const osgViewer::Viewer* viewer );
288
292 void applyTo( osg::Camera* camera ) const;
293
297 void applyTo( osgViewer::Viewer* viewer ) const;
298
303 bool valid;
305
309
310 private:
311 CameraData();
312 void initialize( const osg::Camera* camera );
313 };
314
317
318 public:
319 virtual void preFrame(ExampleApplication* app);
320 virtual void postFrame(ExampleApplication* app);
321
322 protected:
323 virtual ~ExampleApplicationListener() override;
324 };
325
326
328
333 {
334 public:
337
344 {
345 MAIN_SCENE_MASK = 1 << 1,
346 DEBUG_RENDER_MASK = 1 << 2,
347 OSG_RENDER_MASK = 1 << 3,
348 HUD_MASK = 1 << 4,
349 DECORATOR_MASK = 1 << 5,
350 CASTS_SHADOWS_MASK = 1 << 6,
351 RECIEVES_SHADOWS_MASK = 1 << 7
352 };
353
355 {
356 MULTI, // New.
357 ITERATIVE, // New forced to iterative.
358 NUM_SOLVERS
359 };
360
361
362 void setSolverType( SolverType t ) { m_solverType = t; }
363 SolverType getSolverType() const { return m_solverType; }
364
365 std::string getSolverName( SolverType t ) const;
366 SolverType getSolverType( const std::string& name ) const;
367
371 void addAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2);
372 void addAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2);
373 void removeAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2);
374 void removeAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2);
375
379 void setEnableAutoPausing(bool flag);
381
384
385 bool init( agxIO::ArgumentParser* arguments, bool agxOnly = false );
386
388
389#ifndef SWIG
390 bool init( int argc, char** argv );
391#endif
392
393 agxIO::ArgumentParser* getArguments() { return m_arguments.get(); }
394
395 agxOSG::RenderProxyFactory *getRenderProxyFactory() { return m_renderProxyFactory; }
396
399
400 bool addScene( const std::string& scriptFile, const std::string& scriptFunction, int key, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
401 bool addScene( const std::string& scriptFile, const std::string& scriptFunction, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
402
403 bool addScene( BuildScenePtr sceneFunction, int key, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
404 bool addScene( BuildScenePtr sceneFunction, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
405
406 bool addScene( SceneDescription sceneDescription, int key);
407 bool addScene( SceneDescription sceneDescription);
408
411 #if AGX_USE_OPENPLX()
412 m_openplxSceneVector.clear();
413 #endif
414 m_keybindingVector.clear();
415 }
416
417 agx::Callback getStepCallback() const { return m_stepCallback; }
418 void setStepCallback(agx::Callback callback) { m_stepCallback = callback; }
419
420 bool initialized() const { return m_initialized; }
421
422 agxOSG::SceneDecorator *getSceneDecorator() { return m_decorator; }
423
424 virtual int run();
425
426 void setOsgNotifyLevel(osg::NotifySeverity severity) const;
427
439 osg::Group* executePythonScript(const agx::String& file, const agx::String& function, bool& success);
440
445 void stop(int exitCode = 0) { m_shouldStop = true; m_exitCode = exitCode; }
446
448 void cancelStop() { m_shouldStop = false; }
449
451 bool shouldStop() const { return m_shouldStop; }
452
459 bool setWindowRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height);
460
466 bool setWindowTitle(const std::string& title);
467
469 bool breakRequested() const;
470
471 virtual void setupViewer( bool lightingEnabled = true, bool visibleWindow = true );
472
475
476 //void initScene();
477
478 osg::Group *getScene() { return m_scene.get(); }
479 void setScene(osg::Group *scene ) { m_scene = scene; }
480 osg::Group *getSceneRoot() { return m_sceneRoot.get(); }
481 osg::Group* getSceneAgxOSGRoot();
482 osg::Group *getSceneSwitch() { return m_sceneSwitch.get(); }
483
484#ifdef AGX_HAVE_DEPTHPEELING
485 void setEnableDepthPeeling( bool flag );
486 bool getEnableDepthPeeling() const;
487 agxOSG::DepthPeeling* getDepthPeeling();
488#endif
489
497 bool setEnableDebugRenderer( bool flag );
498
501
504
505 void setEnableCaptureSyncWithSimulation( bool enableSync );
507
508 void setEnableOSGRenderer( bool flag );
510
511 void setEnableVSync( bool flag, bool forceUpdate = false );
512 bool getEnableVSync() const;
513
514 void getCameraHome( agx::Vec3& eye, agx::Vec3& center, agx::Vec3& up);
515 void setCameraHome( const agx::Vec3& eye, const agx::Vec3& center, const agx::Vec3& up=agx::Vec3(0,0,1) );
516
522 bool hasRenderContext() const;
523
529 void addRenderTarget(agxOSG::RenderTarget* rtt, osg::Node *targetSceneNode=nullptr);
530
536
543
544#if defined(OSG_VERSION_GREATER_OR_EQUAL)
545# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
546 osgGA::CameraManipulator* getCameraManipulator();
547 const osgGA::CameraManipulator* getCameraManipulator() const;
548#else
549 osgGA::MatrixManipulator* getCameraManipulator();
550 const osgGA::MatrixManipulator* getCameraManipulator() const;
551#endif
552#else
553 osgGA::MatrixManipulator* getCameraManipulator();
554 const osgGA::MatrixManipulator* getCameraManipulator() const;
555#endif
556 agxSDK::Simulation *getSimulation() { return m_simulation.get(); }
557
558 bool restoreFromFile( const std::string& filename );
559 void journalRenderLoader(agxSDK::Assembly *assembly, bool keyFrame);
560
561
568 void setAutoStepping( bool flag, bool resetTimer = true );
569
571 bool getAutoStepping( ) const;
572
573
574 void setEnablePauseUpdate( bool flag ) { m_pauseUpdate = flag; }
575 bool getEnablePauseUpdate( ) const { return m_pauseUpdate; }
576
582 void setRealTimeSync(bool flag);
583 bool getRealTimeSync() const;
584
586 const std::string& getJournalConfigurationPath() const;
587 const std::string& getJournalPlaybackPath() const;
588
590
593
595
597 bool createSceneFromKey( int key );
598 bool createSceneFromIndex( int idx, bool firstStartUp = false );
599
600
604
605 size_t getNumScenes() const;
606
607 void step();
608
610
611 const std::string& getSaveSceneFilename() const { return m_sceneFilename; }
612
613 osg::Group *getRoot() { return m_root.get(); }
614
616 void initSimulation(agxSDK::Simulation *simulation = nullptr, bool initializeGraphics = true);
617 void initViewer(int width, int height, bool osgWindow = true);
618
620 void initRpc();
621
627 void stopAfter(const agx::Real stopTime);
628
629 osgViewer::Viewer *getViewer() { return m_viewer.get(); }
630 osg::Camera *getCamera() { if (m_viewer.valid()) return m_viewer->getCamera(); else return nullptr; }
631
632 bool hasOffscreenWindow() const;
633
638
642 void applyCameraData( const agxOSG::CameraData& cameraData );
643
644 intptr_t getHWND() const;
645
647
648 PickHandler* getPickHandler() { return m_pickHandler; }
649 const PickHandler* getPickHandler() const { return m_pickHandler; }
650
651 std::string getScriptFile() const { return m_scriptFile; }
652
653 void handleReactiveScriptErrors( bool abortSimulation = true );
654
656
658
659 void setEnableSimulationDump( bool flag );
661
663 bool updatePythonCoSimulationServer(const agx::String& filename, std::stringstream& buffer);
665
669
670 bool useCoSimulation() const {return m_useCoSimulation;}
671
672 agx::Vec3 getGravity() const { return m_gravity; }
673
674
675 agxOSG::ImageCapture *getImageCapture() { return m_imageCapture; }
676 const agxOSG::ImageCapture *getImageCapture() const { return m_imageCapture; }
677
679
680 osg::Camera *getTextureCamera() { return m_textureCamera; }
681
682
683 bool isCameraHomeSet() const { return m_cameraHomeSet; }
684
686
690
692 void listSessionNames(const std::string& journalToList);
693
703 double heading, double elevation, double distance,
704 int trackerMode = 0);
705
715 const agx::Vec3& eye, const agx::Vec3& center, const agx::Vec3& up = agx::Vec3::Z_AXIS(),
716 int trackerMode = 0);
717
725
727
729
730
735 bool done() const;
736
737
742 void setQuitEventSetsDone(bool flag);
744
749
753 void setAllowWindowResizing(bool flag);
754
759 void takeScreenShot(const agx::String& filename="");
760
761 void synchronizedStep(bool blocking = false);
762
764
765 void initScene();
766 void initScene(osg::Group *root);
767
768
771
773 void setJournalFormat(agx::UInt journalFormat);
774
776 void setEnableJournal32bitMode(bool enable);
777
779 void setEnableJournalRecord(bool enable);
780
783
785 void setJournalRecordPath(const agx::String& journalPath);
786
788 void setCoordinateSystemTransform( const agx::AffineMatrix4x4& coordinateSystemTransform);
789
792
794 void setGridSize(const agx::Vec2& gridSize);
795
798
800 void setGridResolution(const agx::Vec2u gridResolution);
801
804
806 void setEnableGrid(bool flag);
807
809 bool getEnableGrid() const;
810
813
816
817 // Throttle calls to avoid excessive CPU usage
818 // Is automatically called from `executeWithoutGraphics`
820
821 agxOSG::RenderToTexture * getVideoCaptureRendertoTexture() { return m_videoCaptureRenderToTexture; }
822
823 std::string getProfilingJournalPath() const;
824
825#if AGX_USE_WEBSOCKETS()
826 agxOSG::ExampleApplicationController *getController();
827
828 agx::UInt16 getControlChannelPort();
829 void pushParametersToControlChannel();
830 void setEnableControlChannelTickSignals(bool flag);
831 void pushFrameToRemoteViewer();
832#endif
833
835 void setEnableThreadTimeline(bool flag);
836 void setEnableTaskProfile(bool flag);
837 int getExitCode() { return m_exitCode; }
838
839#if AGX_USE_PYTHON()
840 agxPython::ScriptContextInterface* initPythonContext(agxPython::ScriptManager *scriptManager);
841#endif
842
843 void createVisual(agxSDK::Simulation *simulation, float detailRatio = 1.0f, bool createAxes = false);
844 void createVisual(agxSDK::Assembly *assembly, float detailRatio = 1.0f, bool createAxes = false);
845 agx::Mutex& getFrameMutex() { return m_frameMutex; }
846
851 void setTargetFPS(double fps);
852
856 double getTargetFPS();
857
858#if AGX_USE_OPENPLX()
865 agxopenplx::LoadResult loadOpenPlxFile(std::string filePath, osg::Group* root, agxopenplx::OptParams optionalParameters = agxopenplx::OptParams());
866
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
964
966
968
970
973
976
977 std::string m_sceneFilename;
979
981
983
994 // std::string m_exportMayaAnimationPath;
995
996#if AGX_USE_WEBSOCKETS()
997 friend class ExampleApplicationController;
998#endif
999 friend class AutoPauseListener;
1003
1005
1006 agxCFG::ConfigScriptRef m_settings;
1007
1008 std::string m_xmlPlotFile;
1010
1011 std::string m_scriptFile;
1016
1018#if AGX_USE_OPENGL()
1021#endif
1028 std::string m_profilingRoot;
1037 std::string m_pythonFilePath;
1044 std::string m_journalEofMode;
1049 // agx::UInt m_journalStride;
1053
1056
1058
1060
1061#ifdef AGX_HAVE_DEPTHPEELING
1062 osg::ref_ptr<DepthPeeling> m_depthPeeling;
1063#endif
1068 osg::ref_ptr<osg::Camera> m_textureCamera;
1080 osg::ref_ptr<osg::GraphicsContext> m_pBuffer;
1081 osg::ref_ptr<osg::Camera> m_pBufferCamera;
1083
1084 // OpenPLX cmdline
1085 bool m_openplxUseClick = false;
1086 std::string m_openplxClickServerAddr = "tcp://*:5555";
1087 std::vector<std::string> m_openplxAddBundlePath;
1088 bool m_openplxDebugRenderFrames = false;
1089 bool m_openplxEnableDebugLogs = false;
1091#if AGX_USE_OPENPLX()
1092 std::vector<std::shared_ptr<openplx::Core::Object>> m_openplxSceneVector;
1093 std::unique_ptr<agxopenplx::OsgClickAdapter> m_openplxClickAdapter;
1094#endif
1095
1096 public:
1101 std::string m_hostName;
1102
1103 protected:
1109 osg::ref_ptr<osg::Geode> m_grid;
1110 osg::ref_ptr<osg::MatrixTransform> m_coordinateSystem;
1119
1120 std::string m_videoName;
1125
1130 };
1131
1132}
#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
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.