TuttleOFX
1
|
00001 #ifndef _TUTTLE_COMMON_OFX_UTILITIES_HPP_ 00002 #define _TUTTLE_COMMON_OFX_UTILITIES_HPP_ 00003 00004 #include <tuttle/common/utils/global.hpp> 00005 00006 #include <ofxCore.h> 00007 #include <ofxImageEffect.h> 00008 00009 #include <string> 00010 #include <vector> 00011 00012 namespace tuttle { 00013 namespace ofx { 00014 00015 /// class that is a std::vector of std::strings 00016 typedef std::vector<std::string> StringVec; 00017 00018 inline void setStringVecValue( StringVec& sv, const std::string& value, size_t index = 0 ) 00019 { 00020 size_t size = sv.size(); 00021 00022 if( size <= index ) 00023 { 00024 while( size < index ) 00025 { 00026 sv.push_back( "" ); 00027 ++size; 00028 } 00029 sv.push_back( value ); 00030 } 00031 else 00032 sv[index] = value; 00033 } 00034 00035 /// get the min value 00036 template<class T> 00037 inline T minimum( const T& a, const T& b ) 00038 { 00039 return a < b ? a : b; 00040 } 00041 00042 /// get the max value 00043 template<class T> 00044 inline T maximum( const T& a, const T& b ) 00045 { 00046 return a > b ? a : b; 00047 } 00048 00049 /// clamp the value 00050 template<class T> 00051 inline T clamp( const T& v, const T& min, const T& max ) 00052 { 00053 if( v < min ) 00054 return min; 00055 if( v > max ) 00056 return max; 00057 return v; 00058 } 00059 00060 /// clamp the rect in v to the given bounds 00061 inline OfxRectD clamp( const OfxRectD& v, 00062 const OfxRectD& bounds ) 00063 { 00064 OfxRectD r; 00065 00066 r.x1 = clamp( v.x1, bounds.x1, bounds.x2 ); 00067 r.x2 = clamp( v.x2, bounds.x1, bounds.x2 ); 00068 r.y1 = clamp( v.y1, bounds.y1, bounds.y2 ); 00069 r.y2 = clamp( v.y2, bounds.y1, bounds.y2 ); 00070 return r; 00071 } 00072 00073 /// get the union of the two rects 00074 inline OfxRectD rectUnion( const OfxRectD& a, 00075 const OfxRectD& b ) 00076 { 00077 OfxRectD r; 00078 00079 r.x1 = minimum( a.x1, b.x1 ); 00080 r.x2 = maximum( a.x2, b.x2 ); 00081 r.y1 = minimum( a.y1, b.y1 ); 00082 r.y2 = maximum( a.y2, b.y2 ); 00083 return r; 00084 } 00085 00086 } 00087 } 00088 00089 #endif 00090