⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ippsdemoview.cpp

📁 Intel开发的IPP库的应用例程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
//
//               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-2006 Intel Corporation. All Rights Reserved.
//
*/

// demoView.cpp : implementation of the CippsDemoView class
//
/////////////////////////////////////////////////////////////////////////////

#include <math.h>

#include "stdafx.h"
#include "ippsDemo.h"

#include "ippsDemoDoc.h"
#include "ippsDemoView.h"
#include "ippsDirector.h"
#include "MainFrm.h"
#include "ContextMenu.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CippsDemoView

CFont CippsDemoView::m_Font;
#ifdef _WIN64
COLORREF CippsDemoView::m_colorSignal     = RGB(  0,  0,  0);
COLORREF CippsDemoView::m_colorSignalBack = RGB(192,192,192); 
COLORREF CippsDemoView::m_colorAxis       = RGB(128,  0,  0);
COLORREF CippsDemoView::m_colorAxisBack   = RGB(128,128, 64);
#else
COLORREF CippsDemoView::m_colorSignal     = RGB(  0,  0,  0);
COLORREF CippsDemoView::m_colorSignalBack = RGB(193,205,208); 
COLORREF CippsDemoView::m_colorAxis       = RGB(128,  0,  0);
COLORREF CippsDemoView::m_colorAxisBack   = RGB(160,192,201);
#endif

IMPLEMENT_DYNCREATE(CippsDemoView, CScrollView)

BEGIN_MESSAGE_MAP(CippsDemoView, CScrollView)
   //{{AFX_MSG_MAP(CippsDemoView)
   ON_WM_LBUTTONUP()
   ON_WM_SETCURSOR()
   ON_WM_RBUTTONDOWN()
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CippsDemoView construction/destruction

CippsDemoView::CippsDemoView()
{
   m_numPoints = 0;
   m_points = NULL;
   m_pointsIm = NULL;
   if ((HFONT)m_Font == NULL) {
      m_Font.CreateFont(12, 0, 0, 0, FW_THIN, FALSE, FALSE, 0, 
         ANSI_CHARSET, OUT_CHARACTER_PRECIS,  CLIP_CHARACTER_PRECIS, 
         DEFAULT_QUALITY, DEFAULT_PITCH, NULL);
   }
   m_pBitmap = NULL;
}

CippsDemoView::~CippsDemoView()
{
   if (m_points) delete[] m_points;
   if (m_pointsIm) delete[] m_pointsIm;
}

BOOL CippsDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
   // TODO: Modify the Window class or styles here by modifying
   //  the CREATESTRUCT cs

   return CScrollView::PreCreateWindow(cs);
}

////////////////////////////////////////////////////////////////////////////
// Attributes

BOOL CippsDemoView::ScrollW() 
{ 
   CRect rect;
   GetWindowRect(&rect);
   return rect.Height() - GetClientHeight() >= ::GetSystemMetrics(SM_CYHSCROLL);
}

BOOL CippsDemoView::ScrollH() 
{ 
   CRect rect;
   GetWindowRect(&rect);
   return rect.Width() - GetClientWidth() >= ::GetSystemMetrics(SM_CXHSCROLL);
}

int CippsDemoView::GetSpaceHeight() { 
   return 24;
}
int CippsDemoView::GetSpaceCplxHeight() { 
   return 24;
}
int CippsDemoView::GetSpaceWidth() { 
   return 50;
}

static int getSpaceHeight() { 
   return DEMO_APP->GetXAxis() ? CippsDemoView::GetSpaceHeight() : 0;
}
static int getSpaceCplxHeight() { 
   return DEMO_APP->GetXAxis() ? CippsDemoView::GetSpaceCplxHeight() : 10;
}
static int getSpaceWidth() { 
   return DEMO_APP->GetYAxis() ? CippsDemoView::GetSpaceWidth() : 0;
}
static int getMaxHeight() { return INT_MAX - 100;}
static int getMinStepX() { return 60;}
static int getMinStepY() { return 30;}

int CippsDemoView::GetClientWidth() 
{ 
   RECT rect; 
   GetClientRect(&rect); 
   return rect.right;
}

int CippsDemoView::GetClientHeight() 
{ 
   RECT rect; 
   GetClientRect(&rect); 
   return rect.bottom;
}

int CippsDemoView::GetBorderHeight()
{
   CippsDemoDoc *pDoc = GetDoc();
   ASSERT(pDoc);
   int h = getSpaceHeight()*2;
   if (pDoc->Complex()) h += getSpaceCplxHeight();
   return h;
}

int CippsDemoView::GetBorderWidth()
{
   return getSpaceWidth()*2;
}


int CippsDemoView::GetInitialWidth()
{
   int w = (MAIN_FRAME->GetClientWidth()*9)/10 - GetBorderWidth();
   CippsDemoDoc *pDoc = GetDoc();
   if (w > pDoc->Length())
      w = pDoc->Length();
   return w + GetBorderWidth();
}

int CippsDemoView::GetInitialHeight()
{
   CippsDemoDoc *pDoc = GetDoc();
   return (pDoc->Complex() ? 256 : 128) + GetBorderHeight();
}

double CippsDemoView::GetAmplitude()
{
   double factor = 1;
   return GetAmplitude(factor);
}

double CippsDemoView::GetAmplitude(double factor)
{
   double min, max;
   GetMinMax(min,max);
   double ampl = (max - min)*factor;
   if (GetDoc()->Complex()) ampl *= 2;
   return ampl;
}

static void getConstFrame(double val, double& minVal, double& maxVal)
{
   if (val == 0) {
      minVal = -1;
      maxVal = 1;
      return;
   }
   double aval = val > 0 ? val : -val;   
   double step = pow((double)10,(double)(int)log10(aval));
   for (minVal = 0; aval < minVal || aval > minVal + step; minVal += step);
   maxVal = minVal + step;
   if ((aval - minVal)/aval < 0.1) minVal -=step;
   if ((maxVal - aval)/aval < 0.1) maxVal +=step;
   if (val < 0) {
      double tmp = minVal;
      minVal = -maxVal;
      maxVal = -tmp;
   }
}

void CippsDemoView::GetMinMax(double& min, double& max)
{
   min = GetDoc()->MinMin();
   max = GetDoc()->MaxMax();
   if (GetDoc()->Unsign()) {
      if (min <= max*.5) min = 0;
   } else {
      if (min < 0 && max > 0) {
         if (max < -min && max >= -min*.5)
            max = -min;
         if (-min < max && -min >= max*.5)
            min = -max;
      } else if (min > 0) {
         if (min <= max*.5) min = 0;
      } else if (max < 0) {
         if (max >= min*.5) max = 0;
      }
   }

   if (min == max)
      getConstFrame(min, min, max);
}

int CippsDemoView::GetMinPixel()
{
   double min, max;
   GetMinMax(min,max);
   return (int)(min*GetDoc()->FactorH() + .5);
}

int CippsDemoView::GetMaxPixel()
{
   double min, max;
   GetMinMax(min,max);
   return (int)(max*GetDoc()->FactorH() + .5);
}

enum {NUM_GAP = 8};
static double Gaps[NUM_GAP] = {.1, .2, .5, 1.0, 2.0, 5.0, 10.0, 20.0};

double CippsDemoView::GetStepAxis(double minStep, double magn)
{
   double step;
   do {
      double step10 = pow((double)10,(int)log10(minStep));
      for (int i=0; i<NUM_GAP; i++) {
         step = step10*Gaps[i];
         if (step >= minStep) break;
      }
      minStep *= .5;
   } while (magn > 0 && step > magn);
   return step;
}

int CippsDemoView::GetScaleWidth(double factor)
{
   CippsDemoDoc* pDoc = GetDoc();
   if (factor < 0) factor = pDoc->FactorW();
   int w = (int)(pDoc->Length()*factor + .5) + GetBorderWidth();
   return w;
}

int CippsDemoView::GetScaleHeight(double factor)
{
   CippsDemoDoc* pDoc = GetDoc();
   if (factor < 0) factor = pDoc->FactorH();
   double ampl = GetAmplitude(factor);
   int h = (ampl < getMaxHeight()) ? (int)ampl + GetBorderHeight() : getMaxHeight();
   return h;
}

CSize CippsDemoView::GetScaleSize()
{
   CSize size;
   size.cx = GetScaleWidth();
   size.cy = GetScaleHeight();
   return size;
}

////////////////////////////////////////////////////////////////////////////
// Operations

void CippsDemoView::Zoom()
{
   SetScrollSizes(MM_TEXT, GetScaleSize());

   CippsDemoDoc* pDoc = GetDoc();
   if (pDoc->Complex())
      SetPointsComplex();
   else
      SetPointsReal();
}

void CippsDemoView::SetPointsReal()
{
   CippsDemoDoc* pDoc = GetDoc();
   AllocatePoints();
   double step = 1 / pDoc->FactorW();
   double x = 0.5;
   for (int i=0; i < m_numPoints; i++, x+=step) {
      Ipp64fc value = pDoc->GetScaledValue((int)x);
      m_points[i].x = i + getSpaceWidth();
      m_points[i].y = -(int)(value.re + .5);
   }
}

void CippsDemoView::SetPointsComplex()
{
   CippsDemoDoc* pDoc = GetDoc();
   AllocatePoints();
   double step = 1 / pDoc->FactorW();
   double x = 0.5;
   for (int i=0; i < m_numPoints; i++, x+=step) {
      Ipp64fc value = pDoc->GetScaledValue((int)x);
      m_points[i].x = i + getSpaceWidth();
      m_points[i].y = -(int)(value.re + .5);
      m_pointsIm[i].x = i + getSpaceWidth();
      m_pointsIm[i].y = -(int)(value.im + .5);
   }
}

void CippsDemoView::AllocatePoints()
{
   CippsDemoDoc* pDoc = GetDoc();
   int num = (int)(pDoc->Length() * pDoc->FactorW());
   if (num == m_numPoints) return;
   m_numPoints = num;
   if (m_points) delete[] m_points;
   m_points = new POINT[m_numPoints];
   if (pDoc->Complex()) {
      if (m_pointsIm) delete[] m_pointsIm;
      m_pointsIm = new POINT[m_numPoints];
   }
}

/////////////////////////////////////////////////////////////////////////////
// CippsDemoView drawing

void CippsDemoView::OnInitialUpdate()
{
   CScrollView::OnInitialUpdate();

   CSize sizeTotal;
   sizeTotal.cx = GetInitialWidth();
   sizeTotal.cy = GetInitialHeight();
   SetScrollSizes(MM_TEXT, sizeTotal);

   CippsDemoDoc* pDoc = GetDoc();
   ASSERT(pDoc);
   pDoc->UpdateFrameTitle();
   pDoc->ZoomStandard();
   // Set the total size of this view
}

void CippsDemoView::OnDraw(CDC* pDC)
{
   CippsDemoDoc* pDoc = GetDoc();
   ASSERT_VALID(pDoc);
   if (pDoc->Length() == 0) return;
   if (m_IsUpdated) {
      m_SrcDC.DeleteDC();
      if (!m_SrcDC.CreateCompatibleDC(pDC)) return;
      if (m_pBitmap) delete m_pBitmap;
      m_pBitmap = new CBitmap;
      if (!m_pBitmap->CreateCompatibleBitmap(pDC, 
         GetScaleWidth(), GetScaleHeight())) return;
      m_SrcDC.SelectObject(m_pBitmap);
      DrawDC(&m_SrcDC);
      m_IsUpdated = FALSE;
   }
   pDC->BitBlt(0, 0, GetScaleWidth(), GetScaleHeight(), &m_SrcDC, 0, 0, SRCCOPY);
}

void CippsDemoView::DrawDC(CDC* pDC)
{
   pDC->SetBkMode(TRANSPARENT);
   pDC->SetROP2  (R2_COPYPEN);

   if (GetDoc()->Complex())
      DrawComplex(pDC);
   else
      DrawReal(pDC);
}

int CippsDemoView::GetX0() { return getSpaceWidth(); }
int CippsDemoView::GetX1() { return GetX0() + (int)(GetDoc()->Length() * GetDoc()->FactorW() + .5);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -