📄 esrishapeparser.cpp
字号:
void ESRIShapeParser::_process( const std::vector<ESRIShape::Polygon> &polys ){ if( !_valid ) return; std::vector<ESRIShape::Polygon>::const_iterator p; for( p = polys.begin(); p != polys.end(); p++ ) { ArrayHelper coords(_useDouble); int i; for( i = 0; i < p->numPoints; i++ ) coords.add( p->points[i].x, p->points[i].y, 0.0 ); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); for( i = 0; i < p->numParts; i++ ) { int index = p->parts[i]; int len = i < p->numParts - 1 ? p->parts[i+1] - p->parts[i] : p->numPoints - p->parts[i]; geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::POLYGON, index, len)); } // Use osgUtil::Tessellator to handle concave polygons osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator; tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); tscx->setBoundaryOnly(false); tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); tscx->retessellatePolygons(*(geometry.get())); _geode->addDrawable( geometry.get() ); }}void ESRIShapeParser::_process( const std::vector<ESRIShape::PointM> &ptms ){ if( !_valid ) return; std::vector<ESRIShape::PointM>::const_iterator p; for( p = ptms.begin(); p != ptms.end(); p++ ) { ArrayHelper coords(_useDouble); coords.add( p->x, p->y, 0.0 ); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, 1)); _geode->addDrawable( geometry.get() ); } if( _geode->getNumDrawables() > 1 ) _combinePointToMultipoint();}void ESRIShapeParser::_process( const std::vector<ESRIShape::MultiPointM> &mptms ){ if( !_valid ) return; std::vector<ESRIShape::MultiPointM>::const_iterator p; for( p = mptms.begin(); p != mptms.end(); p++ ) { osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array; // Here is where we would use the 'M' (?) for( int i = 0; i < p->numPoints ; i++ ) coords->push_back( osg::Vec3( p->points[i].x, p->points[i].y, 0.0 )); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, coords->size())); _geode->addDrawable( geometry.get() ); }}void ESRIShapeParser::_process(const std::vector<ESRIShape::PolyLineM> &linems ){ if( !_valid ) return; std::vector<ESRIShape::PolyLineM>::const_iterator p; for( p = linems.begin(); p != linems.end(); p++ ) { osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array; int i; for( i = 0; i < p->numPoints; i++ ) coords->push_back( osg::Vec3( p->points[i].x, p->points[i].y, 0.0 )); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); for( i = 0; i < p->numParts; i++ ) { int index = p->parts[i]; int len = i < p->numParts - 1 ? p->parts[i+1] - p->parts[i] : p->numPoints - p->parts[i]; geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, index, len)); } _geode->addDrawable( geometry.get() ); }}void ESRIShapeParser::_process( const std::vector<ESRIShape::PolygonM> &polyms ){ if( !_valid ) return; std::vector<ESRIShape::PolygonM>::const_iterator p; for( p = polyms.begin(); p != polyms.end(); p++ ) { osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array; int i; for( i = 0; i < p->numPoints; i++ ) coords->push_back( osg::Vec3( p->points[i].x, p->points[i].y, 0.0 )); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); for( i = 0; i < p->numParts; i++ ) { int index = p->parts[i]; int len = i < p->numParts - 1 ? p->parts[i+1] - p->parts[i] : p->numPoints - p->parts[i]; geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::POLYGON, index, len)); } _geode->addDrawable( geometry.get() ); }}void ESRIShapeParser::_process( const std::vector<ESRIShape::PointZ> &ptzs ){ if( !_valid ) return; std::vector<ESRIShape::PointZ>::const_iterator p; for( p = ptzs.begin(); p != ptzs.end(); p++ ) { osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array; coords->push_back( osg::Vec3( p->x, p->y, p->z )); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, 1)); _geode->addDrawable( geometry.get() ); } if( _geode->getNumDrawables() > 1 ) _combinePointToMultipoint();}void ESRIShapeParser::_process( const std::vector<ESRIShape::MultiPointZ> &mptzs ){ if( !_valid ) return; std::vector<ESRIShape::MultiPointZ>::const_iterator p; for( p = mptzs.begin(); p != mptzs.end(); p++ ) { osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array; // Here is where we would use the 'M' (?) for( int i = 0; i < p->numPoints ; i++ ) coords->push_back( osg::Vec3( p->points[i].x, p->points[i].y, p->zArray[i] )); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, coords->size())); _geode->addDrawable( geometry.get() ); }}void ESRIShapeParser::_process(const std::vector<ESRIShape::PolyLineZ> &linezs ){ if( !_valid ) return; std::vector<ESRIShape::PolyLineZ>::const_iterator p; for( p = linezs.begin(); p != linezs.end(); p++ ) { osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array; int i; for( i = 0; i < p->numPoints; i++ ) coords->push_back( osg::Vec3( p->points[i].x, p->points[i].y, p->zArray[i] )); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); for( i = 0; i < p->numParts; i++ ) { int index = p->parts[i]; int len = i < p->numParts - 1 ? p->parts[i+1] - p->parts[i] : p->numPoints - p->parts[i]; geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, index, len)); } _geode->addDrawable( geometry.get() ); }}void ESRIShapeParser::_process( const std::vector<ESRIShape::PolygonZ> &polyzs ){ if( !_valid ) return; std::vector<ESRIShape::PolygonZ>::const_iterator p; for( p = polyzs.begin(); p != polyzs.end(); p++ ) { osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array; int i; for( i = 0; i < p->numPoints; i++ ) coords->push_back( osg::Vec3( p->points[i].x, p->points[i].y, p->zArray[i] )); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); for( i = 0; i < p->numParts; i++ ) { int index = p->parts[i]; int len = i < p->numParts - 1 ? p->parts[i+1] - p->parts[i] : p->numPoints - p->parts[i]; geometry->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::POLYGON, index, len)); } _geode->addDrawable( geometry.get() ); }}void ESRIShapeParser::_process( const std::vector<ESRIShape::MultiPatch> &mpatches ){ if( !_valid ) return; std::vector<ESRIShape::MultiPatch>::const_iterator p; for( p = mpatches.begin(); p != mpatches.end(); p++ ) { osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array; int i; for( i = 0; i < p->numPoints; i++ ) coords->push_back( osg::Vec3( p->points[i].x, p->points[i].y, p->zArray[i] )); osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); // Lets mark poorly supported primitives with red, otherwise white osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; geometry->setColorArray(colors.get()); geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX ); for( i = 0; i < p->numParts; i++ ) { int index = p->parts[i]; int len = i < p->numParts - 1 ? p->parts[i+1] - p->parts[i] : p->numPoints - p->parts[i]; int mode = p->partTypes[i] == TriangleStrip ? osg::PrimitiveSet::TRIANGLE_STRIP : p->partTypes[i] == TriangleFan ? osg::PrimitiveSet::TRIANGLE_FAN : // HACK for now p->partTypes[i] == OuterRing ? osg::PrimitiveSet::LINE_STRIP : p->partTypes[i] == InnerRing ? osg::PrimitiveSet::LINE_STRIP : p->partTypes[i] == FirstRing ? osg::PrimitiveSet::LINE_STRIP : p->partTypes[i] == Ring ? osg::PrimitiveSet::LINE_STRIP : osg::PrimitiveSet::POINTS ; if( p->partTypes[i] == OuterRing || p->partTypes[i] == InnerRing || p->partTypes[i] == FirstRing || p->partTypes[i] == Ring ) { osg::notify(osg::WARN) << "ESRIShapeParser - MultiPatch type " << (p->partTypes[i] == TriangleStrip ? "TriangleStrip": p->partTypes[i] == TriangleFan ? "TriangleFan": p->partTypes[i] == OuterRing ? "OuterRing": p->partTypes[i] == InnerRing ? "InnerRing": p->partTypes[i] == FirstRing ? "FirstRing": p->partTypes[i] == Ring ? "Ring": "Dunno") << " poorly supported. Will be represented by a red line strip" << std::endl; } // Lets mark poorly supported primitives with red, otherwise white osg::Vec4 color = p->partTypes[i] == TriangleStrip ? osg::Vec4(1.0,1.0,1.0,1.0) : p->partTypes[i] == TriangleFan ? osg::Vec4(1.0,1.0,1.0,1.0) : // HACK for now p->partTypes[i] == OuterRing ? osg::Vec4(1.0,0.0,0.0,1.0) : p->partTypes[i] == InnerRing ? osg::Vec4(1.0,0.0,0.0,1.0) : p->partTypes[i] == FirstRing ? osg::Vec4(1.0,0.0,0.0,1.0) : p->partTypes[i] == Ring ? osg::Vec4(1.0,0.0,0.0,1.0) : osg::Vec4(1.0,0.0,0.0,1.0) ; for( int j = 0; j < len; j++ ) colors->push_back( color ); geometry->addPrimitiveSet( new osg::DrawArrays(mode, index, len )); } _geode->addDrawable( geometry.get() ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -