コード例 #1
0
ファイル: MyTree.cpp プロジェクト: styxschip/Note
//增加数据
bool MyTree::Add(int data)
{
  //判断当前是否是空树
  if(m_pRoot == NULL)
  {
    m_pRoot = new TreeNode(data);
    if(m_pRoot == NULL)
    {
      return false;
    }
  }
  else
  {
    TreeNode* pInsert = new TreeNode(data);
    TreeNode* pCur = m_pRoot;
    TreeNode* pParent = NULL;
    bool bLeft = false;

    while(pCur != NULL)
    {
      pParent = pCur;
      if(data < pCur->m_Data)
      {
        pCur = pCur->m_pLeft;
        bLeft = true;
      }
      else if(data > pCur->m_Data)
      {
        pCur = pCur->m_pRight;
        bLeft = false;
      }
    }

    if(bLeft)
    {
      pParent->m_pLeft = pInsert;
    }
    else
    {
      pParent->m_pRight = pInsert;
    }
    pInsert->m_pParent = pParent;

    //更新深度
    UpdateDepth(pInsert);
  }

  m_nCount++;
  return true;
}
コード例 #2
0
ファイル: MyTree.cpp プロジェクト: styxschip/Note
//删除
bool MyTree::Del(int data)
{
  TreeNode* pDelNode = Find(data);
  if(pDelNode == NULL)
  {
    return false;
  }

  while(true)
  {
    //3种情况
    //待删除结点是叶子结点
    if(pDelNode->m_pLeft == NULL && pDelNode->m_pRight == NULL)
    {
      TreeNode* pParent = pDelNode->m_pParent;
      if(pParent)
      {
        if(pParent->m_pLeft == pDelNode)
        {
          pParent->m_pLeft = NULL;
        }
        else
        {
          pParent->m_pRight = NULL;
        }
      }
      else
      {
        m_pRoot = NULL;
      }

      
      UpdateDepth(pDelNode);
      break;
    }
    //待删除结点有两个子结点
    else if(pDelNode->m_pLeft != NULL && pDelNode->m_pRight != NULL)
    {
      //寻找待删除结点的左子树的最大值
      TreeNode* pLeftMax = pDelNode->m_pLeft;
      while(pLeftMax)
      {
        if(pLeftMax->m_pRight == NULL)
        {
          break;
        }
        
        pLeftMax = pLeftMax->m_pRight;
      }
      
      //交换数据
      int nTmp = pDelNode->m_Data;
      pDelNode->m_Data = pLeftMax->m_Data;
      pLeftMax->m_Data = nTmp;
      
      pDelNode = pLeftMax;
      continue;
    }
    //待删除结点有一个子结点
    else
    {
      TreeNode* pParent = pDelNode->m_pParent;
      TreeNode* pChild = NULL;
      if(pDelNode->m_pLeft)
      {
        pChild = pDelNode->m_pLeft;
      }
      else
      {
        pChild = pDelNode->m_pRight;
      }
      pChild->m_pParent = pParent;

      if(pParent)
      {
        if(pParent->m_pLeft == pDelNode)
        {
          pParent->m_pLeft = pChild;
        }
        else
        {
          pParent->m_pRight = pChild;
        }
      }
      //待删除结点是根结点
      else
      {
        m_pRoot = pChild;
      }

      UpdateDepth(pDelNode);

      break;
    }
  }

  delete pDelNode;
  m_nCount--;

  return true;
}
コード例 #3
0
void Kinect2Manager::Update(unsigned int options) {

#ifdef _USE_KINECT

    IColorFrame * pColorFrame = NULL;
    IDepthFrame * pDepthFrame = NULL;
    IBodyFrame * pBodyFrame = NULL;
    IBodyIndexFrame * pBodyIndexFrame = NULL;
    IMultiSourceFrame * pMultiSourceFrame = NULL;

    m_nColorWidth = 0;
    m_nColorHeight = 0;
    m_nDepthWidth = 0;
    m_nDepthHeight = 0;

    m_bCalculateDepthRGBX = options & Update::DepthRGBX;

    int numUpdate = countUpdate(options);

    HRESULT hr = 1;

    if (numUpdate > 1) {
        hr = m_pMultiSourceFrameReader->AcquireLatestFrame(&pMultiSourceFrame);
    }

    if (SUCCEEDED(hr)) {

        if (options & Update::Color) {
            IColorFrameReference* pColorFrameReference = NULL;

            if (numUpdate > 1) {
                hr = pMultiSourceFrame->get_ColorFrameReference(&pColorFrameReference);

                if (SUCCEEDED(hr))
                {
                    hr = pColorFrameReference->AcquireFrame(&pColorFrame);
                }
            }
            else {
                hr = m_pColorFrameReader->AcquireLatestFrame(&pColorFrame);
            }

            if (SUCCEEDED(hr)) {
                m_bMapColorToDepth = options & Update::MapColorToDepth;
            }
            else {
                options &= ~Update::Color;
            }

            SafeRelease(pColorFrameReference);
        }
        if (options & Update::Depth) {
            IDepthFrameReference* pDepthFrameReference = NULL;

            if (numUpdate > 1) {

                hr = pMultiSourceFrame->get_DepthFrameReference(&pDepthFrameReference);
                if (SUCCEEDED(hr))
                {
                    hr = pDepthFrameReference->AcquireFrame(&pDepthFrame);
                }
            }
            else {
                hr = m_pDepthFrameReader->AcquireLatestFrame(&pDepthFrame);
            }

            if (SUCCEEDED(hr)) {

                m_bMapDepthToColor = options & Update::MapDepthToColor;
            }
            else {
                options &= ~Update::Depth;
            }

            SafeRelease(pDepthFrameReference);
        }
        if (options & Update::Body) {
            IBodyFrameReference* pBodyFrameReference = NULL;

            if (numUpdate > 1) {

                hr = pMultiSourceFrame->get_BodyFrameReference(&pBodyFrameReference);
                if (SUCCEEDED(hr))
                {
                    hr = pBodyFrameReference->AcquireFrame(&pBodyFrame);
                }
            }
            else {
                hr = m_pBodyFrameReader->AcquireLatestFrame(&pBodyFrame);
            }
            SafeRelease(pBodyFrameReference);
        }



        if (options & Update::Color && options & Update::Depth) {




            if (options & Update::BodyIndex && options & Update::MapColorToDepth) {
                if (m_bDepthColorMapCalculated) {
                    IBodyIndexFrameReference* pBodyIndexFrameReference = NULL;

                    hr = pMultiSourceFrame->get_BodyIndexFrameReference(&pBodyIndexFrameReference);
                    if (SUCCEEDED(hr))
                    {
                        hr = pBodyIndexFrameReference->AcquireFrame(&pBodyIndexFrame);
                    }

                    SafeRelease(pBodyIndexFrameReference);
                }
            }
        }
    }

    if (pBodyFrame) {
        UpdateBody(pBodyFrame);

    }
    if (pColorFrame) {
        UpdateColor(pColorFrame);
    }

    if (pDepthFrame) {
        UpdateDepth(pDepthFrame);


        if (options & Update::MapDepthToColor) {
            CalculateColorDepthMap();
            if (m_bColorDepthMapCalculated)
                ProcessDepthToColor(m_pDepth, m_nDepthWidth, m_nDepthHeight, m_pColorDepthMap, m_nColorWidth, m_nColorHeight);
        }

        if (options & Update::MapColorToDepth) {
            CalculateDepthColorMap();
            if (m_bDepthColorMapCalculated) {
                ProcessColorToDepth(m_pColorRGBX, m_nColorWidth, m_nColorHeight, m_pDepthColorMap, m_nDepthWidth, m_nDepthHeight);

                if (pBodyIndexFrame) {
                    UpdateBodyIndex(pBodyIndexFrame);
                }
            }

        }
    }


    SafeRelease(pColorFrame);
    SafeRelease(pDepthFrame);
    SafeRelease(pBodyFrame);
    SafeRelease(pBodyIndexFrame);
    SafeRelease(pMultiSourceFrame);
#else

    m_nDepthWidth = CAPTURE_SIZE_X_DEPTH;
    m_nDepthHeight = CAPTURE_SIZE_Y_DEPTH;

    m_nColorWidth = CAPTURE_SIZE_X_COLOR;
    m_nColorHeight = CAPTURE_SIZE_Y_COLOR;

    if (options & Update::MapDepthToColor) {
        CalculateColorDepthMap();
        if (m_bColorDepthMapCalculated)
            ProcessDepthToColor(m_pDepth, m_nDepthWidth, m_nDepthHeight, m_pColorDepthMap, m_nColorWidth, m_nColorHeight);
    }

    if (options & Update::MapColorToDepth) {
        CalculateDepthColorMap();
        if (m_bDepthColorMapCalculated) {
            ProcessColorToDepth(m_pColorRGBX, m_nColorWidth, m_nColorHeight, m_pDepthColorMap, m_nDepthWidth, m_nDepthHeight);

        }

    }

    UpdateBodyIndex(NULL);

#endif
}