AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
agxSDK::SimulationController Class Reference

#include <SimulationController.h>

+ Inheritance diagram for agxSDK::SimulationController:

Public Member Functions

 SimulationController ()
 Create an application with the RemoteCommandServer configuration found in the settings file. More...
 
 SimulationController (bool enableRemoteCommandServer, agx::UInt16 port=agx::InvalidIndex, bool scan=false)
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
void attach ()
 
size_t calculateDirectSolvedContacts () const
 This method will call Space::updated() get all the contacts, generate contact materials, and calculate the number of contacts using the direct solver. More...
 
bool checkAndResetPlotSavedState ()
 
void clearSimulation ()
 Replace the current simulation with a new, empty one. More...
 
bool copyRecording (const agx::String &sessionName, const agx::String &newJournalPath)
 Copy the given session from the active journal into the journal with the given name. More...
 
bool deleteSessionFromDisk (const agx::String &sessionName)
 
bool endPlayback (bool resetScene=true)
 End playback from journal and optionally restore the simulation state to the start of the recording. More...
 
agx::UInt getAccumulatedNumFrames () const
 
bool getContacts (std::vector< agx::Vec3 > &contactPoints, std::vector< agx::Vec3 > &normals, std::vector< agx::Real > &depths) const
 Get all the contact (points and normals) from the buffer in the current Simulation. More...
 
agx::UInt getCurrentFrameIndex () const
 
agx::String getCurrentSessionName ()
 Returns the name of the current session. More...
 
bool getEnableSimulationStatisticsListener () const
 
agx::UInt getFirstFrameIndex () const
 
agx::Real getFirstFrameTimeStamp () const
 
agx::Journal * getJournal ()
 
const agx::Journal * getJournal () const
 
agx::Real getJournalFrequency () const
 Get the frequency with which the journal records the data. More...
 
agx::UInt getJournalStride () const
 Get the stride with which journal records the data. More...
 
agx::UInt getLastFrameIndex () const
 
agx::Real getLastFrameTimeStamp () const
 
agx::UInt getNumCachedFrames () const
 
agx::UInt getNumFrames () const
 
agx::UInt getNumQueuedFrames () const
 
agx::UInt16 getPort () const
 
bool getRealTimeSync () const
 
int getReferenceCount () const
 
bool getRepeat () const
 
bool getSaveSceneToDisk () const
 
agxSDK::Simulation * getSimulation ()
 
const agxSDK::Simulation * getSimulation () const
 
agx::Real getTime () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
bool isRecording () const
 
bool isRunning () const
 
bool isTrackRunning () const
 
bool jumpToFrame (agx::UInt frame)
 
bool jumpToTime (agx::Real time)
 
bool listSessions (agx::Vector< agx::Name > &sessionNames)
 Fills the given StringVector with the names of the currently available sessions. More...
 
bool openJournal (const agx::String &journalPath="Journal.agxJournal", const agx::String &sessionName="", bool loadScene=true, bool attach=true)
 Space is updated when a new frame is loaded if update space is enabled. More...
 
void pause (bool isTemporarilyPaused=false)
 If currently continuously stepping in 'runLoop', then stop and wait after the current step is completed. More...
 
void play (bool wasTemporarilyPaused=false)
 Cause the thread waiting in 'runLoop' to start performing simulation steps. More...
 
bool recordExtraData (const agx::String &key, const agx::String &value)
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void registerErrorSignalCallback (CallbackWrapper_String *callback)
 
void registerJumpSignalCallback (CallbackWrapper_Real *callback)
 
void registerPauseSignalCallback (CallbackWrapper *callback)
 
void registerPlaySignalCallback (CallbackWrapper *callback)
 
void registerPostStepSignalCallback (CallbackWrapper_Real *callback)
 
void registerPreStepSignalCallback (CallbackWrapper_Real *callback)
 
void registerRealTimeSignalCallback (CallbackWrapper_Bool *callback)
 
void registerStartPlaybackSignalCallback (CallbackWrapper_Real *callback)
 
void registerStartRecordingSignalCallback (CallbackWrapper_Real *callback)
 
void registerStopPlaybackSignalCallback (CallbackWrapper_Real *callback)
 
void registerStopRecordingSignalCallback (CallbackWrapper_Real *callback)
 
void relinquishExclusiveAccess ()
 
bool renameRecording (const agx::String &sessionName)
 Rename a recording while the track is running is NOT safe. More...
 
void requestExclusiveAccess ()
 The method is used to gain exclusive access to the SimulationController and the simulation it holds. More...
 
bool resumeRecording (const agx::Name &sessionName, const agx::String &journalConfiguration)
 
agx::String retrieveExtraData (const agx::String &key)
 
void runLoop ()
 Enter a run loop that will repeatedly call 'step' until 'stopRunLoop' is called. More...
 
bool sanityCheck () const
 
void setDefaultSceneLoader (agx::Journal::SceneLoaderCallback callback)
 
void setEnableSimulationStatisticsListener (bool flag)
 Enable/disable the listener that collects all statistics data from the simulation. More...
 
void setFrameStride (agx::UInt stride)
 This can be used to skip frames in playback if the time step is really small. More...
 
agx::Real setJournalFrequency (agx::Real freq)
 Set the frequency with which the journal records the data. More...
 
void setRealTimeSync (bool realTime)
 When real-time mode is enabled, then the 'runLoop' can hold off a call to 'Simulation::step' in order to not get ahead of itself. More...
 
void setRepeat (bool repeat)
 When repeat mode is enabled, the playback will restart from frame 0 when reaching the end. More...
 
void setSaveSceneToDisk (bool flag)
 Specifies if the simulation serialization should be temporary stored to disk or to memory when creating a journal. More...
 
void setupRemoteCommandServer (agx::UInt16 port=agx::InvalidIndex, bool scan=false)
 
void signalSceneChanged ()
 Signal to the plot that the scene has changed (the plot is now invalid). More...
 
void singleStep (bool asynchronous=true)
 When paused, causes the run loop to take a single simulation step. More...
 
bool startRecording (const agx::String &journalConfiguration, const agx::String &journalPath="Journal.agxJournal", const agx::String &sessionName="")
 
void startRunLoopThread ()
 Spawn a new thread that calls 'runLoop'. More...
 
bool startTrack ()
 
bool stopRecording (bool resetScene=true, bool blocking=false)
 
void stopRunLoop ()
 Set a flag that will cause the thread running 'runLoop' to eventually return;. More...
 
bool stopTrack ()
 
bool transferRecording (const agx::String &sessionName, const agx::String &newJournalPath)
 Move the given session from the active journal into the journal with the given name. More...
 
bool truncate (agx::UInt firstFrameToRemove)
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unregisterPostStepSignalCallback (CallbackWrapper_Real *callback)
 
void unregisterPreStepSignalCallback (CallbackWrapper_Real *callback)
 
void unregisterStartPlaybackSignalCallback (CallbackWrapper_Real *callback)
 
void unregisterStartRecordingSignalCallback (CallbackWrapper_Real *callback)
 
void unregisterStopPlaybackSignalCallback (CallbackWrapper_Real *callback)
 
void unregisterStopRecordingSignalCallback (CallbackWrapper_Real *callback)
 

Static Public Member Functions

template<typename T >
static bool ValidateCast (const Referenced *object)
 

Protected Member Functions

virtual ~SimulationController ()
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 

Static Protected Member Functions

static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 

Protected Attributes

Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Detailed Description

Definition at line 66 of file SimulationController.h.

Constructor & Destructor Documentation

agxSDK::SimulationController::SimulationController ( )

Create an application with the RemoteCommandServer configuration found in the settings file.

agxSDK::SimulationController::SimulationController ( bool  enableRemoteCommandServer,
agx::UInt16  port = agx::InvalidIndex,
bool  scan = false 
)
Parameters
enableRemoteCommandServerIf true, then a RemoteCommandServer is started and control callbacks bound.
portThe port number that should be used if a RemoteCommandServer is to be started. Pass agx::InvalidIndex to use the value found in the settings.
scanIf true, then the RemoteCommandServer will search for a available port and may use another port than the given one.
virtual agxSDK::SimulationController::~SimulationController ( )
protectedvirtual

Member Function Documentation

void agx::Referenced::allocateObserverVector ( ) const
protectedinherited
template<typename T >
T* agx::Referenced::as ( )
inherited

Subclass casting.

Template type must match actual type, dynamic_cast assertion will fail otherwise.

Referenced by agx::InternalData::get(), agxVehicle::Track::getNode(), and agx::InternalData::getOrCreate().

template<typename T >
const T* agx::Referenced::as ( ) const
inherited
template<typename T >
T* agx::Referenced::asSafe ( )
inherited

Safe subclass casting, return nullptr if template type does not match.

Referenced by agxUtil::CollectBodiesAndWiresVisitor::visit().

template<typename T >
const T* agx::Referenced::asSafe ( ) const
inherited
void agxSDK::SimulationController::attach ( )
size_t agxSDK::SimulationController::calculateDirectSolvedContacts ( ) const

This method will call Space::updated() get all the contacts, generate contact materials, and calculate the number of contacts using the direct solver.

This can then be used to estimate the complexity of the system.

Methods called:

Space::update() MaterialManager::updateContactMaterials()

bool agxSDK::SimulationController::checkAndResetPlotSavedState ( )
void agxSDK::SimulationController::clearSimulation ( )

Replace the current simulation with a new, empty one.

The current journal settings will also be lost.

bool agxSDK::SimulationController::copyRecording ( const agx::String &  sessionName,
const agx::String &  newJournalPath 
)

Copy the given session from the active journal into the journal with the given name.

The other journal will be created if it does not yet exist. The transfer will fail if the target journal already contains a session with the same name.

The journal at newJournalPath must not be open by another SimulationController, or other journal inspecting/modifying classes.

bool agxSDK::SimulationController::deleteSessionFromDisk ( const agx::String &  sessionName)
void agx::Referenced::deleteUsingDeleteHandler ( ) const
protectedinherited
bool agxSDK::SimulationController::endPlayback ( bool  resetScene = true)

End playback from journal and optionally restore the simulation state to the start of the recording.

Further stepping will generate new simulation data.

Parameters
resetSceneWhen true, then the simulation state will be restored to the start of the recording. When false, then the current state of the simulation is kept for further simulation.
agx::UInt agxSDK::SimulationController::getAccumulatedNumFrames ( ) const
bool agxSDK::SimulationController::getContacts ( std::vector< agx::Vec3 > &  contactPoints,
std::vector< agx::Vec3 > &  normals,
std::vector< agx::Real > &  depths 
) const

Get all the contact (points and normals) from the buffer in the current Simulation.

If no contacts are found the vectors contactPoints and normals are cleared

Returns
false if zero contacts are available, otherwise true
agx::UInt agxSDK::SimulationController::getCurrentFrameIndex ( ) const
agx::String agxSDK::SimulationController::getCurrentSessionName ( )

Returns the name of the current session.

Will be the empty string if there is no session.

static DeleteHandler* agx::Referenced::getDeleteHandler ( )
staticprotectedinherited
Returns
a DeleteHandler.
bool agxSDK::SimulationController::getEnableSimulationStatisticsListener ( ) const
agx::UInt agxSDK::SimulationController::getFirstFrameIndex ( ) const
agx::Real agxSDK::SimulationController::getFirstFrameTimeStamp ( ) const
agx::Journal * agxSDK::SimulationController::getJournal ( )

Definition at line 605 of file SimulationController.h.

const agx::Journal * agxSDK::SimulationController::getJournal ( ) const

Definition at line 604 of file SimulationController.h.

agx::Real agxSDK::SimulationController::getJournalFrequency ( ) const

Get the frequency with which the journal records the data.

-1.0 if no journal exists.

agx::UInt agxSDK::SimulationController::getJournalStride ( ) const

Get the stride with which journal records the data.

agx::UInt(-1) if no journal exists.

agx::UInt agxSDK::SimulationController::getLastFrameIndex ( ) const
agx::Real agxSDK::SimulationController::getLastFrameTimeStamp ( ) const
agx::UInt agxSDK::SimulationController::getNumCachedFrames ( ) const
agx::UInt agxSDK::SimulationController::getNumFrames ( ) const
agx::UInt agxSDK::SimulationController::getNumQueuedFrames ( ) const
agx::UInt16 agxSDK::SimulationController::getPort ( ) const
bool agxSDK::SimulationController::getRealTimeSync ( ) const

Definition at line 599 of file SimulationController.h.

int agx::Referenced::getReferenceCount ( ) const
inherited
Returns
the number pointers currently referencing this object.
bool agxSDK::SimulationController::getRepeat ( ) const
bool agxSDK::SimulationController::getSaveSceneToDisk ( ) const
Returns
true if simulation scene will be temporarily stored to disk when writing a journal.
agxSDK::Simulation * agxSDK::SimulationController::getSimulation ( )

Definition at line 597 of file SimulationController.h.

const agxSDK::Simulation * agxSDK::SimulationController::getSimulation ( ) const

Definition at line 598 of file SimulationController.h.

agx::Real agxSDK::SimulationController::getTime ( ) const
template<typename T >
bool agx::Referenced::is ( ) const
inherited
bool agxSDK::SimulationController::isRecording ( ) const

Definition at line 601 of file SimulationController.h.

bool agxSDK::SimulationController::isRunning ( ) const

Definition at line 602 of file SimulationController.h.

bool agxSDK::SimulationController::isTrackRunning ( ) const
bool agxSDK::SimulationController::jumpToFrame ( agx::UInt  frame)
bool agxSDK::SimulationController::jumpToTime ( agx::Real  time)
bool agxSDK::SimulationController::listSessions ( agx::Vector< agx::Name > &  sessionNames)

Fills the given StringVector with the names of the currently available sessions.

bool agxSDK::SimulationController::openJournal ( const agx::String &  journalPath = "Journal.agxJournal",
const agx::String &  sessionName = "",
bool  loadScene = true,
bool  attach = true 
)

Space is updated when a new frame is loaded if update space is enabled.

It can be used to get updated contacts without saving them to the journal, but it might be expensive. Open the given journal. If there already is an open journal, then the older one will be closed. If we were recording, then the recording will be stopped.

If the second argument, 'sessionName', is non-empty, then the SimulationController will enter playback mode and read from that session. WILL NOT RELOAD THE SCENE. It is the responsibility of the caller to ensure that the loaded session is compatible with the current content of the simulation.

If 'sessionName' is empty, then the SimulationController will be ready to record from the running simulation into the default session in the newly opened journal.

void agxSDK::SimulationController::pause ( bool  isTemporarilyPaused = false)

If currently continuously stepping in 'runLoop', then stop and wait after the current step is completed.

Stepping is resumed again using 'play'.

void agxSDK::SimulationController::play ( bool  wasTemporarilyPaused = false)

Cause the thread waiting in 'runLoop' to start performing simulation steps.

bool agxSDK::SimulationController::recordExtraData ( const agx::String &  key,
const agx::String &  value 
)
void agx::Referenced::reference ( void *  ptr = nullptr) const
inherited

Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.

This method should be used with care, always balanced with the same number of calls to unreference.

Referenced by agxData::Val< UInt >::Val().

void agxSDK::SimulationController::registerErrorSignalCallback ( CallbackWrapper_String *  callback)
void agxSDK::SimulationController::registerJumpSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::registerPauseSignalCallback ( CallbackWrapper *  callback)
void agxSDK::SimulationController::registerPlaySignalCallback ( CallbackWrapper *  callback)
void agxSDK::SimulationController::registerPostStepSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::registerPreStepSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::registerRealTimeSignalCallback ( CallbackWrapper_Bool *  callback)
void agxSDK::SimulationController::registerStartPlaybackSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::registerStartRecordingSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::registerStopPlaybackSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::registerStopRecordingSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::relinquishExclusiveAccess ( )
bool agxSDK::SimulationController::renameRecording ( const agx::String &  sessionName)

Rename a recording while the track is running is NOT safe.

stopTrack can be used to be able to rename, but the attach method needs to be called after.

void agxSDK::SimulationController::requestExclusiveAccess ( )

The method is used to gain exclusive access to the SimulationController and the simulation it holds.

When 'requestExclusiveAccess' has returned, then the run loop won't perform any stepping and all of the manipulator methods (from other threads) will block until 'relinquishExclusiveAccess' has been called.

There is a helper class that can be used to avoid deadlock bugs due to forgetting to relinquish the exclusive access somewhere. This class is called ScopedStepLock and is used as follows, where 'simulationController' is a pointer to an instance of the agxSDK::SimulationController class.

{
axSDK::ScopedStepLock stepLock( simulationController );
// We now have exclusive access to the 'simulationController' object.
}
// The 'stepLock' variable just went out of scope and relinquished the exclusive access.
bool agxSDK::SimulationController::resumeRecording ( const agx::Name &  sessionName,
const agx::String &  journalConfiguration 
)
agx::String agxSDK::SimulationController::retrieveExtraData ( const agx::String &  key)
void agxSDK::SimulationController::runLoop ( )

Enter a run loop that will repeatedly call 'step' until 'stopRunLoop' is called.

The thread can be controlled using the 'play' and 'pause' methods.

There should not be multiple threads executing in 'runLoop' simultaneously.

bool agxSDK::SimulationController::sanityCheck ( ) const
void agxSDK::SimulationController::setDefaultSceneLoader ( agx::Journal::SceneLoaderCallback  callback)
static void agx::Referenced::setDeleteHandler ( DeleteHandler *  handler)
staticprotectedinherited

Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.

void agxSDK::SimulationController::setEnableSimulationStatisticsListener ( bool  flag)

Enable/disable the listener that collects all statistics data from the simulation.

Disabling will remove/delete the previous listener, hence no data will be stored

void agxSDK::SimulationController::setFrameStride ( agx::UInt  stride)

This can be used to skip frames in playback if the time step is really small.

agx::Real agxSDK::SimulationController::setJournalFrequency ( agx::Real  freq)

Set the frequency with which the journal records the data.

void agxSDK::SimulationController::setRealTimeSync ( bool  realTime)

When real-time mode is enabled, then the 'runLoop' can hold off a call to 'Simulation::step' in order to not get ahead of itself.

void agxSDK::SimulationController::setRepeat ( bool  repeat)

When repeat mode is enabled, the playback will restart from frame 0 when reaching the end.

void agxSDK::SimulationController::setSaveSceneToDisk ( bool  flag)

Specifies if the simulation serialization should be temporary stored to disk or to memory when creating a journal.

Storing to memory is default. But this might cause problem, as a large continuous memory need to be allocated. For 32bit applications, it might be problematic to allocate 100Mb or more continuous memory, hence storing to disk might be better. And slower.

DEFAULT: store to memory (false)

Parameters
flag- if true, scene will be stored to disk, otherwise to memory before written to journal.
void agxSDK::SimulationController::setupRemoteCommandServer ( agx::UInt16  port = agx::InvalidIndex,
bool  scan = false 
)
void agxSDK::SimulationController::signalSceneChanged ( )

Signal to the plot that the scene has changed (the plot is now invalid).

void agxSDK::SimulationController::singleStep ( bool  asynchronous = true)

When paused, causes the run loop to take a single simulation step.

Does nothing if currently in play mode.

bool agxSDK::SimulationController::startRecording ( const agx::String &  journalConfiguration,
const agx::String &  journalPath = "Journal.agxJournal",
const agx::String &  sessionName = "" 
)
void agxSDK::SimulationController::startRunLoopThread ( )

Spawn a new thread that calls 'runLoop'.

bool agxSDK::SimulationController::startTrack ( )
bool agxSDK::SimulationController::stopRecording ( bool  resetScene = true,
bool  blocking = false 
)
void agxSDK::SimulationController::stopRunLoop ( )

Set a flag that will cause the thread running 'runLoop' to eventually return;.

bool agxSDK::SimulationController::stopTrack ( )
bool agxSDK::SimulationController::transferRecording ( const agx::String &  sessionName,
const agx::String &  newJournalPath 
)

Move the given session from the active journal into the journal with the given name.

The other journal will be created if it does not yet exist. The transfer will fail if the target journal already contains a session with the same name.

The journal at newJournalPath must not be open by another SimulationController, or other journal inspecting/modifying classes.

bool agxSDK::SimulationController::truncate ( agx::UInt  firstFrameToRemove)
void agx::Referenced::unreference ( void *  ptr = nullptr) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.

This method should be used with care, always balanced with the same number of calls to reference.

void agx::Referenced::unreference_nodelete ( ) const
inherited

Decrement the reference count by one, indicating that a pointer to this object is referencing it.

However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be responsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks.

void agxSDK::SimulationController::unregisterPostStepSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::unregisterPreStepSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::unregisterStartPlaybackSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::unregisterStartRecordingSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::unregisterStopPlaybackSignalCallback ( CallbackWrapper_Real *  callback)
void agxSDK::SimulationController::unregisterStopRecordingSignalCallback ( CallbackWrapper_Real *  callback)
template<typename T >
static bool agx::Referenced::ValidateCast ( const Referenced *  object)
staticinherited

Member Data Documentation

Mutex agx::Referenced::m_mutex
mutableprotectedinherited

Definition at line 240 of file Referenced.h.

ObserverContainer agx::Referenced::m_observers
mutableprotectedinherited

Definition at line 239 of file Referenced.h.

AtomicValue agx::Referenced::m_refCount
mutableprotectedinherited

Definition at line 241 of file Referenced.h.


The documentation for this class was generated from the following file: