VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  {
61  osg::Vec3 attitude;
62  };
63 
64  class TXPParser;
65  class DT_DLL_osgdb_vrftxp 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 
100  {
101  return _lights.size();
102  }
103 
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 
237  static void setShouldLoadLocalMaterials(bool);
238  static bool shouldLoadLocalMaterials();
239 
240  protected:
241 
243  virtual ~TXPArchive();
244 
246  int _id;
247 
249  int _numLODs;
250 
254 
257 
259  typedef std::map<int,osg::ref_ptr<osg::Texture2D> > OSGTexMapType;
261 
262  void SetTexMap(int key,osg::ref_ptr<osg::Texture2D> ref);
263  osg::ref_ptr<osg::Texture2D> GetTexMapEntry(int key);
264 
265 
267  typedef std::map<int,osg::ref_ptr<osg::StateSet> > OSGStatesMapType;
269 
270  void SetStatesMap(int key,osg::ref_ptr<osg::StateSet> ref);
271  osg::ref_ptr<osg::StateSet> GetStatesMapEntry(int key);
272 
274  typedef std::map<int,osg::ref_ptr<osg::Node> > OSGModelsMapType;
276 
278  std::map<int, DeferredLightAttribute> _lights;
279 
281  std::map<int, osg::ref_ptr<osgText::Font> > _fonts;
282 
284  std::map<int, osg::Vec4 > _fcolors;
285 
286  //
288 
290  int _majorVersion, _minorVersion;
291 
292  bool _isMaster;
293 
295 
296  };
297 
298 }
299 
300 #endif
301 
302 
Definition: TXPArchive.h:65
bool GetAttr(int attrCode, int &val) const
Get an attribute (e.g. fid/smc)
int _numLODs
Number of the LODs.
Definition: TXPArchive.h:249
int _minorVersion
Definition: TXPArchive.h:290
std::map< int, osg::ref_ptr< osg::Node > > OSGModelsMapType
Models.
Definition: TXPArchive.h:274
osg::Texture2D * getGlobalTexture(int id)
Returns global texture.
Definition: TXPArchive.h:167
#define DT_DLL_osgdb_vrftxp
Contains DLL export macros.
Definition: osgdb_vrftxpDefines.h:25
void SetUserDataToMaterialAttributes(osg::StateSet &osg_state_set, const trpgMaterial &mat)
This section brought to you by A.
Definition: TXPArchive.h:211
const int & getId() const
Definition: TXPArchive.h:141
std::map< int, osg::Vec4 > _fcolors
Text colors.
Definition: TXPArchive.h:284
this one handles different placement of light direction in osg and terrapage
Definition: TXPArchive.h:56
trpg2dPoint _neExtents
Definition: TXPArchive.h:253
OSGModelsMapType _models
Definition: TXPArchive.h:275
bool _loadMaterialsToStateSet
Definition: TXPArchive.h:294
Gets some informations for a given tile.
Definition: TXPArchive.h:111
std::map< int, osg::ref_ptr< osgText::Font > > & getStyles()
Definition: TXPArchive.h:87
double minRange
Definition: TXPArchive.h:114
int y
Definition: TXPArchive.h:128
trpgwAppAddress addr
Definition: TXPArchive.h:129
osg::ref_ptr< osg::StateSet > fallback
Definition: TXPArchive.h:60
osg::Vec3 center
Definition: TXPArchive.h:113
osg::BoundingBox bbox
Definition: TXPArchive.h:119
osg::ref_ptr< osgSim::LightPointNode > lightPoint
light point at (0,0,0) looking in (0,0,0) direction
Definition: TXPArchive.h:59
float radius
Definition: TXPArchive.h:117
TileLocationInfo()
Definition: TXPArchive.h:123
std::map< int, DeferredLightAttribute > _lights
Light attributes vector.
Definition: TXPArchive.h:278
trpg2dPoint _swExtents
Archive extents.
Definition: TXPArchive.h:252
void SetMaterialAttributesToStateSetVar(bool value)
Definition: TXPArchive.h:226
DeferredLightAttribute & getLightAttribute(unsigned int i)
Get light attrib.
Definition: TXPArchive.h:105
osg::ref_ptr< TXPParser > _parser
Terra Page Parser.
Definition: TXPArchive.h:256
TileLocationInfo(int gx, int gy, int glod, const trpgwAppAddress &gaddr, float gzmin=0.0f, float gzmax=0.0f)
Definition: TXPArchive.h:125
Definition: trpage_io.h:265
Definition: trpage_read.h:185
int getNumLightAttributes()
Definition: TXPArchive.h:99
std::map< int, osg::ref_ptr< osg::StateSet > > OSGStatesMapType
States.
Definition: TXPArchive.h:267
const int & getNumLODs() const
Returns the number of LODs for this archive.
Definition: TXPArchive.h:147
Definition: trpage_io.h:632
OpenThreads::Mutex Mutex
Definition: DtOsgThreadingUtils.h:12
void getOrigin(double &x, double &y)
{ extents.set(_swExtents.x,_swExtents.y,0.0f,_neExtents.x,_neExtents.y,0.0f); }
Definition: TXPArchive.h:160
OSGStatesMapType _statesMap
Definition: TXPArchive.h:268
float zmin
Definition: TXPArchive.h:130
osg::Vec3 size
Definition: TXPArchive.h:118
OpenThreads::Mutex _mutex
Definition: TXPArchive.h:287
double maxRange
Definition: TXPArchive.h:115
int _id
Id of the archive.
Definition: TXPArchive.h:246
Definition: trpage_geom.h:345
void GetVersion(int &majorVer, int &minorVer) const
Definition: TXPArchive.h:198
Definition: TXPParser.h:109
std::map< int, osg::ref_ptr< osg::Texture2D > > OSGTexMapType
Textures.
Definition: TXPArchive.h:259
std::map< int, osg::ref_ptr< osgText::Font > > _fonts
Text styles / Fonts.
Definition: TXPArchive.h:281
bool _isMaster
Definition: TXPArchive.h:292
double lod0Range
Definition: TXPArchive.h:116
std::map< int, osg::Vec4 > & getTextColors()
Definition: TXPArchive.h:91
Definition: TXPArchive.h:121
osg::Vec3 attitude
Definition: TXPArchive.h:61
OSGTexMapType _texmap
Definition: TXPArchive.h:260
void setId(int id)
Set/Get the archive id.
Definition: TXPArchive.h:137
Grid and file location of a tile.
Definition: trpage_managers.h:32

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)