亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ccontroller.cpp

?? 《游戲編程中的人工智能技術(shù)》書中源代碼和可執(zhí)行文件
?? CPP
字號(hào):
#include "CController.h"
#include "resource.h"



string CController::m_sPatternName = "";


//--------------------------------- ctor -------------------------------
//
//----------------------------------------------------------------------
CController::CController(HWND hwnd):m_bDrawing(false),
                          m_iNumSmoothPoints(NUM_VECTORS+1),
                          m_hwnd(hwnd),
                          m_dHighestOutput(0),
                          m_iBestMatch(-1),
                          m_iMatch(-1),
                          m_iNumValidPatterns(NUM_PATTERNS),
                          m_Mode(UNREADY)
                         
{
  //create the database
  m_pData = new CData(m_iNumValidPatterns, NUM_VECTORS);

  //setup the network
  m_pNet = new CNeuralNet(NUM_VECTORS*2,        //inputs
                          m_iNumValidPatterns,  //outputs
                          NUM_HIDDEN_NEURONS,   //hidden
                          LEARNING_RATE);
                          
}

//--------------------------------- dtor --------------------------------
//
//-----------------------------------------------------------------------
CController::~CController()
{
  delete m_pData;
  delete m_pNet;
}
//-----------------------------------------------------------------
//
//  message handler for the dialog box
//-----------------------------------------------------------------
BOOL CALLBACK CController::DialogProc(HWND   hwnd,
                                 UINT   msg,
                                 WPARAM wParam,
                                 LPARAM lParam)
{
  switch(msg)
  {
  case WM_INITDIALOG:
    {
      return true;
    }

    break;

  case WM_COMMAND:
    {
      switch(LOWORD(wParam))
      {
      case IDOK:
        {
          //get a handle to the edit control
          HWND hwndEdit = GetDlgItem(hwnd, IDC_GRAB_NAME); 

          //set the focus
          SetFocus(hwndEdit);

          //get the text
          char buffer[30]; 

          GetWindowText(hwndEdit, buffer, 30);

          m_sPatternName = buffer;

          //if the user hasn't entered a name set name
          if (m_sPatternName.size == 0)
          {
            m_sPatternName = "User defined pattern";
          }
          
          EndDialog(hwnd, 0);

          return true;
        }

        break;
      }
    }

    break;

  }//end switch

  return false;
}

//--------------------------- Clear --------------------------------------
//
//  clears the current data
//------------------------------------------------------------------------
void CController::Clear()
{
  m_vecPath.clear();
  m_vecSmoothPath.clear();
  m_vecVectors.clear();
}

//------------------------------ Drawing ---------------------------------
//
//  this is called whenever the user depresses or releases the right
//  mouse button.
//  If val is true then the right mouse button has been depressed so all
//  mouse data is cleared ready for the next gesture. If val is false a
//  gesture has just been completed. The gesture is then either added to
//  the current data set or it is tested to see if it matches an existing
//  pattern.
//  The hInstance is required so a dialog box can be created as a child
//  window of the main app instance. The dialog box is used to grab the
//  name of any user defined gesture
//------------------------------------------------------------------------
bool CController::Drawing(bool val, HINSTANCE hInstance)
{
  if (val == true)
  {
    Clear();
  }

  else
  {
    //smooth and vectorize the data if we have enough points
    if (Smooth())
    {
      //create the vectors
      CreateVectors();

      if (m_Mode == ACTIVE)
      {

        if (!TestForMatch())
        {
          return false;
        }
      }

      else
      {
        //add the data set if user is happy with it
        if(MessageBox(m_hwnd, "Happy with this gesture?", "OK?", MB_YESNO) == IDYES)
        {
           //grab a name for this pattern
          DialogBox(hInstance,
                    MAKEINTRESOURCE(IDD_DIALOG1),
                    m_hwnd,
                    DialogProc);

          
           //add the data
           m_pData->AddData(m_vecVectors, m_sPatternName);

           //delete the old network
           delete m_pNet;

           ++m_iNumValidPatterns;

           //create a new network
           m_pNet = new CNeuralNet(NUM_VECTORS*2,
                                   m_iNumValidPatterns,
                                   NUM_VECTORS*2,
                                   LEARNING_RATE);

           //train the network
           TrainNetwork();

           m_Mode = ACTIVE;
         }

         else
         {
           //clear dismissed gesture
           m_vecPath.clear();
         }
      }
    }
  }
    
  m_bDrawing = val;

  return true;
}

//------------------------------ TrainNetwork -----------------------------
//
//  Trains the neural net work with the predefined training set
//-------------------------------------------------------------------------
bool CController::TrainNetwork()
{  
  m_Mode = TRAINING;

  if(!m_pNet->Train(m_pData, m_hwnd))
  {
    return false;
  }

  m_Mode = ACTIVE;

  return true;
}
  

//------------------------- TestForMatch ----------------------------------
//
//  checks the mouse pattern to see if it matches one of the learned
//  patterns
//-------------------------------------------------------------------------
bool CController::TestForMatch()
{
  //input the smoothed mouse vectors into the net and see if we get a match
  vector<double> outputs = m_pNet->Update(m_vecVectors);

  if (outputs.size() == 0)
  {
    MessageBox(NULL, "Error in with ANN output", "Error!", MB_OK);

    return false;
  }

  //run through the outputs and see which is highest
  m_dHighestOutput = 0;
  m_iBestMatch = 0;
  m_iMatch = -1;
  
  for (int i=0; i<outputs.size(); ++i)
  {
    if (outputs[i] > m_dHighestOutput)
    {
      //make a note of the most likely candidate
      m_dHighestOutput = outputs[i];

      m_iBestMatch = i;
 

      //if the candidates output exceeds the threshold we 
      //have a match! ...so make a note of it.
      if (m_dHighestOutput > MATCH_TOLERANCE)
      {
        m_iMatch = m_iBestMatch;
                  
      }
    }
  }

  return true;
}

//----------------------------------- CreateVectors ----------------------
//
//  this function creates normalized vectors out of the series of POINTS
//  in m_vecSmoothPoints
//------------------------------------------------------------------------
void CController::CreateVectors()
{ 
  for (int p=1; p<m_vecSmoothPath.size(); ++p)
  {    

    double x = m_vecSmoothPath[p].x - m_vecSmoothPath[p-1].x;
    double y = m_vecSmoothPath[p].y - m_vecSmoothPath[p-1].y;

    SVector2D v1(1, 0);
    SVector2D v2(x, y);

    Vec2DNormalize(v2);

    m_vecVectors.push_back(v2.x);
    m_vecVectors.push_back(v2.y);
  }

}

//------------------------------------- Smooth ---------------------------
//
//------------------------------------------------------------------------
bool CController::Smooth()
{
  //make sure it contains enough points for us to work with
  if (m_vecPath.size() < m_iNumSmoothPoints)
  {
    //return
    return false;
  }

  //copy the raw mouse data
  m_vecSmoothPath = m_vecPath;

  //while there are excess points iterate through the points
  //finding the shortest spans, creating a new point in its place
  //and deleting the adjacent points.
  while (m_vecSmoothPath.size() > m_iNumSmoothPoints)
  {
    double ShortestSoFar = 99999999;

    int PointMarker = 0;

    //calculate the shortest span
    for (int SpanFront=2; SpanFront<m_vecSmoothPath.size()-1; ++SpanFront)
    {
      //calculate the distance between these points
      double length = 
      sqrt( (m_vecSmoothPath[SpanFront-1].x - m_vecSmoothPath[SpanFront].x) *
            (m_vecSmoothPath[SpanFront-1].x - m_vecSmoothPath[SpanFront].x) +

            (m_vecSmoothPath[SpanFront-1].y - m_vecSmoothPath[SpanFront].y)*
            (m_vecSmoothPath[SpanFront-1].y - m_vecSmoothPath[SpanFront].y));

      if (length < ShortestSoFar)
      {
        ShortestSoFar = length;

        PointMarker = SpanFront;
      }      
    }

    //now the shortest span has been found calculate a new point in the 
    //middle of the span and delete the two end points of the span
    POINTS newPoint;

    newPoint.x = (m_vecSmoothPath[PointMarker-1].x + 
                  m_vecSmoothPath[PointMarker].x)/2;

    newPoint.y = (m_vecSmoothPath[PointMarker-1].y +
                  m_vecSmoothPath[PointMarker].y)/2;

    m_vecSmoothPath[PointMarker-1] = newPoint;

    m_vecSmoothPath.erase(m_vecSmoothPath.begin() + PointMarker);
  }

  return true;
}

//--------------------------------- LearningMode -------------------------
//
//  clears the screen and puts the app into learning mode, ready to accept
//  a user defined gesture
//------------------------------------------------------------------------
void CController::LearningMode()
{
  m_Mode = LEARNING;

  Clear();

  //update window
  InvalidateRect(m_hwnd, NULL, TRUE);
  UpdateWindow(m_hwnd);
}
			
//-------------------------------- Render --------------------------------
//
//------------------------------------------------------------------------
void CController::Render(HDC &surface, int cxClient, int cyClient)
{
    
  //render error from any training taking place
  if(m_Mode == TRAINING)
  {   
    string s = "Error: " + ftos(m_pNet->Error());
    TextOut(surface, cxClient/2, 5, s.c_str(), s.size());

     s = "Epochs: " + ftos(m_pNet->Epoch());
    TextOut(surface, 5, 5, s.c_str(), s.size());
  }

  if (m_pNet->Trained())
  {
    if ((m_Mode == ACTIVE))
    {
       string s = "Recognition circuits active";
       TextOut(surface, 5, cyClient-20, s.c_str(), s.size());
    }

    if (m_Mode == LEARNING)
    {
      string s = "Recognition circuits offline - Enter a new gesture";
      TextOut(surface, 5, cyClient-20, s.c_str(), s.size());
    }
  }

  else
  {
     string s = "Training in progress...";
     TextOut(surface, 5, cyClient-20, s.c_str(), s.size());
  }


  if (!m_bDrawing)
  {  
    //render best match
    if (m_dHighestOutput > 0)
    {
   
      if ( (m_vecSmoothPath.size() > 1) && (m_Mode != LEARNING) )
      {
        if (m_dHighestOutput < MATCH_TOLERANCE)
        {
          string s = "I'm guessing this is the pattern " + 
                     m_pData->PatternName(m_iBestMatch); 

          TextOut(surface, 5, 10, s.c_str(), s.size());
        }

        else
        {
          SetTextColor(surface, RGB(0, 0, 255));

          string s = m_pData->PatternName(m_iMatch);
          TextOut(surface, 5, 10, s.c_str(), s.size());

          SetTextColor(surface, RGB(0, 0, 0));

        }
      }

      else if (m_Mode != LEARNING)
      {
        SetTextColor(surface, RGB(255, 0, 0));

        string s = "Not enough points drawn - plz try again";
        TextOut(surface, 5, 10, s.c_str(), s.size());

        SetTextColor(surface, RGB(0, 0, 0));
      }
    }
  }
  
  if (m_vecPath.size() < 1)
  {
    return;
  }
  
  MoveToEx(surface, m_vecPath[0].x, m_vecPath[0].y, NULL);

  for (int vtx=1; vtx<m_vecPath.size(); ++vtx)
  {
    LineTo(surface, m_vecPath[vtx].x, m_vecPath[vtx].y);
  }
  
  //draw the points which make up the smoothed path
  if ((!m_bDrawing) && (m_vecSmoothPath.size() > 0))
  {
    for (int vtx=0; vtx<m_vecPath.size(); ++vtx)
    {
      POINTS pt = m_vecSmoothPath[vtx];

      Ellipse(surface, pt.x-2, pt.y-2, pt.x+2, pt.y+2);
    }
  }	 
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲第一在线综合网站| 91福利在线看| 国产传媒欧美日韩成人| 经典三级在线一区| 国产呦萝稀缺另类资源| 激情欧美一区二区| 激情图片小说一区| 国产一区二区影院| 国产福利一区二区三区视频在线| 精品亚洲欧美一区| 国产精品99久久久久久宅男| 国产福利一区二区三区| 国产成人综合在线观看| 99久久99久久综合| 91福利视频网站| 欧美日本国产视频| 日韩视频免费直播| 337p日本欧洲亚洲大胆精品| 国产色91在线| 亚洲人午夜精品天堂一二香蕉| 亚洲日本丝袜连裤袜办公室| 一区二区久久久| 琪琪久久久久日韩精品| 国产自产高清不卡| 大胆欧美人体老妇| 一本色道久久综合亚洲91| 欧美日韩视频第一区| 欧美一级电影网站| 国产精品无码永久免费888| 综合色天天鬼久久鬼色| 亚洲成人动漫在线观看| 久久国产剧场电影| 99在线精品免费| 欧美日本在线观看| 久久久精品欧美丰满| 一区二区三区欧美视频| 青青草国产精品亚洲专区无| 国产精品伊人色| 色呦呦日韩精品| 亚洲伦在线观看| 天天av天天翘天天综合网色鬼国产 | 日韩一区二区影院| 欧美mv日韩mv国产网站app| 国产精品久久久久久久第一福利| 一区二区三区精品视频| 国产一区二区看久久| 在线视频国内一区二区| 精品国产三级a在线观看| 久久综合狠狠综合久久综合88| 麻豆视频观看网址久久| 日韩午夜激情视频| 99精品视频一区二区三区| 亚洲成人一区在线| 亚洲一区二区三区在线看| 亚洲一区影音先锋| 亚洲超碰97人人做人人爱| 五月天久久比比资源色| 蜜臀国产一区二区三区在线播放| 精品一二三四区| 99在线视频精品| 8v天堂国产在线一区二区| 国产亚洲欧美色| 一区二区高清免费观看影视大全 | 北岛玲一区二区三区四区| 一本大道av伊人久久综合| 欧美日韩一级视频| 国产女主播视频一区二区| 亚洲国产视频在线| 成人高清av在线| 欧美tickle裸体挠脚心vk| 亚洲乱码国产乱码精品精可以看| 日韩综合一区二区| 91麻豆精品秘密| 久久久不卡网国产精品二区| 国模大尺度一区二区三区| 久久老女人爱爱| 精品在线视频一区| 欧美大片在线观看一区二区| 欧美酷刑日本凌虐凌虐| 亚洲欧美另类小说视频| 国产成人一区二区精品非洲| 欧美一区二区三区在线观看视频 | 午夜精品福利在线| av在线不卡免费看| 中文字幕精品一区二区三区精品| 免费在线观看一区二区三区| 欧美午夜一区二区| 亚洲精品自拍动漫在线| 成人免费视频caoporn| 久久婷婷国产综合国色天香| 日韩va亚洲va欧美va久久| 欧美视频完全免费看| 国产精品夜夜嗨| 欧美国产精品一区二区| 久久久国产综合精品女国产盗摄| 欧美a级理论片| 欧美日本乱大交xxxxx| 亚洲午夜精品久久久久久久久| 成人高清视频在线| 国产日韩欧美精品在线| 91黄色激情网站| 日韩制服丝袜av| 丁香亚洲综合激情啪啪综合| 亚洲精品一线二线三线| 麻豆精品在线观看| 精品91自产拍在线观看一区| 热久久久久久久| 日韩三级.com| 蜜臀av性久久久久蜜臀aⅴ流畅 | 91国产福利在线| 一区二区三区美女视频| 欧洲在线/亚洲| 一个色综合av| 精品视频在线免费看| 亚洲成国产人片在线观看| 欧美久久一区二区| 美女一区二区在线观看| 久久久久久久av麻豆果冻| 岛国精品在线播放| 亚洲色图在线播放| 欧美日本乱大交xxxxx| 美女视频一区二区三区| 久久在线免费观看| 99久久久国产精品免费蜜臀| 一区二区三区中文在线观看| 69堂成人精品免费视频| 国产精一区二区三区| 中文字幕日韩一区二区| 欧美制服丝袜第一页| 日本在线不卡视频| 久久久夜色精品亚洲| 99免费精品视频| 亚洲成人免费观看| 精品sm在线观看| www.激情成人| 日韩成人av影视| 亚洲国产精品99久久久久久久久| 日本福利一区二区| 精品一区二区免费在线观看| 国产精品天干天干在观线| 欧美在线视频你懂得| 久久精品国产免费| 亚洲欧洲三级电影| 91精品国产福利| 处破女av一区二区| 午夜欧美在线一二页| 久久九九99视频| 欧美午夜精品一区| 国产91精品欧美| 亚洲午夜精品在线| 中文字幕欧美国产| 欧美日本在线播放| 99视频精品全部免费在线| 日本不卡免费在线视频| 成人中文字幕在线| 视频一区视频二区中文| 国产精品麻豆视频| 欧美精品 日韩| 不卡视频在线观看| 美女视频一区在线观看| 亚洲综合在线第一页| 欧美精品一区二区蜜臀亚洲| 欧美在线影院一区二区| 成人午夜免费视频| 免费高清在线视频一区·| 亚洲色图欧洲色图| 亚洲精品一区二区精华| 欧美色手机在线观看| 岛国精品在线播放| 久久99精品国产麻豆婷婷洗澡| 一区二区在线观看视频 | 麻豆91在线看| 一级日本不卡的影视| 国产精品视频九色porn| 欧美一区二区三区日韩| av欧美精品.com| 国产米奇在线777精品观看| 亚洲观看高清完整版在线观看 | 亚洲天堂免费在线观看视频| xfplay精品久久| 欧美另类久久久品| 色综合久久综合网97色综合| 国产精品99久久久久久久女警 | 麻豆专区一区二区三区四区五区| 亚洲日韩欧美一区二区在线| 久久久久国色av免费看影院| 日韩免费视频一区| 欧美日本一道本| 欧美羞羞免费网站| 91视视频在线直接观看在线看网页在线看| 经典三级视频一区| 欧美aaa在线| 免费国产亚洲视频| 秋霞午夜鲁丝一区二区老狼| 婷婷久久综合九色综合绿巨人 | 国内久久精品视频| 麻豆国产91在线播放| 免费在线观看精品| 日本vs亚洲vs韩国一区三区二区| 亚洲成人精品一区二区|