| 1 | #ifndef ESRI_SHAPE_PARSER_H |
|---|
| 2 | #define ESRI_SHAPE_PARSER_H |
|---|
| 3 | |
|---|
| 4 | #include <string> |
|---|
| 5 | #include <osg/Geode> |
|---|
| 6 | |
|---|
| 7 | #include "ESRIShape.h" |
|---|
| 8 | |
|---|
| 9 | namespace ESRIShape { |
|---|
| 10 | |
|---|
| 11 | class ArrayHelper |
|---|
| 12 | { |
|---|
| 13 | public: |
|---|
| 14 | ArrayHelper(bool useDouble) |
|---|
| 15 | { |
|---|
| 16 | if (useDouble) _vec3darray = new osg::Vec3dArray; |
|---|
| 17 | else _vec3farray = new osg::Vec3Array; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | osg::Array* get() { return _vec3farray.valid() ? |
|---|
| 21 | static_cast<osg::Array*>(_vec3farray.get()) : |
|---|
| 22 | static_cast<osg::Array*>(_vec3darray.get()); } |
|---|
| 23 | |
|---|
| 24 | unsigned int size() { return _vec3farray.valid() ? |
|---|
| 25 | _vec3farray->size() : |
|---|
| 26 | _vec3darray->size(); } |
|---|
| 27 | |
|---|
| 28 | void add(double x, double y, double z) |
|---|
| 29 | { |
|---|
| 30 | if (_vec3farray.valid()) _vec3farray->push_back(osg::Vec3(x,y,z)); |
|---|
| 31 | else _vec3darray->push_back(osg::Vec3d(x,y,z)); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | void add(const osg::Vec3& v) |
|---|
| 35 | { |
|---|
| 36 | if (_vec3farray.valid()) _vec3farray->push_back(v); |
|---|
| 37 | else _vec3darray->push_back(osg::Vec3d(v.x(),v.y(),v.z())); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | void add(const osg::Vec3d& v) |
|---|
| 41 | { |
|---|
| 42 | if (_vec3farray.valid()) _vec3farray->push_back(osg::Vec3(v.x(),v.y(),v.z())); |
|---|
| 43 | else _vec3darray->push_back(v); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | void add(osg::Array* array, unsigned int index) |
|---|
| 47 | { |
|---|
| 48 | osg::Vec3Array* vec3Array = dynamic_cast<osg::Vec3Array*>(array); |
|---|
| 49 | if (vec3Array && index<vec3Array->size()) add((*vec3Array)[index]); |
|---|
| 50 | |
|---|
| 51 | osg::Vec3dArray* vec3dArray = dynamic_cast<osg::Vec3dArray*>(array); |
|---|
| 52 | if (vec3dArray && index<vec3dArray->size()) add((*vec3dArray)[index]); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | osg::ref_ptr<osg::Vec3Array> _vec3farray; |
|---|
| 56 | osg::ref_ptr<osg::Vec3dArray> _vec3darray; |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | class ESRIShapeParser |
|---|
| 61 | { |
|---|
| 62 | public: |
|---|
| 63 | |
|---|
| 64 | ESRIShapeParser( const std::string fileName, bool useDouble); |
|---|
| 65 | |
|---|
| 66 | osg::Geode *getGeode(); |
|---|
| 67 | |
|---|
| 68 | #if 0 |
|---|
| 69 | #if 1 |
|---|
| 70 | typedef osg::Vec3d ShapeVec3; |
|---|
| 71 | typedef osg::Vec3dArray ShapeVec3Array; |
|---|
| 72 | #else |
|---|
| 73 | typedef osg::Vec3 ShapeVec3; |
|---|
| 74 | typedef osg::Vec3Array ShapeVec3Array; |
|---|
| 75 | #endif |
|---|
| 76 | #endif |
|---|
| 77 | |
|---|
| 78 | private: |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | bool _valid; |
|---|
| 83 | bool _useDouble; |
|---|
| 84 | |
|---|
| 85 | osg::ref_ptr<osg::Geode> _geode; |
|---|
| 86 | |
|---|
| 87 | void _combinePointToMultipoint(); |
|---|
| 88 | void _process( const std::vector<ESRIShape::Point> &); |
|---|
| 89 | void _process( const std::vector<ESRIShape::MultiPoint> &); |
|---|
| 90 | void _process( const std::vector<ESRIShape::PolyLine> &); |
|---|
| 91 | void _process( const std::vector<ESRIShape::Polygon> &); |
|---|
| 92 | |
|---|
| 93 | void _process( const std::vector<ESRIShape::PointM> &); |
|---|
| 94 | void _process( const std::vector<ESRIShape::MultiPointM> &); |
|---|
| 95 | void _process( const std::vector<ESRIShape::PolyLineM> &); |
|---|
| 96 | void _process( const std::vector<ESRIShape::PolygonM> &); |
|---|
| 97 | |
|---|
| 98 | void _process( const std::vector<ESRIShape::PointZ> &); |
|---|
| 99 | void _process( const std::vector<ESRIShape::MultiPointZ> &); |
|---|
| 100 | void _process( const std::vector<ESRIShape::PolyLineZ> &); |
|---|
| 101 | void _process( const std::vector<ESRIShape::PolygonZ> &); |
|---|
| 102 | void _process( const std::vector<ESRIShape::MultiPatch> &); |
|---|
| 103 | |
|---|
| 104 | }; |
|---|
| 105 | |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | #endif |
|---|