增加点到面的计算测试

This commit is contained in:
TAO Cheng
2013-06-07 15:38:34 +08:00
parent 667f78e7f4
commit 4e286a5367
2 changed files with 293 additions and 0 deletions
@@ -0,0 +1,261 @@
// SO7_Verfication_Algorithm.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include <math.h>
#include "SO7_Verfication_Algorithm.h"
#include "afxdialogex.h"
// CSO7_Verfication_Algorithm dialog
IMPLEMENT_DYNAMIC(CSO7_Verfication_Algorithm, CDialog)
CSO7_Verfication_Algorithm::CSO7_Verfication_Algorithm(CWnd* pParent /*=NULL*/)
: CDialog(CSO7_Verfication_Algorithm::IDD, pParent)
{
}
CSO7_Verfication_Algorithm::~CSO7_Verfication_Algorithm()
{
}
void CSO7_Verfication_Algorithm::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CSO7_Verfication_Algorithm, CDialog)
ON_BN_CLICKED(IDC_BUTTON_IMAGEDLL_2LASER_CALCULATE, &CSO7_Verfication_Algorithm::OnBnClickedButtonImagedll2laserCalculate)
END_MESSAGE_MAP()
// CSO7_Verfication_Algorithm message handlers
//======================================================
BOOL CSO7_Verfication_Algorithm::OnInitDialog()
{
CDialog::OnInitDialog();
m_BTNFont.CreatePointFont(200,L"Arial Black") ;
((CButton*)(GetDlgItem(IDC_BUTTON_IMAGEDLL_2LASER_CALCULATE)))->SetFont(&m_BTNFont);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSO7_Verfication_Algorithm::OnBnClickedButtonImagedll2laserCalculate()
{
CString str;
UpdateData(TRUE);
USES_CONVERSION;
Struct_3DPoint TopSurfacePnts[3];
Struct_3DPoint BottomSurfacePnts[3];
Struct_3DPoint ReferencePlanePnts[3];
double TopPlaneCoeff[4]={0.0};
double BottomPlaneCoeff[4]={0.0};
double ReferencePlaneCoeff[4]={0.0};
double CalibrateValue(0.0);
double CalibrateTopLaserValue(0.0);
double CalibrateBottomLaserValue(0.0);
double TopLaserValue(0.0);
//==================Calibrate Value===============================
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ_CALIBRATE)->GetWindowText(str);
const char* cTempValue=T2A(str);
CalibrateTopLaserValue=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ__CALIBRATE)->GetWindowText(str);
cTempValue=T2A(str);
CalibrateBottomLaserValue=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_STANDARD_VALUE)->GetWindowText(str);
cTempValue=T2A(str);
CalibrateValue=atof(cTempValue);
//==================Reference Surface===============================
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X1)->GetWindowText(str);
cTempValue=T2A(str);
ReferencePlanePnts[0].x=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y1)->GetWindowText(str);
cTempValue=T2A(str);
ReferencePlanePnts[0].y=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ1)->GetWindowText(str);
cTempValue=T2A(str);
TopLaserValue=atof(cTempValue);
//calibrate
ReferencePlanePnts[0].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue;
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X2)->GetWindowText(str);
cTempValue=T2A(str);
ReferencePlanePnts[1].x=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y2)->GetWindowText(str);
cTempValue=T2A(str);
ReferencePlanePnts[1].y=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ2)->GetWindowText(str);
cTempValue=T2A(str);
TopLaserValue=atof(cTempValue);
//calibrate
ReferencePlanePnts[1].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue;
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X3)->GetWindowText(str);
cTempValue=T2A(str);
ReferencePlanePnts[2].x=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y3)->GetWindowText(str);
cTempValue=T2A(str);
ReferencePlanePnts[2].y=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ3)->GetWindowText(str);
cTempValue=T2A(str);
TopLaserValue=atof(cTempValue);
//calibrate
ReferencePlanePnts[2].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue;
ThreePntsConstructionPanel(ReferencePlanePnts,ReferencePlaneCoeff);
//=====================Top Surface==================================
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X4)->GetWindowText(str);
cTempValue=T2A(str);
TopSurfacePnts[0].x=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y4)->GetWindowText(str);
cTempValue=T2A(str);
TopSurfacePnts[0].y=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ4)->GetWindowText(str);
cTempValue=T2A(str);
TopLaserValue=atof(cTempValue);
//calibrate
TopSurfacePnts[0].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue;
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X5)->GetWindowText(str);
cTempValue=T2A(str);
TopSurfacePnts[1].x=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y5)->GetWindowText(str);
cTempValue=T2A(str);
TopSurfacePnts[1].y=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ5)->GetWindowText(str);
cTempValue=T2A(str);
TopLaserValue=atof(cTempValue);
//calibrate
TopSurfacePnts[1].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue;
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X6)->GetWindowText(str);
cTempValue=T2A(str);
TopSurfacePnts[2].x=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y6)->GetWindowText(str);
cTempValue=T2A(str);
TopSurfacePnts[2].y=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_TOPZ6)->GetWindowText(str);
cTempValue=T2A(str);
TopLaserValue=atof(cTempValue);
//calibrate
TopSurfacePnts[2].z=TopLaserValue-CalibrateTopLaserValue+CalibrateValue+CalibrateBottomLaserValue;
ThreePntsConstructionPanel(TopSurfacePnts,TopPlaneCoeff);
//====================Bottom Surface================================
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X7)->GetWindowText(str);
cTempValue=T2A(str);
BottomSurfacePnts[0].x=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y7)->GetWindowText(str);
cTempValue=T2A(str);
BottomSurfacePnts[0].y=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ1)->GetWindowText(str);
cTempValue=T2A(str);
BottomSurfacePnts[0].z=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X8)->GetWindowText(str);
cTempValue=T2A(str);
BottomSurfacePnts[1].x=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y8)->GetWindowText(str);
cTempValue=T2A(str);
BottomSurfacePnts[1].y=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ2)->GetWindowText(str);
cTempValue=T2A(str);
BottomSurfacePnts[1].z=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_X9)->GetWindowText(str);
cTempValue=T2A(str);
BottomSurfacePnts[2].x=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_Y9)->GetWindowText(str);
cTempValue=T2A(str);
BottomSurfacePnts[2].y=atof(cTempValue);
GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_BOTTOMZ3)->GetWindowText(str);
cTempValue=T2A(str);
BottomSurfacePnts[2].z=atof(cTempValue);
ThreePntsConstructionPanel(BottomSurfacePnts,BottomPlaneCoeff);
/***************************************************************
result
****************************************************************/
double Top2ReferenceDis[4]={0.0};
double Bottom2ReferenceDis[4]={0.0};
double dAnswer(0.0);
CString csOutput;
//==================Top - Reference================================
Top2ReferenceDis[0]=PointToPanelDistance(TopSurfacePnts[0],ReferencePlaneCoeff);
Top2ReferenceDis[1]=PointToPanelDistance(TopSurfacePnts[1],ReferencePlaneCoeff);
Top2ReferenceDis[2]=PointToPanelDistance(TopSurfacePnts[2],ReferencePlaneCoeff);
Top2ReferenceDis[3]=(Top2ReferenceDis[0]+Top2ReferenceDis[1]+Top2ReferenceDis[2])/3.0;
csOutput.Format(_T("%.4g"),Top2ReferenceDis[0]);
((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE)))->SetWindowText(csOutput);
csOutput.Format(_T("%.4g"),Top2ReferenceDis[1]);
((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE2)))->SetWindowText(csOutput);
csOutput.Format(_T("%.4g"),Top2ReferenceDis[2]);
((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE3)))->SetWindowText(csOutput);
csOutput.Format(_T("%.4g"),Top2ReferenceDis[3]);
((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE4)))->SetWindowText(csOutput);
Bottom2ReferenceDis[0]=PointToPanelDistance(BottomSurfacePnts[0],ReferencePlaneCoeff);
Bottom2ReferenceDis[1]=PointToPanelDistance(BottomSurfacePnts[1],ReferencePlaneCoeff);
Bottom2ReferenceDis[2]=PointToPanelDistance(BottomSurfacePnts[2],ReferencePlaneCoeff);
Bottom2ReferenceDis[3]=(Bottom2ReferenceDis[0]+Bottom2ReferenceDis[1]+Bottom2ReferenceDis[2])/3.0;
dAnswer=Top2ReferenceDis[3]-Bottom2ReferenceDis[3];
csOutput.Format(_T("%.4g"),Bottom2ReferenceDis[0]);
((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE5)))->SetWindowText(csOutput);
csOutput.Format(_T("%.4g"),Bottom2ReferenceDis[1]);
((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE6)))->SetWindowText(csOutput);
csOutput.Format(_T("%.4g"),Bottom2ReferenceDis[2]);
((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE7)))->SetWindowText(csOutput);
csOutput.Format(_T("%.4g"),Bottom2ReferenceDis[3]);
((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE8)))->SetWindowText(csOutput);
csOutput.Format(_T("%.4g"),dAnswer);
((CButton*)(GetDlgItem(IDC_EDIT_IMAGEDLL_2LASER_MEASURED_VALUE9)))->SetWindowText(csOutput);
UpdateData(FALSE);
}
//===================================================================
BOOL CSO7_Verfication_Algorithm::ThreePntsConstructionPanel(Struct_3DPoint* pArr,double* Coe)
{
Struct_3DPoint p1,p2,p3;
p1 = pArr[0];
p2 = pArr[1];
p3 = pArr[2];
double a(0.0),b(0.0),c(0.0),d(0.0);
a = ( (p2.y-p1.y)*(p3.z-p1.z)-(p2.z-p1.z)*(p3.y-p1.y) );
b = ( (p2.z-p1.z)*(p3.x-p1.x)-(p2.x-p1.x)*(p3.z-p1.z) );
c = ( (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x) );
d = ( 0-(a*p1.x+b*p1.y+c*p1.z) );
Coe[0]=a;
Coe[1]=b;
Coe[2]=c;
Coe[3]=d;
return TRUE;
};
//===================================================================
double CSO7_Verfication_Algorithm::PointToPanelDistance(Struct_3DPoint PntPos,double* Coe)
{
double m_result(0.0);
double a(0.0),b(0.0),c(0.0),d(0.0);
a=Coe[0];
b=Coe[1];
c=Coe[2];
d=Coe[3];
double x(0.0),y(0.0),z(0.0);
x=PntPos.x;
y=PntPos.y;
z=PntPos.z;
m_result=fabs((a*x+b*y+c*z+d) / sqrt(a*a+b*b+c*c));
return m_result;
};
@@ -0,0 +1,32 @@
#pragma once
typedef struct{
double x;
double y;
double z;
}Struct_3DPoint;
// CSO7_Verfication_Algorithm dialog
class CSO7_Verfication_Algorithm : public CDialog
{
DECLARE_DYNAMIC(CSO7_Verfication_Algorithm)
public:
CSO7_Verfication_Algorithm(CWnd* pParent = NULL); // standard constructor
virtual ~CSO7_Verfication_Algorithm();
// Dialog Data
enum { IDD = IDD_SO7_UTIL_VERIFICATION_ALGORITHM };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
protected:
CFont m_BTNFont;
public:
BOOL ThreePntsConstructionPanel(Struct_3DPoint* pArr,double* Coe);
double PointToPanelDistance(Struct_3DPoint PntPos,double* Coe);
afx_msg void OnBnClickedButtonImagedll2laserCalculate();
};