x:-89.4588 y:-12.1245 z:-11.7807

x:-89.4588 y:-6.44823 z:-11.7807

x:-89.2164 y:-9.07239 z:-11.811

x:-89.4588 y:-12.1245 z:-11.7807

x:-89.2164 y:-9.07239 z:-11.811

x:-89.2164 y:-15.9458 z:-11.811

x:-89.4588 y:-6.44823 z:-11.7807

x:-89.2164 y:-2.19896 z:-11.811

x:-89.2164 y:-9.07239 z:-11.811

x:-89.4588 y:-6.44823 z:-11.7807

x:-89.4959 y:-2.57999 z:-11.7705

x:-89.2164 y:-2.19896 z:-11.811

x:-89.6451 y:-4.75968 z:-11.7127

x:-89.4959 y:-2.57999 z:-11.7705

x:-89.4588 y:-6.44823 z:-11.7807

x:-89.6451 y:-4.75968 z:-11.7127

x:-89.7325 y:1.15286 z:-11.6649

x:-89.4959 y:-2.57999 z:-11.7705

x:-89.7325 y:1.15286 z:-11.6649

x:-89.6451 y:-4.75968 z:-11.7127

x:-89.8026 y:-2.48957 z:-11.6174

x:-89.8026 y:-2.48957 z:-11.6174

x:-89.8883 y:1.02162 z:-11.5459

 



#ifdef _WIN32
#include <Windows.h>
#endif // _WIN32
#include<iostream>

#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/CompositeViewer>
#include <osgDB/ReadFile>
#include <osg/Geode>
#include <osg/Node>
#include <osg/Geometry>
#include <osgGA/TrackballManipulator>
#include <osg/GraphicsContext>
#include <osg/ShapeDrawable>
#include <osg/Material>
#include <osg/Image>
#include <osg/Texture2D>
#include <osg/TexEnv>
#include <osg/TexGen>
#include <osg/NodeVisitor>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osg/AnimationPath>
#include <osg/Matrixd>

#include <osgGA/GUIEventHandler>
#include <osgGA/CameraManipulator>
#include <osgGA/StandardManipulator>
#include <osgGA/OrbitManipulator>
#include <osgGA/TrackballManipulator>
#include <osgUtil/IntersectionVisitor>
#include <osgUtil/LineSegmentIntersector>

class BoundVisitor :public osg::NodeVisitor
{
public:
BoundVisitor() :osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _indent(0)
{
std::cout << "--" << std::endl;
}


virtual void apply(osg::Geode &geode)
{
//osg::Drawable *drawable1= geode.getDrawable(0);
unsigned int count = geode.getNumDrawables();
for (int i = 0; i < count; i++)
{
osg::Geometry *geometry = geode.getDrawable(i)->asGeometry();
if (!geometry)
{
continue;
}

// 顶点数据
osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray());
//osg::Vec3Array vertices = geometry->getVertexArray();
int vertexlNum = vertices->size();
for (int j = 0; j<vertexlNum; j++) {
//dstSubset.vertexs.push_back(vertices->at(j).x());
//dstSubset.vertexs.push_back(vertices->at(j).y());
//dstSubset.vertexs.push_back(vertices->at(j).z());
std::cout << "x:" << vertices->at(j).x() << " y:" << vertices->at(j).y() << " z:" << vertices->at(j).z() << std::endl;
}
}
}

protected:
int _indent;
};


int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\build1.OSGB");
BoundVisitor bv;

node1->accept(bv);
viewer1->setSceneData(node1);


viewer1->setUpViewInWindow(200, 200, 800, 600, 0);

return viewer1->run();
}


 

osg::NodeVisitor   osg3.4.0_2d