Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Sketch.cc

Go to the documentation of this file.
00001 //-*-c++-*-
00002 
00003 #include "Sketch.h"
00004 
00005 namespace DualCoding {
00006 
00007 // These functions must go here instead of in Sketch.h because
00008 // they are not templated.
00009 
00010 #define DEF_MATHOPS_CC(_T1, _T2, _Result) \
00011   DEF_MATHOP_CC( +, _T1, _T2, _Result ) \
00012   DEF_MATHOP_CC( -, _T1, _T2, _Result ) \
00013   DEF_MATHOP_CC( *, _T1, _T2, _Result ) \
00014   DEF_MATHOP_CC( /, _T1, _T2, _Result )
00015 
00016 #define DEF_MATHOP_CC(_Op, _T1, _T2, _Result) \
00017 Sketch<_Result> operator _Op (const Sketch<_T1> &lhs, const Sketch<_T2> &rhs) { \
00018   Sketch<_Result> result(lhs->getName() + #_Op + rhs->getName(), lhs); \
00019   _Result* dest = &(*result.pixels)[0]; \
00020   const _T1* src1 = &(*lhs.pixels)[0]; \
00021   const _T1* end1 = &(*lhs.pixels)[lhs->getNumPixels()]; \
00022   const _T2* src2 = &(*rhs.pixels)[0]; \
00023   while ( src1 != end1 ) \
00024     *dest++ = *src1++ _Op *src2++; \
00025   return result; \
00026 } \
00027 /* continued... */ \
00028 Sketch<_Result> operator _Op (const Sketch<_T1> &lhs, const _T2 value) { \
00029   Sketch<_Result> result(lhs->getName() + #_Op + "scalar", lhs); \
00030   _Result* dest = &(*result.pixels)[0]; \
00031   const _T1* src1 = &(*lhs.pixels)[0]; \
00032   const _T1* end1 = &(*lhs.pixels)[lhs->getNumPixels()]; \
00033   while ( src1 != end1 ) \
00034     *dest++ = *src1++ _Op (_Result)value; \
00035   return result; \
00036 }
00037 
00038 // DEF_MATHOPS(bool, bool, bool) disallowed because valarray<bool> doesn't provide arithmetic
00039 DEF_MATHOPS_CC(bool, uchar, uchar)
00040 DEF_MATHOPS_CC(bool, uint, uint)
00041 DEF_MATHOPS_CC(bool, float, float)
00042 
00043 DEF_MATHOPS_CC(uchar, bool, uchar)
00044 DEF_MATHOPS_CC(uchar, uchar, uchar)
00045 DEF_MATHOPS_CC(uchar, uint, uint)
00046 DEF_MATHOPS_CC(uchar, float, float)
00047 
00048 DEF_MATHOPS_CC(usint, bool, usint)
00049 DEF_MATHOPS_CC(usint, uchar, usint)
00050 DEF_MATHOPS_CC(usint, usint, usint)
00051 DEF_MATHOPS_CC(usint, float, float)
00052 
00053 DEF_MATHOPS_CC(uint, bool, uint)
00054 DEF_MATHOPS_CC(uint, uchar, uint)
00055 DEF_MATHOPS_CC(uint, uint, uint)
00056 DEF_MATHOPS_CC(uint, float, float)
00057 
00058 DEF_MATHOPS_CC(float, bool, float)
00059 DEF_MATHOPS_CC(float, uchar, float)
00060 DEF_MATHOPS_CC(float, uint, float)
00061 DEF_MATHOPS_CC(float, float, float)
00062 
00063 #undef DEF_MATHOPS_CC
00064 #undef DEF_MATHOP_CC
00065 
00066 #define DEF_MATHOPS_INT_CC(_T1) \
00067   DEF_MATHOP_INT_CC( +, _T1) \
00068   DEF_MATHOP_INT_CC( -, _T1) \
00069   DEF_MATHOP_INT_CC( *, _T1) \
00070   DEF_MATHOP_INT_CC( /, _T1)
00071 
00072 #define DEF_MATHOP_INT_CC(_Op, _T1) \
00073 Sketch<_T1> operator _Op (const Sketch<_T1>& lhs, const int value) { \
00074   Sketch<_T1> result(lhs->getName() + #_Op + "scalar", lhs); \
00075   *result.pixels = *lhs.pixels _Op (_T1)(value); \
00076   return result; \
00077 }
00078 
00079 //DEF_MATHOPS_INT(bool, uchar) disallowed because valarray won't mix types
00080 DEF_MATHOPS_INT_CC(uchar)
00081 DEF_MATHOPS_INT_CC(usint)
00082 DEF_MATHOPS_INT_CC(uint)
00083 DEF_MATHOPS_INT_CC(float)
00084 
00085 #undef DEF_MATHOPS_INT_CC
00086 #undef DEF_MATHOP_INT_CC
00087 
00088 // Define a special version of int math ops on Sketch<bool> that converts to Sketch<uchar>
00089 
00090 #define DEF_MATHBOOL_INT_CC(_Op) \
00091 Sketch<uchar> operator _Op (const Sketch<bool>& lhs, const int value) { \
00092   Sketch<uchar> result(lhs->getName() + #_Op + "scalar", lhs); \
00093   uchar* dest = &(*result.pixels)[0]; \
00094   const bool* src1 = &(*lhs.pixels)[0]; \
00095   const bool* end1 = &(*lhs.pixels)[lhs->getNumPixels()]; \
00096   while ( src1 != end1 ) \
00097     *dest++ = *src1++ _Op (uchar)value; \
00098   return result; \
00099 }
00100 
00101 DEF_MATHBOOL_INT_CC( + )
00102 DEF_MATHBOOL_INT_CC( - )
00103 DEF_MATHBOOL_INT_CC( * )
00104 DEF_MATHBOOL_INT_CC( / )
00105 
00106 #undef DEF_MATHBOOL_INT_CC
00107 
00108 template<>
00109 Sketch<bool>::operator Sketch<uchar>() const {
00110   /*
00111     std::cout << "Converting " << this << " '" << getName() << "'"
00112     << " id=" << getId() << ",parent=" << getParentId() << ",refcount=" << data->refcount
00113     << " to Sketch<uchar>\n";
00114   */
00115   Sketch<uchar> converted("uchar("+(*this)->getName()+")", *this);
00116   copyPixels(converted, *this);
00117   return converted;
00118 }
00119 
00120 template<>
00121 Sketch<uchar>::operator Sketch<bool>() const {
00122   /*
00123     std::cout << "Converting " << this << " '" << getName() << "'"
00124     << " id=" << getId() << ",parent=" << getParentId() << ",refcount=" << data->refcount
00125     << " to Sketch<bool>\n";
00126   */
00127   Sketch<bool> converted("bool(" + (*this)->getName() + ")", *this);
00128   copyPixels(converted, *this);
00129   return converted;
00130 }
00131 
00132 Sketch<bool>& operator&= (Sketch<bool>& arg1, Sketch<bool> const& arg2) {
00133   *(arg1.pixels) &= *(arg2.pixels); 
00134   return arg1;
00135 }
00136 
00137 Sketch<bool>& operator|= (Sketch<bool>& arg1, Sketch<bool> const& arg2) {
00138   *(arg1.pixels) |= *(arg2.pixels); 
00139   return arg1;
00140 }
00141 
00142 Sketch<bool>& operator^= (Sketch<bool>& arg1, Sketch<bool> const& arg2) {
00143   *(arg1.pixels) ^= *(arg2.pixels); 
00144   return arg1;
00145 }
00146 
00147 } // namespace

DualCoding 5.1CVS
Generated Mon May 9 04:56:27 2016 by Doxygen 1.6.3