VolumeTile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGVOLUME_tile
  14. #define OSGVOLUME_tile 1
  15. #include <osg/Group>
  16. #include <osg/Image>
  17. #include <osgDB/ReaderWriter>
  18. #include <osgVolume/Layer>
  19. #include <osgVolume/VolumeTechnique>
  20. namespace osgVolume {
  21. class Volume;
  22. class OSGVOLUME_EXPORT TileID
  23. {
  24. public:
  25. TileID();
  26. TileID(int in_level, int in_x, int in_y, int in_z);
  27. bool operator == (const TileID& rhs) const
  28. {
  29. return (level==rhs.level) && (x==rhs.x) && (y==rhs.y) && (z==rhs.z);
  30. }
  31. bool operator != (const TileID& rhs) const
  32. {
  33. return (level!=rhs.level) || (x!=rhs.x) || (y!=rhs.y) || (z!=rhs.z);
  34. }
  35. bool operator < (const TileID& rhs) const
  36. {
  37. if (level<rhs.level) return true;
  38. if (level>rhs.level) return false;
  39. if (x<rhs.x) return true;
  40. if (x>rhs.x) return false;
  41. if (y<rhs.y) return true;
  42. if (y>rhs.y) return false;
  43. return z<rhs.z;
  44. }
  45. bool valid() const { return level>=0; }
  46. int level;
  47. int x;
  48. int y;
  49. int z;
  50. };
  51. /** VolumeTile provides a framework for loosely coupling 3d image data with rendering algorithms.
  52. * This allows TerrainTechnique's to be plugged in at runtime.*/
  53. class OSGVOLUME_EXPORT VolumeTile : public osg::Group
  54. {
  55. public:
  56. VolumeTile();
  57. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  58. VolumeTile(const VolumeTile&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  59. META_Node(osgVolume, VolumeTile);
  60. virtual void traverse(osg::NodeVisitor& nv);
  61. /** Call init on any attached TerrainTechnique.*/
  62. void init();
  63. /** Set the Volume that this Volume tile is a member of.*/
  64. void setVolume(Volume* ts);
  65. /** Get the Volume that this Volume tile is a member of.*/
  66. Volume* getVolume() { return _volume; }
  67. /** Get the const Volume that this Volume tile is a member of.*/
  68. const Volume* getVolume() const { return _volume; }
  69. /** Set the TileID (layer, x,y,z) of the VolumeTile.
  70. * The TileID is used so it can be located by its neighbours
  71. * via the enclosing Volume node that manages a map of TileID to VolumeTiles.*/
  72. void setTileID(const TileID& tileID);
  73. /** Get the TileID (layer, x,y,z) of the VolumeTile.*/
  74. const TileID& getTileID() const { return _tileID; }
  75. void setLocator(Locator* locator) { _locator = locator; }
  76. Locator* getLocator() { return _locator.get(); }
  77. const Locator* getLocator() const { return _locator.get(); }
  78. void setLayer(Layer* layer);
  79. Layer* getLayer() { return _layer.get(); }
  80. const Layer* getLayer() const { return _layer.get(); }
  81. /** Set the VolumeTechnique that will be used to render this tile. */
  82. void setVolumeTechnique(VolumeTechnique* VolumeTechnique);
  83. /** Get the VolumeTechnique that will be used to render this tile. */
  84. VolumeTechnique* getVolumeTechnique() { return _volumeTechnique.get(); }
  85. /** Get the const VolumeTechnique that will be used to render this tile. */
  86. const VolumeTechnique* getVolumeTechnique() const { return _volumeTechnique.get(); }
  87. /** Set the dirty flag on/off.*/
  88. void setDirty(bool dirty);
  89. /** return true if the tile is dirty and needs to be updated,*/
  90. bool getDirty() const { return _dirty; }
  91. virtual osg::BoundingSphere computeBound() const;
  92. protected:
  93. virtual ~VolumeTile();
  94. friend class Volume;
  95. Volume* _volume;
  96. bool _dirty;
  97. bool _hasBeenTraversal;
  98. TileID _tileID;
  99. osg::ref_ptr<VolumeTechnique> _volumeTechnique;
  100. osg::ref_ptr<Locator> _locator;
  101. osg::ref_ptr<Layer> _layer;
  102. };
  103. }
  104. #endif