AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
QtAgxWrapper.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 having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid 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#ifndef AGXQT_QTAGXWRAPPER_H
18#define AGXQT_QTAGXWRAPPER_H
19
20#include <agx/config/AGX_USE_PYTHON.h>
21#include <agxQt/export.h>
22#include <agx/Math.h>
23
24#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
25#include <QTimer>
26#include <QObject>
27#include <QElapsedTimer>
28#include <osgGA/TrackballManipulator>
29#include <osgGA/StateSetManipulator>
30#include <osgViewer/ViewerEventHandlers>
31#include <osgViewer/Renderer>
32#include <agx/PopDisableWarnings.h> // End of disabled warnings.
33
34#include <agxQt/UtilWidgets.h>
35#include <agxQt/QtOSGUtils.h>
36#include <agxQt/export.h>
37#include <agxQt/VideoCapture.h>
38#include <agxQt/CameraViewSet.h>
39
41#include <agxCFG/ConfigScript.h>
42#include <agx/ConfigSingleton.h>
45#include <agxSDK/Simulation.h>
46
48#include <agx/Journal.h>
49#include <agx/AnalysisBox.h>
50
51#include <agxOSG/RenderProxy.h>
52#include <agxOSG/DepthPeeling.h>
53#include <agxOSG/ClipPlane.h>
56
57
58namespace agxPython
59{
60 class ScriptManager;
61}
62
63namespace agxQt
64{
65 class QtAgxWrapperStepCallback;
70 class AGXQT_EXPORT QtAgxWrapper : public QObject, public agx::Referenced
71 {
72 Q_OBJECT
73
74 friend class QtAgxWrapperStepCallback;
75 friend class agxQt::VideoCapture;
76
77 public:
78 // Convenience enum for mapping background color to int
80 {
81 GRAY_GRADIENT=0,
82 WHITE=1,
83 WHITE_GRADIENT=2,
84 SKY_BLUE=3,
85 LIGHT_BLUE = 4,
86 BLACK=5,
87 NUM_COLORS=6
88 };
89
90 public:
92
94 bool init(osgViewer::Viewer* viewer, agxIO::ArgumentParser* arguments);
95
97 bool loadFile(const std::string& filename);
98
101
103 void setViewer(osgViewer::Viewer* viewer);
104 osgViewer::Viewer* getViewer();
105
107 void setScene(osg::Group* scene);
108 osg::Group* getScene();
109
111 agxOSG::SceneDescription getSceneDescription() const { return m_sceneDescription; }
112
114 agxOSG::SceneDecorator* getSceneDecorator();
115
117 agxQt::OsgCameraViewManager* getCameraViewManager();
118
119 // Return the particle render utils object
120 agxQt::ParticleSystemRenderUtility* getParticleRenderUtillity();
121
122 // Return the trajectory renderer
123 agxQt::TrajectoryRenderer* getTrajectoryRenderer();
124
126 void setTimeStep(float dt);
127
130
132 static agxSDK::SimulationController* getActiveSimulation();
133
136
140
143
145 bool saveSimulationState(const std::string& filename);
146
148 bool writeCameraViewsToFile(const std::string& filename);
149
151
152 agxSDK::Simulation* getSimulation();
153
155
156 bool isSimulationRunning() const;
157
158 agx::AnalysisBox* getAnalysisBox();
159
162
164
166
167 bool attachScripts(osg::Group*root);
168
170
172
173 osg::Group* getRoot() { return m_root; }
174
176
177 void setCameraViewDirection( const agx::Vec3& direction );
178
180
182
183 signals:
184 // simulation
185 void signalSimulationUpdate(float timeStamp);
186 void signalNewPlayback(float timeStart, float timeEnd, uint numFrames);
191
193
195
196 // Renderer
198
200
201 public slots:
202 // The main loop of the wrapper
204
205 // Play control
214 void slotSetJournalStride(uint stride);
215 void slotEnableJournalLooping(bool enable);
216
217 // OSG
221 void slotChangeDrawMode(int mode);
225 void slotSetEnableShaders(bool enable);
234
235 // Camera functions
245
246 // Simulation
251
252 private:
253 bool initPythonContext(agxPython::ScriptManager* scriptManager, osg::Group* root);
254
255 protected:
256 virtual ~QtAgxWrapper();
258 void setSceneDescription(const agxOSG::SceneDescription& desc);
259 void lockSimulationAndTriggerEvents(); // See comments in function to see purpose
262 void journalPlayback(const std::string& journalPlaybackPath, const std::string asessionName = "");
265 void journalRenderLoader(agxSDK::Assembly* assembly, bool keyFrame);
266 bool restoreFromFile(const std::string& file);
267 bool executePythonScript(const agx::String& file, const agx::String& function);
268 bool executeMPyScript(const agx::String& file, osg::Group *root);
275 osg::Group* createScene(const agxOSG::SceneDescription& desc, bool &success);
284
286 static void setActiveSimulationController(agxSDK::SimulationController* controller);
287
289 // Variables
291 private:
292 agx::Block m_waitForSimulationStepBlock;
293
294 protected:
295 agxSDK::SimulationControllerRef m_simulationController;
296
297 agxCFG::ConfigScriptRef m_settings;
300 std::string m_pythonFilePath;
301
302 // Journal session related variables
306
307 std::string m_cfgFileName;
308
312
313 // Image capture
315
316 // Camera handler
318
319 // Particle post processing
321 // Trajectory Renderer
323
324 // Analysis Box
326 osg::ref_ptr<osg::Group> m_analysisBoxDrawable;
327
328 // Clip Plane
329 osg::ref_ptr < agxOSG::ClipPlane > m_clipPlane;
331 osg::ref_ptr<osg::Group> m_clipPlaneDrawable;
332
333 osg::ref_ptr<osg::Group> m_axesDrawable;
335
336 // OSG variables
339 osg::ref_ptr<osgViewer::Viewer> m_viewer;
340 osg::ref_ptr<agxOSG::SceneDecorator> m_decorator;
341 osg::ref_ptr<agxOSG::GuiEventAdapter> m_eventAdapter;
342 osg::ref_ptr<osg::Group> m_root;
343 osg::ref_ptr<osg::Group> m_postProcessRoot;
344 osg::ref_ptr<osg::Group> m_sceneRoot;
345 osg::ref_ptr<osg::Group> m_scene;
346 osg::ref_ptr<osg::Switch> m_sceneSwitch;
347 osg::ref_ptr<osgGA::StateSetManipulator> m_ssm;
350
352
353 // Static pointer to active simulation that is used to lock simulation while viewer is rendering the scene.
354 static agxSDK::SimulationController* s_activeController;
357 };
358
359 // Implementation
360 AGX_FORCE_INLINE void QtAgxWrapper::setViewer(osgViewer::Viewer* viewer) { m_viewer = viewer; }
361
362 AGX_FORCE_INLINE osgViewer::Viewer* QtAgxWrapper::getViewer() { return m_viewer; }
363
365
367
368 AGX_FORCE_INLINE void QtAgxWrapper::setScene(osg::Group* scene) { m_scene = scene; }
369
371
372 AGX_FORCE_INLINE osg::Group* QtAgxWrapper::getScene() { return m_scene.get(); }
373
375
376 AGX_FORCE_INLINE void QtAgxWrapper::setActiveSimulationController(agxSDK::SimulationController* controller) { s_activeController = controller; }
377
379
381
383
385
387
389}
390
391#endif
#define AGXQT_EXPORT
A small argument parser class.
This class wraps the ClipPlane functionality of osg together with a clip node and a clip plane.
Definition ClipPlane.h:44
Implementation of the abstract class from the agxRender namespace, this class is responsible for crea...
RigidBodyRenderCache is used to cache generated visuals and lookup mappings of RigidBodies cloned fro...
Decorates a scene with a specific AGX Rendering Style.
Class that is used to manipulate the clip plane in the scene.
Definition QtOSGUtils.h:84
Class that is used to manipulate the axes in the scene.
Definition QtOSGUtils.h:141
Manager class that acts as a wrapper container for the CameravViewset class for OSG based view system...
This utility class is used for post processing of the particle system drawable representation,...
Definition QtOSGUtils.h:354
Class that wraps SimulationController with an interface that enables QT Gui signals to control the si...
std::string m_currentCaptureFolder
void setSceneDescription(const agxOSG::SceneDescription &desc)
osg::Group * createScene(const agxOSG::SceneDescription &desc, bool &success)
void incrementOrthographicProjection(agx::Real increment)
std::string m_cfgFileName
agxQt::ParticleSystemRenderUtility * getParticleRenderUtillity()
osg::ref_ptr< osg::Group > m_postProcessRoot
osg::ref_ptr< osgGA::StateSetManipulator > m_ssm
bool writeCameraViewsToFile(const std::string &filename)
Save the active camera view set to a file.
void journalRenderLoader(agxSDK::Assembly *assembly, bool keyFrame)
void slotSetEnableShaders(bool enable)
void slotChangeDrawMode(int mode)
void signalUpdateSimulationStructure()
agxQt::MeasurementAxesControllerRef m_axesController
osg::ref_ptr< agxOSG::ClipPlane > m_clipPlane
void finalizeAndResetVideoCapture()
void lockSimulationAndTriggerEvents()
agxOSG::RenderProxyFactory * m_renderProxyFactory
void handleArguments(agxIO::ArgumentParser *arguments)
void slotEnableDebugRenderMode(bool)
bool attachScripts(osg::Group *root)
agxQt::MeasurementAxesController * getAxesController()
osg::ref_ptr< agxOSG::SceneDecorator > m_decorator
osg::Group * getScene()
void slotUpdateAxesDrawable()
bool journalContainsImpactData()
void setEnableOrthographicCamera(bool enable)
void initSimulationController()
agx::Real getSimulationUpdateTimeStep()
agx::AnalysisBox * getAnalysisBox()
agxQt::OsgCameraViewManager * getCameraViewManager()
Get the camera view manager.
agxSDK::SimulationControllerRef m_simulationController
agx::UInt m_journalStride
void slotSetViewFromActiveCameraDescription()
agx::String getCurrentSessionName() const
osg::ref_ptr< osg::Group > m_clipPlaneDrawable
void slotSetJournalStride(uint stride)
void slotDecrementOrthographicZoom()
static agxSDK::SimulationController * getActiveSimulation()
Returns the active simulation in the wrapper. This is kind of a "hack" to let the renderer get a simu...
void slotDecrementClipPlane()
std::string m_journalSessionName
void setScene(osg::Group *scene)
Returns pointer to osg structure of the scene.
void setCameraViewDirection(const agx::Vec3 &direction)
void setViewer(osgViewer::Viewer *viewer)
Set the viewer to sync the simulation content to.
void slotUpdateAnalysisBoxDrawable()
bool executeMPyScript(const agx::String &file, osg::Group *root)
void signalSimulationPause()
agxQt::VideoCapture * getVideoCapture()
ParticleSystemRenderUtilityRef m_particleRenderUtil
static agxSDK::SimulationController * s_activeController
osgViewer::Viewer * getViewer()
agxOSG::RigidBodyRenderCache * getRenderCache()
agxOSG::SceneDescription m_sceneDescription
void slotChangeSimulationTime(float)
void startCapture()
Image capturing for video.
bool init(osgViewer::Viewer *viewer, agxIO::ArgumentParser *arguments)
Init.
void journalPlayback(const std::string &journalPlaybackPath, const std::string asessionName="")
osg::ref_ptr< agxOSG::GuiEventAdapter > m_eventAdapter
osg::ref_ptr< osg::Group > m_root
agxSDK::Simulation * getSimulation()
OsgCameraViewManagerRef m_cameraManager
void slotEnableJournalLooping(bool enable)
void signalNewPlayback(float timeStart, float timeEnd, uint numFrames)
agxQt::ClipPlaneController * getClipPlaneController()
void slotHandleStopSimulation()
std::string m_pythonFilePath
osg::ref_ptr< osg::Group > m_analysisBoxDrawable
void signalJournalTrackReachedEnd()
void slotStepForwardSimulation()
void slotChangeParticleShaderMode(int mode)
virtual ~QtAgxWrapper()
bool loadFile(const std::string &filename)
Loads a file into the wrapper.
agxOSG::PickHandlerRef m_pickHandler
agxCFG::ConfigScriptRef m_settings
bool restoreFromFile(const std::string &file)
agxQt::ClipPlaneControllerRef m_clipPlaneController
agxOSG::RigidBodyRenderCacheRef m_renderBodyCache
void slotIncrementOrthographicZoom()
void journalSceneLoader(const agx::String &path)
void slotEnbleDrawStatistics(bool)
agxGL::CameraRef m_GlCamera
void signalNewSimulationLoaded()
void handleFileNameArguments(agxIO::ArgumentParser *arguments)
void slotStoreCurrentViewInCameraSet()
void signalSimulationUpdate(float timeStamp)
osg::ref_ptr< osg::Group > m_axesDrawable
void loadDefaultCameraConfig(const agx::String &filename)
bool executePythonScript(const agx::String &file, const agx::String &function)
osg::ref_ptr< osg::Group > m_scene
void setEnableDataRenderFlag(bool enable, agxOSG::GeometryNode::RenderFlag flag)
agx::AnalysisBoxRef m_analysisBox
bool saveSimulationState(const std::string &filename)
Save simulation state to file.
agx::TimeStamp getTimeStamp()
Get the current timestamp of the simulation.
void clearJournalSessionData()
void setTimeStep(float dt)
Set the time step used in the simulation.
void slotStepBackSimulation()
void signalJournalContainsImpactData(bool hasData)
void slotChangeBackgroundColor(int mode)
agxOSG::SceneDecorator * getSceneDecorator()
Get Scene decorator.
agxQt::VideoCaptureRef m_videoCapture
void slotSetEnableCollisionDataRendering(bool enable)
agxQt::TrajectoryRenderer * getTrajectoryRenderer()
void addGLCameraSynchronizationtoPreCallback(osg::Camera *camera)
agxOSG::ClipPlane * getClipPlane()
void takeScreenShot()
Take screenshot.
osg::ref_ptr< osg::Switch > m_sceneSwitch
osg::ref_ptr< osg::Group > m_sceneRoot
void slotEnableOSGRenderMode(bool)
agxGL::LightsRef m_GlLights
agxOSG::SceneDescription getSceneDescription() const
Returns the description of the active scene.
agx::Vec2u getRenderWindowSize() const
Returns the size of the render window.
void slotSetEnableRenderDataRendering(bool enable)
static void setActiveSimulationController(agxSDK::SimulationController *controller)
Static helper function to get active simulation controller so that other classes can lock the active ...
void signalActiveCameraViewChanged()
void slotChangeAlpha(agx::Real alpha)
TrajectoryRendererRef m_trajectoryRenderer
void reloadActiveScene()
Reloads the active loaded scene.
bool isSimulationRunning() const
void slotIncrementClipPlane()
agx::StringVector m_attachedScripts
void slotUpdateClipplingPlaneDrawable()
osg::Group * getRoot()
osg::ref_ptr< osgViewer::Viewer > m_viewer
void slotMoveLightToLookAt()
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
bool setTimeStep(agx::Real timeStep)
Sets the time step determined by the TimeGovernor in the DynamicsSystem.
Class that can be used to extract data from elements in a simulation within a specified bound.
Definition AnalysisBox.h:33
Block synchronization primitive.
Base class providing referencing counted objects.
Definition Referenced.h:120
T * get() const
Definition ref_ptr.h:256
#define AGX_FORCE_INLINE
Definition macros.h:58
Contains classes/utility functions for connecting AGX to QT with OSG.
uint64_t UInt
Definition Integer.h:27
double Real
Definition Real.h:42
agx::Real TimeStamp
Definition TimeStamp.h:26
A pod-struct for holding information about scenes to load by the application.