Hi,
This patch fixes some performance problems with the DXF loader. It removes
some unnecessary copies of vertex coordinates (which were causing an
exponential explosion). It also replaces BIND_PER_PRIMITIVE normals  with
BIND_PER_VERTEX so that the resulting geometry will be on the fast path.

Tim

Attachment: dxf.tar
Description: Unix tar archive

From 13b50b5bc5fa359af68b12e53a79c42cd6a0a7d4 Mon Sep 17 00:00:00 2001
From: Tim Moore <[email protected]>
Date: Thu, 3 Feb 2011 09:07:19 +0100
Subject: [PATCH] performance fixes for DXF loader

Avoid copies of lists of vertices. One of these copies was causing n-squared
behavior when loading quads.

Build geometry that  uses the fast path.
---
 src/osgPlugins/dxf/scene.cpp |    5 +----
 src/osgPlugins/dxf/scene.h   |   16 ++++++++++------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/osgPlugins/dxf/scene.cpp b/src/osgPlugins/dxf/scene.cpp
index 65303b3..ce67988 100644
--- a/src/osgPlugins/dxf/scene.cpp
+++ b/src/osgPlugins/dxf/scene.cpp
@@ -165,14 +165,11 @@ void scene::addQuads(const std::string & l, unsigned short color, std::vector<Ve
                 n.normalize();
                 short cindex = correctedColorIndex(l, color);
                 ly->_quadnorms[cindex].push_back( n );
-                MapVList mvl = ly->_quads;
-                VList vl = mvl[cindex];
+                VList& vl = ly->_quads[cindex];
                 vl.push_back(addVertex(*a));
                 vl.push_back(addVertex(*b));
                 vl.push_back(addVertex(*c));
                 vl.push_back(addVertex(*d));
-                mvl[cindex] = vl;
-                ly->_quads = mvl;
             }
     }
 }    
diff --git a/src/osgPlugins/dxf/scene.h b/src/osgPlugins/dxf/scene.h
index 758654c..ebb08a6 100644
--- a/src/osgPlugins/dxf/scene.h
+++ b/src/osgPlugins/dxf/scene.h
@@ -102,7 +102,7 @@ osg::Geometry* createTriGeometry( osg::Vec3Array* vertices, osg::Vec3Array* norm
     geom->setColorArray(colors);
     geom->setColorBinding(osg::Geometry::BIND_OVERALL);
     geom->setNormalArray(normals);
-    geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
+    geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
     return geom;
 }
 
@@ -117,7 +117,7 @@ osg::Geometry* createQuadGeometry( osg::Vec3Array* vertices, osg::Vec3Array* nor
     geom->setColorArray(colors);
     geom->setColorBinding(osg::Geometry::BIND_OVERALL);
     geom->setNormalArray(normals);
-    geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
+    geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
     return geom;
 }
 
@@ -252,11 +252,13 @@ protected:
                     coords->push_back(v);
                 }
                 osg::Vec3Array *norms = new osg::Vec3Array;
-                VList normlist = _trinorms[mitr->first];
+                VList& normlist = _trinorms[mitr->first];
                 for (itr = normlist.begin();
                     itr != normlist.end(); ++itr)
                 {
-                    norms->push_back(osg::Vec3(itr->x(), itr->y(), itr->z()));
+                    osg::Vec3 norm(itr->x(), itr->y(), itr->z());
+                    for (int i = 0; i < 3; ++i)
+                        norms->push_back(norm);
                 }
                 root->addChild(createModel(_name, createTriGeometry(coords, norms, getColor(mitr->first))));
             }
@@ -275,10 +277,12 @@ protected:
                     coords->push_back(v);
                 }
                 osg::Vec3Array *norms = new osg::Vec3Array;
-                VList normlist = _quadnorms[mitr->first];
+                VList& normlist = _quadnorms[mitr->first];
                 for (itr = normlist.begin();
                     itr != normlist.end(); ++itr) {
-                    norms->push_back(osg::Vec3(itr->x(), itr->y(), itr->z()));
+                    osg::Vec3 norm(itr->x(), itr->y(), itr->z());
+                    for (int i = 0; i < 4; ++i)
+                        norms->push_back(norm);
                 }
                 root->addChild(createModel(_name, createQuadGeometry(coords, norms, getColor(mitr->first))));
             }
-- 
1.7.3.4

_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to