KernelFilter.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  KernelFilter
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       2D discrete, symmetric filter which can be compactly / efficiently 
00009    stored / applied using a 2D kernel (array)
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #ifndef KERNEL_FILTER_H_
00013 #define KERNEL_FILTER_H_
00014 
00015 #include <filters/Filter.h>
00016 #include <common/image/Rgba.h>
00017 
00018 class Image;
00019 
00020 class KernelFilter : public Filter2D {
00021    public:
00022       ///@name Constructors
00023       //@{-----------------------------------------------------------------
00024       
00025       inline KernelFilter(real_t support = 2)
00026          : Filter2D(support), 
00027            m_width(((unsigned)ceil(support)) | 1), 
00028            m_kernel(NULL), m_isNormalized(false)
00029       {
00030          // Note: cannot call _computeKernel in constructor because 
00031          // both it and evaluate (which the default implementation of 
00032          // _computeKernel calls) are virtual and the subclass' vtable 
00033          // is likely not initialized yet ==> bad consequences
00034       }
00035       
00036       virtual ~KernelFilter();
00037       
00038       
00039       //@}-----------------------------------------------------------------
00040       ///@name Static factory
00041       //@{-----------------------------------------------------------------
00042       
00043       static KernelFilter *create(const std::string &type, PropertyMap &p);
00044       
00045       
00046       //@}-----------------------------------------------------------------
00047       ///@name Initialization
00048       //@{-----------------------------------------------------------------
00049       
00050       virtual void init();
00051       
00052       
00053       //@}-----------------------------------------------------------------
00054       ///@name Main usage interface
00055       //@{-----------------------------------------------------------------
00056       
00057       /**
00058        * @returns the value of this filter function evaluated at the given 
00059        *    point
00060        */
00061       virtual real_t evaluate(const Vector2 &pt) = 0;
00062       
00063       /**
00064        * @brief
00065        *    Applies this filter to the given image, (performs discrete 
00066        * convolution with the given image and this 2D filter)
00067        * 
00068        * @note this involves allocating a temporary intermediate image
00069        */
00070       void apply(Image *image);
00071       
00072       /**
00073        * @brief
00074        *    Convolves this filter with the image at the given location and 
00075        * returns the result
00076        */
00077       RgbaHDR apply(Image *image, real_t x, real_t y);
00078       
00079       
00080       //@}-----------------------------------------------------------------
00081       ///@name Accessors / Mutators
00082       //@{-----------------------------------------------------------------
00083       
00084       /// @returns the underlying 2D kernel
00085       inline const real_t *getKernel() const {
00086          return m_kernel;
00087       }
00088       
00089       /// @returns the width of the kernel (same as height since its symmetric)
00090       inline unsigned getWidth() const {
00091          return m_width;
00092       }
00093       
00094       /// @returns the number of real_ts contained in the kernel
00095       inline unsigned getSize() const {
00096          return m_width * m_width;
00097       }
00098       
00099       //@}-----------------------------------------------------------------
00100       
00101    protected:
00102       /// Allocates and initializes m_kernel
00103       virtual void _computeKernel();
00104       
00105    protected:
00106       unsigned m_width;
00107       real_t  *m_kernel;
00108       
00109       /// whether or not 'apply' should assume the kernel is normalized
00110       bool     m_isNormalized;
00111 };
00112 
00113 #endif // KERNEL_FILTER_H_
00114 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6