当前位置:首页 > C++ > 正文内容

GDAL构建Delaunay三角网

admin3年前 (2020-12-18)C++2800

GDAL能创建Delaunay三角网我是没想到的,需要包含头文件gdal_alg.h

使用GDALTriangulationCreateDelaunay函数,函数说明在此 ,三个参数:

第一个是点的个数,第二三个分别是点的X坐标和点的Y坐标。

返回值是GDALTriangulation* 类型的,GDALTriangulation是个结构体,包含三个成员,一个是int nFacets ,表示三角面片的个数,int类型;第二个是GDALTriFacet* pasFacets,表示三角面片数组,GDALTriFacet仍然是一个结构体,包含两个成员,int anVertexIdx[3]保存了三角形三个顶点的索引,int anNeighborIdx[3]保存了此三角面片相邻的三角面片的索引或者值为-1;GDALTriBarycentricCoefficients* pasFacetCoefficients保存的是三角形的重心系数,也是个结构体,这里不再叙述(不是很明白)。

使用GDALTriangulationCreateDelaunay后要使用GDALTriangulationFree释放资源,还有一些相关函数,可以去翻阅相关手册。


以下代码中

ui->textEdit->append(QString::number(indexOne)+" "+QString::number(indexTwo)+" "+QString::number(indexThree));

因为是用Qt,这句是将每个三角面片的顶点索引输出到testEdit中,所以这句话忽略。

double *x= new double[5]{0,2,4,4,0};
double *y = new double[5]{0,2,0,4,4};
GDALTriangulation* triangularmesh = GDALTriangulationCreateDelaunay(5, x, y);

for (int i = 0; i < triangularmesh->nFacets; i++)
{
int indexOne = triangularmesh->pasFacets[i].anVertexIdx[0];
int indexTwo = triangularmesh->pasFacets[i].anVertexIdx[1];
int indexThree = triangularmesh->pasFacets[i].anVertexIdx[2];
ui->textEdit->append(QString::number(indexOne)+" "+QString::number(indexTwo)+" "+QString::number(indexThree));

}
delete[] x;
delete[] y;
GDALTriangulationFree(triangularmesh);


扫描二维码推送至手机访问。

版权声明:本文由lovedm.club发布,如需转载请注明出处。

本文链接:https://lovedm.club/?id=109

标签: GDAL
分享给朋友:

“GDAL构建Delaunay三角网” 的相关文章

C++ vector 初始化

有几种初始化的方式,直接扔到代码里看了:#include <vector> #include <iostream> #include <algorithm> using namespace std;...

C++计算程序运行的时间

最近在程序中有个读取文件的操作,想知道耗费的时间,查找之后大家都在用C++11中的库chrono,找了个能运行的现成写好的类:链接代码如下:#include <iostream> #include <chrono> using names...

C++ 函数指针

1、什么是函数指针函数是实现特定功能的程序代码的集合,函数代码在内存中也要占据一段存储空间,这段空间的起始地址称为函数的入口地址。C++规定函数的入口地址为函数的指针,即函数名既代表函数,又是函数的指针(或地址)。C++指向函数的指针变量,定义形式为:返回类型 (*函数指针变量名)(形参列表);可以...

C++ 派生类的析构函数的执行顺序

C++ 派生类的析构函数的执行顺序

C++中派生类是不会继承父类的构造函数和析构函数的,这一点要明确。派生类中构造函数的执行顺序是先父类的构造函数然后当前类,析构函数则相反。举例如下:#include <iostream> using namespace std; class&nb...

C++常量

关于常量的一些形式以及含义在此记录一下:#include <iostream> using namespace std; int main() { //常量,不能改变值 const int a =&n...