AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Journal.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 AGX_JOURNAL_H
18#define AGX_JOURNAL_H
19
20#include <agx/Component.h>
21
22#include <agx/Clock.h>
23#include <agx/Pointer.h>
24#include <agx/Range.h>
25#include <agxData/Track.h>
26#include <agxData/FileTrack.h>
27#include <agxData/Hdf5Track.h>
28#include <agxData/FileJournal.h>
29#include <agxSDK/Simulation.h>
32
33namespace agxSDK
34{
35 class Assembly;
36}
37
38
39namespace agx
40{
41
47 {
48 public:
49
50 enum Mode
51 {
52 INVALID = -1,
54 PLAYBACK
55 };
56
58 {
61 CUSTOM
62 };
63
64 public:
68
71
72 class Converter;
73
74 public:
75 Journal(const String& diskPath = "Journal.agxJournal", ArchiveFormat archiveFormat = AUTO, bool loadPlotFromJournal = true, bool readOnlyIfExists=false);
76
80 const Name& getName() const;
81
82
86 // void setDiskPath(const String& path);
87
91 const String& getDiskPath() const;
92
93
97 static void convert(const String& targetPath, const String& sourcePath, ArchiveFormat targetFormat, bool expand = false);
98
99
104
109 bool jumpToFrame(agx::UInt frameIndex);
110
111
117
118
119 bool sanityCheck(const agxSDK::Simulation* simulation, agxData::JournalArchive::Session* session) const;
120
128 void attach(agxSDK::Simulation *simulation, Mode mode, agxData::Track *frameCache = nullptr, bool passive = false);
129
133 void detach();
134
136 agxSDK::Simulation *getSimulation();
137
139 const agxSDK::Simulation *getSimulation() const;
140
144 void setMode(Mode mode);
145
149 Mode getMode() const;
150
155
160
164 bool isJumping() const;
165
170 bool loadConfiguration(const String& configurationFilePath);
171
175 void addDataBinding(const agx::Path& path, bool recursive = false);
176 void addDataBinding(const agx::Object *object, bool recursive = false);
177
181 bool removeDataBinding(const agx::Path& path);
182 bool removeDataBinding(const agx::Object *object);
183
188
193
198 void flush(bool force = false);
199
200
205
210
211
214
219
225
226
227
228
231
236
240 agxData::JournalArchive::Session* setCurrentSession( const agx::Name& sessionName, bool saveSceneOnNextPreTick=true );
241
244 void setCurrentSession( agxData::JournalArchive::Session* session, bool saveSceneOnNextPreTick=true );
245
246 agxData::JournalArchive::Session *getCurrentSession();
247
251 bool renameCurrentSession( const agx::String& newName );
252
256 bool removeSession( const agx::Name& sessionName );
257
258
263 agxData::FrameRef readFrameWithIndex(agx::UInt index);
264
269 agxData::FrameRef readFrameAtTime(agx::Real time);
274
275
276 agxData::Track *getTrack();
277 agxSDK::SimulationFrameReader *getSimulationReader();
278 agxSDK::SimulationFrameWriter *getSimulationWriter();
279 agxData::DiskFrameReader *getFileReader();
280 agxData::DiskFrameWriter *getFileWriter();
281
282 const agxData::Track *getTrack() const;
283 const agxSDK::SimulationFrameReader *getSimulationReader() const;
284 const agxSDK::SimulationFrameWriter *getSimulationWriter() const;
285 const agxData::DiskFrameReader *getFileReader() const;
286 const agxData::DiskFrameWriter *getFileWriter() const;
287
288
292
295
298
299
302
305 static bool findNewestSession( const agx::String& diskPath, agx::JournalRef& journal, agxData::JournalArchive::SessionRef& session);
306
308
309
313 void attachStandalone( agxData::FrameReader* input, agxData::FrameWriter* output );
314
316
318 void saveScene();
319
329 void setSaveSceneToDisk( bool flag );
330
334 bool getSaveSceneToDisk() const;
335
336 protected:
337 virtual ~Journal();
338
339 private:
340
341 void preTickCallback(Clock *clock);
342 void initPlayback();
343 void defaultSceneLoader(const String& path);
344 // void postTickCallback(Clock *clock);
345 void trackExceptionCallback(agxData::Track *track, std::exception& e);
346 void createApiTrack();
347
348
349 private:
350 agxData::JournalArchiveRef m_diskJournal;
351
352 ExceptionHandler m_exceptionHandler;
353
354 Mode m_mode;
355 agxData::JournalArchive::SessionRef m_currentSession;
356 agxSDK::SimulationObserver m_simulation;
357
358 agxData::TrackRef m_track;
359 agxSDK::SimulationFrameReaderRef m_simulationReader;
360 agxSDK::SimulationFrameWriterRef m_simulationWriter;
361 agxData::DiskFrameWriterRef m_fileWriter;
362 agxData::DiskFrameReaderRef m_fileReader;
363
364 SceneLoaderCallback m_sceneLoader;
365 RenderLoaderCallback m_renderLoader;
366
367
368 agxData::TrackRef m_apiTrack;
369 // agxData::DiskFrameReaderRef m_apiFileReader;
370 // agxSDK::SimulationFrameReaderRef m_apiSimulationReader;
371
372 // ComponentRef m_context;
373 // ClockRef m_clock;
374 Clock::TickEvent::CallbackType m_preTickCallback;
375 // Clock::TickEvent::CallbackType m_postTickCallback;
376
377
378 Mutex m_mutex;
379 Block m_block;
380
381 bool m_hasSavedScene;
382 Callback m_loadStartFrameCallback;
383 ArchiveFormat m_archiveFormat;
384 bool m_saveSimulationToDisk;
385 bool m_passive;
386 bool m_loadPlot;
387 Real m_recordStartTime;
388 bool m_isRecording;
389 agx::UInt16 m_serializationVersion;
390 bool m_enableIncrementalStructure;
391 bool m_isJumping;
392 };
393
394 class AGXPHYSICS_EXPORT Journal::Converter
395 {
396 public:
408
411
415
416 public:
418
419 void execute();
420
421 void setSourcePath(const agx::String& path);
422 void setTargetPath(const agx::String& path);
424 void setExpand(agx::Bool expand);
425 void setStartTime(agx::Real startTime);
426 void setEndTime(agx::Real endTime);
428
429 void extractScene(const agx::String& sessionName);
430
431
439
440 private:
441 void writeCallback(const agxData::Frame *frame);
442 void convertSession(
444
445 private:
446 agx::String m_sourcePath;
447 agx::String m_targetPath;
448 ArchiveFormat m_format;
449 agx::Bool m_expand;
450 agx::Real m_startTime;
451 agx::Real m_endTime;
452 agx::UInt m_stride;
454 agxData::JournalArchiveRef m_sourceArchive;
455 agxData::JournalArchiveRef m_targetArchive;
456 SessionHeader m_currentSession;
457 agx::UInt m_numFramesWritten;
458 };
459
460
461 /* Implementation */
462
463 AGX_FORCE_INLINE const Name& Journal::getName() const { return m_diskJournal->getName(); }
464 AGX_FORCE_INLINE const String& Journal::getDiskPath() const { return m_diskJournal->getPath(); }
465 AGX_FORCE_INLINE Journal::Mode Journal::getMode() const { return m_mode; }
466 AGX_FORCE_INLINE agxSDK::Simulation *Journal::getSimulation() { return m_simulation; }
467 AGX_FORCE_INLINE const agxSDK::Simulation *Journal::getSimulation() const { return m_simulation; }
468
469 AGX_FORCE_INLINE agxData::JournalArchive::Session *Journal::getCurrentSession() { return m_currentSession; }
470
471 AGX_FORCE_INLINE agxData::Track *Journal::getTrack() { return m_track; }
472 AGX_FORCE_INLINE agxSDK::SimulationFrameReader *Journal::getSimulationReader() { return m_simulationReader; }
473 AGX_FORCE_INLINE agxSDK::SimulationFrameWriter *Journal::getSimulationWriter() { return m_simulationWriter; }
474
475 AGX_FORCE_INLINE agxData::DiskFrameReader *Journal::getFileReader() { return m_fileReader; }
476 AGX_FORCE_INLINE agxData::DiskFrameWriter *Journal::getFileWriter() { return m_fileWriter; }
477
478 AGX_FORCE_INLINE const agxData::Track *Journal::getTrack() const { return m_track; }
479 AGX_FORCE_INLINE const agxSDK::SimulationFrameReader *Journal::getSimulationReader() const { return m_simulationReader; }
480 AGX_FORCE_INLINE const agxSDK::SimulationFrameWriter *Journal::getSimulationWriter() const { return m_simulationWriter; }
481
482 AGX_FORCE_INLINE const agxData::DiskFrameReader *Journal::getFileReader() const { return m_fileReader; }
483 AGX_FORCE_INLINE const agxData::DiskFrameWriter *Journal::getFileWriter() const { return m_fileWriter; }
484
486
487}
488
489
490#endif /* AGX_JOURNAL_H */
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXPHYSICS_EXPORT
Helper class for the FrameReaders that are backed by a file on disk.
Definition DiskTrack.h:35
Base class for the FrameReaders that are backed by a file on disk.
Definition DiskTrack.h:108
The JournalArchive provides an abstract class for inspecting and manipulating the contents of a creat...
Session(const agx::Name &name)
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Block synchronization primitive.
Templated callback with one argument.
Definition Callback.h:101
Templated callback with two arguments.
Definition Callback.h:140
Generalized callback, using std::function.
Definition Callback.h:54
Clock class keeps representation of virtual/simulated time.
Definition Clock.h:38
An event with one argument.
Definition Event.h:103
T CallbackType
Definition Event.h:37
Callback1< const agx::String & > SceneLoaderCallback
A callback that will be called when starting playback from a recording.
Definition Journal.h:290
void setTargetFormat(ArchiveFormat format)
agxData::JournalArchive::Session * findNewestSession()
agxData::JournalArchive * getFileJournal() const
FoundIncrementalArchiveEvent foundIncrementalArchiveEvent
Definition Journal.h:70
ProgressEvent progressEvent
Definition Journal.h:410
void triggerFrame()
bool jumpToFrame(agx::UInt frameIndex)
Jump to a specified frame during playback.
void setSceneLoader(SceneLoaderCallback loader)
void flush(bool force=false)
Flush the journal.
agx::UInt16 getSerializationVersion() const
Find what serialization version a Journal was stored with.
agx::Event1< Journal * > FoundIncrementalArchiveEvent
Definition Journal.h:67
bool sanityCheck(const agxSDK::Simulation *simulation, agxData::JournalArchive::Session *session) const
const agxData::JournalArchive::SessionTable & getSessions() const
void setTargetPath(const agx::String &path)
void setFrameStride(agx::UInt stride)
RenderLoaderCallback getRenderLoader()
agx::Event1< SessionHeader > SessionEvent
Definition Journal.h:412
void detach()
Detach from the currently attached simulation.
FrameJumpEvent journalFrameJumpEvent
Definition Journal.h:69
Journal(const String &diskPath="Journal.agxJournal", ArchiveFormat archiveFormat=AUTO, bool loadPlotFromJournal=true, bool readOnlyIfExists=false)
agx::Callback2< Journal *, std::exception & > ExceptionHandler
Definition Journal.h:65
SessionEvent sessionEndEvent
Definition Journal.h:414
agx::Real getEndTime() const
agxData::FrameRef readFrameAtTime(agx::Real time)
Explicitly read a frame from the journal.
Callback2< agxSDK::Assembly *, bool > RenderLoaderCallback
Definition Journal.h:293
agx::Event1< Journal * > FrameJumpEvent
Definition Journal.h:66
agx::UInt getFrameStride() const
ArchiveFormat getTargetFormat() const
void setCurrentSession(agxData::JournalArchive::Session *session, bool saveSceneOnNextPreTick=true)
Change the active session to the given session.
void setSourcePath(const agx::String &path)
const ExceptionHandler & getExceptionHandler() const
void clearDataBindings()
Remove all data bindings.
agx::Bool getExpand() const
ArchiveFormat getArchiveFormat() const
void extractScene(const agx::String &sessionName)
void execute()
agxData::FrameRef readFrameWithIndex(agx::UInt index)
Explicitly read a frame from the journal.
const agx::String & getTargetPath() const
void setExpand(agx::Bool expand)
agxData::JournalArchive::Session * loadNewestSession()
Load the most recent session.
void addDataBinding(const agx::Path &path, bool recursive=false)
Add a data binding to the journal, eg Particle.position will register the buffer to be stored/restore...
bool jumpToTime(agx::Real time)
Jump to a specified time during playback.
void setExceptionHandler(const ExceptionHandler &handler)
Specify an exception handler.
bool loadConfiguration(const String &configurationFilePath)
Load data bindings from a configuration file.
void setStartTime(agx::Real startTime)
void addDataBinding(const agx::Object *object, bool recursive=false)
bool getEnableIncrementalStructure() const
bool removeDataBinding(const agx::Object *object)
agx::Real getStartTime() const
bool removeDataBinding(const agx::Path &path)
Remove a data binding from the journal.
bool isJumping() const
void setEndTime(agx::Real endTime)
bool renameCurrentSession(const agx::String &newName)
Change the name of the current session.
agxData::JournalArchive::Session * createNewSession()
Create a new session within the current Journal archive.
void attach(agxSDK::Simulation *simulation, Mode mode, agxData::Track *frameCache=nullptr, bool passive=false)
Attach the journal to a simulation.
agxData::JournalArchive::Session * createNewSession(const Name &name)
agx::Event1< UInt > ProgressEvent
Definition Journal.h:409
const agx::String & getSourcePath() const
agxData::JournalArchive::Session * getSession(const agx::Name &name)
void setEnableIncrementalStructure(bool flag)
Enable/disable incremental simulation structure recording.
bool removeSession(const agx::Name &sessionName)
Remove a session from the journal.
static void convert(const String &targetPath, const String &sourcePath, ArchiveFormat targetFormat, bool expand=false)
Convert journal from one format to another.
void startRecordingAtTime(agx::Real time)
Specify time stamp when journal recording should begin.
agxData::JournalArchive::Session * setCurrentSession(const agx::Name &sessionName, bool saveSceneOnNextPreTick=true)
Change the active session to the session with the given name.
void setRenderLoader(RenderLoaderCallback loader)
void setMode(Mode mode)
Set the journal mode, RECORD or PLAYBACK.
SessionEvent sessionStartEvent
Definition Journal.h:413
static bool findNewestSession(const agx::String &diskPath, agx::JournalRef &journal, agxData::JournalArchive::SessionRef &session)
Inheritance with partial specialization due to bug with ref_ptr containers.
Representation of a name string.
Definition Name.h:33
agx::Object is a refcounted object with a name.
Definition Object.h:59
Representation of a path, a list of name components.
Definition Path.h:33
Base class providing referencing counted objects.
Definition Referenced.h:120
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
#define AGX_FORCE_INLINE
Definition macros.h:58
Contains classes for low level data storage for AGX.
Definition Container.h:23
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint16_t UInt16
Definition Integer.h:31
std::mutex Mutex
Definition Referenced.h:99
uint32_t UInt32
Definition Integer.h:32
bool Bool
Definition Integer.h:40
uint64_t UInt
Definition Integer.h:27
double Real
Definition Real.h:42
STL namespace.