// SetMotion.cpp : 実装ファイル // #include "stdafx.h" #include "SLKinect.h" #include "SetMotion.h" ////////////////////////////////////////////////////////////////////////////////////////// // // CSetMotion ダイアログ // IMPLEMENT_DYNAMIC(CSetMotion, CDialog) CSetMotion::CSetMotion(NiSDK_Lib lib, CParameterSet prm, CWnd* pParent /*=NULL*/) : CDialog(CSetMotion::IDD, pParent) { sdk_lib = lib; param = prm; posButton = NULL; rotButton = NULL; cnfdncSldr = NULL; cnfdncEBox = NULL; jntButton = NULL; maSmthBtn = NULL; maTypeCombo = NULL; maNumCombo = NULL; niteSmthBtn = NULL; smoothSldr = NULL; smoothEBox = NULL; partsCombo = NULL; confidence = param.confidence; smoothNITE = param.smoothNITE; if (confidence<0.5) confidence = 0.5; else if (confidence>1.0) confidence = 1.0; if (smoothNITE<0.0) smoothNITE = 0.0; else if (smoothNITE>1.0) smoothNITE = 1.0; } void CSetMotion::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CSetMotion, CDialog) ON_EN_CHANGE(IDC_EDIT_CNFDNC, OnChangeConfidence) ON_EN_CHANGE(IDC_EDIT_SMOOTH, OnChangeSmooth) ON_WM_HSCROLL() ON_BN_CLICKED(IDC_CHECK_NITE_SMOOTH, OnBnClickedCheckNiteSmooth) ON_BN_CLICKED(IDC_CHECK_MVAV_SMOOTH, &CSetMotion::OnBnClickedCheckMvavSmooth) END_MESSAGE_MAP() // CSetMotion メッセージ ハンドラ BOOL CSetMotion::OnInitDialog() { char buf[LNAME]; CDialog::OnInitDialog(); posButton = (CButton*)GetDlgItem(IDC_RADIO_MOTION_POS); rotButton = (CButton*)GetDlgItem(IDC_RADIO_MOTION_ROT); cnfdncSldr = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_CNFDNC); cnfdncEBox = (CEdit*)GetDlgItem(IDC_EDIT_CNFDNC); jntButton = (CButton*)GetDlgItem(IDC_CHECK_JOINT_CONSTRAINT); maSmthBtn = (CButton*)GetDlgItem(IDC_CHECK_MVAV_SMOOTH); maTypeCombo = (CComboBox*)GetDlgItem(IDC_COMBO_MVAV_TYPE); maNumCombo = (CComboBox*)GetDlgItem(IDC_COMBO_MVAV_NUM); niteSmthBtn = (CButton*)GetDlgItem(IDC_CHECK_NITE_SMOOTH); smoothSldr = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_SMOOTH); smoothEBox = (CEdit*)GetDlgItem(IDC_EDIT_SMOOTH); partsCombo = (CComboBox*)GetDlgItem(IDC_COMBO_DETECT); // if (param.useRotData) { posButton->SetCheck(0); rotButton->SetCheck(1); } else { posButton->SetCheck(1); rotButton->SetCheck(0); } cnfdncSldr->SetRange(50, 100); cnfdncSldr->SetPos((int)(param.confidence*100)); memset(buf, 0, LNAME); snprintf(buf, LNAME-1, "%4.2f", param.confidence); cnfdncEBox->SetWindowText((LPCSTR)buf); if (param.useJointConst) { jntButton->SetCheck(1); } else { jntButton->SetCheck(0); } // maTypeCombo->SetCurSel(param.mvavType-1); maNumCombo->SetCurSel(param.mvavNum-1); if (param.useMvavSmooth) { maSmthBtn->SetCheck(1); maTypeCombo->EnableWindow(TRUE); maNumCombo->EnableWindow(TRUE); } else { maSmthBtn->SetCheck(0); maTypeCombo->EnableWindow(FALSE); maNumCombo->EnableWindow(FALSE); } // smoothSldr->SetRange(0, 100); smoothSldr->SetPos((int)(param.smoothNITE*100)); memset(buf, 0, LNAME); snprintf(buf, LNAME-1, "%4.2f", param.smoothNITE); smoothEBox->SetWindowText((LPCSTR)buf); if (param.useNiteSmooth) { niteSmthBtn->SetCheck(1); smoothSldr->EnableWindow(TRUE); smoothEBox->EnableWindow(TRUE); } else { niteSmthBtn->SetCheck(0); smoothSldr->EnableWindow(FALSE); smoothEBox->EnableWindow(FALSE); } // partsCombo->SetCurSel(param.detectParts-2); // if (sdk_lib==NiSDK_Kinect) { param.usePosData = TRUE; param.useRotData = FALSE; posButton->SetCheck(1); rotButton->SetCheck(0); rotButton->EnableWindow(FALSE); param.detectParts = 2; partsCombo->SetCurSel(param.detectParts-2); partsCombo->EnableWindow(FALSE); // Confidence param.confidence = 0.5; memset(buf, 0, LNAME); snprintf(buf, LNAME-1, "%4.2f", param.confidence); cnfdncEBox->SetWindowText((LPCSTR)buf); cnfdncSldr->SetPos(0); cnfdncSldr->EnableWindow(FALSE); cnfdncEBox->EnableWindow(FALSE); // NITE Smoothing param.useNiteSmooth = FALSE; niteSmthBtn->SetCheck(0); niteSmthBtn->EnableWindow(FALSE); smoothSldr->EnableWindow(FALSE); smoothEBox->EnableWindow(FALSE); } return TRUE; } void CSetMotion::OnOK() { char buf[LNAME]; if (rotButton->GetCheck()) { param.usePosData = FALSE; param.useRotData = TRUE; } else { param.usePosData = TRUE; param.useRotData = FALSE; } // memset(buf, 0, LNAME); cnfdncEBox->GetWindowText(buf, LNAME); param.confidence = (float)atof(buf); if (param.confidence<0.5) param.confidence = 0.5; if (jntButton->GetCheck()) { param.useJointConst = TRUE; } else { param.useJointConst = FALSE; } // if (maSmthBtn->GetCheck()) { param.useMvavSmooth = TRUE; } else { param.useMvavSmooth = FALSE; } param.mvavType = (NiMvAvType)(maTypeCombo->GetCurSel() + 1); param.mvavNum = maNumCombo->GetCurSel() + 1; // memset(buf, 0, LNAME); smoothEBox->GetWindowText(buf, LNAME); param.smoothNITE = (float)atof(buf); // if (niteSmthBtn->GetCheck()) { param.useNiteSmooth = TRUE; } else { param.useNiteSmooth = FALSE; } param.detectParts = partsCombo->GetCurSel() + 2; CDialog::OnOK(); } void CSetMotion::OnChangeConfidence() { char buf[LNAME]; memset(buf, 0, LNAME); cnfdncEBox->GetWindowText(buf, LNAME-1); confidence = (float)atof(buf); if (confidence<0.0 || confidence>1.0) { if (confidence<0.0) confidence = 0.0; else if (confidence>1.0) confidence = 1.0; memset(buf, 0, LNAME); snprintf(buf, LNAME-1, "%4.2f", confidence); cnfdncEBox->SetWindowText(buf); cnfdncEBox->UpdateWindow(); } cnfdncSldr->SetPos((int)(confidence*100)); } void CSetMotion::OnChangeSmooth() { char buf[LNAME]; memset(buf, 0, LNAME); smoothEBox->GetWindowText(buf, LNAME-1); smoothNITE = (float)atof(buf); if (smoothNITE<0.0 || smoothNITE>1.0) { if (smoothNITE<0.0) smoothNITE = 0.0; else if (smoothNITE>1.0) smoothNITE = 1.0; memset(buf, 0, LNAME); snprintf(buf, LNAME-1, "%4.2f", smoothNITE); smoothEBox->SetWindowText(buf); smoothEBox->UpdateWindow(); } smoothSldr->SetPos((int)(smoothNITE*100)); } void CSetMotion::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { char buf[LNAME]; if (cnfdncSldr==(CSliderCtrl*)pScrollBar) { int cnfd = cnfdncSldr->GetPos(); memset(buf, 0, LNAME); snprintf(buf, LNAME-1, "%4.2f", cnfd/100.); cnfdncEBox->SetWindowText(buf); cnfdncEBox->UpdateWindow(); } else { //if (smoothSldr==(CSliderCtrl*)pScrollBar) { int smth = smoothSldr->GetPos(); memset(buf, 0, LNAME); snprintf(buf, LNAME-1, "%4.2f", smth/100.); smoothEBox->SetWindowText(buf); smoothEBox->UpdateWindow(); } } void CSetMotion::OnBnClickedCheckNiteSmooth() { if (niteSmthBtn->GetCheck()) { smoothSldr->EnableWindow(TRUE); smoothEBox->EnableWindow(TRUE); } else { smoothSldr->EnableWindow(FALSE); smoothEBox->EnableWindow(FALSE); } } void CSetMotion::OnBnClickedCheckMvavSmooth() { if (maSmthBtn->GetCheck()) { maTypeCombo->EnableWindow(TRUE); maNumCombo->EnableWindow(TRUE); } else { maTypeCombo->EnableWindow(FALSE); maNumCombo->EnableWindow(FALSE); } }