AGX Dynamics  2.37.3.2
FrameIO.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 #ifndef AGXDATA_FRAMEIO_H
18 #define AGXDATA_FRAMEIO_H
19 
20 #include <agxData/Frame.h>
22 
23 namespace agxData
24 {
26 
29 
32 
34 
36  {
37  public:
41  bool isActive() const;
42 
46  Track *getTrack();
47  const Track *getTrack() const;
48 
58  void addDataBinding(const agx::Path& internalPath, const agx::Path& externalPath, bool recursive = false);
59 
63  void addDataBinding(const agx::Path& path, bool recursive = false);
64 
65 
66  bool removeDataBinding( const agx::Path& path );
67  bool removeDataBinding( const agx::Path& internalPath, const agx::Path& externalPath );
68 
69  // void addDataBinding(const agx::Path& storagePath, agx::UInt32 instanceId, const agx::String& attributeName);
70 
81  void loadDataBindings(const agx::String& xmlFilePath);
82 
83  bool loadDataBindingsJSON(const agx::String& jsonFilePath);
84 
85 
86 
91  const Frame::DataBindingRefVector& getDataBindings() const;
92 
96  void clearDataBindings();
97 
98 
99  void setHeaderFormat(SerializedFrame::HeaderFormat format);
100  SerializedFrame::HeaderFormat getHeaderFormat() const;
101 
102  protected:
103  FrameIO(bool active);
104  virtual ~FrameIO();
105 
106  void addDataBinding(Frame::DataBinding *binding);
107 
108  private:
109  friend class Track;
110  void setTrack(Track *track);
111 
112  // Implementations may override this
113  virtual Frame::DataBinding *createDataBinding(const agx::Path& internalPath, const agx::Path& externalPath);
114 
115  private:
116  bool m_active;
117  Track *m_track;
118  Frame::DataBindingRefVector m_dataBindings;
119  SerializedFrame::HeaderFormat m_headerFormat;
120  };
121 
122 
127  {
128  public:
129  FrameReader(bool active);
130 
131 
132  // This was removed due to thread synchronizing issues
133  // virtual agx::UInt getNextFrameSize() = 0;
134 
142  virtual Frame* readFrame() = 0;
143 
144  virtual agx::UInt getNextFrameIndex();
145  virtual void advanceToNextFrame();
146 
151  virtual bool jumpToFrame(agx::UInt frameIndex);
152  virtual bool jumpToTime(agx::Real time);
153 
154 
155  virtual bool shouldExtract(const agx::Path& path);
156 
157  virtual agx::Real getTimeStep();
158  virtual agx::UInt getFrameStride();
159 
160  protected:
161  virtual ~FrameReader();
162  };
163 
164 
169  {
170  public:
172  WriteEvent writeEvent;
173 
174  public:
175  FrameWriter(bool active);
176 
180  virtual void writeFrame(const Frame *frame) = 0;
181 
182  // TODO: Clean redesign, this is ugly
183  virtual void forceFlush() {}
184 
185 
186  virtual void endOfStream() {}
187 
188  agx::UInt getNumWrittenFrames() const;
189 
190  bool isEOF() const;
191 
192  protected:
193  virtual ~FrameWriter();
194 
196  private:
197  friend class Track;
198  void setEOF(bool flag);
199 
200  private:
201  bool m_eof;
202  };
203 
204 
209  {
210  public:
212 
213  virtual void writeFrame(const agxData::Frame *frame) override;
214 
215  protected:
216  virtual ~DebugFrameWriter();
217  };
218 
219 
220 
221 
226  {
227  public:
228  FrameChannel(FrameReader* reader, FrameWriter* writer) : m_reader(reader), m_writer(writer) {};
229 
230  FrameReader* getReader() { return m_reader; }
231  FrameWriter* getWriter() { return m_writer; }
232 
233  protected:
234  virtual ~FrameChannel() {};
235 
236  private:
237  FrameReaderRef m_reader;
238  FrameWriterRef m_writer;
239  };
240 
241 
242 
243  /* Implementation */
244 
245  //---------------------------------------------------------------
246 
247  AGX_FORCE_INLINE bool FrameIO::isActive() const { return m_active; }
248  AGX_FORCE_INLINE Track *FrameIO::getTrack() { return m_track; }
249  AGX_FORCE_INLINE const Track *FrameIO::getTrack() const { return m_track; }
250 
251  AGX_FORCE_INLINE const Frame::DataBindingRefVector& FrameIO::getDataBindings() const { return m_dataBindings; }
253 
254  //---------------------------------------------------------------
255 
256 
257  //---------------------------------------------------------------
258 
259  AGX_FORCE_INLINE bool FrameWriter::isEOF() const { return m_eof; }
260  AGX_FORCE_INLINE agx::UInt FrameWriter::getNumWrittenFrames() const { return m_numWrittenFrames; }
261 
262  //---------------------------------------------------------------
263 
264 }
265 
266 
267 #endif /* AGXDATA_FRAMEIO_H */
Representation of a path, a list of name components.
Definition: Path.h:32
Track * getTrack()
Definition: FrameIO.h:248
Convenience class that store a FrameReader and a FrameWriter.
Definition: FrameIO.h:225
virtual void forceFlush()
Definition: FrameIO.h:183
virtual ~FrameChannel()
Definition: FrameIO.h:234
The FrameReader reads frames from an external source.
Definition: FrameIO.h:126
agx::UInt m_numWrittenFrames
Definition: FrameIO.h:195
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
bool isActive() const
Definition: FrameIO.h:247
FrameReader * getReader()
Definition: FrameIO.h:230
#define AGX_FORCE_INLINE
Definition: Object.h:59
Base class providing referencing counted objects.
Definition: Referenced.h:119
The FrameWriter writes frames to an external target.
Definition: FrameIO.h:168
uint32_t UInt
Definition: Integer.h:34
SerializedFrame::HeaderFormat getHeaderFormat() const
Definition: FrameIO.h:252
FrameWriter * getWriter()
Definition: FrameIO.h:231
Contains classes for low level data storage for AGX.
Definition: Container.h:23
bool isEOF() const
Definition: FrameIO.h:259
agx::UInt getNumWrittenFrames() const
Definition: FrameIO.h:260
virtual void endOfStream()
Definition: FrameIO.h:186
agx::Event1< const Frame * > WriteEvent
Definition: FrameIO.h:171
The DebugFrameWriter prints the contents processed frames.
Definition: FrameIO.h:208
const Frame::DataBindingRefVector & getDataBindings() const
Definition: FrameIO.h:251
double Real
Definition: Real.h:42
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
WriteEvent writeEvent
Definition: FrameIO.h:172
FrameChannel(FrameReader *reader, FrameWriter *writer)
Definition: FrameIO.h:228
#define AGXCORE_EXPORT
agx::Object is a refcounted object with a name.
Definition: Object.h:58