From 89125426d503b06e434d275fc236468eb952e9e8 Mon Sep 17 00:00:00 2001 From: mschuetz Date: Fri, 6 Mar 2015 14:30:21 +0100 Subject: [PATCH] getPointsInProfile() returns points segment by segment; each segment has a project() function to align points in this segment to x-axis --- src/PointCloudOctree.js | 68 +++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index 91123b18..14c3f6c3 100644 --- a/src/PointCloudOctree.js +++ b/src/PointCloudOctree.js @@ -616,23 +616,71 @@ Potree.PointCloudOctree.prototype.getBoundingBoxWorld = function(){ * * maxDepth: search points up to the given octree depth * + * + * The return value is an array with all segments of the profile path + * var segment = { + * start: THREE.Vector3, + * end: THREE.Vector3, + * points: {} + * project: function() + * }; + * + * The project() function inside each segment can be used to transform + * that segments point coordinates to line up along the x-axis. + * + * */ Potree.PointCloudOctree.prototype.getPointsInProfile = function(profile, maxDepth){ - var points = null; + var points = []; + + var mileage = 0; for(var i = 0; i < profile.points.length - 1; i++){ var start = profile.points[i]; var end = profile.points[i+1]; var ps = this.getProfile(start, end, profile.width, maxDepth); - if(!points){ - points = ps; - }else{ - for(var property in points){ - if(points.hasOwnProperty(property)){ - points[property] = points[property].concat(ps[property]); - } + var project = function(_start, _end, _mileage){ + var start = _start; + var end = _end; + var mileage = _mileage; + + var xAxis = new THREE.Vector3(1,0,0); + var dir = new THREE.Vector3().subVectors(end, start); + dir.y = 0; + dir.normalize(); + var alpha = Math.acos(xAxis.dot(dir)); + if(dir.z > 0){ + alpha = -alpha; } - } + + + return function(position){ + + var toOrigin = new THREE.Matrix4().makeTranslation(-start.x, -start.y, -start.z); + var alignWithX = new THREE.Matrix4().makeRotationY(-alpha); + var applyMileage = new THREE.Matrix4().makeTranslation(mileage, 0, 0); + + + var pos = position.clone(); + pos.applyMatrix4(toOrigin); + pos.applyMatrix4(alignWithX); + pos.applyMatrix4(applyMileage); + + return pos; + }; + + }(start, end, mileage) + + var segment = { + start: start, + end: end, + points: ps, + project: project + }; + + points.push(segment); + + mileage += start.distanceTo(end); } return points; @@ -747,6 +795,8 @@ Potree.PointCloudOctree.prototype.getProfile = function(start, end, width, depth } } + inside.numPoints = inside.position.length; + return inside; } }