1 // fixnode.cxx -- traverse the node file and fix the elevation of all the new
2 // interpolated points.
4 // Written by Curtis Olson, started November 1997.
6 // Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
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.
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.
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.
23 // (Log is kept at end of this file)
34 #endif // HAVE_STDLIB_H
36 #include <Misc/fgstream.hxx>
38 #include "fixnode.hxx"
42 void load_extra(const string& filename, container& extra_list) {
46 // load the node information
47 void load_nodes(const string& filename, container& node_list) {
49 int dim, junk1, junk2;
52 cout << "Loading node file: " << filename << " ...\n";
54 fg_gzifstream in( filename );
56 cout << "Cannot open " + filename + "\n";
57 // exit immediately assuming an airport file for this tile
63 in >> nodecount >> dim >> junk1 >> junk2;
64 cout << " Expecting " << nodecount << " nodes\n";
66 // start with an empty list :-)
67 node_list.erase( node_list.begin(), node_list.end() );
70 while ( ! in.eof() ) {
71 in >> junk1 >> node >> junk2;
73 node_list.push_back(node);
78 // fix the node elevations
79 void fix_nodes( const string& filename, fgDEM& dem, container& node_list )
85 cout << "Fixing up node elevations\n";
88 iterator last = node_list.end();
89 for ( current = node_list.begin() ; current != last ; ++current ) {
90 // printf("Current: %d %.2f %.2f %.2f\n", i, nodes[i][0],
91 // nodes[i][1], nodes[i][2]);
94 dem.interpolate_altitude( (*current).x(),
97 // printf("Fixed: %d %.2f %.2f %.2f\n", i, nodes[i][0],
98 // nodes[i][1], nodes[i][2]);
102 toname = filename + ".orig";
103 cout << "Moving " + filename + " to " + toname + "\n";
104 rename( filename.c_str(), toname.c_str() );
106 cout << "Saving new node file: " + filename + "\n";
108 fd = fopen(filename.c_str(), "w");
110 fprintf( fd, "%d 2 1 0\n", node_list.size() );
113 for ( current = node_list.begin() ; current != last ; ++current ) {
114 fprintf( fd, "%d %.2f %.2f %.2f 0\n", i,
115 (*current).x(), (*current).y(), (*current).z() );
124 // Revision 1.7 1998/11/06 21:33:55 curt
125 // Updates to go along with changes in fgstream.
127 // Revision 1.6 1998/10/20 15:49:22 curt
128 // Converted to Point3D class.
130 // Revision 1.5 1998/09/22 23:49:10 curt
131 // eliminated a left over #include
133 // Revision 1.4 1998/09/19 20:43:52 curt
134 // C++-ified and STL-ified the code. Combined triload.* and fixnode.* into
137 // Revision 1.3 1998/07/22 21:46:40 curt
138 // Fixed a bug that was triggering a seg fault.
140 // Revision 1.2 1998/04/14 02:26:03 curt
141 // Code reorganizations. Added a Lib/ directory for more general libraries.
143 // Revision 1.1 1998/04/08 23:05:56 curt
144 // Adopted Gnu automake/autoconf system.
146 // Revision 1.5 1998/03/19 02:50:19 curt
147 // Updated to support -lDEM class.
149 // Revision 1.4 1998/03/03 16:00:57 curt
150 // More c++ compile tweaks.
152 // Revision 1.3 1998/01/09 23:03:08 curt
153 // Restructured to split 1deg x 1deg dem's into 64 subsections.
155 // Revision 1.2 1997/12/02 13:12:07 curt
156 // Updated to fix every node.
158 // Revision 1.1 1997/11/27 00:17:33 curt