initial upload

This commit is contained in:
2024-09-10 20:25:18 +08:00
parent b8de03ee4f
commit f1cc876972
377 changed files with 2721267 additions and 34 deletions

17
archive/xyz2poly/head.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef _HEAD_H
#define _HEAD_H
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define TOPO "-t"
#define PLANE "-h"
#define OUTPUT "-o"
#define XYZ ".dat"
#define RANGE "-r"
using namespace std;
#endif

185
archive/xyz2poly/main.cpp Normal file
View File

@@ -0,0 +1,185 @@
#include "poly_writer.h"
void disp_help()
{
cout<<"xyz2poly 0.0.1 - convert xyz data to tetgen's poly file"<<endl<<endl
<<"usage: xyz2poly input-file -t<depth>|h<depth> -r<xmin>/<dx>/<xmax>/<ymin>/<dy>/<ymax> [-o<output-file>]"<<endl
<<" -t the bottom plane of the output poly file will be made according to the input topograph data"<<endl
<<" -h create a horizational plane as the bottom plane of output poly file"<<endl
<<" -r predefined info about the input file"<<endl
<<" -o specify the output file's name, the input name will be used if -o is absent"<<endl<<endl
<<"example: xyz2poly in.dat -t500 -r0/10/1000/0/10/1000 -otestout.poly"<<endl;
}
int typeget(char *str, const char* str2,string &str3)//提出头端的子句
{
char* strp = strstr(str, str2); // 从字符串str中查找str2
if (strp == NULL)
{
return 0; // 如果没有找到,返回
}
string temp = str;
str3=temp.substr(strlen(str2));//提出除str2外的子句
return 1;
}
int nameget(char *str, const char* str2,string &str3)//提出尾端的子句
{
char* strp = strstr(str, str2); // 从字符串str中查找str2
if (strp == NULL)
{
return 0; // 如果没有找到,返回
}
string temp = str;
str3=temp.substr(0,strlen(str)-strlen(str2));//提出除str2外的子句
return 1;
}
string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //替换str中所有lod_value为new_value,返回被替换的lod_value的个数
{
int count = 0;
for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length()){
if((pos=str.find(old_value,pos))!=string::npos){
str.replace(pos,old_value.length(),new_value);
count++;
}
else break;
}
num = count;
return str;
}
int main(int argc, char* argv[])
{
if (argc==1)
{
disp_help();
}
else if (argc==2)
{
cout<<"too few arguments, program stopped..."<<endl;
}
else
{
int bottom_type=0;
int space_num;
double depth = -1;
double range[6];
string inname = argv[1];
string temp = "";
string outname = "NOOUTNAME";
stringstream stemp;
for (int i = 2; i < argc; i++)
{
if (typeget(argv[i],OUTPUT,temp))
{
if (temp=="")
{
cout<<"no output name, program stopped..."<<endl;
return 0;
}
else
{
outname = temp;
temp="";
}
}
if (typeget(argv[i],TOPO,temp))
{
if (temp=="")
{
cout<<"no depth info, program stopped..."<<endl;
return 0;
}
else
{
stemp.clear();
stemp.str(temp);
stemp>>depth;
bottom_type = 1;
}
}
if (typeget(argv[i],PLANE,temp))
{
if (temp=="")
{
cout<<"no depth info, program stopped..."<<endl;
return 0;
}
else
{
stemp.clear();
stemp.str(temp);
stemp>>depth;
bottom_type = 2;
}
}
if (typeget(argv[i],RANGE,temp))
{
replace_all(temp,"/"," ",space_num);
stemp.clear();
stemp.str(temp);
if (space_num==5)
{
stemp>>range[0]>>range[1]>>range[2]>>range[3]>>range[4]>>range[5];
if (range[0]>range[2]||(range[0]+range[1])>range[2]||(range[0]+2*range[1])>range[2])
{
cout<<"wrong x range, program stopped..."<<endl;
return 0;
}
else if (range[3]>range[5]||(range[3]+range[4])>range[5]||(range[3]+2*range[4])>range[5])
{
cout<<"wrong y range, program stopped..."<<endl;
return 0;
}
}
else
{
cout<<"insufficient attributes information, program stoped..."<<endl;
return 0;
}
}
}
if (bottom_type==0||depth<0)
{
cout<<"commond not found, program stopped..."<<endl;
return 0;
}
if (outname=="NOOUTNAME")
{
nameget(argv[1],XYZ,temp);
outname = temp + ".poly";
temp="";
}
poly_writer p1;
p1.run(inname,outname,bottom_type,depth,range);
//cout<<inname<<" "<<outname<<" "<<bottom_type<<" "<<depth<<endl;
}
return 0;
}
/*
string filename;
cout<<"This program is designed to tranform .grd file into .poly file."<<endl;
cout<<"The format of .grd file should be text grid (Surfer 6)."<<endl;
cout<<"***************************************************************"<<endl;
cout<<"gird file's name:";
cin>>filename;
poly_writer p1(filename);
p1.readgrd(filename);
p1.info_taker();
p1.node_writer();
p1.face_writer();
p1.hole_writer();
p1.region_writer();
p1.info_writer(filename);
*/

View File

@@ -0,0 +1,273 @@
#ifndef _POLY_WRITER_H
#define _POLY_WRITER_H
#include "head.h"
class poly_writer
{
public:
poly_writer();
~poly_writer();
int readdat(string);
int poly_plane(string);
int poly_topo(string);
int run(string,string,int,double,double*);
private:
int M,N;
double bottom_depth;
double xmin,xmax,dx,ymin,ymax,dy,zmin,zmax;
double *topo;
};
poly_writer::poly_writer()
{
topo = NULL;
}
poly_writer::~poly_writer()
{
if(topo!=NULL) delete[] topo;
}
int poly_writer::run(string inname,string outname,int bottom_type,double depth,double* Range)
{
bottom_depth = depth;
xmin = *Range; dx = *(Range+1); xmax = *(Range+2);
ymin = *(Range+3); dy = *(Range+4); ymax = *(Range+5);
M = (xmax-xmin)/dx+1;
N = (ymax-ymin)/dy+1;
xmax = xmin+(M-1)*dx;
ymax = ymin+(N-1)*dy;
if (readdat(inname)) return 1;
if (bottom_type==1)
{
if (poly_topo(outname)) return 1;
}
else if (bottom_type==2)
{
if (poly_plane(outname)) return 1;
}
return 0;
}
int poly_writer::readdat(string filename)
{
const char* openname = filename.c_str();
ifstream infile(openname);
if (!infile)
{
cout<<filename<<" not found, program stopped..."<<endl;
return 1;
}
else
{
double temp;
topo = new double [M*N];
zmin = 1e20; zmax = -1e20;
for (int i = 0; i < M*N; i++)
{
infile>>temp>>temp>>topo[i];
if (zmin>topo[i]) zmin = topo[i];
if (zmax<topo[i]) zmax = topo[i];
}
infile.close();
return 0;
}
}
int poly_writer::poly_plane(string filename)
{
const char* savename = filename.c_str();
ofstream outfile(savename);
if (!outfile)
{
cout<<"can not create "<<filename<<endl;
return 1;
}
else
{
outfile<<"# Part 1 - node list"<<endl;
outfile<<"# node count, 3 dim, no attribute, no boundary marker"<<endl;
outfile<<M*N+4<<" "<<3<<" "<<0<<" "<<0<<endl;
outfile<<"# Node index, node coordinates"<<endl;
for(int i=0;i<M*N;i++)
{
outfile<<i+1<<" "<<xmin+dx*(i%M)<<" "<<ymin+dy*(i/M)<<" "<<topo[i]<<endl;
}
outfile<<M*N+1<<" "<<xmin<<" "<<ymin<<" "<<zmin-bottom_depth<<endl;
outfile<<M*N+2<<" "<<xmin<<" "<<ymax<<" "<<zmin-bottom_depth<<endl;
outfile<<M*N+3<<" "<<xmax<<" "<<ymin<<" "<<zmin-bottom_depth<<endl;
outfile<<M*N+4<<" "<<xmax<<" "<<ymax<<" "<<zmin-bottom_depth<<endl<<endl;
outfile<<"# Part 2 - facet list"<<endl;
outfile<<"# facet count, no boundary marker"<<endl;
outfile<<(M-1)*(N-1)*2+5<<" "<<0<<endl;
outfile<<"# 1 polygon, no hole, no boundary marker"<<endl;
for(int i=1;i<=N-1;i++)
{
for(int j=1;j<=M-1;j++)
{
outfile<<1<<endl<<3<<" "<<(i-1)*M+j<<" "<<(i-1)*M+j+1<<" "<<i*M+j+1<<endl;
}
}
for(int i=N;i>=2;i--)
{
for(int j=M;j>=2;j--)
{
outfile<<1<<endl<<3<<" "<<(i-1)*M+j<<" "<<(i-1)*M+j-1<<" "<<(i-2)*M+j-1<<endl;
}
}
outfile<<1<<endl<<4<<" "<<M*N+1<<" "<<M*N+2<<" "<<M*N+4<<" "<<M*N+3<<endl;
outfile<<1<<endl<<N+2<<" ";
for(int i=1;i<=N;i++)
{
outfile<<(i-1)*M+1<<" ";
}
outfile<<M*N+2<<" "<<M*N+1<<endl;
outfile<<1<<endl<<N+2<<" ";
for(int i=1;i<=N;i++)
{
outfile<<i*M<<" ";
}
outfile<<M*N+4<<" "<<M*N+3<<endl;
outfile<<1<<endl<<M+2<<" ";
for(int i=1;i<=M;i++)
{
outfile<<i<<" ";
}
outfile<<M*N+3<<" "<<M*N+1<<endl;
outfile<<1<<endl<<M+2<<" ";
for(int i=1;i<=M;i++)
{
outfile<<(N-1)*M+i<<" ";
}
outfile<<M*N+4<<" "<<M*N+2<<endl<<endl;
outfile<<"# Part 3 - hole list"<<endl;
outfile<<"0 # no hole"<<endl;
outfile<<"# Part 4 - region list"<<endl;
outfile<<"0 # no region"<<endl;
outfile<<"#generated by xyz2poly "<<filename;
outfile.close();
return 0;
}
}
int poly_writer::poly_topo(string filename)
{
const char* savename = filename.c_str();
ofstream outfile(savename);
if (!outfile)
{
cout<<"can not create "<<filename<<endl;
return 1;
}
else
{
outfile<<"# Part 1 - node list"<<endl;
outfile<<"# node count, 3 dim, no attribute, no boundary marker"<<endl;
outfile<<2*M*N<<" "<<3<<" "<<0<<" "<<0<<endl;
outfile<<"# Node index, node coordinates"<<endl;
for(int i=0;i<M*N;i++)
{
outfile<<i+1<<" "<<xmin+dx*(i%M)<<" "<<ymin+dy*(i/M)<<" "<<topo[i]<<endl;
}
for(int i=0;i<M*N;i++)
{
outfile<<M*N+i+1<<" "<<xmin+dx*(i%M)<<" "<<ymin+dy*(i/M)<<" "<<topo[i]-bottom_depth<<endl;
}
outfile<<endl<<"# Part 2 - facet list"<<endl;
outfile<<"# facet count, no boundary marker"<<endl;
outfile<<(M-1)*(N-1)*4+4<<" "<<0<<endl;
outfile<<"# 1 polygon, no hole, no boundary marker"<<endl;
for(int i=1;i<=N-1;i++)
{
for(int j=1;j<=M-1;j++)
{
outfile<<1<<endl<<3<<" "<<(i-1)*M+j<<" "<<(i-1)*M+j+1<<" "<<i*M+j+1<<endl;
}
}
for(int i=N;i>=2;i--)
{
for(int j=M;j>=2;j--)
{
outfile<<1<<endl<<3<<" "<<(i-1)*M+j<<" "<<(i-1)*M+j-1<<" "<<(i-2)*M+j-1<<endl;
}
}
for(int i=1;i<=N-1;i++)
{
for(int j=1;j<=M-1;j++)
{
outfile<<1<<endl<<3<<" "<<M*N+(i-1)*M+j<<" "<<M*N+(i-1)*M+j+1<<" "<<M*N+i*M+j+1<<endl;
}
}
for(int i=N;i>=2;i--)
{
for(int j=M;j>=2;j--)
{
outfile<<1<<endl<<3<<" "<<M*N+(i-1)*M+j<<" "<<M*N+(i-1)*M+j-1<<" "<<M*N+(i-2)*M+j-1<<endl;
}
}
outfile<<1<<endl<<N*2<<" ";
for(int i=1;i<=N;i++)
{
outfile<<(i-1)*M+1<<" ";
}
for(int i=N;i>=1;i--)
{
outfile<<M*N+(i-1)*M+1<<" ";
}
outfile<<endl;
outfile<<1<<endl<<N*2<<" ";
for(int i=1;i<=N;i++)
{
outfile<<i*M<<" ";
}
for(int i=N;i>=1;i--)
{
outfile<<M*N+i*M<<" ";
}
outfile<<endl;
outfile<<1<<endl<<M*2<<" ";
for(int i=1;i<=M;i++)
{
outfile<<i<<" ";
}
for(int i=M;i>=1;i--)
{
outfile<<M*N+i<<" ";
}
outfile<<endl;
outfile<<1<<endl<<M*2<<" ";
for(int i=1;i<=M;i++)
{
outfile<<(N-1)*M+i<<" ";
}
for(int i=M;i>=1;i--)
{
outfile<<M*N+(N-1)*M+i<<" ";
}
outfile<<endl<<endl;
outfile<<"# Part 3 - hole list"<<endl;
outfile<<"0 # no hole"<<endl;
outfile<<"# Part 4 - region list"<<endl;
outfile<<"0 # no region"<<endl;
outfile<<"#generated by xyz2poly "<<filename;
outfile.close();
return 0;
}
}
#endif