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/ScanFilterThreshold.h>
00022 #include <cfl/FilterDlg_Threshold.h>
00023 #include <cfl/ToolCilImage.h>
00024
00025 #include <cil/Traits.h>
00026 #include <cil/ThresholdImageFilter.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::ThresholdImageFilter< Image > ThresholdFilterType;
00048
00049 #define CFL_SCHEMAVERSION_FILTERTHRESHOLD 0
00050 // this filter's name
00051 LPCTSTR CScanFilterThreshold::m_lpcsFilterName = _T("Threshold");
00052
00053 LPCTSTR CScanFilterThreshold::m_lpcsShortFilterName = CScanFilterThreshold::m_lpcsFilterName;
00054
00055 IMPLEMENT_SERIAL(CScanFilterThreshold, CScanFilter, CFL_SCHEMAVERSION_FILTERTHRESHOLD)
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 CScanFilterThreshold::CScanFilterThreshold()
00072 {
00073
00074
00075
00076
00077
00078
00079
00080
00081 cil_static_assert( tmBelow == ThresholdFilterType::tmBelow , tmBelow_values_must_match );
00082 cil_static_assert( tmAbove == ThresholdFilterType::tmAbove , tmAbove_values_must_match );
00083 cil_static_assert( tmOutside == ThresholdFilterType::tmOutside, tmOutside_values_must_match );
00084
00085 m_csFilterName = m_lpcsFilterName;
00086
00087 ReadFilterSettings();
00088 }
00089
00090
00091
00092
00093 CScanFilterThreshold::~CScanFilterThreshold()
00094 {
00095
00096
00097 ;
00098 }
00099
00100
00101
00102
00103
00104
00105 void CScanFilterThreshold::Serialize(CArchive& ar)
00106 {
00107
00108
00109 CScanFilter::Serialize( ar );
00110
00111 if ( ar.IsStoring() )
00112 {
00113 ar << m_mode << m_lower << m_upper << m_outside;
00114 }
00115 else
00116 {
00117 int mode;
00118
00119 ar >> mode >> m_lower >> m_upper >> m_outside;
00120
00121 m_mode = static_cast< ThresholdMode >( mode );
00122 }
00123 };
00124
00125
00126
00127
00128
00129 void CScanFilterThreshold::ReadFilterSettings()
00130 {
00131
00132
00133 CWinApp* pApp = AfxGetApp();
00134
00135 if ( Q_INVALID( NULL == pApp ) )
00136 return ;
00137
00138
00139
00140
00141 SetParameters( pApp->GetProfileString( gCflRegistrySubkey, m_lpcsFilterName, _T( "0,-30000,+30000,0" ) ) );
00142 }
00143
00144
00145
00146
00147
00148 void CScanFilterThreshold::WriteFilterSettings() const
00149 {
00150
00151
00152 CWinApp* pApp = AfxGetApp();
00153
00154 if ( Q_INVALID( NULL == pApp ) )
00155 return ;
00156
00157
00158
00159
00160 LPCTSTR pStr = GetParameters();
00161
00162 if ( pStr )
00163 {
00164 pApp->WriteProfileString( gCflRegistrySubkey, m_lpcsFilterName, pStr );
00165 delete const_cast<LPTSTR>( pStr );
00166 }
00167 }
00168
00169
00170
00171
00172
00173
00174 LPCTSTR CScanFilterThreshold::GetParameters() const
00175 {
00176
00177
00178
00179
00180
00181 CString csParameters;
00182
00183 csParameters.Format
00184 ( _T( "%d,%d,%d,%d" )
00185 , GetThresholdMode()
00186 , GetLowerThreshold()
00187 , GetUpperThreshold()
00188 , GetOutsideValue()
00189 );
00190
00191 return strcpy( new TCHAR[ csParameters.GetLength() + 1 ], csParameters );
00192 }
00193
00194
00195
00196
00197
00198 BOOL CScanFilterThreshold::SetParameters( LPCTSTR lpParameters )
00199 {
00200
00201
00202 if ( Q_INVALID( NULL == lpParameters && "CScanFilterThreshold (SetParameters): parameters expected, none provided (NULL)." ) )
00203 {
00204 return FALSE;
00205 }
00206
00207
00208
00209
00210 int mode = tmBelow;
00211 int lower = lpm::NumericTraits< InputPixelType >::Min();
00212 int upper = lpm::NumericTraits< InputPixelType >::Max();
00213 int outside = 0;
00214
00215 int nfields = _stscanf
00216 ( lpParameters
00217 , _T( "%d,%d,%d,%d" )
00218 , &mode
00219 , &lower
00220 , &upper
00221 , &outside
00222 );
00223
00224 m_mode = static_cast< ThresholdMode >( mode );
00225 m_lower = static_cast< InputPixelType >( lower );
00226 m_upper = static_cast< InputPixelType >( upper );
00227 m_outside = static_cast< OutputPixelType >( outside );
00228
00229 if ( Q_INVALID( 4 > nfields && "CScanFilterThreshold (SetParameters): four parameters expected, got less." ) )
00230 {
00231 return FALSE;
00232 }
00233
00234 return TRUE;
00235 }
00236
00237
00238
00239
00240
00241 BOOL CScanFilterThreshold::RunModeless( CWnd* pParentWnd, CDocument* pDoc )
00242 {
00243
00244
00245 CFilterDlg_ThresholdPtr pDlg = new CFilterDlg_Threshold();
00246
00247 if ( Q_INVALID( NULL == pDlg ) )
00248 return FALSE;
00249
00250 pDlg->SetParameters( this, pDoc );
00251
00252
00253
00254
00255
00256 pDlg->Create( IDD_FILTERDLG_THRESHOLD, pParentWnd );
00257
00258 m_pDlg = pDlg;
00259
00260 BOOL bRet = Apply();
00261
00262 if ( bRet )
00263 {
00264 pDlg->UpdateView();
00265 }
00266
00267 return bRet;
00268 }
00269
00270
00271
00272
00273
00274
00275 BOOL CScanFilterThreshold::Apply()
00276 {
00277
00278
00279 if ( Q_INVALID( NULL == m_lpsbIn ) )
00280 return FALSE;
00281
00282 if ( Q_INVALID( NULL == m_lpsbOut ) )
00283 return FALSE;
00284
00285 if ( Q_INVALID( false == m_lpsbIn->IsCompleteFrame() ) )
00286 return FALSE;
00287
00288
00289
00290
00291 Q_RETURN( m_lpsbOut->CreateOutputBufferFor( *m_lpsbIn ) );
00292
00293 m_lpsbOut->m_csBufferName.Format
00294 ( _T("%s - %s %d,%d,%d,%d")
00295 , m_lpsbIn->m_csBufferName
00296 , m_lpcsShortFilterName
00297 , GetThresholdMode()
00298 , GetLowerThreshold()
00299 , GetUpperThreshold()
00300 , GetOutsideValue()
00301 );
00302
00303 if ( IsInteractive() )
00304 {
00305 m_pDlg->SetDlgItemText( IDC_BUFFEROUTNAME, m_lpsbOut->m_csBufferName );
00306 }
00307
00308
00309
00310
00311 ThresholdFilterType filter;
00312
00313 filter.SetOutsideValue ( GetOutsideValue() );
00314
00315 switch ( GetThresholdMode() )
00316 {
00317 case tmBelow:
00318 filter.ThresholdBelow( GetLowerThreshold() );
00319 break;
00320 case tmAbove:
00321 filter.ThresholdAbove( GetUpperThreshold() );
00322 break;
00323 case tmOutside:
00324 filter.ThresholdOutside( GetLowerThreshold(), GetUpperThreshold() );
00325 break;
00326 };
00327
00328 filter.Apply( ToImage( m_lpsbIn ), ToImage( m_lpsbOut ) );
00329
00330
00331
00332
00333 if ( m_lpsbIn->IsBidirectionalScan() && m_lpsbOut->IsBidirectionalScan() )
00334 {
00335 filter.Apply( ToImage( m_lpsbIn, true ), ToImage( m_lpsbOut, true ) );
00336 }
00337
00338 return TRUE;
00339 }
00340
00341
00342
00343
00344