00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00107 #if ! defined ( PIAVE_BASE_HH )
00108 #define PIAVE_BASE_HH
00109
00110
00111 #include <unistd.h>
00112 #include <stdint.h>
00113 #include <errno.h>
00114
00115
00116 #include <iostream>
00117 #include <string>
00118
00119
00120
00121 #ifdef ENABLE_NLS
00122 # include <libintl.h>
00123 # undef _
00124 # define _(String) dgettext (PACKAGE, String)
00125 # ifdef gettext_noop
00126 # define N_(String) gettext_noop (String)
00127 # else
00128 # define N_(String) (String)
00129 # endif
00130 #else
00131 # define textdomain(String) (String)
00132 # define gettext(String) (String)
00133 # define dgettext(Domain,Message) (Message)
00134 # define dcgettext(Domain,Message,Type) (Message)
00135 # define bindtextdomain(Domain,Directory) (Domain)
00136 # define _(String) (String)
00137 # define N_(String) (String)
00138 #endif
00139
00140
00141
00142
00143
00144 #define ABORT(S) { std::cerr << __FILE__ << ":" << __LINE__ << " ERROR: " << S << std::endl; abort(); }
00145 #define WARN(S) { if ( ! PIAVE::Global::quiet ) \
00146 std::cerr << __FILE__ << ":" << __LINE__ << " WARNING: " << S << std::endl; }
00147 #define INFO(S) { if ( PIAVE::Global::verbose && ! PIAVE::Global::quiet ) \
00148 std::cout << __FILE__ << ":" << __LINE__ << " INFO: " << S << std::endl; }
00149 #define ABORT_IF(C,S) { if ( C ) { std::cerr << __FILE__ << ":" << __LINE__ \
00150 << " ERROR: (" << #C <<"): "<< S << std::endl; abort(); }}
00151 #define WARN_IF(C,S) { if ( ! PIAVE::Global::quiet ) \
00152 if ( C ) { std::cerr << __FILE__ << ":" << __LINE__ \
00153 << " WARNING: (" << #C <<"): " << S << std::endl; }}
00154 #define INFO_IF(C,S) { if ( PIAVE::Global::verbose && ! PIAVE::Global::quiet ) \
00155 if ( C ) { std::cout << __FILE__ << ":" << __LINE__ \
00156 << " INFO: (" << #C <<"): " << S << std::endl; }}
00157
00158 #define PRINTV(C) " "<<#C<<"="<<C
00159
00160 #define PDELETE(P) if ( P!=0 ) { delete P ; P = 0;}
00161
00162
00163
00164
00165
00166
00167 namespace PIAVE {
00168
00169 class FOURCC;
00170 class Algorithm;
00171 class Time;
00172 class VideoFmt;
00173
00181 class Global
00182 {
00183 public:
00185 static bool verbose;
00186
00188 static bool quiet;
00189
00191 static bool force_decode;
00192
00193
00194
00195
00196 static VideoFmt renderFmt;
00197
00198
00199
00200
00201
00202
00203 static Algorithm * algo;
00204
00205
00206 static char cbuf[1024];
00207
00217 static void Init();
00218
00222 static void Destroy();
00223
00224
00225
00226
00227
00228
00232 static int hexCharToI( const char a, const char b );
00233
00237 static void printBackTrace();
00238
00242 static void fatalSignalHandler( int );
00243
00244 };
00245
00250 void Init();
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 class Time
00262 {
00263 public:
00264 Time( double s = 0.0 ) : _sec( s ) {}
00265 Time( const Time & o ) : _sec( o._sec ) {}
00266 explicit Time( const std::string & s );
00267
00268 double sec() const { return _sec; }
00269
00270 const Time operator=( const Time & o ) { _sec = o._sec; return (*this); }
00271 const Time operator+( const Time & o ) const { return Time( _sec + o._sec ); }
00272 const Time operator-( const Time & o ) const { return Time( _sec - o._sec ); }
00273 const double operator*( const Time & o ) const { return _sec * o._sec; }
00274 const double operator/( const Time & o ) const { return _sec / o._sec; }
00275 const Time operator+=( const Time & o ) { return _sec += o._sec; }
00276 const Time operator-=( const Time & o ) { return _sec -= o._sec; }
00277
00278 bool operator==( const Time & o ) const {
00279 return (_sec-0.000001<o._sec)&&(_sec+0.000001>o._sec); }
00280 bool operator!=( const Time & o ) const {
00281 return (_sec-0.000001>o._sec)||(_sec+0.000001<o._sec); }
00282 bool operator>( const Time & o ) const { return _sec>o._sec; }
00283 bool operator<( const Time & o ) const { return _sec<o._sec; }
00284 bool operator>=( const Time & o ) const { return ! (_sec<o._sec); }
00285 bool operator<=( const Time & o ) const { return ! (_sec>o._sec); }
00286
00290 std::string toString() const;
00291
00295 timeval toTimeval() const;
00296
00297 private:
00298 double _sec;
00299 };
00300 std::ostream& operator<<( std::ostream&, const Time& );
00301
00302
00303
00304
00305
00306
00307 class TimeInterval
00308 {
00309 public:
00310 TimeInterval( Time start=0, Time length=0 ) :
00311 _start( start ), _length( length ) {}
00312 TimeInterval( const TimeInterval & o ) :
00313 _start( o.start() ), _length( o.length() ) {};
00314
00315 Time start() const { return _start; }
00317 Time stop() const { return _start+_length; }
00318 Time length() const { return _length; }
00319
00320
00321 Time setStart ( const Time start ) { return _start=start; }
00322 Time setStop ( const Time stop ) { if (stop>=_start) _length=stop-_start; return _length; }
00323 Time setLength( const Time length ) { return _length=length; }
00324
00325 const TimeInterval & setTime( const TimeInterval & i )
00326 { _start=i.start(); _length=i.length(); return (*this); }
00327 const TimeInterval & operator=( const TimeInterval & o )
00328 { setTime( o ); return (*this); }
00329
00331 bool contains ( const Time t ) const
00332 { return (t>=_start && t<_start+_length); }
00334 TimeInterval intersect( const TimeInterval & t ) const ;
00336 TimeInterval join( const TimeInterval & t ) const ;
00338 bool operator==( const TimeInterval & o ) const {
00339 return _start==o._start && _length==o._length; };
00341 bool operator!=( const TimeInterval & o ) const {
00342 return ! operator==( o ); }
00343
00346 virtual void print( std::ostream & o, int indent ) const;
00347
00348 private:
00349 Time _start;
00350 Time _length;
00351 };
00352 std::ostream& operator<<( std::ostream&, const TimeInterval& );
00353
00354
00355
00356
00357
00358
00359
00360 template<class I, class T>
00361 I
00362 previous( I first, I last, const T& val)
00363 {
00364 I o;
00365 while ( first != last ) {
00366 if ( (*first) == val ) return first;
00367 o = first;
00368 ++first;
00369 if ( first == last ) return o;
00370 if ( (*first) > val ) return o;
00371 }
00372
00373 return first;
00374 }
00375
00385 class Point
00386 {
00387 public:
00388 Point( double x, double y ) : _x( x ), _y( y ) {}
00389 Point( const Point & p ) : _x( p._x ), _y( p._y ) {}
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00406
00407 double y() const { return _y; }
00408
00409
00410
00412
00413 int ly() const;
00414
00415
00416 private:
00417 double _x;
00418 double _y;
00419 };
00420
00429 class Box
00430 {
00431 public:
00432 Box( double x = 0.1 , double y = 0.1 , double w = 0.8 , double h = 0.8 ) :
00433 _x(x),_y(y),_w(w),_h(h) {}
00435 Box( Point ul, Point lr ) :
00436 _x(ul.x()),_y(ul.y()),_w(lr.x()-ul.x()),_h(lr.y()-ul.y()) {}
00437
00438
00440
00441 double y() const { return _y; }
00442 double w() const { return _w; }
00443 double h() const { return _h; }
00444 double x2() const { return _x+_w; }
00445 double y2() const { return _y+_h; }
00446
00447
00448
00450
00451 int lx() const;
00452 int ly() const;
00453 int lw() const;
00454 int lh() const;
00455 int lx2() const;
00456 int ly2() const;
00457
00458
00460 Point ul() const { return Point( _x,_y ); }
00462 Point lr() const { return Point( x2(),y2() ); }
00463
00464 private:
00465 double _x,_y,_w,_h;
00466
00467 };
00468 std::ostream& operator<<( std::ostream&, const Box& );
00469
00470
00475 class Color
00476 {
00477 public:
00478 enum Space {
00479 NONE,
00480 RGB,
00481 YUV
00482 };
00483
00484 Color( uint8_t a=0, uint8_t b=0, uint8_t c=0, uint8_t d=0 ) {
00485 _col[0] = a; _col[1] = b; _col[2] = c; _col[3] = d; }
00486 Color( const std::string & c );
00487
00488 uint8_t & operator [] ( uint i ) { return _col[i]; }
00489 const uint8_t & operator [] ( uint i ) const { return _col[i]; }
00490 Space space() const { return _space; }
00491 void setSpace( Space s ) { _space=s; }
00492
00493 std::string toString3() const;
00494 std::string toString4() const;
00495 std::string toStringA() const;
00496
00497 private:
00498 Space _space;
00499 uint8_t _col[4];
00500
00501 public:
00502 static const Color white;
00503 static const Color black;
00504 static const Color red;
00505 static const Color green;
00506 static const Color blue;
00507 static const Color yellow;
00508 static const Color magenta;
00509 static const Color cyan;
00510 static const Color transparent_black;
00511 static const Color transparent_white;
00512 };
00513 std::ostream& operator<<( std::ostream&, const Color& );
00514
00515 };
00516
00517 #endif