00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "stdafx.h"
00016
00017 #include <cfl/resource.h>
00018
00019 #include <Camera/InterfaceDll.h>
00020
00021 #include <cfl/ScanFilterBinaryThreshold.h>
00022 #include <cfl/FilterDlg_BinaryThreshold.h>
00023 #include <cfl/ToolCilImage.h>
00024
00025 #include <cil/Traits.h>
00026 #include <cil/BinaryThresholdImageFilter.h>
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifdef _DEBUG
00039 #undef THIS_FILE
00040 static char THIS_FILE[]=__FILE__;
00041 #define new DEBUG_NEW
00042 #endif
00043
00044
00045
00046
00047 typedef cil::BinaryThresholdImageFilter< Image > BinaryThresholdFilterType;
00048
00049 #define CFL_SCHEMAVERSION_FILTERBINARYTHRESHOLD 0
00050 // this filter's name
00051 LPCTSTR CScanFilterBinaryThreshold::m_lpcsFilterName = _T("BinaryThreshold");
00052
00053 LPCTSTR CScanFilterBinaryThreshold::m_lpcsShortFilterName = CScanFilterBinaryThreshold::m_lpcsFilterName;
00054
00055 IMPLEMENT_SERIAL(CScanFilterBinaryThreshold, CScanFilter, CFL_SCHEMAVERSION_FILTERBINARYTHRESHOLD)
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 CScanFilterBinaryThreshold::CScanFilterBinaryThreshold()
00072 {
00073
00074
00075 m_csFilterName = m_lpcsFilterName;
00076
00077 ReadFilterSettings();
00078 }
00079
00080
00081
00082
00083 CScanFilterBinaryThreshold::~CScanFilterBinaryThreshold()
00084 {
00085
00086
00087 ;
00088 }
00089
00090
00091
00092
00093
00094
00095 void CScanFilterBinaryThreshold::Serialize(CArchive& ar)
00096 {
00097
00098
00099 CScanFilter::Serialize( ar );
00100
00101 if ( ar.IsStoring() )
00102 {
00103 ar << m_lower << m_upper << m_inside << m_outside;
00104 }
00105 else
00106 {
00107 ar >> m_lower >> m_upper >> m_inside >> m_outside;
00108 }
00109 };
00110
00111
00112
00113
00114
00115 void CScanFilterBinaryThreshold::ReadFilterSettings()
00116 {
00117
00118
00119 CWinApp* pApp = AfxGetApp();
00120
00121 if ( Q_INVALID( NULL == pApp ) )
00122 return ;
00123
00124
00125
00126
00127 SetParameters( pApp->GetProfileString( gCflRegistrySubkey, m_lpcsFilterName, _T( "-30000,+30000,1,0" ) ) );
00128 }
00129
00130
00131
00132
00133
00134 void CScanFilterBinaryThreshold::WriteFilterSettings() const
00135 {
00136
00137
00138 CWinApp* pApp = AfxGetApp();
00139
00140 if ( Q_INVALID( NULL == pApp ) )
00141 return ;
00142
00143
00144
00145
00146 LPCTSTR pStr = GetParameters();
00147
00148 if ( pStr )
00149 {
00150 pApp->WriteProfileString( gCflRegistrySubkey, m_lpcsFilterName, pStr );
00151 delete const_cast<LPTSTR>( pStr );
00152 }
00153 }
00154
00155
00156
00157
00158
00159
00160 LPCTSTR CScanFilterBinaryThreshold::GetParameters() const
00161 {
00162
00163
00164
00165
00166
00167 CString csParameters;
00168
00169 csParameters.Format
00170 ( _T( "%d,%d,%d,%d" )
00171 , GetLowerThreshold()
00172 , GetUpperThreshold()
00173 , GetInsideValue()
00174 , GetOutsideValue()
00175 );
00176
00177 return strcpy( new TCHAR[ csParameters.GetLength() + 1 ], csParameters );
00178 }
00179
00180
00181
00182
00183
00184 BOOL CScanFilterBinaryThreshold::SetParameters( LPCTSTR lpParameters )
00185 {
00186
00187
00188 if ( Q_INVALID( NULL == lpParameters && "CScanFilterBinaryThreshold (SetParameters): parameters expected, none provided (NULL)." ) )
00189 {
00190 return FALSE;
00191 }
00192
00193
00194
00195
00196 int lower = lpm::NumericTraits< InputPixelType >::Min();
00197 int upper = lpm::NumericTraits< InputPixelType >::Max();
00198 int inside = 1;
00199 int outside = 0;
00200
00201 int nfields = _stscanf
00202 ( lpParameters
00203 , _T( "%d,%d,%d,%d" )
00204 , &lower
00205 , &upper
00206 , &inside
00207 , &outside
00208 );
00209
00210 m_lower = static_cast< InputPixelType >( lower );
00211 m_upper = static_cast< InputPixelType >( upper );
00212 m_inside = static_cast< OutputPixelType >( inside );
00213 m_outside = static_cast< OutputPixelType >( outside );
00214
00215 if ( Q_INVALID( 4 > nfields && "CScanFilterBinaryThreshold (SetParameters): four parameters expected, got less." ) )
00216 {
00217 return FALSE;
00218 }
00219
00220 return TRUE;
00221 }
00222
00223
00224
00225
00226
00227 BOOL CScanFilterBinaryThreshold::RunModeless( CWnd* pParentWnd, CDocument* pDoc )
00228 {
00229
00230
00231 CFilterDlg_BinaryThresholdPtr pDlg = new CFilterDlg_BinaryThreshold();
00232
00233 if ( Q_INVALID( NULL == pDlg ) )
00234 return FALSE;
00235
00236 pDlg->SetParameters( this, pDoc );
00237
00238
00239
00240
00241
00242 pDlg->Create( IDD_FILTERDLG_BINARYTHRESHOLD, pParentWnd );
00243
00244 m_pDlg = pDlg;
00245
00246 BOOL bRet = Apply();
00247
00248 if ( bRet )
00249 {
00250 pDlg->UpdateView();
00251 }
00252
00253 return bRet;
00254 }
00255
00256
00257
00258
00259
00260
00261 BOOL CScanFilterBinaryThreshold::Apply()
00262 {
00263
00264
00265 if ( Q_INVALID( NULL == m_lpsbIn ) )
00266 return FALSE;
00267
00268 if ( Q_INVALID( NULL == m_lpsbOut ) )
00269 return FALSE;
00270
00271 if ( Q_INVALID( false == m_lpsbIn->IsCompleteFrame() ) )
00272 return FALSE;
00273
00274
00275
00276
00277 Q_RETURN( m_lpsbOut->CreateOutputBufferFor( *m_lpsbIn ) );
00278
00279 m_lpsbOut->m_csBufferName.Format
00280 ( _T("%s - %s %d,%d,%d,%d")
00281 , m_lpsbIn->m_csBufferName
00282 , m_lpcsShortFilterName
00283 , GetLowerThreshold()
00284 , GetUpperThreshold()
00285 , GetInsideValue()
00286 , GetOutsideValue()
00287 );
00288
00289 if ( IsInteractive() )
00290 {
00291 m_pDlg->SetDlgItemText( IDC_BUFFEROUTNAME, m_lpsbOut->m_csBufferName );
00292 }
00293
00294
00295
00296
00297 BinaryThresholdFilterType filter;
00298
00299 filter.SetLowerThreshold( GetLowerThreshold() );
00300 filter.SetUpperThreshold( GetUpperThreshold() );
00301 filter.SetInsideValue ( GetInsideValue() );
00302 filter.SetOutsideValue ( GetOutsideValue() );
00303
00304 filter.Apply( ToImage( m_lpsbIn ), ToImage( m_lpsbOut ) );
00305
00306
00307
00308
00309 if ( m_lpsbIn->IsBidirectionalScan() && m_lpsbOut->IsBidirectionalScan() )
00310 {
00311 filter.Apply( ToImage( m_lpsbIn, true ), ToImage( m_lpsbOut, true ) );
00312 }
00313
00314 return TRUE;
00315 }
00316
00317
00318
00319
00320