Filter Library Camera Interface Physics

ScanFilterMinimum.cpp

00001 /*
00002  * ScanFilterMinimum.cpp - minimum image 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-2006, Leiden Probe Microscopy.
00008  * Copyright (C) 2004-2006, Universiteit Leiden.
00009  *
00010  * Authors: Martin J. Moene
00011  *
00012  * $Id: ScanFilterMinimum.cpp 363 2006-03-09 13:21:27Z moene $
00013  */
00014 
00015 #include "stdafx.h"                     // for common (pre-compiled) headers
00016 //#include <cfl/stdafx.h>                 // for common (pre-compiled) headers
00017 #include <cfl/resource.h>               // for messages and other resources
00018 
00019 #include <Camera/InterfaceDll.h>        // Camera--Filter Library interface
00020 
00021 #include <cfl/ScanFilterMinimum.h>      // this filter's header FIXME
00022 #include <cfl/FilterDlg_Minimum.h>      // this filter's dialog
00023 #include <cfl/ToolCilImage.h>           // for Image type and ToImage conversion shim
00024 
00025 #include <cil/MinimumImageFilter.h>     // minimum image filter
00026 
00027 /*
00028  * configuration defines:
00029  */
00030 
00031 // none
00032 
00033 /*
00034  * end of configuration defines.
00035  */
00036 
00037 #ifdef _DEBUG
00038 #undef THIS_FILE
00039 static char THIS_FILE[]=__FILE__;
00040 #define new DEBUG_NEW
00041 #endif
00042 
00043 /*
00044  * convenience types.
00045  */
00046 #ifdef CIL_MinimumImageFilter_USE_TYPE_HACK     // ::Type hack
00047    typedef cil::MinimumImageFilter< Image >::Type MinimumFilterType;
00048 #else
00049    typedef cil::MinimumImageFilter< Image > MinimumFilterType;
00050 #endif
00051 
00052 #define CFL_SCHEMAVERSION_FILTERMINIMUM 0 ///< permanent storage schema version
00053                                         // this filter's name
00054 LPCTSTR CScanFilterMinimum::m_lpcsFilterName = _T("Minimum");
00055                                         // this filter's short name
00056 LPCTSTR CScanFilterMinimum::m_lpcsShortFilterName = CScanFilterMinimum::m_lpcsFilterName;
00057                                         // serialization
00058 IMPLEMENT_SERIAL(CScanFilterMinimum, CScanFilterRank, CFL_SCHEMAVERSION_FILTERMINIMUM)
00059 
00060 /*
00061  * default constructor: setup filter to run without dialog;
00062  * see also CScanFilterNull::CScanFilterNull().
00063  */
00064 CScanFilterMinimum::CScanFilterMinimum()
00065 {
00066 //   Q_LOG( _T("CScanFilterMinimum::CScanFilterMinimum()") );
00067 
00068    m_csFilterName = m_lpcsFilterName;
00069 
00070    ReadFilterSettings();
00071 }
00072 
00073 /*
00074  * create filter dialog and pre Apply() filter to view result;
00075  * see also CScanFilterNull::RunModeless().
00076  */
00077 BOOL CScanFilterMinimum::RunModeless( CWnd* pParentWnd, CDocument* pDoc )
00078 {
00079 //   Q_LOG( _T("CScanFilterMinimum::RunModeless()") );
00080 
00081    CFilterDlg_MinimumPtr pDlg = new CFilterDlg_Minimum();
00082 
00083    if ( Q_INVALID( NULL == pDlg ) )
00084       return FALSE;
00085 
00086    pDlg->SetParameters( this, pDoc );   // (void) method
00087 
00088    /*
00089     * Create returns non-zero if dialog was created and initialized succesfully.
00090     * Note: no pDlg->DestroyWindow() must be done.
00091     */
00092    pDlg->Create( IDD_FILTERDLG_MINIMUM, pParentWnd );
00093 
00094    m_pDlg = pDlg;
00095 
00096    BOOL bRet = Apply();
00097 
00098    if ( bRet )
00099    {
00100       pDlg->UpdateView();
00101    }
00102 
00103    return bRet;
00104 }
00105 
00106 /*
00107  * check parameters, take care of a properly sized output buffer, set its name
00108  * and copy filter parameters, CalculatePlane() and SubtractPlane();
00109  * see also CScanFilterNull::ApplyCore().
00110  */
00111 BOOL CScanFilterMinimum::Apply()
00112 {
00113 //   Q_LOG( _T("CScanFilterMinimum::Apply()") );
00114 
00115    if ( Q_INVALID( NULL == m_lpsbIn ) )
00116       return FALSE;
00117 
00118    if ( Q_INVALID( NULL == m_lpsbOut ) )
00119       return FALSE;
00120 
00121    if ( Q_INVALID( false == m_lpsbIn->IsCompleteFrame() ) )
00122       return FALSE;
00123 
00124    /*
00125     * copy the filter settings (not the data):
00126     */
00127    Q_RETURN( m_lpsbOut->CreateOutputBufferFor( *m_lpsbIn ) );
00128 
00129    m_lpsbOut->m_csBufferName.Format( _T("%s - %s %d,%d"), m_lpsbIn->m_csBufferName, m_lpcsShortFilterName, GetSizeX(), GetSizeY() );
00130 
00131    if ( IsInteractive() )
00132    {
00133       m_pDlg->SetDlgItemText( IDC_BUFFEROUTNAME, m_lpsbOut->m_csBufferName );
00134    }
00135 
00136    /*
00137     * apply filter to L2R part, use radius as specified by size (size 3x3 => radus 1x1):
00138     */
00139    MinimumFilterType filter( ToRadius( m_cpSize.x, m_cpSize.y ) );
00140 
00141    filter.Apply( ToImage( m_lpsbIn ), ToImage( m_lpsbOut ) );
00142 
00143    /*
00144     * if we have a double buffer, L2R and R2L, process that part too.
00145     */
00146    if ( m_lpsbIn->IsBidirectionalScan() && m_lpsbOut->IsBidirectionalScan() )
00147    {
00148       filter.Apply( ToImage( m_lpsbIn, true ), ToImage( m_lpsbOut, true ) );
00149    }
00150 
00151    return TRUE;
00152 }
00153 
00154 /*
00155  * end of file
00156  */

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