20 #pragma clang diagnostic push 21 #pragma clang diagnostic ignored "-Wconversion" 24 #include <agx/config/AGX_USE_OPENGL.h> 25 #include <agx/config/AGX_USE_FFMPEG.h> 26 #include <agx/config/AGX_USE_PYTHON.h> 28 #include <agx/config.h> 32 #include <osgViewer/Viewer> 33 #include <osg/Version> 34 #include <osg/ref_ptr> 35 #include <osg/MatrixTransform> 48 #if AGX_USE_WEBSOCKETS() 57 #include <agxCFG/ConfigScript.h> 76 # include <agx/config/AGX_PYTHON_VERSION.h> 80 #pragma clang diagnostic pop 85 class StandardManipulator;
86 class MatrixManipulator;
105 class CoSimulationServer;
109 class ExampleApplication;
110 class SceneDecorator;
111 class RenderProxyFactory;
113 #if AGX_USE_WEBSOCKETS() 114 class ExampleApplicationController;
126 SceneDescription(
BuildScenePtr sc,
bool isTest =
false,
float stop = -1,
bool isSlowUnittest =
false);
129 SceneDescription(
const std::string& scriptFileName,
const std::string& scriptFunctionName,
bool isTest =
false,
float stop = -1,
bool isSlowUnittest =
false);
132 SceneDescription(
const std::string& sceneFile,
bool isTest =
false,
float stop = -1,
bool isSlowUnittest =
false);
147 #if defined(OSG_VERSION_GREATER_OR_EQUAL) 148 # if OSG_VERSION_GREATER_OR_EQUAL(2,9,11) 171 virtual void operator () (osg::RenderInfo& )
const 177 if (m != m_glCamera->getProjectionMatrix())
178 m_glCamera->setProjectionMatrix(m);
183 if (m2 != m_glCamera->getViewMatrix())
184 m_glCamera->setViewMatrix(m2);
186 auto viewport = m_mainCamera->getViewport();
187 m_glCamera->setViewPort(static_cast<int>(viewport->width()), static_cast<int>(m_mainCamera->getViewport()->height()));
189 using osg::Camera::DrawCallback::operator();
192 osg::Camera *m_mainCamera;
200 : m_glLights(mainLights),
201 m_decorator(decorator)
209 virtual void operator () (osg::RenderInfo& )
const 214 m_glLights->setLightPosition(index, l.getPosition());
215 m_glLights->setLightDirection(index, l.getDirection());
223 using osg::Camera::DrawCallback::operator();
235 #if defined(OSG_VERSION_GREATER_OR_EQUAL) 236 # if OSG_VERSION_GREATER_OR_EQUAL(2,9,11) 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 );
257 SINGLETON_CLASSNAME_METHOD();
258 virtual void shutdown()
override { s_instance =
nullptr; }
259 osgViewer::GraphicsWindow* getWindow( osgViewer::Viewer* viewer,
size_t num = 0 )
const;
275 CameraData(
const osgViewer::Viewer* viewer );
280 void applyTo( osg::Camera* camera )
const;
285 void applyTo( osgViewer::Viewer* viewer )
const;
300 void initialize(
const osg::Camera* camera );
333 MAIN_SCENE_MASK = 1 << 1,
334 DEBUG_RENDER_MASK = 1 << 2,
335 OSG_RENDER_MASK = 1 << 3,
337 DECORATOR_MASK = 1 << 5,
351 std::string getSolverName(
SolverType t )
const;
352 SolverType getSolverType(
const std::string& name )
const;
365 void setEnableAutoPausing(
bool flag);
366 bool getEnableAutoPausing();
376 bool init(
int argc,
char** argv );
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 );
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 );
407 void setOsgNotifyLevel(osg::NotifySeverity severity)
const;
426 void stop(
int exitCode = 0) { m_shouldStop =
true; m_exitCode = exitCode; }
440 bool setWindowRectangle(
unsigned int x,
unsigned int y,
unsigned int width,
unsigned int height);
447 bool setWindowTitle(
const std::string& title);
450 bool breakRequested()
const;
452 virtual void setupViewer(
bool lightingEnabled =
true,
bool visibleWindow =
true );
454 void setupVideoCaptureRenderTotexture();
459 void setScene(osg::Group *scene ) { m_scene = scene; }
461 osg::Group* getSceneAgxOSGRoot();
464 #ifdef AGX_HAVE_DEPTHPEELING 465 void setEnableDepthPeeling(
bool flag );
466 bool getEnableDepthPeeling()
const;
467 agxOSG::DepthPeeling* getDepthPeeling();
477 bool setEnableDebugRenderer(
bool flag );
480 bool getEnableDebugRenderer()
const;
482 void setEnableTextDebugRendering(
bool flag );
483 bool getEnableTextDebugRendering()
const;
485 void setEnableCaptureSyncWithSimulation(
bool enableSync );
486 bool getEnableCaptureSyncWithSimulation( )
const;
488 void setEnableOSGRenderer(
bool flag );
489 bool getEnableOSGRenderer();
491 void setEnableVSync(
bool flag,
bool forceUpdate =
false );
492 bool getEnableVSync()
const;
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;
522 osgGA::MatrixManipulator* getCameraManipulator();
523 const osgGA::MatrixManipulator* getCameraManipulator()
const;
526 osgGA::MatrixManipulator* getCameraManipulator();
527 const osgGA::MatrixManipulator* getCameraManipulator()
const;
531 bool restoreFromFile(
const std::string& filename );
541 void setAutoStepping(
bool flag,
bool resetTimer =
true );
544 bool getAutoStepping( )
const;
555 void setRealTimeSync(
bool flag);
556 bool getRealTimeSync()
const;
559 const std::string& getJournalConfigurationPath()
const;
560 const std::string& getJournalPlaybackPath()
const;
562 void setJournalConfigurationPath(
const agx::String& path);
564 void setEnableJournalIncrementalStructure(
bool enable );
565 bool getEnableJournalIncrementalStructure()
const;
570 bool createSceneFromKey(
int key );
571 bool createSceneFromIndex(
int idx,
bool firstStartUp =
false );
575 void createNextScene();
576 void createPreviousScene();
578 size_t getNumScenes()
const;
586 osg::Group *
getRoot() {
return m_root.get(); }
588 void fitSceneIntoView();
589 void initSimulation(
agxSDK::Simulation *simulation =
nullptr,
bool initializeGraphics =
true);
590 void initViewer(
int width,
int height,
bool osgWindow =
true);
601 void stopAfter(
const agx::Real stopTime);
603 osgViewer::Viewer *
getViewer() {
return m_viewer.get(); }
604 osg::Camera *
getCamera() {
if (m_viewer.valid())
return m_viewer->getCamera();
else return nullptr; }
606 bool hasOffscreenWindow()
const;
618 intptr_t getHWND()
const;
627 void handleReactiveScriptErrors(
bool abortSimulation =
true );
633 void setEnableSimulationDump(
bool flag );
634 bool getEnableSimulationDump( )
const;
636 void updateCoSimulationServer();
637 bool updatePythonCoSimulationServer(
const agx::String& filename, std::stringstream& buffer);
640 void updateRemoteDebugger();
642 void stepSimulation();
659 static void registerRemovedGeometry(
GeometryNode *node);
661 void storeInitialJournalState();
662 void initRecordJournal();
663 void initAppendJournal();
665 void journalPlayback();
666 void listSessionNames(
const std::string& journalToList);
677 double heading,
double elevation,
double distance,
678 int trackerMode = 0);
690 int trackerMode = 0);
700 bool executeOneStepWithoutGraphics();
702 void updateServices();
716 void setQuitEventSetsDone(
bool flag);
717 bool getQuitEventSetsDone()
const;
722 bool getAllowWindowResizing()
const;
727 void setAllowWindowResizing(
bool flag);
733 void takeScreenShot(
const agx::String& filename=
"");
735 void synchronizedStep(
bool blocking =
false);
740 void initScene(osg::Group *
root);
747 void setJournalFormat(
agx::UInt journalFormat);
750 void setEnableJournal32bitMode(
bool enable);
753 void setEnableJournalRecord(
bool enable);
756 void setRequestedJournalFrequency(
agx::Real freq);
759 void setJournalRecordPath(
const agx::String& journalPath);
768 void setGridSize(
const agx::Vec2& gridSize);
774 void setGridResolution(
const agx::Vec2u gridResolution);
780 void setEnableGrid(
bool flag);
783 bool getEnableGrid()
const;
786 void setEnableCoordinateSystem(
bool flag);
789 bool getEnableCoordinateSystem()
const;
793 void throttleIdleCpuUsageBySleeping();
797 std::string getProfilingJournalPath()
const;
799 #if AGX_USE_WEBSOCKETS() 800 agxOSG::ExampleApplicationController *getController();
803 void pushParametersToControlChannel();
804 void setEnableControlChannelTickSignals(
bool flag);
805 void pushFrameToRemoteViewer();
808 void postExecution();
809 void setEnableThreadTimeline(
bool flag);
810 void setEnableTaskProfile(
bool flag);
814 agxPython::ScriptContextInterface* initPythonContext(agxPython::ScriptManager *scriptManager);
825 void setTargetFPS(
double fps);
830 double getTargetFPS();
837 void drawCoordinateSystem();
840 void addGranularCreateVisualCallbacks();
844 bool validateGranularLicenseLimits();
847 class SimulationListener;
852 bool timeToStop()
const;
856 void executeWithoutGraphics();
860 void executeWithGraphics();
863 void generateQuickProfiling();
866 void setArgumentsPostSceneCreation();
867 agxJson::Value extractSimulationStructureToJson();
868 void applyInitialParameters(
const std::string& filePath);
869 void initThreadTimeline();
870 bool initBrickInterop();
872 void triggerPreFrameListeners();
873 void triggerPostFrameListeners();
875 bool attachScripts( osg::Group* root );
877 osg::Group *executeMPyScript(
const agx::String& file,
bool& success);
929 #if AGX_USE_WEBSOCKETS() 930 friend class ExampleApplicationController;
932 friend class AutoPauseListener;
994 #ifdef AGX_HAVE_DEPTHPEELING 995 osg::ref_ptr<DepthPeeling> m_depthPeeling;
void setScene(osg::Group *scene)
Class that encapsulates rendering and simulation using OpenSceneGraph.
agx::UInt m_journalFormat
osgViewer::Viewer * getViewer()
Containins classes for sending/reading data over sockets as well as compression functionality.
VideoFFMPEGPipeCaptureRef m_videoCapture
const PickHandler * getPickHandler() const
osg::ref_ptr< osg::Group > m_scene
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
KeyBindingsVector m_keybindingVector
agxOSG::RigidBodyRenderCacheRef m_cache
agx::Vec3 m_cameraHomeCenter
RenderToTextureRef m_videoCaptureRenderToTexture
bool m_explicitJournalConfigurationPath
osg::Group *(* BuildScenePtr)(agxSDK::Simulation *simulation, ExampleApplication *application)
agx::Journal::FrameJumpEvent::CallbackType m_foundIncrementalArchiveCallback
bool m_allowWindowResizing
void setEnablePauseUpdate(bool flag)
PickHandler * getPickHandler()
std::string m_coSimulationInputFile
void clearAddedScenes()
Remove all added scenes.
std::string m_coSimulationOutputFile
agx::Real m_profilingFrequency
AGXOSG_EXPORT bool setOrbitCamera(osgViewer::Viewer *viewer, agxOSG::GeometryNode *node, const agx::Vec3 &eye, const agx::Vec3 ¢er, const agx::Vec3 &up, int trackerMode)
agxIO::ArgumentParser * getArguments()
agx::ref_ptr< agx::Referenced > m_coSimulationServer
agx::RealModeEnum m_journalRealMode
agxSDK::Simulation * getSimulation()
agx::Event1< bool > AutoStepEvent
agxCFG::ConfigScriptRef m_settings
Generalized callback, using std::function.
std::string m_profilingRoot
The HighAccurayTimer class can replace the regular Timer class in high level applications where the n...
osg::ref_ptr< osgViewer::Viewer > m_viewer
Matrix class for affine transformations.
agx::Real m_journalRecordStartTime
agx::RealVector m_coSimulationOutputData
agx::Real m_journalFrequency
agx::Vector< SceneDescription > KeyBindingsVector
bool m_interactiveRemoteClient
osg::ref_ptr< osg::Group > m_sceneRoot
#define AGX_DECLARE_POINTER_TYPES(type)
Implementation of the abstract class from the agxRender namespace, this class is responsible for crea...
osg::ref_ptr< osg::Camera > m_pBufferCamera
std::string m_cfgFileName
std::string m_xmlPlotFile
static CameraManipulatorFactory * s_instance
std::string m_journalRecordPath
PickHandlerRef m_pickHandler
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
agxOSG::SceneDecorator * getSceneDecorator()
agxOSG::ImageCapture * getImageCapture()
virtual void shutdown() override
Implement this method to cleanup your Singleton class.
agx::Callback getStepCallback() const
bool isCameraHomeSet() const
CameraSynchronization(osg::Camera *mainCamera, agxGL::Camera *glCamera)
agxOSG::RenderProxyFactory * m_renderProxyFactory
agx::Real m_relativeStopTime
Render target is used for rendering camera content to a buffer, either a DEPTH or COLOR target...
agxOSG::ImageCaptureRef m_imageCapture
Block synchronization primitive.
agx::Timer m_frameSleepTimer
A small argument parser class.
Decorates a scene with a specific AGX Rendering Style.
Base class providing referencing counted objects.
bool m_generateTaskProfile
agx::Real m_journalStopTime
The geometry representation used by the collision detection engine.
osg::Camera * getTextureCamera()
Only use as member allocated variable.
osg::Group * getSceneSwitch()
agxOSG::RenderProxyFactory * getRenderProxyFactory()
agx::Vector< agx::String > m_timelineFormats
void setStepCallback(agx::Callback callback)
agx::AffineMatrix4x4 m_coordinateSystemTransform
osg::ref_ptr< agxOSG::SceneDecorator > m_decorator
agx::Real m_journalStartTime
KeyBindings m_keyBindings
agx::RealVector m_coSimulationInputData
osg::ref_ptr< osg::Switch > m_sceneSwitch
std::string m_sceneFilename
std::string m_journalSessionName
agxSDK::Simulation::RigidBodyEvent::CallbackType m_addBodyCallback
LightsSynchronization(agxGL::Lights *mainLights, agxOSG::SceneDecorator *decorator)
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
std::string m_parameterFilePath
agx::Vec3 m_cameraHomeEye
A node that can be associated with a collision geometry so that the transformation of this node is up...
Class for sending serialized agxSDK::Simulation over to a client.
void stop(int exitCode=0)
Stop (=exit) the application at next opportunity.
agxSDK::Simulation::GeometryEvent::CallbackType m_removeGeometryCallback
AutoStepEvent autoStepEvent
agxGL::CameraRef m_GlCamera
agxSDK::SimulationRef m_simulation
agx::Vec2u m_gridResolution
AGXOSG_EXPORT agxOSG::GeometryNode * createVisual(const agxCollide::Geometry *geometry, osg::Group *root, float detailRatio=1.0f, bool createAxes=false, bool evenIfSensor=true)
Given a geometry, this function create visual representation of the shape.
osgGA::MatrixManipulator CameraManipulatorType
agxOSG::VideoFFMPEGPipeCapture * getVideoServerCapture()
Callback2< T1, T2 > CallbackType
std::string scriptFunction
agx::HashSet< agxCollide::GeometryPair > m_autoPausePairs
osg::ref_ptr< agxOSG::GuiEventAdapter > m_eventAdapter
CameraMask
Specifies node masks for different parts of the rendering scene.
The rigid body class, combining a geometric model and a frame of reference.
agx::ref_ptr< agx::Referenced > m_journal
std::string m_pythonFilePath
std::string m_journalConfigurationPath
bool m_autoCycleThroughScenes
bool m_coordinateSystemEnabled
agx::HashTable< int, int > KeyBindings
Templated callback with two arguments.
std::string m_extractSimulationStructureToJsonPath
RealModeEnum
The data type for basic floating point representation.
agxIO::ArgumentParserRef m_arguments
agx::Vector< ExampleApplicationListenerRef > m_listeners
virtual ~CameraSynchronization()
agx::Event m_sceneLoadEvent
const std::string & getSaveSceneFilename() const
agx::ref_ptr< agx::Referenced > m_debugClient
RenderTargetRefVector m_renderTargetSet
agx::Mutex m_serviceMutex
agx::Vector< std::pair< std::string, int > > m_attachedScripts
This namespace contains functionality for using AGX together with version 2 of the Functional Mockup ...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
agxOSG::RenderToTexture * getVideoCaptureRendertoTexture()
A pod-struct for holding information about scenes to load by the application.
agx::ref_ptr< agx::Referenced > m_controller
osg::Camera * getCamera()
bool m_enableJournalIncrementalStructure
bool getEnablePauseUpdate() const
agxSDK::ContactEventListenerRef m_autoPauseListener
osg::ref_ptr< osg::MatrixTransform > m_coordinateSystem
bool m_autoPausingEnabled
virtual ~LightsSynchronization()
GraphicsThrottler m_gfxThrottler
agx::Mutex & getFrameMutex()
void cancelStop()
Will cancel the stop if possible. Continue the ::run loop.
AGXCORE_EXPORT Component * root()
osg::ref_ptr< osg::Group > m_root
AGXOSG_EXPORT osg::MatrixTransform * createAxes(agxCollide::Geometry *geometry, agx::Frame *relativeTransform, osg::Group *root, float scale=1, const agx::Vec4f &color=agx::Vec4f())
Creates osg axes relative a geometry given relative transform.
Inheritance with partial specialization due to bug with ref_ptr containers.
bool m_enableJournalRecording
osg::ref_ptr< osg::GraphicsContext > m_pBuffer
void setSolverType(SolverType t)
const agxOSG::ImageCapture * getImageCapture() const
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
agx::Callback m_stepCallback
An event with no arguments.
bool m_generateThreadTimeline
std::string m_journalPlaybackPath
Container class for lights that is used for synchronizing light data with shaders, such as particle sprite shaders.
StatisticsRendererRef m_statisticsRenderer
osg::Group * getSceneRoot()
std::string m_journalEofMode
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints, geometries.
bool useCoSimulation() const
SolverType getSolverType() const
osg::ref_ptr< osg::Geode > m_grid
osg::ref_ptr< osg::Camera > m_textureCamera
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
agx::Vec3 getGravity() const
std::string getScriptFile() const
agxGL::LightsRef m_GlLights