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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ccontroller.cpp

?? 《游戲編程中的人工智能技術》一書中8
?? CPP
字號:
#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_dMatchProbability(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,
                          true);
                          
}

//--------------------------------- 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 ---------------------------------
//
//------------------------------------------------------------------------
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,
                                   true);

           //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_dMatchProbability = 0;
  m_iBestMatch = 0;
  m_iMatch = -1;
  
  for (int i=0; i<outputs.size(); ++i)
  {
    if (outputs[i] > m_dMatchProbability)
    {
      //make a note of the most likely candidate
      m_dMatchProbability = outputs[i];

      m_iBestMatch = i;
 

      //if the candidates output exceeds the threshold we 
      //have a match! ...so make a note of it.
      if (m_dMatchProbability > 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_dMatchProbability > 0)
    {
   
      if ( (m_vecSmoothPath.size() > 1) && (m_Mode != LEARNING) )
      {
        if (m_dMatchProbability < 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));

        }

        string s = "Probability is " + ftos(m_dMatchProbability);
        TextOut(surface, 5, 30, s.c_str(), s.size());
      }

      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);
    }
  }	 
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区免费网站| 国产自产视频一区二区三区| 日韩va欧美va亚洲va久久| 国产麻豆成人精品| 欧美丰满嫩嫩电影| 中文字幕欧美一| 极品少妇xxxx偷拍精品少妇| 欧美中文字幕一区二区三区亚洲| 26uuu久久天堂性欧美| 一区二区视频在线| 成人性生交大片免费看视频在线| 欧美久久久久久久久| 亚洲欧美日韩一区| 成人免费看视频| 精品美女在线播放| 日本怡春院一区二区| 日本乱人伦一区| 国产精品久久久久一区二区三区| 久久www免费人成看片高清| 欧美日韩一区小说| 亚洲精品v日韩精品| 成人的网站免费观看| 国产欧美一区二区三区鸳鸯浴| 麻豆专区一区二区三区四区五区| 欧美午夜一区二区| 一区二区三区高清不卡| 色综合天天狠狠| 亚洲男同性视频| 成人午夜精品在线| 久久久美女毛片| 国产在线视视频有精品| 精品久久久影院| 久久精品国产99久久6| 日韩免费高清av| 久久国产精品色婷婷| 精品免费日韩av| 国产精品资源在线看| 国产女人水真多18毛片18精品视频| 激情综合色播五月| 久久亚洲欧美国产精品乐播| 极品少妇一区二区三区精品视频 | 亚洲国产综合在线| 欧美色偷偷大香| 日韩福利电影在线观看| 日韩你懂的电影在线观看| 激情久久五月天| 中文字幕国产一区| 色视频成人在线观看免| 一区二区三区精品| 日韩一区二区三区四区| 国产专区欧美精品| 国产精品视频第一区| 色哟哟亚洲精品| 性感美女极品91精品| 日韩免费观看高清完整版在线观看| 久久激五月天综合精品| 日本一区二区成人在线| 日本高清不卡在线观看| 午夜精品一区二区三区免费视频| 日韩午夜av电影| 成人黄色片在线观看| 亚洲小说春色综合另类电影| 日韩三级在线观看| 国产精品系列在线播放| 亚洲视频小说图片| 日韩亚洲欧美综合| 成人av电影免费观看| 亚洲一区二区三区四区不卡| 日韩精品一区二区三区视频播放| 国产成人午夜精品5599 | 一区二区成人在线| 欧美一区中文字幕| 成a人片亚洲日本久久| 午夜精品视频一区| 中文字幕 久热精品 视频在线| 欧美在线视频日韩| 国产91丝袜在线播放0| 午夜激情久久久| 中文av一区特黄| 欧美一级免费观看| 色先锋资源久久综合| 韩国av一区二区三区| 亚洲chinese男男1069| 国产无一区二区| 91精品久久久久久久久99蜜臂| 成人av在线播放网站| 轻轻草成人在线| 综合av第一页| 久久精品免费在线观看| 91精品国产欧美日韩| 95精品视频在线| 国产成人免费9x9x人网站视频| 肉色丝袜一区二区| 亚洲另类中文字| 国产精品网站在线观看| 日韩一级完整毛片| 欧美色综合久久| 色香蕉久久蜜桃| 成人黄页毛片网站| 国产精品综合一区二区三区| 日欧美一区二区| 洋洋成人永久网站入口| 国产精品欧美精品| 久久精品一区二区三区不卡| 精品乱码亚洲一区二区不卡| 678五月天丁香亚洲综合网| 欧美优质美女网站| 99久久精品久久久久久清纯| 国产91清纯白嫩初高中在线观看| 久久66热偷产精品| 久久国内精品自在自线400部| 日韩国产在线观看| 亚洲成人精品影院| 亚洲国产综合在线| 性做久久久久久久免费看| 亚洲最新在线观看| 亚洲综合图片区| 亚洲成av人**亚洲成av**| 亚洲第一搞黄网站| 日日夜夜免费精品| 免费观看在线综合色| 另类的小说在线视频另类成人小视频在线 | 中文字幕一区二区三区四区不卡 | 欧美精品在线观看一区二区| 欧美三级韩国三级日本三斤| 欧美性生活大片视频| 欧美亚洲综合久久| 欧美精品777| 精品国产百合女同互慰| 久久久噜噜噜久噜久久综合| 中文天堂在线一区| 一区二区三区欧美日| 午夜欧美在线一二页| 另类综合日韩欧美亚洲| 国产成人午夜视频| 91论坛在线播放| 欧美肥妇bbw| 久久久99久久| 亚洲男人的天堂在线aⅴ视频| 亚洲成av人影院| 国产乱码精品一区二区三| www.日韩大片| 欧美色视频在线观看| 日韩久久久精品| 国产精品久久久久永久免费观看| 一区二区激情视频| 另类的小说在线视频另类成人小视频在线 | 国产精品白丝在线| 亚洲国产精品久久不卡毛片| 蜜臀av一区二区三区| 成人性视频免费网站| 精品视频一区二区不卡| 久久久久久久综合日本| 亚洲男同1069视频| 激情图片小说一区| 在线视频综合导航| 久久久99免费| 亚洲成人高清在线| 成人黄动漫网站免费app| 欧美日韩精品免费观看视频| 国产欧美一区二区精品性| 亚洲一区二区四区蜜桃| 国产成人精品免费看| 欧美久久免费观看| 国产精品全国免费观看高清 | 日韩欧美在线网站| 日韩伦理av电影| 国内精品久久久久影院薰衣草| 一本一道波多野结衣一区二区| 精品av综合导航| 亚洲国产精品自拍| 波波电影院一区二区三区| 日韩欧美国产一区在线观看| 亚洲日本在线a| 成人性生交大片免费看视频在线| 884aa四虎影成人精品一区| 亚洲天堂av老司机| 成熟亚洲日本毛茸茸凸凹| 欧美一区二区在线不卡| 亚洲精品欧美二区三区中文字幕| 国产精品一区二区久久精品爱涩| 欧美日韩色综合| 亚洲一区av在线| 色一情一乱一乱一91av| 国产精品天美传媒沈樵| 国产酒店精品激情| 精品国产第一区二区三区观看体验| 天天影视色香欲综合网老头| 色系网站成人免费| 国产精品国产成人国产三级| 国产美女av一区二区三区| 日韩免费高清视频| 麻豆专区一区二区三区四区五区| 欧美福利电影网| 日日摸夜夜添夜夜添国产精品 | 国产成人亚洲综合a∨婷婷| 日韩精品一区二区在线| 久久精品国产久精国产| 日韩免费观看高清完整版在线观看| 日韩中文字幕91|