]> git.mxchange.org Git - flightgear.git/blob - FixNode/fixnode.cxx
Moved point interpolation and least squares fitting to contruction program
[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@me.umn.edu
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
40
41 // load extra nodes
42 void load_extra(const string& filename, container& extra_list) {
43 }
44
45
46 // load the node information
47 void load_nodes(const string& filename, container& node_list) {
48     Point3D node;
49     int dim, junk1, junk2;
50     int i, nodecount;
51
52     cout << "Loading node file:  " << filename << " ...\n";
53
54     fg_gzifstream in( filename );
55     if ( !in ) {
56         cout << "Cannot open " + filename + "\n";
57         // exit immediately assuming an airport file for this tile
58         // doesn't exist.
59         exit(-1);
60     }
61
62     // Read header line
63     in >> nodecount >> dim >> junk1 >> junk2;
64     cout << "    Expecting " << nodecount << " nodes\n";
65
66     // start with an empty list :-)
67     node_list.erase( node_list.begin(), node_list.end() );
68
69     in >> skipcomment;
70     while ( ! in.eof() ) {
71         in >> junk1 >> node >> junk2;
72         in >> skipcomment;
73         node_list.push_back(node);
74     }
75 }
76
77
78 // fix the node elevations
79 void fix_nodes( const string& filename, fgDEM& dem, container& node_list )
80 {
81     string toname;
82     FILE *fd;
83     int i;
84
85     cout << "Fixing up node elevations\n";
86
87     iterator current;
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]);
92
93         (*current).setz( 
94                         dem.interpolate_altitude( (*current).x(), 
95                                                   (*current).y() ) );
96
97         // printf("Fixed: %d %.2f %.2f %.2f\n", i, nodes[i][0],
98         //        nodes[i][1], nodes[i][2]);
99     }
100
101
102     toname = filename + ".orig";
103     cout << "Moving " + filename + " to " + toname + "\n";
104     rename( filename.c_str(), toname.c_str() );
105
106     cout << "Saving new node file: " + filename + "\n";
107
108     fd = fopen(filename.c_str(), "w");
109
110     fprintf( fd, "%d 2 1 0\n", node_list.size() );
111
112     i = 1;
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() );
116         ++i;
117     }
118
119     fclose(fd);
120 }
121
122
123 // $Log$
124 // Revision 1.7  1998/11/06 21:33:55  curt
125 // Updates to go along with changes in fgstream.
126 //
127 // Revision 1.6  1998/10/20 15:49:22  curt
128 // Converted to Point3D class.
129 //
130 // Revision 1.5  1998/09/22 23:49:10  curt
131 // eliminated a left over #include
132 //
133 // Revision 1.4  1998/09/19 20:43:52  curt
134 // C++-ified and STL-ified the code.  Combined triload.* and fixnode.* into
135 // a single file.
136 //
137 // Revision 1.3  1998/07/22 21:46:40  curt
138 // Fixed a bug that was triggering a seg fault.
139 //
140 // Revision 1.2  1998/04/14 02:26:03  curt
141 // Code reorganizations.  Added a Lib/ directory for more general libraries.
142 //
143 // Revision 1.1  1998/04/08 23:05:56  curt
144 // Adopted Gnu automake/autoconf system.
145 //
146 // Revision 1.5  1998/03/19 02:50:19  curt
147 // Updated to support -lDEM class.
148 //
149 // Revision 1.4  1998/03/03 16:00:57  curt
150 // More c++ compile tweaks.
151 //
152 // Revision 1.3  1998/01/09 23:03:08  curt
153 // Restructured to split 1deg x 1deg dem's into 64 subsections.
154 //
155 // Revision 1.2  1997/12/02 13:12:07  curt
156 // Updated to fix every node.
157 //
158 // Revision 1.1  1997/11/27 00:17:33  curt
159 // Initial revision.
160 //
161