[Liblas-commits] libpc: checkpoint
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Mar 8 19:05:38 EST 2011
details: http://hg.liblas.orglibpc/rev/b4db8be8ea0f
changeset: 186:b4db8be8ea0f
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Mar 07 20:52:36 2011 -0800
description:
checkpoint
Subject: libpc: added cheesy decimation filter
details: http://hg.liblas.orglibpc/rev/d472a33cd79c
changeset: 187:d472a33cd79c
user: Michael P. Gerlek <mpg at flaxen.com>
date: Tue Mar 08 16:04:11 2011 -0800
description:
added cheesy decimation filter
Subject: libpc: viewer work
details: http://hg.liblas.orglibpc/rev/9bf3a3b2a277
changeset: 188:9bf3a3b2a277
user: Michael P. Gerlek <mpg at flaxen.com>
date: Tue Mar 08 16:05:29 2011 -0800
description:
viewer work
diffstat:
csharp/PCView/MainWindow.xaml.cs | 228 +++++++++++++++++++++++++---
csharp/PCView/PCView.csproj | 7 +
csharp/PCView/PointCloudRenderEngine.cs | 45 ++---
csharp/PCView/Trackball.cs | 80 ++++++++++
csharp/libpc_swig_cpp/libpc.i | 37 ++++-
csharp/libpc_swig_cs/libpc_swig_cs.csproj | 2 +
csharp/libpc_swig_test/TestLiblasReader.cs | 12 +-
include/libpc/DecimationFilter.hpp | 64 ++++++++
src/CMakeLists.txt | 2 +
src/DecimationFilter.cpp | 79 ++++++++++
test/unit/CMakeLists.txt | 1 +
test/unit/DecimationFilterTest.cpp | 77 +++++++++
12 files changed, 570 insertions(+), 64 deletions(-)
diffs (truncated from 872 to 300 lines):
diff -r f769b2b31a74 -r 9bf3a3b2a277 csharp/PCView/MainWindow.xaml.cs
--- a/csharp/PCView/MainWindow.xaml.cs Mon Mar 07 16:31:08 2011 -0800
+++ b/csharp/PCView/MainWindow.xaml.cs Tue Mar 08 16:05:29 2011 -0800
@@ -40,7 +40,9 @@
using System.Windows.Documents;
using System.Windows.Input;
using SlimDX;
-
+ using Libpc;
+ using System;
+
/// <summary>
/// Implements the MouseExample test.
/// </summary>
@@ -50,6 +52,7 @@
private Point m_downPoint;
private bool m_isMoving = false;
private string m_positionString;
+ private Trackball m_trackball;
/// <summary>
/// Initializes a new instance of the Mouse class.
@@ -70,8 +73,25 @@
this.DataContext = this;
- Vector4[] points = CreateData();
- m_renderEngine.SetPoints(points);
+ float minx, miny, minz, maxx, maxy, maxz;
+
+ Vector4[] points = CreateFileData(out minx, out miny, out minz, out maxx, out maxy, out maxz);
+ //Vector4[] points = CreateRandomData(out minx, out miny, out minz, out maxx, out maxy, out maxz);
+
+ float rangeX = maxx - minx;
+ float rangeY = maxy - miny;
+ float rangeZ = maxz - minz;
+ float largestRange = Math.Max(rangeX, Math.Max(rangeY, rangeZ));
+ m_renderEngine.TranslationVector = new Vector3(-minx, -miny, -minz);
+ m_renderEngine.ScaleVector = new Vector3(1 / largestRange, 1 / largestRange, 1 / largestRange);
+
+ m_renderEngine.SetPoints(points, minx, miny, minz, maxx, maxy, maxz);
+
+ m_trackball = null;
+
+ // world coords
+ m_renderEngine.CameraPosition = new Vector3(0.5f, 0.5f, -10.0f);
+ m_renderEngine.TargetPosition = new Vector3(0.5f, 0.5f, 0.5f);
return;
}
@@ -99,47 +119,78 @@
#region mouse handlers
private void Mouse_MouseDown(object sender, MouseButtonEventArgs e)
{
+ Point point = e.GetPosition(x_contentControl);
+
+ if (m_trackball == null)
+ {
+ m_trackball = new Trackball((float)x_contentControl.ActualWidth, (float)x_contentControl.ActualHeight);
+ }
+
if (e.LeftButton == MouseButtonState.Pressed)
{
- m_downPoint = e.GetPosition(x_contentControl);
+ m_downPoint = point;
+ m_trackball.PreviousPoint = m_downPoint;
+ m_isMoving = true;
+ }
+ if (e.RightButton == MouseButtonState.Pressed)
+ {
+ m_downPoint = point;
m_isMoving = true;
}
}
private void Mouse_MouseUp(object sender, MouseButtonEventArgs e)
{
- m_isMoving = false;
+ if (e.LeftButton == MouseButtonState.Pressed)
+ {
+ m_isMoving = false;
+ }
+ if (e.RightButton == MouseButtonState.Pressed)
+ {
+ m_isMoving = false;
+ }
}
private void Mouse_MouseMove(object sender, MouseEventArgs e)
{
- Point mouse = e.GetPosition(x_contentControl);
+ Point point = e.GetPosition(x_contentControl);
- Vector3 world = m_renderEngine.ConvertToWorldCoordinates(mouse, (float)x_contentControl.ActualWidth, (float)x_contentControl.ActualHeight);
-
- PositionString = string.Format(
- CultureInfo.InvariantCulture,
- "[{0},{1}] X={2} Y={3} Z={4}",
- mouse.X,
- mouse.Y,
- world.X.ToString("F1", CultureInfo.InvariantCulture),
- world.Y.ToString("F1", CultureInfo.InvariantCulture),
- world.Z.ToString("F1", CultureInfo.InvariantCulture));
+ {
+ Vector3 world = m_renderEngine.ConvertToWorldCoordinates(point, (float)x_contentControl.ActualWidth, (float)x_contentControl.ActualHeight);
+
+ PositionString = string.Format(
+ CultureInfo.InvariantCulture,
+ "[{0},{1}] X={2} Y={3} Z={4}",
+ point.X,
+ point.Y,
+ world.X.ToString("F1", CultureInfo.InvariantCulture),
+ world.Y.ToString("F1", CultureInfo.InvariantCulture),
+ world.Z.ToString("F1", CultureInfo.InvariantCulture));
+ }
if (e.LeftButton == MouseButtonState.Pressed)
{
if (m_isMoving)
{
- Point currPoint = e.GetPosition(x_contentControl);
- Vector3 camera = m_renderEngine.CameraPosition;
- Vector3 target = m_renderEngine.TargetPosition;
- camera.X += (float)(m_downPoint.X - currPoint.X) / 100.0f;
- target.X += (float)(m_downPoint.X - currPoint.X) / 100.0f;
- camera.Y += -(float)(m_downPoint.Y - currPoint.Y) / 100.0f;
- target.Y += -(float)(m_downPoint.Y - currPoint.Y) / 100.0f;
- m_renderEngine.CameraPosition = camera;
- m_renderEngine.TargetPosition = target;
- m_downPoint = currPoint;
+ Matrix rotation = m_trackball.Update(point);
+ m_renderEngine.RotationMatrix = rotation;
+ }
+ }
+ if (e.RightButton == MouseButtonState.Pressed)
+ {
+ if (m_isMoving)
+ {
+ float x = (float)(m_downPoint.X - point.X);
+ float y = -(float)(m_downPoint.Y - point.Y);
+ Vector3 vc = m_renderEngine.CameraPosition;
+ Vector3 vt = m_renderEngine.TargetPosition;
+ vc.X += x / 100;
+ vc.Y += y / 100;
+ vt.X += x / 100;
+ vt.Y += y / 100;
+ m_renderEngine.CameraPosition = vc;
+ m_renderEngine.TargetPosition = vt;
+ m_downPoint = point;
}
}
@@ -148,14 +199,126 @@
private void Mouse_MouseWheel(object sender, MouseWheelEventArgs e)
{
+ ////float s = (float)e.Delta / 100;
+ ////if (s < 0) s = 1 / -s;
+
+ ////m_renderEngine.Scale *= Matrix.Scaling(s,s,s);
+ //m_renderEngine.Scale = m_trackball.Scale(e.Delta);
+
Vector3 camera = m_renderEngine.CameraPosition;
- camera.Z += e.Delta / 100.0f;
- camera.Z += e.Delta / 100.0f;
+ camera.Z += e.Delta / (120.0f * 1);
+ if (camera.Z >= m_renderEngine.TargetPosition.Z) return;
m_renderEngine.CameraPosition = camera;
+ return;
}
#endregion
- private Vector4[] CreateData()
+ private DecimationFilter m_filter = null; // BUG: swig scoping issue
+ private LiblasReader m_reader = null;
+
+ private Vector4[] CreateFileData(out float minx, out float miny, out float minz, out float maxx, out float maxy, out float maxz)
+ {
+ //string file = "../../test/data/1.2-with-color.las";
+ string file = "../../test/data/hobu.las";
+
+ Vector4 red = new Vector4(1, 0, 0, 1);
+ Vector4 green = new Vector4(0, 1, 0, 1);
+ Vector4 blue = new Vector4(0, 0, 1, 1);
+
+ List<Vector4> points = new List<Vector4>();
+
+ istream istr = Utils.openFile(file);
+ m_reader = new LiblasReader(istr);
+
+ Stage stage = m_reader;
+ {
+ int np = (int)m_reader.getNumPoints();
+ if (np > 100000)
+ {
+ int step = np / 100000;
+ m_filter = new DecimationFilter(m_reader, step);
+ stage = m_filter;
+ }
+ }
+
+ Header header = stage.getHeader();
+ Bounds_double bounds = header.getBounds();
+ minx = (float)bounds.getMinimum(0);
+ miny = (float)bounds.getMinimum(1);
+ minz = (float)bounds.getMinimum(2);
+ maxx = (float)bounds.getMaximum(0);
+ maxy = (float)bounds.getMaximum(1);
+ maxz = (float)bounds.getMaximum(2);
+
+ // 1.2-with-color
+ //minx 635619.9f
+ //miny 848899.7f
+ //minz 406.59f
+ //maxx 638982.563
+ //maxy 853535.438
+ //maxz 586.38
+
+ ulong numPoints = stage.getNumPoints();
+ //numPoints = Math.Min(numPoints, 100000);
+
+ Schema schema = stage.getHeader().getSchema();
+ SchemaLayout layout = new SchemaLayout(schema);
+
+ PointData data = new PointData(layout,(uint)numPoints);
+
+ uint numRead = stage.read(data);
+
+ uint offsetX = (uint)schema.getDimensionIndex(Dimension.Field.Field_X);
+ uint offsetY = (uint)schema.getDimensionIndex(Dimension.Field.Field_Y);
+ uint offsetZ = (uint)schema.getDimensionIndex(Dimension.Field.Field_Z);
+ uint offsetR = (uint)schema.getDimensionIndex(Dimension.Field.Field_Red);
+ uint offsetG = (uint)schema.getDimensionIndex(Dimension.Field.Field_Green);
+ uint offsetBG = (uint)schema.getDimensionIndex(Dimension.Field.Field_Blue);
+
+ for (uint index=0; index<numRead; index++)
+ {
+ Int32 xraw = data.getField_Int32(index, offsetX);
+ Int32 yraw = data.getField_Int32(index, offsetY);
+ Int32 zraw = data.getField_Int32(index, offsetZ);
+ float x = (float)schema.getDimension(offsetX).getNumericValue_Int32(xraw);
+ float y = (float)schema.getDimension(offsetY).getNumericValue_Int32(yraw);
+ float z = (float)schema.getDimension(offsetZ).getNumericValue_Int32(zraw);
+
+ if (index == 0)
+ {
+ minx = maxx = x;
+ miny = maxy = y;
+ minz = maxz = z;
+ }
+ else
+ {
+ minx = Math.Min(x, minx);
+ miny = Math.Min(y, miny);
+ minz = Math.Min(z, minz);
+ maxx = Math.Max(x, maxx);
+ maxy = Math.Max(y, maxy);
+ maxz = Math.Max(z, maxz);
+ }
+
+ UInt16 r = data.getField_UInt16(index, offsetX);
+ UInt16 g = data.getField_UInt16(index, offsetY);
+ UInt16 b = data.getField_UInt16(index, offsetZ);
+
+ points.Add(new Vector4(x, y, z, 1));
+
+ float rf = (float)r / 65535.0f;
+ float gf = (float)g / 65535.0f;
+ float bf = (float)b / 65535.0f;
+ points.Add(new Vector4(rf, gf, bf, 1));
+ //points.Add(blue);
+ }
+
+ Utils.closeFile(istr);
+
+ return points.ToArray();
+ }
+
+ private Vector4[] CreateRandomData(out float minx, out float miny, out float minz, out float maxx, out float maxy, out float maxz)
{
Vector4 red = new Vector4(1, 0, 0, 1);
Vector4 green = new Vector4(0, 1, 0, 1);
@@ -178,6 +341,13 @@
points.Add(new Vector4(r, g, b, 1));
}
+ minx = 0;
+ miny = 0;
+ minz = 0;
+ maxx = 100;
+ maxy = 100;
+ maxz = 100;
+
return points.ToArray();
}
diff -r f769b2b31a74 -r 9bf3a3b2a277 csharp/PCView/PCView.csproj
--- a/csharp/PCView/PCView.csproj Mon Mar 07 16:31:08 2011 -0800
+++ b/csharp/PCView/PCView.csproj Tue Mar 08 16:05:29 2011 -0800
@@ -107,6 +107,7 @@
More information about the Liblas-commits
mailing list