资源简介
机载点云数学形态学类别。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
using namespace std;
struct Point
{
double x y z;
int r g b;
int c;
};
int main()
{
ifstream FileIn;
string filename;
std::cout << “点云路径:“ << std::endl;
cin >> filename;
FileIn.open(filename);
vector data;
double Xmax = -DBL_MAX Xmin = DBL_MAX Ymax = -DBL_MAX Ymin = DBL_MAX;
while (!FileIn.eof())
{
char ch1 ch2;
Point p;
FileIn >> p.x >>ch1>> p.y >>ch2>> p.z;
data.push_back(p);
if (p.x>Xmax)
{
Xmax=p.x;
}
if (p.x < Xmin)
{
Xmin = p.x;
}
if (p.y>Ymax)
{
Ymax = p.y;
}
if (p.y < Ymin)
{
Ymin = p.y;
}
}
FileIn.close();
std::cout << data.size() << std::endl;
//格网化
double grid = 1;
int width = (int)((Xmax - Xmin) / grid)+1;//强制类型转换
int height = (int)((Ymax - Ymin) / grid) + 1;
double *PointGrid = new double[width*height];//动态申请内存
for (int i = 0; i < width*height; i++)
PointGrid[i] = 0;
for (int i = 0; i < data.size(); i++)//遍历每一个点
{
int col = (int)((data[i].x - Xmin) / grid);
int row = (int)((data[i].y - Ymin) / grid);
if (PointGrid[row*width + col] != 0)
{
if(PointGrid[row*width + col]>data[i].z)
PointGrid[row*width + col] = data[i].z;
}
else if (PointGrid[row*width + col] == 0)
{
PointGrid[row*width + col] = data[i].z;
}
}
//腐蚀操作
double *MinPointGrid = new double[width*height];//动态申请内存
int WindowSize = 10;
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
int centerRow = row; int centerCol = col;
double Minz = PointGrid[row*width + col];
for (int x = -WindowSize / 2; x <= Wind
- 上一篇:OpenGL实现模拟瀑布的粒子系统
- 下一篇:c++ 编写的 有理数类
评论
共有 条评论