]> git.mxchange.org Git - flightgear.git/blob - FixNode/fixnode.cxx
C++-ified and STL-ified the code. Combined triload.* and fixnode.* into
[flightgear.git] / FixNode / fixnode.cxx
1 // fixnode.cxx -- traverse the node file and fix the elevation of all the new
2 //                interpolated points.
3 //
4 // Written by Curtis Olson, started November 1997.
5 //
6 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24
25
26
27 #include <stdio.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <string>
31
32 #ifdef HAVE_STDLIB_H
33 #  include <stdlib.h>
34 #endif // HAVE_STDLIB_H
35
36 #include <Misc/fgstream.hxx>
37
38 #include "fixnode.hxx"
39 #include "triload.hxx"
40
41
42 // load the node information
43 void load_nodes(const string& filename, container& node_list) {
44     fgPoint3d node;
45     int dim, junk1, junk2;
46     int i, nodecount;
47
48     cout << "Loading node file:  " + filename + " ...\n";
49
50     fg_gzifstream in( filename );
51     if ( !in ) {
52         cout << "Cannot open " + filename + "\n";
53         // exit immediately assuming an airport file for this tile
54         // doesn't exist.
55         exit(-1);
56     }
57
58     // Read header line
59     in.stream() >> nodecount >> dim >> junk1 >> junk2;
60     cout << "    Expecting " << nodecount << " nodes\n";
61
62     // start with an empty list :-)
63     node_list.erase( node_list.begin(), node_list.end() );
64
65     in.eat_comments();
66     while ( ! in.eof() ) {
67         in.stream() >> junk1 >> node.x >> node.y >> node.z >> junk2;
68         in.eat_comments();
69         node_list.push_back(node);
70     }
71 }
72
73
74 // fix the node elevations
75 void fix_nodes( const string& filename, fgDEM& dem, container& node_list )
76 {
77     string toname;
78     FILE *fd;
79     int i;
80
81     cout << "Fixing up node elevations\n";
82
83     iterator current;
84     iterator last = node_list.end();
85     for ( current = node_list.begin() ; current != last ; ++current ) {
86         // printf("Current: %d %.2f %.2f %.2f\n", i, nodes[i][0],
87         //        nodes[i][1], nodes[i][2]);
88
89         (*current).z = 
90             dem.interpolate_altitude( (*current).x, (*current).y );
91
92         // printf("Fixed: %d %.2f %.2f %.2f\n", i, nodes[i][0],
93         //        nodes[i][1], nodes[i][2]);
94     }
95
96
97     toname = filename + ".orig";
98     cout << "Moving " + filename + " to " + toname + "\n";
99     rename( filename.c_str(), toname.c_str() );
100
101     cout << "Saving new node file: " + filename + "\n";
102
103     fd = fopen(filename.c_str(), "w");
104
105     fprintf( fd, "%d 2 1 0\n", node_list.size() );
106
107     i = 1;
108     for ( current = node_list.begin() ; current != last ; ++current ) {
109         fprintf( fd, "%d %.2f %.2f %.2f 0\n", i,
110                  (*current).x, (*current).y, (*current).z );
111         ++i;
112     }
113
114     fclose(fd);
115 }
116
117
118 // $Log$
119 // Revision 1.4  1998/09/19 20:43:52  curt
120 // C++-ified and STL-ified the code.  Combined triload.* and fixnode.* into
121 // a single file.
122 //
123 // Revision 1.3  1998/07/22 21:46:40  curt
124 // Fixed a bug that was triggering a seg fault.
125 //
126 // Revision 1.2  1998/04/14 02:26:03  curt
127 // Code reorganizations.  Added a Lib/ directory for more general libraries.
128 //
129 // Revision 1.1  1998/04/08 23:05:56  curt
130 // Adopted Gnu automake/autoconf system.
131 //
132 // Revision 1.5  1998/03/19 02:50:19  curt
133 // Updated to support -lDEM class.
134 //
135 // Revision 1.4  1998/03/03 16:00:57  curt
136 // More c++ compile tweaks.
137 //
138 // Revision 1.3  1998/01/09 23:03:08  curt
139 // Restructured to split 1deg x 1deg dem's into 64 subsections.
140 //
141 // Revision 1.2  1997/12/02 13:12:07  curt
142 // Updated to fix every node.
143 //
144 // Revision 1.1  1997/11/27 00:17:33  curt
145 // Initial revision.
146 //
147