c語言同名標靶點自動匹配算法實現(xiàn)實例代碼
更新時間:2018年02月03日 08:45:07 作者:微book
這篇文章主要介紹了c語言同名標靶點自動匹配算法實現(xiàn)實例代碼,分享了相關代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
1.兩個標靶數(shù)據(jù)


2.匹配結果

3.代碼
#include <iostream>
#include <vector>
#include <math.h>
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<Point> 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<pc1.pData.size()-2;++i)
for(int j=i+1;j<pc1.pData.size()-1;++j)
for (int k=j+1;k<pc1.pData.size();++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<pc2.pData.size();++m)
for (int n=0;n<pc2.pData.size();++n)
for (int l=0;l<pc2.pData.size();++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)
{
cout<<"pc1....."<<p1.id<<"pc2......"<<_p1.id<<endl;
cout<<"pc1....."<<p2.id<<"pc2......"<<_p2.id<<endl;
cout<<"pc1....."<<p3.id<<"pc2......"<<_p3.id<<endl;
}
}
}
}
}
int main()
{
char *file1="測試點云\\點云Mark0.txt";
char *file2="測試點云\\點云Mark1.txt";
PointCloud pc1,pc2;
pc1.readFile(file1);
pc2.readFile(file2);
PointMatch(pc1,pc2);
}
總結
以上就是本文關于c語言同名標靶點自動匹配算法實現(xiàn)實例代碼的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關文章
淺析VSCode launch.json中的各種替換變量的意思 ${workspaceFolder} ${file} $
這篇文章主要介紹了VSCode launch.json中的各種替換變量的意思 ${workspaceFolder} ${file} ${fileBasename} ${fileDirname}等,非常不錯具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03
c++之解決char轉string時出現(xiàn)的亂碼問題
這篇文章主要介紹了c++之解決char轉string時出現(xiàn)的亂碼問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08
淺析C/C++ 中return *this和return this的區(qū)別
return *this返回的是當前對象的克隆或者本身,return this返回當前對象的地址,下面通過本文給大家介紹C/C++ 中return *this和return this的區(qū)別,感興趣的朋友一起看看吧2019-10-10

