VR-Forces 4.2 Class Documentation
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(
128  trpgReadBuffer &buf,
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 
314  osg::ref_ptr<osg::Group> _root;
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 

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)