1 /*****************************************************************************
4 Author: Christian Mayer
6 Called by: command line
8 ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ----------
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 ------------------------------------------------------------------------------
29 Test program for the weather database
32 ------------------------------------------------------------------------------
34 *****************************************************************************/
36 /****************************************************************************/
38 /****************************************************************************/
39 #include "FGLocalWeatherDatabase.h"
40 #include "FGGlobalWeatherDatabase.h"
41 #include "LibVoronoi/FGVoronoi.h"
42 #include "FGWeatherUtils.h"
47 /****************************************************************************/
48 /********************************** CODE ************************************/
49 /****************************************************************************/
52 //init local database:
54 FGLocalWeatherDatabase local(Point3D(0,0,0), 10000, FGLocalWeatherDatabase::use_global);
55 FGGlobalWeatherDatabase global(FGGlobalWeatherDatabase_working);
59 FGPhysicalProperties x;
60 FGPhysicalProperties2D x2d;
61 FGPhysicalProperties2DVector getAllvect;
63 cout << "\n**************** FGGlobalWeatherDatabase Test ****************\n";
64 x.Temperature.insert(FGTemperatureItem(100, Celsius(10)));
65 global.add(Point2D(5,5), x);
67 x.Temperature.insert(FGTemperatureItem(110, Celsius(-10)));
68 global.add(Point3D(10,10,10), x);
70 x2d.Temperature.insert(FGTemperatureItem(90, Celsius(-20)));
71 x2d.p = Point2D(10,5);
75 getAllvect = global.getAll(p2d, 10000);
76 cout << "Returned size: " << getAllvect.size() << "\n";
77 getAllvect = global.getAll(p2d, 10000, 30);
78 cout << "Returned size: " << getAllvect.size() << "\n";
79 getAllvect = global.getAll(p, 10000);
80 cout << "Returned size: " << getAllvect.size() << "\n";
81 getAllvect = global.getAll(p, 10000, 3);
82 cout << "Returned size: " << getAllvect.size() << "\n";
84 cout << "Temperature: " << global.get(Point3D(5, 5, 100)).Temperature << "°C\n";
85 cout << "AirPressure at 0m: " << global.get(Point3D(5, 5, 0)).AirPressure << "\n";
86 cout << "AirPressure at 1000m: " << global.get(Point3D(5, 5, 1000)).AirPressure << "\n";
91 cout << "\n**************** FGMicroWeather Test ****************\n";
92 vector<Point2D> points;
94 points.push_back(Point2D(0.1, 0.1));
95 points.push_back(Point2D(0.9, 0.1));
96 points.push_back(Point2D(0.9, 0.9));
97 points.push_back(Point2D(0.1, 0.9));
98 points.push_back(Point2D(0.1, 0.1));
100 x2d.p = Point2D(0.4, 0.4);
102 FGMicroWeather micro(x2d, points);
104 cout << "hasPoint 0.5, 0.5: ";
105 if (micro.hasPoint(Point2D(0.5, 0.5)) == true)
110 cout << "\nhasPoint 0.9, 0.5: ";
111 if (micro.hasPoint(Point2D(0.9, 0.5)) == true)
116 cout << "\nhasPoint 1.5, 0.5: ";
117 if (micro.hasPoint(Point2D(1.5, 0.5)) == true)
125 cout << "\n**************** Voronoi Diagram Test ****************\n";
126 FGVoronoiInputList input;
127 FGVoronoiOutputList output;
128 FGVoronoiInput test(Point2D(0.0), FGPhysicalProperties2D());
130 test.position = Point2D(0.1,0.2);
131 input.push_back(test);
133 test.position = Point2D(0.8,0.9);
134 input.push_back(test);
136 test.position = Point2D(0.9,0.1);
137 input.push_back(test);
139 test.position = Point2D(0.6,0.4);
140 input.push_back(test);
142 test.position = Point2D(1.1,1.2);
143 input.push_back(test);
145 test.position = Point2D(1.8,1.9);
146 input.push_back(test);
148 test.position = Point2D(1.9,1.1);
149 input.push_back(test);
151 test.position = Point2D(1.6,1.4);
152 input.push_back(test);
154 test.position = Point2D(2.9,2.1);
155 input.push_back(test);
157 test.position = Point2D(2.6,2.4);
158 input.push_back(test);
160 output = Voronoiate(input);
163 for (FGVoronoiOutputList::iterator it=output.begin(); it!=output.end(); it++)
165 cout << "Cell start: ";
166 for (Point2DList::iterator it2= it->boundary.begin();it2!= it->boundary.end();it2++)
168 if (it2==it->boundary.begin())
178 cout << "\n**************** Database Stress Test ****************\n";
180 time_t starttime, currenttime;
181 unsigned long count = 0;
182 unsigned long count2 = 0;
184 cout << "Filling Database... ";
186 for (count = 0; count < 5000; count++)
188 xxx = (rand()%36000)/100.0;
189 yyy = (rand()%18000)/100.0;
191 local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point2D(xxx, yyy)));
193 local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(-10.0)));
194 local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(+10.0)));
195 local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(-100.0)));
196 local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(+100.0)));
198 time( ¤ttime );
199 cout << float(count)/float(currenttime - starttime) << "/s filling rate; ";
202 for (count = 0; count < 5; count++)
204 local.reset(FGLocalWeatherDatabase::use_global); //make sure I've got a current voronoi
207 time( ¤ttime );
208 cout << float(currenttime - starttime)/float(count) << "s resetting time; Done\n";
212 cout << "local.get() test: 10 seconds\n";
214 time( ¤ttime );
215 for (;currenttime<(starttime+10);)
217 time( ¤ttime );
219 local.get(Point3D(0.0));
222 cout << "Result: " << float(count) / float(currenttime-starttime) << "/s\n";
225 cout << "output = Voronoiate(input) test: 10 seconds\n";
227 time( ¤ttime );
228 for (;currenttime<(starttime+10);)
230 time( ¤ttime );
232 output = Voronoiate(input);
235 cout << "Result: " << float(count) / float(currenttime-starttime) << "/s\n";
236 cout << "Reference: 176800/s\n";
238 cout << "\n**************** Database Stress Test end ****************\n";