Updraft  1.0
Open source glider flight visualisation tool.
oaengine.h
Go to the documentation of this file.
00001 #ifndef UPDRAFT_SRC_PLUGINS_AIRSPACES_OAENGINE_H_
00002 #define UPDRAFT_SRC_PLUGINS_AIRSPACES_OAENGINE_H_
00003 
00004 
00005 #include <math.h>
00006 #include <osgDB/ReadFile>
00007 #include <osg/LineWidth>
00008 #include <osgEarthUtil/ObjectPlacer>
00009 #include <osg/PositionAttitudeTransform>
00010 #include <osg/Geometry>
00011 #include <osg/Depth>
00012 #include <QString>
00013 #include <QtGui>
00014 #include <osgEarthUtil/ElevationManager>
00015 
00016 #include "../../pluginbase.h"
00017 #include "../../libraries/openairspace/openairspace.h"
00018 #include "../../maplayerinterface.h"
00019 #include "../../core/maplayer.h"
00020 
00021 
00022 
00023 namespace Updraft {
00024 namespace Airspaces {
00025 
00026 
00027 typedef OpenAirspace::Coordinate Position;
00028 
00031 static const double DEG_TO_RAD = 0.017453292519943295769236907684886;
00032 static const double RAD_TO_DEG = 1/DEG_TO_RAD;
00033 
00035 static const int NM_TO_M = 1852;
00036 static const double M_TO_NM = 1./1852;
00037 
00039 static const double FT_TO_M = 0.3048;
00040 static const double M_TO_FT = 1/0.3048;
00041 
00043 static const double EARTH_RADIUS_IN_METERS = 6372797.560856;
00044 
00046 static const double M_2PI = 2*M_PI;
00047 
00049 static const double ARC_GRANULARITY = 0.05;
00050 
00052 static const float DEFAULT_TRANSPARENCY = 0.1f;
00053 
00055 static const int GND = 0;
00056 static const int ROOF = 80000;
00057 
00058 
00060 class oaEngine {
00061  public:
00065   oaEngine(MapLayerGroupInterface* LG, CoreInterface* g_core);
00066 
00074   QVector<QPair<osg::Node*, QString> > * Draw(const QString& fileName);
00075 
00079   QVector<MapLayerInterface*>* DrawII(const QString&);
00080 
00081  private:
00083   MapLayerGroupInterface *mapLayerGroup;
00084 
00086   QVector<QTreeWidgetItem*> treeItems;
00087 
00089   osg::Geode* OAGeode;
00090 
00092   osgEarth::Util::ElevationManager* elevationMan;
00093 
00095   QVector<QPair<osg::Node*, QString> > * mapLayers;
00096 
00098   SettingInterface* testSetting;
00099 
00102   float width;
00103   osg::Vec4f col;
00104 
00107   Position* heightRefPoint;
00108 
00113   bool USE_POINTWISE_ELEVATION;
00117   float ELEV_TILE_RESOLUTION;
00120   bool DRAW_UNDERGROUND;
00122   bool TOP_FACE;
00124   bool BOTTOM_FACE;
00126   bool SIDE_FACE;
00128   bool TOP_WIREFRAME;
00130   bool BOTTOM_WIREFRAME;
00132   bool SIDE_WIREFRAME;
00134   bool SIDE_COL_GRADIENT;
00136   float POLY_OPACITY_BOTTOM;
00137   float POLY_OPACITY_TOP;
00139   float WIRE_OPACITY_BOTTOM;
00140   float WIRE_OPACITY_TOP;
00142   int GND;
00143   int ROOF;
00144 
00145 
00152   QVector<double>* ComputeHeightData(
00153   int* floor, int* ceiling,
00154   bool* floorAgl, bool* ceilingAgl,
00155   Position* heightRefPoint,
00156   OpenAirspace::Airspace* A,
00157   QVector<Position>* pointsWGS);
00158 
00160   void FillOGLArrays(
00161   QVector<Position>* pointsWGS,
00162   QVector<double>* pointsGnd,
00163   int floor, int ceiling,
00164   bool floorAgl, bool ceilingAgl);
00165 
00167   osg::Geode* FindLayer(const QString& name);
00168 
00170   void PushLayer(osg::Geode* geode, const QString& displayName);
00171 
00173   osg::Geometry* DrawPolygon(
00174     QVector<Position>* pointsWGS,  // list of WGS polygon points
00175     const QVector<double>* pointsGnd,  // list of the groud levels
00176     osg::Vec4& col,   // colour of the vertices
00177     osg::PrimitiveSet::Mode primitive,  // drawing mode
00178     int height, bool agl, bool cw);   // height, orientation
00179 
00181   osg::Geometry* DrawPolygonSides(
00182     const QVector<Position>* pointsWGS,
00183     const QVector<double>* pointsGnd,
00184     osg::Vec4& colBot, osg::Vec4& colTop,
00185     osg::PrimitiveSet::Mode primitive,
00186     const int floor, const int ceiling,
00187     const bool floorAgl, const bool ceilingAgl);
00188 
00190   double DistToAngle(double dist);
00191 
00193   double ArcInRadians(const Position& from, const Position& to);
00194 
00196   double DistanceInMeters(const Position& from, const Position& to);
00197 
00199   void InsertArcI(const OpenAirspace::ArcI& aa,
00200     QVector<Position>* vertexList);
00201   void InsertArcII(const OpenAirspace::ArcII& aa,
00202     QVector<Position>* vertexList);
00203   // void InsertArcII(const Position& centre, const Position& start,
00204   //   const Position& end, bool cw, QVector<Position>* vertexList);
00205   void InsertCircle(const OpenAirspace::Circle& cc,
00206     QVector<Position>* vertexList);
00207 
00209   void InsertMidArc(const Position& centre, double from,
00210     double to, const bool cw, const double& r,
00211     QVector<Position>* vertexList);
00212 
00215   double AngleRad(const Position& centre, const Position& point);
00216 
00219   double AngleRadPos(const Position& centre, const Position& point);
00220 
00222   Position ComputeArcPoint(const Position& centre, double r, double partAngle);
00223   // double Dot(const osg::Vec2d&, const osg::Vec2d&);
00224 
00226   void SetWidthAndColour(const OpenAirspace::Airspace* A);
00227 
00229   bool IsPolyOrientationCW(QVector<Position>* pointsWGS);
00230 };  // oaEngine
00231 }  // Airspaces
00232 }  // Updraft
00233 
00234 #endif  // UPDRAFT_SRC_PLUGINS_AIRSPACES_OAENGINE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines