Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Globe.h
1 //
2 // Globe.h
3 //
4 // Copyright (c) 2001-2011 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef GLOBEH
9 #define GLOBEH
10 
11 #include "vtdata/Icosa.h"
12 #include "vtdata/Features.h"
13 #include "vtdata/FilePath.h"
14 #include "TimeEngines.h"
15 #include "GeomUtil.h"
16 
17 class vtTerrainScene;
18 
23 class GlobeLayer : public vtGroup
24 {
25 public:
26  void DestructGeometry();
27 
28  vtFeatureSet *m_pSet;
29 };
30 
32 
35 
44 class vtIcoGlobe : public DymaxIcosa, public vtTimeTarget
45 {
46 public:
47  enum Style
48  {
49  GEODESIC, INDEPENDENT_GEODESIC, RIGHT_TRIANGLE, DYMAX_UNFOLD
50  };
51 
52  // construction
53  vtIcoGlobe();
54  virtual ~vtIcoGlobe();
55 
56  void Create(int iTriangleCount, const vtString &strImagePrefix,
57  Style style = GEODESIC);
58  void Create(int iTriangleCount, vtImage **images, Style style);
59  vtTransform *GetTop() { return m_top; }
60  vtGroup *GetSurface() { return m_SurfaceGroup; }
61 
62  // control globe behavior
63  void SetInflation(float f);
64  void SetUnfolding(float f);
65  void SetCulling(bool bCull);
66  void SetLighting(bool bLight);
67  void SetTime(const vtTime &time);
68  void ShowAxis(bool bShow);
69  void SetSeasonalTilt(bool bTilt) { m_bTilt = bTilt; }
70  bool GetSeasonalTilt() { return m_bTilt; }
71  FQuat GetRotation() { return m_Rotation; }
72 
73  // surface features
74  GlobeLayerArray &GetGlobeLayers() { return m_GlobeLayers; }
75  int AddGlobeFeatures(const char *fname, float fSize);
76  void RemoveLayer(GlobeLayer *glay);
77 
78  void AddTerrainRectangles(vtTerrainScene *pTerrainScene);
79  double AddSurfaceLineToMesh(vtGeomFactory *pMF, const DPoint2 &g1, const DPoint2 &g2);
80  double AddSurfaceLineToMesh(vtGeomFactory *pMF, const DLine2 &line);
81 
82  void SetEarthMaterials(vtMaterialArray *mats);
83  vtMaterialArray *GetEarthMaterials();
84 
85 protected:
86  struct IcoVert
87  {
88  DPoint3 p;
89  FPoint2 uv;
90  };
91 
92  // Each movable face, composed of 1 to 6 subfaces of an original
93  // icosahedron face.
94  struct MFace
95  {
96  vtTransform *xform;
97  vtGeode *geode;
98  vtGroup *surfgroup;
99  FPoint3 local_origin;
100  FPoint3 axis; // axis of rotation ("hinge") for each face
101  };
102 
103  void CreateMeshMat(int iTriangleCount);
104  vtMaterialArray *CreateMaterialsFromFiles(const vtString &strImagePrefix);
105  vtMaterialArray *CreateMaterialsFromImages(vtImage **images);
106  void CreateCoreMaterials();
107  void CreateNodes();
108 
109  int GetMFace(int face, int subface);
110  void BuildSphericalFeatures(GlobeLayer *glay, float fSize);
111  void BuildSphericalPoints(GlobeLayer *glay, float fSize);
112  void BuildSphericalLines(GlobeLayer *glay, float fSize);
113  void BuildSphericalPolygons(GlobeLayer *glay, float fSize);
114  void BuildFlatFeatures(GlobeLayer *glay, float fSize);
115  void BuildFlatPoint(GlobeLayer *glay, int i, float fSize);
116 
117  void FindLocalOrigin(int mface);
118  void SetMeshConnect(int mface);
119 
120  void EstimateTesselation(int iTriangleCount);
121  void CreateUnfoldableDymax();
122  void CreateNormalSphere();
123  void CreateIndependentGeodesicSphere();
124 
125  // these methods create a mesh for each face composed of strips
126  void add_face1(vtMesh *mesh, int face, bool second);
127  void set_face_verts1(vtMesh *geom, int face, float f);
128 
129  // these methods use a right-triangle recursion to create faces
130  void add_face2(vtMesh *mesh, int face, int mface, int subfaces, bool second);
131  void set_face_verts2(vtMesh *geom, int face, float f);
132  void add_subface(vtMesh *mesh, int face, int v0, int v1, int v2,
133  bool flip, int depth);
134  void refresh_face_positions(vtMesh *mesh, int mface, float f);
135 
136  // these methods create several meshes per face
137  void create_independent_face(int face, bool second);
138  void add_face_independent_meshes(int pair, int face, bool second);
139 
140  vtIcoGlobe::Style m_style;
141 
142  // Common to all globe styles
143  vtTransform *m_top;
144  vtGroup *m_SurfaceGroup;
145  vtGeode *m_pAxisGeom;
146  vtMaterialArray *m_coremats;
147  vtMaterialArray *m_earthmats;
148  std::vector<int> m_globe_mat;
149  int m_red;
150  int m_yellow;
151  int m_white;
152  std::vector<vtMesh*> m_mesh;
153  int m_meshes; // 20 or 22 for normal or unfoldable globe
154  bool m_bUnfolded;
155  bool m_bTilt;
156  FQuat m_Rotation;
157 
158  vtMesh *m_cylinder;
159 
160  // TEMP- replace with feature layer soon
161  vtGeode *m_pRectangles;
162 
163  // for GEODESIC
164  vtGeode *m_GlobeGeom;
165  int m_freq; // tesselation frequency
166  int m_subfreq; // tesselation subfrequency
167 
168  // for RIGHT_TRIANGLE
169  int m_vert;
170  vtArray<IcoVert> m_rtv[22]; // right-triangle vertices
171  int m_depth; // tesselation depth
172 
173  // for DYMAX_UNFOLD
174  MFace m_mface[22];
175  FQuat m_diff;
176 
177  // Features (point, line, polygon..) draped on the globe
178  GlobeLayerArray m_GlobeLayers;
179 };
180 
181 vtMovGeode *CreateSimpleEarth(const vtString &strDataPath);
182 
183 void geo_to_xyz(double radius, const DPoint2 &geo, FPoint3 &p);
184 void geo_to_xyz(double radius, const DPoint2 &geo, DPoint3 &p);
185 void xyz_to_geo(double radius, const FPoint3 &p, DPoint3 &geo);
186  // Group terrain
188 
189 #endif // GLOBEH
190