Filter Library | Camera | Interface Physics |
#include <ScanFilterNull.h>
Inheritance diagram for CScanFilterNull:
As a filter, class CScanFilterNull simply copies its input buffer to its ouput buffer using STL std::transform(), while applying the formula: .
Definition at line 91 of file ScanFilterNull.h.
Public Types | |
Types | |
typedef CScanBaseBuffer::ValueType | ValueType |
specify the scan base buffer datatype; having ValueType we omit the type specification from the variablename: pStart in stead of pwStart ; see for example Process(). | |
typedef ValueType * | Pointer |
the pointer type. | |
typedef const ValueType * | ConstPointer |
the const pointer type. | |
Public Member Functions | |
Camera--Filter Interface | |
virtual void | ReadFilterSettings () |
configure filter with settings as provided by the application on the filterlist window (e.g. | |
virtual void | WriteFilterSettings () const |
save filter settings e.g. | |
virtual LPCTSTR | GetParameters () const |
provide current filter parameter(s) for filter-scripting capture in the main application; see also CScanFilterNull::GetParameters(). | |
virtual BOOL | SetParameters (LPCTSTR lpParameters) |
set parameters for filter-script execution of filter; see also CScanFilterNull::SetParameters(). | |
virtual BOOL | RunModeless (CWnd *pParentWnd, CDocument *pDoc) |
create filter dialog and pre Apply() filter to view result; see also CScanFilterNull::RunModeless(). | |
virtual BOOL | Apply () |
let ApplyCore() perform the filter processing; catch MFC and std exceptions; see also CScanFilterNull::Apply(). | |
virtual BOOL | ApplyCore () |
check parameters, take care of a properly sized output buffer, set its name and copy filter parameters and Process(); see also CScanFilterNull::ApplyCore(). | |
virtual void | Process (ConstPointer pStartIn, Pointer pStartOut, DWORD dwSize) |
filter specified data range to output. | |
virtual SPerformanceTestResult | GetPerformanceTestResult () |
measure algorithm performance. | |
Accessors | |
double | GetFactor () |
the factor. | |
double | GetOffset () |
the offset. | |
Mutators | |
void | SetFactor (double aFactor) |
set the factor. | |
void | SetOffset (double aOffset) |
set the offset. | |
Static Public Attributes | |
static LPCTSTR | m_lpcsFilterName |
filter name | |
static LPCTSTR | m_lpcsShortFilterName |
the class short filtername. | |
static const double | def_dFactor |
default factor | |
static const double | def_dOffset |
default offset | |
Protected Member Functions | |
virtual void | Serialize (CArchive &ar) |
store or retrieve the object's settings; currently filter serialization is not used; see also CScanFilterNull::Serialize(). | |
Private Attributes | |
double | m_dFactor |
current factor value | |
double | m_dOffset |
current offset value |
CScanFilterNull::CScanFilterNull | ( | ) |
The constructor initializes the class' datamembers and prepares the filter to run without dialog by calling ReadFilterSettings().
For example:
CScanFilterNull::CScanFilterNull() : CScanFilter( ), m_dFactor( def_dFactor ), m_dOffset( def_dOffset ) { m_csFilterName = m_lpcsFilterName; ReadFilterSettings(); // get filter settings to run without dialog }
Definition at line 93 of file ScanFilterNull.cpp.
CScanFilterNull::~CScanFilterNull | ( | ) | [virtual] |
The destructor may have to release resources (e.g. memory) that the constructor has allocated. In this specific case, the destructor does nothing; however note that the base-class destructor (CScanFilter::~CScanFilter()) does some more work: it destroys the dialog if present.
For example:
CScanFilterNull::~CScanFilterNull() { ; // do nothing }
Definition at line 118 of file ScanFilterNull.cpp.
CScanFilterNull::CScanFilterNull | ( | ) |
The constructor initializes the class' datamembers and prepares the filter to run without dialog by calling ReadFilterSettings().
For example:
CScanFilterNull::CScanFilterNull() : CScanFilter( ), m_dFactor( def_dFactor ), m_dOffset( def_dOffset ) { m_csFilterName = m_lpcsFilterName; ReadFilterSettings(); // get filter settings to run without dialog }
Definition at line 93 of file ScanFilterNull.cpp.
CScanFilterNull::~CScanFilterNull | ( | ) | [virtual] |
The destructor may have to release resources (e.g. memory) that the constructor has allocated. In this specific case, the destructor does nothing; however note that the base-class destructor (CScanFilter::~CScanFilter()) does some more work: it destroys the dialog if present.
For example:
CScanFilterNull::~CScanFilterNull() { ; // do nothing }
Definition at line 118 of file ScanFilterNull.cpp.
void CScanFilterNull::ReadFilterSettings | ( | ) | [virtual] |
via registry); see also CScanFilterNull::ReadFilterSettings().
This method obtains the filter setting as supplied by the application on the filterlist window, for example via the registry, and initializes the filter with these settings.
ReadFilterSettings() is called from the constructor of the filter.
A no-op example:
void CScanFilterNull::ReadFilterSettings( ) { // Only few filters provide this method. }
An if-used example:
void CScanFilterNull::ReadFilterSettings( ) { CWinApp* pApp = AfxGetApp(); if ( Q_INVALID( NULL == pApp ) ) return ; // // parameter string: x-size,y-size,parameter,factor // SetParameters( pApp->GetProfileString( gCflRegistrySubkey, m_lpcsFilterName, _T( "1,0" ) ) ); }
Reimplemented from CScanFilter.
Definition at line 229 of file ScanFilterNull.cpp.
References gCflRegistrySubkey, m_lpcsFilterName, Q_INVALID, and SetParameters().
void CScanFilterNull::WriteFilterSettings | ( | ) | const [virtual] |
for use with the filterlist window (e.g. via registry); see also ReadFilterSettings().
A no-op example:
void CScanFilterNull::WriteFilterSettings( ) const { // Only few filters provide this method. }
An if-used example:
void CScanFilterNull::WriteFilterSettings( ) const { CWinApp* pApp = AfxGetApp(); if ( Q_INVALID( NULL == pApp ) ) return ; // // parameter string: x-size,y-size,parameter,factor // LPCTSTR pStr = GetParameters(); if ( pStr ) { pApp->WriteProfileString( gCflRegistrySubkey, m_lpcsFilterName, pStr ); delete const_cast<LPTSTR>( pStr ); } }
Reimplemented from CScanFilter.
Definition at line 285 of file ScanFilterNull.cpp.
References gCflRegistrySubkey, GetParameters(), m_lpcsFilterName, and Q_INVALID.
LPCTSTR CScanFilterNull::GetParameters | ( | ) | const [virtual] |
Analogous to GetInitParameters(), this method returns filter parameters, in this case for the filter-scripting capture operation in the main application.
delete-ing
returned string storage.LPCTSTR CScanFilterNull::GetParameters( ) const { // returns "no parameter values": return NULL; }
An if-used example:
LPCTSTR CScanFilterNull::GetParameters( ) const { // format parameters and return a c-string on the heap: CString csParameters; csParameters.Format( _T( "%g,%g" ), m_dFactor, m_dOffset ); return strcpy( new TCHAR[ csParameters.GetLength() + 1 ], csParameters ); }
Reimplemented from CScanFilter.
Definition at line 347 of file ScanFilterNull.cpp.
References m_dFactor, and m_dOffset.
Referenced by WriteFilterSettings().
BOOL CScanFilterNull::SetParameters | ( | LPCTSTR | lpParameters | ) | [virtual] |
This method initializes the filter parameters for filter-script execution of the filter toe the parameters specified.
lpParameters | a C-string specifying the filter parameter values, e.g. "1.23,4.56". |
BOOL CScanFilterNull::SetParameters( LPCTSTR lpParameters ) { // we do not expect any parameters, so say so: if ( Q_INVALID ( NULL != lpParameters && 0 < ::strlen( lpParameters ) && "CScanFilterNull (SetParameters): no parameters expected." ) ) { return FALSE; } return FALSE; }
An if-used example:
BOOL CScanFilterNull::SetParameters( LPCTSTR lpParameters ) { if ( Q_INVALID( NULL == lpParameters && "CScanFilterNull (SetParameters): parameters expected, none provided (NULL).") ) { return FALSE; } // set defaults, read parameter string with factor and optional offset: m_dFactor = def_dFactor; m_dOffset = def_dOffset; int nfields = _stscanf( lpParameters, _T( "%lg,%lg" ), &m_dFactor, &m_dOffset ); if ( Q_LOG( 1 > nfields && "CScanFilterNull (SetParameters): factor and optional offset expected, got none." ) ) { return FALSE; } return TRUE; }
Reimplemented from CScanFilter.
Definition at line 422 of file ScanFilterNull.cpp.
References def_dFactor, def_dOffset, m_dFactor, m_dOffset, Q_INVALID, and Q_LOG.
Referenced by ReadFilterSettings().
BOOL CScanFilterNull::RunModeless | ( | CWnd * | pParentWnd, | |
CDocument * | pDoc | |||
) | [virtual] |
This method creates the filter dialog and pre-applies the filter using Apply() to show its result.
pDoc | the document to update on a filter action (parameter change, Ok, Cancel) | |
pParentWnd | the parent window for the creation of the filter dialog box |
BOOL CScanFilter::RunModeless( CWnd* pParentWnd, CDocument* pDoc ) { CFilterDlg_NullPtr pDlg = new CFilterDlg_Null(); if ( Q_INVALID( NULL == pDlg ) ) return FALSE; pDlg->SetParameters( this, pDoc ); // (void) method // Q_RETURN( pDlg->Create( IDD_FILTERDLG_NULL, pParentWnd ) ); // FIXME-ADAPT: IDD_ pDlg->Create( IDD_FILTERDLG_NULL, pParentWnd ); // FIXME-ADAPT: IDD_ m_pDlg = pDlg; // pre-Apply the filter and show initial results; // on error, simulate failure to create dialog: BOOL bRet = Apply(); if ( bRet ) { pDlg->UpdateView(); } return bRet; }
Reimplemented from CScanFilter.
Definition at line 500 of file ScanFilterNull.cpp.
References Apply(), CScanFilter::m_pDlg, Q_INVALID, CFilterDlg::SetParameters(), and CFilterDlg::UpdateView().
BOOL CScanFilterNull::Apply | ( | ) | [virtual] |
Method Apply is an MFC and std exception handling wrapper around method ApplyCore.
BOOL CScanFilterNull::Apply() { BOOL bRet = FALSE; // preset to Failure try { bRet = ApplyCore(); // sets status, unless exception occurs } catch ( CException* e ) { Q_MFC_EXCEPTION( e ); // macro uses pointer-to (without surrounding () ) e->Delete(); // see MSDN: Exceptions: Catching and Deleting Exceptions } catch ( const std::exception& e ) { Q_STD_EXCEPTION( e ); } return bRet; // return status }
Reimplemented from CScanFilter.
Definition at line 570 of file ScanFilterNull.cpp.
References ApplyCore(), CScanFilter::IsInteractive(), Q_MFC_EXCEPTION, and Q_STD_EXCEPTION.
Referenced by RunModeless().
BOOL CScanFilterNull::ApplyCore | ( | ) | [virtual] |
This method checks the presence of the filter's buffer(s), takes care of a properly sized output buffer, set its name and copies the filter parameters from the input buffer to the ouput buffer and calls Process() to do the filter processing.
For an example of a filter that uses two input buffers, see filter ScanFilterDZ.h and ScanFilterDZ.cpp (class CScanFilterDZ).
BOOL CScanFilterNull::ApplyCore() { if ( Q_INVALID( NULL == m_lpsbIn ) ) return FALSE; if ( Q_INVALID( NULL == m_lpsbOut ) ) return FALSE; // // for first Apply, setup filter settings, filter name, dialog if present // and output buffer: // // // copy the filter settings (not the data): // Q_RETURN( m_lpsbOut->CreateOutputBufferFor( *m_lpsbIn ) ); // FIXME-ADAPT: filtername m_lpsbOut->m_csBufferName.Format( _T("%s - %s"), m_lpsbIn->m_csBufferName, m_lpcsShortFilterName ); // // if the dialog is present: // if ( IsInteractive() ) { m_pDlg->SetDlgItemText( IDC_BUFFEROUTNAME, m_lpsbOut->m_csBufferName ); } // // process the L2R part and the R2L part (if present). // DWORD dwSize = m_lpsbIn->FrameSize(); if ( m_lpsbIn->IsBidirectionalScan() && m_lpsbOut->IsBidirectionalScan() ) { dwSize *= 2; } Process( m_lpsbIn->Data(), m_lpsbOut->Data(), dwSize ); // // recalculate all temporary variables: // m_lpsbOut->m_dwParameterMask = 0; return TRUE; // return Ok }
Definition at line 669 of file ScanFilterNull.cpp.
References CScanBaseBuffer::CreateOutputBufferFor(), CScanBaseBuffer::Data(), CScanBaseBuffer::GetFrameSize(), CScanBaseBuffer::IsBidirectionalScan(), CScanFilter::IsInteractive(), CScanBaseBuffer::m_csBufferName, CScanBaseBuffer::m_dwParameterMask, m_lpcsShortFilterName, CScanFilter::m_lpsbIn, CScanFilter::m_lpsbOut, CScanFilter::m_pDlg, Process(), Q_INVALID, and Q_RETURN.
Referenced by Apply().
void CScanFilterNull::Process | ( | ConstPointer | pStartIn, | |
Pointer | pStartOut, | |||
DWORD | dwSize | |||
) | [virtual] |
This filter simply copies its input buffer to its ouput buffer using STL std:: transform(), while applying the formula: .
void CScanFilterNull::Process( ConstPointer pStartIn, Pointer pStartOut, DWORD dwSize ) { // FIXME-ADAPT: required operation is highly filter-specific. std::transform( pStartIn, // in.begin() pStartIn + dwSize, // in.end() pStartOut, // out.begin() NullOp<ValueType>( GetFactor(), GetOffset() ) // UnaryOp ); }
Definition at line 781 of file ScanFilterNull.cpp.
References GetFactor(), and GetOffset().
Referenced by ApplyCore(), and GetPerformanceTestResult().
SPerformanceTestResult CScanFilterNull::GetPerformanceTestResult | ( | ) | [virtual] |
We measure two aspects of the algorithm:
In the following example, there is no preparation phase, so all time is attributed to the operation on the buffers.
SPerformanceTestResult result; typedef long Count; CPerfTimer Timer; // // time Preparation: // ; // nothing here // // time Process: // Time timeToProcess = 0.4; // time to measure in [s] Count countProcessed = 0; // iteration count Timer.Start( true ); // restart start the timing while ( Timer.Elapsed() < timeToProcess ) { Process( m_lpsbIn->Data(), m_lpsbOut->Data(), m_lpsbIn->FrameSize() ); ++countProcessed; // update iteration count } Timer.Stop(); // stop the timing result.timeBuffer = Timer.Elapsed() / countProcessed; if ( m_lpsbIn->IsBidirectionalScan() && m_lpsbOut->IsBidirectionalScan() ) { result.timeBuffer *= 2; } result.totalTime = result.timePrepare + result.timeBuffer; return result; }
Definition at line 844 of file ScanFilterNull.cpp.
References CScanBaseBuffer::Data(), CPerfTimer::Elapsed(), CScanBaseBuffer::GetFrameSize(), CScanBaseBuffer::IsBidirectionalScan(), CScanFilter::m_lpsbIn, CScanFilter::m_lpsbOut, Process(), CPerfTimer::Start(), CPerfTimer::Stop(), SPerformanceTestResult::timeBuffer, SPerformanceTestResult::timePrepare, and SPerformanceTestResult::totalTime.
void CScanFilterNull::Serialize | ( | CArchive & | ar | ) | [protected, virtual] |
This method lets you store the filter's settings to and retrieve them from an archive. This process is called serialization.
ar | the archiver |
// store or retrieve the object's settings. void CScanFilterNull::Serialize( CArchive& ar ) { CScanFilter::Serialize( ar ); if ( ar.IsStoring() ) { ar << m_dFactor << m_dOffset; } else { ar >> m_dFactor >> m_dOffset; } }
Reimplemented from CScanFilter.
Definition at line 156 of file ScanFilterNull.cpp.
References m_dFactor, m_dOffset, and CScanFilter::Serialize().