[180] | 1 | #ifndef _X3D_PARSER_XERCES__H
|
---|
| 2 | #define _X3D_PARSER_XERCES__H
|
---|
| 3 |
|
---|
| 4 | // ---------------------------------------------------------------------------
|
---|
| 5 | // Includes
|
---|
| 6 | // ---------------------------------------------------------------------------
|
---|
| 7 | #include <xercesc/sax/HandlerBase.hpp>
|
---|
[261] | 8 | #include "Mesh.h"
|
---|
[712] | 9 | #include <stack>
|
---|
[180] | 10 |
|
---|
| 11 | XERCES_CPP_NAMESPACE_USE
|
---|
| 12 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 13 | class AttributeList;
|
---|
| 14 | XERCES_CPP_NAMESPACE_END
|
---|
| 15 |
|
---|
[860] | 16 | namespace GtpVisibilityPreprocessor {
|
---|
| 17 |
|
---|
[180] | 18 | class SceneGraphNode;
|
---|
| 19 | class Mesh;
|
---|
| 20 | class Material;
|
---|
[439] | 21 | class ViewCellsManager;
|
---|
[180] | 22 |
|
---|
[971] | 23 |
|
---|
[752] | 24 | struct ltstr
|
---|
| 25 | {
|
---|
| 26 | bool operator()(const string &s1, const string &s2) const
|
---|
| 27 | {
|
---|
| 28 | return s1 < s2;
|
---|
| 29 | }
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 | typedef map<string, Mesh *, ltstr> MeshDefinitions;
|
---|
| 33 | typedef map<string, Material *, ltstr> MaterialDefinitions;
|
---|
| 34 |
|
---|
[180] | 35 | class X3dParseHandlers : public HandlerBase
|
---|
| 36 | {
|
---|
| 37 | public:
|
---|
| 38 | // -----------------------------------------------------------------------
|
---|
| 39 | // Constructors and Destructor
|
---|
| 40 | // -----------------------------------------------------------------------
|
---|
[657] | 41 | X3dParseHandlers(SceneGraphNode *root, const bool loadPolygonsAsMeshes = false);
|
---|
[180] | 42 | ~X3dParseHandlers();
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | // -----------------------------------------------------------------------
|
---|
| 46 | // Getter methods
|
---|
| 47 | // -----------------------------------------------------------------------
|
---|
| 48 | unsigned int GetElementCount()
|
---|
| 49 | {
|
---|
| 50 | return mElementCount;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | unsigned int GetAttrCount()
|
---|
| 54 | {
|
---|
| 55 | return mAttrCount;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | unsigned int GetCharacterCount()
|
---|
| 59 | {
|
---|
| 60 | return mCharacterCount;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | unsigned int GetSpaceCount()
|
---|
| 64 | {
|
---|
| 65 | return mSpaceCount;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | // -----------------------------------------------------------------------
|
---|
| 70 | // Handlers for the SAX DocumentHandler interface
|
---|
| 71 | // -----------------------------------------------------------------------
|
---|
| 72 | void endElement(const XMLCh* const name);
|
---|
| 73 | void startElement(const XMLCh* const name, AttributeList& attributes);
|
---|
| 74 | void characters(const XMLCh* const chars, const unsigned int length);
|
---|
| 75 | void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
|
---|
| 76 | void resetDocument();
|
---|
| 77 |
|
---|
| 78 | SceneGraphNode *mCurrentNode;
|
---|
| 79 | Mesh *mCurrentMesh;
|
---|
[658] | 80 | vector<VertexIndexContainer> mCurrentVertexIndices;
|
---|
| 81 | VertexContainer mCurrentVertices;
|
---|
[752] | 82 | string mCurrentMeshName;
|
---|
[658] | 83 |
|
---|
[180] | 84 | Material *mCurrentMaterial;
|
---|
[752] | 85 |
|
---|
[657] | 86 | bool mLoadPolygonsAsMeshes;
|
---|
[490] | 87 |
|
---|
[712] | 88 | typedef stack<Matrix4x4> TrafoStack;
|
---|
| 89 |
|
---|
[752] | 90 | bool mUsingMeshDefinition;
|
---|
[712] | 91 | // stack of accumulated transformations
|
---|
| 92 | TrafoStack mTransformations;
|
---|
| 93 |
|
---|
[752] | 94 | MaterialDefinitions mMaterialDefinitions;
|
---|
| 95 | MeshDefinitions mMeshDefinitions;
|
---|
| 96 |
|
---|
[801] | 97 | // TODO: for storing meshes
|
---|
| 98 | MeshContainer *mMeshes;
|
---|
[752] | 99 | bool mIsMeshDefinition;
|
---|
[180] | 100 | // Handlers for X3D
|
---|
| 101 | void
|
---|
| 102 | StartIndexedFaceSet(
|
---|
| 103 | AttributeList& attributes);
|
---|
| 104 |
|
---|
| 105 | void
|
---|
| 106 | EndShape();
|
---|
| 107 |
|
---|
[712] | 108 | void EndTransform();
|
---|
| 109 | void StartTransform(AttributeList& attributes);
|
---|
| 110 |
|
---|
[180] | 111 | void
|
---|
| 112 | StartCoordinate(
|
---|
| 113 | AttributeList& attributes);
|
---|
| 114 |
|
---|
| 115 | void
|
---|
| 116 | StartMaterial(
|
---|
| 117 | AttributeList& attributes);
|
---|
| 118 |
|
---|
[712] | 119 | /// applies transformation m to this mesh
|
---|
| 120 | void ApplyTransformation(Mesh *mesh, const Matrix4x4 &m) const;
|
---|
| 121 |
|
---|
| 122 | /// transforms mesh using the given transformations
|
---|
| 123 | void ApplyTransformations(TrafoStack trafos, Mesh *mesh) const;
|
---|
| 124 |
|
---|
| 125 |
|
---|
[180] | 126 | // -----------------------------------------------------------------------
|
---|
| 127 | // Handlers for the SAX ErrorHandler interface
|
---|
| 128 | // -----------------------------------------------------------------------
|
---|
| 129 | void warning(const SAXParseException& exc);
|
---|
| 130 | void error(const SAXParseException& exc);
|
---|
| 131 | void fatalError(const SAXParseException& exc);
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | private:
|
---|
| 135 | // -----------------------------------------------------------------------
|
---|
| 136 | // Private data members
|
---|
| 137 | //
|
---|
| 138 | // fAttrCount
|
---|
| 139 | // fCharacterCount
|
---|
| 140 | // fElementCount
|
---|
| 141 | // fSpaceCount
|
---|
| 142 | // These are just counters that are run upwards based on the input
|
---|
| 143 | // from the document handlers.
|
---|
| 144 | // -----------------------------------------------------------------------
|
---|
| 145 | unsigned int mAttrCount;
|
---|
| 146 | unsigned int mCharacterCount;
|
---|
| 147 | unsigned int mElementCount;
|
---|
| 148 | unsigned int mSpaceCount;
|
---|
| 149 | };
|
---|
| 150 |
|
---|
[260] | 151 | /** Parser handlers for view cell x3d files.
|
---|
| 152 | */
|
---|
| 153 | class X3dViewCellsParseHandlers : public HandlerBase
|
---|
| 154 | {
|
---|
| 155 | public:
|
---|
| 156 | // -----------------------------------------------------------------------
|
---|
| 157 | // Constructors and Destructor
|
---|
| 158 | // -----------------------------------------------------------------------
|
---|
[439] | 159 | X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager,
|
---|
[657] | 160 | const float viewCellHeight);
|
---|
[260] | 161 | ~X3dViewCellsParseHandlers();
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | // -----------------------------------------------------------------------
|
---|
| 165 | // Getter methods
|
---|
| 166 | // -----------------------------------------------------------------------
|
---|
| 167 | unsigned int GetElementCount()
|
---|
| 168 | {
|
---|
| 169 | return mElementCount;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | unsigned int GetAttrCount()
|
---|
| 173 | {
|
---|
| 174 | return mAttrCount;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | unsigned int GetCharacterCount()
|
---|
| 178 | {
|
---|
| 179 | return mCharacterCount;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | unsigned int GetSpaceCount()
|
---|
| 183 | {
|
---|
| 184 | return mSpaceCount;
|
---|
| 185 | }
|
---|
[180] | 186 |
|
---|
[260] | 187 |
|
---|
| 188 | // -----------------------------------------------------------------------
|
---|
| 189 | // Handlers for the SAX DocumentHandler interface
|
---|
| 190 | // -----------------------------------------------------------------------
|
---|
| 191 | void endElement(const XMLCh* const name);
|
---|
| 192 | void startElement(const XMLCh* const name, AttributeList& attributes);
|
---|
| 193 | void characters(const XMLCh* const chars, const unsigned int length);
|
---|
| 194 | void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
|
---|
| 195 | void resetDocument();
|
---|
| 196 |
|
---|
[439] | 197 | ViewCellsManager *mViewCellsManager;
|
---|
[312] | 198 | float mViewCellHeight;
|
---|
[657] | 199 |
|
---|
[312] | 200 |
|
---|
[261] | 201 | VertexIndexContainer mCurrentVertexIndices;
|
---|
[658] | 202 |
|
---|
[260] | 203 | // Handlers for X3D
|
---|
| 204 | void
|
---|
| 205 | StartIndexedFaceSet(
|
---|
| 206 | AttributeList& attributes);
|
---|
| 207 |
|
---|
| 208 | void
|
---|
| 209 | EndShape();
|
---|
| 210 |
|
---|
| 211 | void
|
---|
| 212 | StartCoordinate(
|
---|
| 213 | AttributeList& attributes);
|
---|
| 214 |
|
---|
| 215 | void
|
---|
| 216 | StartMaterial(
|
---|
| 217 | AttributeList& attributes);
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | // -----------------------------------------------------------------------
|
---|
| 221 | // Handlers for the SAX ErrorHandler interface
|
---|
| 222 | // -----------------------------------------------------------------------
|
---|
| 223 | void warning(const SAXParseException& exc);
|
---|
| 224 | void error(const SAXParseException& exc);
|
---|
| 225 | void fatalError(const SAXParseException& exc);
|
---|
| 226 |
|
---|
| 227 |
|
---|
| 228 | private:
|
---|
| 229 | // -----------------------------------------------------------------------
|
---|
| 230 | // Private data members
|
---|
| 231 | //
|
---|
| 232 | // fAttrCount
|
---|
| 233 | // fCharacterCount
|
---|
| 234 | // fElementCount
|
---|
| 235 | // fSpaceCount
|
---|
| 236 | // These are just counters that are run upwards based on the input
|
---|
| 237 | // from the document handlers.
|
---|
| 238 | // -----------------------------------------------------------------------
|
---|
| 239 | unsigned int mAttrCount;
|
---|
| 240 | unsigned int mCharacterCount;
|
---|
| 241 | unsigned int mElementCount;
|
---|
| 242 | unsigned int mSpaceCount;
|
---|
| 243 | };
|
---|
| 244 |
|
---|
| 245 |
|
---|
[180] | 246 | // ---------------------------------------------------------------------------
|
---|
| 247 | // This is a simple class that lets us do easy (though not terribly efficient)
|
---|
| 248 | // trancoding of XMLCh data to local code page for display.
|
---|
| 249 | // ---------------------------------------------------------------------------
|
---|
| 250 | class StrX
|
---|
| 251 | {
|
---|
| 252 | public :
|
---|
| 253 | // -----------------------------------------------------------------------
|
---|
| 254 | // Constructors and Destructor
|
---|
| 255 | // -----------------------------------------------------------------------
|
---|
| 256 | StrX(const XMLCh* const toTranscode)
|
---|
| 257 | {
|
---|
| 258 | // Call the private transcoding method
|
---|
| 259 | mLocalForm = XMLString::transcode(toTranscode);
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | ~StrX()
|
---|
| 263 | {
|
---|
| 264 | XMLString::release(&mLocalForm);
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | // -----------------------------------------------------------------------
|
---|
| 268 | // Getter methods
|
---|
| 269 | // -----------------------------------------------------------------------
|
---|
| 270 | const char* LocalForm() const
|
---|
| 271 | {
|
---|
| 272 | return mLocalForm;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | private :
|
---|
| 276 | // -----------------------------------------------------------------------
|
---|
| 277 | // Private data members
|
---|
| 278 | //
|
---|
| 279 | // fLocalForm
|
---|
| 280 | // This is the local code page form of the string.
|
---|
| 281 | // -----------------------------------------------------------------------
|
---|
| 282 | char* mLocalForm;
|
---|
| 283 | };
|
---|
| 284 |
|
---|
| 285 | inline XERCES_STD_QUALIFIER ostream&
|
---|
| 286 | operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
| 287 | {
|
---|
| 288 | target << toDump.LocalForm();
|
---|
| 289 | return target;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
[860] | 292 | }
|
---|
| 293 |
|
---|
[180] | 294 | #endif
|
---|