AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Journal.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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>
30 #include <agxSDK/SimulationTrack.h>
31 
32 namespace agxSDK
33 {
34  class Assembly;
35 }
36 
37 
38 namespace agx
39 {
40 
46  {
47  public:
48 
49  enum Mode
50  {
51  INVALID = -1,
53  PLAYBACK
54  };
55 
57  {
59  HDF5,
60  CUSTOM
61  };
62 
63  public:
65 
66  class Converter;
67 
68  public:
69  Journal(const String& diskPath = "Journal.agxJournal", ArchiveFormat archiveFormat = AUTO, bool loadPlotFromJournal = true, bool readOnlyIfExists=false);
70 
74  const Name& getName() const;
75 
76 
80  // void setDiskPath(const String& path);
81 
85  const String& getDiskPath() const;
86 
87 
91  static void convert(const String& targetPath, const String& sourcePath, ArchiveFormat targetFormat, bool expand = false);
92 
93 
97  ArchiveFormat getArchiveFormat() const;
98 
103  bool jumpToFrame(agx::UInt frameIndex);
104 
105 
110  bool jumpToTime(agx::Real time);
111 
112 
113  bool sanityCheck(const agxSDK::Simulation* simulation, agxData::JournalArchive::Session* session) const;
114 
122  void attach(agxSDK::Simulation *simulation, Mode mode, agxData::Track *frameCache = nullptr, bool passive = false);
123 
127  void detach();
128 
130  agxSDK::Simulation *getSimulation();
131 
133  const agxSDK::Simulation *getSimulation() const;
134 
138  void setMode(Mode mode);
139 
143  Mode getMode() const;
144 
148  void setEnableIncrementalStructure(bool flag);
149 
153  bool getEnableIncrementalStructure() const;
154 
158  bool isJumping() const;
159 
164  bool loadConfiguration(const String& configurationFilePath);
165 
169  void addDataBinding(const agx::Path& path, bool recursive = false);
170  void addDataBinding(const agx::Object *object, bool recursive = false);
171 
175  bool removeDataBinding(const agx::Path& path);
176  bool removeDataBinding(const agx::Object *object);
177 
181  void clearDataBindings();
182 
186  void startRecordingAtTime(agx::Real time);
187 
192  void flush(bool force = false);
193 
194 
198  void setExceptionHandler(const ExceptionHandler& handler);
199 
203  const ExceptionHandler& getExceptionHandler() const;
204 
205 
207  agxData::JournalArchive* getFileJournal() const;
208 
212  const agxData::JournalArchive::SessionTable& getSessions() const;
213 
218  agxData::JournalArchive::Session* loadNewestSession();
219 
220 
221 
222 
224  agxData::JournalArchive::Session* getSession( const agx::Name& name );
225 
228  agxData::JournalArchive::Session* createNewSession();
229  agxData::JournalArchive::Session* createNewSession(const Name& name);
230 
234  agxData::JournalArchive::Session* setCurrentSession( const agx::Name& sessionName, bool saveSceneOnNextPreTick=true );
235 
238  void setCurrentSession( agxData::JournalArchive::Session* session, bool saveSceneOnNextPreTick=true );
239 
240  agxData::JournalArchive::Session *getCurrentSession();
241 
245  bool renameCurrentSession( const agx::String& newName );
246 
250  bool removeSession( const agx::Name& sessionName );
251 
252 
257  agxData::FrameRef readFrameWithIndex(agx::UInt index);
258 
263  agxData::FrameRef readFrameAtTime(agx::Real time);
267  agx::UInt16 getSerializationVersion() const;
268 
269 
270  agxData::Track *getTrack();
271  agxSDK::SimulationFrameReader *getSimulationReader();
272  agxSDK::SimulationFrameWriter *getSimulationWriter();
273  agxData::DiskFrameReader *getFileReader();
274  agxData::DiskFrameWriter *getFileWriter();
275 
276  const agxData::Track *getTrack() const;
277  const agxSDK::SimulationFrameReader *getSimulationReader() const;
278  const agxSDK::SimulationFrameWriter *getSimulationWriter() const;
279  const agxData::DiskFrameReader *getFileReader() const;
280  const agxData::DiskFrameWriter *getFileWriter() const;
281 
282 
285  void setSceneLoader(SceneLoaderCallback loader);
286 
288  void setRenderLoader(RenderLoaderCallback loader);
289 
290  RenderLoaderCallback getRenderLoader();
291  void triggerFrame();
292 
293 
295  agxData::JournalArchive::Session *findNewestSession();
296 
299  static bool findNewestSession( const agx::String& diskPath, agx::JournalRef& journal, agxData::JournalArchive::SessionRef& session);
300 
302 
303 
307  void attachStandalone( agxData::FrameReader* input, agxData::FrameWriter* output );
308 
310 
312  void saveScene();
313 
323  void setSaveSceneToDisk( bool flag );
324 
328  bool getSaveSceneToDisk() const;
329 
330  protected:
331  virtual ~Journal();
332 
333  private:
334 
335  void preTickCallback(Clock *clock);
336  void initPlayback();
337  void defaultSceneLoader(const String& path);
338  // void postTickCallback(Clock *clock);
339  void trackExceptionCallback(agxData::Track *track, std::exception& e);
340  void createApiTrack();
341 
342 
343  private:
344  agxData::JournalArchiveRef m_diskJournal;
345 
346  ExceptionHandler m_exceptionHandler;
347 
348  Mode m_mode;
349  agxData::JournalArchive::SessionRef m_currentSession;
350  agxSDK::SimulationObserver m_simulation;
351 
352  agxData::TrackRef m_track;
353  agxSDK::SimulationFrameReaderRef m_simulationReader;
354  agxSDK::SimulationFrameWriterRef m_simulationWriter;
355  agxData::DiskFrameWriterRef m_fileWriter;
356  agxData::DiskFrameReaderRef m_fileReader;
357 
358  SceneLoaderCallback m_sceneLoader;
359  RenderLoaderCallback m_renderLoader;
360 
361 
362  agxData::TrackRef m_apiTrack;
363  // agxData::DiskFrameReaderRef m_apiFileReader;
364  // agxSDK::SimulationFrameReaderRef m_apiSimulationReader;
365 
366  // ComponentRef m_context;
367  // ClockRef m_clock;
368  Clock::TickEvent::CallbackType m_preTickCallback;
369  // Clock::TickEvent::CallbackType m_postTickCallback;
370 
371 
372  Mutex m_mutex;
373  Block m_block;
374 
375  bool m_hasSavedScene;
376  Callback m_loadStartFrameCallback;
377  ArchiveFormat m_archiveFormat;
378  bool m_saveSimulationToDisk;
379  bool m_passive;
380  bool m_loadPlot;
381  Real m_recordStartTime;
382  bool m_isRecording;
383  agx::UInt16 m_serializationVersion;
384  bool m_enableIncrementalStructure;
385  bool m_isJumping;
386  };
387 
388  class AGXPHYSICS_EXPORT Journal::Converter
389  {
390  public:
392  {
401  };
402 
404  ProgressEvent progressEvent;
405 
407  SessionEvent sessionStartEvent;
408  SessionEvent sessionEndEvent;
409 
410  public:
411  Converter();
412 
413  void execute();
414 
415  void setSourcePath(const agx::String& path);
416  void setTargetPath(const agx::String& path);
417  void setTargetFormat(ArchiveFormat format);
418  void setExpand(agx::Bool expand);
419  void setStartTime(agx::Real startTime);
420  void setEndTime(agx::Real endTime);
421  void setFrameStride(agx::UInt stride);
422 
423  void extractScene(const agx::String& sessionName);
424 
425 
426  const agx::String& getSourcePath() const;
427  const agx::String& getTargetPath() const;
428  ArchiveFormat getTargetFormat() const;
429  agx::Bool getExpand() const;
430  agx::Real getStartTime() const;
431  agx::Real getEndTime() const;
432  agx::UInt getFrameStride() const;
433 
434  private:
435  void writeCallback(const agxData::Frame *frame);
436  void convertSession(
438 
439  private:
440  agx::String m_sourcePath;
441  agx::String m_targetPath;
442  ArchiveFormat m_format;
443  agx::Bool m_expand;
444  agx::Real m_startTime;
445  agx::Real m_endTime;
446  agx::UInt m_stride;
448  agxData::JournalArchiveRef m_sourceArchive;
449  agxData::JournalArchiveRef m_targetArchive;
450  SessionHeader m_currentSession;
451  agx::UInt m_numFramesWritten;
452  };
453 
454 
455  /* Implementation */
456 
457  AGX_FORCE_INLINE const Name& Journal::getName() const { return m_diskJournal->getName(); }
458  AGX_FORCE_INLINE const String& Journal::getDiskPath() const { return m_diskJournal->getPath(); }
461  AGX_FORCE_INLINE const agxSDK::Simulation *Journal::getSimulation() const { return m_simulation; }
462 
464 
468 
471 
472  AGX_FORCE_INLINE const agxData::Track *Journal::getTrack() const { return m_track; }
475 
476  AGX_FORCE_INLINE const agxData::DiskFrameReader *Journal::getFileReader() const { return m_fileReader; }
477  AGX_FORCE_INLINE const agxData::DiskFrameWriter *Journal::getFileWriter() const { return m_fileWriter; }
478 
480 
481 }
482 
483 
484 #endif /* AGX_JOURNAL_H */
Helper class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:34
Representation of a path, a list of name components.
Definition: Path.h:33
SessionEvent sessionEndEvent
Definition: Journal.h:408
agx::Event1< UInt > ProgressEvent
Definition: Journal.h:403
agx::ref_ptr< Track > TrackRef
Definition: agxData/Track.h:34
agxData::JournalArchive::Session * getCurrentSession()
Definition: Journal.h:463
Session(const agx::Name &name)
bool Bool
Definition: Integer.h:48
agxData::DiskFrameWriter * getFileWriter()
Definition: Journal.h:470
Base class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:107
Generalized callback, using std::function.
Definition: Callback.h:53
agxSDK::Simulation * getSimulation()
Definition: Journal.h:460
agxSDK::SimulationFrameReader * getSimulationReader()
Definition: Journal.h:466
The JournalArchive provides an abstract class for inspecting and manipulating the contents of a creat...
#define AGXPHYSICS_EXPORT
agx::ref_ptr< Frame > FrameRef
Definition: Frame.h:52
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:62
agx::Callback2< Journal *, std::exception & > ExceptionHandler
Definition: Journal.h:64
agx::Event1< SessionHeader > SessionEvent
Definition: Journal.h:406
Block synchronization primitive.
Base class providing referencing counted objects.
Definition: Referenced.h:113
agxData::Track * getTrack()
Definition: Journal.h:465
uint32_t UInt
Definition: Integer.h:34
const Name & getName() const
Definition: Journal.h:457
agx::ref_ptr< SimulationFrameWriter > SimulationFrameWriterRef
Callback1< const agx::String & > SceneLoaderCallback
A callback that will be called when starting playback from a recording.
Definition: Journal.h:284
agx::ref_ptr< DiskFrameReader > DiskFrameReaderRef
Definition: DiskTrack.h:27
Mode getMode() const
Definition: Journal.h:459
agx::ref_ptr< DiskFrameWriter > DiskFrameWriterRef
Definition: DiskTrack.h:102
agx::ref_ptr< JournalArchive > JournalArchiveRef
agxSDK::SimulationFrameWriter * getSimulationWriter()
Definition: Journal.h:467
typedef void(GLAD_API_PTR *GLDEBUGPROC)(GLenum source
agxData::DiskFrameReader * getFileReader()
Definition: Journal.h:469
const String & getDiskPath() const
Set the disk path.
Definition: Journal.h:458
agx::ref_ptr< SimulationFrameReader > SimulationFrameReaderRef
std::mutex Mutex
Definition: Referenced.h:93
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
Clock class keeps representation of virtual/simulated time.
Definition: Clock.h:37
ProgressEvent progressEvent
Definition: Journal.h:404
uint16_t UInt16
Definition: Integer.h:39
agx::observer_ptr< Simulation > SimulationObserver
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
Callback2< agxSDK::Assembly *, bool > RenderLoaderCallback
Definition: Journal.h:287
SessionEvent sessionStartEvent
Definition: Journal.h:407
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:101
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:100
agx::Object is a refcounted object with a name.
Definition: Object.h:59