Debian Codegraph @

cvd/timeddiskbuffer.h

raw symbols SCIP
1 #ifndef TIMEDDISKBUFFER_H
2 #define TIMEDDISKBUFFER_H
3
4 #include <cvd/diskbuffer2.h>
5
6 namespace CVD
7 {
8
9 namespace Exceptions
10 {
11 /// %Exceptions specific to DiskBuffer2
12 /// @ingroup gException
13 namespace TimedDiskBuffer
14 {
15 /// Base class for all DiskBuffer2 exceptions
16 /// @ingroup gException
17 struct All : public CVD::Exceptions::VideoBuffer::All
18 {
19 using CVD::Exceptions::VideoBuffer::All::All;
20 };
21 /// list lengths for name and time lists do not agree
22 /// @ingroup gException
23 struct IncompatibleListLengths : public All
24 {
25 IncompatibleListLengths();
26 };
27 }
28 }
29
30 /// Play a series of image files as a video stream and use a list of provided timestamps.
31 /// Provides frames of type CVD::DiskBuffer2Frame and throws exceptions of type
32 /// CVD::Exceptions::DiskBuffer2 and CVD::Exceptions::TimedDiskBuffer
33 /// @param T The pixel type of the frames to provide (usually <code>CVD::Rgb<CVD::byte></code>
34 /// or <code>CVD::byte</code>. If the image files are of a different type, they will be automatically
35 /// converted (see @link gImageIO Image loading and saving, and format conversion@endlink).
36 /// @ingroup gVideoBuffer
37 template <class T>
38 class TimedDiskBuffer : public CVD::DiskBuffer2<T>
39 {
40 public:
41 /// Construct a TimedDiskBuffer2 from a vector of filenames and timestamps.
42 /// see @ref Diskbuffer2 for details on how to use it.
43 /// @param names The filenames to use (played in the order that they are in the vector)
44 /// @param times The frame time stamps
45 /// @param eob What should the buffer do when it reaches the end of the list of files?
46 TimedDiskBuffer(const std::vector<std::string>& names, const std::vector<double>& times, CVD::VideoBufferFlags::OnEndOfBuffer eob = CVD::VideoBufferFlags::RepeatLastFrame);
47
48 virtual CVD::DiskBuffer2Frame<T>* get_frame();
49
50 protected:
51 std::vector<double> file_times;
52 };
53
54 template <class T>
55 inline TimedDiskBuffer<T>::TimedDiskBuffer(const std::vector<std::string>& names, const std::vector<double>& times, CVD::VideoBufferFlags::OnEndOfBuffer eob)
56 : CVD::DiskBuffer2<T>(names, 1, eob)
57 {
58 if(times.size() != names.size())
59 throw Exceptions::TimedDiskBuffer::IncompatibleListLengths();
60 file_times = times;
61 }
62
63 //
64 // GET FRAME
65 //
66 template <class T>
67 inline CVD::DiskBuffer2Frame<T>* TimedDiskBuffer<T>::get_frame()
68 {
69 int current_frame = this->next_frame;
70 if(current_frame < 0)
71 current_frame = 0;
72 // get a frame from the super class
73 CVD::DiskBuffer2Frame<T>* vf = CVD::DiskBuffer2<T>::get_frame();
74 vf->timestamp(file_times[current_frame]);
75 return vf;
76 }
77 }
78
79 #endif