tools.hh

00001 #ifndef __TOOLS_H
00002 #define __TOOLS_H
00003 
00004 #include <boost/shared_ptr.hpp>
00005 #include <boost/multi_array.hpp>
00006 #include <boost/numeric/ublas/vector.hpp>
00007 #include <complex>
00008 #include <functional>
00009 #include <mimas/mm_image.h>
00010 #include <mimas/mm_image_input.h>
00011 #include <mimas/mm_multi_array_op.h>
00012 #include <mimas/mm_rgba.h>
00013 #include <popt.h>
00014 #include <string>
00015 
00016 // #define MMUSEOSMESA
00017 
00018 #ifndef MMUSEOSMESA
00019 #define GLX_GLXEXT_PROTOTYPES
00020 #include <GL/glx.h>
00021 #include <X11/Xlib.h>
00022 #else
00023 #include <GL/osmesa.h>
00024 #endif
00025 
00030 template< typename T >
00031 mimas::mm_image< T > multi_array_to_mm_image
00032    ( const boost::multi_array< T, 2 > &x );
00033 
00038 template< typename T >
00039 boost::multi_array< T, 2 > mm_image_to_multi_array
00040    ( const mimas::mm_image< T > &x );
00041 
00045 template< typename T >
00046 struct fast_sqr: public std::unary_function< T, int >
00047 {
00050   fast_sqr(void) {
00051     for ( short int i=0; i<(signed)table.size(); i++ )
00052       table[i] = (int)i * i;
00053   }
00058   int operator()( const T &x ) const {
00059     assert( x > -(signed)table.size() && x < (signed)table.size() );
00060     return table[ x < 0 ? -x : x ];
00061   }
00063   boost::array< int, 512 > table;
00064 };
00065 
00067 template< typename T >
00068 struct rand_function: public std::unary_function< T, int >
00069 {
00071   rand_function(void) { srand( time( 0 ) ); }
00073   int operator()( const T &size ) const {
00074     return (int)( rand() / ( RAND_MAX + 1.0 ) * size );
00075   }
00076 };
00077 
00079 template< typename T >
00080 struct _fastsqr: public std::unary_function< T, int > 
00081 {
00083   int operator()( const T &x ) const { return f( x ); }
00085   fast_sqr< T > f;
00086 };
00087 
00089 template< typename T >
00090 struct _sqr: public std::unary_function< T, T > 
00091 {
00093   T operator()( const T &x ) const { return x * x; }
00094 };
00095 
00097 template< typename T >
00098 struct _sqrt: public std::unary_function< T, T > 
00099 {
00101   T operator()( const T &x ) const { return sqrt( x ); }
00102 };
00103 
00105 template< typename T >
00106 struct _conj: public std::unary_function< T, T >
00107 {
00109   T operator()( const T &x ) const
00110   { return conj( x ); }
00111 };
00112 
00114 template< typename T >
00115 struct _tobinary: public std::unary_function< T, bool > {
00119   bool operator()( const T &x ) const
00120   { return x > 0 ? true : false; }
00121 };
00122 
00124 template< typename T >
00125 struct _touchar: public std::unary_function< T, unsigned char > {
00127   unsigned char operator()( const T &x ) const
00128   { return static_cast< unsigned char >( x ); }
00129 };
00130 
00132 template< typename T >
00133 struct _todouble: public std::unary_function< T, double > {
00135   double operator()( const T &x ) const
00136   { return static_cast< double >( x ); }
00137 };
00138 
00140 template< typename T >
00141 struct _tobw: public std::unary_function< T,
00142                                           mimas::mm_rgba< unsigned char > > {
00144   mimas::mm_rgba< unsigned char > operator()( const T &x ) const
00145   { return
00146       x ? mimas::mm_rgba< unsigned char >( 0, 255, 0 ) :
00147           mimas::mm_rgba< unsigned char >( 0, 0, 0 ); }
00148 };
00149 
00151 template< typename T >
00152 struct _tobw2: public std::unary_function< T,
00153                                            unsigned char > {
00155   unsigned char operator()( const T &x ) const
00156   { return x ? 255 : 0; }
00157 };
00158 
00160 mimas::mm_image< short int > gradX
00161   ( const mimas::mm_image< unsigned char > &m );
00163 mimas::mm_image< short int > gradY
00164   ( const mimas::mm_image< unsigned char > &m );
00166 template< typename T >
00167 mimas::mm_image< T > load_image( const std::string &fileName );
00172 mimas::mm_image< bool > edgeDetect
00173   ( const mimas::mm_image< unsigned char > &m,
00174     short int threshold );
00176 mimas::mm_image< unsigned char > down_sample
00177   ( const mimas::mm_image< unsigned char > &x, int rate, int fringe );
00179 mimas::mm_image< bool > gradientLevels
00180   ( const mimas::mm_image< unsigned char > &image,
00181   short int minGradient );
00183 boost::numeric::ublas::vector< int > center
00184   ( const std::vector< boost::numeric::ublas::vector< int > > &points );
00186 std::vector< boost::numeric::ublas::vector< int > > featurePoints
00187   ( const mimas::mm_image< bool > &binary );
00192 std::vector< boost::numeric::ublas::vector< int > > subtractOffset
00193   ( const std::vector< boost::numeric::ublas::vector< int > > &points,
00194     const boost::numeric::ublas::vector< int > &offset );
00195 
00199 std::vector< boost::numeric::ublas::vector< int > > scalePoints
00200   ( const std::vector< boost::numeric::ublas::vector< int > > &points,
00201     double scale );
00202 
00204 boost::shared_ptr< mimas::mm_image_input< mimas::mm_rgba< unsigned char > > >
00205    open_image_input
00206    ( int selectedInput, poptContext &optCon,
00207      int gstreamerSHMKey, int gstreamerSEMKey,
00208      const char *device, int channel,
00209      int width, int height, int brightness, int contrast,
00210      int shutter, int gain, int balance );
00211 
00212 #include "tools.tcc"
00213 
00214 #endif

doxygen-1.4.5 documentation for micron-vision - Tue Jan 17 15:29:15 2006