AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ExampleApplication.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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
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>
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()
76# include <agx/config/AGX_PYTHON_VERSION.h>
77#endif
78
79#ifdef __clang__
80#pragma clang diagnostic pop
81#endif
82
83namespace osgGA
84{
85 class StandardManipulator;
86 class MatrixManipulator;
87}
88
89namespace agxFMI2
90{
91 namespace Export
92 {
93 class Module;
94 }
95}
96
97
98namespace agxSDK
99{
100 class Assembly;
101}
102
103namespace agxNet
104{
105 class CoSimulationServer;
106}
107
108namespace agxOSG {
109 class ExampleApplication;
110 class SceneDecorator;
111 class RenderProxyFactory;
112 class GeometryNode;
113#if AGX_USE_WEBSOCKETS()
114 class ExampleApplicationController;
115#endif
116
117 typedef osg::Group * (*BuildScenePtr)(agxSDK::Simulation *simulation, ExampleApplication *application);
118
121
124
126 SceneDescription(BuildScenePtr sc, bool isTest = false, float stop = -1, bool isSlowUnittest = false);
127
129 SceneDescription(const std::string& scriptFileName, const std::string& scriptFunctionName, bool isTest = false, float stop = -1, bool isSlowUnittest = false);
130
132 SceneDescription(const std::string& sceneFile, bool isTest = false, float stop = -1, bool isSlowUnittest = false);
133
134 bool isValid() const { return valid; }
135
136
141 bool valid;
142 std::string scriptFunction;
143 std::string fileName;
144 };
145
146
147#if defined(OSG_VERSION_GREATER_OR_EQUAL)
148# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
149 typedef osgGA::StandardManipulator CameraManipulatorType;
150# else
151 typedef osgGA::MatrixManipulator CameraManipulatorType;
152# endif
153#else
154 typedef osgGA::MatrixManipulator CameraManipulatorType;
155#endif
156
157
158
159#if AGX_USE_OPENGL()
160 class CameraSynchronization : public osg::Camera::DrawCallback
161 {
162 public:
163 CameraSynchronization(osg::Camera *mainCamera, agxGL::Camera *glCamera) : m_mainCamera(mainCamera), m_glCamera(glCamera)
164 {
165 }
166
168 {
169 }
170
171 virtual void operator () (osg::RenderInfo& /* renderInfo */) const
172 {
173 // Explicit support for Real=float agx with Real=double osg
174 agxData::Val<agx::Matrix4x4d> projection(agx::Matrix4x4d(m_mainCamera->getProjectionMatrix().ptr()));
175 agx::Matrix4x4 m = projection.transform<agx::Matrix4x4 > ();
176
177 if (m != m_glCamera->getProjectionMatrix())
178 m_glCamera->setProjectionMatrix(m);
179
180 agxData::Val<agx::Matrix4x4d> view(agx::Matrix4x4d(m_mainCamera->getViewMatrix().ptr()));
182
183 if (m2 != m_glCamera->getViewMatrix())
184 m_glCamera->setViewMatrix(m2);
185
186 auto viewport = m_mainCamera->getViewport();
187 m_glCamera->setViewPort(static_cast<int>(viewport->width()), static_cast<int>(m_mainCamera->getViewport()->height()));
188 }
189 using osg::Camera::DrawCallback::operator();
190
191 private:
192 osg::Camera *m_mainCamera;
193 agxGL::Camera *m_glCamera;
194 };
195
196 class LightsSynchronization : public osg::Camera::DrawCallback
197 {
198 public:
200 : m_glLights(mainLights),
201 m_decorator(decorator)
202 {
203 }
204
206 {
207 }
208
209 virtual void operator () (osg::RenderInfo& /* renderInfo */) const
210 {
211
212 auto updateLight = [this](size_t index, agxOSG::LightSource l)
213 {
214 m_glLights->setLightPosition(index, l.getPosition());
215 m_glLights->setLightDirection(index, l.getDirection());
216 };
217
218 updateLight(0, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT0));
219 updateLight(1, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT1));
220 updateLight(2, m_decorator->getLightSource(agxOSG::SceneDecorator::LIGHT2));
221 }
222
223 using osg::Camera::DrawCallback::operator();
224
225 private:
226 agxGL::Lights *m_glLights;
227 SceneDecorator *m_decorator;
228 };
229#endif
230
232 {
233 public:
235#if defined(OSG_VERSION_GREATER_OR_EQUAL)
236# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
237 FPS,
238# endif
239#endif
240 NUM_TYPES };
241
243
245
246 CameraManipulatorType* next( osgViewer::Viewer* viewer = nullptr );
247 CameraManipulatorType* next( osgViewer::GraphicsWindow* window = nullptr );
248 CameraManipulatorType* create( osgViewer::Viewer* viewer = nullptr );
249 CameraManipulatorType* create( Types type, osgViewer::Viewer* viewer = nullptr );
250 CameraManipulatorType* create( Types type, osgViewer::GraphicsWindow* window = nullptr );
251 CameraManipulatorType* create( osgViewer::GraphicsWindow* window = nullptr );
252
253 void setType( Types type ) { m_currentType = type; }
254 Types getType() const { return m_currentType; }
255
256 protected:
257 SINGLETON_CLASSNAME_METHOD();
258 virtual void shutdown() override { s_instance = nullptr; }
259 osgViewer::GraphicsWindow* getWindow( osgViewer::Viewer* viewer, size_t num = 0 ) const;
260
263 };
264
266 {
270 CameraData( const osg::Camera* camera );
271
275 CameraData( const osgViewer::Viewer* viewer );
276
280 void applyTo( osg::Camera* camera ) const;
281
285 void applyTo( osgViewer::Viewer* viewer ) const;
286
291 bool valid;
293
297
298 private:
299 CameraData();
300 void initialize( const osg::Camera* camera );
301 };
302
305
306 public:
307 virtual void preFrame(ExampleApplication* app);
308 virtual void postFrame(ExampleApplication* app);
309
310 protected:
311 virtual ~ExampleApplicationListener() override;
312 };
313
314
316
321 {
322 public:
325
332 {
333 MAIN_SCENE_MASK = 1 << 1,
334 DEBUG_RENDER_MASK = 1 << 2,
335 OSG_RENDER_MASK = 1 << 3,
336 HUD_MASK = 1 << 4,
337 DECORATOR_MASK = 1 << 5,
338 };
339
341 {
342 MULTI, // New.
343 ITERATIVE, // New forced to iterative.
344 NUM_SOLVERS
345 };
346
347
348 void setSolverType( SolverType t ) { m_solverType = t; }
349 SolverType getSolverType() const { return m_solverType; }
350
351 std::string getSolverName( SolverType t ) const;
352 SolverType getSolverType( const std::string& name ) const;
353
357 void addAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2);
358 void addAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2);
359 void removeAutoPausePair(const agx::RigidBody *body1, const agx::RigidBody *body2);
360 void removeAutoPausePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2);
361
365 void setEnableAutoPausing(bool flag);
367
370
371 bool init( agxIO::ArgumentParser* arguments, bool agxOnly = false );
372
374
375#ifndef SWIG
376 bool init( int argc, char** argv );
377#endif
378
379 agxIO::ArgumentParser* getArguments() { return m_arguments.get(); }
380
381 agxOSG::RenderProxyFactory *getRenderProxyFactory() { return m_renderProxyFactory; }
382
385
386 bool addScene( const std::string& scriptFile, const std::string& scriptFunction, int key, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
387 bool addScene( const std::string& scriptFile, const std::string& scriptFunction, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
388
389 bool addScene( BuildScenePtr sceneFunction, int key, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
390 bool addScene( BuildScenePtr sceneFunction, bool isPartofUnitTest=true, float stopAfter=-1, bool isSlowUnittest=false );
391
392 bool addScene( SceneDescription sceneDescription, int key);
393 bool addScene( SceneDescription sceneDescription);
394
396 void clearAddedScenes() { m_keybindingVector.clear(); }
397
398 agx::Callback getStepCallback() const { return m_stepCallback; }
399 void setStepCallback(agx::Callback callback) { m_stepCallback = callback; }
400
401 bool initialized() const { return m_initialized; }
402
403 agxOSG::SceneDecorator *getSceneDecorator() { return m_decorator; }
404
405 virtual int run();
406
407 void setOsgNotifyLevel(osg::NotifySeverity severity) const;
408
420 osg::Group* executePythonScript(const agx::String& file, const agx::String& function, bool& success);
421
426 void stop(int exitCode = 0) { m_shouldStop = true; m_exitCode = exitCode; }
427
429 void cancelStop() { m_shouldStop = false; }
430
432 bool shouldStop() const { return m_shouldStop; }
433
440 bool setWindowRectangle(unsigned int x, unsigned int y, unsigned int width, unsigned int height);
441
447 bool setWindowTitle(const std::string& title);
448
450 bool breakRequested() const;
451
452 virtual void setupViewer( bool lightingEnabled = true, bool visibleWindow = true );
453
455
456 //void initScene();
457
458 osg::Group *getScene() { return m_scene.get(); }
459 void setScene(osg::Group *scene ) { m_scene = scene; }
460 osg::Group *getSceneRoot() { return m_sceneRoot.get(); }
461 osg::Group* getSceneAgxOSGRoot();
462 osg::Group *getSceneSwitch() { return m_sceneSwitch.get(); }
463
464#ifdef AGX_HAVE_DEPTHPEELING
465 void setEnableDepthPeeling( bool flag );
466 bool getEnableDepthPeeling() const;
467 agxOSG::DepthPeeling* getDepthPeeling();
468#endif
469
477 bool setEnableDebugRenderer( bool flag );
478
481
484
485 void setEnableCaptureSyncWithSimulation( bool enableSync );
487
488 void setEnableOSGRenderer( bool flag );
490
491 void setEnableVSync( bool flag, bool forceUpdate = false );
492 bool getEnableVSync() const;
493
494 void getCameraHome( agx::Vec3& eye, agx::Vec3& center, agx::Vec3& up);
495 void setCameraHome( const agx::Vec3& eye, const agx::Vec3& center, const agx::Vec3& up=agx::Vec3(0,0,1) );
496
502 void addRenderTarget(agxOSG::RenderTarget* rtt, osg::Node *targetSceneNode=nullptr);
503
509
516
517#if defined(OSG_VERSION_GREATER_OR_EQUAL)
518# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
519 osgGA::CameraManipulator* getCameraManipulator();
520 const osgGA::CameraManipulator* getCameraManipulator() const;
521#else
522 osgGA::MatrixManipulator* getCameraManipulator();
523 const osgGA::MatrixManipulator* getCameraManipulator() const;
524#endif
525#else
526 osgGA::MatrixManipulator* getCameraManipulator();
527 const osgGA::MatrixManipulator* getCameraManipulator() const;
528#endif
529 agxSDK::Simulation *getSimulation() { return m_simulation.get(); }
530
531 bool restoreFromFile( const std::string& filename );
532 void journalRenderLoader(agxSDK::Assembly *assembly, bool keyFrame);
533
534
541 void setAutoStepping( bool flag, bool resetTimer = true );
542
544 bool getAutoStepping( ) const;
545
546
547 void setEnablePauseUpdate( bool flag ) { m_pauseUpdate = flag; }
548 bool getEnablePauseUpdate( ) const { return m_pauseUpdate; }
549
555 void setRealTimeSync(bool flag);
556 bool getRealTimeSync() const;
557
559 const std::string& getJournalConfigurationPath() const;
560 const std::string& getJournalPlaybackPath() const;
561
563
566
568
570 bool createSceneFromKey( int key );
571 bool createSceneFromIndex( int idx, bool firstStartUp = false );
572
573
577
578 size_t getNumScenes() const;
579
580 void step();
581
583
584 const std::string& getSaveSceneFilename() const { return m_sceneFilename; }
585
586 osg::Group *getRoot() { return m_root.get(); }
587
589 void initSimulation(agxSDK::Simulation *simulation = nullptr, bool initializeGraphics = true);
590 void initViewer(int width, int height, bool osgWindow = true);
591
593 void initRpc();
595
601 void stopAfter(const agx::Real stopTime);
602
603 osgViewer::Viewer *getViewer() { return m_viewer.get(); }
604 osg::Camera *getCamera() { if (m_viewer.valid()) return m_viewer->getCamera(); else return nullptr; }
605
606 bool hasOffscreenWindow() const;
607
612
616 void applyCameraData( const agxOSG::CameraData& cameraData );
617
618 intptr_t getHWND() const;
619
621
622 PickHandler* getPickHandler() { return m_pickHandler; }
623 const PickHandler* getPickHandler() const { return m_pickHandler; }
624
625 std::string getScriptFile() const { return m_scriptFile; }
626
627 void handleReactiveScriptErrors( bool abortSimulation = true );
628
630
632
633 void setEnableSimulationDump( bool flag );
635
637 bool updatePythonCoSimulationServer(const agx::String& filename, std::stringstream& buffer);
639
643
644 bool useCoSimulation() const {return m_useCoSimulation;}
645
646 agx::Vec3 getGravity() const { return m_gravity; }
647
648
649 agxOSG::ImageCapture *getImageCapture() { return m_imageCapture; }
650 const agxOSG::ImageCapture *getImageCapture() const { return m_imageCapture; }
651
653
654 osg::Camera *getTextureCamera() { return m_textureCamera; }
655
656
657 bool isCameraHomeSet() const { return m_cameraHomeSet; }
658
660
664
666 void listSessionNames(const std::string& journalToList);
667
677 double heading, double elevation, double distance,
678 int trackerMode = 0);
679
689 const agx::Vec3& eye, const agx::Vec3& center, const agx::Vec3& up = agx::Vec3::Z_AXIS(),
690 int trackerMode = 0);
691
699
701
703
704
709 bool done() const;
710
711
716 void setQuitEventSetsDone(bool flag);
718
723
727 void setAllowWindowResizing(bool flag);
728
733 void takeScreenShot(const agx::String& filename="");
734
735 void synchronizedStep(bool blocking = false);
736
738
739 void initScene();
740 void initScene(osg::Group *root);
741
742
745
747 void setJournalFormat(agx::UInt journalFormat);
748
750 void setEnableJournal32bitMode(bool enable);
751
753 void setEnableJournalRecord(bool enable);
754
757
759 void setJournalRecordPath(const agx::String& journalPath);
760
762 void setCoordinateSystemTransform( const agx::AffineMatrix4x4& coordinateSystemTransform);
763
766
768 void setGridSize(const agx::Vec2& gridSize);
769
772
774 void setGridResolution(const agx::Vec2u gridResolution);
775
778
780 void setEnableGrid(bool flag);
781
783 bool getEnableGrid() const;
784
787
790
791 // Throttle calls to avoid excessive CPU usage
792 // Is automatically called from `executeWithoutGraphics`
794
795 agxOSG::RenderToTexture * getVideoCaptureRendertoTexture() { return m_videoCaptureRenderToTexture; }
796
797 std::string getProfilingJournalPath() const;
798
799#if AGX_USE_WEBSOCKETS()
800 agxOSG::ExampleApplicationController *getController();
801
802 agx::UInt16 getControlChannelPort();
803 void pushParametersToControlChannel();
804 void setEnableControlChannelTickSignals(bool flag);
805 void pushFrameToRemoteViewer();
806#endif
807
809 void setEnableThreadTimeline(bool flag);
810 void setEnableTaskProfile(bool flag);
811 int getExitCode() { return m_exitCode; }
812
813#if AGX_USE_PYTHON()
814 agxPython::ScriptContextInterface* initPythonContext(agxPython::ScriptManager *scriptManager);
815#endif
816
817 void createVisual(agxSDK::Simulation *simulation, float detailRatio = 1.0f, bool createAxes = false);
818 void createVisual(agxSDK::Assembly *assembly, float detailRatio = 1.0f, bool createAxes = false);
819 agx::Mutex& getFrameMutex() { return m_frameMutex; }
820
825 void setTargetFPS(double fps);
826
830 double getTargetFPS();
831
832 protected:
833
835
836 void drawGrid();
838
842
843 // Return true if we are ok with the number of particles with respect to the granular license limits.
845
846 protected:
847 class SimulationListener;
848
852 bool timeToStop() const;
853
854
855 void execute();
857 bool executeOneStepWithoutGraphics(bool& saveAfterEnabled, agx::Real saveAfterTime, agx::HighAccuracyTimer& timer);
858
859
861 bool executeOneStepWithGraphics(bool& saveAfterEnabled, agx::Real saveAfterTime, agx::HighAccuracyTimer& timer);
862
866 void setArgumentsPostSceneCreation(); // This function will override a number of settings with their command line argument specifications
868 void applyInitialParameters(const std::string& filePath);
870
873
874 bool attachScripts( osg::Group* root );
875 osg::Group *executeMPyScript(const agx::String& file, bool& success);
876
877 osg::Group *createScene( const SceneDescription& desc, bool &success );
878
880
881 osg::ref_ptr<agxOSG::SceneDecorator> m_decorator;
883 osg::ref_ptr<agxOSG::GuiEventAdapter> m_eventAdapter;
884 osg::ref_ptr<osgViewer::Viewer> m_viewer;
885
887
888 osg::ref_ptr<osg::Group> m_root;
889 osg::ref_ptr<osg::Group> m_sceneRoot;
890 osg::ref_ptr<osg::Group> m_scene;
891 osg::ref_ptr<osg::Switch> m_sceneSwitch;
892
894
896
898
900
903
906
907 std::string m_sceneFilename;
909
911 std::string m_cfgFileName;
912
914
925 // std::string m_exportMayaAnimationPath;
926
927#if AGX_USE_WEBSOCKETS()
928 friend class ExampleApplicationController;
929#endif
930 friend class AutoPauseListener;
934
936
937 agxCFG::ConfigScriptRef m_settings;
938
939 std::string m_xmlPlotFile;
941
942 std::string m_scriptFile;
947
949#if AGX_USE_OPENGL()
952#endif
959 std::string m_profilingRoot;
968 std::string m_pythonFilePath;
975 std::string m_journalEofMode;
980 // agx::UInt m_journalStride;
984
987
989
991
992#ifdef AGX_HAVE_DEPTHPEELING
993 osg::ref_ptr<DepthPeeling> m_depthPeeling;
994#endif
999 osg::ref_ptr<osg::Camera> m_textureCamera;
1011 osg::ref_ptr<osg::GraphicsContext> m_pBuffer;
1012 osg::ref_ptr<osg::Camera> m_pBufferCamera;
1014
1015 public:
1020 std::string m_hostName;
1021
1022 protected:
1028 osg::ref_ptr<osg::Geode> m_grid;
1029 osg::ref_ptr<osg::MatrixTransform> m_coordinateSystem;
1038
1039 std::string m_videoName;
1043
1047 };
1048
1049}
#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 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 * 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?
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()
agx::RealVector m_coSimulationOutputData
static void registerRemovedGeometry(GeometryNode *node)
void stopAfter(const agx::Real stopTime)
Lets the application stop after a certain simulation time.
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.
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 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()
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.
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
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 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
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...
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.
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:68
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
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.
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:120
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
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()
Templated vector class.
Definition agx/Vector.h:53
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:36
std::mutex Mutex
Definition Referenced.h:99
uint64_t UInt
Definition Integer.h:27
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 &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.