Skip to content

Commit

Permalink
From Martin Beckett, "I have added support for DXF POINTS to the dxf …
Browse files Browse the repository at this point in the history
…reader plugin

It's really just a cut-paste job from the existing LINE support.

The current dxf plugin architecture isn't very efficient, especially if you
are loading large point clouds (LIDAR)
eg. it makes multiple lookups of the layer name for each vertex.
I don't know if I can improve this for the general case or if I have to add a
special large point cloud dxf reader."
  • Loading branch information
robertosfield committed Feb 20, 2009
1 parent 23c6ad8 commit a01a9d7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/osgPlugins/dxf/dxfEntity.cpp
Expand Up @@ -24,6 +24,7 @@ std::map<std::string, ref_ptr<dxfBasicEntity> > dxfEntity::_registry;
RegisterEntityProxy<dxf3DFace> g_dxf3DFace;
RegisterEntityProxy<dxfCircle> g_dxfCircle;
RegisterEntityProxy<dxfArc> g_dxfArc;
RegisterEntityProxy<dxfPoint> g_dxfPoint;
RegisterEntityProxy<dxfLine> g_dxfLine;
RegisterEntityProxy<dxfVertex> g_dxfVertex;
RegisterEntityProxy<dxfPolyline> g_dxfPolyline;
Expand Down Expand Up @@ -326,6 +327,34 @@ dxfLine::drawScene(scene* sc)
// std::cout << ++lcount << " ";
// sc->ocs_clear();
}
void
dxfPoint::assign(dxfFile* dxf, codeValue& cv)
{
double d = cv._double;
//unsigned short s = cv._short;
switch (cv._groupCode) {
case 10:
_a.x() = d;
break;
case 20:
_a.y() = d;
break;
case 30:
_a.z() = d;
break;
default:
dxfBasicEntity::assign(dxf, cv);
break;
}
}

void
dxfPoint::drawScene(scene* sc)
{
Matrixd m;
getOCSMatrix(_ocs, m);
sc->addPoint(getLayer(), _color,_a);
}

void
dxfPolyline::assign(dxfFile* dxf, codeValue& cv)
Expand Down
16 changes: 16 additions & 0 deletions src/osgPlugins/dxf/dxfEntity.h
Expand Up @@ -104,6 +104,22 @@ class dxfArc : public dxfBasicEntity
double _endAngle;
osg::Vec3d _ocs;
};

class dxfPoint : public dxfBasicEntity
{
public:
dxfPoint() : _ocs(0,0,1) {}
virtual ~dxfPoint() {}
virtual dxfBasicEntity* create() { return new dxfPoint; }
virtual const char* name() { return "POINT"; }
virtual void assign(dxfFile* dxf, codeValue& cv);
virtual void drawScene(scene* sc);
protected:
osg::Vec3d _a;
//osg::Vec3d _b;
osg::Vec3d _ocs;
};

class dxfLine : public dxfBasicEntity
{
public:
Expand Down
9 changes: 9 additions & 0 deletions src/osgPlugins/dxf/scene.cpp
Expand Up @@ -50,6 +50,15 @@ Vec3d scene::addNormal(Vec3d v)
// to do: vertices are not always listed in order. find why.
return v;
}
void
scene::addPoint(const std::string & l, unsigned short color, Vec3d & s)
{
dxfLayer* layer = _layerTable->findOrCreateLayer(l);
if (layer->getFrozen()) return;
sceneLayer* ly = findOrCreateSceneLayer(l);
Vec3d a(addVertex(s));
ly->_points[correctedColorIndex(l, color)].push_back(a);
}

void
scene::addLine(const std::string & l, unsigned short color, Vec3d & s, Vec3d & e)
Expand Down
37 changes: 36 additions & 1 deletion src/osgPlugins/dxf/scene.h
Expand Up @@ -57,6 +57,23 @@ class bounds {
};


static inline
osg::Geometry* createPtGeometry( osg::PrimitiveSet::Mode pointType, osg::Vec3Array* vertices, const osg::Vec4 & color)
{
osg::Geometry* geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->addPrimitiveSet(new osg::DrawArrays(pointType, 0, vertices->size()));
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(color);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
osg::Vec3Array *norms = new osg::Vec3Array;
norms->push_back(osg::Vec3(0,0,1));
geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
return geom;
}

static inline
osg::Geometry* createLnGeometry( osg::PrimitiveSet::Mode lineType, osg::Vec3Array* vertices, const osg::Vec4 & color)
{
Expand All @@ -74,7 +91,6 @@ osg::Geometry* createLnGeometry( osg::PrimitiveSet::Mode lineType, osg::Vec3Arra
return geom;
}


static inline
osg::Geometry* createTriGeometry( osg::Vec3Array* vertices, osg::Vec3Array* normals, const osg::Vec4 & color)
{
Expand Down Expand Up @@ -143,12 +159,14 @@ class sceneLayer : public osg::Referenced {
virtual ~sceneLayer() {}
void layer2osg(osg::Group* root, bounds &b)
{
osgPoints(root, b);
osgLines(root, b);
osgTriangles(root, b);
osgQuads(root, b);
osgText(root, b);
}
MapVListList _linestrips;
MapVList _points;
MapVList _lines;
MapVList _triangles;
MapVList _trinorms;
Expand All @@ -171,6 +189,22 @@ class sceneLayer : public osg::Referenced {
std::string _name;

osg::Vec4 getColor(unsigned short color);

void osgPoints(osg::Group* root, bounds &b)
{

for (MapVList::iterator mitr = _points.begin();
mitr != _points.end(); ++mitr) {
osg::Vec3Array *coords = new osg::Vec3Array;
for (VList::iterator itr = mitr->second.begin();
itr != mitr->second.end(); ++itr) {
osg::Vec3 v(itr->x() - b._min.x(), itr->y() - b._min.y(), itr->z() - b._min.z());
coords->push_back(v);
}
root->addChild(createModel(_name, createPtGeometry(osg::PrimitiveSet::POINTS, coords, getColor(mitr->first))));
}
}

void osgLines(osg::Group* root, bounds &b)
{
for(MapVListList::iterator mlitr = _linestrips.begin();
Expand Down Expand Up @@ -314,6 +348,7 @@ class scene : public osg::Referenced {
}
unsigned short correctedColorIndex(const std::string & l, unsigned short color);

void addPoint(const std::string & l, unsigned short color, osg::Vec3d & s);
void addLine(const std::string & l, unsigned short color, osg::Vec3d & s, osg::Vec3d & e);
void addLineStrip(const std::string & l, unsigned short color, std::vector<osg::Vec3d> & vertices);
void addLineLoop(const std::string & l, unsigned short color, std::vector<osg::Vec3d> & vertices);
Expand Down

0 comments on commit a01a9d7

Please sign in to comment.