#ifndef _FRACTAL_TOPO_H #define _FRACTAL_TOPO_H #include #include #include #include #include #include #include #include #include "ctime" #include "unistd.h" #include "ctype.h" #define max(a,b) a>b?a:b; #define PARA "-p" #define RANGE "-r" #define PREDEFINED "-t" #define GAUSS "-g" #define OUTPUT "-o" #define BOLDRED "\033[1m\033[31m" #define RESET "\033[0m" #define pi (4.0*atan(1.0)) using namespace std; struct posi { double x,y,v; }; //滤波器函数参数组 struct elliFilter { double muX,muY,sigma,theta,Lx,Ly,magnify,rho; }; double sign(double input) { if (input >= 0.0) return 1.0; else return -1.0; } double ElliFilter(int type,double x,double y,elliFilter elf) { double xd,yd,filter; xd = x - elf.muX; yd = y - elf.muY; double xyModule = sqrt(pow(xd,2)+pow(yd,2)+1e-20); double t = sign(yd)*acos(xd/xyModule); double weight = sqrt(pow(elf.Lx*cos(t - elf.theta*pi/180.0),2) + pow(elf.Ly*sin(t - elf.theta*pi/180.0),2)); if(type) //如果type为真则使用arctan构造加权函数 { filter = pi - 2.0*atan(elf.rho*weight*xyModule - elf.rho*elf.sigma); filter = filter/(pi + 2.0*atan(elf.rho*elf.sigma)); } //type为假则使用以e为底的幂函数构造加权函数 else filter = elf.magnify*pow(2.0,-1.0*weight*weight*xyModule*xyModule/(elf.sigma*elf.sigma)); return filter; } class FracTopo { public: FracTopo(); ~FracTopo(); int topo_gener_regular();//生成随机地形 int output_regular();//输出文件 int gauss_filter_regular(); int topo_gener_random(); int output_random(); int gauss_filter_random(); int run(double*,double*,double*,double*,char*); private: double xmin,xmax,dx,ymin,ymax,dy; double ld,lu,rd,ru; int xnum,ynum,order_x,order_y,imax; double H; double randmax; elliFilter filter_N; int ntotal; int random_num; double** topo; double** topo_range; posi* topo_random; int ifarctan; }; FracTopo::FracTopo() { topo = NULL; topo_range = NULL; topo_random = NULL; } FracTopo::~FracTopo() { if (topo!=NULL) { for(int j=0; j