diff --git a/src/osgPlugins/dxf/dxfEntity.cpp b/src/osgPlugins/dxf/dxfEntity.cpp index 27e0b5809..a0c678daf 100644 --- a/src/osgPlugins/dxf/dxfEntity.cpp +++ b/src/osgPlugins/dxf/dxfEntity.cpp @@ -24,6 +24,7 @@ std::map > dxfEntity::_registry; RegisterEntityProxy g_dxf3DFace; RegisterEntityProxy g_dxfCircle; RegisterEntityProxy g_dxfArc; +RegisterEntityProxy g_dxfPoint; RegisterEntityProxy g_dxfLine; RegisterEntityProxy g_dxfVertex; RegisterEntityProxy g_dxfPolyline; @@ -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) diff --git a/src/osgPlugins/dxf/dxfEntity.h b/src/osgPlugins/dxf/dxfEntity.h index c59bb1e35..6ff5a7f51 100644 --- a/src/osgPlugins/dxf/dxfEntity.h +++ b/src/osgPlugins/dxf/dxfEntity.h @@ -104,6 +104,22 @@ protected: 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: diff --git a/src/osgPlugins/dxf/scene.cpp b/src/osgPlugins/dxf/scene.cpp index 83478cb52..65303b3f9 100644 --- a/src/osgPlugins/dxf/scene.cpp +++ b/src/osgPlugins/dxf/scene.cpp @@ -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) diff --git a/src/osgPlugins/dxf/scene.h b/src/osgPlugins/dxf/scene.h index 3bc43a600..758654cac 100644 --- a/src/osgPlugins/dxf/scene.h +++ b/src/osgPlugins/dxf/scene.h @@ -57,6 +57,23 @@ public: }; +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) { @@ -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) { @@ -143,12 +159,14 @@ public: 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; @@ -171,6 +189,22 @@ protected: 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(); @@ -314,6 +348,7 @@ public: } 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 & vertices); void addLineLoop(const std::string & l, unsigned short color, std::vector & vertices);