misc
nasal
props
- route
serial
structure
threads
+++ /dev/null
-routetest
-waytest
+++ /dev/null
-
-include (SimGearComponent)
-
-set(HEADERS
- route.hxx
- waypoint.hxx
- )
-
-set(SOURCES
- route.cxx
- waypoint.cxx
- )
-
-simgear_component(route route "${SOURCES}" "${HEADERS}")
\ No newline at end of file
+++ /dev/null
-// route.cxx -- Class to manage a list of waypoints (route)
-//
-// Written by Curtis Olson, started October 2000.
-//
-// Copyright (C) 2000 Curtis L. Olson - curt@hfrl.umn.edu
-//
-// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// $Id$
-
-#ifdef HAVE_CONFIG_H
-# include <simgear_config.h>
-#endif
-
-#include "route.hxx"
-
-
-// constructor
-SGRoute::SGRoute() {
- route.clear();
-}
-
-
-// destructor
-SGRoute::~SGRoute() {
-}
-
-/** Update the length of the leg ending at waypoint index */
-void SGRoute::update_distance_and_track(int index)
-{
- SGWayPoint& curr = route[ index ];
- double course, dist;
-
- if ( index == 0 ) {
- dist = 0;
- course = 0.0;
- } else {
- const SGWayPoint& prev = route[index - 1];
- curr.CourseAndDistance( prev, &course, &dist );
- }
-
- curr.set_distance(dist);
- curr.set_track(course);
-}
-
-/**
- * Add waypoint (default), or insert waypoint at position n.
- * @param wp a waypoint
- */
-void SGRoute::add_waypoint( const SGWayPoint &wp, int n ) {
- int size = route.size();
- if ( n < 0 || n >= size ) {
- n = size;
- route.push_back( wp );
- } else {
- route.insert( route.begin() + n, 1, wp );
- // update distance of next leg if not at end of route
- update_distance_and_track( n + 1 );
- }
- update_distance_and_track( n );
-}
-
-/** Delete waypoint with index n (last one if n < 0) */
-void SGRoute::delete_waypoint( int n ) {
- int size = route.size();
- if ( size == 0 )
- return;
- if ( n < 0 || n >= size )
- n = size - 1;
-
- route.erase( route.begin() + n );
- // update distance of next leg if not at end of route
- if ( n < size - 1 )
- update_distance_and_track( n );
-}
-
-double SGRoute::total_distance() const {
- double total = 0.0;
- for (unsigned int i=0; i<route.size(); ++i) {
- total += route[i].get_distance();
- }
- return total;
-}
+++ /dev/null
-/**
- * \file route.hxx
- * Provides a class to manage a list of waypoints (i.e. a route).
- */
-
-// Written by Curtis Olson, started October 2000.
-//
-// Copyright (C) 2000 Curtis L. Olson - curt@hfrl.umn.edu
-//
-// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// $Id$
-
-
-#ifndef _ROUTE_HXX
-#define _ROUTE_HXX
-
-
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-#include <simgear/compiler.h>
-
-#include <vector>
-
-using std::vector;
-
-#include <simgear/route/waypoint.hxx>
-
-/**
- * A class to manage a list of waypoints (i.e. a route).
- */
-
-class SGRoute {
-
-private:
-
- typedef vector < SGWayPoint > route_list;
- route_list route;
- int current_wp;
-
- void update_distance_and_track(int index);
-
-public:
-
- /** Constructor */
- SGRoute();
-
- /** Destructor */
- ~SGRoute();
-
- /** Clear the entire route */
- inline void clear() {
- route.clear();
- current_wp = 0;
- }
-
- /**
- * Add waypoint (default), or insert waypoint at position n.
- * @param wp a waypoint
- */
- void add_waypoint( const SGWayPoint &wp, int n = -1 );
- /**
- * Get the number of waypoints (i.e. route length )
- * @return route length
- */
- inline int size() const { return route.size(); }
-
- /**
- * Get the front waypoint.
- * @return the first waypoint.
- */
- inline SGWayPoint get_first() const {
- if ( route.size() ) {
- return route[0];
- } else {
- return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
- }
- }
-
- /**
- * Get the current waypoint
- * @return the current waypoint
- */
- inline SGWayPoint get_current() const {
- if ( current_wp < (int)route.size() ) {
- return route[current_wp];
- } else {
- return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
- }
- }
-
- inline SGWayPoint get_previous() const {
- if ( (current_wp > 0) && (current_wp < (int)route.size()) ) {
- return route[current_wp - 1];
- } else {
- return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
- }
- }
-
- inline SGWayPoint get_next() const {
- if ( (current_wp + 1) < (int)route.size() ) {
- return route[current_wp+1];
- } else {
- return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
- }
- }
-
- /**
- * Set the current waypoint
- * @param number of waypoint to make current.
- */
- inline void set_current( int n ) {
- if ( n >= 0 && n < (int)route.size() ) {
- current_wp = n;
- }
- }
-
- inline int current_index() const {
- return current_wp;
- }
-
- /** Increment the current waypoint pointer. */
- inline void increment_current() {
- if ( current_wp < (int)route.size() - 1 ) {
- ++current_wp;
- }
- }
-
- /**
- * Get the nth waypoint
- * @param n waypoint number
- * @return the nth waypoint
- */
- inline SGWayPoint get_waypoint( const int n ) const {
- if ( n < (int)route.size() ) {
- return route[n];
- } else {
- return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
- }
- }
-
- /** Delete the front waypoint */
- inline void delete_first() { delete_waypoint(0); }
-
- /** Delete waypoint waypoint with index n (last one if n < 0) */
- void delete_waypoint( int n = 0 );
-
- /**
- * Helper, sum the distance members of each waypoint
- */
- double total_distance() const;
-};
-
-
-#endif // _ROUTE_HXX
+++ /dev/null
-#include <simgear/compiler.h>
-#include <simgear/constants.h>
-
-#include <iostream>
-
-#include "route.hxx"
-#include "waypoint.hxx"
-
-using std::cout;
-using std::endl;
-
-void dump_route(const SGRoute& route, const char* message)
-{
- cout << "Route dump: " << message << endl;
- for (int i = 0; i < route.size(); i++) {
- const SGWayPoint wp = route.get_waypoint(i);
- cout << "\t#" << i << " " << wp.get_id() << " (" << wp.get_target_lat()
- << ", " << wp.get_target_lon() << ") @" << wp.get_target_alt()
- << " dist: " << wp.get_distance() << endl;
- }
-}
-
-int main()
-{
- SGRoute route;
-/*
- route.add_waypoint( SGWayPoint(0, 0, 0, SGWayPoint::CARTESIAN, "Start") );
- route.add_waypoint( SGWayPoint(1, 0, 0, SGWayPoint::CARTESIAN, "1") );
- route.add_waypoint( SGWayPoint(2, 0, 0, SGWayPoint::CARTESIAN, "2") );
- route.add_waypoint( SGWayPoint(2, 2, 0, SGWayPoint::CARTESIAN, "3") );
- route.add_waypoint( SGWayPoint(4, 2, 0, SGWayPoint::CARTESIAN, "4") );
-
- dump_route(route, "Init");
- route.set_current( 1 );
-
- cout << "( 0.5, 0 ) = " << route.distance_off_route( 0.5, 0 ) << endl;
- cout << "( 0.5, 1 ) = " << route.distance_off_route( 0.5, 1 ) << endl;
- cout << "( 0.5, -1 ) = " << route.distance_off_route( 0.5, 1 ) << endl;
-
- route.set_current( 3 );
-
- cout << "( 2, 4 ) = " << route.distance_off_route( 2, 4 ) << endl;
- cout << "( 2.5, 4 ) = " << route.distance_off_route( 2.5, 4 ) << endl;
-
- SGWayPoint wp2 = route.get_waypoint(2);
- route.delete_waypoint(2);
- dump_route(route, "removed WP2");
-
- route.add_waypoint(wp2, 3);
- dump_route(route, "added back WP2 after WP3");
-*/
- return 0;
-}
+++ /dev/null
-// waypoint.cxx -- Class to hold data and return info relating to a waypoint
-//
-// Written by Curtis Olson, started September 2000.
-//
-// Copyright (C) 2000 Curtis L. Olson - curt@hfrl.umn.edu
-//
-// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// $Id$
-
-#ifdef HAVE_CONFIG_H
-# include <simgear_config.h>
-#endif
-
-#include <simgear/math/sg_geodesy.hxx>
-
-#include "waypoint.hxx"
-
-using std::string;
-
-// Constructor
-SGWayPoint::SGWayPoint( const double lon, const double lat, const double alt,
- const modetype, const string& s, const string& n ) :
- pos(SGGeod::fromDegM(lon, lat, alt)),
- id(s),
- name(n),
- _distance(0.0),
- _track(0.0),
- _speed(0.0)
-{
-}
-
-SGWayPoint::SGWayPoint(const SGGeod& geod, const string& s, const string& n ) :
- pos(geod),
- id(s),
- name(n),
- _distance(0.0),
- _track(0.0),
- _speed(0.0)
-{
-}
-
-// Destructor
-SGWayPoint::~SGWayPoint() {
-}
-
-void SGWayPoint::CourseAndDistance(const SGGeod& cur, double& course, double& dist ) const {
- double reverse;
- SGGeodesy::inverse(cur, pos, course, reverse, dist);
-}
-
-// Calculate course and distances. For WGS84 and SPHERICAL
-// coordinates lat, lon, and course are in degrees, alt and distance
-// are in meters. For CARTESIAN coordinates x = lon, y = lat. Course
-// is in degrees and distance is in what ever units x and y are in.
-void SGWayPoint::CourseAndDistance( const double cur_lon,
- const double cur_lat,
- const double cur_alt,
- double *course, double *dist ) const {
- CourseAndDistance(SGGeod::fromDegM(cur_lon, cur_lat, cur_alt), *course, *dist);
-}
-
-// Calculate course and distances between two waypoints
-void SGWayPoint::CourseAndDistance( const SGWayPoint &wp,
- double *course, double *dist ) const {
- CourseAndDistance( wp.get_target(), *course, *dist );
-}
+++ /dev/null
-/**
- * \file waypoint.hxx
- * Provides a class to manage waypoints
- */
-
-// Written by Curtis Olson, started September 2000.
-//
-// Copyright (C) 2000 Curtis L. Olson - curt@hfrl.umn.edu
-//
-// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// $Id$
-
-
-#ifndef _WAYPOINT_HXX
-#define _WAYPOINT_HXX
-
-#include <simgear/compiler.h>
-
-#include <simgear/math/SGMath.hxx>
-#include <simgear/math/SGGeod.hxx>
-
-#include <string>
-
-
-/**
- * A class to manage waypoints.
- */
-
-class SGWayPoint {
-
-public:
-
- /**
- * Waypoint mode.
- * <li> WGS84 requests all bearing and distance math be done assuming a
- * WGS84 ellipsoid world. This is the most expensive computationally,
- * but also the most accurate.
- * <li> SPHERICAL requests all bearing and distance math be done assuming
- * the world is a perfect sphere. This is less compuntationally
- * expensive than using wgs84 math and still a fairly good
- * approximation of the real world, especially over shorter distances.
- */
- enum modetype {
- WGS84 = 0,
- };
-
-private:
- SGGeod pos;
- std::string id;
- std::string name;
-
- // route data associated with the waypoint
- double _distance;
- double _track;
- double _speed;
-
-public:
-
- /**
- * Construct a waypoint
- * @param lon destination longitude
- * @param lat destination latitude
- * @param alt target altitude
- * @param mode type of coordinates/math to use
- * @param s waypoint identifier
- * @param n waypoint name
- */
- SGWayPoint( const double lon = 0.0, const double lat = 0.0,
- const double alt = 0.0, const modetype m = WGS84,
- const std::string& s = "", const std::string& n = "" );
-
- /**
- * Construct from a geodetic position, in WGS84 coordinates
- */
- SGWayPoint(const SGGeod& pos, const std::string& s, const std::string& n);
-
- /** Destructor */
- ~SGWayPoint();
-
- /**
- * Calculate course and distances. For WGS84 and SPHERICAL
- * coordinates lat, lon, and course are in degrees, alt and
- * distance are in meters. For CARTESIAN coordinates x = lon, y =
- * lat. Course is in degrees and distance is in what ever units x
- * and y are in.
- * @param cur_lon (in) current longitude
- * @param cur_lat (in) current latitude
- * @param cur_alt (in) current altitude
- * @param course (out) heading from current location to this waypoint
- * @param dist (out) distance from current location to this waypoint
- */
- void CourseAndDistance( const double cur_lon, const double cur_lat,
- const double cur_alt,
- double *course, double *dist ) const;
-
- void CourseAndDistance(const SGGeod& current,
- double& course, double& dist ) const;
-
- /**
- * Calculate course and distances between a specified starting waypoint
- * and this waypoint.
- * @param wp (in) original waypoint
- * @param course (out) heading from current location to this waypoint
- * @param dist (out) distance from current location to this waypoint
- */
- void CourseAndDistance( const SGWayPoint &wp,
- double *course, double *dist ) const;
-
- /** @return waypoint longitude */
- inline double get_target_lon() const { return pos.getLongitudeDeg(); }
-
- /** @return waypoint latitude */
- inline double get_target_lat() const { return pos.getLatitudeDeg(); }
-
- /** @return waypoint altitude */
- inline double get_target_alt() const { return pos.getElevationM(); }
-
- inline const SGGeod& get_target() const { return pos; }
-
- /**
- *
- */
- inline void setTargetAltFt(double elev)
- { pos.setElevationFt(elev); }
-
- /**
- * This value is not calculated by this class. It is simply a
- * placeholder for the user to stash a distance value. This is useful
- * when you stack waypoints together into a route. You can calculate the
- * distance from the previous waypoint once and save it here. Adding up
- * all the distances here plus the distance to the first waypoint gives you
- * the total route length. Note, you must update this value yourself, this
- * is for your convenience only.
- * @return waypoint distance holder (what ever the user has stashed here)
- */
- inline double get_distance() const { return _distance; }
-
- /**
- * Set the waypoint distance value to a value of our choice.
- * @param d distance
- */
- inline void set_distance( double d ) { _distance = d; }
-
- inline double get_track() const { return _track; }
- inline void set_track(double t) { _track = t; }
-
- inline double get_speed() const { return _speed; }
- inline void set_speed(double v) { _speed = v; }
-
- /** @return waypoint id */
- inline const std::string& get_id() const { return id; }
-
- /** @return waypoint name */
- inline const std::string& get_name() const { return name; }
-
-};
-
-
-#endif // _WAYPOINT_HXX
+++ /dev/null
-#include <simgear/compiler.h>
-#include <simgear/constants.h>
-
-#include <iostream>
-
-#include "waypoint.hxx"
-
-using std::cout;
-using std::endl;
-
-int main() {
- SGWayPoint a1(-93.216923, 44.880547, 0.0, SGWayPoint::WGS84, "KMSP");
-
-
- // KMSN (Madison)
- double cur_lon = -89.336939;
- double cur_lat = 43.139541;
- double cur_alt = 0.0;
-
- double course, distance;
-
- a1.CourseAndDistance( cur_lon, cur_lat, cur_alt, &course, &distance );
- cout << "Course to " << a1.get_id() << " is " << course << endl;
- cout << "Distance to " << a1.get_id() << " is " << distance * SG_METER_TO_NM
- << endl;
-
- SGWayPoint b1(-88.237037, 43.041038, 0.0, SGWayPoint::WGS84, "KUES");
-
-
- b1.CourseAndDistance( cur_lon, cur_lat, cur_alt, &course, &distance );
- cout << "Course to " << b1.get_id() << " is " << course << endl;
- cout << "Distance to " << b1.get_id() << " is " << distance * SG_METER_TO_NM
- << endl;
-
- cout << endl;
-
- return 0;
-}