00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PARSER_EXPAT_H__
00021 #define __PARSER_EXPAT_H__
00022
00023 #include <vector>
00024 #include <iostream>
00025 #include <sstream>
00026 #include <fstream>
00027 #include <bzlib.h>
00028 #include <cassert>
00029 #include <iterator>
00030 #include <expat.h>
00031 #include <algorithm>
00032
00033 #include "../utils/utils.h"
00034 #include "expatmm/expatmm.h"
00035 #include "parser_utils.h"
00036
00037 #ifndef CONVERTER
00038 #include "../segmentation/StableSegmentation/stablesegmentationreader.h"
00039 #include "../segmentation/TimeSegmentation/timesegmentationreader.h"
00040 #include "../segmentation/cluster.h"
00041 #include "../mesh/mesh.h"
00042 #endif
00043
00060 namespace ParserNS {
00061
00062 using namespace expatmm;
00063 using MeshNS::SimpleMesh;
00064 using MeshNS::SimpleVertex;
00065 using MeshNS::SimpleFace;
00066
00097 template<class V, class F,
00098 template<class U, class V = std::allocator<U> > class C>
00099 class Parser: public ExpatXMLFileParser {
00100
00101 public:
00112 typedef enum {
00113 Immediate, Callback, Progressive
00114 } Mode;
00115
00124 Parser(std::string path, Parser::Mode mode) :
00125 ExpatXMLFileParser(), _path(path), _mode(mode), MS(false), dm(false),
00126 ms(false), mesh(false), face(false), vertices(false), _first(
00127 true), _face(false), _vertices(false), _time(false),
00128 _stable(false), _vertex(false) {
00129 }
00130
00135 void parse();
00144 void write(const MeshSequenceType& type, const int& frame,
00145 const C<C<V> >& verts, const C<C<F> >& faces);
00146
00147 #ifndef CONVERTER
00148 inline int getNbFrame() const {
00149 return _nbFrames;
00150 }
00151 inline MeshSequenceType getMSType() const {
00152 return _mst;
00153 }
00154 const C<C<V> >& getVerticesInTime() const {
00155 return _verticesInTime;
00156 }
00157 const C<C<F> >& getFacesInTime() const {
00158 return _facesInTime;
00159 }
00160 C<SegmentationNS::SegmentationPtr> getSegmentation() {
00161 return _segmentation;
00162 }
00163
00164 void setSegmentation(const C<SegmentationNS::SegmentationPtr>& seg) {
00165 _segmentation = seg;
00166 }
00167 void setMeshSequence(MeshNS::MeshSequencePtr ms) {
00168 _msCallBack = ms;
00169 }
00170
00171
00172 MeshNS::PolyhedronPtr getNext() {
00173 }
00174
00175
00176
00177
00178
00179
00180 #endif
00181
00182 private:
00183 void writeMesh(std::ofstream& root, const C<C<V> >& verts,
00184 const C<C<F> >& faces, int which);
00185
00186 void writeFaces(std::ofstream& root, const C<C<F> >&f, int which);
00187 void writeVertices(std::ofstream& root, const C<C<V> >& verts, int which);
00188
00189 #ifndef CONVERTER
00190 void writeProcessing(std::ofstream& root, const C<
00191 SegmentationNS::SegmentationPtr>& segmentation);
00192 void writeSegmentation(std::ofstream& root, const C<
00193 SegmentationNS::SegmentationPtr>& segmentations);
00194 void readGroup(const std::string& buf);
00195 #endif
00196 virtual void StartElement(const XML_Char *name, const XML_Char **attrs M_UNUSED);
00197 virtual void EndElement(const XML_Char *name);
00198 virtual void CharacterData(const XML_Char *s, int len) {
00199 std::string data(s, len);
00200 buffer += data;
00201 }
00202
00203 private:
00204 void uncompress();
00205 void compress() const;
00206
00207 std::string _path;
00208 std::string _name;
00209 Mode _mode;
00210 int _nbFrames;
00211 C<C<V> > _verticesInTime;
00212 C<C<F> > _facesInTime;
00213
00214 MeshSequenceType _mst;
00215
00216 bool MS;
00217 bool dm, ms;
00218 bool mesh;
00219 bool face;
00220 bool vertices;
00221 bool _first;
00222
00223 bool _face;
00224 bool _vertices;
00225 bool _time;
00226 bool _stable;
00227 bool _vertex;
00228
00229 F _currentFace;
00230 C<F> _currentFaceMesh;
00231 V _currentVertex;
00232 C<V> _currentVerticesMesh;
00233
00234 #ifndef CONVERTER
00235 C<SegmentationNS::Cluster> _currentSegmentation;
00236 SegmentationNS::Cluster _currentCluster;
00237 MeshNS::MeshSequencePtr _msCallBack;
00238
00239 C<SegmentationNS::SegmentationPtr> _segmentation;
00240 #endif
00241 std::string buffer;
00242
00243 };
00244 #include "parser.impl"
00245 }
00246
00247 #endif