gctl_toolkits/archive/xyz2poly/main.cpp

186 lines
4.5 KiB
C++
Raw Normal View History

2024-09-10 20:25:18 +08:00
#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);
*/