📄 run.cpp
字号:
/*
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright(c) 1999-2007 Intel Corporation. All Rights Reserved.
//
*/
// Run.cpp: implementation of the CRun class.
// CRun is the base class for all classes that process vectors or images
// by concrete IPP functions.
// CRun class works with CDemoDoc class that contains source and
// destination vector or image.
// CRun class uses classes derived from CParamDlg class to obtain
// IPP function parameters by dialog.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "demo.h"
#include "DemoDoc.h"
#include "Run.h"
#include "Vector.h"
#include "ParamDlg.h"
#include "Timing.h"
#include "Histo.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRun::CRun()
{
m_UsedVectors = 0;
m_pDocSrc = NULL;
m_pDocSrc2 = NULL;
m_pDocSrc3 = NULL;
m_pDocDst = NULL;
m_pDocDst2 = NULL;
m_pDocMask = NULL;
m_NewDst = FALSE;
m_NewDst2 = FALSE;
scaleFactor = 0;
m_PickVecPos = -1;
m_Perf = -1;
m_PerfUnit = _T("");
m_pTicker = new CTicker;
}
CRun::~CRun()
{
}
void CRun::IppErrorMessage(IppStatus result)
{
IppErrorMessage(m_Func, result);
}
void CRun::IppErrorMessage(CString funcName, IppStatus result)
{
if (result == 0) return;
CString message;
if (result == stsNoFunction)
message.Format(_T("Function %s isn't implemented, sorry"), funcName);
else
message.Format(_T("%s in %s:\nIppStatus = %d:\n%s"),
result < 0 ? _T("Error") : _T("Warning"),
funcName, result, ippGetStatusString(result));
DEMO_APP->MessageBox(message, (result < 0) ? MB_OK | MB_ICONWARNING : MB_OK);
}
void CRun::GetFunctions(CFuncList& funcList)
{
InitFuncList();
funcList.AddTail(&m_FuncList);
}
BOOL CRun::IsFunction(CString funcName)
{
InitFuncList();
return (BOOL)m_FuncList.Find(funcName);
}
void CRun::InitFuncList()
{
if (m_FuncList.GetCount()) return;
m_Outstand = TRUE;
CallIppFunction();
m_Outstand = FALSE;
}
BOOL CRun::Open(CFunc func)
{
m_Func = func;
m_UsedVectors = VEC_SRC | VEC_DST;
m_Perf = -1;
m_PerfUnit = _T("elmnt");
return TRUE;
}
void CRun::Close()
{
m_UsedVectors = 0;
}
BOOL CRun::ProcessFunctionStart(CDemoDoc *pDoc, CString funcName)
{
if (!IsFunction(funcName)) return FALSE;
m_pDocSrc = pDoc;
m_pDocSrc2 = NULL;
m_pDocSrc3 = NULL;
m_pDocDst = NULL;
m_pDocDst2 = NULL;
m_pDocMask = NULL;
if (!Open(funcName)) return FALSE;
if (m_Func.Inplace()) m_UsedVectors &= ~VEC_DST;
return TRUE;
}
void CRun::ProcessFunctionFinish()
{
DEMO_APP->SetCursorArrow();
Close();
}
void CRun::ProcessFunction()
{
if (!CheckEqualDocs()) return;
if (!GetParms()) return;
DEMO_APP->SetCursorWait();
if (!PrepareSrc()) return;
if (!PrepareDst()) return;
if (!ProcessCall()) return;
if (!NoDst()) ActivateDst();
SetHistory();
return;
}
BOOL CRun::ProcessCall()
{
//*simplify timing* SaveVectorForTiming();
PrepareParameters();
if (!BeforeCall()) return FALSE;
m_pTicker->Reset(); //*simplify timing*
int result = CallIpp();
if (result <= 0) {
AfterCall(FALSE);
DeleteNewDst();
return FALSE;
}
//*simplify timing* Timing();
if (!AfterCall(TRUE)) return FALSE;
//*simplify timing* <<<<<<
double divisor = GetPerfDivisor(m_PerfUnit);
if (divisor <= 1.e-6) {
divisor = 1;
m_PerfUnit = "";
}
m_Perf = m_pTicker->Ticks() / divisor;
//*simplify timing* >>>>>>>>
return TRUE;
}
CParamDlg* CRun::CreateDlg()
{
return NULL;
}
void CRun::DeleteDlg(CParamDlg* pDlg)
{
if (pDlg) delete pDlg;
}
void CRun::UpdateData(CParamDlg* pDlg, BOOL save)
{
if (save) {
scaleFactor = _ttoi(pDlg->m_scaleString);
} else {
pDlg->m_UsedVectors = m_UsedVectors;
pDlg->m_Func = m_Func;
pDlg->m_pDocSrc = m_pDocSrc;
pDlg->m_pDocSrc2 = m_pDocSrc2;
pDlg->m_pDocSrc3 = m_pDocSrc3;
pDlg->m_pDocMask = m_pDocMask;
pDlg->m_pDocDst = m_pDocDst;
pDlg->m_scaleString.Format(_T("%d"),scaleFactor);
}
}
BOOL CRun::GetParms()
{
CParamDlg* pDlg = CreateDlg();
if (pDlg) {
UpdateData(pDlg, FALSE);
try {
if (pDlg->DoModal() != IDOK) return FALSE;
} catch (CSExcept except) {
ExcDlgMessage(except);
return FALSE;
}
UpdateData(pDlg);
DeleteDlg(pDlg);
}
return TRUE;
}
BOOL CRun::CallIpp(BOOL bMessage)
{
IppStatus funcResult = ippStsNoErr;
try {
m_pTicker->Start(); //*simplify timing*
funcResult = CallIppFunction();
m_pTicker->Stop(); //*simplify timing*
} catch (CSExcept except) {
ExcIppMessage(except);
return FALSE;
}
if (funcResult == ippStsNoErr)
return TRUE;
if (bMessage)
IppErrorMessage(funcResult);
return funcResult > 0 ? TRUE : FALSE;
}
void CRun::ExcIppMessage(CSExcept except)
{
AfxMessageBox(_T("Exception in ") + m_Func + _T(": ") + except.GetExString());
}
void CRun::ExcDlgMessage(CSExcept except)
{
AfxMessageBox(
_T("Exception in Parameters' Dialog: ") +
except.GetExString() + _T("\n")
_T("Refer to program builder"));
}
BOOL CRun::CheckEqualDocs()
{
int firstPos, secondPos;
if (GetEqualDocPos(firstPos, secondPos)) {
if (AfxMessageBox(
GetVectorName(firstPos)
+ _T(" and ") + GetVectorName(secondPos)
+ _T(" are equal.\n")
+ _T("Function ") + m_Func + _T(" may give unexpected result."),
MB_OKCANCEL) != IDOK) return FALSE;
}
return TRUE;
}
BOOL CRun::GetEqualDocPos(int& firstPos, int& secondPos)
{
if (m_pDocDst) {
secondPos = VEC_DST;
if (m_pDocSrc == m_pDocDst) {
firstPos = VEC_SRC;
return TRUE;
}
if (m_pDocSrc2 == m_pDocDst) {
firstPos = VEC_SRC2;
return TRUE;
}
if (m_pDocMask == m_pDocDst) {
firstPos = VEC_MASK;
return TRUE;
}
}
if (m_pDocSrc2 && m_Func.Inplace()) {
secondPos = VEC_SRC2;
if (m_pDocSrc == m_pDocSrc2) {
firstPos = VEC_SRC;
return TRUE;
}
if (m_pDocMask == m_pDocSrc2) {
firstPos = VEC_MASK;
return TRUE;
}
}
return FALSE;
}
void CRun::SaveVectorForTiming()
{
if (!CTiming::GetFlag()) return;
if (!m_Func.Inplace()) return;
SaveInplaceVector();
}
void CRun::SetParmsBeforeTiming()
{
if (!m_Func.Inplace()) return;
SetInplaceParms();
}
void CRun::SetParmsAfterTiming()
{
if (!m_Func.Inplace()) return;
ResetInplaceParms();
}
void CRun::Timing()
{
m_Perf = -1;
if (!CTiming::GetFlag()) return;
double divisor = GetPerfDivisor(m_PerfUnit);
if (divisor <= 0) return;
SetParmsBeforeTiming();
CTiming tim;
int num;
double perf = 0;
switch (CTiming::GetMethod()) {
case timAUTO:
tim.Reset();
for (num = 1; tim.GetAccuracy() > 0.05; num *= 2) {
tim.Start();
Loop(num);
tim.Stop(num);
}
perf = tim.GetTicks();
break;
case timLOOP:
num = CTiming::GetNumber();
tim.Start();
Loop(num);
tim.Stop(num);
perf = tim.GetTicks();
break;
case timSTAT:
num = CTiming::GetNumber();
perf = 0;
for (int i=0; i<num; i++) {
tim.Start();
Loop(1);
tim.Stop(1);
perf += tim.GetTicks();
}
perf /= num;
break;
}
perf /= divisor;
m_Perf = perf;
SetParmsAfterTiming();
}
void CRun::Loop(int num)
{
while (num--) CallIppFunction();
}
BOOL CRun::PickStart()
{
m_pDocSrc->IsPicked(TRUE);
m_PickVecPos = VEC_SRC;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -