VR-Forces 4.2 Class Documentation
TXPArchive.h
Go to the documentation of this file.
1 /***************************************************************************
2  * December 2003
3  *
4  * This TerraPage loader was re-written in a fashion to use PagedLOD
5  * to manage paging entirely, also includes a version of Terrex's smart mesh
6  * adapted to work with PagedLOD. The essential code by Boris Bralo is still present,
7  * slight modified.
8  * nick at terrex dot com
9  *
10  * Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield
11  *****************************************************************************/
12 
13 /***************************************************************************
14  * OpenSceneGraph loader for Terrapage format database
15  * by Boris Bralo 2002
16  *
17  * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
18  *
19  * This loader is based on/modified from Terrain Experts Performer Loader,
20  * and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net
21  *
22  * That loader is redistributed under the terms listed on Terrain Experts
23  * website (www.terrex.com/www/pages/technology/technologypage.htm)
24  *
25  * "TerraPage is provided as an Open Source format for use by anyone...
26  * We supply the TerraPage C++ source code free of charge. Anyone
27  * can use it and redistribute it as needed (including our competitors).
28  * We do, however, ask that you keep the TERREX copyrights intact."
29  *
30  * Copyright Terrain Experts Inc. 1999.
31  * All Rights Reserved.
32  *
33  *****************************************************************************/
34 #ifndef __TXPARCHIVE_H_
35 #define __TXPARCHIVE_H_
36 
37 #include "trpage_sys.h"
38 #include "trpage_read.h"
39 #include "trpage_geom.h"
40 
41 #include <osg/Referenced>
42 #include <osg/BoundingBox>
43 #include <osg/Texture2D>
44 #include <osg/StateSet>
45 #include <osg/Node>
46 #include <osg/PagedLOD>
47 #include <osg/Array>
48 #include <osgSim/LightPointNode>
49 #include <osgText/Font>
50 
51 #include <OpenThreads/Mutex>
52 
53 namespace txp
54 {
57  {
59  osg::ref_ptr<osgSim::LightPointNode> lightPoint;
60  osg::ref_ptr<osg::StateSet> fallback;
61  osg::Vec3 attitude;
62  };
63 
64  class TXPParser;
65  class DT_DLL_osgdb_vrftxt TXPArchive : public trpgr_Archive, public osg::Referenced
66  {
67  public:
69  TXPArchive();
70 
72  bool openFile(const std::string& archiveName);
74  bool loadMaterials();
75  bool loadMaterial(int ix);
76  bool loadTexture(int i);
77 
79  bool loadModels();
80  bool loadModel(int ix);
81 
83  bool loadLightAttributes();
84 
86  bool loadTextStyles();
87  inline std::map<int, osg::ref_ptr<osgText::Font> >& getStyles()
88  {
89  return _fonts;
90  }
91  inline std::map<int, osg::Vec4 >& getTextColors()
92  {
93  return _fcolors;
94  }
95 
97  void addLightAttribute(osgSim::LightPointNode* lpn, osg::StateSet* fallback , const osg::Vec3& attitude,int handle);
98 
99  int getNumLightAttributes()
100  {
101  return _lights.size();
102  }
103 
105  inline DeferredLightAttribute& getLightAttribute(unsigned int i)
106  {
107  return _lights[i];
108  };
109 
111  struct TileInfo
112  {
113  osg::Vec3 center;
114  double minRange;
115  double maxRange;
116  double lod0Range;
117  float radius;
118  osg::Vec3 size;
119  osg::BoundingBox bbox;
120  };
122  {
123  TileLocationInfo() : x( -1 ), y( -1 ), lod( -1 )
124  {}
125  TileLocationInfo(int gx, int gy, int glod, const trpgwAppAddress& gaddr, float gzmin = 0.0f, float gzmax = 0.0f):
126  x( gx ), y( gy ), lod( glod ), addr( gaddr ), zmin( gzmin ), zmax( gzmax )
127  {}
128  int x, y, lod;
130  float zmin, zmax;
131  };
132 
133  bool getTileInfo(int x, int y, int lod, TileInfo& info);
134  bool getTileInfo(const TileLocationInfo& loc, TileInfo& info);
135 
137  inline void setId(int id)
138  {
139  _id = id;
140  }
141  inline const int& getId() const
142  {
143  return _id;
144  }
145 
147  inline const int& getNumLODs() const
148  {
149  return _numLODs;
150  }
151 
154  void getExtents(osg::BoundingBox& extents);
158 
160  inline void getOrigin(double& x, double& y)
161  {
162  x=_swExtents.x;
163  y=_swExtents.y;
164  }
165 
167  inline osg::Texture2D* getGlobalTexture(int id)
168  {
169  return GetTexMapEntry(id).get();
170  }
171 
176  osg::Group* getTileContent(
177  int x,
178  int y,
179  int lod,
180  double realMinRange,
181  double realMaxRange,
182  double usedMaxRange,
183  osg::Vec3& tileCenter,
184  std::vector<TileLocationInfo>& childInfoList);
185 
187  osg::Group* getTileContent(
188  const TileLocationInfo& loc,
189  double realMinRange,
190  double realMaxRange,
191  double usedMaxRange,
192  osg::Vec3& tileCenter,
193  std::vector<TileLocationInfo>& childInfoList);
194 
196  bool getLODSize(int lod, int& x, int& y);
197 
198  void GetVersion(int& majorVer, int& minorVer) const
199  {
200  majorVer = _majorVersion;
201  minorVer = _minorVersion;
202  }
203 
207  //
211  void SetUserDataToMaterialAttributes(osg::StateSet& osg_state_set, const trpgMaterial& mat)
212  {
213  if(!_loadMaterialsToStateSet)
214  return;
215 
216  int attr_values = 0;
217  osg::ref_ptr<osg::IntArray> ourValueArray = new osg::IntArray();
218  for(int attrIter = 0 ; attrIter < 4; ++attrIter)
219  {
220  mat.GetAttr(attrIter, attr_values);
221  ourValueArray->push_back(attr_values);
222  }
223  osg_state_set.setUserData(ourValueArray.get());
224  }
225 
226  void SetMaterialAttributesToStateSetVar(bool value) {_loadMaterialsToStateSet = value;}
227 
229  static void setShouldLoadDisplayData(bool);
230  static bool shouldLoadDisplayData();
231  static void setExternalLoadOptions(osg::ref_ptr<osgDB::ReaderWriter::Options> opts);
232  static osg::ref_ptr<osgDB::ReaderWriter::Options> externalLoadOptions();
233 
234  protected:
235 
237  virtual ~TXPArchive();
238 
240  int _id;
241 
243  int _numLODs;
244 
248 
250  osg::ref_ptr<TXPParser> _parser;
251 
253  typedef std::map<int,osg::ref_ptr<osg::Texture2D> > OSGTexMapType;
255 
256  void SetTexMap(int key,osg::ref_ptr<osg::Texture2D> ref);
257  osg::ref_ptr<osg::Texture2D> GetTexMapEntry(int key);
258 
259 
261  typedef std::map<int,osg::ref_ptr<osg::StateSet> > OSGStatesMapType;
263 
264  void SetStatesMap(int key,osg::ref_ptr<osg::StateSet> ref);
265  osg::ref_ptr<osg::StateSet> GetStatesMapEntry(int key);
266 
268  typedef std::map<int,osg::ref_ptr<osg::Node> > OSGModelsMapType;
270 
272  std::map<int, DeferredLightAttribute> _lights;
273 
275  std::map<int, osg::ref_ptr<osgText::Font> > _fonts;
276 
278  std::map<int, osg::Vec4 > _fcolors;
279 
280  //
281  OpenThreads::Mutex _mutex;
282 
284  int _majorVersion, _minorVersion;
285 
286  bool _isMaster;
287 
289 
290  };
291 
292 }
293 
294 #endif
295 
296 

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)