00001 #ifndef IMAGE_OP_H 00002 #define IMAGE_OP_H 00003 00004 #include "image.h" 00005 #include "multi_array_op.h" 00006 00024 namespace mimas { 00025 00027 template< 00028 typename T, class F 00029 > 00030 image_ref< T > &image_apply( image_ref< T > &_img, F f ) 00031 { 00032 if ( _img.initialised() ) { 00033 boost::multi_array_ref< T, 2 > data( _img.rawData(), 00034 boost::extents[ _img.getHeight() ] 00035 [ _img.getWidth() ] ); 00036 multi_apply( data, f ); 00037 }; 00038 return _img; 00039 } 00040 00042 template< 00043 typename T1, typename T2, class F, 00044 typename T2Ptr 00045 > 00046 image_ref< T1 > &image_apply( image_ref< T1 > &a, 00047 const const_image_ref< T2, T2Ptr > &b, F f ) 00048 { 00049 if ( a.initialised() && b.initialised() ) { 00050 boost::multi_array_ref< T1, 2 > 00051 da( a.rawData(), boost::extents[ a.getHeight() ][ a.getWidth() ] ); 00052 boost::const_multi_array_ref< T2, 2 > 00053 db( b.rawData(), boost::extents[ b.getHeight() ][ b.getWidth() ] ); 00054 multi_apply( da, db, f ); 00055 }; 00056 return a; 00057 } 00058 00060 template< 00061 typename T1, typename T2, typename T3, class F, 00062 typename T2Ptr, typename T3Ptr 00063 > 00064 image_ref< T1 > &image_apply( image_ref< T1 > &a, 00065 const const_image_ref< T2, T2Ptr > &b, 00066 const const_image_ref< T3, T3Ptr > &c, F f ) 00067 { 00068 if ( a.initialised() && b.initialised() && c.initialised() ) { 00069 boost::multi_array_ref< T1, 2 > 00070 da( a.rawData(), boost::extents[ a.getHeight() ][ a.getWidth() ] ); 00071 boost::const_multi_array_ref< T2, 2 > 00072 db( b.rawData(), boost::extents[ b.getHeight() ][ b.getWidth() ] ); 00073 boost::const_multi_array_ref< T3, 2 > 00074 dc( c.rawData(), boost::extents[ c.getHeight() ][ c.getWidth() ] ); 00075 multi_apply( da, db, dc, f ); 00076 }; 00077 return a; 00078 } 00079 00080 template< 00081 typename T1, typename T2, class F, 00082 typename T2Ptr 00083 > 00084 image< T1 > image_func( const const_image_ref< T2, T2Ptr > &a, F f ) 00085 { 00086 image< T1 > retVal; retVal.init( a.getWidth(), a.getHeight() ); 00087 image_apply( retVal, a, _multi_help1< T1, T2, F >( f ) ); 00088 return retVal; 00089 } 00090 00091 template< 00092 typename T1, typename T2, typename T3, class F, 00093 typename T2Ptr, typename T3Ptr 00094 > 00095 image< T1 > image_func( const const_image_ref< T2, T2Ptr > &a, 00096 const const_image_ref< T3, T3Ptr > &b, 00097 F f ) 00098 { 00099 image< T1 > retVal; retVal.init( a.getWidth(), a.getHeight() ); 00100 image_apply( retVal, a, b, _multi_help2< T1, T2, T3, F >( f ) ); 00101 return retVal; 00102 } 00103 00104 }; 00106 00107 #define __MIMASINTERNALIMAGEFUNC operator*= 00108 #define __MIMASEXTERNALIMAGEFUNC operator* 00109 #define __MIMASFUNCTIONOBJECT std::multiplies 00110 #include "image_op_help.h" 00111 00112 #define __MIMASINTERNALIMAGEFUNC operator/= 00113 #define __MIMASEXTERNALIMAGEFUNC operator/ 00114 #define __MIMASFUNCTIONOBJECT std::divides 00115 #include "image_op_help.h" 00116 00117 #define __MIMASINTERNALIMAGEFUNC operator+= 00118 #define __MIMASEXTERNALIMAGEFUNC operator+ 00119 #define __MIMASFUNCTIONOBJECT std::plus 00120 #include "image_op_help.h" 00121 00122 #define __MIMASINTERNALIMAGEFUNC operator-= 00123 #define __MIMASEXTERNALIMAGEFUNC operator- 00124 #define __MIMASFUNCTIONOBJECT std::minus 00125 #include "image_op_help.h" 00126 00127 #define __MIMASEXTERNALIMAGEFUNC absolute 00128 #define __MIMASINTERNALIMAGEFUNC absoluteIt 00129 #define __MIMASFUNCTIONOBJECT _abs 00130 #include "image_op_help2.h" 00131 00132 #define __MIMASEXTERNALIMAGEFUNC conj 00133 #define __MIMASINTERNALIMAGEFUNC conjIt 00134 #define __MIMASFUNCTIONOBJECT _conj 00135 #include "image_op_help2.h" 00136 00137 #define __MIMASEXTERNALIMAGEFUNC sqr 00138 #define __MIMASINTERNALIMAGEFUNC sqrIt 00139 #define __MIMASFUNCTIONOBJECT _sqr 00140 #include "image_op_help2.h" 00141 00142 #define __MIMASEXTERNALIMAGEFUNC logarithm 00143 #define __MIMASINTERNALIMAGEFUNC logarithmIt 00144 #define __MIMASFUNCTIONOBJECT _log 00145 #include "image_op_help2.h" 00146 00147 #define __MIMASEXTERNALIMAGEFUNC squareRoot 00148 #define __MIMASINTERNALIMAGEFUNC squareRootIt 00149 #define __MIMASFUNCTIONOBJECT _sqrt 00150 #include "image_op_help2.h" 00151 00152 #define __MIMASEXTERNALIMAGEFUNC sumSquares 00153 #define __MIMASFUNCTIONOBJECT _sumsquares 00154 #include "image_op_help3.h" 00155 00156 #define __MIMASEXTERNALIMAGEFUNC orientation 00157 #define __MIMASFUNCTIONOBJECT _orientation 00158 #include "image_op_help3.h" 00159 00160 namespace mimas { 00161 00164 00165 template < 00166 typename T1, typename T2, typename T2Ptr 00167 > 00168 image< T1 > norm( const const_image_ref< T2, T2Ptr > &a ) 00169 { 00170 return image_func< T1 >( a, _norm< T1, T2 >() ); 00171 } 00172 00174 template < 00175 typename T1, typename T2 00176 > 00177 image< T1 > arg( const image< T2 > &a ) 00178 { 00179 return image_func< T1 >( a, _arg< T1, T2 >() ); 00180 } 00181 00183 template < 00184 typename T 00185 > 00186 image< int > fastSqr( const image< T > &a ) 00187 { 00188 return image_func< int >( a, _fastsqr< T >() ); 00189 }; 00190 00191 } 00192 00193 #endif