From 84d8eeb7cb686acec741750c96f34df8b46b272b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Dec 2012 09:55:48 +0000 Subject: [PATCH] First cut of generating lines from .trk data --- src/osgPlugins/trk/ReaderWriterTRK.cpp | 109 +++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 8 deletions(-) diff --git a/src/osgPlugins/trk/ReaderWriterTRK.cpp b/src/osgPlugins/trk/ReaderWriterTRK.cpp index ae034f13f..dad4a58e5 100644 --- a/src/osgPlugins/trk/ReaderWriterTRK.cpp +++ b/src/osgPlugins/trk/ReaderWriterTRK.cpp @@ -1,9 +1,9 @@ // Released under the OSGPL license, as part of the OpenSceneGraph distribution. // // specification : http://www.trackvis.org/docs/?subsect=fileformat +// #include - -#include +#include #include #include @@ -69,20 +69,113 @@ class ReaderWriterTRK : public osgDB::ReaderWriter if (fin.fail()) return ReadResult::ERROR_IN_READING_FILE; OSG_NOTICE<<"Read header successfuly ["< geode = new osg::Geode; + + osg::ref_ptr geometry = new osg::Geometry; + geode->addDrawable(geometry.get()); - return ReadResult::FILE_NOT_HANDLED; + osg::ref_ptr vertices = new osg::Vec3Array; + geometry->setVertexArray(vertices.get()); + + osg::ref_ptr lines = new osg::DrawElementsUInt(GL_LINES); + geometry->addPrimitiveSet(lines.get()); + + for(int i=0; i(&n_points),4); + if (fin.fail()) break; + + // OSG_NOTICE<<" n_points="<(point_data), n_point_floats*4); + if (fin.fail()) break; + + if (n_p!=0) + { + float* property_data = new float[n_p]; + fin.read(reinterpret_cast(&property_data), n_p*4); + if (fin.fail()) break; + + delete [] property_data; + + } + + if (n_points>0) + { + // record the index of the first vertex of the new track + int vi = vertices->size(); + + // add the vertices of the track + for(int pi=0; pipush_back(osg::Vec3(vptr[0],vptr[1],vptr[2])); + } + + // add the line segmenets for track + for(int pi=0; pipush_back(vi); + lines->push_back(vi+1); + } + } + + delete [] point_data; + } + + if (fin.fail()) + { + OSG_NOTICE<<"Error on reading track file."<