AGXDynamics  2.35.0.2
Journal.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, is copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx 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 
33 namespace agxSDK
34 {
35  class Assembly;
36 }
37 
38 
39 namespace agx
40 {
41 
47  {
48  public:
49 
50  enum Mode
51  {
52  INVALID = -1,
54  PLAYBACK
55  };
56 
58  {
60  HDF5,
61  CUSTOM
62  };
63 
64  public:
66 
67  class Converter;
68 
69  public:
70  Journal(const String& diskPath = "Journal.agxJournal", ArchiveFormat archiveFormat = AUTO, bool loadPlotFromJournal = true, bool readOnlyIfExists=false);
71 
75  const Name& getName() const;
76 
77 
81  // void setDiskPath(const String& path);
82 
86  const String& getDiskPath() const;
87 
88 
92  static void convert(const String& targetPath, const String& sourcePath, ArchiveFormat targetFormat, bool expand = false);
93 
94 
98  ArchiveFormat getArchiveFormat() const;
99 
104  bool jumpToFrame(agx::UInt frameIndex);
105 
106 
111  bool jumpToTime(agx::Real time);
112 
113 
114  bool sanityCheck(const agxSDK::Simulation* simulation, agxData::JournalArchive::Session* session) const;
115 
123  void attach(agxSDK::Simulation *simulation, Mode mode, agxData::Track *frameCache = nullptr, bool passive = false);
124 
128  void detach();
129 
131  agxSDK::Simulation *getSimulation();
132 
134  const agxSDK::Simulation *getSimulation() const;
135 
139  void setMode(Mode mode);
140 
144  Mode getMode() const;
145 
149  void setEnableIncrementalStructure(bool flag);
150 
154  bool getEnableIncrementalStructure() const;
155 
159  bool isJumping() const;
160 
165  bool loadConfiguration(const String& configurationFilePath);
166 
170  void addDataBinding(const agx::Path& path, bool recursive = false);
171  void addDataBinding(const agx::Object *object, bool recursive = false);
172 
176  bool removeDataBinding(const agx::Path& path);
177  bool removeDataBinding(const agx::Object *object);
178 
182  void clearDataBindings();
183 
187  void startRecordingAtTime(agx::Real time);
188 
193  void flush(bool force = false);
194 
195 
199  void setExceptionHandler(const ExceptionHandler& handler);
200 
204  const ExceptionHandler& getExceptionHandler() const;
205 
206 
208  agxData::JournalArchive* getFileJournal() const;
209 
213  const agxData::JournalArchive::SessionTable& getSessions() const;
214 
219  agxData::JournalArchive::Session* loadNewestSession();
220 
221 
222 
223 
225  agxData::JournalArchive::Session* getSession( const agx::Name& name );
226 
229  agxData::JournalArchive::Session* createNewSession();
230  agxData::JournalArchive::Session* createNewSession(const Name& name);
231 
235  agxData::JournalArchive::Session* setCurrentSession( const agx::Name& sessionName, bool saveSceneOnNextPreTick=true );
236 
239  void setCurrentSession( agxData::JournalArchive::Session* session, bool saveSceneOnNextPreTick=true );
240 
241  agxData::JournalArchive::Session *getCurrentSession();
242 
246  bool renameCurrentSession( const agx::String& newName );
247 
251  bool removeSession( const agx::Name& sessionName );
252 
253 
258  agxData::FrameRef readFrameWithIndex(agx::UInt index);
259 
264  agxData::FrameRef readFrameAtTime(agx::Real time);
268  agx::UInt16 getSerializationVersion() const;
269 
270 
271  agxData::Track *getTrack();
272  agxSDK::SimulationFrameReader *getSimulationReader();
273  agxSDK::SimulationFrameWriter *getSimulationWriter();
274  agxData::DiskFrameReader *getFileReader();
275  agxData::DiskFrameWriter *getFileWriter();
276 
277  const agxData::Track *getTrack() const;
278  const agxSDK::SimulationFrameReader *getSimulationReader() const;
279  const agxSDK::SimulationFrameWriter *getSimulationWriter() const;
280  const agxData::DiskFrameReader *getFileReader() const;
281  const agxData::DiskFrameWriter *getFileWriter() const;
282 
283 
286  void setSceneLoader(SceneLoaderCallback loader);
287 
289  void setRenderLoader(RenderLoaderCallback loader);
290 
291  RenderLoaderCallback getRenderLoader();
292  void triggerFrame();
293 
294 
296  agxData::JournalArchive::Session *findNewestSession();
297 
300  static bool findNewestSession( const agx::String& diskPath, agx::JournalRef& journal, agxData::JournalArchive::SessionRef& session);
301 
303 
304 
308  void attachStandalone( agxData::FrameReader* input, agxData::FrameWriter* output );
309 
311 
313  void saveScene();
314 
324  void setSaveSceneToDisk( bool flag );
325 
329  bool getSaveSceneToDisk() const;
330 
331  protected:
332  virtual ~Journal();
333 
334  private:
335 
336  void preTickCallback(Clock *clock);
337  void initPlayback();
338  void defaultSceneLoader(const String& path);
339  // void postTickCallback(Clock *clock);
340  void trackExceptionCallback(agxData::Track *track, std::exception& e);
341  void createApiTrack();
342 
343 
344  private:
345  agxData::JournalArchiveRef m_diskJournal;
346 
347  ExceptionHandler m_exceptionHandler;
348 
349  Mode m_mode;
350  agxData::JournalArchive::SessionRef m_currentSession;
351  agxSDK::SimulationObserver m_simulation;
352 
353  agxData::TrackRef m_track;
354  agxSDK::SimulationFrameReaderRef m_simulationReader;
355  agxSDK::SimulationFrameWriterRef m_simulationWriter;
356  agxData::DiskFrameWriterRef m_fileWriter;
357  agxData::DiskFrameReaderRef m_fileReader;
358 
359  SceneLoaderCallback m_sceneLoader;
360  RenderLoaderCallback m_renderLoader;
361 
362 
363  agxData::TrackRef m_apiTrack;
364  // agxData::DiskFrameReaderRef m_apiFileReader;
365  // agxSDK::SimulationFrameReaderRef m_apiSimulationReader;
366 
367  // ComponentRef m_context;
368  // ClockRef m_clock;
369  Clock::TickEvent::CallbackType m_preTickCallback;
370  // Clock::TickEvent::CallbackType m_postTickCallback;
371 
372 
373  Mutex m_mutex;
374  Block m_block;
375 
376  bool m_hasSavedScene;
377  Callback m_loadStartFrameCallback;
378  ArchiveFormat m_archiveFormat;
379  bool m_saveSimulationToDisk;
380  bool m_passive;
381  bool m_loadPlot;
382  Real m_recordStartTime;
383  bool m_isRecording;
384  agx::UInt16 m_serializationVersion;
385  bool m_enableIncrementalStructure;
386  bool m_isJumping;
387  };
388 
389  class AGXPHYSICS_EXPORT Journal::Converter
390  {
391  public:
393  {
402  };
403 
406 
410 
411  public:
412  Converter();
413 
414  void execute();
415 
416  void setSourcePath(const agx::String& path);
417  void setTargetPath(const agx::String& path);
418  void setTargetFormat(ArchiveFormat format);
419  void setExpand(agx::Bool expand);
420  void setStartTime(agx::Real startTime);
421  void setEndTime(agx::Real endTime);
422  void setFrameStride(agx::UInt stride);
423 
424  void extractScene(const agx::String& sessionName);
425 
426 
427  const agx::String& getSourcePath() const;
428  const agx::String& getTargetPath() const;
429  ArchiveFormat getTargetFormat() const;
430  agx::Bool getExpand() const;
431  agx::Real getStartTime() const;
432  agx::Real getEndTime() const;
433  agx::UInt getFrameStride() const;
434 
435  private:
436  void writeCallback(const agxData::Frame *frame);
437  void convertSession(
439 
440  private:
441  agx::String m_sourcePath;
442  agx::String m_targetPath;
443  ArchiveFormat m_format;
444  agx::Bool m_expand;
445  agx::Real m_startTime;
446  agx::Real m_endTime;
447  agx::UInt m_stride;
449  agxData::JournalArchiveRef m_sourceArchive;
450  agxData::JournalArchiveRef m_targetArchive;
451  SessionHeader m_currentSession;
452  agx::UInt m_numFramesWritten;
453  };
454 
455 
456  /* Implementation */
457 
458  AGX_FORCE_INLINE const Name& Journal::getName() const { return m_diskJournal->getName(); }
459  AGX_FORCE_INLINE const String& Journal::getDiskPath() const { return m_diskJournal->getPath(); }
462  AGX_FORCE_INLINE const agxSDK::Simulation *Journal::getSimulation() const { return m_simulation; }
463 
465 
469 
472 
473  AGX_FORCE_INLINE const agxData::Track *Journal::getTrack() const { return m_track; }
474  AGX_FORCE_INLINE const agxSDK::SimulationFrameReader *Journal::getSimulationReader() const { return m_simulationReader; }
475  AGX_FORCE_INLINE const agxSDK::SimulationFrameWriter *Journal::getSimulationWriter() const { return m_simulationWriter; }
476 
477  AGX_FORCE_INLINE const agxData::DiskFrameReader *Journal::getFileReader() const { return m_fileReader; }
478  AGX_FORCE_INLINE const agxData::DiskFrameWriter *Journal::getFileWriter() const { return m_fileWriter; }
479 
481 
482 }
483 
484 
485 #endif /* AGX_JOURNAL_H */
Pointer.h
agx::Journal
Definition: Journal.h:46
agx::Real
double Real
Definition: Real.h:42
agx::Journal::sessionStartEvent
SessionEvent sessionStartEvent
Definition: Journal.h:408
agx::Journal::RECORD
@ RECORD
Definition: Journal.h:53
agx::Journal::SessionHeader::endFrame
agx::UInt endFrame
Definition: Journal.h:396
agx::Journal::ProgressEvent
agx::Event1< UInt > ProgressEvent
Definition: Journal.h:404
agx::Path
Representation of a path, a list of name components.
Definition: Path.h:33
Simulation.h
agxData::JournalArchive::Session
Session(const agx::Name &name)
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agx::Journal::SessionHeader::name
agx::String name
Definition: Journal.h:394
agxSDK::SimulationFrameWriterRef
agx::ref_ptr< SimulationFrameWriter > SimulationFrameWriterRef
Definition: SimulationTrack.FrameWriter.h:38
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agx::Journal::getSimulationReader
agxSDK::SimulationFrameReader * getSimulationReader()
Definition: Journal.h:467
agxData::JournalArchive
The JournalArchive provides an abstract class for inspecting and manipulating the contents of a creat...
Definition: JournalArchive.h:41
agx::FrameRef
agx::ref_ptr< Frame > FrameRef
Definition: Frame.h:52
agx::Journal::SessionHeader::startTime
agx::Real startTime
Definition: Journal.h:397
agx::Journal::getMode
Mode getMode() const
Definition: Journal.h:460
Track.h
agx::Journal::AUTO
@ AUTO
Definition: Journal.h:59
agx::Journal::getFileWriter
agxData::DiskFrameWriter * getFileWriter()
Definition: Journal.h:471
agx::Journal::SessionHeader::versionName
agx::String versionName
Definition: Journal.h:400
agx::Callback
Generalized callback, using std::function.
Definition: Callback.h:53
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agx::Journal::progressEvent
ProgressEvent progressEvent
Definition: Journal.h:405
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxData
Contains classes for low level data storage for AGX.
Definition: Container.h:23
Clock.h
agx::Block
Block synchronization primitive.
Definition: ThreadSynchronization.h:96
agx::UInt16
uint16_t UInt16
Definition: Integer.h:39
agx::ref_ptr< Journal >
agx::Journal::sessionEndEvent
SessionEvent sessionEndEvent
Definition: Journal.h:409
agxData::Track
Definition: agxData/Track.h:35
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agx::Journal::SessionEvent
agx::Event1< SessionHeader > SessionEvent
Definition: Journal.h:407
agx::Journal::ArchiveFormat
ArchiveFormat
Definition: Journal.h:57
agx::Journal::SceneLoaderCallback
Callback1< const agx::String & > SceneLoaderCallback
A callback that will be called when starting playback from a recording.
Definition: Journal.h:285
agx::Journal::getSimulation
agxSDK::Simulation * getSimulation()
Definition: Journal.h:461
agx::Mutex
std::mutex Mutex
Definition: Referenced.h:93
FileJournal.h
Hdf5Track.h
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:871
Component.h
Range.h
agx::Journal::RenderLoaderCallback
Callback2< agxSDK::Assembly *, bool > RenderLoaderCallback
Definition: Journal.h:288
agxData::DiskFrameWriterRef
agx::ref_ptr< DiskFrameWriter > DiskFrameWriterRef
Definition: DiskTrack.h:102
agx::Name
Representation of a name string.
Definition: Name.h:32
agxData::JournalArchiveRef
agx::ref_ptr< JournalArchive > JournalArchiveRef
Definition: JournalArchive.h:183
agx::Object
agx::Object is a refcounted object with a name.
Definition: Object.h:59
agx::Journal::getSimulationWriter
agxSDK::SimulationFrameWriter * getSimulationWriter()
Definition: Journal.h:468
agx::Callback1< const agx::String & >
agx::Event1< UInt >
agx::Journal::getTrack
agxData::Track * getTrack()
Definition: Journal.h:466
SimulationTrack.FrameReader.h
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agxData::DiskFrameReaderRef
agx::ref_ptr< DiskFrameReader > DiskFrameReaderRef
Definition: DiskTrack.h:27
agx::UInt
uint32_t UInt
Definition: Integer.h:34
agx::Bool
bool Bool
Definition: Integer.h:48
SimulationTrack.FrameWriter.h
agx::Journal::SessionHeader::startFrame
agx::UInt startFrame
Definition: Journal.h:395
agx::Journal::SessionHeader::version
agx::UInt32 version
Definition: Journal.h:401
agx::Journal::SessionHeader
Definition: Journal.h:392
agx::Journal::HDF5
@ HDF5
Definition: Journal.h:60
agxSDK::SimulationFrameReaderRef
agx::ref_ptr< SimulationFrameReader > SimulationFrameReaderRef
Definition: SimulationTrack.FrameReader.h:38
agx::Journal::SessionHeader::stride
agx::UInt stride
Definition: Journal.h:399
agx::Journal::ExceptionHandler
agx::Callback2< Journal *, std::exception & > ExceptionHandler
Definition: Journal.h:65
agx::AgXString< std::string >
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agx::Clock
Clock class keeps representation of virtual/simulated time.
Definition: Clock.h:37
agxSDK::SimulationFrameWriter
Definition: SimulationTrack.FrameWriter.h:39
agxData::DiskFrameReader
Helper class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:34
agxData::DiskFrameWriter
Base class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:107
agx::Journal::getDiskPath
const String & getDiskPath() const
Set the disk path.
Definition: Journal.h:459
agx::Journal::getName
const Name & getName() const
Definition: Journal.h:458
agx::Callback2< Journal *, std::exception & >
agx::Journal::getFileReader
agxData::DiskFrameReader * getFileReader()
Definition: Journal.h:470
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agxData::TrackRef
agx::ref_ptr< Track > TrackRef
Definition: agxData/Track.h:34
agx::Journal::SessionHeader::endTime
agx::Real endTime
Definition: Journal.h:398
agx::Journal::Mode
Mode
Definition: Journal.h:50
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agxSDK::SimulationFrameReader
Definition: SimulationTrack.FrameReader.h:39
agxSDK::SimulationObserver
agx::observer_ptr< Simulation > SimulationObserver
Definition: StatisticsTrack.h:26
FileTrack.h
agx::Journal::getCurrentSession
agxData::JournalArchive::Session * getCurrentSession()
Definition: Journal.h:464