空间后方交会前方交会 MFC 实现 CSU 摄影测量学
空间后方交会前方交会 MFC 实现 CSU 摄影测量学
摄影测量学基础
(工具:VS2010)
一、 实验目的
• 通过对数字影像空间后交前交的程序设计实验,要求我们进一步理解和掌握影像外方位元素的有关理论、原理和方法。掌握VC++.net中创建类
• 利用计算机程序设计语言编写摄影测量空间交会软件进行快速确定影像的外方位元素及其精度,然后通过求得的外方位元素求解未知点的地面摄影测量坐标,达到通过摄影测量量测地面地理数据的目的。
二、实验内容与要求
要求:用C、VB或者Matlab编写空间后方交会一前方交会计算机程序。
➢提交实验报告:程序框图,程序源代码、计算结果及体会。
➢计算结果:地面点坐标、外方位元素及精度。
实验数据:
三、设计与实现:
3.1设计思路
3.1.1 基本框架:
3.1.2 成员关系:
3.2 界面设计及属性:
3.3 主要代码:
3.3.1 文件:Matrix.h
/***************************************************************************
* 文件名:<Matrix.h> *
* *
* 描述:矩阵类 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年4月19日 引用 *** *
* *
* 外部过程: *
* *
/**************************************************************************/
#pragma once
class CMatrix
{
public:
CMatrix(int row=3,int col=3);
// copy constructor
CMatrix (const CMatrix& m);
~CMatrix(void);
private:
double **dMatData;//保存矩阵元素数据的二维数组
int iRow;//矩阵的行
int iCol;//矩阵的列
public:
int Row() const {
return iRow;}//返回行
int Col() const {
return iCol;}//返回列
void SetSize (int row, int col);//调整数组的大小,原有数据不变(未测试)
double& operator () (int row, int col);//获取矩阵元素
double operator () (int row, int col) const;//重载获取矩阵元素函数,只有const对象能访问
CMatrix& operator = (const CMatrix& m) ;
//注意:友元函数并不是类自己的成员函数
friend CMatrix operator + (const CMatrix& m1,const CMatrix& m2);
friend CMatrix operator - (const CMatrix& m1,const CMatrix& m2);
friend CMatrix operator * (const CMatrix& m1,const CMatrix& m2);
friend CMatrix operator * (const double& num, const CMatrix& m1);
friend CMatrix operator * (const CMatrix& m1,const double& num);
friend CMatrix operator ~ (const CMatrix& m);//矩阵转置
CMatrix Inv();//矩阵求逆
void Unit();//生成单位矩阵
};
3.3.2文件:Math.cpp
#include "StdAfx.h"
#include "Matrix.h"
#include "math.h"
CMatrix::CMatrix(int row,int col)
{
iRow=row;
iCol=col;
dMatData = new double*[row];
for (int i=0; i < row; i++)
{
dMatData[i]= new double[col];
for(int j=0;j<col;j++)
{
dMatData[i][j]=0;
}
}
}
// copy constructor,
//拷贝构造函数的作用:
//(1)以类对象作为函数参数传值调用时;
//(2)函数返回值为类对象;
//(3)用一个已定义的对象去初始化一个新对象时;
CMatrix::CMatrix (const CMatrix& m)
{
iRow=m.Row();
iCol=m.Col();
dMatData = new double*[iRow];
for (int i=0; i < iRow; i++)
{
dMatData[i]= new double[iCol];
// for(int j=0;j<iCol;j++)
{
memcpy(dMatData[i],m.dMatData[i],sizeof(double)*iCol);
}
}
}
CMatrix::~CMatrix(void)
{
for (int i=0; i < iRow; i++)
{
delete[] dMatData[i];
}
delete[] dMatData;
}
//返回数组元素(引用返回)
double& CMatrix::operator () (int row, int col)
{
if (row >= iRow || col >= iCol)
{
throw( "CMatrix::operator(): Index out of range!");
}
return dMatData[row][col];
}
返回数组元素(重载)
double CMatrix::operator () (int row, int col) const
{
if (row >= iRow || col >= iCol)
{
throw( "CMatrix::operator(): Index out of range!");
}
return dMatData[row][col];
}
//重载预算符+
CMatrix operator + (const CMatrix& m1,const CMatrix& m2)
{
if((m1.Col()!=m2.Col()) ||(m1.Row()!=m2.Row()) )
{
throw( "CMatrix::operator+: The two matrix have different size!");
}
CMatrix matTmp(m1.Row(),m1.Col());
for(int i=0;i<m1.Row();i++)
{
for(int j=0;j<m1.Col();j++)
{
matTmp(i,j)=m1(i,j)+m2(i,j);
}
}
return matTmp;
}
//重载赋值运算符=,当左右两边矩阵的大小不相等时,
//以右边的大小为基准,调整左边矩阵的大小
CMatrix &CMatrix::operator = (const CMatrix& m)
{
//revised in 2011-4-1, by Daiwujiao
// if(iRow!=m.Row()||iCol!=m.Col())
//{
// throw( "CMatrix::operator=: The two matrix have different size!");
//}
if(iRow!=m.Row()||iCol!=m.Col())
{
SetSize(m.Row(),m.Col());
}
for (int i=0; i < iRow; i++)
{
for(int j=0;j<iCol;j++)
{
dMatData[i][j]=m(i,j);
}
}
return *this;
}
//调整矩阵大小,原有值不变
void CMatrix::SetSize (int row, int col)
{
if (row == iRow && col == iCol)
{
return;
}
double **rsData = new double*[row];
for (int i=0; i < row; i++)
{
rsData[i]= new double[col];
for(int j=0;j<col;j++)
{
rsData[i][j]=0;
}
}
int minRow=(iRow>row)?row:iRow;
int minCol= (iCol>col)?col:iCol;
int colSize = minCol * sizeof(double);
for (int i=0; i < minRow; i++)
{
memcpy( rsData[i], dMatData[i], colSize);
}
for (int i=0; i < minRow; i++)
{
delete[] dMatData[i];
}
delete[] dMatData;
dMatData=rsData;
iRow=row;
iCol=col;
return;
}
//重载预算符-
CMatrix operator - (const CMatrix& m1,const CMatrix& m2)
{
if((m1.Col()!=m2.Col()) ||(m1.Row()!=m2.Row()) )
{
throw( "CMatrix::operator-: The two matrix have different size!");
}
CMatrix matTmp(m1.Row(),m1.Col());
for(int i=0;i<m1.Row();i++)
{
for(int j=0;j<m1.Col();j++)
{
matTmp(i,j)=m1(i,j)-m2(i,j);
}
}
return matTmp;
}
//重载预算符*,两个矩阵相乘,m1的列要等于m2的行
CMatrix operator * (const CMatrix& m1,const CMatrix& m2)
{
if((m1.Col()!=m2.Row()))
{
throw( "CMatrix::operator*: The col of matrix m1 doesn't equ to row of m2 !");
}
CMatrix matTmp(m1.Row(),m2.Col());
for(int i=0;i<m1.Row();i++)
{
for(int j=0;j<m2.Col();j++)
{
for(int k=0;k<m2.Row();k++)
{
matTmp(i,j)+=m1(i,k)*m2(k,j);
}
}
}
return matTmp;
}
//重载预算符*,矩阵右乘一个数
CMatrix operator * (const CMatrix& m1,const double& num)
{
CMatrix matTmp(m1.Row(),m1.Col());
for(int i=0;i<m1.Row();i++)
{
for(int j=0;j<m1.Col();j++)
{
matTmp(i,j)=m1(i,j)*num;
}
}
return matTmp;
}
//重载预算符*,矩阵左乘一个数
CMatrix operator * (const double& num, const CMatrix& m1)
{
CMatrix matTmp(m1.Row(),m1.Col());
for(int i=0;i<m1.Row();i++)
{
for(int j=0;j<m1.Col();j++)
{
matTmp(i,j)=m1(i,j)*num;
}
}
return matTmp;
}
//矩阵转置
CMatrix operator ~ (const CMatrix& m)
{
CMatrix matTmp(m.Col(),m.Row());
for (int i=0; i < m.Row(); i++)
for (int j=0; j < m.Col(); j++)
{
matTmp(j