c语语言言同同名名标标靶靶点点自自动动匹匹配配算算法法实实现现实实例例代代码码
1.两两个个标标靶靶数数据据
2.匹匹配配结结果果
3.代代码码
#include
#include
#include
using namespace std;
struct Point
{
int id;
float x,y,z;
Point(int id,float x,float y,float z):id( id),x( x),y( y),z( z){}
};
struct Triangle
{
Point p1,p2,p3;
};
class PointCloud
{
public:
bool readFile(char *filename);
//void PointMatch(const PointCloud& pc1,const PointCloud &pc2);
vector pData;
int r,g,b;
};
bool PointCloud::readFile(char *filename)
{
if(filename==NULL)return false;
FILE *fp=fopen(filename,"r");
if (!fp)
{
printf("Load file %s failed\n", filename);
return false;
}
char buffer[100];
int count=0;
while(!feof(fp))
{
fgets(buffer, 300, fp);
float x,y,z;
sscanf s(buffer,"%f%f%f",&x,&y,&z);
Point p(count++,x,y,z);
pData.push back(p);
}
pData.pop back();
}
float calDis(const Point &p1,const Point &p2)
{
return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)+(p2.z-p1.z)*(p2.z-p1.z));
}
void PointMatch(const PointCloud& pc1,const PointCloud &pc2)
{
for (int i=0;i
for(int j=i+1;j
for (int k=j+1;k
{
Point p1=pc1.pData[i];
Point p2=pc1.pData[j];
Point p3=pc1.pData[k];
float s12=calDis(p1,p2);
float s13=calDis(p1,p3);
float s23=calDis(p2,p3);
for (int m=0;m
for (int n=0;n
for (int l=0;l
{
if (n!=m&&m!=l&&n!=l)
{
Point p1=pc2.pData[m];
Point p2=pc2.pData[n];
Point p3=pc2.pData[l];
float s12=calDis( p1, p2);
float s13=calDis( p1, p3);
float s23=calDis( p2, p3);
if (fabs(s12- s12)<0.45&&fabs(s13- s13)<0.45&&fabs(s23- s23)<0.45)