Filter Library Camera Interface Physics

ScanFilterCustom.h

00001 /*
00002  * ScanFilterCustom.h - custom filter.
00003  *
00004  * This file is part of the Camera Filter Library.
00005  * Computer Aided Measurement Environment for Realtime Atomic imaging (Camera)
00006  *
00007  * Copyright (C) 2004-2005, Leiden Probe Microscopy.
00008  * Copyright (C) 2004-2005, Universiteit Leiden.
00009  *
00010  * Authors: M. Seynen (original), Martin J. Moene
00011  *
00012  * $Id: ScanFilterCustom.h 236 2005-06-27 09:03:17Z moene $
00013  */
00014 
00015 #ifndef CFL_SCANFILTERCUSTOM_H
00016 #define CFL_SCANFILTERCUSTOM_H
00017 
00018 #if _MSC_VER > 1000
00019 #pragma once
00020 #endif // _MSC_VER > 1000
00021 
00022 #include <cfl/ScanFilter.h>             // for base class
00023 #include <cfl/ScanBaseBuffer.h>         // for ValueType
00024 
00025 /**
00026  * \addtogroup cfl_filtercustom Custom Filter
00027  * \brief smooth filter.
00028  *
00029 
00030 <h3>Purpose</h3>
00031 
00032 Provide filters based on several predefined convolution kernels and a user definable kernel.
00033 
00034 <h3>Description</h3>
00035 
00036 The custom filter provides the following predefined filter kernels:
00037 - Blur (5 x 5)
00038 - Low pass (3 x 3)
00039 - High pass (5 x 5)
00040 - Edge (4 x 4)
00041 - Pyramidal (5 x 5)
00042 - Cone (5 x 5)
00043 - Gaussian, sigma=1 (5 x 5)
00044 - Laplacian (3 x 3)
00045 - Sharpening (3 x 3)
00046 
00047 <h3>Algorithm</h3>
00048 
00049 Convolution
00050 
00051 <h3>Examples</h3>
00052 Try to find some interesting pictures for most filters.
00053 
00054 <h3>Contact</h3>
00055 Dipl.phys. M.J. Rost<br>
00056 Huygens Laboratorium<br>
00057 Universiteit Leiden<br>
00058 Niels Bohrweg 2<br>
00059 2333 CA Leiden, The Netherlands<br>
00060 <br>
00061 Tel: +31 71 5275600<br>
00062 Fax: +31 71 5275404<br>
00063 <br>
00064 E-mail: rost@physics.LeidenUniv.nl<br>
00065 Web: http://www.geocities.com/marcel_rost/<br>
00066 
00067  *
00068  * @{
00069  */
00070 
00071 DECLARE_CLASS( CScanFilterCustom );     // create various types
00072 
00073 /**
00074  * \brief smooth filter.
00075  *
00076  */
00077 class CScanFilterCustom : public CScanFilter
00078 {
00079    /**
00080     * its dialog class.
00081     */
00082    friend class CFilterDlg_Custom;
00083 
00084 public:
00085    /**
00086     * the value type.
00087     */
00088    typedef CScanBaseBuffer::ValueType ValueType;
00089 
00090    /**
00091     * the kernel-weight type.
00092     */
00093    typedef double WeightType;
00094 
00095    /**
00096     * the kernel-weight pointer type.
00097     */
00098    typedef WeightType* WeightTypePtr;
00099 
00100    /**
00101     * the kernel-weight pointer type (const).
00102     */
00103    typedef const WeightType* WeightTypeConstPtr;
00104 
00105    /**
00106     * the filter type.
00107     */
00108    enum FilterType
00109    {
00110       ftBlur = 0,                       ///< the blur filter
00111       ftLowPass,                        ///< the low pass filter
00112       ftHighPass,                       ///< the high pass filter
00113       ftEdge,                           ///< the edge filter
00114       ftPyramidal,                      ///< the pyramidal filter
00115       ftCone,                           ///< the cone filter
00116       ftGaussian,                       ///< the gaussian filter
00117       ftLaplacian,                      ///< the laplacian filter
00118       ftSharpening,                     ///< the laplacian sharpening filter
00119       ftUser,                           ///< the user defined filter
00120    };
00121 
00122    /**
00123     * the kernel size.
00124     */
00125    enum
00126    {
00127       KernelWidth  = 5,                 ///< the kernel width
00128       KernelHeight = 5,                 ///< the kernel height
00129       KernelSize   = KernelWidth * KernelHeight,        ///< the kernel size
00130    };
00131 
00132    ///
00133    /// \name Construction
00134    /// @{
00135 
00136    /**
00137     * default constructor.
00138     */
00139    CScanFilterCustom();
00140 
00141    /**
00142     * destructor.
00143     */
00144    virtual ~CScanFilterCustom();
00145 
00146    /// @}
00147    /// \name Camera--Filter Interface
00148    /// @{
00149 
00150    /**
00151     * \brief configure filter with settings as provided by the application on the
00152     * filterlist window (e.g. via registry); see also CScanFilterNull::ReadFilterSettings().
00153     */
00154    virtual void ReadFilterSettings();
00155 
00156    /**
00157     * \brief save filter settings e.g. for use with the filterlist window (e.g. via registry);
00158     * see also ReadFilterSettings().
00159     */
00160    virtual void WriteFilterSettings() const;
00161 
00162    /**
00163     * provide current filter parameter(s) for filter-scripting capture
00164     * in the main application;
00165     * see also CScanFilterNull::GetParameters().
00166     */
00167    virtual LPCTSTR GetParameters() const;
00168 
00169    /**
00170     * set parameters for filter-script execution of filter; 
00171     * see also CScanFilterNull::SetParameters().
00172     */
00173    virtual BOOL SetParameters( LPCTSTR lpParameters );
00174 
00175    /**
00176     * start filter dialog to edit parameters; no filter operations;
00177     * see also CScanFilterNull::EditModeless().
00178     */
00179 //   virtual BOOL EditModeless( CWnd *pParentWnd );
00180 
00181    /**
00182     * create filter dialog and pre Apply() filter to view result;
00183     * see also CScanFilterNull::RunModeless().
00184     */
00185    virtual BOOL RunModeless( CWnd *pParentWnd, CDocument *pDoc );
00186 
00187    /**
00188     * check parameters, take care of a properly sized output buffer,
00189     * set its name and copy filter parameters and process;
00190     * see also CScanFilterNull::ApplyCore().
00191     */
00192    virtual BOOL Apply();
00193 
00194    /**
00195     * the supported dragmethod(s).
00196     */
00197 //   virtual DragSupportType SupportDragInput() const;
00198 
00199    /**
00200     * apply the filter to the selected area.
00201     */
00202 //   void SetDragInput( BOOL bL2R, CRect rcIn );
00203 
00204    /// @}
00205    /// \name Predicates
00206    /// @{
00207 
00208    /// @}
00209    /// \name Accessors
00210    /// @{
00211 
00212    /**
00213     * the current filter type.
00214     */
00215    FilterType GetFilterType() const;
00216 
00217    /**
00218     * the current short filter name.
00219     */
00220    LPCTSTR GetShortFilterName() const;
00221 
00222    /**
00223     * the given kernel weight.
00224     */
00225    WeightType GetWeight( int n ) const;
00226 
00227    /// @}
00228    /// \name Mutators
00229    /// @{
00230 
00231    /**
00232     * set the given filter type.
00233     */
00234    void SetFilterType( FilterType type );
00235 
00236    /**
00237     * set the given kernel weight.
00238     */
00239    void SetWeight( int n, WeightType w );
00240 
00241    /// @}
00242 
00243 public:
00244    /**
00245     * the filter name.
00246     */
00247    static LPCTSTR m_lpcsFilterName;
00248 
00249    /**
00250     * the class short filtername.
00251     */
00252    static LPCTSTR m_lpcsShortFilterName;
00253 
00254 protected:
00255    /**
00256     * store or retrieve the object's settings.
00257     */
00258    virtual void Serialize(CArchive& ar);
00259    DECLARE_SERIAL(CScanFilterCustom)
00260 
00261    /**
00262     * process the given frame part (L2R, R2L frame part).
00263     */
00264    void Convolve( BOOL bDoR2L );
00265 
00266 protected:
00267    /**
00268     * the filter type.
00269     */
00270    FilterType m_currentFilterType;
00271 
00272    /**
00273     * the current filter-weights (5x5).
00274     */
00275    WeightTypeConstPtr m_currentWeights;
00276 
00277    /**
00278     * the blur filter-weights (5x5).
00279     */
00280    static const WeightType m_blurWeights[ KernelSize ];
00281 
00282    /**
00283     * the low-pass filter-weights (5x5).
00284     */
00285    static const WeightType m_lowpassWeights[ KernelSize ];
00286 
00287    /**
00288     * the high-pass filter-weights (5x5).
00289     */
00290    static const WeightType m_highpassWeights[ KernelSize ];
00291 
00292    /**
00293     * the edge filter-weights (5x5).
00294     */
00295    static const WeightType m_edgeWeights[ KernelSize ];
00296 
00297    /**
00298     * the pyramidal filter-weights (5x5).
00299     */
00300    static const WeightType m_pyramidalWeights[ KernelSize ];
00301 
00302    /**
00303     * the cone filter-weights (5x5).
00304     */
00305    static const WeightType m_coneWeights[ KernelSize ];
00306 
00307    /**
00308     * the gaussian filter-weights (5x5).
00309     */
00310    static const WeightType m_gaussianWeights[ KernelSize ];
00311 
00312    /**
00313     * the laplacian filter-weights (5x5).
00314     */
00315    static const WeightType m_laplacianWeights[ KernelSize ];
00316 
00317    /**
00318     * the sharpening filter-weights (5x5).
00319     */
00320    static const WeightType m_sharpeningWeights[ KernelSize ];
00321 
00322    /**
00323     * the user filter-weights (5x5).
00324     */
00325    WeightType m_userWeights[ KernelSize ];
00326 
00327 };
00328 
00329 /// @} cfl_filterCustom
00330 
00331 /**
00332  * the current filter type.
00333  */
00334 inline CScanFilterCustom::FilterType CScanFilterCustom::GetFilterType() const
00335 {
00336    return m_currentFilterType;
00337 }
00338 
00339 /*
00340  * the given kernel weight.
00341  */
00342 inline CScanFilterCustom::WeightType CScanFilterCustom::GetWeight( int n ) const
00343 {
00344    if ( Q_INVALID ( ( 0 > n || n > KernelSize ) && "ensure valid weight number." ) )
00345    {
00346       return 1.0;
00347    }
00348 
00349    return m_currentWeights[ n ];
00350 }
00351 
00352 /*
00353  * set the given kernel weight.
00354  */
00355 inline void CScanFilterCustom::SetWeight( int n, WeightType w )
00356 {
00357    if ( Q_INVALID ( ( 0 > n || n > KernelSize ) && "ensure valid weight number." ) )
00358    {
00359       return ;
00360    }
00361 
00362    if ( Q_INVALID ( ftUser != GetFilterType() && "ensure user filter type." ) )
00363    {
00364       return ;
00365    }
00366 
00367    m_userWeights[ n ] = w;
00368 }
00369 
00370 #endif // CFL_SCANFILTERCUSTOM_H
00371 
00372 /*
00373  * end of file
00374  */
00375 

Camera Filter Library documentation © 2004-2007 by Leiden Probe Microscopy