]> git.mxchange.org Git - flightgear.git/commitdiff
Restructured to split 1deg x 1deg dem's into 64 subsections.
authorcurt <curt>
Fri, 9 Jan 1998 23:03:05 +0000 (23:03 +0000)
committercurt <curt>
Fri, 9 Jan 1998 23:03:05 +0000 (23:03 +0000)
FixNode/fixnode.c
FixNode/main.c
FixNode/triload.c
FixNode/triload.h
FixObj/main.c
FixObj/obj.c
FixObj/obj.h
Tools/README
Tri2obj/depend
Tri2obj/tri2obj.c
Triangle/Makefile

index d3feb16c5e47ed2f257c1fc8a7fe9c7a6afc74a7..8c3aee33a1b5d0d350b84ae6300f7854e4657952 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #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.
  *
index 7ebd5d7e530fdc36f5ee54f942b6fd8d74aa7318..002c495cfa6190c7a36185324238c8a9436e27c8 100644 (file)
  */
 
 
+#include <dirent.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/types.h>
 
 #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.
  *
index 2d6d670d7cbd1959196a99db20b0bd89dfc6b4f3..f0510bd2700a55826d1a4c672cbc231920f1d544 100644 (file)
 #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.
+ *
  */
index 058c01869f3c3b4efcae258a594d52dab1168c58..2d84f8e7480da55791a2121d354c6d29d2b3d72e 100644 (file)
@@ -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.
+ *
  */
index 0a499f1f9ccb638cb27168049b17a4e2b2e2dadd..bb20a0e37fef2a99780fc3e71d0d4d8f55c1ea95 100644 (file)
 
 
 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.
+ *
  */
index 55201f0fd8e85ee8b181c981d7abbe049797e746..19b87d4b12dad3381ff45a3c2648c2aa5911ee9b 100644 (file)
@@ -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.
+ *
  */
index c0ecf801c14d6b27d30c02ae5004d7e91024cfa9..54689de06d985c5034cfe6f608590111930d5c9c 100644 (file)
@@ -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.
+ *
  */
index 21133e438836b141f7a5463e00826b97f1124f27..fa4bf72903a6ec470b3291175779867283f6792f 100644 (file)
@@ -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/...
index 5e652e883d4130f25f6297bf0ce63d4c363f9e0d..73c1337131066549c95c50d8319f3b05a8b2e6fb 100644 (file)
@@ -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
index 0737899ae4f25f211242d593e4c50308f83de814..b38b074387bd5e31950dd5d7e8924ca55f497ba4 100644 (file)
@@ -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.
  *
index 66afd63cdccecb90ede00c75eebe887f26972982..cccdf2b1cb6c72b8003c86d08a3c16153e8f0697 100644 (file)
@@ -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.