Develop and Download Open Source Software

Browse CVS Repository

Contents of /autocoast/src/src/autocoast.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.22 - (show annotations) (download) (as text)
Tue Nov 30 10:42:27 2004 UTC (19 years, 4 months ago) by tmurakam
Branch: MAIN
CVS Tags: v0_3, HEAD
Changes since 1.21: +10 -4 lines
File MIME type: text/x-c++src
fix argument check

1 //
2 // AutoCoast: Automatic Coastline scenery generator for Flight Simulator
3 //
4 // Copyright (c) 2004, Takuya Murakami. All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // 2. Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
21 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 // autocoast.cc : main
30
31 #include <stdio.h>
32 #include <stdlib.h>
33
34 #include "cell.hpp"
35 #include "opt.hpp"
36
37 AcOptions AcOpts;
38
39 static void WriteBGL(LwmBgl *lwm, VtpBgl *vtp, FILE *batfile, int u, int v, int u2, int v2);
40
41 static void banner(void)
42 {
43 fprintf(stderr, BANNER);
44 }
45
46 // main func
47 int main(int argc, char **argv)
48 {
49 char *argv0;
50 int u, v, min_u, min_v, max_u, max_v, num_u, num_v, num_cells;
51 char filename[128];
52
53 banner();
54
55 AcOpts.set_arg_help("west north [east] [south]");
56
57 AcOpts.parse(&argc, &argv);
58
59 if (argc < 3 || argc > 5) {
60 AcOpts.usage();
61 exit(1);
62 }
63
64 if (AcOpts.useDegree) {
65 min_u = Cell::lon2x(atof(argv[1]));
66 min_v = Cell::lat2y(atof(argv[2]));
67 max_u = (argc > 3) ? Cell::lon2x(atof(argv[3])) : min_u;
68 max_v = (argc > 4) ? Cell::lat2y(atof(argv[4])) : min_v;
69 } else {
70 min_u = atoi(argv[1]);
71 min_v = atoi(argv[2]);
72 max_u = (argc > 3) ? atoi(argv[3]) : min_u;
73 max_v = (argc > 4) ? atoi(argv[4]) : min_v;
74 }
75
76 fprintf(stderr, "cells: [%d,%d] - [%d, %d]\n", min_u, min_v, max_u, max_v);
77
78 if (min_u < 0 || max_u < min_u || 768 <= max_u) {
79 fprintf(stderr, "Invalid u (longitude) value\n");
80 exit(1);
81 }
82 if (min_v < 0 || max_v < min_v || 512 <= max_v) {
83 fprintf(stderr, "Invalid v (latitude) value\n");
84 exit(1);
85 }
86
87
88 num_u = max_u - min_u + 1;
89 num_v = max_v - min_v + 1;
90 num_cells = num_u * num_v;
91
92 // Load dataset
93 fprintf(stderr, "* Loading dataset\n");
94 DataSet source;
95 source.LoadData();
96
97 source.printStat();
98 fprintf(stderr, "\n");
99
100 // Create cell data
101 Cell *cells = new Cell[num_cells];
102 #define CELL(u, v) cells[(u - min_u) + (v - min_v) * num_u]
103 Cell *c;
104
105 BoundingBox bbox;
106
107 for (v = min_v; v <= max_v; v++) {
108 for (u = min_u; u <= max_u; u++) {
109 c = &CELL(u, v);
110 c->setid(u, v);
111 bbox.extend(c->getBoundingBox());
112 }
113 }
114
115 // open batch file
116 FILE *batfile = fopen("compile.bat", "w");
117 if (!batfile) {
118 fprintf(stderr, "Can't open file: compile.bat\n");
119 exit(1);
120 }
121
122 // Clipping (1st stage: whole cells)
123 fprintf(stderr, "* Global clipping\n");
124 DataSet *clipped = source.Clipping(bbox);
125 clipped->printStat();
126 fprintf(stderr, "\n");
127
128 LwmBgl *lwm = new LwmBgl;
129 VtpBgl *vtp = new VtpBgl;
130
131 int i = 1;
132 for (v = min_v; v <= max_v; v++) {
133
134 // Clipping (2nd stage: one cell line)
135 c = &CELL(min_u, v);
136 BoundingBox bbox_line = *(c->getBoundingBox());
137
138 c = &CELL(max_u, v);
139 bbox_line.extend(c->getBoundingBox());
140
141 DataSet *clipped_line = clipped->Clipping(bbox_line);
142 //clipped_line->printStat();
143 //fprintf(stderr, "\n");
144
145 // Process each cells
146 for (u = min_u; u <= max_u; u++) {
147 c = &CELL(u, v);
148 fprintf(stderr, "%d/%d: Cell[%d:%d] ", i, num_cells, u, v);
149
150 // Clipping (3rd stage: each cell)
151 if (!c->Clipping(clipped_line)) {
152 // data empty : do nothing
153 fprintf(stderr, "no data\n");
154 }
155 else {
156 // generate data
157 c->GenLwmBgl(lwm);
158 c->GenVtpBgl(vtp);
159 fprintf(stderr, "\n");
160
161 if (AcOpts.splitBgl) {
162 WriteBGL(lwm, vtp, batfile, u, v, -1, -1);
163
164 delete lwm;
165 delete vtp;
166
167 lwm = new LwmBgl;
168 vtp = new VtpBgl;
169 }
170 }
171
172 c++;
173 i++;
174 }
175 delete clipped_line;
176 }
177
178 if (!AcOpts.splitBgl) {
179 WriteBGL(lwm, vtp, batfile, min_u, min_v, max_u, max_v);
180 }
181
182 fclose(batfile);
183
184 delete lwm;
185 delete vtp;
186 delete [] cells;
187
188 return 0;
189 }
190
191 static void WriteBGL(LwmBgl *lwm, VtpBgl *vtp, FILE *batfile, int u, int v, int u2, int v2)
192 {
193 char filename[128];
194
195 if (u2 < 0) {
196 sprintf(filename, "lwm_%d_%d.asm", u, v);
197 } else {
198 sprintf(filename, "lwm_%d_%d_%d_%d.asm", u, v, u2, v2);
199 }
200 lwm->WriteBGL(filename);
201 fprintf(batfile, "bglc %s\n", filename);
202
203 if (u2 < 0) {
204 sprintf(filename, "vtp_%d_%d.asm", u, v);
205 } else {
206 sprintf(filename, "vtp_%d_%d_%d_%d.asm", u, v, u2, v2);
207 }
208 vtp->WriteBGL(filename);
209 fprintf(batfile, "bglc %s\n", filename);
210 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26