VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TXPParser.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 
35 #ifndef __TXPPARSER_H_
36 #define __TXPPARSER_H_
37 
38 #include <osg/Referenced>
39 #include <osg/Texture2D>
40 #include <osg/StateSet>
41 #include <osg/Node>
42 
43 #include <stack>
44 
45 #include "trpage_read.h"
46 
47 #include "TXPArchive.h"
48 
49 namespace txp
50 {
51 
53 osg::Texture2D* getLocalTexture(trpgrImageHelper& image_helper, const trpgTexture* tex);
54 osg::Texture2D* getTemplateTexture(trpgrImageHelper& image_helper, trpgLocalMaterial* locmat, const trpgTexture* tex, int index=0);
55 
56 
57 
76 
77 class GeodeGroup : public osg::Group
78 {
79 public:
80 
81  GeodeGroup() : osg::Group(), _geode(NULL)
82  {}
83 
84  GeodeGroup(const GeodeGroup& gg,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
85  osg::Group(gg, copyop), _geode(gg._geode)
86  {}
87 
88  META_Node(txp, GeodeGroup);
89 
90  osg::Geode* getGeode()
91  {
92  if (_geode == 0)
93  {
94  _geode = new osg::Geode();
95  addChild(_geode);
96  }
97 
98  return _geode;
99  }
100 protected:
101  osg::Geode* _geode;
102 };
103 
104 
105 class TXPArchive;
106 class childRefRead;
108 
109 class TXPParser : public trpgSceneParser, public osg::Referenced
110 {
111 public:
112  TXPParser();
113 
115  inline void setArchive(TXPArchive* archive)
116  {
117  _archive = archive;
118  }
119 
122  {
123  return _archive;
124  }
125 
127  osg::Group *parseScene(
129  std::map<int,osg::ref_ptr<osg::StateSet> > &materials,
130  std::map<int,osg::ref_ptr<osg::Node> > &models,
131  double realMinRange, double realMaxRange, double usedMaxRange);
132 
134  inline osg::Group* getCurrTop()
135  {
136  return _currentTop ? _currentTop : _root.get();
137  }
138 
140  inline void setPotentionalTileGroup(osg::Group* grp)
141  {
142  _tileGroups[grp] = 1;
143  }
144 
146  inline std::map<int,osg::ref_ptr<osg::StateSet> >* getMaterials()
147  {
148  return _materialMap;
149  }
150 
152  inline void loadMaterial( int ix )
153  {
154  _archive->loadMaterial( ix );
155  }
156 
158  std::vector<osg::ref_ptr<osg::StateSet> >* getLocalMaterials()
159  {
160  return &_localMaterials;
161  }
162 
164  void loadLocalMaterials();
165 
167  std::map<int,osg::ref_ptr<osg::Node> >* getModels()
168  {
169  return _models;
170  }
171 
173  bool requestModel(int ix);
174 
177  {
178  return &_tileHeader;
179  }
180 
181 
183  inline const bool underBillboardSubgraph() const
184  {
186  }
187 
189  inline void setUnderBillboardSubgraph(bool b)
190  {
192  }
193 
196  {
197  int type;
198  int mode;
201  };
202 
205  {
206  _lastBillboardInfo = info;
207  }
208 
211  {
212  info = _lastBillboardInfo;
213  }
214 
217 
219  inline const bool underLayerSubgraph() const
220  {
221  return _underLayerSubgraph;
222  }
223 
225  inline void setUnderLayerSubgraph(bool b)
226  {
228  }
229 
231  inline void setLayerGeode(osg::Geode* layer)
232  {
233  _layerGeode = layer;
234  }
235 
237  inline osg::Geode* getLayerGeode() const
238  {
239  return _layerGeode;
240  }
241 
242  inline unsigned int getNumLayerLavels() const { return _numLayerLevels; }
243 
245  void setMaxAnisotropy(float anisotropy)
246  {
247  _defaultMaxAnisotropy = anisotropy;
248  }
249  float getMaxAnisotropy() const
250  {
251  return _defaultMaxAnisotropy;
252  }
253 
256  inline double checkAndGetMinRange(double range)
257  {
258  if ((range-_realMinRange) < 0.0001)
259  return 0.0;
260  else
261  return range;
262  }
263  inline double checkAndGetMaxRange(double range)
264  {
265  if ((range-_realMaxRange) < 0.0001)
266  return _usedMaxRange;
267  else
268  return range;
269  }
270 
272  inline const osg::Vec3 getTileCenter() const
273  {
274  return _tileCenter;
275  }
276 
277  inline void setCurrentNode( osg::Node* node )
278  {
279  _currentNode = node;
280  }
281 
283  unsigned int GetNbChildrenRef() const;
284 
287  const trpgChildRef* GetChildRef(unsigned int idx) const;
288 
289 
290 
291 protected:
292 
293  virtual ~TXPParser();
294 
296  void removeEmptyGroups();
297 
299  bool StartChildren(void *);
300 
302  bool EndChildren(void *);
303 
306 
308  osg::Group* _currentTop;
309 
311  osg::Node* _currentNode;
312 
315 
317  std::stack<osg::Group*> _parents;
318 
320  std::map<osg::Group*,int> _tileGroups;
321 
323  void replaceTileLod(osg::Group*);
324 
326  typedef std::map<int,osg::ref_ptr<osg::StateSet> >* MaterialMapType;
328 
330  std::vector<osg::ref_ptr<osg::StateSet> > _localMaterials;
331 
333  typedef std::map<int,osg::ref_ptr<osg::Node> > OSGModelsMapType;
335 
338 
341 
344 
347 
350 
353 
355  osg::Geode* _layerGeode;
356 
359 
364 
366  osg::Vec3 _tileCenter;
367 
369  osg::Geode* createBoundingBox(int x,int y, int lod);
370 
371  private:
372 
374 
375 
376 };
377 
378 
380 //----------------------------------------------------------------------------
381 class geomRead : public trpgr_Callback
382 {
383 public:
384 
385  geomRead(TXPParser *in_parse) : _parse(in_parse)
386  {}
387  void *Parse(trpgToken tok,trpgReadBuffer &buf);
388 protected:
390 };
391 
392 
393 //----------------------------------------------------------------------------
394 class groupRead : public trpgr_Callback
395 {
396 public:
397  groupRead(TXPParser *in_parse) : _parse(in_parse)
398  {}
399  void *Parse(trpgToken tok,trpgReadBuffer &buf);
400 protected:
402 };
403 
404 //----------------------------------------------------------------------------
406 {
407 public:
408  attachRead(TXPParser *in_parse) : _parse(in_parse)
409  {}
410  void *Parse(trpgToken tok,trpgReadBuffer &buf);
411 protected:
413 
414 };
415 //----------------------------------------------------------------------------
417 {
418 public:
419  typedef std::vector<trpgChildRef> ChildRefList;
420 
421  childRefRead(TXPParser *in_parse) : _parse(in_parse)
422  {}
423  void Reset();
424  void *Parse(trpgToken tok,trpgReadBuffer &buf);
425 
427  unsigned int GetNbChildrenRef() const
428  {
429  return childRefList.size();
430  }
433  const trpgChildRef* GetChildRef(unsigned int idx) const
434  {
435  if(idx >= childRefList.size())
436  return 0;
437  else
438  return &childRefList[idx];
439  }
440 
441 protected:
443 
444 
445 
446 private:
447 
449 
450 
451 };
452 
453 //----------------------------------------------------------------------------
454 class lodRead : public trpgr_Callback
455 {
456 public:
457  lodRead(TXPParser *in_parse) : _parse(in_parse)
458  {}
459  void *Parse(trpgToken tok,trpgReadBuffer &buf);
460 protected:
462 };
463 
464 //----------------------------------------------------------------------------
466 {
467 public:
468  tileHeaderRead(TXPParser *in_parse) : _parse(in_parse)
469  {}
470  void *Parse(trpgToken tok,trpgReadBuffer &buf);
471 protected:
473 };
474 
475 //----------------------------------------------------------------------------
476 
478 {
479 public:
480  modelRefRead(TXPParser *in_parse) : _parse(in_parse)
481  {}
482  void *Parse(trpgToken tok,trpgReadBuffer &buf);
483 protected:
485 };
486 
487 //----------------------------------------------------------------------------
489 {
490 public:
491  billboardRead(TXPParser *in_parse) : _parse(in_parse)
492  {}
493  void *Parse(trpgToken tok,trpgReadBuffer &buf);
494 protected:
496 };
497 
498 //----------------------------------------------------------------------------
500 {
501 public:
502  lightRead(TXPParser *in_parse) : _parse(in_parse)
503  {}
504  void *Parse(trpgToken tok,trpgReadBuffer &buf);
505 protected:
507 };
508 
509 //----------------------------------------------------------------------------
511 {
512 public:
513  layerRead(TXPParser *in_parse) : _parse(in_parse)
514  {}
515  void *Parse(trpgToken tok,trpgReadBuffer &buf);
516 protected:
518 };
519 
520 //----------------------------------------------------------------------------
522 {
523 public:
524  labelRead(TXPParser *in_parse) : _parse(in_parse)
525  {}
526  void *Parse(trpgToken tok,trpgReadBuffer &buf);
527 protected:
529 };
530 
531 }
532 
533 #endif
534 
535 
Definition: TXPArchive.h:65
osg::Vec3 _tileCenter
tile center
Definition: TXPParser.h:366
Definition: TXPParser.h:405
MaterialMapType _materialMap
Definition: TXPParser.h:327
bool _underBillboardSubgraph
true if we are under billboard subgraph
Definition: TXPParser.h:340
trpgTileHeader * getTileHeaderRef()
Return a reference to the tile header (after a tile has been read)
Definition: TXPParser.h:176
lightRead(TXPParser *in_parse)
Definition: TXPParser.h:502
TXPParser * _parse
Definition: TXPParser.h:472
Definition: trpage_read.h:256
groupRead(TXPParser *in_parse)
Definition: TXPParser.h:397
Definition: TXPParser.h:416
geomRead(TXPParser *in_parse)
Definition: TXPParser.h:385
TXPParser * _parse
Definition: TXPParser.h:506
osg::Group * getCurrTop()
Returns the current Top Group.
Definition: TXPParser.h:134
double checkAndGetMaxRange(double range)
Definition: TXPParser.h:263
TXPParser * _parse
Definition: TXPParser.h:461
const bool underLayerSubgraph() const
Returns if we are under layer subgraph.
Definition: TXPParser.h:219
META_Node(txp, GeodeGroup)
Definition: trpage_geom.h:1763
TXPParser * _parse
Definition: TXPParser.h:517
this one handles different placement of light direction in osg and terrapage
Definition: TXPArchive.h:56
void setUnderLayerSubgraph(bool b)
Sets if we are under layer subgraph.
Definition: TXPParser.h:225
float _defaultMaxAnisotropy
default value to use when setting up textures.
Definition: TXPParser.h:358
childRefRead * _childRefCB
Definition: TXPParser.h:373
TXPParser * _parse
Definition: TXPParser.h:412
std::map< int, osg::ref_ptr< osg::StateSet > > * MaterialMapType
Materials.
Definition: TXPParser.h:326
Definition: TXPParser.h:510
virtual ~TXPParser()
std::map< int, osg::ref_ptr< osg::Node > > OSGModelsMapType
Model list.
Definition: TXPParser.h:333
Definition: TXPParser.h:499
void * Parse(trpgToken tok, trpgReadBuffer &buf)
ChildRefList childRefList
Definition: TXPParser.h:448
void removeEmptyGroups()
Removes any empty groups and LODs.
layerRead(TXPParser *in_parse)
Definition: TXPParser.h:513
GeodeGroup(const GeodeGroup &gg, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: TXPParser.h:84
void * Parse(trpgToken tok, trpgReadBuffer &buf)
const trpgChildRef * GetChildRef(unsigned int idx) const
This will return the trpgChildRef node pointer associated with the index. Will return 0 if index is o...
void * Parse(trpgToken tok, trpgReadBuffer &buf)
std::map< int, osg::ref_ptr< osg::StateSet > > * getMaterials()
Return the current material list (passed in to ParseScene())
Definition: TXPParser.h:146
voidpf void * buf
Definition: ioapi.h:39
bool StartChildren(void *)
Called on start children.
double _realMaxRange
Definition: TXPParser.h:362
osg::Geode * getLayerGeode() const
Returns the current layer geode.
Definition: TXPParser.h:237
void setUnderBillboardSubgraph(bool b)
Sets if we are under billboard subgraph.
Definition: TXPParser.h:189
std::map< osg::Group *, int > _tileGroups
Potentional Tile groups.
Definition: TXPParser.h:320
void * Parse(trpgToken tok, trpgReadBuffer &buf)
void setMaxAnisotropy(float anisotropy)
default value to use when setting up textures.
Definition: TXPParser.h:245
Definition: trpage_geom.h:1226
Definition: TXPParser.h:465
osg::Group * parseScene(trpgReadBuffer &buf, std::map< int, osg::ref_ptr< osg::StateSet > > &materials, std::map< int, osg::ref_ptr< osg::Node > > &models, double realMinRange, double realMaxRange, double usedMaxRange)
Scene parser.
std::vector< osg::ref_ptr< osg::StateSet > > _localMaterials
Local materials.
Definition: TXPParser.h:330
osg::Texture2D * getTemplateTexture(trpgrImageHelper &image_helper, trpgLocalMaterial *locmat, const trpgTexture *tex, int index=0)
bool EndChildren(void *)
Called on end children.
Definition: trpage_geom.h:2476
tileHeaderRead(TXPParser *in_parse)
Definition: TXPParser.h:468
lodRead(TXPParser *in_parse)
Definition: TXPParser.h:457
void * Parse(trpgToken tok, trpgReadBuffer &buf)
osg::Geode * _layerGeode
Our Layer Geode.
Definition: TXPParser.h:355
TXPParser * _parse
Definition: TXPParser.h:484
std::vector< trpgChildRef > ChildRefList
Definition: TXPParser.h:419
double _usedMaxRange
Definition: TXPParser.h:363
void setLastBillboardInfo(TXPBillboardInfo &info)
Sets info for the last billboard parsed.
Definition: TXPParser.h:204
TXPParser * _parse
Definition: TXPParser.h:442
void setPotentionalTileGroup(osg::Group *grp)
Sets the group as potentional tile group.
Definition: TXPParser.h:140
std::vector< osg::ref_ptr< osg::StateSet > > * getLocalMaterials()
New to TerraPage 2.0 - local materials.
Definition: TXPParser.h:158
{secret}
Definition: trpage_read.h:32
callback functions for various scene graph elements
Definition: TXPParser.h:381
osg::Geode * _geode
Definition: TXPParser.h:101
unsigned int GetNbChildrenRef() const
After parsing this will return the number of trpgChildRef node found.
osg::Texture2D * getLocalTexture(trpgrImageHelper &image_helper, const trpgTexture *tex)
Gets local texture via the image helper.
void loadLocalMaterials()
Load local materials.
void setArchive(TXPArchive *archive)
Sets the archive to be parsed.
Definition: TXPParser.h:115
osg::ref_ptr< osg::Group > _root
The root of the tile.
Definition: TXPParser.h:314
trpg3dPoint axis
Definition: TXPParser.h:200
TXPParser * _parse
Definition: TXPParser.h:528
bool _underLayerSubgraph
true if we are under layer subgraph
Definition: TXPParser.h:349
int _numLayerLevels
Numbers of levels below layer subgraph.
Definition: TXPParser.h:352
Definition: TXPParser.h:454
billboardRead(TXPParser *in_parse)
Definition: TXPParser.h:491
Definition: TXPParser.h:394
TXPBillboardInfo _lastBillboardInfo
Last billboard we parsed.
Definition: TXPParser.h:346
double checkAndGetMinRange(double range)
We need to change the LOD ranges within tiles since we have done it for the PagedLODs representing ti...
Definition: TXPParser.h:256
trpgTileHeader _tileHeader
Tile header.
Definition: TXPParser.h:337
childRefRead(TXPParser *in_parse)
Definition: TXPParser.h:421
bool requestModel(int ix)
Request a model to be load.
TXPArchive * getArchive()
Gets the archive.
Definition: TXPParser.h:121
Definition: TXPParser.h:488
Definition: TXPParser.h:521
float getMaxAnisotropy() const
Definition: TXPParser.h:249
bool loadMaterial(int ix)
This is group that will has geode node It is better since all the geometry children will be added int...
Definition: TXPParser.h:77
int mode
Definition: TXPParser.h:198
void replaceTileLod(osg::Group *)
Replace the tile lod to regular group.
Definition: TXPParser.h:109
osg::Geode * getGeode()
Definition: TXPParser.h:90
void * Parse(trpgToken tok, trpgReadBuffer &buf)
void * Parse(trpgToken tok, trpgReadBuffer &buf)
OSGModelsMapType * _models
Definition: TXPParser.h:334
Definition: trpage_geom.h:1898
TXPArchive * _archive
THE archive.
Definition: TXPParser.h:305
void * Parse(trpgToken tok, trpgReadBuffer &buf)
std::stack< osg::Group * > _parents
Parents list.
Definition: TXPParser.h:317
osg::Group * _currentTop
Current parent.
Definition: TXPParser.h:308
int _numBillboardLevels
Number of levels below the billboard node.
Definition: TXPParser.h:343
int type
Definition: TXPParser.h:197
DeferredLightAttribute & getLightAttribute(int ix)
Gets light attrib.
unsigned int GetNbChildrenRef() const
After parsing this will return the number of trpgChildRef node found.
Definition: TXPParser.h:427
Definition: trpage_read.h:99
void setCurrentNode(osg::Node *node)
Definition: TXPParser.h:277
Definition: TXPParser.h:477
TXPParser * _parse
Definition: TXPParser.h:401
trpg3dPoint center
Definition: TXPParser.h:199
std::map< int, osg::ref_ptr< osg::Node > > * getModels()
Return the current model list.
Definition: TXPParser.h:167
Definition: trpage_io.h:452
void setLayerGeode(osg::Geode *layer)
Set the current layer geode.
Definition: TXPParser.h:231
const osg::Vec3 getTileCenter() const
gets tile center, from the top lod node
Definition: TXPParser.h:272
GeodeGroup()
Definition: TXPParser.h:81
osg::Geode * createBoundingBox(int x, int y, int lod)
TEMP.
void getLastBillboardInfo(TXPBillboardInfo &info)
Gets info for the last billboard parsed.
Definition: TXPParser.h:210
labelRead(TXPParser *in_parse)
Definition: TXPParser.h:524
void loadMaterial(int ix)
Ensure material is loaded.
Definition: TXPParser.h:152
unsigned int getNumLayerLavels() const
Definition: TXPParser.h:242
void * Parse(trpgToken tok, trpgReadBuffer &buf)
double _realMinRange
LOD ranges to be used when parsing tiles.
Definition: TXPParser.h:361
modelRefRead(TXPParser *in_parse)
Definition: TXPParser.h:480
const bool underBillboardSubgraph() const
Returns true if we are under billboard subgraph.
Definition: TXPParser.h:183
TXPParser * _parse
Definition: TXPParser.h:495
Definition: trpage_io.h:285
const trpgChildRef * GetChildRef(unsigned int idx) const
This will return the trpgChildRef node associated with the index. this will return 0 if idx is out of...
Definition: TXPParser.h:433
short trpgToken
16 bit token definition value. These are values such as TRPGTEXTABLE or TRPG_ATTACH, etc...
Definition: trpage_io.h:61
osg::Node * _currentNode
Current node.
Definition: TXPParser.h:311
attachRead(TXPParser *in_parse)
Definition: TXPParser.h:408
void * Parse(trpgToken tok, trpgReadBuffer &buf)
void * Parse(trpgToken tok, trpgReadBuffer &buf)
TXPParser * _parse
Definition: TXPParser.h:389
TXP Billboard info.
Definition: TXPParser.h:195

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)