[Liblas-commits] hg-main-tree: inlined some things; made color filter work with L...

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Apr 18 17:03:32 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/b19f310c3724
changeset: 591:b19f310c3724
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Apr 18 14:02:39 2011 -0700
description:
inlined some things; made color filter work with LAS schema
Subject: hg-main-tree: switch to native las driver, some tuning

details:   http://hg.libpc.orghg-main-tree/rev/5ad49de6335d
changeset: 592:5ad49de6335d
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Apr 18 14:03:15 2011 -0700
description:
switch to native las driver, some tuning

diffstat:

 apps/pcview/Controller.cpp               |   10 ++-
 apps/pcview/Controller.hpp               |    5 +-
 apps/pcview/Engine.cpp                   |   35 ++++++++++-
 apps/pcview/main.cpp                     |  103 ++++++++++++++++++++++++------
 include/libpc/PointBuffer.hpp            |   37 +++++++++-
 include/libpc/SchemaLayout.hpp           |    5 +-
 include/libpc/filters/ColorFilter.hpp    |    3 +-
 src/PointBuffer.cpp                      |   37 +----------
 src/SchemaLayout.cpp                     |    6 -
 src/drivers/las/Reader.cpp               |   11 ++-
 src/filters/ColorFilter.cpp              |   59 +++++++++++------
 src/filters/DecimationFilter.cpp         |   26 +++++--
 src/filters/DecimationFilterIterator.cpp |    9 +-
 13 files changed, 240 insertions(+), 106 deletions(-)

diffs (truncated from 726 to 300 lines):

diff -r 78997149b0cf -r 5ad49de6335d apps/pcview/Controller.cpp
--- a/apps/pcview/Controller.cpp	Fri Apr 15 20:21:11 2011 -0700
+++ b/apps/pcview/Controller.cpp	Mon Apr 18 14:03:15 2011 -0700
@@ -50,6 +50,7 @@
     , m_cameraZ(m_defaultCameraZ)
     , m_numPoints(0)
     , m_points(NULL)
+    , m_colors(NULL)
     , m_minx(0.0f)
     , m_miny(0.0f)
     , m_minz(0.0f)
@@ -187,10 +188,17 @@
 }
  
 
-void Controller::setPoints(const float* points, int numPoints)
+const boost::uint16_t* Controller::getColors() const
+{
+    return m_colors;
+}
+
+
+void Controller::setPoints(const float* points, const boost::uint16_t* colors, int numPoints)
 {
     m_numPoints = numPoints;
     m_points = points;
+    m_colors = colors;
 }
 
 
diff -r 78997149b0cf -r 5ad49de6335d apps/pcview/Controller.hpp
--- a/apps/pcview/Controller.hpp	Fri Apr 15 20:21:11 2011 -0700
+++ b/apps/pcview/Controller.hpp	Mon Apr 18 14:03:15 2011 -0700
@@ -37,6 +37,7 @@
 
 #include <deque>
 
+#include <boost/cstdint.hpp>
 
 class Command;
 
@@ -66,7 +67,8 @@
 
     int getNumPoints() const;
     const float* getPoints() const;
-    void setPoints(const float* points, int numPoints);
+    const boost::uint16_t* getColors() const;
+    void setPoints(const float* points, const boost::uint16_t* colors, int numPoints);
 
     void setBounds(float minx, float miny, float minz, float maxx, float maxy, float maxz);
     void getBounds(float& minx, float& miny, float& minz, float& maxx, float& maxy, float& maxz, float& delx, float& dely, float& delz);
@@ -94,6 +96,7 @@
 
     int m_numPoints;
     const float* m_points;
+    const boost::uint16_t* m_colors;
 
     float m_minx, m_miny, m_minz, m_maxx, m_maxy, m_maxz;
 
diff -r 78997149b0cf -r 5ad49de6335d apps/pcview/Engine.cpp
--- a/apps/pcview/Engine.cpp	Fri Apr 15 20:21:11 2011 -0700
+++ b/apps/pcview/Engine.cpp	Mon Apr 18 14:03:15 2011 -0700
@@ -133,6 +133,7 @@
 
     controller.reset();
 
+    delete m_arcBall;
     m_arcBall = new ArcBallControl(controller.getWindowSizeW(), controller.getWindowSizeH());
 
     m_scale = 1.0;
@@ -229,6 +230,7 @@
         break;
 
     case 27: // ESC key
+    case 'q':
         controller.pushCommand(new CommandExit());
         break;
 
@@ -355,8 +357,10 @@
     glTranslated(-minx-delx/2.0,-miny-dely/2.0,-minz-delx/2.0);
 
     const float* points = controller.getPoints();
+    const boost::uint16_t* colors = controller.getColors();
     const int numPoints = controller.getNumPoints();
     
+#if 0
     // draw points
     glBegin(GL_POINTS);
     glColor3f(1,1,1);
@@ -365,10 +369,36 @@
         float x = points[i];
         float y = points[i+1];
         float z = points[i+2];
-        glVertex3f(x,y,z);
+
+        if (colors != NULL)
+        {
+            boost::uint16_t r = colors[i];
+            boost::uint16_t g = colors[i+1];
+            boost::uint16_t b = colors[i+2];
+
+            glColor3us(r, g, b);
+        }
+
+        glVertex3f(x, y, z);
     }
     glEnd();
+#else
+    glEnableClientState(GL_COLOR_ARRAY);
+    glEnableClientState(GL_VERTEX_ARRAY);
+    glColorPointer(3, GL_UNSIGNED_SHORT, 0, colors);
+    glVertexPointer(3, GL_FLOAT, 0, points);
+    
+    glBegin(GL_POINTS);
+    for (int i=0; i<numPoints; i++)
+    {
+        glArrayElement(i);
+    }
+    glEnd();
+    //glDrawElements(GL_POINTS, numPoints, GL_FLOAT, points);
+#endif
 
+    if (0)
+    {
     // draw cube
     glBegin(GL_LINES);
     
@@ -410,7 +440,9 @@
     glVertex3f(maxx,maxy,maxz);
 
     glEnd();
+    }
 
+#if 0
     // put indicator at orgin
     glBegin(GL_LINE_STRIP);
     glColor3f(1,1,1);
@@ -419,6 +451,7 @@
     glVertex3f(minx, miny, minz+0.2f*delz);
     glVertex3f(minx+0.2f*delx, miny, minz);
     glEnd();
+#endif
 
     glFlush();
 
diff -r 78997149b0cf -r 5ad49de6335d apps/pcview/main.cpp
--- a/apps/pcview/main.cpp	Fri Apr 15 20:21:11 2011 -0700
+++ b/apps/pcview/main.cpp	Mon Apr 18 14:03:15 2011 -0700
@@ -33,20 +33,30 @@
 ****************************************************************************/
 
 #include <stdlib.h>
+
+#include <boost/timer.hpp>
+
 #include "Engine.hpp"
 #include "Controller.hpp"
 
 #include <libpc/filters/DecimationFilter.hpp>
+#include <libpc/filters/ColorFilter.hpp>
+#include <libpc/drivers/las/Reader.hpp>
 #include <libpc/drivers/liblas/Reader.hpp>
-#include <libpc/drivers/liblas/Iterator.hpp>
+#include <libpc/drivers/las/Reader.hpp>
+#include <libpc/Color.hpp>
 #include <libpc/PointBuffer.hpp>
 #include <libpc/Schema.hpp>
 #include <libpc/SchemaLayout.hpp>
 #include <libpc/Bounds.hpp>
 #include <libpc/Dimension.hpp>
+#include <libpc/Iterator.hpp>
 
 using namespace std;
 
+static float* g_points = NULL;
+static boost::uint16_t* g_colors = NULL;
+
 
 static float myrand_gaussian() // returns [0..1]
 {
@@ -73,14 +83,15 @@
 static void readFakeFile(Controller& controller)
 {
     const int numPoints = 10000;
-    static float points[numPoints * 3];
+    g_points = new float[numPoints * 3];
+    g_colors = new boost::uint16_t[numPoints * 3];
 
     const float minx = 100.0;
     const float maxx = 200.0;
     const float miny = 50.0;
     const float maxy = 250.0;
     const float minz = 10.0;
-    const float maxz = 15.0;
+    const float maxz = 50.0;
     const float delx = maxx-minx;
     const float dely = maxy-miny;
     const float delz = maxz-minz;
@@ -91,12 +102,24 @@
         float y = miny + dely*myrand_normal();
         float z = minz + delz*myrand_gaussian();
 
-        points[i] = (float)x;
-        points[i+1] = (float)y;
-        points[i+2] = (float)z;
+        g_points[i] = (float)x;
+        g_points[i+1] = (float)y;
+        g_points[i+2] = (float)z;
+
+        double red,green,blue;
+        libpc::Color::interpolateColor(z,minz,maxz,red,green,blue);
+        
+        const double vmax = (std::numeric_limits<boost::uint16_t>::max)();
+        boost::uint16_t r16 = (boost::uint16_t)(red * vmax);
+        boost::uint16_t g16 = (boost::uint16_t)(green * vmax);
+        boost::uint16_t b16 = (boost::uint16_t)(blue * vmax);
+
+        g_colors[i] = r16;
+        g_colors[i+1] = g16;
+        g_colors[i+2] = b16;
     }
 
-    controller.setPoints(points, numPoints);
+    controller.setPoints(g_points, g_colors, numPoints);
     controller.setBounds(minx, miny, minz, maxx, maxy, maxz);
 
     return;
@@ -105,19 +128,33 @@
 
 static void readFile(Controller& controller, const string& file)
 {
-    libpc::Stage* reader = new libpc::drivers::liblas::LiblasReader(file);
+    boost::timer timer;
+
+    const int maxPoints = 10 * 1000;
+
+    libpc::Stage* reader = new libpc::drivers::las::LasReader(file);
+    //libpc::Stage* reader = new libpc::drivers::liblas::LiblasReader(file);
     libpc::Stage* stage = reader;
     
+    printf("given %d points\n", (boost::uint32_t)stage->getNumPoints());
+
     libpc::Stage* decimator = NULL;
-    if (reader->getNumPoints() > 50000)
+    if (reader->getNumPoints() > maxPoints)
     {
-        boost::uint32_t factor = (boost::uint32_t)reader->getNumPoints() / 50000;
-        decimator = new libpc::filters::DecimationFilter(*reader, factor);
+        boost::uint32_t factor = (boost::uint32_t)reader->getNumPoints() / maxPoints;
+        decimator = new libpc::filters::DecimationFilter(*stage, factor);
         stage = decimator;
     }
 
+    libpc::Stage* colorizer = NULL;
+    {
+        colorizer = new libpc::filters::ColorFilter(*stage);
+        stage = colorizer;
+    }
+
     boost::uint32_t numPoints = (boost::uint32_t)stage->getNumPoints();
     printf("reading of %d points started\n", numPoints);
+    std::cout << "Elapsed time: " << timer.elapsed() << " seconds" << std::endl;
 
     const libpc::Schema& schema = stage->getSchema();
     const libpc::SchemaLayout schemaLayout(schema);
@@ -127,11 +164,22 @@
     boost::uint32_t numRead = iter->read(buffer);
     assert(numPoints==numRead);
 
+    printf("reading into buffer done\n", numPoints);
+    std::cout << "Elapsed time: " << timer.elapsed() << " seconds" << std::endl;
+
     const int offsetX = schema.getDimensionIndex(libpc::Dimension::Field_X, libpc::Dimension::Int32);
     const int offsetY = schema.getDimensionIndex(libpc::Dimension::Field_Y, libpc::Dimension::Int32);
     const int offsetZ = schema.getDimensionIndex(libpc::Dimension::Field_Z, libpc::Dimension::Int32);
+    const int offsetR = schema.getDimensionIndex(libpc::Dimension::Field_Red, libpc::Dimension::Uint16);
+    const int offsetG = schema.getDimensionIndex(libpc::Dimension::Field_Green, libpc::Dimension::Uint16);
+    const int offsetB = schema.getDimensionIndex(libpc::Dimension::Field_Blue, libpc::Dimension::Uint16);
 
-    float* points = new float[numRead * 3];
+    const libpc::Dimension& xDim = schema.getDimension(offsetX);
+    const libpc::Dimension& yDim = schema.getDimension(offsetY);
+    const libpc::Dimension& zDim = schema.getDimension(offsetZ);
+
+    g_points = new float[numRead * 3];
+    g_colors = new boost::uint16_t[numRead * 3];
 
     int cnt=0;
     for (boost::uint32_t i=0; i<numRead; i++)
@@ -139,26 +187,38 @@
         const boost::int32_t xraw = buffer.getField<boost::int32_t>(i, offsetX);
         const boost::int32_t yraw = buffer.getField<boost::int32_t>(i, offsetY);
         const boost::int32_t zraw = buffer.getField<boost::int32_t>(i, offsetZ);
+        
+        const boost::int16_t r16 = buffer.getField<boost::int16_t>(i, offsetR);
+        const boost::int16_t g16 = buffer.getField<boost::int16_t>(i, offsetG);
+        const boost::int16_t b16 = buffer.getField<boost::int16_t>(i, offsetB);
 
-        const double x = schema.getDimension(offsetX).applyScaling(xraw);
-        const double y = schema.getDimension(offsetY).applyScaling(yraw);


More information about the Liblas-commits mailing list