+++ /dev/null
-/*****************************************************************************
-
- Module: FGGlobalWeatherDatabase.cpp
- Author: Christian Mayer
- Date started: 28.05.99
- Called by: main program
-
- -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
-
- This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
- Foundation; either version 2 of the License, or (at your option) any later
- version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Further information about the GNU General Public License can also be found on
- the world wide web at http://www.gnu.org.
-
-FUNCTIONAL DESCRIPTION
-------------------------------------------------------------------------------
-Database for the global weather
-This database is only called by the local database and by the weather
-simulator driving this database
-
-HISTORY
-------------------------------------------------------------------------------
-28.05.1999 Christian Mayer Created
-16.06.1999 Durk Talsma Portability for Linux
-20.06.1999 Christian Mayer added lots of consts
-11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
- suggestion
-19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
- and lots of wee code cleaning
-*****************************************************************************/
-
-/****************************************************************************/
-/* INCLUDES */
-/****************************************************************************/
-#include "FGGlobalWeatherDatabase.h"
-
-/****************************************************************************/
-/********************************** CODE ************************************/
-/****************************************************************************/
-
-template<class V>
-V triangle_interpolate(const sgVec2& x1, const V& v1, const sgVec2& x2, const V& v2, const sgVec2& x3, const V& v3, const sgVec2& p)
-{
- /************************************************************************/
- /* First I have to solve the two equations. Rewritten they look like: */
- /* */
- /* a11 * x1 + a12 * x2 = b1 */
- /* a21 * x1 + a22 * x2 = b2 */
- /* */
- /* with */
- /* */
- /* a11 = x2[0] - x1[0] a12 = x3[0] - x1[0] b1 = p[0] - x1[0] */
- /* a21 = x2[1] - x1[1] a22 = x3[1] - x1[1] b2 = p[1] - x1[1] */
- /* */
- /* So I can easily get the solution by saying: */
- /* */
- /* | a11 a12 | */
- /* D = | | */
- /* | a21 a22 | */
- /* */
- /* | b1 a12 | | a11 b1 | */
- /* | | | | */
- /* | b2 a22 | | a21 b2 | */
- /* x1 = ----------- x2 = ----------- */
- /* D D */
- /* */
- /* I just need to take care then that D != 0 or I would get no */
- /* solution or an infinite amount. Both wouildn't be good... */
- /************************************************************************/
-
- float D = (x2[0] - x1[0]) * (x3[1] - x1[1]) - (x2[1] - x1[1]) * (x3[0] - x1[0]);
-
- if (D == 0.0)
- return v1; //BAD THING HAPPENED!!! I should throw an exeption
-
- float x = ( (p [0] - x1[0]) * (x3[1] - x1[1]) - (p [1] - x1[1]) * (x3[0] - x1[0]) ) / D;
- float y = ( (x2[0] - x1[0]) * (p [1] - x1[1]) - (x2[1] - x1[1]) * (p [0] - x1[0]) ) / D;
-
- return v1 + x * (v2 - v1) + y * (v3 - v1);
-}
-
-/****************************************************************************/
-/* Constructor and Destructor */
-/****************************************************************************/
-FGGlobalWeatherDatabase::FGGlobalWeatherDatabase(const FGGlobalWeatherDatabaseStatus s)
-{
- DatabaseStatus = s;
-}
-
-FGGlobalWeatherDatabase::~FGGlobalWeatherDatabase()
-{
-}
-
-/****************************************************************************/
-/* Get the physical properties on the specified point p */
-/* do this by interpolating between the 3 closest points */
-/****************************************************************************/
-FGPhysicalProperties FGGlobalWeatherDatabase::get(const sgVec2& p) const
-{
- WeatherPrecision distance[3]; //store the 3 closest distances
- FGPhysicalProperties2DVectorConstIt iterator[3]; //and the coresponding iterators
- WeatherPrecision d;
-
- distance[0] = 9.46e15; //init with a distance that every calculated
- distance[1] = 9.46e15; //distance is guranteed to be shorter as
- distance[2] = 9.46e15; //9.46e15 metres are 1 light year...
-
- for (FGPhysicalProperties2DVectorConstIt it=database.begin(); it!=database.end(); it++)
- { //go through the whole database
- d = sgDistanceVec2(it->p, p);
-
- if (d<distance[0])
- {
- distance[2] = distance[1]; distance[1] = distance[0]; distance[0] = d;
- iterator[2] = iterator[1]; iterator[1] = iterator[0]; iterator[0] = it;
- //NOTE: The last line causes a warning that an unitialized variable
- //is used. You can ignore this warning here.
- }
- else if (d<distance[1])
- {
- distance[2] = distance[1]; distance[1] = d;
- iterator[2] = iterator[1]; iterator[1] = it;
- }
- else if (d<distance[2])
- {
- distance[2] = d;
- iterator[2] = it;
- }
- }
-
- //now I've got the closest entry in xx[0], the 2nd closest in xx[1] and the
- //3rd in xx[2];
-
- //interpolate now:
- return triangle_interpolate(
- iterator[0]->p, (FGPhysicalProperties)*iterator[0],
- iterator[1]->p, (FGPhysicalProperties)*iterator[1],
- iterator[2]->p, (FGPhysicalProperties)*iterator[2], p);
-}
-
-/****************************************************************************/
-/* update the database. Since the last call we had dt seconds */
-/****************************************************************************/
-void FGGlobalWeatherDatabase::update(const WeatherPrecision dt)
-{
- // I've got nothing to update here (yet...)
-}
-
-/****************************************************************************/
-/* Add a physical property on the specified point p */
-/****************************************************************************/
-void FGGlobalWeatherDatabase::add(const sgVec2& p, const FGPhysicalProperties& x)
-{
- FGPhysicalProperties2D e;
-
- sgCopyVec2(e.p, p);
-
- e.Wind = x.Wind;
- e.Turbulence = x.Turbulence;
- e.Temperature = x.Temperature;
- e.AirPressure = x.AirPressure;
- e.VaporPressure = x.VaporPressure;
-
- e.Clouds = x.Clouds;
- e.SnowRainIntensity = x.SnowRainIntensity;
- e.snowRainType = x.snowRainType;
- e.LightningProbability = x.LightningProbability;
-
- database.push_back(e);
-}
-
-/****************************************************************************/
-/* Change the closest physical property to p. If p is further away than */
-/* tolerance I'm returning false otherwise true */
-/****************************************************************************/
-bool FGGlobalWeatherDatabase::change(const FGPhysicalProperties2D& p, const WeatherPrecision tolerance)
-{
- for (FGPhysicalProperties2DVectorIt it = database.begin(); it != database.end(); it++)
- {
- if (sgScalarProductVec2(it->p, p.p) < (tolerance*tolerance))
- { //assume that's my point
- (*it) = p;
- return true;
- }
- }
-
- return false;
-}
-
-/****************************************************************************/
-/* Get all, but at least min, stored point in the circle around p with the */
-/* radius r */
-/****************************************************************************/
-FGPhysicalProperties2DVector FGGlobalWeatherDatabase::getAll(const sgVec2& p, const WeatherPrecision r, const unsigned int min)
-{
- FGPhysicalProperties2DVector ret_list;
-
- if ( (DatabaseStatus == FGGlobalWeatherDatabase_only_static)
- ||(DatabaseStatus == FGGlobalWeatherDatabase_working ) )
- { //doest it make sense?
-
- FGPhysicalProperties2DVectorIt *it; //store the closest entries
- WeatherPrecision *d;
- unsigned int act_it = 0;
- int i;
-
- it = new FGPhysicalProperties2DVectorIt[min+1];
- d = new WeatherPrecision[min+1];
-
- for (it[0]=database.begin(); it[act_it]!=database.end(); it[act_it]++)
- { //go through the whole database
- d[act_it] = sgScalarProductVec2(it[act_it]->p, p);
-
- if (r >= d[act_it])
- { //add it
- ret_list.push_back(*it[act_it]);
- }
- else
- {
- if (act_it>0)
- { //figure out if this distance belongs to the closest ones
- WeatherPrecision dummy;
- FGPhysicalProperties2DVectorIt dummyIt;
-
- for (i = act_it++; i >= 0;)
- {
- if (d[i] >= d[--i])
- {
- act_it--;
- break; //nope => stop
- }
-
- //swap both
- dummy =d[i]; d[i] = d[i+1]; d[i+1] = dummy;
- dummyIt = it[i]; it[i] = it[i+1]; it[i+1] = dummyIt;
- }
- }
- }
- }
-
- if (ret_list.size()<min)
- {
- for(i = 0; (i < (int)(min - ret_list.size())) && (ret_list.size() < database.size()); i++)
- ret_list.push_back(*it[i]);
- }
-
- delete d;
- delete it;
- }
-
- return ret_list;
-}
-
+++ /dev/null
-/*****************************************************************************
-
- Header: FGGlobalWeatherDatabase.h
- Author: Christian Mayer
- Date started: 28.05.99
-
- -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
-
- This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
- Foundation; either version 2 of the License, or (at your option) any later
- version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Further information about the GNU General Public License can also be found on
- the world wide web at http://www.gnu.org.
-
-FUNCTIONAL DESCRIPTION
-------------------------------------------------------------------------------
-Database for the global weather
-This database is only called by the local database and by the weather
-simulator driving this database
-
-HISTORY
-------------------------------------------------------------------------------
-28.05.1999 Christian Mayer Created
-16.06.1999 Durk Talsma Portability for Linux
-20.06.1999 Christian Mayer added lots of consts
-30.06.1999 Christian Mayer STL portability
-11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
- suggestion
-19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
- and lots of wee code cleaning
-*****************************************************************************/
-
-/****************************************************************************/
-/* SENTRY */
-/****************************************************************************/
-#ifndef FGGlobalWeatherDatabase_H
-#define FGGlobalWeatherDatabase_H
-
-/****************************************************************************/
-/* INCLUDES */
-/****************************************************************************/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <Include/compiler.h>
-
-#include <vector>
-#include STL_IOSTREAM
-
-#include <sg.h>
-
-#include "FGPhysicalProperties.h"
-#include "FGPhysicalProperty.h"
-
-/****************************************************************************/
-/* DEFINES */
-/****************************************************************************/
-FG_USING_STD(vector);
-#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
-FG_USING_STD(iostream);
-#endif
-FG_USING_NAMESPACE(std);
-
-enum FGGlobalWeatherDatabaseStatus {
- FGGlobalWeatherDatabase_not_used,
- FGGlobalWeatherDatabase_switched_off,
- FGGlobalWeatherDatabase_only_static,
- FGGlobalWeatherDatabase_working
-};
-
-class FGGlobalWeatherDatabase;
-ostream& operator<< ( ostream& out, const FGGlobalWeatherDatabase& p );
-
-/****************************************************************************/
-/* CLASS DECLARATION */
-/****************************************************************************/
-class FGGlobalWeatherDatabase
-{
-private:
-protected:
- FGGlobalWeatherDatabaseStatus DatabaseStatus;
- FGPhysicalProperties2DVector database;
-
-public:
- /************************************************************************/
- /* Constructor and Destructor */
- /************************************************************************/
- FGGlobalWeatherDatabase(const FGGlobalWeatherDatabaseStatus s = FGGlobalWeatherDatabase_not_used);
- ~FGGlobalWeatherDatabase();
-
- /************************************************************************/
- /* Get the physical properties on the specified point p */
- /************************************************************************/
- FGPhysicalProperties get(const sgVec2& p) const;
- FGPhysicalProperty get(const sgVec3& p) const
- {
- sgVec2 temp;
- sgSetVec2( temp, p[0], p[1] );
-
- return FGPhysicalProperty( get(temp), p[3] );
- }
-
- /************************************************************************/
- /* update the database. Since the last call we had dt seconds */
- /************************************************************************/
- void update(const WeatherPrecision dt);
-
- /************************************************************************/
- /* Add a physical property on the specified point p */
- /************************************************************************/
- void add(const sgVec2& p, const FGPhysicalProperties& x);
- void add(const FGPhysicalProperties2D& x)
- {
- database.push_back(x);
- }
-
- /************************************************************************/
- /* Change the closest physical property to p. If p is further away than */
- /* tolerance I'm returning false otherwise true */
- /************************************************************************/
- bool change(const FGPhysicalProperties2D& p, const WeatherPrecision tolerance = 0.0000001);
-
- /************************************************************************/
- /* Get all stored points in the circle around p with the radius r, but */
- /* at least min points. */
- /************************************************************************/
- FGPhysicalProperties2DVector getAll(const sgVec2& p, const WeatherPrecision r, const unsigned int min = 0);
- FGPhysicalProperties2DVector getAll(const sgVec3& p, const WeatherPrecision r, const unsigned int min = 0)
- {
- sgVec2 temp;
- sgSetVec2(temp, p[0], p[1]);
-
- return getAll(temp, r, min);
- }
-
- /************************************************************************/
- /* get/set the operating status of the database */
- /************************************************************************/
- FGGlobalWeatherDatabaseStatus getDatabaseStatus(void) const { return DatabaseStatus; }
- void setDatabaseStatus(const FGGlobalWeatherDatabaseStatus& s) { DatabaseStatus = s; }
-
- /************************************************************************/
- /* Dump the whole database */
- /************************************************************************/
- friend ostream& operator<< ( ostream& out, const FGGlobalWeatherDatabase& p );
-
-};
-
-inline ostream& operator<< ( ostream& out, const FGGlobalWeatherDatabase& p )
-{
- //out << "Database status: " << DatabaseStatus << "\n";
- out << "Database number of entries: " << p.database.size() << "\n";
-
- for (FGPhysicalProperties2DVector::const_iterator it = p.database.begin(); it != p.database.end(); it++)
- out << "Next entry: " << *it;
-
- return out;
-}
-
-/****************************************************************************/
-#endif /*FGGlobalWeatherDatabase_H*/
+++ /dev/null
-/*****************************************************************************
-
- Module: FGMicroWeather.cpp
- Author: Christian Mayer
- Date started: 28.05.99
- Called by: FGLocalWeatherDatabase
-
- -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
-
- This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
- Foundation; either version 2 of the License, or (at your option) any later
- version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Further information about the GNU General Public License can also be found on
- the world wide web at http://www.gnu.org.
-
-FUNCTIONAL DESCRIPTION
-------------------------------------------------------------------------------
-Handle the weather areas
-
-HISTORY
-------------------------------------------------------------------------------
-28.05.1999 Christian Mayer Created
-16.06.1999 Durk Talsma Portability for Linux
-20.06.1999 Christian Mayer added lots of consts
-11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
- suggestion
-19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
- and lots of wee code cleaning
-*****************************************************************************/
-
-/****************************************************************************/
-/* INCLUDES */
-/****************************************************************************/
-#include <Include/compiler.h>
-#include <Include/fg_constants.h>
-
-#include "FGMicroWeather.h"
-
-/****************************************************************************/
-/********************************** CODE ************************************/
-/****************************************************************************/
-FGMicroWeather::FGMicroWeather(const FGPhysicalProperties2D& p, const positionList& points)
-{
- StoredWeather = p;
- position = points;
-}
-
-FGMicroWeather::~FGMicroWeather()
-{
-}
-
-/****************************************************************************/
-/* Add the features to the micro weather */
-/* return succss */
-/****************************************************************************/
-void FGMicroWeather::addWind(const WeatherPrecision alt, const FGWindItem& x)
-{
- StoredWeather.Wind[alt] = x;
-}
-
-void FGMicroWeather::addTurbulence(const WeatherPrecision alt, const FGTurbulenceItem& x)
-{
- StoredWeather.Turbulence[alt] = x;
-}
-
-void FGMicroWeather::addTemperature(const WeatherPrecision alt, const WeatherPrecision x)
-{
- StoredWeather.Temperature[alt] = x;
-}
-
-void FGMicroWeather::addAirPressure(const WeatherPrecision alt, const WeatherPrecision x)
-{
- cerr << "Error: caught attempt to add AirPressure which is logical wrong\n";
- //StoredWeather.AirPressure[alt] = x;
-}
-
-void FGMicroWeather::addVaporPressure(const WeatherPrecision alt, const WeatherPrecision x)
-{
- StoredWeather.VaporPressure[alt] = x;
-}
-
-void FGMicroWeather::addCloud(const WeatherPrecision alt, const FGCloudItem& x)
-{
- StoredWeather.Clouds[alt] = x;
-}
-
-void FGMicroWeather::setSnowRainIntensity(const WeatherPrecision x)
-{
- StoredWeather.SnowRainIntensity = x;
-}
-
-void FGMicroWeather::setSnowRainType(const SnowRainType x)
-{
- StoredWeather.snowRainType = x;
-}
-
-void FGMicroWeather::setLightningProbability(const WeatherPrecision x)
-{
- StoredWeather.LightningProbability = x;
-}
-
-void FGMicroWeather::setStoredWeather(const FGPhysicalProperties2D& x)
-{
- StoredWeather = x;
-}
-
-/****************************************************************************/
-/* return true if p is inside this micro weather */
-/* code stolen from $FG_ROOT/Simulator/Objects/fragment.cxx, which was */
-/* written by Curtis L. Olson - curt@me.umn.edu */
-/****************************************************************************/
-
-template <class T> //template to help with the calulation
-inline const int FG_SIGN(const T& x) {
- return x < T(0) ? -1 : 1;
-}
-
-bool FGMicroWeather::hasPoint(const sgVec2& p) const
-{
- if (position.size()==0)
- return true; //no border => this tile is infinite
-
- if (position.size()==1)
- return false; //a border on 1 point?!?
-
- //when I'm here I've got at least 2 points
-
- WeatherPrecision t;
- signed char side1, side2;
- const_positionListIt it = position.begin();
- const_positionListIt it2 = it; it2++;
-
- for (;;)
- {
-
- if (it2 == position.end())
- break;
-
- if (fabs(it->p[0] - it2->p[0]) >= FG_EPSILON)
- {
- t = (it->p[1] - it2->p[1]) / (it->p[0] - it2->p[0]);
-
- side1 = FG_SIGN (t * (StoredWeather.p[0] - it2->p[0]) + it2->p[1] - StoredWeather.p[1]);
- side2 = FG_SIGN (t * ( p[0] - it2->p[0]) + it2->p[1] - p[1]);
- if ( side1 != side2 )
- return false; //cout << "failed side check\n";
- }
- else
- {
- t = (it->p[0] - it2->p[0]) / (it->p[1] - it2->p[1]);
-
- side1 = FG_SIGN (t * (StoredWeather.p[1] - it2->p[1]) + it2->p[0] - StoredWeather.p[0]);
- side2 = FG_SIGN (t * ( p[1] - it2->p[1]) + it2->p[0] - p[0]);
- if ( side1 != side2 )
- return false; //cout << "failed side check\n";
- }
-
- it++; it2++;
- }
-
- return true;
-}
+++ /dev/null
-/*****************************************************************************
-
- Header: FGMicroWeather.h
- Author: Christian Mayer
- Date started: 28.05.99
-
- -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
-
- This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
- Foundation; either version 2 of the License, or (at your option) any later
- version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Further information about the GNU General Public License can also be found on
- the world wide web at http://www.gnu.org.
-
-FUNCTIONAL DESCRIPTION
-------------------------------------------------------------------------------
-Store the single weather areas
-
-HISTORY
-------------------------------------------------------------------------------
-28.05.1999 Christian Mayer Created
-16.06.1999 Durk Talsma Portability for Linux
-20.06.1999 Christian Mayer added lots of consts
-30.06.1999 Christian Mayer STL portability
-11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
- suggestion
-19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
- and lots of wee code cleaning
-*****************************************************************************/
-
-/****************************************************************************/
-/* SENTRY */
-/****************************************************************************/
-#ifndef FGMicroWeather_H
-#define FGMicroWeather_H
-
-/****************************************************************************/
-/* INCLUDES */
-/****************************************************************************/
-#include <set>
-
-#include "sg.h"
-#include "FGWeatherVectorWrap.h"
-
-#include "FGWeatherDefs.h"
-
-//Include all the simulated weather features
-#include "FGCloud.h"
-#include "FGSnowRain.h"
-
-#include "FGAirPressureItem.h"
-#include "FGWindItem.h"
-#include "FGTurbulenceItem.h"
-
-#include "FGPhysicalProperties.h"
-#include "FGPhysicalProperty.h"
-
-/****************************************************************************/
-/* DEFINES */
-/****************************************************************************/
-FG_USING_STD(set);
-FG_USING_NAMESPACE(std);
-
-/****************************************************************************/
-/* CLASS DECLARATION */
-/****************************************************************************/
-class FGMicroWeather
-{
-private:
-protected:
- typedef vector<sgVec2Wrap> positionList;
- typedef positionList::iterator positionListIt;
- typedef positionList::const_iterator const_positionListIt;
- positionList position; //the points that specify the outline of the
- //micro weather (lat/lon)
-
- FGPhysicalProperties2D StoredWeather; //property if nothing is specified
-
-public:
- /************************************************************************/
- /* Constructor and Destructor */
- /************************************************************************/
- FGMicroWeather(const FGPhysicalProperties2D& p, const positionList& points);
- ~FGMicroWeather();
-
- /************************************************************************/
- /* Add a feature to the micro weather */
- /************************************************************************/
- void addWind (const WeatherPrecision alt, const FGWindItem& x);
- void addTurbulence (const WeatherPrecision alt, const FGTurbulenceItem& x);
- void addTemperature (const WeatherPrecision alt, const WeatherPrecision x);
- void addAirPressure (const WeatherPrecision alt, const WeatherPrecision x);
- void addVaporPressure(const WeatherPrecision alt, const WeatherPrecision x);
- void addCloud (const WeatherPrecision alt, const FGCloudItem& x);
-
- void setSnowRainIntensity (const WeatherPrecision x);
- void setSnowRainType (const SnowRainType x);
- void setLightningProbability(const WeatherPrecision x);
-
- void setStoredWeather (const FGPhysicalProperties2D& x);
-
- /************************************************************************/
- /* get physical properties in the micro weather */
- /* NOTE: I don't neet to speify a positon as the properties don't */
- /* change in a micro weather */
- /************************************************************************/
- FGPhysicalProperties get(void) const
- {
- return FGPhysicalProperties();
- }
-
- FGPhysicalProperty get(const WeatherPrecision altitude) const
- {
- return FGPhysicalProperty(StoredWeather, altitude);
- }
-
- /************************************************************************/
- /* return true if p is inside this micro weather */
- /************************************************************************/
- bool hasPoint(const sgVec2& p) const;
- bool hasPoint(const sgVec3& p) const
- {
- sgVec2 temp;
- sgSetVec2(temp, p[0], p[1]);
-
- return hasPoint( temp );
- }
-};
-
-/****************************************************************************/
-#endif /*FGMicroWeather_H*/
+++ /dev/null
-/*****************************************************************************
-
- Module: FGVoronoi.cpp
- Author: Christian Mayer
- Date started: 28.05.99
-
- -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
-
- This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
- Foundation; either version 2 of the License, or (at your option) any later
- version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Further information about the GNU General Public License can also be found on
- the world wide web at http://www.gnu.org.
-
-FUNCTIONAL DESCRIPTION
-------------------------------------------------------------------------------
-library for Voronoi Diagram calculation based on Steven Fortune 'Sweep2'
-FGVoronoi is the wraper to feed the voronoi calulation with a vetor of points
-and any class you want, as it uses templates
-NOTE: Sweep2 didn't free *any* memory. So I'm doing what I can, but that's not
- good enough...
-
-HISTORY
-------------------------------------------------------------------------------
-30.05.99 Christian Mayer Created
-16.06.99 Durk Talsma Portability for Linux
-11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
- suggestion
-19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
- and lots of wee code cleaning
-*****************************************************************************/
-
-/****************************************************************************/
-/* INCLUDES */
-/****************************************************************************/
-#include "FGVoronoi.h"
-#include <Voronoi/voronoi.h>
-#include <Voronoi/my_memory.h>
-
-#include <Voronoi/defs.h>
-
-extern "C" {
- //forward definitions
- void voronoi(int triangulate, struct Site *(*nextsite)());
- void geominit();
- void freeinit(struct Freelist *fl, int size);
- struct Site *nextone();
- bool readsites(PointList input);
-};
-
-/****************************************************************************/
-/********************************** CODE ************************************/
-/****************************************************************************/
-FGVoronoiOutputList Voronoiate(const FGVoronoiInputList& input)
-{
- FGVoronoiOutputList ret_list;
-
- PointList p2ds;
-
- FGVoronoiInputList::const_iterator it1;
-
- //get the points
- for (it1 = input.begin(); it1 != input.end(); it1++)
- {
- p2ds.push_back(VoronoiPoint(it1->position[0], it1->position[1]));
- }
-
- cl.clear(); //make sure that it's empty
-
- if (readsites(p2ds) == false)
- return ret_list;
-
- freeinit(&sfl, sizeof *sites);
- siteidx = 0;
- geominit();
- voronoi(triangulate, nextone);
-
- _my_free();
- /*free(sites); //to prevent a *big* memory leak...
- free(ELhash); //Sweep2 didn't free *any* memory...
- free(PQhash);*/
-
- for (cellList::iterator it2 = cl.begin(); it2 != cl.end(); it2++)
- {
- it2->sort();
- it2->strip();
-
- //uncomment for debugging
- //cout << *it2;
-
- Point2DList boundary;
-
- //copy points
- PointList::iterator it3 = it2->boundary.begin();
-
- if (it3->infinity == false)
- boundary.push_back( sgVec2Wrap(it3->p) );
- else
- {
- sgVec2 direction_vector;
- sgCopyVec2(direction_vector, it3->p);
-
- it3++;
- sgAddVec2(direction_vector, it3->p);
-
- boundary.push_back( direction_vector );
- }
-
- for (; it3 != it2->boundary.end(); it3++)
- {
- boundary.push_back( sgVec2Wrap(it3->p) );
-
- }
-
- it3--;
- if (it3->infinity == true)
- {
- sgVec2 direction_vector;
- sgCopyVec2(direction_vector, it3->p);
-
- it3--;
- sgAddVec2(direction_vector, it3->p);
-
- boundary.pop_back();
- boundary.push_back(direction_vector);
- }
-
- ret_list.push_back(FGVoronoiOutput(boundary, input[it2->ID].value));
-
- }
-
- return ret_list;
-
-}
-
-extern "C"
-{
-
-/* return a single in-storage site */
-struct Site *nextone(void)
-{
- struct Site *s;
- if(siteidx < nsites)
- {
- s = &sites[siteidx];
- siteidx ++;
- return(s);
- }
- else
- return( (struct Site *)NULL);
-}
-
-
-/* sort sites on y, then x, coord */
-//int scomp(const struct Point *s1, const struct Point *s2)
-int scomp(const void *s1, const void *s2)
-{
- if(((Point*)s1) -> y < ((Point*)s2) -> y) return(-1);
- if(((Point*)s1) -> y > ((Point*)s2) -> y) return(1);
- if(((Point*)s1) -> x < ((Point*)s2) -> x) return(-1);
- if(((Point*)s1) -> x > ((Point*)s2) -> x) return(1);
- return(0);
-}
-
-
-
-/* read all sites, sort, and compute xmin, xmax, ymin, ymax */
-bool readsites(PointList input)
-{
- int i;
-
- if (input.size() == 0)
- return false; //empty array
-
- PointList::iterator It = input.begin();
-
- nsites=0;
- sites = (struct Site *) myalloc(4000*sizeof(*sites));
-
- while(It != input.end())
- {
- sites[nsites].coord.x = It->p[0];
- sites[nsites].coord.y = It->p[1];
-
- sites[nsites].sitenbr = nsites;
- sites[nsites].refcnt = 0;
- nsites ++;
- It++;
-
- if (nsites % 4000 == 0)
- sites = (struct Site *) my_realloc(sites,(nsites+4000)*sizeof(*sites));
- };
-
- qsort(sites, nsites, sizeof (*sites), scomp);
- xmin=sites[0].coord.x;
- xmax=sites[0].coord.x;
-
- for(i=1; i<nsites; i+=1)
- {
- if(sites[i].coord.x < xmin)
- xmin = sites[i].coord.x;
- if(sites[i].coord.x > xmax)
- xmax = sites[i].coord.x;
- };
-
- ymin = sites[0].coord.y;
- ymax = sites[nsites-1].coord.y;
-
- return true;
-}
-
-
-}
-
-
+++ /dev/null
-/*****************************************************************************
-
- Header: FGVoronoi.h
- Author: Christian Mayer
- Date started: 28.05.99
-
- -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
-
- This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
- Foundation; either version 2 of the License, or (at your option) any later
- version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Further information about the GNU General Public License can also be found on
- the world wide web at http://www.gnu.org.
-
-FUNCTIONAL DESCRIPTION
-------------------------------------------------------------------------------
-library for Voronoi Diagram calculation based on Steven Fortune 'Sweep2'
-FGVoronoi is the wraper to feed the voronoi calulation with a vetor of points
-and any class you want, as it uses templates
-NOTE: Sweep2 didn't free *any* memory. So I'm doing what I can, but that's not
- good enough...
-
-HISTORY
-------------------------------------------------------------------------------
-30.05.1999 Christian Mayer Created
-16.06.1999 Durk Talsma Portability for Linux
-20.06.1999 Christian Mayer added lots of consts
-30.06.1999 Christian Mayer STL portability
-11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
- suggestion
-19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
- and lots of wee code cleaning
-*****************************************************************************/
-
-/****************************************************************************/
-/* SENTRY */
-/****************************************************************************/
-#ifndef FGVoronoi_H
-#define FGVoronoi_H
-
-/****************************************************************************/
-/* INCLUDES */
-/****************************************************************************/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <Include/compiler.h>
-
-#ifdef HAVE_WINDOWS_H
-# include <windows.h>
-#endif
-
-#include <vector>
-
-#include "sg.h"
-
-#include "FGWeatherVectorWrap.h"
-#include "FGPhysicalProperties.h"
-
-/****************************************************************************/
-/* DEFINES */
-/****************************************************************************/
-FG_USING_STD(vector);
-FG_USING_NAMESPACE(std);
-
-typedef vector<sgVec2Wrap> Point2DList;
-
-struct FGVoronoiInput
-{
- sgVec2 position;
- FGPhysicalProperties2D value;
-
- FGVoronoiInput(const sgVec2& p, const FGPhysicalProperties2D& v)
- {
- sgCopyVec2(position, p);
- value = v;
- }
-};
-
-struct FGVoronoiOutput
-{
- Point2DList boundary;
- FGPhysicalProperties2D value;
-
- FGVoronoiOutput(const Point2DList& b, const FGPhysicalProperties2D& v)
- {
- boundary = b;
- value = v;
- };
-};
-
-typedef vector<FGVoronoiInput> FGVoronoiInputList;
-typedef vector<FGVoronoiOutput> FGVoronoiOutputList;
-
-/****************************************************************************/
-/* FUNCTION DECLARATION */
-/****************************************************************************/
-FGVoronoiOutputList Voronoiate(const FGVoronoiInputList& input);
-
-#endif /*FGVoronoi_H*/
+++ /dev/null
-/*****************************************************************************
-
- Module: test.cpp
- Author: Christian Mayer
- Date started: 28.05.99
- Called by: command line
-
- ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ----------
-
- This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
- Foundation; either version 2 of the License, or (at your option) any later
- version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Further information about the GNU General Public License can also be found on
- the world wide web at http://www.gnu.org.
-
-FUNCTIONAL DESCRIPTION
-------------------------------------------------------------------------------
-Test program for the weather database
-
-HISTORY
-------------------------------------------------------------------------------
-28.05.99 CM Created
-*****************************************************************************/
-
-/****************************************************************************/
-/* INCLUDES */
-/****************************************************************************/
-#include "FGLocalWeatherDatabase.h"
-#include "FGGlobalWeatherDatabase.h"
-#include "LibVoronoi/FGVoronoi.h"
-#include "FGWeatherUtils.h"
-#include <time.h>
-#include STL_IOSTREAM
-#include <vector>
-
-/****************************************************************************/
-/********************************** CODE ************************************/
-/****************************************************************************/
-int main(void)
-{
- //init local database:
-
- FGLocalWeatherDatabase local(Point3D(0,0,0), 10000, FGLocalWeatherDatabase::use_global);
- FGGlobalWeatherDatabase global(FGGlobalWeatherDatabase_working);
-
- Point3D p(0);
- Point2D p2d(0);
- FGPhysicalProperties x;
- FGPhysicalProperties2D x2d;
- FGPhysicalProperties2DVector getAllvect;
-
- cout << "\n**************** FGGlobalWeatherDatabase Test ****************\n";
- x.Temperature.insert(FGTemperatureItem(100, Celsius(10)));
- global.add(Point2D(5,5), x);
-
- x.Temperature.insert(FGTemperatureItem(110, Celsius(-10)));
- global.add(Point3D(10,10,10), x);
-
- x2d.Temperature.insert(FGTemperatureItem(90, Celsius(-20)));
- x2d.p = Point2D(10,5);
-
- global.add(x2d);
-
- getAllvect = global.getAll(p2d, 10000);
- cout << "Returned size: " << getAllvect.size() << "\n";
- getAllvect = global.getAll(p2d, 10000, 30);
- cout << "Returned size: " << getAllvect.size() << "\n";
- getAllvect = global.getAll(p, 10000);
- cout << "Returned size: " << getAllvect.size() << "\n";
- getAllvect = global.getAll(p, 10000, 3);
- cout << "Returned size: " << getAllvect.size() << "\n";
-
- cout << "Temperature: " << global.get(Point3D(5, 5, 100)).Temperature << "°C\n";
- cout << "AirPressure at 0m: " << global.get(Point3D(5, 5, 0)).AirPressure << "\n";
- cout << "AirPressure at 1000m: " << global.get(Point3D(5, 5, 1000)).AirPressure << "\n";
-
- cout << global;
-
-
- cout << "\n**************** FGMicroWeather Test ****************\n";
- vector<Point2D> points;
-
- points.push_back(Point2D(0.1, 0.1));
- points.push_back(Point2D(0.9, 0.1));
- points.push_back(Point2D(0.9, 0.9));
- points.push_back(Point2D(0.1, 0.9));
- points.push_back(Point2D(0.1, 0.1));
-
- x2d.p = Point2D(0.4, 0.4);
-
- FGMicroWeather micro(x2d, points);
-
- cout << "hasPoint 0.5, 0.5: ";
- if (micro.hasPoint(Point2D(0.5, 0.5)) == true)
- cout << "true";
- else
- cout << "false";
-
- cout << "\nhasPoint 0.9, 0.5: ";
- if (micro.hasPoint(Point2D(0.9, 0.5)) == true)
- cout << "true";
- else
- cout << "false";
-
- cout << "\nhasPoint 1.5, 0.5: ";
- if (micro.hasPoint(Point2D(1.5, 0.5)) == true)
- cout << "true";
- else
- cout << "false";
-
- cout << "\n";
-
-
- cout << "\n**************** Voronoi Diagram Test ****************\n";
- FGVoronoiInputList input;
- FGVoronoiOutputList output;
- FGVoronoiInput test(Point2D(0.0), FGPhysicalProperties2D());
-
- test.position = Point2D(0.1,0.2);
- input.push_back(test);
-
- test.position = Point2D(0.8,0.9);
- input.push_back(test);
-
- test.position = Point2D(0.9,0.1);
- input.push_back(test);
-
- test.position = Point2D(0.6,0.4);
- input.push_back(test);
-
- test.position = Point2D(1.1,1.2);
- input.push_back(test);
-
- test.position = Point2D(1.8,1.9);
- input.push_back(test);
-
- test.position = Point2D(1.9,1.1);
- input.push_back(test);
-
- test.position = Point2D(1.6,1.4);
- input.push_back(test);
-
- test.position = Point2D(2.9,2.1);
- input.push_back(test);
-
- test.position = Point2D(2.6,2.4);
- input.push_back(test);
-
- output = Voronoiate(input);
-
- cout << "\n";
- for (FGVoronoiOutputList::iterator it=output.begin(); it!=output.end(); it++)
- {
- cout << "Cell start: ";
- for (Point2DList::iterator it2= it->boundary.begin();it2!= it->boundary.end();it2++)
- {
- if (it2==it->boundary.begin())
- cout << "(";
- else
- cout << "-(";
-
- cout << *it2 << ")";
- }
- cout << "\n";
- }
-
- cout << "\n**************** Database Stress Test ****************\n";
-
- time_t starttime, currenttime;
- unsigned long count = 0;
- unsigned long count2 = 0;
- float xxx, yyy;
- cout << "Filling Database... ";
- time( &starttime );
- for (count = 0; count < 5000; count++)
- {
- xxx = (rand()%36000)/100.0;
- yyy = (rand()%18000)/100.0;
-
- local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point2D(xxx, yyy)));
- }
- local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(-10.0)));
- local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(+10.0)));
- local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(-100.0)));
- local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(+100.0)));
-
- time( ¤ttime );
- cout << float(count)/float(currenttime - starttime) << "/s filling rate; ";
- time( &starttime );
-
- for (count = 0; count < 5; count++)
- {
- local.reset(FGLocalWeatherDatabase::use_global); //make sure I've got a current voronoi
- }
-
- time( ¤ttime );
- cout << float(currenttime - starttime)/float(count) << "s resetting time; Done\n";
- count = 0;
-
- //for (;count<200;)
- cout << "local.get() test: 10 seconds\n";
- time( &starttime );
- time( ¤ttime );
- for (;currenttime<(starttime+10);)
- {
- time( ¤ttime );
- count++;
- local.get(Point3D(0.0));
- }
-
- cout << "Result: " << float(count) / float(currenttime-starttime) << "/s\n";
-
- count = 0;
- cout << "output = Voronoiate(input) test: 10 seconds\n";
- time( &starttime );
- time( ¤ttime );
- for (;currenttime<(starttime+10);)
- {
- time( ¤ttime );
- count++;
- output = Voronoiate(input);
- }
-
- cout << "Result: " << float(count) / float(currenttime-starttime) << "/s\n";
- cout << "Reference: 176800/s\n";
-
- cout << "\n**************** Database Stress Test end ****************\n";
- return 0;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-