1
0
Fork 0

Restructured to split 1deg x 1deg dem's into 64 subsections.

This commit is contained in:
curt 1998-01-09 23:03:05 +00:00
parent 0b3701e0c2
commit 0e813d878b
11 changed files with 145 additions and 90 deletions

View file

@ -26,6 +26,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "fixnode.h" #include "fixnode.h"
#include "../Dem2node/mesh.h" #include "../Dem2node/mesh.h"
@ -33,8 +34,8 @@
/* load the node information */ /* load the node information */
void fixnodes(char *basename, struct MESH *m) { void fixnodes(char *filename, struct MESH *m) {
char file[256]; char toname[256];
FILE *fd; FILE *fd;
int i; int i;
@ -55,12 +56,14 @@ void fixnodes(char *basename, struct MESH *m) {
nodes[i][1], nodes[i][2]); */ 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); fprintf(fd, "%d 2 1 0\n", nodecount);
@ -74,9 +77,12 @@ void fixnodes(char *basename, struct MESH *m) {
/* $Log$ /* $Log$
/* Revision 1.2 1997/12/02 13:12:07 curt /* Revision 1.3 1998/01/09 23:03:08 curt
/* Updated to fix every node. /* 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 * Revision 1.1 1997/11/27 00:17:33 curt
* Initial revision. * Initial revision.
* *

View file

@ -24,36 +24,85 @@
*/ */
#include <dirent.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include "../Dem2node/demparse.h" #include "../Dem2node/demparse.h"
#include "fixnode.h" #include "fixnode.h"
#include "triload.h" #include "triload.h"
int main(int argc, char **argv) { /* Original DEM which is used to interpolate z values */
char basename[256];
struct MESH dem_mesh; struct MESH dem_mesh;
strcpy(basename, argv[1]);
/* 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 */ /* load the input data files */
triload(basename); triload(file_path);
fixnodes(file_path, &dem_mesh);
}
}
}
}
/* main */
int main(int argc, char **argv) {
char demfile[256], root_path[256];
if ( argc != 3 ) {
printf("Usage %s demfile root_path\n", argv[0]);
exit(-1);
}
strcpy(demfile, argv[1]);
strcpy(root_path, argv[2]);
/* load the corresponding dem file so we can interpolate elev values */ /* 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); return(0);
} }
/* $Log$ /* $Log$
/* Revision 1.2 1997/12/02 13:12:07 curt /* Revision 1.3 1998/01/09 23:03:08 curt
/* Updated to fix every node. /* 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 * Revision 1.1 1997/11/27 00:17:34 curt
* Initial revision. * Initial revision.
* *

View file

@ -30,37 +30,19 @@
#include "triload.h" #include "triload.h"
int origcount;
int nodecount; int nodecount;
double nodes[MAX_NODES][3]; double nodes[MAX_NODES][3];
/* load the node information */ /* load the node information */
void triload(char *basename) { void triload(char *filename) {
char origname[256], nodename[256]; FILE *node;
FILE *orig, *node;
int dim, junk1, junk2; int dim, junk1, junk2;
int i; int i;
strcpy(origname, basename); printf("Loading node file: %s ...\n", filename);
strcat(origname, ".node"); if ( (node = fopen(filename, "r")) == NULL ) {
printf("Cannot open file '%s'\n", filename);
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);
exit(-1); exit(-1);
} }
@ -85,7 +67,10 @@ void triload(char *basename) {
/* $Log$ /* $Log$
/* Revision 1.1 1997/11/27 00:17:35 curt /* Revision 1.2 1998/01/09 23:03:09 curt
/* Initial revision. /* Restructured to split 1deg x 1deg dem's into 64 subsections.
/* /*
* Revision 1.1 1997/11/27 00:17:35 curt
* Initial revision.
*
*/ */

View file

@ -36,7 +36,7 @@
#define MAX_TRIS 400000 #define MAX_TRIS 400000
extern int origcount, nodecount, tricount; extern int nodecount, tricount;
double nodes[MAX_NODES][3]; double nodes[MAX_NODES][3];
@ -48,7 +48,10 @@ void triload(char *basename);
/* $Log$ /* $Log$
/* Revision 1.1 1997/11/27 00:17:35 curt /* Revision 1.2 1998/01/09 23:03:09 curt
/* Initial revision. /* Restructured to split 1deg x 1deg dem's into 64 subsections.
/* /*
* Revision 1.1 1997/11/27 00:17:35 curt
* Initial revision.
*
*/ */

View file

@ -29,19 +29,27 @@
int main(int argc, char **argv) { 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 */ /* load the input data files */
obj_fix(basename); obj_fix(infile, outfile);
return(0); return(0);
} }
/* $Log$ /* $Log$
/* Revision 1.1 1997/12/08 19:28:54 curt /* Revision 1.2 1998/01/09 23:03:12 curt
/* Initial revision. /* Restructured to split 1deg x 1deg dem's into 64 subsections.
/* /*
* Revision 1.1 1997/12/08 19:28:54 curt
* Initial revision.
*
*/ */

View file

@ -63,7 +63,7 @@ void list_add(int *list, int *list_ptr, int node) {
list[*list_ptr] = node; list[*list_ptr] = node;
*list_ptr += 1; *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 */ /* dump header */
fprintf(out, "t %d %d %d\n", list[i], list[i+1], list[i+2]); 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; i += 3;
/* dump rest of strip (until -1) */ /* dump rest of strip (until -1) */
@ -139,26 +139,19 @@ double check_cur_face(int n1, int n2, int n3) {
/* Load a .obj file */ /* Load a .obj file */
void obj_fix(char *basename) { void obj_fix(char *infile, char *outfile) {
char line[256]; char line[256];
char inpath[256], outpath[256];
double dot_prod; double dot_prod;
int first, ncount, vncount, n1, n2, n3, n4; int first, ncount, vncount, n1, n2, n3, n4;
int is_ccw; int is_ccw;
strcpy(inpath, basename); if ( (in = fopen(infile, "r")) == NULL ) {
strcat(inpath, ".obj"); printf("Cannot open file: %s\n", infile);
strcpy(outpath, basename);
strcat(outpath, ".1.obj");
if ( (in = fopen(inpath, "r")) == NULL ) {
printf("Cannot open file: %s\n", inpath);
exit(-1); exit(-1);
} }
if ( (out = fopen(outpath, "w")) == NULL ) { if ( (out = fopen(outfile, "w")) == NULL ) {
printf("Cannot open file: %s\n", outpath); printf("Cannot open file: %s\n", outfile);
exit(-1); exit(-1);
} }
@ -169,7 +162,7 @@ void obj_fix(char *basename) {
ncount = 1; ncount = 1;
vncount = 1; vncount = 1;
printf("Reading file: %s\n", inpath); printf("Reading file: %s\n", infile);
while ( fgets(line, 250, in) != NULL ) { while ( fgets(line, 250, in) != NULL ) {
if ( line[0] == '#' ) { if ( line[0] == '#' ) {
@ -274,7 +267,7 @@ void obj_fix(char *basename) {
} }
} }
} else { } 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$ /* $Log$
/* Revision 1.1 1997/12/08 19:28:54 curt /* Revision 1.2 1998/01/09 23:03:12 curt
/* Initial revision. /* Restructured to split 1deg x 1deg dem's into 64 subsections.
/* /*
* Revision 1.1 1997/12/08 19:28:54 curt
* Initial revision.
*
*/ */

View file

@ -36,14 +36,17 @@ extern int stack[MAXNODES];
/* Load a .obj file */ /* Load a .obj file */
void obj_fix(char *basename); void obj_fix(char *infile, char *outfile);
#endif /* OBJ_H */ #endif /* OBJ_H */
/* $Log$ /* $Log$
/* Revision 1.1 1997/12/08 19:28:55 curt /* Revision 1.2 1998/01/09 23:03:13 curt
/* Initial revision. /* Restructured to split 1deg x 1deg dem's into 64 subsections.
/* /*
* Revision 1.1 1997/12/08 19:28:55 curt
* Initial revision.
*
*/ */

View file

@ -1,15 +1,19 @@
1. Start with file.dem 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/...

View file

@ -1,3 +1,4 @@
tri2obj.o: tri2obj.c tri2obj.h ../../Src/constants.h ../../Src/types.h \ tri2obj.o: tri2obj.c tri2obj.h ../../Src/Include/constants.h \
../../Src/Math/fg_geodesy.h ../../Src/Math/mat3.h \ ../../Src/Include/types.h ../../Src/Math/fg_geodesy.h \
../../Src/Math/polar.h ../../Src/Math/../types.h ../../Src/Math/mat3.h ../../Src/Math/polar.h \
../../Src/Math/../Include/types.h

View file

@ -29,8 +29,8 @@
#include "tri2obj.h" #include "tri2obj.h"
#include "../../Src/constants.h" #include "../../Src/Include/constants.h"
#include "../../Src/types.h" #include "../../Src/Include/types.h"
#include "../../Src/Math/fg_geodesy.h" #include "../../Src/Math/fg_geodesy.h"
#include "../../Src/Math/mat3.h" #include "../../Src/Math/mat3.h"
#include "../../Src/Math/polar.h" #include "../../Src/Math/polar.h"
@ -234,10 +234,7 @@ void dump_obj(char *basename) {
/* dump faces */ /* dump faces */
printf(" writing faces\n"); printf(" writing faces\n");
for ( i = 1; i <= tricount; i++ ) { for ( i = 1; i <= tricount; i++ ) {
fprintf(obj, "f %d//%d %d//%d %d//%d\n", fprintf(obj, "f %d %d %d\n", tris[i][0], tris[i][1], tris[i][2]);
tris[i][0], tris[i][0],
tris[i][1], tris[i][1],
tris[i][2], tris[i][2]);
} }
fclose(obj); fclose(obj);
@ -259,9 +256,12 @@ int main(int argc, char **argv) {
/* $Log$ /* $Log$
/* Revision 1.5 1997/12/08 19:17:50 curt /* Revision 1.6 1998/01/09 23:03:15 curt
/* Fixed a type in the normal generation code. /* 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 * Revision 1.4 1997/12/02 13:13:32 curt
* Fixed problem with averaged vertex normals. * Fixed problem with averaged vertex normals.
* *

View file

@ -83,7 +83,7 @@ TRILIBDEFS = -DTRILIBRARY
# RM should be set to the name of your favorite rm (file deletion program). # 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. # The action starts here.