AGX Dynamics  2.37.3.2
Hdf5Track.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are 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 
18 
19 #ifndef AGXDATA_HDF5_TRACK_H
20 #define AGXDATA_HDF5_TRACK_H
21 
22 #include <agx/config/AGX_USE_HDF5.h>
23 #include <agx/config.h>
24 
25 #if AGX_USE_HDF5()
26 
27 #include <agx/agx.h>
28 #include <agxData/DiskTrack.h>
29 #include <agxData/Hdf5Journal.h>
30 
32 
33 #include <agx/AgxH5.h>
34 
35 namespace agxData
36 {
37 
38 
39  AGX_DECLARE_POINTER_TYPES( Hdf5FrameReader );
40 
44  class AGXCORE_EXPORT Hdf5FrameReader : public agxData::DiskFrameReader
45  {
46  public:
47  Hdf5FrameReader( agxData::JournalArchive::Session* session );
48 
49 
50  virtual const agxData::JournalArchive::Session* getSession() const override;
51 
52 
63  virtual bool jumpToFrame( agx::UInt frameIndex ) override;
64 
68  virtual bool jumpToTime( agx::Real time ) override;
69 
71  agx::UInt getFrameOffset() const;
72 
74  protected:
75  virtual ~Hdf5FrameReader();
76 
77  virtual agxData::Frame* readFrame( agx::UInt frameIndex ) override;
78 
79  private:
80  bool isValidFrame( agx::UInt frameIndex ) const;
81 
82  void extractEvents( H5::Group& frameNode, agx::Object::EventRefVector& events );
83 
84  SerializedFrame::Component* createFrame( H5::Group& frameNode );
85  SerializedFrame::Component* createComponent( H5::Group& componentNode, const H5std_string& name );
86  SerializedFrame::EntityStorage* createEntityStorage( H5::Group& storageNode, const H5std_string& name );
87  SerializedFrame::Node* createBuffer( H5::Group& bufferNode, const H5std_string& name );
88  SerializedFrame::Node* createValue( H5::Group& valueNode, const H5std_string& name );
89  void addChildren( agxData::SerializedFrame::Component* frameNode, H5::Group& hdf5Node );
90  void addBuffers( agxData::SerializedFrame::Component* frameNode, H5::Group& hdf5Node );
91  void addValues( agxData::SerializedFrame::Component* frameNode, H5::Group& hdf5Node );
92 
93  void readComponent();
94  void readBuffer();
95  void readValue();
96 
97 
98  private:
99  agxData::Hdf5Journal::Session* m_session;
100  agx::Path m_nodePath;
101  };
102 
103  AGX_DECLARE_POINTER_TYPES( Hdf5FrameWriter );
104 
105  class AGXCORE_EXPORT Hdf5FrameWriter : public agxData::DiskFrameWriter
106  {
107  public:
108  Hdf5FrameWriter( agxData::JournalArchive::Session* session );
109 
110  virtual void writeFrame( const agxData::Frame* frame ) override;
111 
112  virtual const JournalArchive::Session* getSession() const override;
113 
114  agx::UInt getNumFramesWritten() const;
115 
116  protected:
117  virtual ~Hdf5FrameWriter();
118 
119  private:
120  static void write( H5::CommonFG& parent, SerializedFrame::EntityStorage* storage );
121  static void write( H5::CommonFG& parent, SerializedFrame::CustomBuffer* buffer );
122  static void write( H5::CommonFG& parent, SerializedFrame::PartialBuffer *buffer );
123  static void write( H5::CommonFG& parent, SerializedFrame::Buffer* buffer );
124  static void write( H5::CommonFG& parent, SerializedFrame::Value* value );
125  static void write( H5::CommonFG& parent, SerializedFrame::Component* component );
126  static void write( H5::CommonFG& parent, SerializedFrame::Node* node );
127  static void writeEvents( H5::CommonFG& parent, const agx::Object::EventRefVector& events );
128 
129  public:
130  static void writeChildren( H5::CommonFG& parent, const agxData::SerializedFrame::Component* component );
131 
132 
133  private:
134  agx::UInt m_numFramesWritten;
135  agxData::Hdf5Journal::SessionRef m_session;
136  };
137 
138 
139 }
140 
141 // AGX_USE_HDF5
142 #endif
143 
144 
145 // Include guard
146 #endif
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:32
Node(const agx::Name &name, agx::Index id)
Session(const agx::Name &name)
Base class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:107
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
uint32_t UInt
Definition: Integer.h:34
Contains classes for low level data storage for AGX.
Definition: Container.h:23
PartialBuffer(agxData::Frame::PartialBuffer *buffer)
bool AGXPHYSICS_EXPORT write(const std::string &filename, const agxStream::Serializable *data)
Write a Serializable object to a file.
CustomBuffer(const agx::Name &name, agx::Index id, const Format *format, size_t numElements)
EntityStorage(const agxData::Frame::EntityStorage *storage)
Buffer(const agx::Name &name, agx::Index id, BinaryData *data, const Format *format, size_t numElements, size_t byteOffset)
Value(const agx::Name &name, agx::Index id, BinaryData *data, const Format *format, size_t offset)
virtual Frame * readFrame() override
Reads the next frame from disk using the virtual readFrame(UInt) method.
double Real
Definition: Real.h:42
#define AGXCORE_EXPORT