OpenFrames
SkySphere.hpp
Go to the documentation of this file.
1 /***********************************
2  Copyright 2018 Ravishankar Mathur
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 ***********************************/
16 
21 #ifndef _OF_SKYSPHERE_
22 #define _OF_SKYSPHERE_
23 
24 #include <OpenFrames/Export.h>
25 #include <OpenFrames/Sphere.hpp>
26 
27 #include <array>
28 
29 namespace OpenFrames
30 {
41  class OF_EXPORT SkySphere : public OpenFrames::Sphere
42  {
43  public:
45  enum DrawMode
46  {
47  NONE = 0, // Don't draw anything
48  TEXTURE = 1, // Draw provided texture
49  STARFIELD = 2 // Draw stars from provided star catalog
50  };
51 
52  struct Star
53  {
54  float ra; // Radians, 0 <= ra <= 2*PI
55  float dec; // Radians, -PI/2 <= dec <= PI/2
56  float mag, colorindex; // Nondim, unbounded
57  };
58 
59  SkySphere(const std::string &name);
60 
63  void setDrawMode(unsigned int drawMode);
64  unsigned int getDrawMode();
65 
74  bool setStarData(const std::string &catalogName, float minMag, float maxMag, unsigned int maxNumStars,
75  float minPixSize, float maxPixSize, float minDimRatio);
76 
79  static void StarToPoint(const Star &star, osg::Vec3 &pos, osg::Vec4 &color);
80 
81  // Get the Geometry bin to which a star should be assigned
82  static unsigned int getStarBin(const osg::Vec3 &p);
83 
84  protected:
85  virtual ~SkySphere(); // Must be allocated on heap using 'new'
86 
87  bool processStars(); // Load and set up all star data
88 
89  // Clear all stars
90  void clearStars();
91 
92  std::string _starCatalogFile; // File containing star catalog
93  float _minMag, _maxMag; // Range of drawn star magnitudes
94  unsigned int _maxNumStars; // Maximum number of drawn stars
95  float _minPixSize, _maxPixSize; // Limits on final star pixel size
96  float _minDimRatio; // Minimum dimming ratio for any star
97 
98  // Stars are grouped by position into star bins. Bins are arranged
99  // in a cube superscribed on the star unit sphere. Each cube face
100  // contains bins arranged in a square grid.
101  // Note that each bin does not have an equal number of stars, since
102  // the sphere->cube mapping is not evenly spaced and stars are not
103  // uniformly distributed in the sky
104 
105  // Number of bin rows (and columns) per cube face
106  static const unsigned int _starBinSpacing = 2;
107 
108  // Total number of bins for a 6-sided cube
109  static const unsigned int _starBinCount = _starBinSpacing*_starBinSpacing*6;
110 
111  // Star bins containing each set of stars
112  typedef std::array<osg::ref_ptr<osg::Geometry>, _starBinCount> StarBins;
113  StarBins _starBinGeoms;
114  osg::ref_ptr<osg::Geode> _starGeode; // Contains all StarBins
115 
116  private:
117  void _init();
118  };
119 
120 } // !namespace OpenFrames
121 
122 #endif // !define _OF_SKYSPHERE_
Extends OpenFrames::Sphere.
Definition: SkySphere.hpp:41
Definition: SkySphere.hpp:52
Definition: CoordinateAxes.hpp:29
A ReferenceFrame with a sphere at the origin.
Definition: Sphere.hpp:41
DrawMode
Definition: SkySphere.hpp:45