initial upload

This commit is contained in:
2024-09-10 16:01:52 +08:00
commit f4bfeb6cf8
56 changed files with 49192 additions and 0 deletions

2196
archived/QdTree_Icosa.h Normal file

File diff suppressed because it is too large Load Diff

476
archived/dataStruct.h Normal file
View File

@@ -0,0 +1,476 @@
#ifndef _DATASTRUCT_H
#define _DATASTRUCT_H
#include "sysDefine.h"
//直角坐标系下的一个点
struct cpoint
{
double x,y,z;
cpoint() //初始化坐标值
{
x = y = z = MAX_DBL;
}
};
typedef vector<cpoint> cpointArray;
//直角坐标点的一些数学运算
cpoint operator -(cpoint a, cpoint b)
{
cpoint m;
m.x=a.x-b.x;
m.y=a.y-b.y;
m.z=a.z-b.z;
return m;
}
cpoint operator +(cpoint a, cpoint b) //矢量加法
{
cpoint m;
m.x=a.x+b.x;
m.y=a.y+b.y;
m.z=a.z+b.z;
return m;
}
cpoint operator *(double sign,cpoint b) //矢量乘法
{
cpoint m;
m.x=sign*b.x;
m.y=sign*b.y;
m.z=sign*b.z;
return m;
}
//重载逻辑等操作符作用于矢量,判断两个直角点是否相等
bool operator ==(cpoint a, cpoint b)
{
if(fabs(a.x-b.x)<ZERO&&fabs(a.y-b.y)<ZERO&&fabs(a.z-b.z)<ZERO)
{
return 1;
}
else return 0;
}
double dot(cpoint a, cpoint b) //矢量点乘
{
return a.x*b.x+a.y*b.y+a.z*b.z;
}
cpoint cross(cpoint a,cpoint b) //矢量叉乘
{
cpoint v;
v.x = a.y*b.z-a.z*b.y;
v.y = a.z*b.x-a.x*b.z;
v.z = a.x*b.y-a.y*b.x;
return v;
}
//返回两个直角坐标点的中点位置
cpoint middle_cpoint(cpoint a,cpoint b)
{
cpoint c;
c.x = 0.5*(a.x + b.x);
c.y = 0.5*(a.y + b.y);
c.z = 0.5*(a.z + b.z);
return c;
}
//返回两点之间的一个点 以第一个点为参考点 第三个参数为相对于原线段的比例
cpoint scale_cpoint(cpoint a,cpoint b,double scale)
{
cpoint c;
c.x = a.x + (b.x - a.x)*scale;
c.y = a.y + (b.y - a.y)*scale;
c.z = a.z + (b.z - a.z)*scale;
return c;
}
cpoint rescale_cpoint(cpoint a,double refr)
{
cpoint c;
double m = sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
c.x = a.x*refr/m;
c.y = a.y*refr/m;
c.z = a.z*refr/m;
return c;
}
double length_cpoint(cpoint v) //矢量模
{
return sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
}
double distance_cpoint(cpoint a, cpoint b)
{
cpoint m;
double d;
m.x=a.x-b.x;
m.y=a.y-b.y;
m.z=a.z-b.z;
d = sqrt(m.x*m.x + m.y*m.y + m.z*m.z);
return d;
}
//计算两个向量的夹角
double cpoint_angle(cpoint a,cpoint b)
{
return acos((a.x*b.x+a.y*b.y+a.z*b.z)/(sqrt(a.x*a.x+a.y*a.y+a.z*a.z)*sqrt(b.x*b.x+b.y*b.y+b.z*b.z)))*180.0/pi;
}
//求三角形中心坐标
cpoint Tri_center(cpoint vec1,cpoint vec2,cpoint vec3)
{
cpoint c;
c.x = (vec1.x+vec2.x+vec3.x)/3.0;
c.y = (vec1.y+vec2.y+vec3.y)/3.0;
c.z = (vec1.z+vec2.z+vec3.z)/3.0;
return c;
}
//球坐标系下的一个点
struct spoint
{
double lon,lat,rad;
spoint() //初始化坐标值
{
lon = lat = rad = MAX_DBL;
}
};
typedef vector<spoint> spointArray;
/*直角坐标与球坐标相互转换函数 注意这里使用的球坐标是地理坐标范围 即经度为-180~180 纬度为-90~90*/
cpoint s2c(spoint s)
{
cpoint c;
c.x = s.rad*sin((0.5 - s.lat/180.0)*pi)*cos((2.0 + s.lon/180.0)*pi);
c.y = s.rad*sin((0.5 - s.lat/180.0)*pi)*sin((2.0 + s.lon/180.0)*pi);
c.z = s.rad*cos((0.5 - s.lat/180.0)*pi);
return c;
}
spoint c2s(cpoint c)
{
spoint s;
s.rad = sqrt(pow(c.x,2)+pow(c.y,2)+pow(c.z,2));
if (fabs(s.rad)<ZERO) //点距离原点极近 将点置于原点
{
s.lat = s.lon = s.rad = 0.0;
}
else
{
s.lat = 90.0 - acos(c.z/s.rad)*180.0/pi;
s.lon = atan2(c.y,c.x)*180.0/pi;
}
return s;
}
//顶点
struct vertex
{
int id; //索引
cpoint posic; //直角坐标系位置
spoint posis; //球坐标系位置
vertex()
{
id = -1; //初始化顶点索引值为-1 这里不需要初始化坐标位置 因为已经由相应的初始化函数完成了初始化
}
void set(int i) //设置索引值
{
id = i;
}
void set(cpoint c) //从直角坐标位置初始化
{
posic.x = c.x; posic.y = c.y; posic.z = c.z;
posis = c2s(posic);
}
void set(spoint s) //从球坐标位置初始化
{
posis.lon = s.lon; posis.lat = s.lat; posis.rad = s.rad;
posic = s2c(posis);
}
void info() //显示顶点信息
{
cout << id << " " << setprecision(16) << posic.x << " " << posic.y << " " << posic.z << " " << posis.lon << " " << posis.lat << " " << posis.rad << endl;
}
};
typedef vector<vertex> vertexArray;
typedef map<int,vertex> idMap; //顶点索引值映射 用于通过索引值寻找相应顶点
typedef map<string,vertex> strMap; //顶点位置映射 用于通过顶点位置寻找相应顶点
typedef map<int,int> outIdMap; //输出msh文件时重新索引三角形顶点集
//计算一个顶点向量的中点
cpoint middle_vertex(vertexArray vert)
{
cpoint c;
c.x = 0; c.y = 0; c.z = 0;
if (!vert.empty())
{
for (int i = 0; i < vert.size(); i++)
{
c.x += vert.at(i).posic.x;
c.y += vert.at(i).posic.y;
c.z += vert.at(i).posic.z;
}
c.x /= vert.size();
c.y /= vert.size();
c.z /= vert.size();
}
return c;
}
/*旋转顶点的方位
旋转的方式为首先绕着x轴旋转 然后绕着z轴旋转
给出参考点的原位置olda与新位置newa以获取旋转参数 然后求取输入点oldb做相同旋转后的新坐标newb
*/
vertex rotate_vertex(vertex olda,vertex newa,vertex oldb)
{
vertex newb;
vertex temp_ref,temp_b;
double yz_angle = (newa.posis.lat - olda.posis.lat)*pi/180.0;
//首先绕olda.lon即x轴旋转oldb
temp_b.posic.x = oldb.posic.x;
temp_b.posic.y = oldb.posic.y*cos(-1.0*yz_angle)+oldb.posic.z*sin(-1.0*yz_angle);
temp_b.posic.z = oldb.posic.z*cos(-1.0*yz_angle)-oldb.posic.y*sin(-1.0*yz_angle);
temp_b.set(temp_b.posic);
//计算绕x轴旋转后olda的位置 这是后一步旋转需要的参考值
temp_ref.posic.x = olda.posic.x;
temp_ref.posic.y = olda.posic.y*cos(-1.0*yz_angle)+olda.posic.z*sin(-1.0*yz_angle);
temp_ref.posic.z = olda.posic.z*cos(-1.0*yz_angle)-olda.posic.y*sin(-1.0*yz_angle);
temp_ref.set(temp_ref.posic);
//注意绕z轴旋转的经度参考位置为olda绕x轴旋转后的经度值
double xy_angle = (newa.posis.lon - temp_ref.posis.lon)*pi/180.0;
//绕z轴旋转temp_b z值不变
newb.id = oldb.id;
newb.posic.x = temp_b.posic.x*cos(-1.0*xy_angle)+temp_b.posic.y*sin(-1.0*xy_angle);
newb.posic.y = temp_b.posic.y*cos(-1.0*xy_angle)-temp_b.posic.x*sin(-1.0*xy_angle);
newb.posic.z = temp_b.posic.z;
newb.set(newb.posic);
return newb;
}
//点 点包含索引和一个顶点
struct point
{
int id;
int maxDepth;
double minDeg;
int physic;
vertex vert;
point()
{
id = -1;
maxDepth = -1;
minDeg = -1.0;
}
void info()
{
cout << id << " " << maxDepth << " " << minDeg << endl;
vert.info();
}
};
typedef vector<point> pointArray;
//折线 折线包含索引和一个顶点向量 顶点从前向后连成折线
struct line
{
int id;
int maxDepth;
double minDeg;
int physic;
vertexArray vert;
line()
{
id = -1;
maxDepth = -1;
minDeg = -1.0;
}
void info()
{
cout << id << " " << maxDepth << " " << minDeg << endl;
for (int i = 0; i < vert.size(); i++)
{
vert.at(i).info();
}
}
void clear_vert()
{
if (!vert.empty()) vert.clear();
}
};
typedef vector<line> lineArray;
//多边形 多边形包含索引和一个顶点向量 顶点逆时针连成多边形 注意多边形第一个点和最后一个点应该一致
struct polygon
{
int id;
int maxDepth;
double minDeg;
int physic;
vertexArray vert;
polygon()
{
id = -1;
maxDepth = -1;
minDeg = -1.0;
}
void info()
{
cout << id << " " << maxDepth << " " << minDeg << endl;
for (int i = 0; i < vert.size(); i++)
{
vert.at(i).info();
}
}
void clear_vert()
{
if (!vert.empty()) vert.clear();
}
};
typedef vector<polygon> polygonArray;
//圆形
struct circle
{
int id;
int maxDepth;
double minDeg;
double radDeg;
int physic;
vertex cen;
};
typedef vector<circle> circleArray;
//三角形信息结构体,包含三角形的三个顶点索引,逆时针排序
struct triangle
{
int ids[3];//三角形顶点
int physic; //三角形的物理属性组
triangle() //初始化顶点索引
{
physic = 0; //默认的物理属性组为0
ids[0] = ids[1] = ids[2] = -1;
}
};
typedef vector<triangle> triangleArray;
//平面参数结构体
struct planePara
{
double A,B,C,D;
planePara()
{
A = B = C = D = MAX_DBL;
}
};
//矢量与平面的交点
cpoint lineOnPlane(cpoint c,cpoint normal,cpoint p)
{
cpoint m;
m.x = 0; m.y = 0; m.z = 0;
double t;
if (dot(normal,p) != 0) //平面与矢量平行
{
t = dot(normal,c)/dot(normal,p);
m.x += p.x*t;
m.y += p.y*t;
m.z += p.z*t;
}
return m;
}
//正二十面体结构体,包含正二十面体的十二个顶点和二十个面的顶点索引,三角面索引按逆时针排序
struct Icosa
{
vertex vert[12];
triangle tri[20];
};
//四叉树节点结构体,这是整个算法中最重要的结构体包含一个指向triangle的指针和指向四个子节点的指针
struct Qdtree_node
{
int id;//节点的编号
int outId;//节点在文件输出时候的id 这个id会在return_leaf函数中确定
int depth;//节点深度
bool outOK; //节点是否可以被输出
triangle* tri;//节点三角形顶点索引 逆时针
Qdtree_node* children[4];//四个子节点指针
Qdtree_node() //初始化变量值
{
id = -1;
depth = -1;
outOK = true;
children[0] = children[1] = children[2] = children[3] = NULL;
tri = new triangle;
}
void info()
{
cout << id << endl;
cout << depth << endl;
cout << outOK << endl;
cout << tri->ids[0] << " " << tri->ids[1] << " " << tri->ids[2] << endl;
}
};
//四叉树结构
struct Qdtree
{
Qdtree_node *root;//根节点
};
/*
// 在现行的代码中 我们不再使用平面投影算法 因此不再需要使用以下的数据类型与函数
struct point2d
{
double x,y;
point2d()
{
x = y = MAX_DBL;
}
};
//由三个顶点计算平面参数
planePara get_planePara(cpoint v1,cpoint v2,cpoint v3)
{
planePara pl;
pl.A = (v2.y - v1.y)*(v3.z - v1.z) - (v3.y - v1.y)*(v2.z - v1.z);
pl.B = (v2.z - v1.z)*(v3.x - v1.x) - (v3.z - v1.z)*(v2.x - v1.x);
pl.C = (v2.x - v1.x)*(v3.y - v1.y) - (v3.x - v1.x)*(v2.y - v1.y);
pl.D = -1.0*(pl.A*v1.x + pl.B*v1.y + pl.C*v1.z);
return pl;
}
//点在平面上的投影
vertex dotOnPlane(planePara pl,vertex v)
{
vertex m;
double t = (pl.A*v.posic.x + pl.B*v.posic.y + pl.C*v.posic.z + pl.D)/(pl.A*pl.A + pl.B*pl.B + pl.C*pl.C);
m.posic.x = v.posic.x - pl.A*t;
m.posic.y = v.posic.y - pl.B*t;
m.posic.z = v.posic.z - pl.C*t;
m.set(m.posic);
return m;
}
//以平面内一条直线为x轴 起点为原点 计算另一个点到新的坐标系内的坐标值
point2d newXY(vertex v1,vertex v2,vertex v3,vertex p)
{
point2d p2d;
vertex m,ap;
cpoint dir_map,dir_v123;
m.posic = v2.posic - v1.posic;
ap.posic = p.posic - v1.posic;
//因为cos函数在这种情况下自动可以区分正负情况 所以x值的计算比较简单
p2d.x = dot(ap.posic,m.posic)/length_cpoint(m.posic);
//下面我们来计算y值 相对比较麻烦 首先计算一下距离
p2d.y = sqrt(pow(length_cpoint(ap.posic),2) - p2d.x*p2d.x);
//计算一下三角形的外向法矢量 m与ap的法矢量
dir_v123 = cross(v2.posic-v1.posic,v3.posic-v1.posic);
dir_map = cross(v2.posic-v1.posic,ap.posic);
//如果两个向量同向则y值为正 否则为负
if (dot(dir_v123,dir_map) < 0) p2d.y *= -1.0;
return p2d;
}
*/
#endif

21
archived/main.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include "QdTree_Icosa.h"
int main(int argc, char* argv[])
{
char para[1024];
QdTree_Icosa q;
if (argc == 1)
{
strcpy(para,"NULL");
q.runtine(para);
}
else
{
for (int i = 1; i < argc; i++)
{
strcpy(para,argv[i]);
q.runtine(para);
}
}
return 0;
}

154
archived/progressBar_imp.h Normal file
View File

@@ -0,0 +1,154 @@
#ifndef _PROGRESS_BAR_
#define _PROGRESS_BAR_
//#ifdef _WINDOWS
//#include <windows.h>
//#else
//#include <sys/ioctl.h>
//#endif
#include <sys/ioctl.h>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <thread>
#include <chrono>
#define TOTAL_PERCENTAGE 100.0
#define CHARACTER_WIDTH_PERCENTAGE 4
class ProgressBar
{
public:
ProgressBar();
ProgressBar(unsigned long n_, const char *description_="", std::ostream& out_=std::cerr);
void SetFrequencyUpdate(unsigned long frequency_update_);
void SetStyle(const char* unit_bar_, const char* unit_space_);
void Progressed(unsigned long idx_);
private:
unsigned long n;
unsigned int desc_width;
unsigned long frequency_update;
std::ostream* out;
const char *description;
const char *unit_bar;
const char *unit_space;
void ClearBarField();
int GetConsoleWidth();
int GetBarLength();
};
ProgressBar::ProgressBar() {}
ProgressBar::ProgressBar(unsigned long n_, const char* description_, std::ostream& out_){
n = n_;
frequency_update = n_;
description = description_;
out = &out_;
unit_bar = "\u2588";
unit_space = "-";
desc_width = std::strlen(description); // character width of description field
}
void ProgressBar::SetFrequencyUpdate(unsigned long frequency_update_){
if(frequency_update_ > n){
frequency_update = n; // prevents crash if freq_updates_ > n_
}
else{
frequency_update = frequency_update_;
}
}
void ProgressBar::SetStyle(const char* unit_bar_, const char* unit_space_){
unit_bar = unit_bar_;
unit_space = unit_space_;
}
int ProgressBar::GetConsoleWidth(){
int width;
#ifdef _WINDOWS
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
width = csbi.srWindow.Right - csbi.srWindow.Left;
#else
struct winsize win;
ioctl(0, TIOCGWINSZ, &win);
width = win.ws_col;
#endif
return width;
}
int ProgressBar::GetBarLength(){
// get console width and according adjust the length of the progress bar
int bar_length = static_cast<int>((GetConsoleWidth() - desc_width - CHARACTER_WIDTH_PERCENTAGE) / 2.);
return bar_length;
}
void ProgressBar::ClearBarField(){
for(int i=0;i<GetConsoleWidth();++i){
*out << " ";
}
*out << "\r" << std::flush;
}
void ProgressBar::Progressed(unsigned long idx_)
{
try{
if(idx_ > n) throw idx_;
// determines whether to update the progress bar from frequency_update
if ((idx_ != n-1) && ((idx_+1) % (n/frequency_update) != 0)) return;
// calculate the size of the progress bar
int bar_size = GetBarLength();
// calculate percentage of progress
double progress_percent = idx_* TOTAL_PERCENTAGE/(n-1);
// calculate the percentage value of a unit bar
double percent_per_unit_bar = TOTAL_PERCENTAGE/bar_size;
// display progress bar
*out << " " << description << " |";
for(int bar_length=0;bar_length<=bar_size-1;++bar_length){
if(bar_length*percent_per_unit_bar<progress_percent){
*out << unit_bar;
}
else{
*out << unit_space;
}
}
if(idx_ == n-1)
*out << "|" << std::setw(CHARACTER_WIDTH_PERCENTAGE + 1) << std::setprecision(1) << std::fixed << progress_percent << "%\r" << std::flush << std::endl;
else *out << "|" << std::setw(CHARACTER_WIDTH_PERCENTAGE + 1) << std::setprecision(1) << std::fixed << progress_percent << "%\r" << std::flush;
}
catch(unsigned long e){
ClearBarField();
std::cerr << "PROGRESS_BAR_EXCEPTION: _idx (" << e << ") went out of bounds, greater than n (" << n << ")." << std::endl << std::flush;
}
}
#endif

96
archived/sysDefine.h Normal file
View File

@@ -0,0 +1,96 @@
#ifndef _SYSDEFINE_H
#define _SYSDEFINE_H
#include "iostream"
#include "fstream"
#include "sstream"
#include "string"
#include "cmath"
#include "iomanip"
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "vector"
#include "map"
#include "algorithm"
#include "ctime"
#define MAX_DBL 1.0e+30
#define MIN_BDL -1.0e+30
#define ZERO 1.0e-20
#define pole_radius 6351251.669//WGS84椭球极半径
#define equator_radius 6378137//WGS84椭球长半径
#define pi (4.0*atan(1.0))
#define golden_mean (sqrt(5.0)+1)/2//黄金比例
#define defaultR 1e+5
#define BOLDRED "\033[1m\033[31m"
#define RESET "\033[0m"
using namespace std;
typedef vector<int> _1iArray;
typedef vector<vector<int> > _2iArray;
//操作计时
clock_t start,finish;
//以度计算的正弦函数
inline double sind(double degree)
{
return sin(degree*pi/180.0);
}
//以度计算的余弦函数
inline double cosd(double degree)
{
return cos(degree*pi/180.0);
}
//全局函数
int open_infile(ifstream &infile,char* filename)
{
infile.open(filename);
if (!infile)
{
cerr << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
return -1;
}
return 0;
}
int open_outfile(ofstream &outfile,char* filename)
{
outfile.open(filename);
if (!outfile)
{
cerr << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
return -1;
}
return 0;
}
//计算WGS84椭球半径
double WGS84_r(double lati)
{
return pole_radius*equator_radius/sqrt(pow(pole_radius,2)*pow(cos((double) lati*pi/180.0),2)+pow(equator_radius,2)*pow(sin((double) lati*pi/180.0),2));
}
//计算一个参考椭球或者参考球在纬度位置的半径
double REF_r(double lati,double refr,double refR)
{
return refr*refR/sqrt(pow(refr,2)*pow(cos((double) lati*pi/180.0),2)+pow(refR,2)*pow(sin((double) lati*pi/180.0),2));
}
// 球面双线性插值函数 以度为单位的版本
double SphBiInterp_deg(double CoLat1,double CoLat2,double Lon1,double Lon2,double CoLat0,double Lon0,double h11,double h12,double h21,double h22)
{
double Delta=(Lon2-Lon1)*(cosd(CoLat2)-cosd(CoLat1));
double A=(Lon1*(h12-h22)+Lon2*(h21-h11))/Delta;
double B=(cosd(CoLat1)*(h21-h22)+cosd(CoLat2)*(h12-h11))/Delta;
double C=(h11+h22-h21-h12)/Delta;
double D=(Lon2*cosd(CoLat2)*h11-Lon2*cosd(CoLat1)*h21+Lon1*cosd(CoLat1)*h22-Lon1*cosd(CoLat2)*h12)/Delta;
double h0=A*cosd(CoLat0)+B*Lon0+C*Lon0*cosd(CoLat0)+D;
return h0;
}
#endif

59
archived/template.sh Normal file
View File

@@ -0,0 +1,59 @@
#!/bin/bash
# 从命令行获取块名称
blocknames=$1
# 声明常量
execfile=./bin/Qdtree_icosa.ex
parafile=log.txt
# 正演参数块 名称为forward
if [[ $blocknames == "moho" ]]; then
# 声明程序参数文件内容并通过cat保存在parafile
cat <<- EOF > $parafile
basic-depth=5
max-depth=10
orientation=NULL
extra-points=NULL
extra-lines=NULL
extra-polys=NULL
extra-circles=NULL
outline-polys=NULL
msh-save=d5-globe.msh
sph-save=NULL
EOF
# 运行程序
$execfile $parafile
elif [[ $blocknames == "USA" ]]; then
# 声明程序参数文件内容并通过cat保存在parafile
cat <<- EOF > $parafile
basic-depth=3
max-depth=7
orientation=NULL
extra-points=NULL
extra-lines=NULL
extra-polys=doc/test/china-border.txt
extra-circles=NULL
outline-polys=NULL
msh-save=china.msh
sph-save=NULL
EOF
# 运行程序
$execfile $parafile
elif [[ $blocknames == "test" ]]; then
# 声明程序参数文件内容并通过cat保存在parafile
cat <<- EOF > $parafile
basic-depth=6
max-depth=10
orientation=NULL
extra-points=NULL
extra-lines=NULL
extra-polys=NULL
extra-circles=NULL
outline-polys=doc/test/test-outline.txt
msh-save=test-d6.msh
sph-save=NULL
EOF
# 运行程序
$execfile $parafile
fi