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