00001
00007 #ifndef __KERNEL_FACTORY_H__
00008 #define __KERNEL_FACTORY_H__
00009
00010 #include <string>
00011 using std::string;
00012 #include <functional>
00013
00014 #include "stringparser.h"
00015 #include "pnm_io.h"
00016 #include "radialfunction.h"
00017 #include "neuralregion.h"
00018 #include "generic_stdlib.h"
00019
00020
00022 class KernelFactory {
00023 public:
00025 typedef InternalNeuralRegion::WeightMatrix KernelMatrix;
00026
00027 KernelFactory() : max_blur_type(Blur_CircularRandom) { }
00028 virtual ~KernelFactory() { }
00029
00030 KernelMatrix create( int index, double world_size_scale, StringArgs arglist );
00031
00033 typedef double (*kernel_fnPtr) (double x_sq, double sig_sq);
00034
00036 inline KernelMatrix create(kernel_fnPtr fnptr, double radius,
00037 double max_radius, string& errors,
00038 bool circular=true, bool normalize=true) {
00039 return RadialFunction::matrix<KernelMatrix>
00040 (fnptr,radius,max_radius,errors,circular,normalize);
00041 }
00042
00044 void register_params_and_commands( void );
00045
00047 enum BlurTypes {Blur_SquareAverage,Blur_CircularAverage,Blur_Gaussian,Blur_DoG,Blur_LoG,
00048 Blur_GoD,Blur_DoGGoD,Blur_PGM,Blur_SquareRandom,Blur_CircularRandom};
00049
00051 const BlurTypes max_blur_type;
00052
00053 private:
00054
00055 static double blur_radius;
00056 static double blur_radius_surround_multiplier;
00057 static double blur_scale;
00058 static double blur_range_multiplier;
00059 static int blur_type;
00060 static char default_kernel_filename[];
00061 };
00062
00063
00065 class KernelFactoryWrapper : public Generic::unary_virtual_function<double,KernelFactory::KernelMatrix> {
00066 public:
00067 KernelFactoryWrapper(KernelFactory factory, StringArgs args, int num=0)
00068 : e(num), arglist(args), kf(factory) { }
00070 virtual KernelFactory::KernelMatrix operator() ( double size_scale )
00071 { return kf.create(e,size_scale,arglist); }
00072 private:
00073 int e;
00074 StringArgs arglist;
00075 KernelFactory& kf;
00076 };
00077
00078 #endif