From Martin Beckett, "I have added support for DXF POINTS to the dxf 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."
This commit is contained in:
parent
4a50d54d3e
commit
ddddec2b2f
@ -24,6 +24,7 @@ std::map<std::string, ref_ptr<dxfBasicEntity> > dxfEntity::_registry;
|
|||||||
RegisterEntityProxy<dxf3DFace> g_dxf3DFace;
|
RegisterEntityProxy<dxf3DFace> g_dxf3DFace;
|
||||||
RegisterEntityProxy<dxfCircle> g_dxfCircle;
|
RegisterEntityProxy<dxfCircle> g_dxfCircle;
|
||||||
RegisterEntityProxy<dxfArc> g_dxfArc;
|
RegisterEntityProxy<dxfArc> g_dxfArc;
|
||||||
|
RegisterEntityProxy<dxfPoint> g_dxfPoint;
|
||||||
RegisterEntityProxy<dxfLine> g_dxfLine;
|
RegisterEntityProxy<dxfLine> g_dxfLine;
|
||||||
RegisterEntityProxy<dxfVertex> g_dxfVertex;
|
RegisterEntityProxy<dxfVertex> g_dxfVertex;
|
||||||
RegisterEntityProxy<dxfPolyline> g_dxfPolyline;
|
RegisterEntityProxy<dxfPolyline> g_dxfPolyline;
|
||||||
@ -326,6 +327,34 @@ dxfLine::drawScene(scene* sc)
|
|||||||
// std::cout << ++lcount << " ";
|
// std::cout << ++lcount << " ";
|
||||||
// sc->ocs_clear();
|
// 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
|
void
|
||||||
dxfPolyline::assign(dxfFile* dxf, codeValue& cv)
|
dxfPolyline::assign(dxfFile* dxf, codeValue& cv)
|
||||||
|
@ -104,6 +104,22 @@ protected:
|
|||||||
double _endAngle;
|
double _endAngle;
|
||||||
osg::Vec3d _ocs;
|
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
|
class dxfLine : public dxfBasicEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -50,6 +50,15 @@ Vec3d scene::addNormal(Vec3d v)
|
|||||||
// to do: vertices are not always listed in order. find why.
|
// to do: vertices are not always listed in order. find why.
|
||||||
return v;
|
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
|
void
|
||||||
scene::addLine(const std::string & l, unsigned short color, Vec3d & s, Vec3d & e)
|
scene::addLine(const std::string & l, unsigned short color, Vec3d & s, Vec3d & e)
|
||||||
|
@ -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
|
static inline
|
||||||
osg::Geometry* createLnGeometry( osg::PrimitiveSet::Mode lineType, osg::Vec3Array* vertices, const osg::Vec4 & color)
|
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;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
osg::Geometry* createTriGeometry( osg::Vec3Array* vertices, osg::Vec3Array* normals, const osg::Vec4 & color)
|
osg::Geometry* createTriGeometry( osg::Vec3Array* vertices, osg::Vec3Array* normals, const osg::Vec4 & color)
|
||||||
{
|
{
|
||||||
@ -143,12 +159,14 @@ public:
|
|||||||
virtual ~sceneLayer() {}
|
virtual ~sceneLayer() {}
|
||||||
void layer2osg(osg::Group* root, bounds &b)
|
void layer2osg(osg::Group* root, bounds &b)
|
||||||
{
|
{
|
||||||
|
osgPoints(root, b);
|
||||||
osgLines(root, b);
|
osgLines(root, b);
|
||||||
osgTriangles(root, b);
|
osgTriangles(root, b);
|
||||||
osgQuads(root, b);
|
osgQuads(root, b);
|
||||||
osgText(root, b);
|
osgText(root, b);
|
||||||
}
|
}
|
||||||
MapVListList _linestrips;
|
MapVListList _linestrips;
|
||||||
|
MapVList _points;
|
||||||
MapVList _lines;
|
MapVList _lines;
|
||||||
MapVList _triangles;
|
MapVList _triangles;
|
||||||
MapVList _trinorms;
|
MapVList _trinorms;
|
||||||
@ -171,6 +189,22 @@ protected:
|
|||||||
std::string _name;
|
std::string _name;
|
||||||
|
|
||||||
osg::Vec4 getColor(unsigned short color);
|
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)
|
void osgLines(osg::Group* root, bounds &b)
|
||||||
{
|
{
|
||||||
for(MapVListList::iterator mlitr = _linestrips.begin();
|
for(MapVListList::iterator mlitr = _linestrips.begin();
|
||||||
@ -314,6 +348,7 @@ public:
|
|||||||
}
|
}
|
||||||
unsigned short correctedColorIndex(const std::string & l, unsigned short color);
|
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 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 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);
|
void addLineLoop(const std::string & l, unsigned short color, std::vector<osg::Vec3d> & vertices);
|
||||||
|
Loading…
Reference in New Issue
Block a user