This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathAnimation.hpp
70 lines (62 loc) · 1.95 KB
/
Animation.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef Animation_hpp
#define Animation_hpp
#include <stdio.h>
#include <vector>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <json.hpp>
#include "AnimatedRig.hpp"
class Animation
{
public:
Animation( double targetFps );
~Animation();
double SegmentDuration() const { return _segmentDuration; }
void SegmentDuration( double v ) { _segmentDuration = v; }
void OutputDirectory( std::string v ) { _outputDirectory = v; }
void Smooth( SMOOTH_TYPE v ) { _smoothType = v; }
void MaxMissingFrameGap( double v ) { _maxMissingFrameGap = v; }
const std::vector< std::string > & SegmentFilenames() const;
void FlushSegments();
void AddPose( std::string rigId,
std::unique_ptr< Pose > & pose );
const std::map< std::string, AnimatedRig > & GetAnimatedRigs() const;
private:
std::vector< std::pair< int, int > > GetBounds( int & start,
int & end );
void WriteForever();
void ProcessAndWrite( int startTimestamp,
int endTimestamp,
bool flush = false );
double _segmentDuration;
std::map< std::string, AnimatedRig > _animatedRigs;
std::vector< std::string > _segmentFilenames;
std::thread _thread;
std::mutex _mutex;
std::condition_variable _flushEvent;
volatile bool _quit = false;
double _fps;
std::unique_ptr< nlohmann::json > _json;
std::string _outputDirectory;
double _maxMissingFrameGap = 0.5;
volatile bool _flush = false;
SMOOTH_TYPE _smoothType = SMOOTH_TYPE_NONE;
};
#endif /* Animation_hpp */
inline const std::map< std::string, AnimatedRig > & Animation::GetAnimatedRigs() const
{
return _animatedRigs;
}
inline const std::vector< std::string > & Animation::SegmentFilenames() const
{
return _segmentFilenames;
}
inline void Animation::FlushSegments()
{
// Mark for writing
_flush = true;
// Wait for the flush to complete for safety
std::unique_lock< std::mutex > waitLock( _mutex );
_flushEvent.wait( waitLock );
}