| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifndef FLT_FLIGHTDATA_H |
|---|
| 21 | #define FLT_FLIGHTDATA_H 1 |
|---|
| 22 | |
|---|
| 23 | #include <vector> |
|---|
| 24 | #include <osg/Notify> |
|---|
| 25 | #include <osg/Transform> |
|---|
| 26 | #include <osg/Geometry> |
|---|
| 27 | #include <osg/PolygonOffset> |
|---|
| 28 | #include <osg/Depth> |
|---|
| 29 | #include <osgDB/ReaderWriter> |
|---|
| 30 | #include <osgDB/Options> |
|---|
| 31 | |
|---|
| 32 | #include "Types.h" |
|---|
| 33 | #include "Record.h" |
|---|
| 34 | #include "Pools.h" |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | namespace flt { |
|---|
| 38 | |
|---|
| 39 | class Header; |
|---|
| 40 | class PushLevel; |
|---|
| 41 | class PopLevel; |
|---|
| 42 | |
|---|
| 43 | enum Version |
|---|
| 44 | { |
|---|
| 45 | VERSION_11 = 11, |
|---|
| 46 | VERSION_12 = 12, |
|---|
| 47 | VERSION_13 = 13, |
|---|
| 48 | VERSION_14 = 14, |
|---|
| 49 | VERSION_14_1 = 14, |
|---|
| 50 | VERSION_14_2 = 1420, |
|---|
| 51 | VERSION_15_1 = 1510, |
|---|
| 52 | VERSION_15_4 = 1540, |
|---|
| 53 | VERSION_15_5 = 1550, |
|---|
| 54 | VERSION_15_6 = 1560, |
|---|
| 55 | VERSION_15_7 = 1570, |
|---|
| 56 | VERSION_15_8 = 1580, |
|---|
| 57 | VERSION_16_0 = 1600, |
|---|
| 58 | VERSION_16_1 = 1610 |
|---|
| 59 | }; |
|---|
| 60 | |
|---|
| 61 | enum CoordUnits { |
|---|
| 62 | METERS = 0, |
|---|
| 63 | KILOMETERS = 1, |
|---|
| 64 | FEET = 4, |
|---|
| 65 | INCHES = 5, |
|---|
| 66 | NAUTICAL_MILES = 8 |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | double unitsToMeters(CoordUnits unit); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | enum Projection { |
|---|
| 73 | FLAT_EARTH = 0, |
|---|
| 74 | TRAPEZOIDAL = 1, |
|---|
| 75 | ROUND_EARTH = 2, |
|---|
| 76 | LAMBERT = 3, |
|---|
| 77 | UTM = 4, |
|---|
| 78 | GEODETIC = 5, |
|---|
| 79 | GEOCENTRIC = 6 |
|---|
| 80 | }; |
|---|
| 81 | |
|---|
| 82 | enum Ellipsoid { |
|---|
| 83 | WGS_1984 = 0, |
|---|
| 84 | WGS_1972 = 1, |
|---|
| 85 | BESSEL = 2, |
|---|
| 86 | CLARKE_1866 = 3, |
|---|
| 87 | NAD_1927 = 4 |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | class Document |
|---|
| 92 | { |
|---|
| 93 | public: |
|---|
| 94 | |
|---|
| 95 | Document(); |
|---|
| 96 | virtual ~Document(); |
|---|
| 97 | |
|---|
| 98 | void setOptions(const osgDB::ReaderWriter::Options* options) { _options = options; } |
|---|
| 99 | const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); } |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | void setCurrentPrimaryRecord(PrimaryRecord* record) { _currentPrimaryRecord=record; } |
|---|
| 103 | PrimaryRecord* getCurrentPrimaryRecord() { return _currentPrimaryRecord.get(); } |
|---|
| 104 | const PrimaryRecord* getCurrentPrimaryRecord() const { return _currentPrimaryRecord.get(); } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | PrimaryRecord* getTopOfLevelStack(); |
|---|
| 108 | void pushLevel(); |
|---|
| 109 | void popLevel(); |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | void pushSubface(); |
|---|
| 113 | void popSubface(); |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | void pushExtension(); |
|---|
| 117 | void popExtension(); |
|---|
| 118 | |
|---|
| 119 | void setHeaderNode(osg::Node* node) { _osgHeader = node; } |
|---|
| 120 | osg::Node* getHeaderNode() { return _osgHeader.get(); } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | void setInstanceDefinition(int no, osg::Node* node) { _instanceDefinitionMap[no] = node; } |
|---|
| 124 | osg::Node* getInstanceDefinition(int no); |
|---|
| 125 | |
|---|
| 126 | uint32 version() const { return _version; } |
|---|
| 127 | bool done() const { return _done; } |
|---|
| 128 | int level() const { return _level; } |
|---|
| 129 | int subfaceLevel() const { return _subfaceLevel; } |
|---|
| 130 | double unitScale() const { return _unitScale; } |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | void setVertexPool(VertexPool* vp) { _vertexPool = vp; } |
|---|
| 134 | VertexPool* getVertexPool() { return _vertexPool.get(); } |
|---|
| 135 | const VertexPool* getVertexPool() const { return _vertexPool.get(); } |
|---|
| 136 | |
|---|
| 137 | void setColorPool(ColorPool* cp, bool parent=false) { _colorPool = cp; _colorPoolParent=parent; } |
|---|
| 138 | ColorPool* getColorPool() { return _colorPool.get(); } |
|---|
| 139 | const ColorPool* getColorPool() const { return _colorPool.get(); } |
|---|
| 140 | bool getColorPoolParent() const { return _colorPoolParent; } |
|---|
| 141 | |
|---|
| 142 | void setTexturePool(TexturePool* tp, bool parent=false) { _texturePool = tp; _texturePoolParent=parent; } |
|---|
| 143 | TexturePool* getTexturePool() { return _texturePool.get(); } |
|---|
| 144 | TexturePool* getOrCreateTexturePool(); |
|---|
| 145 | bool getTexturePoolParent() const { return _texturePoolParent; } |
|---|
| 146 | |
|---|
| 147 | void setMaterialPool(MaterialPool* mp, bool parent=false) { _materialPool = mp; _materialPoolParent=parent; } |
|---|
| 148 | MaterialPool* getMaterialPool() { return _materialPool.get(); } |
|---|
| 149 | MaterialPool* getOrCreateMaterialPool(); |
|---|
| 150 | bool getMaterialPoolParent() const { return _materialPoolParent; } |
|---|
| 151 | |
|---|
| 152 | void setLightSourcePool(LightSourcePool* lsp, bool parent=false) { _lightSourcePool = lsp; _lightSourcePoolParent=parent; } |
|---|
| 153 | LightSourcePool* getLightSourcePool() { return _lightSourcePool.get(); } |
|---|
| 154 | LightSourcePool* getOrCreateLightSourcePool(); |
|---|
| 155 | bool getLightSourcePoolParent() const { return _lightSourcePoolParent; } |
|---|
| 156 | |
|---|
| 157 | void setLightPointAppearancePool(LightPointAppearancePool* lpap, bool parent=false) { _lightPointAppearancePool = lpap; _lightPointAppearancePoolParent=parent; } |
|---|
| 158 | LightPointAppearancePool* getLightPointAppearancePool() { return _lightPointAppearancePool.get(); } |
|---|
| 159 | LightPointAppearancePool* getOrCreateLightPointAppearancePool(); |
|---|
| 160 | bool getLightPointAppearancePoolParent() const { return _lightPointAppearancePoolParent; } |
|---|
| 161 | |
|---|
| 162 | void setLightPointAnimationPool(LightPointAnimationPool* lpap, bool parent=false) { _lightPointAnimationPool = lpap; _lightPointAnimationPoolParent=parent; } |
|---|
| 163 | LightPointAnimationPool* getLightPointAnimationPool() { return _lightPointAnimationPool.get(); } |
|---|
| 164 | LightPointAnimationPool* getOrCreateLightPointAnimationPool(); |
|---|
| 165 | bool getLightPointAnimationPoolParent() const { return _lightPointAnimationPoolParent; } |
|---|
| 166 | |
|---|
| 167 | void setShaderPool(ShaderPool* cp, bool parent=false) { _shaderPool = cp; _shaderPoolParent=parent; } |
|---|
| 168 | ShaderPool* getShaderPool() { return _shaderPool.get(); } |
|---|
| 169 | ShaderPool* getOrCreateShaderPool(); |
|---|
| 170 | bool getShaderPoolParent() const { return _shaderPoolParent; } |
|---|
| 171 | |
|---|
| 172 | void setSubSurfacePolygonOffset(int level, osg::PolygonOffset* po); |
|---|
| 173 | osg::PolygonOffset* getSubSurfacePolygonOffset(int level); |
|---|
| 174 | |
|---|
| 175 | void setSubSurfaceDepth(osg::Depth* depth) { _subsurfaceDepth = depth; } |
|---|
| 176 | osg::Depth* getSubSurfaceDepth() { return _subsurfaceDepth.get(); } |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | void setReplaceClampWithClampToEdge(bool flag) { _replaceClampWithClampToEdge = flag; } |
|---|
| 181 | bool getReplaceClampWithClampToEdge() const { return _replaceClampWithClampToEdge; } |
|---|
| 182 | void setPreserveFace(bool flag) { _preserveFace = flag; } |
|---|
| 183 | bool getPreserveFace() const { return _preserveFace; } |
|---|
| 184 | void setPreserveObject(bool flag) { _preserveObject = flag; } |
|---|
| 185 | bool getPreserveObject() const { return _preserveObject; } |
|---|
| 186 | void setReplaceDoubleSidedPolys(bool flag) { _replaceDoubleSidedPolys = flag; } |
|---|
| 187 | bool getReplaceDoubleSidedPolys() const { return _replaceDoubleSidedPolys; } |
|---|
| 188 | void setDefaultDOFAnimationState(bool state) { _defaultDOFAnimationState = state; } |
|---|
| 189 | bool getDefaultDOFAnimationState() const { return _defaultDOFAnimationState; } |
|---|
| 190 | void setUseTextureAlphaForTransparancyBinning(bool flag) { _useTextureAlphaForTransparancyBinning=flag; } |
|---|
| 191 | bool getUseTextureAlphaForTransparancyBinning() const { return _useTextureAlphaForTransparancyBinning; } |
|---|
| 192 | void setUseBillboardCenter(bool flag) { _useBillboardCenter=flag; } |
|---|
| 193 | bool getUseBillboardCenter() const { return _useBillboardCenter; } |
|---|
| 194 | void setDoUnitsConversion(bool flag) { _doUnitsConversion=flag; } |
|---|
| 195 | bool getDoUnitsConversion() const { return _doUnitsConversion; } |
|---|
| 196 | void setDesiredUnits(CoordUnits units ) { _desiredUnits=units; } |
|---|
| 197 | CoordUnits getDesiredUnits() const { return _desiredUnits; } |
|---|
| 198 | |
|---|
| 199 | void setKeepExternalReferences( bool flag) { _keepExternalReferences=flag; } |
|---|
| 200 | bool getKeepExternalReferences() const { return _keepExternalReferences; } |
|---|
| 201 | |
|---|
| 202 | void setReadObjectRecordData(bool flag) { _readObjectRecordData = flag; } |
|---|
| 203 | bool getReadObjectRecordData() const { return _readObjectRecordData; } |
|---|
| 204 | |
|---|
| 205 | protected: |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | osg::ref_ptr<const osgDB::ReaderWriter::Options> _options; |
|---|
| 209 | bool _replaceClampWithClampToEdge; |
|---|
| 210 | bool _preserveFace; |
|---|
| 211 | bool _preserveObject; |
|---|
| 212 | bool _replaceDoubleSidedPolys; |
|---|
| 213 | bool _defaultDOFAnimationState; |
|---|
| 214 | bool _useTextureAlphaForTransparancyBinning; |
|---|
| 215 | bool _useBillboardCenter; |
|---|
| 216 | bool _doUnitsConversion; |
|---|
| 217 | bool _readObjectRecordData; |
|---|
| 218 | CoordUnits _desiredUnits; |
|---|
| 219 | |
|---|
| 220 | bool _keepExternalReferences; |
|---|
| 221 | |
|---|
| 222 | friend class Header; |
|---|
| 223 | bool _done; |
|---|
| 224 | int _level; |
|---|
| 225 | int _subfaceLevel; |
|---|
| 226 | double _unitScale; |
|---|
| 227 | uint32 _version; |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | osg::ref_ptr<osg::Node> _osgHeader; |
|---|
| 231 | |
|---|
| 232 | osg::ref_ptr<VertexPool> _vertexPool; |
|---|
| 233 | osg::ref_ptr<ColorPool> _colorPool; |
|---|
| 234 | osg::ref_ptr<TexturePool> _texturePool; |
|---|
| 235 | osg::ref_ptr<MaterialPool> _materialPool; |
|---|
| 236 | osg::ref_ptr<LightSourcePool> _lightSourcePool; |
|---|
| 237 | osg::ref_ptr<LightPointAppearancePool> _lightPointAppearancePool; |
|---|
| 238 | osg::ref_ptr<LightPointAnimationPool> _lightPointAnimationPool; |
|---|
| 239 | osg::ref_ptr<ShaderPool> _shaderPool; |
|---|
| 240 | |
|---|
| 241 | typedef std::map<int, osg::ref_ptr<osg::PolygonOffset> > SubSurfacePolygonOffsets; |
|---|
| 242 | SubSurfacePolygonOffsets _subsurfacePolygonOffsets; |
|---|
| 243 | osg::ref_ptr<osg::Depth> _subsurfaceDepth; |
|---|
| 244 | |
|---|
| 245 | bool _colorPoolParent; |
|---|
| 246 | bool _texturePoolParent; |
|---|
| 247 | bool _materialPoolParent; |
|---|
| 248 | bool _lightSourcePoolParent; |
|---|
| 249 | bool _lightPointAppearancePoolParent; |
|---|
| 250 | bool _lightPointAnimationPoolParent; |
|---|
| 251 | bool _shaderPoolParent; |
|---|
| 252 | |
|---|
| 253 | osg::ref_ptr<PrimaryRecord> _currentPrimaryRecord; |
|---|
| 254 | |
|---|
| 255 | typedef std::vector<osg::ref_ptr<PrimaryRecord> > LevelStack; |
|---|
| 256 | LevelStack _levelStack; |
|---|
| 257 | LevelStack _extensionStack; |
|---|
| 258 | |
|---|
| 259 | typedef std::map<int,osg::ref_ptr<osg::Node> > InstanceDefinitionMap; |
|---|
| 260 | InstanceDefinitionMap _instanceDefinitionMap; |
|---|
| 261 | }; |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | inline TexturePool* Document::getOrCreateTexturePool() |
|---|
| 265 | { |
|---|
| 266 | if (!_texturePool.valid()) |
|---|
| 267 | _texturePool = new TexturePool; |
|---|
| 268 | return _texturePool.get(); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | inline MaterialPool* Document::getOrCreateMaterialPool() |
|---|
| 273 | { |
|---|
| 274 | if (!_materialPool.valid()) |
|---|
| 275 | _materialPool = new MaterialPool; |
|---|
| 276 | return _materialPool.get(); |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | inline LightSourcePool* Document::getOrCreateLightSourcePool() |
|---|
| 281 | { |
|---|
| 282 | if (!_lightSourcePool.valid()) |
|---|
| 283 | _lightSourcePool = new LightSourcePool; |
|---|
| 284 | return _lightSourcePool.get(); |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | inline LightPointAppearancePool* Document::getOrCreateLightPointAppearancePool() |
|---|
| 289 | { |
|---|
| 290 | if (!_lightPointAppearancePool.valid()) |
|---|
| 291 | _lightPointAppearancePool = new LightPointAppearancePool; |
|---|
| 292 | return _lightPointAppearancePool.get(); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | inline LightPointAnimationPool* Document::getOrCreateLightPointAnimationPool() |
|---|
| 296 | { |
|---|
| 297 | if (!_lightPointAnimationPool.valid()) |
|---|
| 298 | _lightPointAnimationPool = new LightPointAnimationPool; |
|---|
| 299 | return _lightPointAnimationPool.get(); |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | inline ShaderPool* Document::getOrCreateShaderPool() |
|---|
| 304 | { |
|---|
| 305 | if (!_shaderPool.valid()) |
|---|
| 306 | _shaderPool = new ShaderPool; |
|---|
| 307 | return _shaderPool.get(); |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | inline PrimaryRecord* Document::getTopOfLevelStack() |
|---|
| 312 | { |
|---|
| 313 | |
|---|
| 314 | if (_levelStack.empty()) |
|---|
| 315 | return NULL; |
|---|
| 316 | |
|---|
| 317 | return _levelStack.back().get(); |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | #endif |
|---|