1 /* 2 * The big star catalogue extension to Stellarium: 3 * Author and Copyright: Johannes Gajdosik, 2006, 2007 4 * The implementation of SpecialZoneArray<Star>::draw is based on 5 * Stellarium, Copyright (C) 2002 Fabien Chereau, 6 * and therefore has shared copyright. 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 21 */ 22 23 #ifndef ZONEARRAY_HPP 24 #define ZONEARRAY_HPP 25 26 #include "ZoneData.hpp" 27 #include "Star.hpp" 28 29 #include "StelCore.hpp" 30 #include "StelSkyDrawer.hpp" 31 #include "StarMgr.hpp" 32 33 #include <QString> 34 #include <QFile> 35 #include <QDebug> 36 37 #ifdef __OpenBSD__ 38 #include <unistd.h> 39 #endif 40 41 class StelPainter; 42 43 // Patch by Rainer Canavan for compilation on irix with mipspro compiler part 1 44 #ifndef MAP_NORESERVE 45 # ifdef MAP_AUTORESRV 46 # if (defined(__sgi) && defined(_COMPILER_VERSION)) 47 # define MAP_NORESERVE MAP_AUTORESRV 48 # endif 49 # else 50 # define MAP_NORESERVE 0 51 # endif 52 #endif 53 54 55 #define NR_OF_HIP 120416 56 #define FILE_MAGIC 0x835f040a 57 #define FILE_MAGIC_OTHER_ENDIAN 0x0a045f83 58 #define FILE_MAGIC_NATIVE 0x835f040b 59 #define MAX_MAJOR_FILE_VERSION 0 60 61 //! @struct HipIndexStruct 62 //! Container for Hipparcos information. Stores a pointer to a Hipparcos star, 63 //! its catalog and its triangle. 64 struct HipIndexStruct 65 { 66 const SpecialZoneArray<Star1> *a; 67 const SpecialZoneData<Star1> *z; 68 const Star1 *s; 69 }; 70 71 //! @class ZoneArray 72 //! Manages all ZoneData structures of a given StelGeodesicGrid level. An 73 //! instance of this class is never created directly; the named constructor 74 //! returns an instance of one of its subclasses. All it really does is 75 //! bootstrap the loading process. 76 class ZoneArray 77 { 78 public: 79 //! Named public constructor for ZoneArray. Opens a catalog, reads its 80 //! header info, and creates a SpecialZoneArray or HipZoneArray for 81 //! loading. 82 //! @param extended_file_name path of the star catalog to load from 83 //! @param use_mmap whether or not to mmap the star catalog 84 //! @return an instance of SpecialZoneArray or HipZoneArray 85 static ZoneArray *create(const QString &extended_file_name, bool use_mmap); ~ZoneArray()86 virtual ~ZoneArray() 87 { 88 nr_of_zones = 0; 89 } 90 91 //! Get the total number of stars in this catalog. getNrOfStars() const92 unsigned int getNrOfStars() const { return nr_of_stars; } 93 94 //! Dummy method that does nothing. See subclass implementation. updateHipIndex(HipIndexStruct hipIndex[]) const95 virtual void updateHipIndex(HipIndexStruct hipIndex[]) const {Q_UNUSED(hipIndex);} 96 97 //! Pure virtual method. See subclass implementation. 98 virtual void searchAround(const StelCore* core, int index,const Vec3d &v,double cosLimFov, 99 QList<StelObjectP > &result) = 0; 100 101 //! Pure virtual method. See subclass implementation. 102 virtual void draw(StelPainter* sPainter, int index,bool is_inside, 103 const RCMag* rcmag_table, int limitMagIndex, StelCore* core, 104 int maxMagStarName, float names_brightness, 105 const QVector<SphericalCap>& boundingCaps, 106 const bool withAberration, const Vec3f vel) const = 0; 107 108 //! Get whether or not the catalog was successfully loaded. 109 //! @return @c true if at least one zone was loaded, otherwise @c false isInitialized(void) const110 bool isInitialized(void) const { return (nr_of_zones>0); } 111 112 //! Initialize the ZoneData struct at the given index. 113 void initTriangle(int index, const Vec3f &c0, const Vec3f &c1, const Vec3f &c2); 114 115 virtual void scaleAxis() = 0; 116 117 //! File path of the catalog. 118 const QString fname; 119 120 //! Level in StelGeodesicGrid. 121 const int level; 122 123 //! Lower bound of magnitudes in this level. Units: millimag. May be negative for brightest stars. 124 const int mag_min; 125 126 //! Range of magnitudes in this level. Units: millimags 127 const int mag_range; 128 129 //! Number of steps used to describe values in @em mag_range. Always positive. Individual stars have their mag entries from 0..mag_steps. 130 const int mag_steps; 131 132 float star_position_scale; 133 134 protected: 135 //! Load a catalog and display its progress on the splash screen. 136 //! @return @c true if successful, or @c false if an error occurred 137 static bool readFile(QFile& file, void *data, qint64 size); 138 139 //! Protected constructor. Initializes fields and does not load anything. 140 ZoneArray(const QString& fname, QFile* file, int level, int mag_min, int mag_range, int mag_steps); 141 unsigned int nr_of_zones; 142 unsigned int nr_of_stars; 143 ZoneData *zones; 144 QFile* file; 145 }; 146 147 //! @class SpecialZoneArray 148 //! Implements all the virtual methods in ZoneArray. Is only separate from 149 //! %ZoneArray because %ZoneArray decides on the template parameter. 150 //! @tparam Star either Star1, Star2 or Star3, depending on the brightness of 151 //! stars in this catalog. 152 template<class Star> 153 class SpecialZoneArray : public ZoneArray 154 { 155 public: 156 //! Handles loading of the meaty part of star catalogs. 157 //! @param file catalog to load from 158 //! @param byte_swap whether to switch endianness of catalog data 159 //! @param use_mmap whether or not to mmap the star catalog 160 //! @param level level in StelGeodesicGrid 161 //! @param mag_min lower bound of magnitudes 162 //! @param mag_range range of magnitudes 163 //! @param mag_steps number of steps used to describe values in range 164 SpecialZoneArray(QFile* file,bool byte_swap,bool use_mmap,int level,int mag_min, 165 int mag_range,int mag_steps); 166 ~SpecialZoneArray(void) Q_DECL_OVERRIDE; 167 protected: 168 //! Get an array of all SpecialZoneData objects in this catalog. getZones(void) const169 SpecialZoneData<Star> *getZones(void) const 170 { 171 return static_cast<SpecialZoneData<Star>*>(zones); 172 } 173 174 //! Draw stars and their names onto the viewport. 175 //! @param sPainter the painter to use 176 //! @param index zone index to draw 177 //! @param isInsideViewport whether the zone is inside the current viewport. If false, we need to test more to skip stars. 178 //! @param rcmag_table table of magnitudes 179 //! @param limitMagIndex index from rcmag_table at which stars are not visible anymore 180 //! @param core core to use for drawing 181 //! @param maxMagStarName magnitude limit of stars that display labels 182 //! @param names_brightness brightness of labels 183 //! @param boundingCaps 184 //! @param withAberration true if aberration to be applied 185 //! @param vel velocity vector of observer planet 186 virtual void draw(StelPainter* sPainter, int index, bool isInsideViewport, 187 const RCMag *rcmag_table, int limitMagIndex, StelCore* core, 188 int maxMagStarName, float names_brightness, 189 const QVector<SphericalCap>& boundingCaps, 190 const bool withAberration, const Vec3f vel) const Q_DECL_OVERRIDE; 191 192 virtual void scaleAxis() Q_DECL_OVERRIDE; 193 virtual void searchAround(const StelCore* core, int index,const Vec3d &v,double cosLimFov, 194 QList<StelObjectP > &result) Q_DECL_OVERRIDE; 195 196 Star *stars; 197 private: 198 uchar *mmap_start; 199 }; 200 201 //! @class HipZoneArray 202 //! ZoneArray of Hipparcos stars. It's just a SpecialZoneArray<Star1> that 203 //! implements updateHipIndex(HipIndexStruct). 204 class HipZoneArray : public SpecialZoneArray<Star1> 205 { 206 public: HipZoneArray(QFile * file,bool byte_swap,bool use_mmap,int level,int mag_min,int mag_range,int mag_steps)207 HipZoneArray(QFile* file,bool byte_swap,bool use_mmap, 208 int level,int mag_min,int mag_range,int mag_steps) 209 : SpecialZoneArray<Star1>(file,byte_swap,use_mmap,level, 210 mag_min,mag_range,mag_steps) {} 211 212 //! Add Hipparcos information for all stars in this catalog into @em hipIndex. 213 //! @param hipIndex array of Hipparcos info structs 214 void updateHipIndex(HipIndexStruct hipIndex[]) const; 215 }; 216 217 #endif // ZONEARRAY_HPP 218