head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.39; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.55; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.02; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.21.58; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# newbucket.hxx

Go to the documentation of this file.

    00001 /**************************************************************************
    00002  * newbucket.hxx -- new bucket routines for better world modeling
    00003  *
    00004  * Written by Curtis L. Olson, started February 1999.
    00005  *
    00006  * Copyright (C) 1999  Curtis L. Olson - curt@@flightgear.org
    00007  *
    00008  * This library is free software; you can redistribute it and/or
    00009  * modify it under the terms of the GNU Library General Public
    00010  * License as published by the Free Software Foundation; either
    00011  * version 2 of the License, or (at your option) any later version.
    00012  *
    00013  * This library is distributed in the hope that it will be useful,
    00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00016  * Library General Public License for more details.
    00017  *
    00018  * You should have received a copy of the GNU Library General Public
    00019  * License along with this library; if not, write to the
    00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00021  * Boston, MA  02111-1307, USA.
    00022  *
    00023  * $Id: newbucket.hxx,v 1.13 2001/03/25 01:42:40 curt Exp $
    00024  **************************************************************************/
    00025
    00030 #ifndef _NEWBUCKET_HXX
    00031 #define _NEWBUCKET_HXX
    00032
    00033 #include <simgear/compiler.h>
    00034 #include <simgear/constants.h>
    00035
    00036 #ifdef SG_HAVE_STD_INCLUDES
    00037 #  include <cmath>
    00038 #  include <cstdio> // sprintf()
    00039 #else
    00040 #  include <math.h>
    00041 #  include <stdio.h> // sprintf()
    00042 #endif
    00043
    00044 #include STL_IOSTREAM
    00045
    00046 // I don't understand ... <math.h> or <cmath> should be included
    00047 // already depending on how you defined SG_HAVE_STD_INCLUDES, but I
    00048 // can go ahead and add this -- CLO
    00049 #ifdef __MWERKS__
    00050 SG_USING_STD(sprintf);
    00051 SG_USING_STD(fabs);
    00052 #endif
    00053
    00054 #include STL_STRING
    00055
    00056 SG_USING_STD(string);
    00057
    00058 #if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
    00059 SG_USING_STD(ostream);
    00060 #endif
    00061
    00062
    00066 #define SG_BUCKET_SPAN      0.125
    00067
    00071 #define SG_HALF_BUCKET_SPAN ( 0.5 * SG_BUCKET_SPAN )
    00072
    00073
    00074 // return the horizontal tile span factor based on latitude
    00075 static double sg_bucket_span( double l ) {
    00076     if ( l >= 89.0 ) {
    00077         return 360.0;
    00078     } else if ( l >= 88.0 ) {
    00079         return 8.0;
    00080     } else if ( l >= 86.0 ) {
    00081         return 4.0;
    00082     } else if ( l >= 83.0 ) {
    00083         return 2.0;
    00084     } else if ( l >= 76.0 ) {
    00085         return 1.0;
    00086     } else if ( l >= 62.0 ) {
    00087         return 0.5;
    00088     } else if ( l >= 22.0 ) {
    00089         return 0.25;
    00090     } else if ( l >= -22.0 ) {
    00091         return 0.125;
    00092     } else if ( l >= -62.0 ) {
    00093         return 0.25;
    00094     } else if ( l >= -76.0 ) {
    00095         return 0.5;
    00096     } else if ( l >= -83.0 ) {
    00097         return 1.0;
    00098     } else if ( l >= -86.0 ) {
    00099         return 2.0;
    00100     } else if ( l >= -88.0 ) {
    00101         return 4.0;
    00102     } else if ( l >= -89.0 ) {
    00103         return 8.0;
    00104     } else {
    00105         return 360.0;
    00106     }
    00107 }
    00108
    00109
    00117 class SGBucket {
    00118
    00119 private:
    00120     double cx, cy;  // centerpoint (lon, lat) in degrees of bucket
    00121     int lon;        // longitude index (-180 to 179)
    00122     int lat;        // latitude index (-90 to 89)
    00123     int x;          // x subdivision (0 to 7)
    00124     int y;          // y subdivision (0 to 7)
    00125
    00126 public:
    00127
    00131     SGBucket();
    00132
    00138     SGBucket(const double dlon, const double dlat);
    00139
    00146     SGBucket(const bool is_good);
    00147
    00151     SGBucket(const long int bindex);
    00152
    00156     ~SGBucket();
    00157
    00163     void set_bucket( double dlon, double dlat );
    00164
    00170     void set_bucket( double *lonlat );
    00171
    00178     inline void make_bad() {
    00179         set_bucket(0.0, 0.0);
    00180         lon = -1000;
    00181     }
    00182
    00198     inline long int gen_index() const {
    00199         return ((lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x;
    00200     }
    00201
    00207     inline string gen_index_str() const {
    00208         char tmp[20];
    00209         sprintf(tmp, "%ld",
    00210                 (((long)lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x);
    00211         return (string)tmp;
    00212     }
    00213
    00218     string gen_base_path() const;
    00219
    00223     inline double get_center_lon() const {
    00224         double span = sg_bucket_span( lat + y / 8.0 + SG_HALF_BUCKET_SPAN );
    00225
    00226         if ( span >= 1.0 ) {
    00227             return lon + span / 2.0;
    00228         } else {
    00229             return lon + x * span + span / 2.0;
    00230         }
    00231     }
    00232
    00236     inline double get_center_lat() const {
    00237         return lat + y / 8.0 + SG_HALF_BUCKET_SPAN;
    00238     }
    00239
    00243     double get_width() const;
    00244
    00248     double get_height() const;
    00249
    00253     double get_width_m() const;
    00254
    00258     double get_height_m() const;
    00259
    00260     // Informational methods.
    00261
    00265     inline int get_lon() const { return lon; }
    00266
    00270     inline int get_lat() const { return lat; }
    00271
    00275     inline int get_x() const { return x; }
    00276
    00280     inline int get_y() const { return y; }
    00281
    00282     // friends
    00283
    00284     friend ostream& operator<< ( ostream&, const SGBucket& );
    00285     friend bool operator== ( const SGBucket&, const SGBucket& );
    00286 };
    00287
    00288
    00299 SGBucket sgBucketOffset( double dlon, double dlat, int x, int y );
    00300
    00301
    00310 void sgBucketDiff( const SGBucket& b1, const SGBucket& b2, int *dx, int *dy );
    00311
    00312
    00318 inline ostream&
    00319 operator<< ( ostream& out, const SGBucket& b )
    00320 {
    00321     return out << b.lon << ":" << b.x << ", " << b.lat << ":" << b.y;
    00322 }
    00323
    00324
    00331 inline bool
    00332 operator== ( const SGBucket& b1, const SGBucket& b2 )
    00333 {
    00334     return ( b1.lon == b2.lon &&
    00335              b1.lat == b2.lat &&
    00336              b1.x == b2.x &&
    00337              b1.y == b2.y );
    00338 }
    00339
    00340
    00341 #endif // _NEWBUCKET_HXX
    00342
    00343

@ 1.3 log @Oops, try again. @ text @d216 1 a216 1