| 1 | #ifndef IVE_DATAOUTPUTSTREAM |
|---|
| 2 | #define IVE_DATAOUTPUTSTREAM 1 |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | #include <iostream> // for ofstream |
|---|
| 7 | #include <string> |
|---|
| 8 | #include <sstream> |
|---|
| 9 | |
|---|
| 10 | #include <osg/Vec2> |
|---|
| 11 | #include <osg/Vec3> |
|---|
| 12 | #include <osg/Vec4> |
|---|
| 13 | #include <osg/Quat> |
|---|
| 14 | #include <osg/Array> |
|---|
| 15 | #include <osg/Matrix> |
|---|
| 16 | #include <osg/Geometry> |
|---|
| 17 | #include <osg/Shape> |
|---|
| 18 | #include <osg/Uniform> |
|---|
| 19 | #include <osgDB/ReaderWriter> |
|---|
| 20 | |
|---|
| 21 | #include <osgTerrain/TerrainTile> |
|---|
| 22 | #include <osgVolume/VolumeTile> |
|---|
| 23 | |
|---|
| 24 | #include "IveVersion.h" |
|---|
| 25 | #include "DataTypeSize.h" |
|---|
| 26 | #include "Exception.h" |
|---|
| 27 | |
|---|
| 28 | #include <osg/StateSet> |
|---|
| 29 | #include <osg/ref_ptr> |
|---|
| 30 | |
|---|
| 31 | namespace ive { |
|---|
| 32 | |
|---|
| 33 | class DataOutputStream{ |
|---|
| 34 | |
|---|
| 35 | public: |
|---|
| 36 | DataOutputStream(std::ostream* ostream, const osgDB::ReaderWriter::Options* options); |
|---|
| 37 | ~DataOutputStream(); |
|---|
| 38 | |
|---|
| 39 | const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); } |
|---|
| 40 | |
|---|
| 41 | unsigned int getVersion() { return VERSION; } |
|---|
| 42 | |
|---|
| 43 | void writeBool(bool b); |
|---|
| 44 | void writeChar(char c); |
|---|
| 45 | void writeUChar(unsigned char c); |
|---|
| 46 | void writeUShort(unsigned short s); |
|---|
| 47 | void writeShort(short s); |
|---|
| 48 | void writeUInt(unsigned int s); |
|---|
| 49 | void writeInt(int i); |
|---|
| 50 | void writeFloat(float f); |
|---|
| 51 | void writeLong(long l); |
|---|
| 52 | void writeULong(unsigned long l); |
|---|
| 53 | void writeDouble(double d); |
|---|
| 54 | void writeString(const std::string& s); |
|---|
| 55 | void writeCharArray(const char* data, int size); |
|---|
| 56 | void writeVec2(const osg::Vec2& v); |
|---|
| 57 | void writeVec3(const osg::Vec3& v); |
|---|
| 58 | void writeVec4(const osg::Vec4& v); |
|---|
| 59 | void writeVec2d(const osg::Vec2d& v); |
|---|
| 60 | void writeVec3d(const osg::Vec3d& v); |
|---|
| 61 | void writeVec4d(const osg::Vec4d& v); |
|---|
| 62 | void writePlane(const osg::Plane& v); |
|---|
| 63 | void writeVec4ub(const osg::Vec4ub& v); |
|---|
| 64 | void writeQuat(const osg::Quat& q); |
|---|
| 65 | void writeBinding(osg::Geometry::AttributeBinding b); |
|---|
| 66 | void writeArray(const osg::Array* a); |
|---|
| 67 | void writeIntArray(const osg::IntArray* a); |
|---|
| 68 | void writeUByteArray(const osg::UByteArray* a); |
|---|
| 69 | void writeUShortArray(const osg::UShortArray* a); |
|---|
| 70 | void writeUIntArray(const osg::UIntArray* a); |
|---|
| 71 | void writeVec4ubArray(const osg::Vec4ubArray* a); |
|---|
| 72 | void writeVec2b(const osg::Vec2b& v); |
|---|
| 73 | void writeVec3b(const osg::Vec3b& v); |
|---|
| 74 | void writeVec4b(const osg::Vec4b& v); |
|---|
| 75 | |
|---|
| 76 | void writePackedFloatArray(const osg::FloatArray* a, float maxError); |
|---|
| 77 | |
|---|
| 78 | void writeFloatArray(const osg::FloatArray* a); |
|---|
| 79 | void writeVec2Array(const osg::Vec2Array* a); |
|---|
| 80 | void writeVec3Array(const osg::Vec3Array* a); |
|---|
| 81 | void writeVec4Array(const osg::Vec4Array* a); |
|---|
| 82 | void writeVec2sArray(const osg::Vec2sArray* a); |
|---|
| 83 | void writeVec3sArray(const osg::Vec3sArray* a); |
|---|
| 84 | void writeVec4sArray(const osg::Vec4sArray* a); |
|---|
| 85 | void writeVec2bArray(const osg::Vec2bArray* a); |
|---|
| 86 | void writeVec3bArray(const osg::Vec3bArray* a); |
|---|
| 87 | void writeVec4bArray(const osg::Vec4bArray* a); |
|---|
| 88 | void writeVec2dArray(const osg::Vec2dArray* a); |
|---|
| 89 | void writeVec3dArray(const osg::Vec3dArray* a); |
|---|
| 90 | void writeVec4dArray(const osg::Vec4dArray* a); |
|---|
| 91 | void writeMatrixf(const osg::Matrixf& mat); |
|---|
| 92 | void writeMatrixd(const osg::Matrixd& mat); |
|---|
| 93 | |
|---|
| 94 | void writeStateSet(const osg::StateSet* stateset); |
|---|
| 95 | void writeStateAttribute(const osg::StateAttribute* sa); |
|---|
| 96 | void writeUniform(const osg::Uniform* uniform); |
|---|
| 97 | void writeShader(const osg::Shader* shader); |
|---|
| 98 | void writeDrawable(const osg::Drawable* sa); |
|---|
| 99 | void writeShape(const osg::Shape* sa); |
|---|
| 100 | void writeNode(const osg::Node* sa); |
|---|
| 101 | void writeImage(IncludeImageMode mode, osg::Image *image); |
|---|
| 102 | void writeImage(osg::Image *image); |
|---|
| 103 | |
|---|
| 104 | void writeLayer(const osgTerrain::Layer* layer); |
|---|
| 105 | void writeLocator(const osgTerrain::Locator* locator); |
|---|
| 106 | |
|---|
| 107 | void writeVolumeLayer(const osgVolume::Layer* layer); |
|---|
| 108 | void writeVolumeLocator(const osgVolume::Locator* locator); |
|---|
| 109 | void writeVolumeProperty(const osgVolume::Property* propety); |
|---|
| 110 | |
|---|
| 111 | void writeObject(const osg::Object* object); |
|---|
| 112 | |
|---|
| 113 | void setWriteDirectory(const std::string& directoryName) { _writeDirectory = directoryName; } |
|---|
| 114 | const std::string& getWriteDirectory() const { return _writeDirectory; } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | void setIncludeImageMode(IncludeImageMode mode) {_includeImageMode=mode;}; |
|---|
| 118 | IncludeImageMode getIncludeImageMode() const {return _includeImageMode;}; |
|---|
| 119 | IncludeImageMode getIncludeImageMode(const osg::Image* image) const; |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | void setIncludeExternalReferences(bool b) {_includeExternalReferences=b;}; |
|---|
| 123 | bool getIncludeExternalReferences() const {return _includeExternalReferences;}; |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | void setWriteExternalReferenceFiles(bool b) {_writeExternalReferenceFiles=b;}; |
|---|
| 127 | bool getWriteExternalReferenceFiles() const {return _writeExternalReferenceFiles;}; |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | void setUseOriginalExternalReferences(bool b) {_useOriginalExternalReferences=b;}; |
|---|
| 131 | bool getUseOriginalExternalReferences() const {return _useOriginalExternalReferences;}; |
|---|
| 132 | |
|---|
| 133 | void setTerrainMaximumErrorToSizeRatio(double ratio) { _maximumErrorToSizeRatio = ratio; } |
|---|
| 134 | double getTerrainMaximumErrorToSizeRatio() const { return _maximumErrorToSizeRatio; } |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | bool _verboseOutput; |
|---|
| 138 | |
|---|
| 139 | bool compress(std::ostream& fout, const std::string& source) const; |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | void setExternalFileWritten(const std::string& filename, bool hasBeenWritten=true); |
|---|
| 143 | bool getExternalFileWritten(const std::string& filename) const; |
|---|
| 144 | |
|---|
| 145 | void throwException(const std::string& message) { _exception = new Exception(message); } |
|---|
| 146 | void throwException(Exception* exception) { _exception = exception; } |
|---|
| 147 | const Exception* getException() const { return _exception.get(); } |
|---|
| 148 | |
|---|
| 149 | private: |
|---|
| 150 | |
|---|
| 151 | std::ostream* _ostream; |
|---|
| 152 | std::ostream* _output_ostream; |
|---|
| 153 | |
|---|
| 154 | std::stringstream _compressionStream; |
|---|
| 155 | int _compressionLevel; |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | typedef std::map<const osg::StateSet*,int> StateSetMap; |
|---|
| 159 | typedef std::map<const osg::StateAttribute*,int> StateAttributeMap; |
|---|
| 160 | typedef std::map<const osg::Uniform*,int> UniformMap; |
|---|
| 161 | typedef std::map<const osg::Shader*,int> ShaderMap; |
|---|
| 162 | typedef std::map<const osg::Drawable*,int> DrawableMap; |
|---|
| 163 | typedef std::map<const osg::Shape*,int> ShapeMap; |
|---|
| 164 | typedef std::map<const osg::Node*,int> NodeMap; |
|---|
| 165 | typedef std::map<const osgTerrain::Layer*,int> LayerMap; |
|---|
| 166 | typedef std::map<const osgTerrain::Locator*,int> LocatorMap; |
|---|
| 167 | typedef std::map<const osgVolume::Layer*,int> VolumeLayerMap; |
|---|
| 168 | typedef std::map<const osgVolume::Locator*,int> VolumeLocatorMap; |
|---|
| 169 | typedef std::map<const osgVolume::Property*,int> VolumePropertyMap; |
|---|
| 170 | |
|---|
| 171 | StateSetMap _stateSetMap; |
|---|
| 172 | StateAttributeMap _stateAttributeMap; |
|---|
| 173 | UniformMap _uniformMap; |
|---|
| 174 | ShaderMap _shaderMap; |
|---|
| 175 | DrawableMap _drawableMap; |
|---|
| 176 | ShapeMap _shapeMap; |
|---|
| 177 | NodeMap _nodeMap; |
|---|
| 178 | LayerMap _layerMap; |
|---|
| 179 | LocatorMap _locatorMap; |
|---|
| 180 | VolumeLayerMap _volumeLayerMap; |
|---|
| 181 | VolumeLocatorMap _volumeLocatorMap; |
|---|
| 182 | VolumePropertyMap _volumePropertyMap; |
|---|
| 183 | |
|---|
| 184 | std::string _writeDirectory; |
|---|
| 185 | bool _includeExternalReferences; |
|---|
| 186 | bool _writeExternalReferenceFiles; |
|---|
| 187 | bool _useOriginalExternalReferences; |
|---|
| 188 | double _maximumErrorToSizeRatio; |
|---|
| 189 | |
|---|
| 190 | IncludeImageMode _includeImageMode; |
|---|
| 191 | |
|---|
| 192 | osg::ref_ptr<const osgDB::ReaderWriter::Options> _options; |
|---|
| 193 | |
|---|
| 194 | typedef std::map<std::string, bool> ExternalFileWrittenMap; |
|---|
| 195 | ExternalFileWrittenMap _externalFileWritten; |
|---|
| 196 | |
|---|
| 197 | osg::ref_ptr<Exception> _exception; |
|---|
| 198 | }; |
|---|
| 199 | |
|---|
| 200 | } |
|---|
| 201 | #endif // IVE_DATAOUTPUTSTREAM |
|---|