Added initial ESRIShape file loader.
Untabbed and formated LOGO loader. Removed extraneous noise from NET loader
This commit is contained in:
1212
src/osgPlugins/ESRIShape/ESRIShape.cpp
Normal file
1212
src/osgPlugins/ESRIShape/ESRIShape.cpp
Normal file
File diff suppressed because it is too large
Load Diff
400
src/osgPlugins/ESRIShape/ESRIShape.h
Normal file
400
src/osgPlugins/ESRIShape/ESRIShape.h
Normal file
@@ -0,0 +1,400 @@
|
||||
#ifndef OSG_SHAPE_H
|
||||
#define OSG_SHAPE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <osg/Referenced>
|
||||
|
||||
namespace ESRIShape {
|
||||
|
||||
typedef int Integer;
|
||||
typedef short Short;
|
||||
typedef unsigned char Byte;
|
||||
typedef double Double;
|
||||
typedef unsigned char * BytePtr;
|
||||
|
||||
enum ByteOrder {
|
||||
LittleEndian,
|
||||
BigEndian
|
||||
};
|
||||
|
||||
enum PartType{
|
||||
TriangleStrip = 0,
|
||||
TriangleFan = 1,
|
||||
OuterRing = 2,
|
||||
InnerRing = 3,
|
||||
FirstRing = 4,
|
||||
Ring = 5
|
||||
};
|
||||
|
||||
enum ShapeType {
|
||||
ShapeTypeNullShape = 0,
|
||||
ShapeTypePoint = 1,
|
||||
ShapeTypePolyLine = 3,
|
||||
ShapeTypePolygon = 5,
|
||||
ShapeTypeMultiPoint = 8,
|
||||
ShapeTypePointZ = 11,
|
||||
ShapeTypePolyLineZ = 13,
|
||||
ShapeTypePolygonZ = 15,
|
||||
ShapeTypeMultiPointZ = 18,
|
||||
ShapeTypePointM = 21,
|
||||
ShapeTypePolyLineM = 23,
|
||||
ShapeTypePolygonM = 25,
|
||||
ShapeTypeMultiPointM = 28,
|
||||
ShapeTypeMultiPatch = 31
|
||||
};
|
||||
|
||||
|
||||
struct BoundingBox
|
||||
{
|
||||
Double Xmin;
|
||||
Double Ymin;
|
||||
Double Xmax;
|
||||
Double Ymax;
|
||||
Double Zmin;
|
||||
Double Zmax;
|
||||
Double Mmin;
|
||||
Double Mmax;
|
||||
|
||||
bool read( int fd );
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
///////////////
|
||||
|
||||
struct ShapeHeader
|
||||
{
|
||||
Integer fileCode;
|
||||
Byte _unused_0[20];
|
||||
Integer fileLength;
|
||||
Integer version;
|
||||
Integer shapeType;
|
||||
BoundingBox bbox;
|
||||
|
||||
bool read(int fd);
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
struct RecordHeader
|
||||
{
|
||||
Integer recordNumber;
|
||||
Integer contentLength;
|
||||
|
||||
RecordHeader();
|
||||
|
||||
bool read( int fd );
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
|
||||
struct NullRecord
|
||||
{
|
||||
Integer shapeType;
|
||||
NullRecord();
|
||||
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Box
|
||||
{
|
||||
Double Xmin, Ymin, Xmax, Ymax;
|
||||
|
||||
Box();
|
||||
Box(const Box &b );
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
struct Range {
|
||||
Double min, max;
|
||||
Range();
|
||||
Range( const Range &r );
|
||||
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
struct ShapeObject : public osg::Referenced
|
||||
{
|
||||
ShapeType shapeType;
|
||||
ShapeObject(ShapeType s);
|
||||
virtual ~ShapeObject();
|
||||
};
|
||||
|
||||
|
||||
struct Point : public ShapeObject
|
||||
{
|
||||
Double x, y;
|
||||
|
||||
Point();
|
||||
Point(const Point &p);
|
||||
virtual ~Point();
|
||||
|
||||
bool read( int fd );
|
||||
void print();
|
||||
};
|
||||
|
||||
struct PointRecord
|
||||
{
|
||||
Point point;
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
struct MultiPoint: public ShapeObject
|
||||
{
|
||||
Box bbox;
|
||||
Integer numPoints;
|
||||
struct Point *points;
|
||||
|
||||
MultiPoint();
|
||||
|
||||
MultiPoint( const struct MultiPoint &mpoint );
|
||||
|
||||
virtual ~MultiPoint();
|
||||
|
||||
bool read( int fd );
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
struct PolyLine: public ShapeObject
|
||||
{
|
||||
Box bbox;
|
||||
Integer numParts;
|
||||
Integer numPoints;
|
||||
Integer *parts;
|
||||
struct Point *points;
|
||||
|
||||
PolyLine();
|
||||
|
||||
PolyLine( const PolyLine &p );
|
||||
|
||||
virtual ~PolyLine();
|
||||
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct Polygon : public ShapeObject
|
||||
{
|
||||
Box bbox;
|
||||
Integer numParts;
|
||||
Integer numPoints;
|
||||
Integer *parts;
|
||||
Point *points;
|
||||
|
||||
Polygon();
|
||||
|
||||
Polygon( const Polygon &p );
|
||||
|
||||
virtual ~Polygon();
|
||||
|
||||
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
struct PointM : public ShapeObject
|
||||
{
|
||||
Double x, y, m;
|
||||
|
||||
PointM();
|
||||
|
||||
PointM(const PointM &p);
|
||||
|
||||
virtual ~PointM();
|
||||
|
||||
bool read( int fd );
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
struct PointMRecord
|
||||
{
|
||||
PointM pointM;
|
||||
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
|
||||
struct MultiPointM: public ShapeObject
|
||||
{
|
||||
Box bbox;
|
||||
Integer numPoints;
|
||||
struct Point *points;
|
||||
struct Range mRange;
|
||||
Double *mArray;
|
||||
|
||||
MultiPointM();
|
||||
|
||||
MultiPointM( const struct MultiPointM &mpointm );
|
||||
|
||||
virtual ~MultiPointM();
|
||||
|
||||
bool read( int fd );
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
|
||||
struct PolyLineM: public ShapeObject
|
||||
{
|
||||
Box bbox;
|
||||
Integer numParts;
|
||||
Integer numPoints;
|
||||
Integer *parts;
|
||||
struct Point *points;
|
||||
struct Range mRange;
|
||||
Double *mArray;
|
||||
|
||||
PolyLineM();
|
||||
|
||||
PolyLineM(const PolyLineM &p);
|
||||
|
||||
virtual ~PolyLineM();
|
||||
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
|
||||
struct PolygonM : public ShapeObject
|
||||
{
|
||||
Box bbox;
|
||||
Integer numParts;
|
||||
Integer numPoints;
|
||||
Integer *parts;
|
||||
Point *points;
|
||||
struct Range mRange;
|
||||
Double *mArray;
|
||||
|
||||
PolygonM();
|
||||
|
||||
PolygonM(const PolygonM &p);
|
||||
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
struct PointZ : public ShapeObject
|
||||
{
|
||||
Double x, y, z, m;
|
||||
|
||||
PointZ();
|
||||
PointZ(const PointZ &p);
|
||||
virtual ~PointZ();
|
||||
|
||||
bool read( int fd );
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
struct PointZRecord
|
||||
{
|
||||
PointZ pointZ;
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
struct MultiPointZ: public ShapeObject
|
||||
{
|
||||
Box bbox;
|
||||
Integer numPoints;
|
||||
struct Point *points;
|
||||
struct Range zRange;
|
||||
Double *zArray;
|
||||
struct Range mRange;
|
||||
Double *mArray;
|
||||
|
||||
MultiPointZ();
|
||||
|
||||
MultiPointZ( const struct MultiPointZ &);
|
||||
|
||||
virtual ~MultiPointZ();
|
||||
|
||||
bool read( int fd );
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct PolyLineZ: public ShapeObject
|
||||
{
|
||||
Box bbox;
|
||||
Integer numParts;
|
||||
Integer numPoints;
|
||||
Integer *parts;
|
||||
struct Point *points;
|
||||
struct Range zRange;
|
||||
Double *zArray;
|
||||
struct Range mRange;
|
||||
Double *mArray;
|
||||
|
||||
PolyLineZ();
|
||||
|
||||
PolyLineZ( const PolyLineZ &p );
|
||||
|
||||
virtual ~PolyLineZ();
|
||||
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
|
||||
struct PolygonZ : public ShapeObject
|
||||
{
|
||||
Box bbox;
|
||||
Integer numParts;
|
||||
Integer numPoints;
|
||||
Integer *parts;
|
||||
Point *points;
|
||||
struct Range zRange;
|
||||
Double *zArray;
|
||||
struct Range mRange;
|
||||
Double *mArray;
|
||||
|
||||
PolygonZ();
|
||||
|
||||
PolygonZ( const PolygonZ &p );
|
||||
|
||||
virtual ~PolygonZ();
|
||||
|
||||
|
||||
bool read( int fd );
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
struct MultiPatch
|
||||
{
|
||||
Box bbox;
|
||||
Integer numParts;
|
||||
Integer numPoints;
|
||||
Integer *parts;
|
||||
Integer *partTypes;
|
||||
struct Point *points;
|
||||
Range zRange;
|
||||
Double *zArray;
|
||||
Range mRange;
|
||||
Double *mArray;
|
||||
|
||||
MultiPatch();
|
||||
MultiPatch( const MultiPatch &);
|
||||
virtual ~MultiPatch();
|
||||
bool read( int );
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
582
src/osgPlugins/ESRIShape/ESRIShapeParser.cpp
Normal file
582
src/osgPlugins/ESRIShape/ESRIShapeParser.cpp
Normal file
@@ -0,0 +1,582 @@
|
||||
#include <fcntl.h>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include "ESRIShapeParser.h"
|
||||
|
||||
using namespace ESRIShape;
|
||||
|
||||
ESRIShapeParser::ESRIShapeParser( const std::string fileName ):
|
||||
_valid(false)
|
||||
{
|
||||
int fd = 0;
|
||||
if( !fileName.empty() )
|
||||
{
|
||||
if( (fd = open( fileName.c_str(), O_RDONLY )) <= 0 )
|
||||
{
|
||||
perror( fileName.c_str() );
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
_valid = true;
|
||||
|
||||
ESRIShape::ShapeHeader head;
|
||||
head.read(fd);
|
||||
|
||||
//head.print();
|
||||
|
||||
_geode = new osg::Geode;
|
||||
|
||||
switch( head.shapeType )
|
||||
{
|
||||
case ESRIShape::ShapeTypeNullShape :
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypePoint :
|
||||
{
|
||||
std::vector<ESRIShape::Point> pts;
|
||||
ESRIShape::PointRecord pointRecord;
|
||||
while( pointRecord.read(fd) )
|
||||
pts.push_back( pointRecord.point );
|
||||
_process( pts );
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypeMultiPoint :
|
||||
{
|
||||
std::vector<ESRIShape::MultiPoint> mpts;
|
||||
ESRIShape::MultiPoint mpoint;
|
||||
|
||||
while( mpoint.read(fd) )
|
||||
mpts.push_back( mpoint );
|
||||
|
||||
_process( mpts );
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypePolyLine :
|
||||
{
|
||||
std::vector<ESRIShape::PolyLine> plines;
|
||||
ESRIShape::PolyLine pline;
|
||||
|
||||
while( pline.read(fd) )
|
||||
plines.push_back( pline );
|
||||
|
||||
_process( plines );
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypePolygon :
|
||||
{
|
||||
std::vector<ESRIShape::Polygon> polys;
|
||||
ESRIShape::Polygon poly;
|
||||
|
||||
while( poly.read(fd) )
|
||||
polys.push_back( poly );
|
||||
|
||||
_process( polys );
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypePointM :
|
||||
{
|
||||
std::vector<ESRIShape::PointM> ptms;
|
||||
ESRIShape::PointMRecord pointMRecord;
|
||||
while( pointMRecord.read(fd) )
|
||||
ptms.push_back( pointMRecord.pointM );
|
||||
_process( ptms );
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypeMultiPointM :
|
||||
{
|
||||
std::vector<ESRIShape::MultiPointM> mptms;
|
||||
ESRIShape::MultiPointM mpointm;
|
||||
|
||||
while( mpointm.read(fd) )
|
||||
mptms.push_back( mpointm );
|
||||
|
||||
_process( mptms );
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypePolyLineM :
|
||||
{
|
||||
std::vector<ESRIShape::PolyLineM> plinems;
|
||||
ESRIShape::PolyLineM plinem;
|
||||
|
||||
while( plinem.read(fd) )
|
||||
plinems.push_back( plinem );
|
||||
|
||||
_process( plinems );
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypePolygonM :
|
||||
{
|
||||
std::vector<ESRIShape::PolygonM> polyms;
|
||||
ESRIShape::PolygonM polym;
|
||||
|
||||
while( polym.read(fd) )
|
||||
polyms.push_back( polym );
|
||||
|
||||
_process( polyms );
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case ESRIShape::ShapeTypePointZ :
|
||||
{
|
||||
std::vector<ESRIShape::PointZ> ptzs;
|
||||
ESRIShape::PointZRecord pointZRecord;
|
||||
while( pointZRecord.read(fd) )
|
||||
ptzs.push_back( pointZRecord.pointZ );
|
||||
_process( ptzs );
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypeMultiPointZ :
|
||||
{
|
||||
std::vector<ESRIShape::MultiPointZ> mptzs;
|
||||
ESRIShape::MultiPointZ mpointz;
|
||||
|
||||
while( mpointz.read(fd) )
|
||||
mptzs.push_back( mpointz );
|
||||
|
||||
_process( mptzs );
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypePolyLineZ :
|
||||
{
|
||||
std::vector<ESRIShape::PolyLineZ> plinezs;
|
||||
ESRIShape::PolyLineZ plinez;
|
||||
|
||||
while( plinez.read(fd) )
|
||||
plinezs.push_back( plinez );
|
||||
|
||||
_process( plinezs );
|
||||
}
|
||||
break;
|
||||
|
||||
case ESRIShape::ShapeTypePolygonZ :
|
||||
{
|
||||
std::vector<ESRIShape::PolygonZ> polyzs;
|
||||
ESRIShape::PolygonZ polyz;
|
||||
|
||||
while( polyz.read(fd) )
|
||||
polyzs.push_back( polyz );
|
||||
|
||||
_process( polyzs );
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case ESRIShape::ShapeTypeMultiPatch :
|
||||
{
|
||||
std::vector<ESRIShape::MultiPatch> mpatches;
|
||||
ESRIShape::MultiPatch mpatch;
|
||||
|
||||
while( mpatch.read( fd ) )
|
||||
mpatches.push_back( mpatch );
|
||||
|
||||
_process(mpatches);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
osg::Geode *ESRIShapeParser::getGeode()
|
||||
{
|
||||
return _geode.get();
|
||||
}
|
||||
|
||||
void ESRIShapeParser::_combinePointToMultipoint()
|
||||
{
|
||||
if( !_valid ) return;
|
||||
|
||||
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array;
|
||||
unsigned int numDrawables = _geode->getNumDrawables();
|
||||
|
||||
for( unsigned int i = 0; i < numDrawables; i++ )
|
||||
{
|
||||
osg::Geometry *geom = dynamic_cast<osg::Geometry *>(_geode->getDrawable(i));
|
||||
if( geom != 0L )
|
||||
{
|
||||
osg::Vec3Array *va = dynamic_cast<osg::Vec3Array *>(geom->getVertexArray());
|
||||
if( va != 0L )
|
||||
coords->push_back( va->front() );
|
||||
}
|
||||
}
|
||||
|
||||
_geode->removeDrawable( 0, numDrawables );
|
||||
|
||||
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::Point> &pts )
|
||||
{
|
||||
if( !_valid ) return;
|
||||
|
||||
std::vector<ESRIShape::Point>::const_iterator p;
|
||||
for( p = pts.begin(); p != pts.end(); p++ )
|
||||
{
|
||||
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array;
|
||||
coords->push_back( osg::Vec3( 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::MultiPoint> &mpts )
|
||||
{
|
||||
if( !_valid ) return;
|
||||
|
||||
std::vector<ESRIShape::MultiPoint>::const_iterator p;
|
||||
for( p = mpts.begin(); p != mpts.end(); p++ )
|
||||
{
|
||||
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array;
|
||||
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::PolyLine> &lines )
|
||||
{
|
||||
if( !_valid ) return;
|
||||
|
||||
std::vector<ESRIShape::PolyLine>::const_iterator p;
|
||||
for( p = lines.begin(); p != lines.end(); p++ )
|
||||
{
|
||||
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array;
|
||||
|
||||
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());
|
||||
|
||||
for( int 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::Polygon> &polys )
|
||||
{
|
||||
if( !_valid ) return;
|
||||
|
||||
std::vector<ESRIShape::Polygon>::const_iterator p;
|
||||
for( p = polys.begin(); p != polys.end(); p++ )
|
||||
{
|
||||
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array;
|
||||
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());
|
||||
|
||||
for( int 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::PointM> &ptms )
|
||||
{
|
||||
if( !_valid ) return;
|
||||
|
||||
std::vector<ESRIShape::PointM>::const_iterator p;
|
||||
for( p = ptms.begin(); p != ptms.end(); p++ )
|
||||
{
|
||||
osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array;
|
||||
coords->push_back( osg::Vec3( 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;
|
||||
|
||||
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());
|
||||
|
||||
for( int 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;
|
||||
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());
|
||||
|
||||
for( int 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;
|
||||
|
||||
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());
|
||||
|
||||
for( int 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;
|
||||
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());
|
||||
|
||||
for( int 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;
|
||||
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());
|
||||
|
||||
// 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( int 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 i = 0; i < len; i++ )
|
||||
colors->push_back( color );
|
||||
|
||||
geometry->addPrimitiveSet( new osg::DrawArrays(mode, index, len ));
|
||||
}
|
||||
|
||||
_geode->addDrawable( geometry.get() );
|
||||
}
|
||||
}
|
||||
43
src/osgPlugins/ESRIShape/ESRIShapeParser.h
Normal file
43
src/osgPlugins/ESRIShape/ESRIShapeParser.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef ESRI_SHAPE_PARSER_H
|
||||
#define ESRI_SHAPE_PARSER_H
|
||||
|
||||
#include <string>
|
||||
#include <osg/Geode>
|
||||
|
||||
#include "ESRIShape.h"
|
||||
|
||||
namespace ESRIShape {
|
||||
|
||||
class ESRIShapeParser
|
||||
{
|
||||
public:
|
||||
ESRIShapeParser( const std::string fileName="" );
|
||||
|
||||
osg::Geode *getGeode();
|
||||
|
||||
private:
|
||||
bool _valid;
|
||||
osg::ref_ptr<osg::Geode> _geode;
|
||||
|
||||
void _combinePointToMultipoint();
|
||||
void _process( const std::vector<ESRIShape::Point> &);
|
||||
void _process( const std::vector<ESRIShape::MultiPoint> &);
|
||||
void _process( const std::vector<ESRIShape::PolyLine> &);
|
||||
void _process( const std::vector<ESRIShape::Polygon> &);
|
||||
|
||||
void _process( const std::vector<ESRIShape::PointM> &);
|
||||
void _process( const std::vector<ESRIShape::MultiPointM> &);
|
||||
void _process( const std::vector<ESRIShape::PolyLineM> &);
|
||||
void _process( const std::vector<ESRIShape::PolygonM> &);
|
||||
|
||||
void _process( const std::vector<ESRIShape::PointZ> &);
|
||||
void _process( const std::vector<ESRIShape::MultiPointZ> &);
|
||||
void _process( const std::vector<ESRIShape::PolyLineZ> &);
|
||||
void _process( const std::vector<ESRIShape::PolygonZ> &);
|
||||
void _process( const std::vector<ESRIShape::MultiPatch> &);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
36
src/osgPlugins/ESRIShape/ESRIShapeReaderWriter.cpp
Normal file
36
src/osgPlugins/ESRIShape/ESRIShapeReaderWriter.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
#include "ESRIShape.h"
|
||||
#include "ESRIShapeParser.h"
|
||||
|
||||
class ESRIShapeReaderWriter : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
ESRIShapeReaderWriter() {}
|
||||
|
||||
virtual const char* className() { return "ESRI Shape ReaderWriter"; }
|
||||
|
||||
virtual bool acceptsExtension(const std::string& extension) const
|
||||
{
|
||||
return osgDB::equalCaseInsensitive(extension,"shp");
|
||||
}
|
||||
|
||||
virtual ReadResult readObject(const std::string& fileName, const Options* opt) const
|
||||
{ return readNode(fileName,opt); }
|
||||
|
||||
virtual ReadResult readNode(const std::string& fileName, const Options* ) const
|
||||
{
|
||||
std::string ext = osgDB::getFileExtension(fileName);
|
||||
if (!acceptsExtension(ext))
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
ESRIShape::ESRIShapeParser sp(fileName);
|
||||
return sp.getGeode();
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
osgDB::RegisterReaderWriterProxy<ESRIShapeReaderWriter> g_esriShapeReaderWriter_Proxy;
|
||||
|
||||
15
src/osgPlugins/ESRIShape/GNUmakefile
Normal file
15
src/osgPlugins/ESRIShape/GNUmakefile
Normal file
@@ -0,0 +1,15 @@
|
||||
TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
ESRIShape.cpp\
|
||||
ESRIShapeParser.cpp\
|
||||
ESRIShapeReaderWriter.cpp\
|
||||
|
||||
LIBS += $(OSG_LIBS) $(OTHER_LIBS) $(SOCKET_LIBS)
|
||||
|
||||
TARGET_BASENAME = shp
|
||||
include $(TOPDIR)/Make/cygwin_plugin_def
|
||||
PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
@@ -23,56 +23,56 @@ class Logos: public osg::Drawable
|
||||
{
|
||||
public:
|
||||
enum RelativePosition{
|
||||
Center,
|
||||
UpperLeft,
|
||||
UpperRight,
|
||||
LowerLeft,
|
||||
LowerRight,
|
||||
UpperCenter,
|
||||
LowerCenter,
|
||||
last_position
|
||||
Center,
|
||||
UpperLeft,
|
||||
UpperRight,
|
||||
LowerLeft,
|
||||
LowerRight,
|
||||
UpperCenter,
|
||||
LowerCenter,
|
||||
last_position
|
||||
};
|
||||
|
||||
struct logosCullCallback : public osg::Drawable::CullCallback
|
||||
{
|
||||
struct logosCullCallback : public osg::Drawable::CullCallback
|
||||
{
|
||||
virtual bool cull(osg::NodeVisitor *visitor, osg::Drawable* drawable, osg::State*) const
|
||||
{
|
||||
Logos *logos = dynamic_cast <Logos *>(drawable);
|
||||
osgUtil::CullVisitor *cv = dynamic_cast<osgUtil::CullVisitor *>(visitor);
|
||||
if( logos != NULL && cv != NULL )
|
||||
{
|
||||
osg::Viewport *vp = cv->getViewport();
|
||||
if( vp != NULL )
|
||||
{
|
||||
int x, y, aw, ah, bw, bh;
|
||||
logos->getViewport()->getViewport( x, y, aw, ah );
|
||||
vp->getViewport(x, y, bw, bh );
|
||||
if( aw != bw || ah != bh )
|
||||
{
|
||||
logos->getViewport()->setViewport( x, y, bw, bh );
|
||||
logos->dirtyDisplayList();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
{
|
||||
Logos *logos = dynamic_cast <Logos *>(drawable);
|
||||
osgUtil::CullVisitor *cv = dynamic_cast<osgUtil::CullVisitor *>(visitor);
|
||||
if( logos != NULL && cv != NULL )
|
||||
{
|
||||
osg::Viewport *vp = cv->getViewport();
|
||||
if( vp != NULL )
|
||||
{
|
||||
int x, y, aw, ah, bw, bh;
|
||||
logos->getViewport()->getViewport( x, y, aw, ah );
|
||||
vp->getViewport(x, y, bw, bh );
|
||||
if( aw != bw || ah != bh )
|
||||
{
|
||||
logos->getViewport()->setViewport( x, y, bw, bh );
|
||||
logos->dirtyDisplayList();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Logos()
|
||||
{
|
||||
osg::StateSet *sset = new osg::StateSet;
|
||||
osg::BlendFunc *transp = new osg::BlendFunc;
|
||||
transp->setFunction(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
sset->setAttribute( transp );
|
||||
sset->setMode( GL_BLEND, osg::StateAttribute::ON );
|
||||
sset->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
|
||||
sset->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::OFF );
|
||||
sset->setRenderBinDetails( StateSet::TRANSPARENT_BIN + 1 , "RenderBin" );
|
||||
setStateSet( sset );
|
||||
viewport = new osg::Viewport;
|
||||
setCullCallback( new logosCullCallback );
|
||||
_contextID = 0;
|
||||
}
|
||||
Logos()
|
||||
{
|
||||
osg::StateSet *sset = new osg::StateSet;
|
||||
osg::BlendFunc *transp = new osg::BlendFunc;
|
||||
transp->setFunction(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
sset->setAttribute( transp );
|
||||
sset->setMode( GL_BLEND, osg::StateAttribute::ON );
|
||||
sset->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
|
||||
sset->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::OFF );
|
||||
sset->setRenderBinDetails( StateSet::TRANSPARENT_BIN + 1 , "RenderBin" );
|
||||
setStateSet( sset );
|
||||
viewport = new osg::Viewport;
|
||||
setCullCallback( new logosCullCallback );
|
||||
_contextID = 0;
|
||||
}
|
||||
|
||||
Logos(const Logos& logo, const CopyOp& copyop=CopyOp::SHALLOW_COPY) :Drawable( logo, copyop ) {}
|
||||
|
||||
@@ -82,92 +82,93 @@ class Logos: public osg::Drawable
|
||||
virtual const char* className() const { return "Logos"; }
|
||||
|
||||
virtual void drawImplementation(osg::State &state ) const
|
||||
{
|
||||
if( state.getContextID() != _contextID ) return;
|
||||
{
|
||||
if( state.getContextID() != _contextID )
|
||||
return;
|
||||
|
||||
int x = 0, y = 0, w = 1, h = 1;
|
||||
if( viewport != NULL )
|
||||
viewport->getViewport( x, y, w, h );
|
||||
float vx = x;
|
||||
float vy = y;
|
||||
float vw = w;
|
||||
float vh = h;
|
||||
int x = 0, y = 0, w = 1, h = 1;
|
||||
if( viewport != NULL )
|
||||
viewport->getViewport( x, y, w, h );
|
||||
float vx = x;
|
||||
float vy = y;
|
||||
float vw = w;
|
||||
float vh = h;
|
||||
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho( 0.0, vw, 0.0, vh, -1.0, 1.0 );
|
||||
glOrtho( 0.0, vw, 0.0, vh, -1.0, 1.0 );
|
||||
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glColor4f( 1, 1, 1, 1 );
|
||||
glColor4f( 1, 1, 1, 1 );
|
||||
|
||||
std::vector <osg::Image *>::const_iterator p;
|
||||
float th = 0.0;
|
||||
for( p = logos[Center].begin(); p != logos[Center].end(); p++ )
|
||||
th += (*p)->t();
|
||||
std::vector <osg::Image *>::const_iterator p;
|
||||
float th = 0.0;
|
||||
for( p = logos[Center].begin(); p != logos[Center].end(); p++ )
|
||||
th += (*p)->t();
|
||||
|
||||
float place[][4] = {
|
||||
{ vw*0.5, ((vh*0.5) + th*0.5), -0.5, -1.0 },
|
||||
{ vx, vh, 0.0, -1.0 },
|
||||
{ vw, vh, -1.0, -1.0 },
|
||||
{ vx, vy, 0.0, 1.0 },
|
||||
{ vw, vy, -1.0, 1.0 },
|
||||
{ vw*0.5, vh , -0.5, -1.0 },
|
||||
{ vw*0.5, 0.0 , -0.5, 1.0 },
|
||||
};
|
||||
float place[][4] = {
|
||||
{ vw*0.5, ((vh*0.5) + th*0.5), -0.5, -1.0 },
|
||||
{ vx, vh, 0.0, -1.0 },
|
||||
{ vw, vh, -1.0, -1.0 },
|
||||
{ vx, vy, 0.0, 1.0 },
|
||||
{ vw, vy, -1.0, 1.0 },
|
||||
{ vw*0.5, vh , -0.5, -1.0 },
|
||||
{ vw*0.5, 0.0 , -0.5, 1.0 },
|
||||
};
|
||||
|
||||
for( int i = Center; i < last_position; i++ )
|
||||
{
|
||||
if( logos[i].size() != 0 )
|
||||
{
|
||||
float x = place[i][0];
|
||||
float y = place[i][1];
|
||||
float xi = place[i][2];
|
||||
float yi = place[i][3];
|
||||
for( p = logos[i].begin(); p != logos[i].end(); p++ )
|
||||
{
|
||||
osg::Image *img = *p;
|
||||
x = place[i][0] + xi * img->s();
|
||||
if( i == Center || i == UpperLeft || i == UpperRight || i == UpperCenter)
|
||||
y += yi * img->t();
|
||||
glRasterPos2f( x, y );
|
||||
glDrawPixels( img->s(), img->t(), img->getPixelFormat(), img->getDataType(), img->data() );
|
||||
if( i == LowerLeft || i == LowerRight || i == LowerCenter)
|
||||
y += yi * img->t();
|
||||
}
|
||||
}
|
||||
}
|
||||
for( int i = Center; i < last_position; i++ )
|
||||
{
|
||||
if( logos[i].size() != 0 )
|
||||
{
|
||||
float x = place[i][0];
|
||||
float y = place[i][1];
|
||||
float xi = place[i][2];
|
||||
float yi = place[i][3];
|
||||
for( p = logos[i].begin(); p != logos[i].end(); p++ )
|
||||
{
|
||||
osg::Image *img = *p;
|
||||
x = place[i][0] + xi * img->s();
|
||||
if( i == Center || i == UpperLeft || i == UpperRight || i == UpperCenter)
|
||||
y += yi * img->t();
|
||||
glRasterPos2f( x, y );
|
||||
glDrawPixels( img->s(), img->t(), img->getPixelFormat(), img->getDataType(), img->data() );
|
||||
if( i == LowerLeft || i == LowerRight || i == LowerCenter)
|
||||
y += yi * img->t();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glPopMatrix();
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
}
|
||||
glPopMatrix();
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glPopMatrix();
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
}
|
||||
|
||||
void addLogo( RelativePosition pos, std::string name )
|
||||
{
|
||||
osg::Image *image = osgDB::readImageFile( name.c_str() );
|
||||
if( image != NULL )
|
||||
logos[pos].push_back( image );
|
||||
}
|
||||
void addLogo( RelativePosition pos, std::string name )
|
||||
{
|
||||
osg::Image *image = osgDB::readImageFile( name.c_str() );
|
||||
if( image != NULL )
|
||||
logos[pos].push_back( image );
|
||||
}
|
||||
|
||||
osg::Viewport *getViewport() { return viewport; }
|
||||
void setContextID( unsigned int id ) { _contextID = id; }
|
||||
osg::Viewport *getViewport() { return viewport; }
|
||||
void setContextID( unsigned int id ) { _contextID = id; }
|
||||
|
||||
bool hasLogos()
|
||||
{
|
||||
int n = 0;
|
||||
for( int i = Center; i <= last_position; i++ )
|
||||
n += logos[i].size();
|
||||
return (n != 0);
|
||||
}
|
||||
bool hasLogos()
|
||||
{
|
||||
int n = 0;
|
||||
for( int i = Center; i <= last_position; i++ )
|
||||
n += logos[i].size();
|
||||
return (n != 0);
|
||||
}
|
||||
|
||||
virtual osg::BoundingBox computeBound() const
|
||||
{
|
||||
return osg::BoundingBox( -1, -1, -1, 1, 1, 1);
|
||||
{
|
||||
return osg::BoundingBox( -1, -1, -1, 1, 1, 1);
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -175,15 +176,15 @@ class Logos: public osg::Drawable
|
||||
|
||||
virtual ~Logos() {}
|
||||
private :
|
||||
std::vector <osg::Image *> logos[last_position];
|
||||
osg::Viewport *viewport;
|
||||
unsigned int _contextID;
|
||||
std::vector <osg::Image *> logos[last_position];
|
||||
osg::Viewport *viewport;
|
||||
unsigned int _contextID;
|
||||
};
|
||||
|
||||
|
||||
class LOGOReaderWriter : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
public:
|
||||
virtual const char* className() const { return "Logo Database Reader/Writer"; }
|
||||
|
||||
virtual bool acceptsExtension(const std::string& extension) const
|
||||
@@ -197,80 +198,81 @@ public:
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
std::string fileName = osgDB::findDataFile( file, options );
|
||||
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
|
||||
if (fileName.empty())
|
||||
return ReadResult::FILE_NOT_FOUND;
|
||||
|
||||
osg::notify(osg::INFO)<< "ReaderWriterLOGO::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
osg::Geode *geode = new osg::Geode;
|
||||
osg::Geode *geode = new osg::Geode;
|
||||
|
||||
unsigned int screen = 0;
|
||||
unsigned int screen = 0;
|
||||
|
||||
Logos* ld = new Logos;
|
||||
ld->setContextID( screen );
|
||||
Logos* ld = new Logos;
|
||||
ld->setContextID( screen );
|
||||
|
||||
Logos::RelativePosition pos = Logos::LowerRight;
|
||||
Logos::RelativePosition pos = Logos::LowerRight;
|
||||
|
||||
FILE *fp;
|
||||
if( (fp = fopen( fileName.c_str(), "r")) == NULL )
|
||||
return NULL;
|
||||
while( !feof(fp))
|
||||
{
|
||||
char buff[128];
|
||||
FILE *fp;
|
||||
if( (fp = fopen( fileName.c_str(), "r")) == NULL )
|
||||
return NULL;
|
||||
while( !feof(fp))
|
||||
{
|
||||
char buff[128];
|
||||
|
||||
if( fscanf( fp, "%s", buff ) != 1 )
|
||||
break;
|
||||
if( fscanf( fp, "%s", buff ) != 1 )
|
||||
break;
|
||||
|
||||
std::string str(buff);
|
||||
std::string str(buff);
|
||||
|
||||
if( str == "Center" )
|
||||
pos = Logos::Center;
|
||||
else if( str == "UpperLeft" )
|
||||
pos = Logos::UpperLeft;
|
||||
else if( str == "UpperRight" )
|
||||
pos = Logos::UpperRight;
|
||||
else if( str == "LowerLeft" )
|
||||
pos = Logos::LowerLeft;
|
||||
else if( str == "LowerRight" )
|
||||
pos = Logos::LowerRight;
|
||||
else if( str == "UpperCenter" )
|
||||
pos = Logos::UpperCenter;
|
||||
else if( str == "LowerCenter" )
|
||||
pos = Logos::LowerCenter;
|
||||
else if( str == "Camera" )
|
||||
{
|
||||
unsigned int n;
|
||||
if( (fscanf( fp, "%d", &n )) != 1 )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Error... Camera requires an integer argument\n";
|
||||
break;
|
||||
}
|
||||
if( screen != n )
|
||||
{
|
||||
screen = n;
|
||||
if( ld->hasLogos() )
|
||||
{
|
||||
geode->addDrawable( ld );
|
||||
ld = new Logos;
|
||||
ld->setContextID( screen );
|
||||
}
|
||||
else
|
||||
ld->setContextID( screen );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( str.length() )
|
||||
ld->addLogo( pos, str );
|
||||
}
|
||||
}
|
||||
fclose( fp );
|
||||
|
||||
if( ld->hasLogos() )
|
||||
geode->addDrawable( ld );
|
||||
|
||||
geode->setCullingActive(false);
|
||||
return geode;
|
||||
}
|
||||
if( str == "Center" )
|
||||
pos = Logos::Center;
|
||||
else if( str == "UpperLeft" )
|
||||
pos = Logos::UpperLeft;
|
||||
else if( str == "UpperRight" )
|
||||
pos = Logos::UpperRight;
|
||||
else if( str == "LowerLeft" )
|
||||
pos = Logos::LowerLeft;
|
||||
else if( str == "LowerRight" )
|
||||
pos = Logos::LowerRight;
|
||||
else if( str == "UpperCenter" )
|
||||
pos = Logos::UpperCenter;
|
||||
else if( str == "LowerCenter" )
|
||||
pos = Logos::LowerCenter;
|
||||
else if( str == "Camera" )
|
||||
{
|
||||
unsigned int n;
|
||||
if( (fscanf( fp, "%d", &n )) != 1 )
|
||||
{
|
||||
osg::notify(osg::WARN) << "Error... Camera requires an integer argument\n";
|
||||
break;
|
||||
}
|
||||
if( screen != n )
|
||||
{
|
||||
screen = n;
|
||||
if( ld->hasLogos() )
|
||||
{
|
||||
geode->addDrawable( ld );
|
||||
ld = new Logos;
|
||||
ld->setContextID( screen );
|
||||
}
|
||||
else
|
||||
ld->setContextID( screen );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( str.length() )
|
||||
ld->addLogo( pos, str );
|
||||
}
|
||||
}
|
||||
fclose( fp );
|
||||
|
||||
if( ld->hasLogos() )
|
||||
geode->addDrawable( ld );
|
||||
|
||||
geode->setCullingActive(false);
|
||||
return geode;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ class NetReader : public osgDB::ReaderWriter
|
||||
{
|
||||
osg::Timer_t start = osg::Timer::instance()->tick();
|
||||
|
||||
osg::notify(osg::NOTICE) << "osgPlugin .net: start load" << inFileName << std::endl;
|
||||
//osg::notify(osg::NOTICE) << "osgPlugin .net: start load" << inFileName << std::endl;
|
||||
|
||||
std::string hostname;
|
||||
std::string serverPrefix;
|
||||
@@ -234,8 +234,8 @@ class NetReader : public osgDB::ReaderWriter
|
||||
if( !serverPrefix.empty() )
|
||||
fileName = serverPrefix + '/' + fileName;
|
||||
|
||||
osg::notify(osg::WARN) << "hostname " << hostname << std::endl;
|
||||
osg::notify(osg::WARN) << "filename " << fileName << std::endl;
|
||||
//osg::notify(osg::WARN) << "hostname " << hostname << std::endl;
|
||||
//osg::notify(osg::WARN) << "filename " << fileName << std::endl;
|
||||
|
||||
|
||||
// Invoke the reader corresponding to the extension
|
||||
|
||||
Reference in New Issue
Block a user