VNMediaClientNET

JsonObjectsTracker.h
1
13 #ifndef JSONOBJECTSTRACKER_H
14 #define JSONOBJECTSTRACKER_H
15
16 #include <map>
17 #include <set>
18 #include <vector>
19 #include <list>
20 #include <string>
21 #include <boost/shared_ptr.hpp>
22
23 #if defined( WIN32 ) && defined( _MSC_VER )
24 #include <WinSock2.h>
25 #endif
26
27 #include "AbstractObjectsTracker.h"
28 #include "Logger.h"
29
30 #define OBJEVT_COUNT 2
31 #define MLPG_COUNT 3
32 #define MILLION 1000000
33
34 namespace Json { class Value; }
35
36 class JsonObjectsTracker : public AbstractObjectsTracker
37 {
38 public: // to provide non-static version (some of JsonObjectsTracker objects) add 'parent' to RenderObject
39 void setFrameTime( struct timeval* tv ) { frame_time = tv->tv_sec * (long long) MILLION + tv->tv_usec; }
40 long long frameTime() { return frame_time; }
41 private:
42 long long frame_time;
43 public:
44 JsonObjectsTracker();
45 virtual ~JsonObjectsTracker();
46
47 virtual void setObjectsData(const std::string& Bitstream, const std::map< std::string, std::vector< std::string > >& VisibleMetadata);
48
52 virtual void parseAndDraw(Graphics* g2, const Rectangle2& dstRect, const Rectangle2& srcRect, float zoomFactor);
53
54 void clearObjects();
55
56 void log_debug( const std::string& msg ) { Logger::debug( msg ); }
57
58 private:
59 class RenderObject
60 {
61 public:
62 virtual ~RenderObject();
63 void setObj( long long now, double Lifetime, int LineWidth, Color ObjectColor );
64 void setObj( const RenderObject& ro );
65 virtual void draw( JsonObjectsTracker* jsot );
66 bool isAlive( long long now ) const;
67 public:
68 long long start;
69 long long finish;
70 int lineWidth;
71 Color color;
72 };
73 typedef boost::shared_ptr< RenderObject > RenderObjectPtr;
74
75 class BBObject : public RenderObject
76 {
77 public:
78 virtual void draw( JsonObjectsTracker* jsot );
79 public:
80 int x, y;
81 int w, h;
82 };
83 typedef boost::shared_ptr< BBObject > BBObjectPtr;
84
85 class MLine : public RenderObject
86 {
87 public:
88 virtual void draw( JsonObjectsTracker* jsot );
89 void preparePointData( JsonObjectsTracker* jsot );
90 bool isNativeDraw();
91 public:
92 std::vector< Point2 > points;
93 bool is_native_draw;
94 };
95 typedef boost::shared_ptr< MLine > MLinePtr;
96
97 class Polygon : public MLine
98 {
99 public:
100 virtual void draw( JsonObjectsTracker* jsot );
101 };
102 typedef boost::shared_ptr< Polygon > PolygonPtr;
103
104 class Text : public RenderObject
105 {
106 public:
107 virtual void draw( JsonObjectsTracker* jsot );
108 public:
109 int x, y;
110 float h;
111 std::string msg;
112 std::string style;
113 };
114 typedef boost::shared_ptr< Text > TextPtr;
115
116 class Metadata : public Text
117 {
118 public:
119 virtual void draw( JsonObjectsTracker* jsot );
120 public:
121 //std::string meta_id;
122 };
123 typedef boost::shared_ptr< Metadata > MetadataPtr;
124
125 typedef std::map< std::string, BBObjectPtr > bboxes_map_t;
126 typedef std::map< std::string, RenderObjectPtr > object2_map_t;
127 typedef std::map< std::string, object2_map_t > object_map_t;
128 typedef std::list< RenderObjectPtr > objects_list_t;
129
130 private:
131 bool parseMLPVertecies( MLinePtr ml, const Json::Value& jsPoints );
132 std::list< RenderObjectPtr > parseMLinePolygon( int mp, const Json::Value& js, const Json::Value& parent, const std::string& extraInfo = std::string() );
133 TextPtr parseTextMetadata( int tm, const Json::Value& js, const Json::Value& parent, const std::string& extraInfo = std::string() );
134 void parseRootObject( const Json::Value& js );
135
136 void updateTrails();
137
138 private:
139 static const char* objs_evts[OBJEVT_COUNT];
140 static const char* ml_pg[MLPG_COUNT];
141 static std::set< std::string > notObjIds;
142
143 static std::set< std::string > genNotObjsIds();
144 static const Json::Value getProp( const char* prop, const Json::Value& js, const Json::Value& parent );
145
146 private:
147 bboxes_map_t bboxes[OBJEVT_COUNT];
148 object_map_t objmap;
149 objects_list_t objects;
150
151 bool calc_trail;
152
153 private: // temporal objects
154 Graphics* graph;
155 //int im_height;
156 //Rectangle2 screenRect;
157
158 Rectangle2 dstRect;
159 Rectangle2 srcRect;
160 float zoomFactor;
161 float kW;
162 float kH;
163 float metaY;
164
165 std::vector<int> xPoints;
166 std::vector<int> yPoints;
167 const std::map< std::string, std::vector< std::string > >* visibleMetadata;
168 };
169
170 #endif // JSONOBJECTSTRACKER_H
JsonObjectsTracker
Definition: JsonObjectsTracker.h:37
JsonObjectsTracker::parseAndDraw
virtual void parseAndDraw(Graphics *g2, const Rectangle2 &dstRect, const Rectangle2 &srcRect, float zoomFactor)
Definition: JsonObjectsTracker.cpp:408
Rectangle2
Definition: Rectangle.h:18
Graphics
Definition: Graphics.h:68
AbstractObjectsTracker
Definition: AbstractObjectsTracker.h:25
Color
Definition: Graphics.h:15