1
0
Fork 0

add --force option to hgtfit.

This option will ignore when loading, and replace when writing the
.fit.gz files.  Very useful when experimenting with different levels of detail.
This commit is contained in:
Peter Sadrozinski 2012-10-18 20:38:52 -04:00
parent 165f7e2481
commit 2dd32d2839

View file

@ -27,6 +27,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@ -108,6 +109,7 @@ Terra::ImportMask *MASK=&default_mask;
Terra::real error_threshold=40.0;
unsigned int min_points=50;
unsigned int point_limit=1000;
bool force=false;
inline int goal_not_met(Terra::GreedySubdivision* mesh)
{
@ -140,22 +142,30 @@ void greedy_insertion(Terra::GreedySubdivision* mesh)
bool endswith(const std::string& s1, const std::string& suffix) {
size_t s1len=s1.size();
size_t sufflen=suffix.size();
if (s1len<sufflen)
if (s1len<sufflen) {
return false;
}
return s1.compare(s1len-sufflen,sufflen,suffix)==0;
}
void fit_file(const SGPath& path) {
SG_LOG(SG_GENERAL, SG_INFO,"Working on file '" << path << "'");
SGPath outPath(path.dir());
outPath.append(path.file_base() + ".fit.gz");
if (!force) {
if (outPath.exists() && (path.modTime() < outPath.modTime())) {
SG_LOG(SG_GENERAL, SG_INFO ,"Skipping " << outPath << ", source " << path << " is older");
return;
}
} else {
if ( outPath.exists() ) {
unlink( outPath.c_str() );
}
}
SGBucket bucket(0,0); // dummy bucket
TGArray inarray(path.dir() + "/" + path.file_base());
@ -189,6 +199,7 @@ void fit_file(const SGPath& path) {
gzprintf(fp,"%+03.8f %+02.8f %0.2f\n",vx,vy,vz);
}
}
delete mesh;
delete DEM;
@ -214,13 +225,16 @@ void walk_path(const SGPath& path) {
}
void usage(char* progname, const std::string& msg) {
if (msg.size()!=0)
if (msg.size()!=0) {
SG_LOG(SG_GENERAL,SG_ALERT, msg);
}
SG_LOG(SG_GENERAL,SG_INFO, "Usage: " << progname << " [options] <file | path to walk>");
SG_LOG(SG_GENERAL,SG_INFO, "\t -h | --help ");
SG_LOG(SG_GENERAL,SG_INFO, "\t -m | --minnodes 50");
SG_LOG(SG_GENERAL,SG_INFO, "\t -x | --maxnodes 1000");
SG_LOG(SG_GENERAL,SG_INFO, "\t -e | --maxerror 40");
SG_LOG(SG_GENERAL,SG_INFO, "\t -f | --force");
SG_LOG(SG_GENERAL,SG_INFO, "\t -v | --version");
SG_LOG(SG_GENERAL,SG_INFO, "");
SG_LOG(SG_GENERAL,SG_INFO, "Algorithm will produce at least <minnodes> fitted nodes, but no");
@ -234,6 +248,8 @@ void usage(char* progname, const std::string& msg) {
SG_LOG(SG_GENERAL,SG_INFO, "The input file must be a .arr.gz file such as that produced");
SG_LOG(SG_GENERAL,SG_INFO, "by demchop or hgtchop utils.");
SG_LOG(SG_GENERAL,SG_INFO, "");
SG_LOG(SG_GENERAL,SG_INFO, "Force will overwrite existing .arr.gz files, even if the input is older");
SG_LOG(SG_GENERAL,SG_INFO, "");
SG_LOG(SG_GENERAL,SG_INFO, "**** NOTE ****:");
SG_LOG(SG_GENERAL,SG_INFO, "If a directory is input all .arr.gz files in directory will be");
SG_LOG(SG_GENERAL,SG_INFO, "processed recursively.");
@ -248,6 +264,7 @@ struct option options[]={
{"minnodes",required_argument,NULL,'m'},
{"maxnodes",required_argument,NULL,'x'},
{"maxerror",required_argument,NULL,'e'},
{"force",no_argument,NULL,'f'},
{"version",no_argument,NULL,'v'},
{NULL,0,NULL,0}
};
@ -270,6 +287,9 @@ int main(int argc, char** argv) {
case 'e':
error_threshold=atof(optarg);
break;
case 'f':
force=true;
break;
case 'v':
SG_LOG(SG_GENERAL,SG_INFO,argv[0] << " Version 1.0");
exit(0);
@ -279,9 +299,11 @@ int main(int argc, char** argv) {
exit(1);
}
}
SG_LOG(SG_GENERAL, SG_INFO, "Min points = " << min_points);
SG_LOG(SG_GENERAL, SG_INFO, "Max points = " << point_limit);
SG_LOG(SG_GENERAL, SG_INFO, "Max error = " << error_threshold);
if (optind<argc) {
while (optind<argc) {
walk_path(SGPath(argv[optind++]));