From 0e813d878b7fd856a73f26fd4fff0cbe12536141 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 9 Jan 1998 23:03:05 +0000 Subject: [PATCH] Restructured to split 1deg x 1deg dem's into 64 subsections. --- FixNode/fixnode.c | 22 ++++++++++------ FixNode/main.c | 67 ++++++++++++++++++++++++++++++++++++++++------- FixNode/triload.c | 35 +++++++------------------ FixNode/triload.h | 9 ++++--- FixObj/main.c | 18 +++++++++---- FixObj/obj.c | 32 ++++++++++------------ FixObj/obj.h | 9 ++++--- Tools/README | 18 ++++++++----- Tri2obj/depend | 7 ++--- Tri2obj/tri2obj.c | 16 +++++------ Triangle/Makefile | 2 +- 11 files changed, 145 insertions(+), 90 deletions(-) diff --git a/FixNode/fixnode.c b/FixNode/fixnode.c index d3feb16c5..8c3aee33a 100644 --- a/FixNode/fixnode.c +++ b/FixNode/fixnode.c @@ -26,6 +26,7 @@ #include #include +#include #include "fixnode.h" #include "../Dem2node/mesh.h" @@ -33,8 +34,8 @@ /* load the node information */ -void fixnodes(char *basename, struct MESH *m) { - char file[256]; +void fixnodes(char *filename, struct MESH *m) { + char toname[256]; FILE *fd; int i; @@ -55,12 +56,14 @@ void fixnodes(char *basename, struct MESH *m) { nodes[i][1], nodes[i][2]); */ } - strcpy(file, basename); - strcat(file, ".1.node"); - printf("Overwriting original node file: %s\n", file); + sprintf(toname, "%s.orig", filename); + printf("Moving %s to %s\n", filename, toname); + rename(filename, toname); - fd = fopen(file, "w"); + printf("Saving new node file: %s\n", filename); + + fd = fopen(filename, "w"); fprintf(fd, "%d 2 1 0\n", nodecount); @@ -74,9 +77,12 @@ void fixnodes(char *basename, struct MESH *m) { /* $Log$ -/* Revision 1.2 1997/12/02 13:12:07 curt -/* Updated to fix every node. +/* Revision 1.3 1998/01/09 23:03:08 curt +/* Restructured to split 1deg x 1deg dem's into 64 subsections. /* + * Revision 1.2 1997/12/02 13:12:07 curt + * Updated to fix every node. + * * Revision 1.1 1997/11/27 00:17:33 curt * Initial revision. * diff --git a/FixNode/main.c b/FixNode/main.c index 7ebd5d7e5..002c495cf 100644 --- a/FixNode/main.c +++ b/FixNode/main.c @@ -24,36 +24,85 @@ */ +#include #include #include +#include #include "../Dem2node/demparse.h" #include "fixnode.h" #include "triload.h" +/* Original DEM which is used to interpolate z values */ +struct MESH dem_mesh; + + +/* find all the matching files in the specified directory and fix them */ +void process_files(char *root_path) { + DIR *d; + struct dirent *de; + char file_path[256]; + char *ptr; + int len; + + if ( (d = opendir(root_path)) == NULL ) { + printf("cannot open directory '%s'.", root_path); + exit(-1); + } + + while ( (de = readdir(d)) != NULL ) { + len = strlen(de->d_name); + if ( len > 7 ) { + ptr = de->d_name; + ptr += (len - 7); + /* printf("--> %s \n", ptr); */ + + if ( strcmp(ptr, ".1.node") == 0 ) { + strcpy(file_path, root_path); + strcat(file_path, "/"); + strcat(file_path, de->d_name); + printf("File = %s\n", file_path); + + /* load the input data files */ + triload(file_path); + + fixnodes(file_path, &dem_mesh); + } + } + } +} + + +/* main */ int main(int argc, char **argv) { - char basename[256]; - struct MESH dem_mesh; + char demfile[256], root_path[256]; - strcpy(basename, argv[1]); + if ( argc != 3 ) { + printf("Usage %s demfile root_path\n", argv[0]); + exit(-1); + } - /* load the input data files */ - triload(basename); + strcpy(demfile, argv[1]); + strcpy(root_path, argv[2]); /* load the corresponding dem file so we can interpolate elev values */ - dem_parse(basename, &dem_mesh); + dem_parse(demfile, &dem_mesh); - fixnodes(basename, &dem_mesh); + /* process all the *.1.node files in the specified directory */ + process_files(root_path); return(0); } /* $Log$ -/* Revision 1.2 1997/12/02 13:12:07 curt -/* Updated to fix every node. +/* Revision 1.3 1998/01/09 23:03:08 curt +/* Restructured to split 1deg x 1deg dem's into 64 subsections. /* + * Revision 1.2 1997/12/02 13:12:07 curt + * Updated to fix every node. + * * Revision 1.1 1997/11/27 00:17:34 curt * Initial revision. * diff --git a/FixNode/triload.c b/FixNode/triload.c index 2d6d670d7..f0510bd27 100644 --- a/FixNode/triload.c +++ b/FixNode/triload.c @@ -30,37 +30,19 @@ #include "triload.h" -int origcount; int nodecount; double nodes[MAX_NODES][3]; /* load the node information */ -void triload(char *basename) { - char origname[256], nodename[256]; - FILE *orig, *node; +void triload(char *filename) { + FILE *node; int dim, junk1, junk2; int i; - strcpy(origname, basename); - strcat(origname, ".node"); - - strcpy(nodename, basename); - strcat(nodename, ".1.node"); - - /* open original node file to see number of original nodes */ - - printf("Checking original node file: %s ...\n", origname); - if ( (orig = fopen(origname, "r")) == NULL ) { - printf("Cannot open file '%s'\n", origname); - exit(-1); - } - fscanf(orig, "%d %d %d %d", &origcount, &dim, &junk1, &junk2); - printf(" Found %d nodes\n", origcount); - - printf("Loading node file: %s ...\n", nodename); - if ( (node = fopen(nodename, "r")) == NULL ) { - printf("Cannot open file '%s'\n", nodename); + printf("Loading node file: %s ...\n", filename); + if ( (node = fopen(filename, "r")) == NULL ) { + printf("Cannot open file '%s'\n", filename); exit(-1); } @@ -85,7 +67,10 @@ void triload(char *basename) { /* $Log$ -/* Revision 1.1 1997/11/27 00:17:35 curt -/* Initial revision. +/* Revision 1.2 1998/01/09 23:03:09 curt +/* Restructured to split 1deg x 1deg dem's into 64 subsections. /* + * Revision 1.1 1997/11/27 00:17:35 curt + * Initial revision. + * */ diff --git a/FixNode/triload.h b/FixNode/triload.h index 058c01869..2d84f8e74 100644 --- a/FixNode/triload.h +++ b/FixNode/triload.h @@ -36,7 +36,7 @@ #define MAX_TRIS 400000 -extern int origcount, nodecount, tricount; +extern int nodecount, tricount; double nodes[MAX_NODES][3]; @@ -48,7 +48,10 @@ void triload(char *basename); /* $Log$ -/* Revision 1.1 1997/11/27 00:17:35 curt -/* Initial revision. +/* Revision 1.2 1998/01/09 23:03:09 curt +/* Restructured to split 1deg x 1deg dem's into 64 subsections. /* + * Revision 1.1 1997/11/27 00:17:35 curt + * Initial revision. + * */ diff --git a/FixObj/main.c b/FixObj/main.c index 0a499f1f9..bb20a0e37 100644 --- a/FixObj/main.c +++ b/FixObj/main.c @@ -29,19 +29,27 @@ int main(int argc, char **argv) { - char basename[256]; + char infile[256], outfile[256]; - strcpy(basename, argv[1]); + if ( argc != 3 ) { + printf("Usage %s: infile outfile\n", argv[0]); + } + + strcpy(infile, argv[1]); + strcpy(outfile, argv[2]); /* load the input data files */ - obj_fix(basename); + obj_fix(infile, outfile); return(0); } /* $Log$ -/* Revision 1.1 1997/12/08 19:28:54 curt -/* Initial revision. +/* Revision 1.2 1998/01/09 23:03:12 curt +/* Restructured to split 1deg x 1deg dem's into 64 subsections. /* + * Revision 1.1 1997/12/08 19:28:54 curt + * Initial revision. + * */ diff --git a/FixObj/obj.c b/FixObj/obj.c index 55201f0fd..19b87d4b1 100644 --- a/FixObj/obj.c +++ b/FixObj/obj.c @@ -63,7 +63,7 @@ void list_add(int *list, int *list_ptr, int node) { list[*list_ptr] = node; *list_ptr += 1; - printf("list pointer = %d adding %d\n", *list_ptr, node); + /* printf("list pointer = %d adding %d\n", *list_ptr, node); */ } @@ -84,7 +84,7 @@ void dump_list(int *list, int list_ptr) { /* dump header */ fprintf(out, "t %d %d %d\n", list[i], list[i+1], list[i+2]); - printf("t %d %d %d\n", list[i], list[i+1], list[i+2]); + /* printf("t %d %d %d\n", list[i], list[i+1], list[i+2]); */ i += 3; /* dump rest of strip (until -1) */ @@ -139,26 +139,19 @@ double check_cur_face(int n1, int n2, int n3) { /* Load a .obj file */ -void obj_fix(char *basename) { +void obj_fix(char *infile, char *outfile) { char line[256]; - char inpath[256], outpath[256]; double dot_prod; int first, ncount, vncount, n1, n2, n3, n4; int is_ccw; - strcpy(inpath, basename); - strcat(inpath, ".obj"); - - strcpy(outpath, basename); - strcat(outpath, ".1.obj"); - - if ( (in = fopen(inpath, "r")) == NULL ) { - printf("Cannot open file: %s\n", inpath); + if ( (in = fopen(infile, "r")) == NULL ) { + printf("Cannot open file: %s\n", infile); exit(-1); } - if ( (out = fopen(outpath, "w")) == NULL ) { - printf("Cannot open file: %s\n", outpath); + if ( (out = fopen(outfile, "w")) == NULL ) { + printf("Cannot open file: %s\n", outfile); exit(-1); } @@ -169,7 +162,7 @@ void obj_fix(char *basename) { ncount = 1; vncount = 1; - printf("Reading file: %s\n", inpath); + printf("Reading file: %s\n", infile); while ( fgets(line, 250, in) != NULL ) { if ( line[0] == '#' ) { @@ -274,7 +267,7 @@ void obj_fix(char *basename) { } } } else { - printf("Unknown line in %s = %s\n", inpath, line); + printf("Unknown line in %s = %s\n", infile, line); } } @@ -290,7 +283,10 @@ void obj_fix(char *basename) { /* $Log$ -/* Revision 1.1 1997/12/08 19:28:54 curt -/* Initial revision. +/* Revision 1.2 1998/01/09 23:03:12 curt +/* Restructured to split 1deg x 1deg dem's into 64 subsections. /* + * Revision 1.1 1997/12/08 19:28:54 curt + * Initial revision. + * */ diff --git a/FixObj/obj.h b/FixObj/obj.h index c0ecf801c..54689de06 100644 --- a/FixObj/obj.h +++ b/FixObj/obj.h @@ -36,14 +36,17 @@ extern int stack[MAXNODES]; /* Load a .obj file */ -void obj_fix(char *basename); +void obj_fix(char *infile, char *outfile); #endif /* OBJ_H */ /* $Log$ -/* Revision 1.1 1997/12/08 19:28:55 curt -/* Initial revision. +/* Revision 1.2 1998/01/09 23:03:13 curt +/* Restructured to split 1deg x 1deg dem's into 64 subsections. /* + * Revision 1.1 1997/12/08 19:28:55 curt + * Initial revision. + * */ diff --git a/Tools/README b/Tools/README index 21133e438..fa4bf7290 100644 --- a/Tools/README +++ b/Tools/README @@ -1,15 +1,19 @@ 1. Start with file.dem -2. dem2node file tolerance^2 (meters) +2. dem2node file.dem tolerance^2 (meters) - - dem2node file 160000 + - dem2node file.dem 160000 -3. fixnode file.1 +3. triangle -q file -4. tri2obj file.1 +4. fixnode file -5. strip file.1.obj +5. tri2obj file.1 -6. cp bands.d file.new.obj +6. strip file.1.obj -7. fixobj file.new +7. cp bands.d file-new.obj + +8. fixobj file-new + +9. cp file-new.1.obj .../Scenery/... diff --git a/Tri2obj/depend b/Tri2obj/depend index 5e652e883..73c133713 100644 --- a/Tri2obj/depend +++ b/Tri2obj/depend @@ -1,3 +1,4 @@ -tri2obj.o: tri2obj.c tri2obj.h ../../Src/constants.h ../../Src/types.h \ - ../../Src/Math/fg_geodesy.h ../../Src/Math/mat3.h \ - ../../Src/Math/polar.h ../../Src/Math/../types.h +tri2obj.o: tri2obj.c tri2obj.h ../../Src/Include/constants.h \ + ../../Src/Include/types.h ../../Src/Math/fg_geodesy.h \ + ../../Src/Math/mat3.h ../../Src/Math/polar.h \ + ../../Src/Math/../Include/types.h diff --git a/Tri2obj/tri2obj.c b/Tri2obj/tri2obj.c index 0737899ae..b38b07438 100644 --- a/Tri2obj/tri2obj.c +++ b/Tri2obj/tri2obj.c @@ -29,8 +29,8 @@ #include "tri2obj.h" -#include "../../Src/constants.h" -#include "../../Src/types.h" +#include "../../Src/Include/constants.h" +#include "../../Src/Include/types.h" #include "../../Src/Math/fg_geodesy.h" #include "../../Src/Math/mat3.h" #include "../../Src/Math/polar.h" @@ -234,10 +234,7 @@ void dump_obj(char *basename) { /* dump faces */ printf(" writing faces\n"); for ( i = 1; i <= tricount; i++ ) { - fprintf(obj, "f %d//%d %d//%d %d//%d\n", - tris[i][0], tris[i][0], - tris[i][1], tris[i][1], - tris[i][2], tris[i][2]); + fprintf(obj, "f %d %d %d\n", tris[i][0], tris[i][1], tris[i][2]); } fclose(obj); @@ -259,9 +256,12 @@ int main(int argc, char **argv) { /* $Log$ -/* Revision 1.5 1997/12/08 19:17:50 curt -/* Fixed a type in the normal generation code. +/* Revision 1.6 1998/01/09 23:03:15 curt +/* Restructured to split 1deg x 1deg dem's into 64 subsections. /* + * Revision 1.5 1997/12/08 19:17:50 curt + * Fixed a type in the normal generation code. + * * Revision 1.4 1997/12/02 13:13:32 curt * Fixed problem with averaged vertex normals. * diff --git a/Triangle/Makefile b/Triangle/Makefile index 66afd63cd..cccdf2b1c 100644 --- a/Triangle/Makefile +++ b/Triangle/Makefile @@ -83,7 +83,7 @@ TRILIBDEFS = -DTRILIBRARY # RM should be set to the name of your favorite rm (file deletion program). -RM = /bin/rm +RM = /bin/rm -f # The action starts here. -- 2.39.2