').load(new URL(Potree.scriptPath + "/profile.html").href, () => {
- $('#potree_render_area').append(elProfile.children());
- this._2dprofile = new Potree.Viewer.Profile(this, document.getElementById("profile_draw_container"));
+ $(document.body).append(elProfile.children());
+ this._2dprofile = new Potree.Viewer.Profile(this);
+
+ $("#profile_window").draggable({
+ handle: $("#profile_titlebar"),
+ containment: $(document.body)
+ });
+ $("#profile_window").resizable();
if(callback){
$(callback);
}
});
+
+
});
@@ -15224,64 +15251,505 @@ class EDLRenderer{
};
+Potree.ProfilePointStore = class ProfilePointStore{
+
+ constructor(profile){
+ this.profile = profile;
+ this.boundingBox = new THREE.Box3();
+ this.projectedBoundingBox = new THREE.Box3();
+ this.maxPoints = 50*1000;
+ this.numPoints = 0;
+
+ this.buffers = {
+ position: new Float32Array(3 * this.maxPoints),
+ color: new Uint8Array(3 * this.maxPoints)
+ };
+
+ this.segments = [];
+ for(let i = 0; i < profile.points.length - 1; i++){
+ let start = profile.points[i + 0];
+ let end = profile.points[i + 1];
+
+ let startGround = new THREE.Vector3(start.x, start.y, 0);
+ let endGround = new THREE.Vector3(end.x, end.y, 0);
+
+ let center = new THREE.Vector3().addVectors(endGround, startGround).multiplyScalar(0.5);
+ let length = startGround.distanceTo(endGround);
+
+ let segment = {
+ start: start,
+ end: end,
+ points: {},
+ length: length,
+ numPoints: 0
+ };
+
+ this.segments.push(segment);
+ }
+ }
+
+ onProgress(progress){
+
+ if(this.segments.length !== progress.segments.length){
+ return;
+ }
+
+
+ for(let i = 0; i < progress.segments.length; i++){
+ let sourceSegment = progress.segments[i];
+ let targetSegment = this.segments[i];
+
+ for(let attribute of Object.keys(sourceSegment.points)){
+ if(targetSegment.points[attribute] === undefined){
+ targetSegment.points[attribute] = new Array(targetSegment.numPoints).fill(0);
+ }
+
+ targetSegment.points[attribute] = targetSegment.points[attribute]
+ .concat(sourceSegment.points[attribute]);
+
+ if(attribute === "position"){
+ for(let j = 0; j < sourceSegment.numPoints; j++){
+
+ let x = sourceSegment.points.mileage[j];
+ let y = sourceSegment.points.position[j].z;
+ let z = 0;
+
+ let offset = 3 * (this.numPoints + j);
+
+ this.buffers.position[offset + 0] = x;
+ this.buffers.position[offset + 1] = y;
+ this.buffers.position[offset + 2] = z;
+ }
+ }else if(attribute === "color"){
+ for(let j = 0; j < sourceSegment.numPoints; j++){
+
+ let r = sourceSegment.points.color[j][0];
+ let g = sourceSegment.points.color[j][1];
+ let b = sourceSegment.points.color[j][2];
+
+ let offset = 3 * (this.numPoints + j);
+
+ this.buffers.color[offset + 0] = r;
+ this.buffers.color[offset + 1] = g;
+ this.buffers.color[offset + 2] = b;
+ }
+ }
+
+ }
+
+ targetSegment.numPoints += sourceSegment.numPoints;
+ this.numPoints += sourceSegment.numPoints;
+ }
+
+ }
+
+ selectPoint(mileage, elevation, radius){
+
+ let closest = {
+ distance: Infinity,
+ segment: null,
+ index: null
+ };
+
+ for(let segment of this.segments){
+ for(let i = 0; i < segment.numPoints; i++){
+
+ let m = segment.points.mileage[i] - mileage;
+ let e = segment.points.position[i].z - elevation;
+
+ let r = Math.sqrt(m * m + e * e);
+
+ if(r < radius && r < closest.distance){
+ closest = {
+ distance: r,
+ segment: segment,
+ index: i
+ };
+ }
+ }
+ }
+
+ if(closest.distance < Infinity){
+ let point = {};
+
+ let attributes = Object.keys(closest.segment.points);
+ for(let attribute of attributes){
+ point[attribute] = closest.segment.points[attribute][closest.index];
+ }
+
+ return point;
+ }else{
+ return null;
+ }
+ }
+
+
+}
+
Potree.Viewer.Profile = class ProfileWindow{
- constructor(viewer, element){
+ constructor(viewer){
this.viewer = viewer;
this.enabled = true;
- this.element = element;
this.currentProfile = null;
this.requests = [];
- this.pointsProcessed = 0;
- this.margin = {top: 0, right: 0, bottom: 20, left: 40};
this.maximized = false;
this.threshold = 20*1000;
+ this.autoFit = true;
+ this.numPoints = 0;
+ this.mouse = new THREE.Vector2();
+ this.points = null;
+ this.selectedPoint = null;
+
+ this.elRoot = $("#profile_window");
+
+ this.renderArea = this.elRoot.find("#profileCanvasContainer");
+
+ { // THREE.JS
+ this.renderer = new THREE.WebGLRenderer({alpha: true, premultipliedAlpha: false});
+ this.renderer.setClearColor( 0x000000, 0 );
+ this.renderer.setSize(10, 10);
+ this.renderer.autoClear = true;
+ this.renderArea.append($(this.renderer.domElement));
+ this.renderer.domElement.tabIndex = "2222";
+ this.renderer.context.getExtension("EXT_frag_depth");
+ $(this.renderer.domElement).css("width", "100%");
+ $(this.renderer.domElement).css("height", "100%");
+
+ this.camera = new THREE.OrthographicCamera(-10, 10, 10, -10, -1000, 1000);
+
+ this.scene = new THREE.Scene();
+
+ this.maxPoints = 50*1000;
+ this.geometry = new THREE.BufferGeometry();
+ this.buffers = {
+ position: new Float32Array(3 * this.maxPoints),
+ color: new Uint8Array(3 * this.maxPoints),
+ };
+
+ this.geometry.addAttribute("position", new THREE.BufferAttribute(this.buffers.position, 3));
+ this.geometry.addAttribute("color", new THREE.BufferAttribute(this.buffers.color, 3, true));
+ this.geometry.setDrawRange(0, 100);
+ //this.material = new THREE.PointsMaterial( { size: 0.001, vertexColors: THREE.VertexColors } );
+ this.material = new Potree.PointCloudMaterial({size: 2.0});
+ this.material.pointSizeType = Potree.PointSizeType.FIXED;
+ this.tPoints = new THREE.Points(this.geometry, this.material);
+ this.scene.add(this.tPoints);
+
+
+ let sg = new THREE.SphereGeometry(1, 16, 16);
+ let sm = new THREE.MeshNormalMaterial();
+ this.pickSphere = new THREE.Mesh(sg, sm);
+ this.pickSphere.visible = false;
+ this.scene.add(this.pickSphere);
+ }
+
+ { // SVG
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
+ let marginLeft = this.renderArea[0].offsetLeft;
+
+ this.svg = d3.select("svg#profileSVG");
+ this.svg.selectAll("*").remove();
+
+ this.scaleX = d3.scale.linear()
+ .domain([this.camera.left + this.camera.position.x, this.camera.right + this.camera.position.x])
+ .range([0, width]);
+ this.scaleY = d3.scale.linear()
+ .domain([this.camera.bottom + this.camera.position.y, this.camera.top + this.camera.position.y])
+ .range([height, 0]);
+
+ this.xAxis = d3.svg.axis()
+ .scale(this.scaleX)
+ .orient("bottom")
+ .innerTickSize(-height)
+ .outerTickSize(1)
+ .tickPadding(10)
+ .ticks(width / 50);
+
+ this.yAxis = d3.svg.axis()
+ .scale(this.scaleY)
+ .orient("left")
+ .innerTickSize(-width)
+ .outerTickSize(1)
+ .tickPadding(10)
+ .ticks(height / 20);
+
+ this.svg.append("g")
+ .attr("class", "x axis")
+ .attr("transform", `translate(${marginLeft}, ${height})`)
+ .call(this.xAxis);
+
+ this.svg.append("g")
+ .attr("class", "y axis")
+ .attr("transform", `translate(${marginLeft}, 0)`)
+ .call(this.yAxis);
+ }
+
+ this.min = new THREE.Vector3(0, 0, 0);
+ this.max = new THREE.Vector3(0, 0, 0);
+ this.size = new THREE.Vector3(0, 0, 0);
+ this.center = new THREE.Vector3(0, 0, 0);
+ this.scale = new THREE.Vector3(1, 1, 1);
+
+ this.mouseIsDown = false;
+
+ $(window).resize( () => {
+ this.render();
+ });
+
+ this.renderArea.mousedown(e => {
+ this.mouseIsDown = true;
+ });
+
+ this.renderArea.mouseup(e => {
+ this.mouseIsDown = false;
+ });
+
+ this.renderArea.mousemove( e => {
+ if(this.points === null || this.points.numPoints === 0){
+ return;
+ }
+
+ let rect = this.renderArea[0].getBoundingClientRect();
+ let x = e.clientX - rect.left;
+ let y = e.clientY - rect.top;
+
+ let newMouse = new THREE.Vector2(x, y);
+
+ if(this.mouseIsDown){
+ // DRAG
+ let cPos = this.toCamSpace(new THREE.Vector3(this.mouse.x, this.mouse.y, 0));
+ let ncPos = this.toCamSpace(new THREE.Vector3(newMouse.x, newMouse.y, 0));
+
+ let diff = new THREE.Vector3().subVectors(ncPos, cPos);
+ this.camera.position.sub(diff);
+ this.render();
+ }else if(this.points){
+ // FIND HOVERED POINT
+ let pixelRadius = 10;
+ let ncPos = this.toCamSpace(new THREE.Vector3(newMouse.x, newMouse.y, 0));
+ let ncPosBorder = this.toCamSpace(new THREE.Vector3(newMouse.x + pixelRadius, newMouse.y, 0));
+ let mileage = ncPos.x;
+ let elevation = ncPos.y;
+ let radius = Math.abs(ncPosBorder.x - ncPos.x);
+ let point = this.points.selectPoint(mileage, elevation, radius);
+
+ if(point){
+ this.elRoot.find("#profileSelectionProperties").fadeIn(200);
+ this.pickSphere.visible = true;
+ this.pickSphere.scale.set(0.5 * radius, 0.5 * radius, 0.5 * radius);
+ this.pickSphere.position.set(point.mileage, point.position.z, 0);
+
+ let info = this.elRoot.find("#profileSelectionProperties");
+ let html = "
"
+ info.html(html);
+
+ this.selectedPoint = point;
+ }else{
+ //this.pickSphere.visible = false;
+ //this.selectedPoint = null;
+ }
+ this.render();
+
+
+ }
+
+ this.mouse.copy(newMouse);
+ });
+
+ let onWheel = e => {
+ this.autoFit = false;
+ let delta = 0;
+ if( e.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9
+ delta = e.wheelDelta;
+ } else if ( e.detail !== undefined ) { // Firefox
+ delta = -e.detail;
+ }
+
+ let ndelta = Math.sign(delta);
+
+ let sPos = new THREE.Vector3(this.mouse.x, this.mouse.y, 0);
+ let cPos = this.toCamSpace(sPos);
+
+ if(ndelta > 0){
+ // + 10%
+ this.scale.multiplyScalar(1.1);
+ }else{
+ // - 10%
+ this.scale.multiplyScalar(100/110);
+ }
+
+ this.scale.max(new THREE.Vector3(0.5, 0.5, 0.5));
+ this.scale.min(new THREE.Vector3(100, 100, 100));
+
+ let ncPos = this.toCamSpace(sPos);
+
+ let diff = new THREE.Vector3().subVectors(ncPos, cPos);
+ this.camera.position.sub(diff);
+
+ this.render();
+ };
+ $(this.renderArea)[0].addEventListener("mousewheel", onWheel, false );
+ $(this.renderArea)[0].addEventListener("DOMMouseScroll", onWheel, false ); // Firefox
+
this.scheduledDraw = null;
- $('#closeProfileContainer').click(() => {
- this.hide();
- this.enabled = false;
- });
-
- $('#profile_toggle_size_button').click(() => {
- this.maximized = !this.maximized;
-
- if(this.maximized){
- $('#profile_window').css("height", "100%");
- }else{
- $('#profile_window').css("height", "30%");
- }
- });
-
- //this.drawOnChange = (event) => {
- // this.redraw();
- //};
-
this.redraw = () => {
if(this.currentProfile){
this.draw(this.currentProfile);
}
};
- viewer.addEventListener("height_range_changed", this.redraw);
+ $('#closeProfileContainer').click(() => {
+ this.hide();
+ this.enabled = false;
+ });
+
+ //$('#profile_toggle_size_button').click(() => {
+ // this.maximized = !this.maximized;
+ //
+ // if(this.maximized){
+ // $('#profile_window').css("height", "100%");
+ // }else{
+ // $('#profile_window').css("height", "30%");
+ // }
+ //
+ // this.render();
+ //});
- let width = document.getElementById('profile_window').clientWidth;
- let height = document.getElementById('profile_window').clientHeight;
- let resizeLoop = () => {
- requestAnimationFrame(resizeLoop);
- let newWidth = document.getElementById('profile_window').clientWidth;
- let newHeight = document.getElementById('profile_window').clientHeight;
+ }
+
+ toCamSpace(coord){
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
+
+ let cam = new THREE.Vector3(
+ coord.x - width / 2,
+ -coord.y + height / 2,
+ 0);
+
+ cam.divide(this.scale);
+ cam.add(this.camera.position);
+
+ return cam;
+ }
+
+ toScreenSpace(coord){
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
+
+ let v = new THREE.Vector3().subVectors(coord, this.camera.position);
+ v.multiply(this.scale);
+
+ let screen = new THREE.Vector3(
+ width / 2 + v.x,
+ height / 2 - v.y,
+ 0);
+
+ return screen;
+ }
+
+ render(){
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
+
+ { // THREEJS
+
+ let left = (-width / 2) / this.scale.x;
+ let right = (+width / 2) / this.scale.x;
+ let top = (+height / 2) / this.scale.y;
+ let bottom = (-height / 2) / this.scale.y;
+
+ this.camera.left = left;
+ this.camera.right = right;
+ this.camera.top = top;
+ this.camera.bottom = bottom;
+ this.camera.updateProjectionMatrix();
- if(newWidth !== width || newHeight !== height){
- setTimeout(this.redraw, 50, {profile: this.currentProfile});
- }
-
- width = newWidth;
- height = newHeight;
- };
- requestAnimationFrame(resizeLoop);
+ let radius =
+ this.toCamSpace(new THREE.Vector3(0, 0, 0)).distanceTo(
+ this.toCamSpace(new THREE.Vector3(5, 0, 0)));
+ this.pickSphere.scale.set(radius, radius, radius);
+ this.pickSphere.position.z = this.camera.far - radius;
+
+
+ this.renderer.setSize(width, height);
+
+ this.renderer.render(this.scene, this.camera);
+ }
+
+ { // SVG SCALES
+ let marginLeft = this.renderArea[0].offsetLeft;
+
+ this.scaleX.domain([this.camera.left + this.camera.position.x, this.camera.right + this.camera.position.x])
+ .range([0, width]);
+ this.scaleY.domain([this.camera.bottom + this.camera.position.y, this.camera.top + this.camera.position.y])
+ .range([height, 0]);
+
+ this.xAxis.scale(this.scaleX)
+ .orient("bottom")
+ .innerTickSize(-height)
+ .outerTickSize(1)
+ .tickPadding(10)
+ .ticks(width / 50);
+ this.yAxis.scale(this.scaleY)
+ .orient("left")
+ .innerTickSize(-width)
+ .outerTickSize(1)
+ .tickPadding(10)
+ .ticks(height / 20);
+
+ d3.select(".x,axis")
+ .attr("transform", `translate(${marginLeft}, ${height})`)
+ .call(this.xAxis);
+ d3.select(".y,axis")
+ .attr("transform", `translate(${marginLeft}, 0)`)
+ .call(this.yAxis);
+ }
}
show(){
@@ -15301,215 +15769,129 @@ Potree.Viewer.Profile = class ProfileWindow{
this.requests = [];
};
- preparePoints(profileProgress){
+ handleNewPoints(profileProgress){
+ this.points.onProgress(profileProgress);
+
+ let prepared = this.preparePoints(profileProgress);
+
+ if(prepared.numPoints === 0){
+ return;
+ }
+
+ if(this.numPoints === 0){
+ this.min.fromArray(prepared.buffers.position, 3);
+ this.max.fromArray(prepared.buffers.position, 3);
+ }
+
+ for(let i = 0; i < prepared.numPoints; i++){
+ let pos = new THREE.Vector3().fromArray(
+ prepared.buffers.position.slice(3*i, 3*i+3));
+ this.min.min(pos);
+ this.max.max(pos);
+ }
+ let newSize = new THREE.Vector3().subVectors(this.max, this.min);
+ this.size.copy(newSize);
+
+ let newNumPoints = this.numPoints + prepared.numPoints;
+
+ let position = this.buffers.position;
+ let color = this.buffers.color;
+
+ position.set(this.points.buffers.position.slice(3 * this.numPoints, 3 * newNumPoints), 3 * this.numPoints);
+ color.set(this.points.buffers.color.slice(3 * this.numPoints, 3 * newNumPoints), 3 * this.numPoints);
+
+ this.geometry.attributes.position.needsUpdate = true;
+ this.geometry.attributes.color.needsUpdate = true;
+
+ this.geometry.setDrawRange(0, newNumPoints);
+
+ this.numPoints = newNumPoints;
+
+ this.center = new THREE.Vector3().addVectors(this.min, this.max)
+ .multiplyScalar(0.5);
+
+ if(this.autoFit){ // SCALE
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
+
+ let sx = width / this.size.x;
+ let sy = height / this.size.y;
+ let scale = Math.min(sx, sy);
+
+ this.scale.set(scale, scale, 1);
+ this.camera.position.copy(this.center);
+ }
+
+ this.firstUpdateFollows = false;
+
+ this.elRoot.find("#profile_num_points").html(
+ Potree.utils.addCommas(this.numPoints.toFixed(0)));
+ }
+ preparePoints(profileProgress){
+
let segments = profileProgress.segments;
if (segments.length === 0){
return false;
}
- let data = [];
+ let numPoints = profileProgress.size();
+
+ let position = new Float32Array(3 * numPoints);
+ let color = new Uint8Array(3 * numPoints);
+
let distance = 0;
let totalDistance = 0;
let min = new THREE.Vector3(Math.max());
let max = new THREE.Vector3(0);
- // Get the same color map as Three
- let hr = this.viewer.getHeightRange();
-
- let heightRange = hr.max - hr.min;
- let colorRange = [];
- let colorDomain = [];
-
- // Read the altitude gradient used in 3D scene
- let gradient = viewer.scene.pointclouds[0].material.gradient;
- for (let c = 0; c < gradient.length; c++){
- colorDomain.push(hr.min + heightRange * gradient[c][0]);
- colorRange.push('#' + gradient[c][1].getHexString());
- }
-
- // Altitude color map scale
- let colorRamp = d3.scale.linear()
- .domain(colorDomain)
- .range(colorRange)
- .clamp(true);
-
// Iterate the profile's segments
+ let i = 0;
for(let segment of segments){
let sv = new THREE.Vector3().subVectors(segment.end, segment.start).setZ(0)
- let segmentLength = sv.length();
+ let segmentDir = sv.clone().normalize();
let points = segment.points;
// Iterate the segments' points
- for(let j = 0; j < points.numPoints; j++){
+ for(let j = 0; j < segment.numPoints; j++){
let p = points.position[j];
- let pl = new THREE.Vector3().subVectors(p, segment.start).setZ(0);
+
+ //let svp = new THREE.Vector3().subVectors(p, segment.start);
+ //let distance = segmentDir.dot(svp);
min.min(p);
max.max(p);
- let distance = totalDistance + pl.length();
+ //position[3*i + 0] = distance + totalDistance;
+ position[3*i + 0] = points.mileage[j];
+ position[3*i + 1] = p.z;
+ position[3*i + 2] = 0;
- let d = {
- distance: distance,
- x: p.x,
- y: p.y,
- z: p.z,
- altitude: p.z,
- heightColor: colorRamp(p.z),
- color: points.color ? points.color[j] : [0, 0, 0],
- intensity: points.intensity ? points.intensity[j] : 0,
- classification: points.classification ? points.classification[j] : 0,
- returnNumber: points.returnNumber ? points.returnNumber[j] : 0,
- numberOfReturns: points.numberOfReturns ? points.numberOfReturns[j] : 0,
- pointSourceID: points.pointSourceID ? points.pointSourceID[j] : 0,
- };
+ let c = points.color ? points.color[j] : [0, 0, 0];
+ color[3*i + 0] = c[0];
+ color[3*i + 1] = c[1];
+ color[3*i + 2] = c[2];
- data.push(d);
+
+ i++;
}
- // Increment distance from the profile start point
- totalDistance += segmentLength;
+ totalDistance += segment.length;
}
-
- let output = {
- 'data': data,
- 'minX': min.x,
- 'minY': min.y,
- 'minZ': min.z,
- 'maxX': max.x,
- 'maxY': max.y,
- 'maxZ': max.z
+
+ let result = {
+ numPoints: numPoints,
+ min: min,
+ max: max,
+ buffers: {
+ position: position,
+ color: color
+ }
};
- return output;
+ return result;
};
- pointHighlight(coordinates){
-
- let pointSize = 6;
-
- let svg = d3.select("svg#profileSVG");
-
- // Find the hovered point if applicable
- let d = this.points;
- let sx = this.scaleX;
- let sy = this.scaleY;
- let xs = coordinates[0];
- let ys = coordinates[1];
-
- // Fix FF vs Chrome discrepancy
- //if(navigator.userAgent.indexOf("Firefox") == -1 ) {
- // xs = xs - this.margin.left;
- // ys = ys - this.margin.top;
- //}
- let hP = [];
- let tol = pointSize;
-
- for (let i=0; i < d.length; i++){
- if(sx(d[i].distance) < xs + tol && sx(d[i].distance) > xs - tol && sy(d[i].altitude) < ys + tol && sy(d[i].altitude) > ys -tol){
- hP.push(d[i]);
- }
- }
-
- if(hP.length > 0){
- let p = hP[0];
- this.hoveredPoint = hP[0];
- let cx, cy;
- if(navigator.userAgent.indexOf("Firefox") == -1 ) {
- cx = this.scaleX(p.distance) + this.margin.left;
- cy = this.scaleY(p.altitude) + this.margin.top;
- } else {
- cx = this.scaleX(p.distance);
- cy = this.scaleY(p.altitude);
- }
-
- //cx -= pointSize / 2;
- cy -= pointSize / 2;
-
- //let svg = d3.select("svg#profileSVG");
- d3.selectAll("rect").remove();
- let rectangle = svg.append("rect")
- .attr("x", cx)
- .attr("y", cy)
- .attr("id", p.id)
- .attr("width", pointSize)
- .attr("height", pointSize)
- .style("fill", 'yellow');
-
-
- let marker = $("#profile_selection_marker");
- marker.css("display", "initial");
- marker.css("left", cx + "px");
- marker.css("top", cy + "px");
- marker.css("width", pointSize + "px");
- marker.css("height", pointSize + "px");
- marker.css("background-color", "yellow");
-
- //let html = 'x: ' + Math.round(10 * p.x) / 10 + ' y: ' + Math.round(10 * p.y) / 10 + ' z: ' + Math.round( 10 * p.altitude) / 10 + ' - ';
- //html += i18n.t('tools.classification') + ': ' + p.classificationCode + ' - ';
- //html += i18n.t('tools.intensity') + ': ' + p.intensityCode;
-
- let html = 'x: ' + Math.round(10 * p.x) / 10 + ' y: ' + Math.round(10 * p.y) / 10 + ' z: ' + Math.round( 10 * p.altitude) / 10 + ' - ';
- html += "offset: " + p.distance.toFixed(3) + ' - ';
- html += "Classification: " + p.classification + ' - ';
- html += "Intensity: " + p.intensity;
-
- $('#profileInfo').css('color', 'yellow');
- $('#profileInfo').html(html);
-
- } else {
- d3.selectAll("rect").remove();
- $('#profileInfo').html("");
-
- let marker = $("#profile_selection_marker");
- marker.css("display", "none");
- }
- };
-
- strokeColor(d){
- let material = this.viewer.getMaterial();
- if (material === Potree.PointColorType.RGB) {
- let [r, g, b] = d.color.map(e => parseInt(e));
-
- return `rgb( ${r}, ${g}, ${b})`;
- } else if (material === Potree.PointColorType.INTENSITY) {
- let irange = viewer.getIntensityRange();
- let i = parseInt(255 * (d.intensity - irange[0]) / (irange[1] - irange[0]));
-
- return `rgb(${i}, ${i}, ${i})`;
- } else if (material === Potree.PointColorType.CLASSIFICATION) {
- let classif = this.viewer.scene.pointclouds[0].material.classification;
- if (typeof classif[d.classification] != 'undefined'){
- let color = 'rgb(' + classif[d.classification].x * 100 + '%,';
- color += classif[d.classification].y * 100 + '%,';
- color += classif[d.classification].z * 100 + '%)';
- return color;
- } else {
- return 'rgb(255,255,255)';
- }
- } else if (material === Potree.PointColorType.HEIGHT) {
- return d.heightColor;
- } else if (material === Potree.PointColorType.RETURN_NUMBER) {
-
- if(d.numberOfReturns === 1){
- return 'rgb(255, 255, 0)';
- }else{
- if(d.returnNumber === 1){
- return 'rgb(255, 0, 0)';
- }else if(d.returnNumber === d.numberOfReturns){
- return 'rgb(0, 0, 255)';
- }else{
- return 'rgb(0, 255, 0)';
- }
- }
-
- return d.heightColor;
- } else {
- return d.color;
- }
- }
-
draw(profile){
if(!this.enabled){
return;
@@ -15527,7 +15909,7 @@ Potree.Viewer.Profile = class ProfileWindow{
// 2d profile draws don't need frame-by-frame granularity, it's
// fine to handle a redraw once every 100ms
let executeScheduledDraw = () => {
- this.actuallyDraw(this.scheduledDraw);
+ this.prepareDraw(this.scheduledDraw);
this.scheduledDraw = null;
};
@@ -15537,16 +15919,12 @@ Potree.Viewer.Profile = class ProfileWindow{
this.scheduledDraw = profile;
}
- actuallyDraw(profile){
-
- if(this.context){
- let containerWidth = this.element.clientWidth;
- let containerHeight = this.element.clientHeight;
-
- let width = containerWidth - (this.margin.left + this.margin.right);
- let height = containerHeight - (this.margin.top + this.margin.bottom);
- this.context.clearRect(0, 0, width, height);
- }
+ prepareDraw(profile){
+ this.autoFit = true;
+ this.numPoints = 0;
+ this.geometry.setDrawRange(0, this.numPoints);
+ this.pickSphere.visible = false;
+ this.elRoot.find("#profileSelectionProperties").hide();
if(this.currentProfile){
this.currentProfile.removeEventListener("marker_moved", this.redraw);
@@ -15556,10 +15934,15 @@ Potree.Viewer.Profile = class ProfileWindow{
viewer.removeEventListener("material_changed", this.redraw);
viewer.removeEventListener("height_range_changed", this.redraw);
viewer.removeEventListener("intensity_range_changed", this.redraw);
+
+ for(let request of this.requests){
+ request.cancel();
+ }
}
this.currentProfile = profile;
+ this.points = new Potree.ProfilePointStore(this.currentProfile);
{
this.currentProfile.addEventListener("marker_moved", this.redraw);
@@ -15570,200 +15953,6 @@ Potree.Viewer.Profile = class ProfileWindow{
viewer.addEventListener("height_range_changed", this.redraw);
viewer.addEventListener("intensity_range_changed", this.redraw);
}
-
- if(!this.__drawData){
- this.__drawData = {};
- }
- this.points = [];
- this.rangeX = [Infinity, -Infinity];
- this.rangeY = [Infinity, -Infinity];
-
- this.pointsProcessed = 0;
-
- for(let request of this.requests){
- request.cancel();
- }
- this.requests = [];
-
- let drawPoints = (points, rangeX, rangeY) => {
-
- let mileage = 0;
- for(let i = 0; i < profile.points.length; i++){
- let point = profile.points[i];
-
- if(i > 0){
- let previous = profile.points[i-1];
- let dx = point.x - previous.x;
- let dy = point.y - previous.y;
- let distance = Math.sqrt(dx * dx + dy * dy);
- mileage += distance;
- }
-
- let radius = 4;
-
- let cx = this.scaleX(mileage);
- let cy = this.context.canvas.clientHeight;
-
- this.context.beginPath();
- this.context.arc(cx, cy, radius, 0, 2 * Math.PI, false);
- this.context.fillStyle = '#a22';
- this.context.fill();
- };
-
-
- let pointSize = 2;
- let i = -1, n = points.length, d, cx, cy;
- while (++i < n) {
- d = points[i];
- cx = this.scaleX(d.distance);
- cy = this.scaleY(d.altitude);
- this.context.beginPath();
- this.context.moveTo(cx, cy);
- this.context.fillStyle = this.strokeColor(d);
- this.context.fillRect(cx, cy, pointSize, pointSize);
- }
- };
-
- let projectedBoundingBox = null;
-
- let setupAndDraw = () => {
- let containerWidth = this.element.clientWidth;
- let containerHeight = this.element.clientHeight;
-
- let width = containerWidth - (this.margin.left + this.margin.right);
- let height = containerHeight - (this.margin.top + this.margin.bottom);
-
- this.scaleX = d3.scale.linear();
- this.scaleY = d3.scale.linear();
-
- let domainProfileWidth = this.rangeX[1] - this.rangeX[0];
- let domainProfileHeight = this.rangeY[1] - this.rangeY[0];
- let domainRatio = domainProfileWidth / domainProfileHeight;
- let rangeProfileWidth = width;
- let rangeProfileHeight = height;
- let rangeRatio = rangeProfileWidth / rangeProfileHeight;
-
- if(domainRatio < rangeRatio){
- // canvas scale
- let targetWidth = domainProfileWidth * (rangeProfileHeight / domainProfileHeight);
- this.scaleY.range([height, 0]);
- this.scaleX.range([width / 2 - targetWidth / 2, width / 2 + targetWidth / 2]);
-
- // axis scale
- let domainScale = rangeRatio / domainRatio;
- let domainScaledWidth = domainProfileWidth * domainScale;
- this.axisScaleX = d3.scale.linear()
- .domain([
- domainProfileWidth / 2 - domainScaledWidth / 2 ,
- domainProfileWidth / 2 + domainScaledWidth / 2 ])
- .range([0, width]);
- this.axisScaleY = d3.scale.linear()
- .domain(this.rangeY)
- .range([height, 0]);
- }else{
- // canvas scale
- let targetHeight = domainProfileHeight* (rangeProfileWidth / domainProfileWidth);
- this.scaleX.range([0, width]);
- this.scaleY.range([height / 2 + targetHeight / 2, height / 2 - targetHeight / 2]);
-
- // axis scale
- let domainScale = domainRatio / rangeRatio;
- let domainScaledHeight = domainProfileHeight * domainScale;
- let domainHeightCentroid = (this.rangeY[1] + this.rangeY[0]) / 2;
- this.axisScaleX = d3.scale.linear()
- .domain(this.rangeX)
- .range([0, width]);
- this.axisScaleY = d3.scale.linear()
- .domain([
- domainHeightCentroid - domainScaledHeight / 2 ,
- domainHeightCentroid + domainScaledHeight / 2 ])
- .range([height, 0]);
- }
- this.scaleX.domain(this.rangeX);
- this.scaleY.domain(this.rangeY);
-
-
-
- this.axisZoom = d3.behavior.zoom()
- .x(this.axisScaleX)
- .y(this.axisScaleY)
- .scaleExtent([0,128])
- .size([width, height]);
-
- this.zoom = d3.behavior.zoom()
- .x(this.scaleX)
- .y(this.scaleY)
- .scaleExtent([0,128])
- .size([width, height])
- .on("zoom", () => {
- this.axisZoom.translate(this.zoom.translate());
- this.axisZoom.scale(this.zoom.scale());
-
- let svg = d3.select("svg#profileSVG");
- svg.select(".x.axis").call(xAxis);
- svg.select(".y.axis").call(yAxis);
-
- this.context.clearRect(0, 0, width, height);
- drawPoints(this.points, this.rangeX, this.rangeY);
- });
-
- this.context = d3.select("#profileCanvas")
- .attr("width", width)
- .attr("height", height)
- .call(this.zoom)
- .node().getContext("2d");
-
- d3.select("svg#profileSVG").selectAll("*").remove();
-
- let svg = d3.select("svg#profileSVG")
- .call(this.zoom)
- .attr("width", (width + this.margin.left + this.margin.right).toString())
- .attr("height", (height + this.margin.top + this.margin.bottom).toString())
- .attr("transform", "translate(" + this.margin.left + "," + this.margin.top + ")");
-
- let scope = this;
- d3.select("#profileCanvas").on("mousemove", function(){
- let coord = d3.mouse(this);
- scope.pointHighlight(coord);
- });
-
- // Create x axis
- let xAxis = d3.svg.axis()
- .scale(this.axisScaleX)
- .innerTickSize(-height)
- .outerTickSize(5)
- .orient("bottom")
- .ticks(10, "m");
-
- // Create y axis
- let yAxis = d3.svg.axis()
- .scale(this.axisScaleY)
- .innerTickSize(-width)
- .outerTickSize(5)
- .orient("left")
- .ticks(10, "m");
-
- // Append axis to the chart
- let gx = svg.append("g")
- .attr("class", "x axis")
- .call(xAxis);
-
- svg.append("g")
- .attr("class", "y axis")
- .call(yAxis);
-
- if(navigator.userAgent.indexOf("Firefox") == -1 ) {
- svg.select(".y.axis").attr("transform", "translate("+ (this.margin.left).toString() + "," + this.margin.top.toString() + ")");
- svg.select(".x.axis").attr("transform", "translate(" + this.margin.left.toString() + "," + (height + this.margin.top).toString() + ")");
- } else {
- svg.select(".x.axis").attr("transform", "translate( 0 ," + height.toString() + ")");
- }
-
- drawPoints(this.points, this.rangeX, this.rangeY);
-
- document.getElementById("profile_num_points").innerHTML = Potree.utils.addCommas(this.pointsProcessed) + " ";
- };
-
for(let pointcloud of this.viewer.scene.pointclouds.filter(p => p.visible)){
@@ -15773,27 +15962,11 @@ Potree.Viewer.Profile = class ProfileWindow{
return;
}
- if(!projectedBoundingBox){
- projectedBoundingBox = event.points.projectedBoundingBox;
- }else{
- projectedBoundingBox.union(event.points.projectedBoundingBox);
- }
+ this.handleNewPoints(event.points);
- let result = this.preparePoints(event.points);
- let points = result.data;
- this.points = this.points.concat(points);
+ this.render();
- let batchRangeX = [d3.min(points, function(d) { return d.distance; }), d3.max(points, function(d) { return d.distance; })];
- let batchRangeY = [d3.min(points, function(d) { return d.altitude; }), d3.max(points, function(d) { return d.altitude; })];
-
- this.rangeX = [ Math.min(this.rangeX[0], batchRangeX[0]), Math.max(this.rangeX[1], batchRangeX[1]) ];
- this.rangeY = [ Math.min(this.rangeY[0], batchRangeY[0]), Math.max(this.rangeY[1], batchRangeY[1]) ];
-
- this.pointsProcessed += result.data.length;
-
- setupAndDraw();
-
- if(this.pointsProcessed > this.threshold){
+ if(this.numPoints > this.threshold){
this.cancel();
}
},
@@ -15813,6 +15986,7 @@ Potree.Viewer.Profile = class ProfileWindow{
}
}
+
setThreshold(value){
this.threshold = value;
@@ -15825,70 +15999,80 @@ Potree.Viewer.Profile = class ProfileWindow{
}
let file = "";
- let points = this.points.slice();
- points.sort((a, b) => (a.distance - b.distance));
+ let pointsPerSegment = this.points.segments.map(s => s.points);
+ let points = {};
+ let attributes = Object.keys(pointsPerSegment[0]);
+ for(let attribute of attributes){
+ let arrays = pointsPerSegment.map(p => p[attribute]);
+ points[attribute] = arrays.reduce( (a, v) => a.concat(v));
+ }
{ // header-line
let header = "x, y";
- if(points[0].hasOwnProperty("color")){
+ if(points.hasOwnProperty("color")){
header += ", r, g, b";
}
- if(points[0].hasOwnProperty("intensity")){
+ if(points.hasOwnProperty("intensity")){
header += ", intensity";
}
- if(points[0].hasOwnProperty("classification")){
+ if(points.hasOwnProperty("classification")){
header += ", classification";
}
- if(points[0].hasOwnProperty("numberOfReturns")){
+ if(points.hasOwnProperty("numberOfReturns")){
header += ", numberOfReturns";
}
- if(points[0].hasOwnProperty("pointSourceID")){
+ if(points.hasOwnProperty("pointSourceID")){
header += ", pointSourceID";
}
- if(points[0].hasOwnProperty("returnNumber")){
+ if(points.hasOwnProperty("returnNumber")){
header += ", returnNumber";
}
file += header + "\n";
}
+
+ let numPoints = points.position.length;
// actual data
- for(let point of points){
- let line = point.distance.toFixed(4) + ", ";
- line += point.altitude.toFixed(4) + ", ";
+ for(let i = 0; i < numPoints; i++){
- if(point.hasOwnProperty("color")){
- line += point.color.join(", ");
+ let values = [];
+
+ values.push(points.mileage[i].toFixed(4));
+ values.push(points.position[i].z.toFixed(4));
+
+ if(attributes.includes("color")){
+ values.push(points.color[i].join(", "));
}
- if(point.hasOwnProperty("intensity")){
- line += ", " + point.intensity;
+ if(attributes.includes("intensity")){
+ values.push(points.intensity[i]);
}
- if(point.hasOwnProperty("classification")){
- line += ", " + point.classification;
+ if(attributes.includes("classification")){
+ values.push(points.classification[i]);
}
- if(point.hasOwnProperty("numberOfReturns")){
- line += ", " + point.numberOfReturns;
+ if(attributes.includes("numberOfReturns")){
+ values.push(points.numberOfReturns[i]);
}
- if(point.hasOwnProperty("pointSourceID")){
- line += ", " + point.pointSourceID;
+ if(attributes.includes("pointSourceID")){
+ values.push(points.pointSourceID[i]);
}
- if(point.hasOwnProperty("returnNumber")){
- line += ", " + point.returnNumber;
+ if(attributes.includes("returnNumber")){
+ values.push(points.returnNumber[i]);
}
- line += "\n";
+ let line = values.join(", ") + "\n";
file = file + line;
}
@@ -15897,13 +16081,24 @@ Potree.Viewer.Profile = class ProfileWindow{
}
getPointsInProfileAsLas(){
- let points = this.points;
+
+ let pointsPerSegment = this.points.segments.map(s => s.points);
+ let points = {};
+ let attributes = Object.keys(pointsPerSegment[0]);
+ for(let attribute of attributes){
+ let arrays = pointsPerSegment.map(p => p[attribute]);
+ points[attribute] = arrays.reduce( (a, v) => a.concat(v));
+ }
+ let numPoints = points.position.length;
+
let boundingBox = new THREE.Box3();
- for(let point of points){
- boundingBox.expandByPoint(point);
+ for(let i = 0; i < numPoints; i++){
+ let position = points.position[i];
+ boundingBox.expandByPoint(position);
}
+
let offset = boundingBox.min.clone();
let diagonal = boundingBox.min.distanceTo(boundingBox.max);
let scale = new THREE.Vector3(0.01, 0.01, 0.01);
@@ -15922,10 +16117,9 @@ Potree.Viewer.Profile = class ProfileWindow{
}
}
- let buffer = new ArrayBuffer(227 + 28 * points.length);
+ let buffer = new ArrayBuffer(227 + 28 * numPoints);
let view = new DataView(buffer);
let u8View = new Uint8Array(buffer);
- //let u16View = new Uint16Array(buffer);
setString("LASF", 0, buffer);
u8View[24] = 1;
@@ -15954,7 +16148,7 @@ Potree.Viewer.Profile = class ProfileWindow{
view.setUint16(105, 28, true);
// number of point records 107 4
- view.setUint32(107, points.length, true);
+ view.setUint32(107, numPoints, true);
// number of points by return 111 20
@@ -15976,10 +16170,16 @@ Potree.Viewer.Profile = class ProfileWindow{
// z offset 171 8
view.setFloat64(171, offset.z, true);
+ let hasIntensity = attributes.includes("intensity");
+ let hasReturnNumber = attributes.includes("returnNumber");
+ let hasClassification = attributes.includes("classification");
+ let hasPointSourceID = attributes.includes("pointSourceID");
+
let boffset = 227;
- for(let i = 0; i < points.length; i++){
- let point = points[i];
- let position = new THREE.Vector3(point.x, point.y, point.z);
+ for(let i = 0; i < numPoints; i++){
+ //let point = points[i];
+ //let position = new THREE.Vector3(point.x, point.y, point.z);
+ let position = points.position[i];
let ux = parseInt((position.x - offset.x) / scale.x);
let uy = parseInt((position.y - offset.y) / scale.y);
@@ -15988,21 +16188,30 @@ Potree.Viewer.Profile = class ProfileWindow{
view.setUint32(boffset + 0, ux, true);
view.setUint32(boffset + 4, uy, true);
view.setUint32(boffset + 8, uz, true);
+
+ if(hasIntensity){
+ view.setUint16(boffset + 12, (points.intensity[i]), true);
+ }
- view.setUint16(boffset + 12, (point.intensity), true);
- let rt = point.returnNumber;
- rt += (point.numberOfReturns << 3);
- view.setUint8(boffset + 14, rt);
+ if(hasReturnNumber){
+ let rt = points.returnNumber[i];
+ rt += (points.numberOfReturns[i] << 3);
+ view.setUint8(boffset + 14, rt);
+ }
+
+ if(hasClassification){
+ view.setUint8(boffset + 15, points.classification[i]);
+ }
- // classification
- view.setUint8(boffset + 15, point.classification);
// scan angle rank
// user data
// point source id
- view.setUint16(boffset + 18, point.pointSourceID);
- view.setUint16(boffset + 20, (point.color[0] * 255), true);
- view.setUint16(boffset + 22, (point.color[1] * 255), true);
- view.setUint16(boffset + 24, (point.color[2] * 255), true);
+ if(hasPointSourceID){
+ view.setUint16(boffset + 18, points.pointSourceID[i]);
+ }
+ view.setUint16(boffset + 20, (points.color[i][0] * 255), true);
+ view.setUint16(boffset + 22, (points.color[i][1] * 255), true);
+ view.setUint16(boffset + 24, (points.color[i][2] * 255), true);
boffset += 28;
}
diff --git a/build/potree/profile.html b/build/potree/profile.html
index 6737fd29..50e5bf35 100644
--- a/build/potree/profile.html
+++ b/build/potree/profile.html
@@ -1,9 +1,15 @@
-
+
-
+
@@ -34,7 +40,7 @@
width: 100%;
flex-grow: 1;
position: relative; height: 100%;
- box-sizing: border-box;">
+ box-sizing: border-box; user-select: none">
+
+
+ position: asdsadf asdf
+ rgb: 123 423 123
+
diff --git a/examples/elevation_profile.html b/examples/elevation_profile.html
index f4e3047c..757197eb 100644
--- a/examples/elevation_profile.html
+++ b/examples/elevation_profile.html
@@ -57,7 +57,7 @@
window.viewer = new Potree.Viewer(document.getElementById("potree_render_area"));
- viewer.setEDLEnabled(true);
+ viewer.setEDLEnabled(false);
viewer.setPointSize(1);
viewer.setMaterial("RGB");
viewer.setFOV(60);
diff --git a/src/ProfileRequest.js b/src/ProfileRequest.js
index d7cb4a9e..64d1c482 100644
--- a/src/ProfileRequest.js
+++ b/src/ProfileRequest.js
@@ -78,7 +78,7 @@ Potree.ProfileData = function(profile){
var size = 0;
for(var i = 0; i < this.segments.length; i++){
if(this.segments[i].points){
- size += this.segments[i].points.numPoints;
+ size += this.segments[i].numPoints;
}
}
return size;
@@ -94,6 +94,7 @@ Potree.ProfileRequest = function(pointcloud, profile, maxDepth, callback){
this.callback = callback;
this.temporaryResult = new Potree.ProfileData(this.profile);
this.pointsServed = 0;
+ this.highestLevelServed = 0;
this.priorityQueue = new BinaryHeap(function(x){return 1 / x.weight;});
@@ -149,12 +150,12 @@ Potree.ProfileRequest = function(pointcloud, profile, maxDepth, callback){
// add points to result
intersectedNodes.push(node);
Potree.getLRU().touch(node);
+ this.highestLevelServed = node.getLevel();
if((node.level % node.pcoGeometry.hierarchyStepSize) === 0 && node.hasChildren){
this.traverse(node);
}
}else{
- console.log("loading " + node.name);
node.load();
this.priorityQueue.push(element);
}
@@ -189,6 +190,7 @@ Potree.ProfileRequest = function(pointcloud, profile, maxDepth, callback){
this.getPointsInsideProfile = function(nodes, target){
+ let totalMileage = 0;
for(var pi = 0; pi < target.segments.length; pi++){
var segment = target.segments[pi];
@@ -202,7 +204,7 @@ Potree.ProfileRequest = function(pointcloud, profile, maxDepth, callback){
if(!segment.points){
segment.points = {};
- segment.points.boundingBox = new THREE.Box3();
+ segment.boundingBox = new THREE.Box3();
for (var property in geometry.attributes) {
if (geometry.attributes.hasOwnProperty(property)) {
@@ -213,8 +215,13 @@ Potree.ProfileRequest = function(pointcloud, profile, maxDepth, callback){
}
}
}
+
+ segment.points["mileage"] = [];
}
+ let sv = new THREE.Vector3().subVectors(segment.end, segment.start).setZ(0);
+ let segmentDir = sv.clone().normalize();
+
for(var i = 0; i < numPoints; i++){
var pos = new THREE.Vector3(p[3*i], p[3*i+1], p[3*i+2]);
pos.applyMatrix4(pointcloud.matrixWorld);
@@ -222,7 +229,13 @@ Potree.ProfileRequest = function(pointcloud, profile, maxDepth, callback){
var centerDistance = Math.abs(segment.halfPlane.distanceToPoint(pos));
if(distance < profile.width / 2 && centerDistance < segment.length / 2){
- segment.points.boundingBox.expandByPoint(pos);
+ segment.boundingBox.expandByPoint(pos);
+
+ let svp = new THREE.Vector3().subVectors(pos, segment.start);
+ let localMileage = segmentDir.dot(svp);
+
+ let mileage = localMileage + totalMileage;
+ segment.points["mileage"].push(mileage);
for (var property in geometry.attributes) {
if (geometry.attributes.hasOwnProperty(property)) {
@@ -252,18 +265,24 @@ Potree.ProfileRequest = function(pointcloud, profile, maxDepth, callback){
}
}
- segment.points.numPoints = segment.points.position.length;
+ segment.numPoints = segment.points.position.length;
- if(segment.points.numPoints > 0){
- target.boundingBox.expandByPoint(segment.points.boundingBox.min);
- target.boundingBox.expandByPoint(segment.points.boundingBox.max);
+ if(segment.numPoints > 0){
+ target.boundingBox.expandByPoint(segment.boundingBox.min);
+ target.boundingBox.expandByPoint(segment.boundingBox.max);
target.projectedBoundingBox.expandByPoint(new THREE.Vector2(0, target.boundingBox.min.y));
target.projectedBoundingBox.expandByPoint(new THREE.Vector2(0, target.boundingBox.max.y));
}
+
+ totalMileage += segment.length;
}
};
+ this.finishLevelThenCancel = function(){
+ this.maxDepth = this.highestLevelServed;
+ };
+
this.cancel = function(){
callback.onCancel();
diff --git a/src/materials/PointCloudMaterial.js b/src/materials/PointCloudMaterial.js
index b844afa1..38283023 100644
--- a/src/materials/PointCloudMaterial.js
+++ b/src/materials/PointCloudMaterial.js
@@ -85,622 +85,590 @@ Potree.TreeType = {
KDTREE: 1
};
-Potree.PointCloudMaterial = function(parameters){
- THREE.Material.call( this );
- parameters = parameters || {};
-
- this.visibleNodesTexture = Potree.utils.generateDataTexture( 2048, 1, new THREE.Color( 0xffffff ) );
- this.visibleNodesTexture.minFilter = THREE.NearestFilter;
- this.visibleNodesTexture.magFilter = THREE.NearestFilter;
+Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMaterial{
- let pointSize = parameters.size || 1.0;
- let minSize = parameters.minSize || 1.0;
- let maxSize = parameters.maxSize || 50.0;
- let treeType = parameters.treeType || Potree.TreeType.OCTREE;
-
- this._pointSizeType = Potree.PointSizeType.ATTENUATED;
- this._pointShape = Potree.PointShape.SQUARE;
- this._interpolate = false;
- this._pointColorType = Potree.PointColorType.RGB;
- this._useClipBox = false;
- this.numClipBoxes = 0;
- this._clipMode = Potree.ClipMode.DISABLED;
- this._weighted = false;
- this._depthMap = null;
- this._gradient = Potree.Gradients.RAINBOW;
- this._classification = Potree.Classification.DEFAULT;
- this.gradientTexture = Potree.PointCloudMaterial.generateGradientTexture(this._gradient);
- this.classificationTexture = Potree.PointCloudMaterial.generateClassificationTexture(this._classification);
- this.lights = false;
- this.fog = false;
- this._treeType = treeType;
- this._useEDL = false;
-
- this.attributes = {
- position: { type: "fv", value: [] },
- color: { type: "fv", value: [] },
- normal: { type: "fv", value: [] },
- intensity: { type: "f", value: [] },
- classification: { type: "f", value: [] },
- returnNumber: { type: "f", value: [] },
- numberOfReturns: { type: "f", value: [] },
- pointSourceID: { type: "f", value: [] }
- };
-
- this.uniforms = {
- spacing: { type: "f", value: 1.0 },
- blendHardness: { type: "f", value: 2.0 },
- blendDepthSupplement: { type: "f", value: 0.0 },
- fov: { type: "f", value: 1.0 },
- screenWidth: { type: "f", value: 1.0 },
- screenHeight: { type: "f", value: 1.0 },
- near: { type: "f", value: 0.1 },
- far: { type: "f", value: 1.0 },
- uColor: { type: "c", value: new THREE.Color( 0xffffff ) },
- opacity: { type: "f", value: 1.0 },
- size: { type: "f", value: pointSize },
- minSize: { type: "f", value: minSize },
- maxSize: { type: "f", value: maxSize },
- octreeSize: { type: "f", value: 0 },
- bbSize: { type: "fv", value: [0,0,0] },
- heightMin: { type: "f", value: 0.0 },
- heightMax: { type: "f", value: 1.0 },
- intensityMin: { type: "f", value: 0.0 },
- intensityMax: { type: "f", value: 1.0 },
- clipBoxCount: { type: "f", value: 0 },
- visibleNodes: { type: "t", value: this.visibleNodesTexture },
- pcIndex: { type: "f", value: 0 },
- gradient: { type: "t", value: this.gradientTexture },
- classificationLUT: { type: "t", value: this.classificationTexture },
- clipBoxes: { type: "Matrix4fv", value: [] },
- clipBoxPositions: { type: "fv", value: null },
- depthMap: { type: "t", value: null },
- diffuse: { type: "fv", value: [1,1,1]},
- transition: { type: "f", value: 0.5 },
- intensityRange: { type: "fv", value: [0, 65000] },
- intensityGamma: { type: "f", value: 1 },
- intensityContrast: { type: "f", value: 0 },
- intensityBrightness:{ type: "f", value: 0 },
- rgbGamma: { type: "f", value: 1 },
- rgbContrast: { type: "f", value: 0 },
- rgbBrightness: { type: "f", value: 0 },
- wRGB: { type: "f", value: 1 },
- wIntensity: { type: "f", value: 0 },
- wElevation: { type: "f", value: 0 },
- wClassification: { type: "f", value: 0 },
- wReturnNumber: { type: "f", value: 0 },
- wSourceID: { type: "f", value: 0 },
- };
-
- this.defaultAttributeValues.normal = [0,0,0];
- this.defaultAttributeValues.classification = [0,0,0];
-
- this.vertexShader = this.getDefines() + Potree.Shaders["pointcloud.vs"];
- this.fragmentShader = this.getDefines() + Potree.Shaders["pointcloud.fs"];
- this.vertexColors = THREE.VertexColors;
-};
-
-Potree.PointCloudMaterial.prototype = new THREE.RawShaderMaterial();
-
-
-//Potree.PointCloudMaterial.prototype.copyFrom = function(source){
-//
-// for(let uniform of source.uniforms){
-// this.uniforms.value = source.uniforms.value;
-// }
-//
-// this.pointSizeType = source.pointSizeType;
-//
-//};
-//
-//Potree.PointCloudMaterial.prototype.clone = function(){
-// let material = new Potree.PointCloudMaterial();
-// material.copyFrom(this);
-//
-// return material;
-//};
-
-Potree.PointCloudMaterial.prototype.updateShaderSource = function(){
-
- this.vertexShader = this.getDefines() + Potree.Shaders["pointcloud.vs"];
- this.fragmentShader = this.getDefines() + Potree.Shaders["pointcloud.fs"];
-
- if(this.depthMap){
- this.uniforms.depthMap.value = this.depthMap;
- //this.depthMap = depthMap;
- //this.setValues({
- // depthMap: this.depthMap,
- //});
- }
-
- if(this.opacity === 1.0){
- this.blending = THREE.NoBlending;
- this.transparent = false;
- this.depthTest = true;
- this.depthWrite = true;
- }else{
- this.blending = THREE.AdditiveBlending;
- this.transparent = true;
- this.depthTest = false;
- this.depthWrite = true;
- }
+ constructor(parameters = {}){
+ super();
- if(this.weighted){
- this.blending = THREE.AdditiveBlending;
- this.transparent = true;
- this.depthTest = true;
- this.depthWrite = false;
- }
+ this.visibleNodesTexture = Potree.utils.generateDataTexture( 2048, 1, new THREE.Color( 0xffffff ) );
+ this.visibleNodesTexture.minFilter = THREE.NearestFilter;
+ this.visibleNodesTexture.magFilter = THREE.NearestFilter;
- this.needsUpdate = true;
-};
-
-Potree.PointCloudMaterial.prototype.getDefines = function(){
-
- var defines = "";
-
- if(this.pointSizeType === Potree.PointSizeType.FIXED){
- defines += "#define fixed_point_size\n";
- }else if(this.pointSizeType === Potree.PointSizeType.ATTENUATED){
- defines += "#define attenuated_point_size\n";
- }else if(this.pointSizeType === Potree.PointSizeType.ADAPTIVE){
- defines += "#define adaptive_point_size\n";
- }
-
- if(this.pointShape === Potree.PointShape.SQUARE){
- defines += "#define square_point_shape\n";
- }else if(this.pointShape === Potree.PointShape.CIRCLE){
- defines += "#define circle_point_shape\n";
- }
-
- if(this._interpolate){
- defines += "#define use_interpolation\n";
- }
-
- if(this._useEDL){
- defines += "#define use_edl\n";
- }
-
- if(this._pointColorType === Potree.PointColorType.RGB){
- defines += "#define color_type_rgb\n";
- }else if(this._pointColorType === Potree.PointColorType.COLOR){
- defines += "#define color_type_color\n";
- }else if(this._pointColorType === Potree.PointColorType.DEPTH){
- defines += "#define color_type_depth\n";
- }else if(this._pointColorType === Potree.PointColorType.HEIGHT){
- defines += "#define color_type_height\n";
- }else if(this._pointColorType === Potree.PointColorType.INTENSITY){
- defines += "#define color_type_intensity\n";
- }else if(this._pointColorType === Potree.PointColorType.INTENSITY_GRADIENT){
- defines += "#define color_type_intensity_gradient\n";
- }else if(this._pointColorType === Potree.PointColorType.LOD){
- defines += "#define color_type_lod\n";
- }else if(this._pointColorType === Potree.PointColorType.POINT_INDEX){
- defines += "#define color_type_point_index\n";
- }else if(this._pointColorType === Potree.PointColorType.CLASSIFICATION){
- defines += "#define color_type_classification\n";
- }else if(this._pointColorType === Potree.PointColorType.RETURN_NUMBER){
- defines += "#define color_type_return_number\n";
- }else if(this._pointColorType === Potree.PointColorType.SOURCE){
- defines += "#define color_type_source\n";
- }else if(this._pointColorType === Potree.PointColorType.NORMAL){
- defines += "#define color_type_normal\n";
- }else if(this._pointColorType === Potree.PointColorType.PHONG){
- defines += "#define color_type_phong\n";
- }else if(this._pointColorType === Potree.PointColorType.RGB_HEIGHT){
- defines += "#define color_type_rgb_height\n";
- }else if(this._pointColorType === Potree.PointColorType.COMPOSITE){
- defines += "#define color_type_composite\n";
- }
-
- if(this.clipMode === Potree.ClipMode.DISABLED){
- defines += "#define clip_disabled\n";
- }else if(this.clipMode === Potree.ClipMode.CLIP_OUTSIDE){
- defines += "#define clip_outside\n";
- }else if(this.clipMode === Potree.ClipMode.HIGHLIGHT_INSIDE){
- defines += "#define clip_highlight_inside\n";
- }
-
- if(this._treeType === Potree.TreeType.OCTREE){
- defines += "#define tree_type_octree\n";
- }else if(this._treeType === Potree.TreeType.KDTREE){
- defines += "#define tree_type_kdtree\n";
- }
-
- if(this.weighted){
- defines += "#define weighted_splats\n";
- }
-
- if(this.numClipBoxes > 0){
- defines += "#define use_clip_box\n";
- }
-
- return defines;
-};
-
-Potree.PointCloudMaterial.prototype.setClipBoxes = function(clipBoxes){
- if(!clipBoxes){
- return;
- }
-
- this.clipBoxes = clipBoxes;
- var doUpdate = (this.numClipBoxes !== clipBoxes.length) && (clipBoxes.length === 0 || this.numClipBoxes === 0);
-
- this.numClipBoxes = clipBoxes.length;
- this.uniforms.clipBoxCount.value = this.numClipBoxes;
-
- if(doUpdate){
- this.updateShaderSource();
- }
-
- this.uniforms.clipBoxes.value = new Float32Array(this.numClipBoxes * 16);
- this.uniforms.clipBoxPositions.value = new Float32Array(this.numClipBoxes * 3);
-
- for(var i = 0; i < this.numClipBoxes; i++){
- var box = clipBoxes[i];
+ let pointSize = parameters.size || 1.0;
+ let minSize = parameters.minSize || 1.0;
+ let maxSize = parameters.maxSize || 50.0;
+ let treeType = parameters.treeType || Potree.TreeType.OCTREE;
- this.uniforms.clipBoxes.value.set(box.inverse.elements, 16*i);
-
- this.uniforms.clipBoxPositions.value[3*i+0] = box.position.x;
- this.uniforms.clipBoxPositions.value[3*i+1] = box.position.y;
- this.uniforms.clipBoxPositions.value[3*i+2] = box.position.z;
+ this._pointSizeType = Potree.PointSizeType.ATTENUATED;
+ this._pointShape = Potree.PointShape.SQUARE;
+ this._interpolate = false;
+ this._pointColorType = Potree.PointColorType.RGB;
+ this._useClipBox = false;
+ this.numClipBoxes = 0;
+ this._clipMode = Potree.ClipMode.DISABLED;
+ this._weighted = false;
+ this._depthMap = null;
+ this._gradient = Potree.Gradients.RAINBOW;
+ this._classification = Potree.Classification.DEFAULT;
+ this.gradientTexture = Potree.PointCloudMaterial.generateGradientTexture(this._gradient);
+ this.classificationTexture = Potree.PointCloudMaterial.generateClassificationTexture(this._classification);
+ this.lights = false;
+ this.fog = false;
+ this._treeType = treeType;
+ this._useEDL = false;
+
+ this.attributes = {
+ position: { type: "fv", value: [] },
+ color: { type: "fv", value: [] },
+ normal: { type: "fv", value: [] },
+ intensity: { type: "f", value: [] },
+ classification: { type: "f", value: [] },
+ returnNumber: { type: "f", value: [] },
+ numberOfReturns: { type: "f", value: [] },
+ pointSourceID: { type: "f", value: [] }
+ };
+
+ this.uniforms = {
+ spacing: { type: "f", value: 1.0 },
+ blendHardness: { type: "f", value: 2.0 },
+ blendDepthSupplement: { type: "f", value: 0.0 },
+ fov: { type: "f", value: 1.0 },
+ screenWidth: { type: "f", value: 1.0 },
+ screenHeight: { type: "f", value: 1.0 },
+ near: { type: "f", value: 0.1 },
+ far: { type: "f", value: 1.0 },
+ uColor: { type: "c", value: new THREE.Color( 0xffffff ) },
+ opacity: { type: "f", value: 1.0 },
+ size: { type: "f", value: pointSize },
+ minSize: { type: "f", value: minSize },
+ maxSize: { type: "f", value: maxSize },
+ octreeSize: { type: "f", value: 0 },
+ bbSize: { type: "fv", value: [0,0,0] },
+ heightMin: { type: "f", value: 0.0 },
+ heightMax: { type: "f", value: 1.0 },
+ intensityMin: { type: "f", value: 0.0 },
+ intensityMax: { type: "f", value: 1.0 },
+ clipBoxCount: { type: "f", value: 0 },
+ visibleNodes: { type: "t", value: this.visibleNodesTexture },
+ pcIndex: { type: "f", value: 0 },
+ gradient: { type: "t", value: this.gradientTexture },
+ classificationLUT: { type: "t", value: this.classificationTexture },
+ clipBoxes: { type: "Matrix4fv", value: [] },
+ clipBoxPositions: { type: "fv", value: null },
+ depthMap: { type: "t", value: null },
+ diffuse: { type: "fv", value: [1,1,1]},
+ transition: { type: "f", value: 0.5 },
+ intensityRange: { type: "fv", value: [0, 65000] },
+ intensityGamma: { type: "f", value: 1 },
+ intensityContrast: { type: "f", value: 0 },
+ intensityBrightness:{ type: "f", value: 0 },
+ rgbGamma: { type: "f", value: 1 },
+ rgbContrast: { type: "f", value: 0 },
+ rgbBrightness: { type: "f", value: 0 },
+ wRGB: { type: "f", value: 1 },
+ wIntensity: { type: "f", value: 0 },
+ wElevation: { type: "f", value: 0 },
+ wClassification: { type: "f", value: 0 },
+ wReturnNumber: { type: "f", value: 0 },
+ wSourceID: { type: "f", value: 0 },
+ };
+
+ this.defaultAttributeValues.normal = [0,0,0];
+ this.defaultAttributeValues.classification = [0,0,0];
+
+ this.vertexShader = this.getDefines() + Potree.Shaders["pointcloud.vs"];
+ this.fragmentShader = this.getDefines() + Potree.Shaders["pointcloud.fs"];
+ this.vertexColors = THREE.VertexColors;
}
-};
+
+ updateShaderSource(){
+ this.vertexShader = this.getDefines() + Potree.Shaders["pointcloud.vs"];
+ this.fragmentShader = this.getDefines() + Potree.Shaders["pointcloud.fs"];
+
+ if(this.depthMap){
+ this.uniforms.depthMap.value = this.depthMap;
+ //this.depthMap = depthMap;
+ //this.setValues({
+ // depthMap: this.depthMap,
+ //});
+ }
+
+ if(this.opacity === 1.0){
+ this.blending = THREE.NoBlending;
+ this.transparent = false;
+ this.depthTest = true;
+ this.depthWrite = true;
+ }else{
+ this.blending = THREE.AdditiveBlending;
+ this.transparent = true;
+ this.depthTest = false;
+ this.depthWrite = true;
+ }
+
+ if(this.weighted){
+ this.blending = THREE.AdditiveBlending;
+ this.transparent = true;
+ this.depthTest = true;
+ this.depthWrite = false;
+ }
+
+ this.needsUpdate = true;
+ }
+
+ getDefines(){
+ let defines = "";
+
+ if(this.pointSizeType === Potree.PointSizeType.FIXED){
+ defines += "#define fixed_point_size\n";
+ }else if(this.pointSizeType === Potree.PointSizeType.ATTENUATED){
+ defines += "#define attenuated_point_size\n";
+ }else if(this.pointSizeType === Potree.PointSizeType.ADAPTIVE){
+ defines += "#define adaptive_point_size\n";
+ }
+
+ if(this.pointShape === Potree.PointShape.SQUARE){
+ defines += "#define square_point_shape\n";
+ }else if(this.pointShape === Potree.PointShape.CIRCLE){
+ defines += "#define circle_point_shape\n";
+ }
+
+ if(this._interpolate){
+ defines += "#define use_interpolation\n";
+ }
+
+ if(this._useEDL){
+ defines += "#define use_edl\n";
+ }
+
+ if(this._pointColorType === Potree.PointColorType.RGB){
+ defines += "#define color_type_rgb\n";
+ }else if(this._pointColorType === Potree.PointColorType.COLOR){
+ defines += "#define color_type_color\n";
+ }else if(this._pointColorType === Potree.PointColorType.DEPTH){
+ defines += "#define color_type_depth\n";
+ }else if(this._pointColorType === Potree.PointColorType.HEIGHT){
+ defines += "#define color_type_height\n";
+ }else if(this._pointColorType === Potree.PointColorType.INTENSITY){
+ defines += "#define color_type_intensity\n";
+ }else if(this._pointColorType === Potree.PointColorType.INTENSITY_GRADIENT){
+ defines += "#define color_type_intensity_gradient\n";
+ }else if(this._pointColorType === Potree.PointColorType.LOD){
+ defines += "#define color_type_lod\n";
+ }else if(this._pointColorType === Potree.PointColorType.POINT_INDEX){
+ defines += "#define color_type_point_index\n";
+ }else if(this._pointColorType === Potree.PointColorType.CLASSIFICATION){
+ defines += "#define color_type_classification\n";
+ }else if(this._pointColorType === Potree.PointColorType.RETURN_NUMBER){
+ defines += "#define color_type_return_number\n";
+ }else if(this._pointColorType === Potree.PointColorType.SOURCE){
+ defines += "#define color_type_source\n";
+ }else if(this._pointColorType === Potree.PointColorType.NORMAL){
+ defines += "#define color_type_normal\n";
+ }else if(this._pointColorType === Potree.PointColorType.PHONG){
+ defines += "#define color_type_phong\n";
+ }else if(this._pointColorType === Potree.PointColorType.RGB_HEIGHT){
+ defines += "#define color_type_rgb_height\n";
+ }else if(this._pointColorType === Potree.PointColorType.COMPOSITE){
+ defines += "#define color_type_composite\n";
+ }
+
+ if(this.clipMode === Potree.ClipMode.DISABLED){
+ defines += "#define clip_disabled\n";
+ }else if(this.clipMode === Potree.ClipMode.CLIP_OUTSIDE){
+ defines += "#define clip_outside\n";
+ }else if(this.clipMode === Potree.ClipMode.HIGHLIGHT_INSIDE){
+ defines += "#define clip_highlight_inside\n";
+ }
+
+ if(this._treeType === Potree.TreeType.OCTREE){
+ defines += "#define tree_type_octree\n";
+ }else if(this._treeType === Potree.TreeType.KDTREE){
+ defines += "#define tree_type_kdtree\n";
+ }
+
+ if(this.weighted){
+ defines += "#define weighted_splats\n";
+ }
+
+ if(this.numClipBoxes > 0){
+ defines += "#define use_clip_box\n";
+ }
+ return defines;
+ }
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "gradient", {
- get: function(){
+
+ setClipBoxes(clipBoxes){
+ if(!clipBoxes){
+ return;
+ }
+
+ this.clipBoxes = clipBoxes;
+ let doUpdate = (this.numClipBoxes !== clipBoxes.length) && (clipBoxes.length === 0 || this.numClipBoxes === 0);
+
+ this.numClipBoxes = clipBoxes.length;
+ this.uniforms.clipBoxCount.value = this.numClipBoxes;
+
+ if(doUpdate){
+ this.updateShaderSource();
+ }
+
+ this.uniforms.clipBoxes.value = new Float32Array(this.numClipBoxes * 16);
+ this.uniforms.clipBoxPositions.value = new Float32Array(this.numClipBoxes * 3);
+
+ for(let i = 0; i < this.numClipBoxes; i++){
+ let box = clipBoxes[i];
+
+ this.uniforms.clipBoxes.value.set(box.inverse.elements, 16*i);
+
+ this.uniforms.clipBoxPositions.value[3*i+0] = box.position.x;
+ this.uniforms.clipBoxPositions.value[3*i+1] = box.position.y;
+ this.uniforms.clipBoxPositions.value[3*i+2] = box.position.z;
+ }
+ }
+
+ get gradient(){
return this._gradient;
- },
- set: function(value){
+ }
+
+ set gradient(value){
if(this._gradient !== value){
this._gradient = value;
this.gradientTexture = Potree.PointCloudMaterial.generateGradientTexture(this._gradient);
this.uniforms.gradient.value = this.gradientTexture;
}
}
-});
+
+
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "classification", {
- get: function(){
+ get classification(){
return this._classification;
- },
- set: function(value){
+ }
+
+ set classification(value){
//if(this._classification !== value){
this._classification = value;
this.classificationTexture = Potree.PointCloudMaterial.generateClassificationTexture(this._classification);
this.uniforms.classificationLUT.value = this.classificationTexture;
//}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "spacing", {
- get: function(){
+ get spacing(){
return this.uniforms.spacing.value;
- },
- set: function(value){
+ }
+
+ set spacing(value){
if(this.uniforms.spacing.value !== value){
this.uniforms.spacing.value = value;
- //this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "useClipBox", {
- get: function(){
+
+
+ get useClipBox(){
return this._useClipBox;
- },
- set: function(value){
+ }
+
+ set useClipBox(value){
if(this._useClipBox !== value){
this._useClipBox = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "weighted", {
- get: function(){
+
+ get weighted(){
return this._weighted;
- },
- set: function(value){
+ }
+
+ set weighted(value){
if(this._weighted !== value){
this._weighted = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "fov", {
- get: function(){
+
+ get fov(){
return this.uniforms.fov.value;
- },
- set: function(value){
+ }
+
+ set fov(value){
if(this.uniforms.fov.value !== value){
this.uniforms.fov.value = value;
//this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "screenWidth", {
- get: function(){
+ get screenWidth(){
return this.uniforms.screenWidth.value;
- },
- set: function(value){
+ }
+
+ set screenWidth(value){
if(this.uniforms.screenWidth.value !== value){
this.uniforms.screenWidth.value = value;
//this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "screenHeight", {
- get: function(){
+
+ get screenHeight(){
return this.uniforms.screenHeight.value;
- },
- set: function(value){
+ }
+
+ set screenHeight(value){
if(this.uniforms.screenHeight.value !== value){
this.uniforms.screenHeight.value = value;
//this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "near", {
- get: function(){
+
+ get near(){
return this.uniforms.near.value;
- },
- set: function(value){
+ }
+
+ set near(value){
if(this.uniforms.near.value !== value){
this.uniforms.near.value = value;
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "far", {
- get: function(){
+
+ get far(){
return this.uniforms.far.value;
- },
- set: function(value){
+ }
+
+ set far(value){
if(this.uniforms.far.value !== value){
this.uniforms.far.value = value;
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "opacity", {
- get: function(){
+
+ get opacity(){
return this.uniforms.opacity.value;
- },
- set: function(value){
- if(this.uniforms.opacity){
+ }
+
+ set opacity(value){
+ if(this.uniforms && this.uniforms.opacity){
if(this.uniforms.opacity.value !== value){
this.uniforms.opacity.value = value;
this.updateShaderSource();
}
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "pointColorType", {
- get: function(){
+
+ get pointColorType(){
return this._pointColorType;
- },
- set: function(value){
+ }
+
+ set pointColorType(value){
if(this._pointColorType !== value){
this._pointColorType = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "depthMap", {
- get: function(){
+
+ get depthMap(){
return this._depthMap;
- },
- set: function(value){
+ }
+
+ set depthMap(value){
if(this._depthMap !== value){
this._depthMap = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "pointSizeType", {
- get: function(){
+
+ get pointSizeType(){
return this._pointSizeType;
- },
- set: function(value){
+ }
+
+ set pointSizeType(value){
if(this._pointSizeType !== value){
this._pointSizeType = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "clipMode", {
- get: function(){
+
+ get clipMode(){
return this._clipMode;
- },
- set: function(value){
+ }
+
+ set clipMode(value){
if(this._clipMode !== value){
this._clipMode = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "interpolate", {
- get: function(){
+
+ get interpolate(){
return this._interpolate;
- },
- set: function(value){
+ }
+
+ set interpolate(value){
if(this._interpolate !== value){
this._interpolate = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "useEDL", {
- get: function(){
+
+ get useEDL(){
return this._useEDL;
- },
- set: function(value){
+ }
+
+ set useEDL(value){
if(this._useEDL !== value){
this._useEDL = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "color", {
- get: function(){
+
+ get color(){
return this.uniforms.uColor.value;
- },
- set: function(value){
+ }
+
+ set color(value){
if(this.uniforms.uColor.value !== value){
this.uniforms.uColor.value.copy(value);
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "pointShape", {
- get: function(){
+
+ get pointShape(){
return this._pointShape;
- },
- set: function(value){
+ }
+
+ set pointShape(value){
if(this._pointShape !== value){
this._pointShape = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "treeType", {
- get: function(){
+
+ get treeType(){
return this._treeType;
- },
- set: function(value){
+ }
+
+ set treeType(value){
if(this._treeType !== value){
this._treeType = value;
this.updateShaderSource();
}
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "bbSize", {
- get: function(){
+
+ get bbSize(){
return this.uniforms.bbSize.value;
- },
- set: function(value){
+ }
+
+ set bbSize(value){
this.uniforms.bbSize.value = value;
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "size", {
- get: function(){
+
+ get size(){
return this.uniforms.size.value;
- },
- set: function(value){
+ }
+
+ set size(value){
this.uniforms.size.value = value;
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "heightMin", {
- get: function(){
+
+ get heightMin(){
return this.uniforms.heightMin.value;
- },
- set: function(value){
+ }
+
+ set heightMin(value){
this.uniforms.heightMin.value = value;
}
-});
-Object.defineProperty(Potree.PointCloudMaterial.prototype, "heightMax", {
- get: function(){
+
+ get heightMax(){
return this.uniforms.heightMax.value;
- },
- set: function(value){
+ }
+
+ set heightMax(value){
this.uniforms.heightMax.value = value;
}
-});
-/**
- * Generates a look-up texture for gradient values (height, intensity, ...)
- *
- */
-Potree.PointCloudMaterial.generateGradientTexture = function(gradient) {
- var size = 64;
+ static generateGradientTexture(gradient){
+ let size = 64;
- // create canvas
- let canvas = document.createElement( 'canvas' );
- canvas.width = size;
- canvas.height = size;
+ // create canvas
+ let canvas = document.createElement( 'canvas' );
+ canvas.width = size;
+ canvas.height = size;
- // get context
- var context = canvas.getContext( '2d' );
+ // get context
+ let context = canvas.getContext( '2d' );
- // draw gradient
- context.rect( 0, 0, size, size );
- var ctxGradient = context.createLinearGradient( 0, 0, size, size );
-
- for(var i = 0;i < gradient.length; i++){
- var step = gradient[i];
+ // draw gradient
+ context.rect( 0, 0, size, size );
+ let ctxGradient = context.createLinearGradient( 0, 0, size, size );
- ctxGradient.addColorStop(step[0], "#" + step[1].getHexString());
- }
-
- context.fillStyle = ctxGradient;
- context.fill();
-
- var texture = new THREE.Texture( canvas );
- texture.needsUpdate = true;
- //textureImage = texture.image;
+ for(let i = 0;i < gradient.length; i++){
+ let step = gradient[i];
+
+ ctxGradient.addColorStop(step[0], "#" + step[1].getHexString());
+ }
+
+ context.fillStyle = ctxGradient;
+ context.fill();
+
+ let texture = new THREE.Texture( canvas );
+ texture.needsUpdate = true;
+ //textureImage = texture.image;
- return texture;
-};
-
-/**
- * Generates a look up texture for classification colors
- *
- */
-Potree.PointCloudMaterial.generateClassificationTexture = function(classification){
- var width = 256;
- var height = 256;
- var size = width*height;
-
- var data = new Uint8Array(4*size);
-
- for(var x = 0; x < width; x++){
- for(var y = 0; y < height; y++){
- //var u = 2 * (x / width) - 1;
- //var v = 2 * (y / height) - 1;
-
- var i = x + width*y;
-
- var color;
- if(classification[x]){
- color = classification[x];
- }else if(classification[x % 32]){
- color = classification[x % 32];
- }else{
- color = classification.DEFAULT;
- }
-
-
- data[4*i+0] = 255 * color.x;
- data[4*i+1] = 255 * color.y;
- data[4*i+2] = 255 * color.z;
- data[4*i+3] = 255 * color.w;
- }
+ return texture;
}
- var texture = new THREE.DataTexture(data, width, height, THREE.RGBAFormat);
- texture.magFilter = THREE.NearestFilter;
- texture.needsUpdate = true;
-
- return texture;
-};
\ No newline at end of file
+ static generateClassificationTexture(classification){
+ let width = 256;
+ let height = 256;
+ let size = width*height;
+
+ let data = new Uint8Array(4*size);
+
+ for(let x = 0; x < width; x++){
+ for(let y = 0; y < height; y++){
+
+ let i = x + width*y;
+
+ let color;
+ if(classification[x]){
+ color = classification[x];
+ }else if(classification[x % 32]){
+ color = classification[x % 32];
+ }else{
+ color = classification.DEFAULT;
+ }
+
+
+ data[4*i+0] = 255 * color.x;
+ data[4*i+1] = 255 * color.y;
+ data[4*i+2] = 255 * color.z;
+ data[4*i+3] = 255 * color.w;
+ }
+ }
+
+ let texture = new THREE.DataTexture(data, width, height, THREE.RGBAFormat);
+ texture.magFilter = THREE.NearestFilter;
+ texture.needsUpdate = true;
+
+ return texture;
+ }
+};
diff --git a/src/materials/shaders/pointcloud.vs b/src/materials/shaders/pointcloud.vs
index f7856c28..bc6f2d41 100644
--- a/src/materials/shaders/pointcloud.vs
+++ b/src/materials/shaders/pointcloud.vs
@@ -39,8 +39,6 @@ uniform float far;
uniform float heightMin;
uniform float heightMax;
-uniform float intensityMin;
-uniform float intensityMax;
uniform float size; // pixel size factor
uniform float minSize; // minimum pixel size
uniform float maxSize; // maximum pixel size
diff --git a/src/navigation/InputHandler.js b/src/navigation/InputHandler.js
index 13883a49..e9ca2ec1 100644
--- a/src/navigation/InputHandler.js
+++ b/src/navigation/InputHandler.js
@@ -184,7 +184,7 @@ Potree.InputHandler = class InputHandler extends THREE.EventDispatcher{
this.pressedKeys[e.keyCode] = true;
- e.preventDefault();
+ //e.preventDefault();
}
onKeyUp(e){
diff --git a/src/viewer/potree.css b/src/viewer/potree.css
index 08e0519f..12bcc5be 100644
--- a/src/viewer/potree.css
+++ b/src/viewer/potree.css
@@ -257,6 +257,9 @@ canvas {
body{
margin: 0;
padding: 0;
+ position: absolute;
+ width: 100%;
+ height: 100%;
}
.axis {
@@ -265,17 +268,21 @@ body{
}
.axis path{
- fill: none;
- stroke: var(--font-color);
- shape-rendering: crispEdges;
- opacity: 0.7;
+ fill: rgba(255, 255, 255, 0.5);
+ stroke: var(--font-color);
+ shape-rendering: crispEdges;
+ opacity: 0.7;
}
.axis line {
- fill: none;
- stroke: var(--font-color);
- shape-rendering: crispEdges;
- opacity: 0.1;
+ fill: rgba(255, 255, 255, 0.5);
+ stroke: var(--font-color);
+ shape-rendering: crispEdges;
+ opacity: 0.1;
+}
+
+.tick text{
+ font-size: 12px;
}
.measurement_item{
@@ -436,12 +443,8 @@ body{
width: 100% !important;
}
-.pv-menu-list .ui-selectmenu-button span.ui-selectmenu-text{
- line-height: 0.8em;
-}
-
-.ui-selectmenu-text{
- background-color: white;
+.ui-widget{
+ box-sizing:border-box
}
.panel-body > li > .ui-slider{
@@ -702,3 +705,8 @@ body{
bottom: -5px;
opacity: 1.0;
}
+
+
+
+
+
diff --git a/src/viewer/profile.html b/src/viewer/profile.html
index 6737fd29..50e5bf35 100644
--- a/src/viewer/profile.html
+++ b/src/viewer/profile.html
@@ -1,9 +1,15 @@
-
+
-
+
@@ -34,7 +40,7 @@
width: 100%;
flex-grow: 1;
position: relative; height: 100%;
- box-sizing: border-box;">
+ box-sizing: border-box; user-select: none">
+
+
+ position: asdsadf asdf
+ rgb: 123 423 123
+
diff --git a/src/viewer/profile.js b/src/viewer/profile.js
index 5b033958..acb4cfc7 100644
--- a/src/viewer/profile.js
+++ b/src/viewer/profile.js
@@ -1,62 +1,513 @@
+Potree.ProfilePointStore = class ProfilePointStore{
+
+ constructor(profile){
+ this.profile = profile;
+ this.boundingBox = new THREE.Box3();
+ this.projectedBoundingBox = new THREE.Box3();
+ this.maxPoints = 50*1000;
+ this.numPoints = 0;
+
+ this.buffers = {
+ position: new Float32Array(3 * this.maxPoints),
+ color: new Uint8Array(3 * this.maxPoints),
+ intensity: new Uint16Array(this.maxPoints),
+ classification: new Uint8Array(this.maxPoints),
+ };
+
+ this.segments = [];
+ for(let i = 0; i < profile.points.length - 1; i++){
+ let start = profile.points[i + 0];
+ let end = profile.points[i + 1];
+
+ let startGround = new THREE.Vector3(start.x, start.y, 0);
+ let endGround = new THREE.Vector3(end.x, end.y, 0);
+
+ let center = new THREE.Vector3().addVectors(endGround, startGround).multiplyScalar(0.5);
+ let length = startGround.distanceTo(endGround);
+
+ let segment = {
+ start: start,
+ end: end,
+ points: {},
+ length: length,
+ numPoints: 0
+ };
+
+ this.segments.push(segment);
+ }
+ }
+
+ onProgress(progress){
+
+ if(this.segments.length !== progress.segments.length){
+ return;
+ }
+
+ for(let i = 0; i < progress.segments.length; i++){
+ let sourceSegment = progress.segments[i];
+ let targetSegment = this.segments[i];
+
+ for(let attribute of Object.keys(sourceSegment.points)){
+ if(targetSegment.points[attribute] === undefined){
+ targetSegment.points[attribute] = new Array(targetSegment.numPoints).fill(0);
+ }
+
+ targetSegment.points[attribute] = targetSegment.points[attribute]
+ .concat(sourceSegment.points[attribute]);
+
+ if(attribute === "position"){
+ for(let j = 0; j < sourceSegment.numPoints; j++){
+
+ let x = sourceSegment.points.mileage[j];
+ let y = sourceSegment.points.position[j].z;
+ let z = 0;
+
+ let offset = 3 * (this.numPoints + j);
+
+ this.buffers.position[offset + 0] = x;
+ this.buffers.position[offset + 1] = y;
+ this.buffers.position[offset + 2] = z;
+ }
+ }else if(attribute === "color"){
+ for(let j = 0; j < sourceSegment.numPoints; j++){
+
+ let r = sourceSegment.points.color[j][0];
+ let g = sourceSegment.points.color[j][1];
+ let b = sourceSegment.points.color[j][2];
+
+ let offset = 3 * (this.numPoints + j);
+
+ this.buffers.color[offset + 0] = r;
+ this.buffers.color[offset + 1] = g;
+ this.buffers.color[offset + 2] = b;
+ }
+ }else if(attribute === "intensity"){
+ for(let j = 0; j < sourceSegment.numPoints; j++){
+ this.buffers.intensity[this.numPoints + j] = sourceSegment.points.intensity[j];
+ }
+ }else if(attribute === "classification"){
+ for(let j = 0; j < sourceSegment.numPoints; j++){
+ this.buffers.classification[this.numPoints + j] = sourceSegment.points.classification[j];
+ }
+ }
+
+ }
+
+ targetSegment.numPoints += sourceSegment.numPoints;
+ this.numPoints += sourceSegment.numPoints;
+ }
+
+ }
+
+ selectPoint(mileage, elevation, radius){
+
+ let closest = {
+ distance: Infinity,
+ segment: null,
+ index: null
+ };
+
+ for(let segment of this.segments){
+ for(let i = 0; i < segment.numPoints; i++){
+
+ let m = segment.points.mileage[i] - mileage;
+ let e = segment.points.position[i].z - elevation;
+
+ let r = Math.sqrt(m * m + e * e);
+
+ if(r < radius && r < closest.distance){
+ closest = {
+ distance: r,
+ segment: segment,
+ index: i
+ };
+ }
+ }
+ }
+
+ if(closest.distance < Infinity){
+ let point = {};
+
+ let attributes = Object.keys(closest.segment.points);
+ for(let attribute of attributes){
+ point[attribute] = closest.segment.points[attribute][closest.index];
+ }
+
+ return point;
+ }else{
+ return null;
+ }
+ }
+
+
+}
+
Potree.Viewer.Profile = class ProfileWindow{
- constructor(viewer, element){
+ constructor(viewer){
this.viewer = viewer;
this.enabled = true;
- this.element = element;
this.currentProfile = null;
this.requests = [];
- this.pointsProcessed = 0;
- this.margin = {top: 0, right: 0, bottom: 20, left: 40};
this.maximized = false;
this.threshold = 20*1000;
+ this.autoFit = true;
+ this.numPoints = 0;
+ this.mouse = new THREE.Vector2();
+ this.points = null;
+ this.selectedPoint = null;
+ this.pointColorType = Potree.PointColorType.RGB;
+
+ this.elRoot = $("#profile_window");
+
+ this.renderArea = this.elRoot.find("#profileCanvasContainer");
+
+ { // THREE.JS
+ this.renderer = new THREE.WebGLRenderer({alpha: true, premultipliedAlpha: false});
+ this.renderer.setClearColor( 0x000000, 0 );
+ this.renderer.setSize(10, 10);
+ this.renderer.autoClear = true;
+ this.renderArea.append($(this.renderer.domElement));
+ this.renderer.domElement.tabIndex = "2222";
+ this.renderer.context.getExtension("EXT_frag_depth");
+ $(this.renderer.domElement).css("width", "100%");
+ $(this.renderer.domElement).css("height", "100%");
+
+ this.camera = new THREE.OrthographicCamera(-10, 10, 10, -10, -1000, 1000);
+
+ this.scene = new THREE.Scene();
+
+ this.maxPoints = 50*1000;
+ this.geometry = new THREE.BufferGeometry();
+ this.buffers = {
+ position: new Float32Array(3 * this.maxPoints),
+ color: new Uint8Array(3 * this.maxPoints),
+ intensity: new Uint16Array(this.maxPoints),
+ classification: new Uint8Array(this.maxPoints),
+ returnNumber: new Uint8Array(this.maxPoints),
+ numberOfReturns: new Uint8Array(this.maxPoints),
+ pointSourceID: new Uint16Array(this.maxPoints)
+ };
+
+ this.geometry.addAttribute("position", new THREE.BufferAttribute(this.buffers.position, 3));
+ this.geometry.addAttribute("color", new THREE.BufferAttribute(this.buffers.color, 3, true));
+ this.geometry.addAttribute("intensity", new THREE.BufferAttribute(this.buffers.intensity, 1, false));
+ this.geometry.addAttribute("classification", new THREE.BufferAttribute(this.buffers.classification, 1, false));
+ this.geometry.addAttribute("returnNumber", new THREE.BufferAttribute(this.buffers.returnNumber, 1, false));
+ this.geometry.addAttribute("numberOfReturns", new THREE.BufferAttribute(this.buffers.numberOfReturns, 1, false));
+ this.geometry.addAttribute("pointSourceID", new THREE.BufferAttribute(this.buffers.pointSourceID, 1, false));
+
+ this.geometry.setDrawRange(0, 100);
+ this.material = new Potree.PointCloudMaterial({size: 2.0});
+ this.material.pointSizeType = Potree.PointSizeType.FIXED;
+ this.tPoints = new THREE.Points(this.geometry, this.material);
+ this.scene.add(this.tPoints);
+
+
+ let sg = new THREE.SphereGeometry(1, 16, 16);
+ let sm = new THREE.MeshNormalMaterial();
+ this.pickSphere = new THREE.Mesh(sg, sm);
+ this.pickSphere.visible = false;
+ this.scene.add(this.pickSphere);
+ }
+
+ { // SVG
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
+ let marginLeft = this.renderArea[0].offsetLeft;
+
+ this.svg = d3.select("svg#profileSVG");
+ this.svg.selectAll("*").remove();
+
+ this.scaleX = d3.scale.linear()
+ .domain([this.camera.left + this.camera.position.x, this.camera.right + this.camera.position.x])
+ .range([0, width]);
+ this.scaleY = d3.scale.linear()
+ .domain([this.camera.bottom + this.camera.position.y, this.camera.top + this.camera.position.y])
+ .range([height, 0]);
+
+ this.xAxis = d3.svg.axis()
+ .scale(this.scaleX)
+ .orient("bottom")
+ .innerTickSize(-height)
+ .outerTickSize(1)
+ .tickPadding(10)
+ .ticks(width / 50);
+
+ this.yAxis = d3.svg.axis()
+ .scale(this.scaleY)
+ .orient("left")
+ .innerTickSize(-width)
+ .outerTickSize(1)
+ .tickPadding(10)
+ .ticks(height / 20);
+
+ this.svg.append("g")
+ .attr("class", "x axis")
+ .attr("transform", `translate(${marginLeft}, ${height})`)
+ .call(this.xAxis);
+
+ this.svg.append("g")
+ .attr("class", "y axis")
+ .attr("transform", `translate(${marginLeft}, 0)`)
+ .call(this.yAxis);
+ }
+
+ this.min = new THREE.Vector3(0, 0, 0);
+ this.max = new THREE.Vector3(0, 0, 0);
+ this.size = new THREE.Vector3(0, 0, 0);
+ this.center = new THREE.Vector3(0, 0, 0);
+ this.scale = new THREE.Vector3(1, 1, 1);
+
+ this.mouseIsDown = false;
+
+ $(window).resize( () => {
+ this.render();
+ });
+
+ this.renderArea.mousedown(e => {
+ this.mouseIsDown = true;
+ });
+
+ this.renderArea.mouseup(e => {
+ this.mouseIsDown = false;
+ });
+
+ this.renderArea.mousemove( e => {
+ if(this.points === null || this.points.numPoints === 0){
+ return;
+ }
+
+ let rect = this.renderArea[0].getBoundingClientRect();
+ let x = e.clientX - rect.left;
+ let y = e.clientY - rect.top;
+
+ let newMouse = new THREE.Vector2(x, y);
+
+ if(this.mouseIsDown){
+ // DRAG
+ let cPos = this.toCamSpace(new THREE.Vector3(this.mouse.x, this.mouse.y, 0));
+ let ncPos = this.toCamSpace(new THREE.Vector3(newMouse.x, newMouse.y, 0));
+
+ let diff = new THREE.Vector3().subVectors(ncPos, cPos);
+ this.camera.position.sub(diff);
+ this.render();
+ }else if(this.points){
+ // FIND HOVERED POINT
+ let pixelRadius = 10;
+ let ncPos = this.toCamSpace(new THREE.Vector3(newMouse.x, newMouse.y, 0));
+ let ncPosBorder = this.toCamSpace(new THREE.Vector3(newMouse.x + pixelRadius, newMouse.y, 0));
+ let mileage = ncPos.x;
+ let elevation = ncPos.y;
+ let radius = Math.abs(ncPosBorder.x - ncPos.x);
+ let point = this.points.selectPoint(mileage, elevation, radius);
+
+ if(point){
+ this.elRoot.find("#profileSelectionProperties").fadeIn(200);
+ this.pickSphere.visible = true;
+ this.pickSphere.scale.set(0.5 * radius, 0.5 * radius, 0.5 * radius);
+ this.pickSphere.position.set(point.mileage, point.position.z, 0);
+
+ let info = this.elRoot.find("#profileSelectionProperties");
+ let html = "
";
+ for(let attribute of Object.keys(point)){
+ let value = point[attribute];
+ if(attribute === "position"){
+ let values = value.toArray().map(v => Potree.utils.addCommas(v.toFixed(3)));
+ html += `
+
+ | x |
+ ${values[0]} |
+
+
+ | y |
+ ${values[1]} |
+
+
+ | z |
+ ${values[2]} |
+
`;
+ }else if(attribute === "color"){
+ html += `
+
+ | ${attribute} |
+ ${value.join(", ")} |
+
`;
+ }else if(attribute === "normal"){
+ continue;
+ }else if(attribute === "mileage"){
+ html += `
+
+ | ${attribute} |
+ ${value.toFixed(3)} |
+
`;
+ }else{
+ html += `
+
+ | ${attribute} |
+ ${value} |
+
`;
+ }
+
+ }
+ html += "
"
+ info.html(html);
+
+ this.selectedPoint = point;
+ }else{
+ //this.pickSphere.visible = false;
+ //this.selectedPoint = null;
+ }
+ this.render();
+
+
+ }
+
+ this.mouse.copy(newMouse);
+ });
+
+ let onWheel = e => {
+ this.autoFit = false;
+ let delta = 0;
+ if( e.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9
+ delta = e.wheelDelta;
+ } else if ( e.detail !== undefined ) { // Firefox
+ delta = -e.detail;
+ }
+
+ let ndelta = Math.sign(delta);
+
+ let sPos = new THREE.Vector3(this.mouse.x, this.mouse.y, 0);
+ let cPos = this.toCamSpace(sPos);
+
+ if(ndelta > 0){
+ // + 10%
+ this.scale.multiplyScalar(1.1);
+ }else{
+ // - 10%
+ this.scale.multiplyScalar(100/110);
+ }
+
+ this.scale.max(new THREE.Vector3(0.5, 0.5, 0.5));
+ this.scale.min(new THREE.Vector3(100, 100, 100));
+
+ let ncPos = this.toCamSpace(sPos);
+
+ let diff = new THREE.Vector3().subVectors(ncPos, cPos);
+ this.camera.position.sub(diff);
+
+ this.render();
+ };
+ $(this.renderArea)[0].addEventListener("mousewheel", onWheel, false );
+ $(this.renderArea)[0].addEventListener("DOMMouseScroll", onWheel, false ); // Firefox
+
this.scheduledDraw = null;
- $('#closeProfileContainer').click(() => {
- this.hide();
- this.enabled = false;
- });
-
- $('#profile_toggle_size_button').click(() => {
- this.maximized = !this.maximized;
-
- if(this.maximized){
- $('#profile_window').css("height", "100%");
- }else{
- $('#profile_window').css("height", "30%");
- }
- });
-
- //this.drawOnChange = (event) => {
- // this.redraw();
- //};
-
this.redraw = () => {
if(this.currentProfile){
this.draw(this.currentProfile);
}
};
- viewer.addEventListener("height_range_changed", this.redraw);
+ $('#closeProfileContainer').click(() => {
+ this.hide();
+ this.enabled = false;
+ });
+ }
+
+ toCamSpace(coord){
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
- let width = document.getElementById('profile_window').clientWidth;
- let height = document.getElementById('profile_window').clientHeight;
- let resizeLoop = () => {
- requestAnimationFrame(resizeLoop);
+ let cam = new THREE.Vector3(
+ coord.x - width / 2,
+ -coord.y + height / 2,
+ 0);
+
+ cam.divide(this.scale);
+ cam.add(this.camera.position);
+
+ return cam;
+ }
+
+ toScreenSpace(coord){
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
+
+ let v = new THREE.Vector3().subVectors(coord, this.camera.position);
+ v.multiply(this.scale);
+
+ let screen = new THREE.Vector3(
+ width / 2 + v.x,
+ height / 2 - v.y,
+ 0);
+
+ return screen;
+ }
+
+ render(){
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
+
+ { // THREEJS
+
+ let left = (-width / 2) / this.scale.x;
+ let right = (+width / 2) / this.scale.x;
+ let top = (+height / 2) / this.scale.y;
+ let bottom = (-height / 2) / this.scale.y;
+
+ this.camera.left = left;
+ this.camera.right = right;
+ this.camera.top = top;
+ this.camera.bottom = bottom;
+ this.camera.updateProjectionMatrix();
- let newWidth = document.getElementById('profile_window').clientWidth;
- let newHeight = document.getElementById('profile_window').clientHeight;
-
- if(newWidth !== width || newHeight !== height){
- setTimeout(this.redraw, 50, {profile: this.currentProfile});
- }
-
- width = newWidth;
- height = newHeight;
- };
- requestAnimationFrame(resizeLoop);
+ let radius =
+ this.toCamSpace(new THREE.Vector3(0, 0, 0)).distanceTo(
+ this.toCamSpace(new THREE.Vector3(5, 0, 0)));
+ this.pickSphere.scale.set(radius, radius, radius);
+ this.pickSphere.position.z = this.camera.far - radius;
+
+ this.material.pointColorType = this.viewer.pointColorType;
+ this.material.uniforms.intensityRange.value = this.viewer.getIntensityRange();
+ this.material.heightMin = this.viewer.getHeightRange().min;
+ this.material.heightMax = this.viewer.getHeightRange().max;
+
+ this.renderer.setSize(width, height);
+
+ this.renderer.render(this.scene, this.camera);
+ }
+
+ { // SVG SCALES
+ let marginLeft = this.renderArea[0].offsetLeft;
+
+ this.scaleX.domain([this.camera.left + this.camera.position.x, this.camera.right + this.camera.position.x])
+ .range([0, width]);
+ this.scaleY.domain([this.camera.bottom + this.camera.position.y, this.camera.top + this.camera.position.y])
+ .range([height, 0]);
+
+ this.xAxis.scale(this.scaleX)
+ .orient("bottom")
+ .innerTickSize(-height)
+ .outerTickSize(1)
+ .tickPadding(10)
+ .ticks(width / 50);
+ this.yAxis.scale(this.scaleY)
+ .orient("left")
+ .innerTickSize(-width)
+ .outerTickSize(1)
+ .tickPadding(10)
+ .ticks(height / 20);
+
+ d3.select(".x,axis")
+ .attr("transform", `translate(${marginLeft}, ${height})`)
+ .call(this.xAxis);
+ d3.select(".y,axis")
+ .attr("transform", `translate(${marginLeft}, 0)`)
+ .call(this.yAxis);
+ }
}
show(){
@@ -76,215 +527,147 @@ Potree.Viewer.Profile = class ProfileWindow{
this.requests = [];
};
- preparePoints(profileProgress){
+ handleNewPoints(profileProgress){
+ this.points.onProgress(profileProgress);
+
+ let prepared = this.preparePoints(profileProgress);
+
+ if(prepared.numPoints === 0){
+ return;
+ }
+
+ if(this.numPoints === 0){
+ this.min.fromArray(prepared.buffers.position, 3);
+ this.max.fromArray(prepared.buffers.position, 3);
+ }
+
+ for(let i = 0; i < prepared.numPoints; i++){
+ let pos = new THREE.Vector3().fromArray(
+ prepared.buffers.position.slice(3*i, 3*i+3));
+ this.min.min(pos);
+ this.max.max(pos);
+ }
+ let newSize = new THREE.Vector3().subVectors(this.max, this.min);
+ this.size.copy(newSize);
+
+ let newNumPoints = this.numPoints + prepared.numPoints;
+
+ let position = this.buffers.position;
+ let color = this.buffers.color;
+ let intensity = this.buffers.intensity;
+ let classification = this.buffers.classification;
+
+ position.set(this.points.buffers.position.slice(3 * this.numPoints, 3 * newNumPoints), 3 * this.numPoints);
+ color.set(this.points.buffers.color.slice(3 * this.numPoints, 3 * newNumPoints), 3 * this.numPoints);
+ intensity.set(this.points.buffers.intensity.slice(this.numPoints, newNumPoints), this.numPoints);
+ classification.set(this.points.buffers.classification.slice(this.numPoints, newNumPoints), this.numPoints);
+
+
+ for(let key of Object.keys(this.geometry.attributes)){
+ this.geometry.attributes[key].needsUpdate = true;
+ }
+
+
+ this.geometry.setDrawRange(0, newNumPoints);
+
+ this.numPoints = newNumPoints;
+
+ this.center = new THREE.Vector3().addVectors(this.min, this.max)
+ .multiplyScalar(0.5);
+
+ if(this.geometry.boundingSphere){
+ this.geometry.boundingSphere.center.copy(this.center);
+ this.geometry.boundingSphere.radius = this.min.distanceTo(this.max) / 2;
+ }
+
+ if(this.autoFit){ // SCALE
+ let width = this.renderArea[0].clientWidth;
+ let height = this.renderArea[0].clientHeight;
+
+ let sx = width / this.size.x;
+ let sy = height / this.size.y;
+ let scale = Math.min(sx, sy);
+
+ this.scale.set(scale, scale, 1);
+ this.camera.position.copy(this.center);
+ }
+
+ this.firstUpdateFollows = false;
+
+ this.elRoot.find("#profile_num_points").html(
+ Potree.utils.addCommas(this.numPoints.toFixed(0)));
+ }
+ preparePoints(profileProgress){
+
let segments = profileProgress.segments;
if (segments.length === 0){
return false;
}
- let data = [];
+ let numPoints = profileProgress.size();
+
+ let position = new Float32Array(3 * numPoints);
+ let color = new Uint8Array(3 * numPoints);
+ let intensity = new Uint16Array(numPoints);
+ let classification = new Uint8Array(numPoints);
+
let distance = 0;
let totalDistance = 0;
let min = new THREE.Vector3(Math.max());
let max = new THREE.Vector3(0);
- // Get the same color map as Three
- let hr = this.viewer.getHeightRange();
-
- let heightRange = hr.max - hr.min;
- let colorRange = [];
- let colorDomain = [];
-
- // Read the altitude gradient used in 3D scene
- let gradient = viewer.scene.pointclouds[0].material.gradient;
- for (let c = 0; c < gradient.length; c++){
- colorDomain.push(hr.min + heightRange * gradient[c][0]);
- colorRange.push('#' + gradient[c][1].getHexString());
- }
-
- // Altitude color map scale
- let colorRamp = d3.scale.linear()
- .domain(colorDomain)
- .range(colorRange)
- .clamp(true);
-
// Iterate the profile's segments
+ let i = 0;
for(let segment of segments){
let sv = new THREE.Vector3().subVectors(segment.end, segment.start).setZ(0)
- let segmentLength = sv.length();
+ let segmentDir = sv.clone().normalize();
let points = segment.points;
// Iterate the segments' points
- for(let j = 0; j < points.numPoints; j++){
+ for(let j = 0; j < segment.numPoints; j++){
let p = points.position[j];
- let pl = new THREE.Vector3().subVectors(p, segment.start).setZ(0);
+
+ //let svp = new THREE.Vector3().subVectors(p, segment.start);
+ //let distance = segmentDir.dot(svp);
min.min(p);
max.max(p);
- let distance = totalDistance + pl.length();
+ //position[3*i + 0] = distance + totalDistance;
+ position[3*i + 0] = points.mileage[j];
+ position[3*i + 1] = p.z;
+ position[3*i + 2] = 0;
- let d = {
- distance: distance,
- x: p.x,
- y: p.y,
- z: p.z,
- altitude: p.z,
- heightColor: colorRamp(p.z),
- color: points.color ? points.color[j] : [0, 0, 0],
- intensity: points.intensity ? points.intensity[j] : 0,
- classification: points.classification ? points.classification[j] : 0,
- returnNumber: points.returnNumber ? points.returnNumber[j] : 0,
- numberOfReturns: points.numberOfReturns ? points.numberOfReturns[j] : 0,
- pointSourceID: points.pointSourceID ? points.pointSourceID[j] : 0,
- };
+ let c = points.color ? points.color[j] : [0, 0, 0];
+ color[3*i + 0] = c[0];
+ color[3*i + 1] = c[1];
+ color[3*i + 2] = c[2];
- data.push(d);
+ intensity[i] = points.intensity ? points.intensity[j] : 0;
+ classification[i] = points.classification ? points.classification[j] : 0;
+
+ i++;
}
- // Increment distance from the profile start point
- totalDistance += segmentLength;
+ totalDistance += segment.length;
}
-
- let output = {
- 'data': data,
- 'minX': min.x,
- 'minY': min.y,
- 'minZ': min.z,
- 'maxX': max.x,
- 'maxY': max.y,
- 'maxZ': max.z
+
+ let result = {
+ numPoints: numPoints,
+ min: min,
+ max: max,
+ buffers: {
+ position: position,
+ color: color,
+ intensity: intensity,
+ classification: classification
+ }
};
- return output;
+ return result;
};
- pointHighlight(coordinates){
-
- let pointSize = 6;
-
- let svg = d3.select("svg#profileSVG");
-
- // Find the hovered point if applicable
- let d = this.points;
- let sx = this.scaleX;
- let sy = this.scaleY;
- let xs = coordinates[0];
- let ys = coordinates[1];
-
- // Fix FF vs Chrome discrepancy
- //if(navigator.userAgent.indexOf("Firefox") == -1 ) {
- // xs = xs - this.margin.left;
- // ys = ys - this.margin.top;
- //}
- let hP = [];
- let tol = pointSize;
-
- for (let i=0; i < d.length; i++){
- if(sx(d[i].distance) < xs + tol && sx(d[i].distance) > xs - tol && sy(d[i].altitude) < ys + tol && sy(d[i].altitude) > ys -tol){
- hP.push(d[i]);
- }
- }
-
- if(hP.length > 0){
- let p = hP[0];
- this.hoveredPoint = hP[0];
- let cx, cy;
- if(navigator.userAgent.indexOf("Firefox") == -1 ) {
- cx = this.scaleX(p.distance) + this.margin.left;
- cy = this.scaleY(p.altitude) + this.margin.top;
- } else {
- cx = this.scaleX(p.distance);
- cy = this.scaleY(p.altitude);
- }
-
- //cx -= pointSize / 2;
- cy -= pointSize / 2;
-
- //let svg = d3.select("svg#profileSVG");
- d3.selectAll("rect").remove();
- let rectangle = svg.append("rect")
- .attr("x", cx)
- .attr("y", cy)
- .attr("id", p.id)
- .attr("width", pointSize)
- .attr("height", pointSize)
- .style("fill", 'yellow');
-
-
- let marker = $("#profile_selection_marker");
- marker.css("display", "initial");
- marker.css("left", cx + "px");
- marker.css("top", cy + "px");
- marker.css("width", pointSize + "px");
- marker.css("height", pointSize + "px");
- marker.css("background-color", "yellow");
-
- //let html = 'x: ' + Math.round(10 * p.x) / 10 + ' y: ' + Math.round(10 * p.y) / 10 + ' z: ' + Math.round( 10 * p.altitude) / 10 + ' - ';
- //html += i18n.t('tools.classification') + ': ' + p.classificationCode + ' - ';
- //html += i18n.t('tools.intensity') + ': ' + p.intensityCode;
-
- let html = 'x: ' + Math.round(10 * p.x) / 10 + ' y: ' + Math.round(10 * p.y) / 10 + ' z: ' + Math.round( 10 * p.altitude) / 10 + ' - ';
- html += "offset: " + p.distance.toFixed(3) + ' - ';
- html += "Classification: " + p.classification + ' - ';
- html += "Intensity: " + p.intensity;
-
- $('#profileInfo').css('color', 'yellow');
- $('#profileInfo').html(html);
-
- } else {
- d3.selectAll("rect").remove();
- $('#profileInfo').html("");
-
- let marker = $("#profile_selection_marker");
- marker.css("display", "none");
- }
- };
-
- strokeColor(d){
- let material = this.viewer.getMaterial();
- if (material === Potree.PointColorType.RGB) {
- let [r, g, b] = d.color.map(e => parseInt(e));
-
- return `rgb( ${r}, ${g}, ${b})`;
- } else if (material === Potree.PointColorType.INTENSITY) {
- let irange = viewer.getIntensityRange();
- let i = parseInt(255 * (d.intensity - irange[0]) / (irange[1] - irange[0]));
-
- return `rgb(${i}, ${i}, ${i})`;
- } else if (material === Potree.PointColorType.CLASSIFICATION) {
- let classif = this.viewer.scene.pointclouds[0].material.classification;
- if (typeof classif[d.classification] != 'undefined'){
- let color = 'rgb(' + classif[d.classification].x * 100 + '%,';
- color += classif[d.classification].y * 100 + '%,';
- color += classif[d.classification].z * 100 + '%)';
- return color;
- } else {
- return 'rgb(255,255,255)';
- }
- } else if (material === Potree.PointColorType.HEIGHT) {
- return d.heightColor;
- } else if (material === Potree.PointColorType.RETURN_NUMBER) {
-
- if(d.numberOfReturns === 1){
- return 'rgb(255, 255, 0)';
- }else{
- if(d.returnNumber === 1){
- return 'rgb(255, 0, 0)';
- }else if(d.returnNumber === d.numberOfReturns){
- return 'rgb(0, 0, 255)';
- }else{
- return 'rgb(0, 255, 0)';
- }
- }
-
- return d.heightColor;
- } else {
- return d.color;
- }
- }
-
draw(profile){
if(!this.enabled){
return;
@@ -302,7 +685,7 @@ Potree.Viewer.Profile = class ProfileWindow{
// 2d profile draws don't need frame-by-frame granularity, it's
// fine to handle a redraw once every 100ms
let executeScheduledDraw = () => {
- this.actuallyDraw(this.scheduledDraw);
+ this.prepareDraw(this.scheduledDraw);
this.scheduledDraw = null;
};
@@ -312,16 +695,12 @@ Potree.Viewer.Profile = class ProfileWindow{
this.scheduledDraw = profile;
}
- actuallyDraw(profile){
-
- if(this.context){
- let containerWidth = this.element.clientWidth;
- let containerHeight = this.element.clientHeight;
-
- let width = containerWidth - (this.margin.left + this.margin.right);
- let height = containerHeight - (this.margin.top + this.margin.bottom);
- this.context.clearRect(0, 0, width, height);
- }
+ prepareDraw(profile){
+ this.autoFit = true;
+ this.numPoints = 0;
+ this.geometry.setDrawRange(0, this.numPoints);
+ this.pickSphere.visible = false;
+ this.elRoot.find("#profileSelectionProperties").hide();
if(this.currentProfile){
this.currentProfile.removeEventListener("marker_moved", this.redraw);
@@ -331,10 +710,15 @@ Potree.Viewer.Profile = class ProfileWindow{
viewer.removeEventListener("material_changed", this.redraw);
viewer.removeEventListener("height_range_changed", this.redraw);
viewer.removeEventListener("intensity_range_changed", this.redraw);
+
+ for(let request of this.requests){
+ request.cancel();
+ }
}
this.currentProfile = profile;
+ this.points = new Potree.ProfilePointStore(this.currentProfile);
{
this.currentProfile.addEventListener("marker_moved", this.redraw);
@@ -345,200 +729,6 @@ Potree.Viewer.Profile = class ProfileWindow{
viewer.addEventListener("height_range_changed", this.redraw);
viewer.addEventListener("intensity_range_changed", this.redraw);
}
-
- if(!this.__drawData){
- this.__drawData = {};
- }
- this.points = [];
- this.rangeX = [Infinity, -Infinity];
- this.rangeY = [Infinity, -Infinity];
-
- this.pointsProcessed = 0;
-
- for(let request of this.requests){
- request.cancel();
- }
- this.requests = [];
-
- let drawPoints = (points, rangeX, rangeY) => {
-
- let mileage = 0;
- for(let i = 0; i < profile.points.length; i++){
- let point = profile.points[i];
-
- if(i > 0){
- let previous = profile.points[i-1];
- let dx = point.x - previous.x;
- let dy = point.y - previous.y;
- let distance = Math.sqrt(dx * dx + dy * dy);
- mileage += distance;
- }
-
- let radius = 4;
-
- let cx = this.scaleX(mileage);
- let cy = this.context.canvas.clientHeight;
-
- this.context.beginPath();
- this.context.arc(cx, cy, radius, 0, 2 * Math.PI, false);
- this.context.fillStyle = '#a22';
- this.context.fill();
- };
-
-
- let pointSize = 2;
- let i = -1, n = points.length, d, cx, cy;
- while (++i < n) {
- d = points[i];
- cx = this.scaleX(d.distance);
- cy = this.scaleY(d.altitude);
- this.context.beginPath();
- this.context.moveTo(cx, cy);
- this.context.fillStyle = this.strokeColor(d);
- this.context.fillRect(cx, cy, pointSize, pointSize);
- }
- };
-
- let projectedBoundingBox = null;
-
- let setupAndDraw = () => {
- let containerWidth = this.element.clientWidth;
- let containerHeight = this.element.clientHeight;
-
- let width = containerWidth - (this.margin.left + this.margin.right);
- let height = containerHeight - (this.margin.top + this.margin.bottom);
-
- this.scaleX = d3.scale.linear();
- this.scaleY = d3.scale.linear();
-
- let domainProfileWidth = this.rangeX[1] - this.rangeX[0];
- let domainProfileHeight = this.rangeY[1] - this.rangeY[0];
- let domainRatio = domainProfileWidth / domainProfileHeight;
- let rangeProfileWidth = width;
- let rangeProfileHeight = height;
- let rangeRatio = rangeProfileWidth / rangeProfileHeight;
-
- if(domainRatio < rangeRatio){
- // canvas scale
- let targetWidth = domainProfileWidth * (rangeProfileHeight / domainProfileHeight);
- this.scaleY.range([height, 0]);
- this.scaleX.range([width / 2 - targetWidth / 2, width / 2 + targetWidth / 2]);
-
- // axis scale
- let domainScale = rangeRatio / domainRatio;
- let domainScaledWidth = domainProfileWidth * domainScale;
- this.axisScaleX = d3.scale.linear()
- .domain([
- domainProfileWidth / 2 - domainScaledWidth / 2 ,
- domainProfileWidth / 2 + domainScaledWidth / 2 ])
- .range([0, width]);
- this.axisScaleY = d3.scale.linear()
- .domain(this.rangeY)
- .range([height, 0]);
- }else{
- // canvas scale
- let targetHeight = domainProfileHeight* (rangeProfileWidth / domainProfileWidth);
- this.scaleX.range([0, width]);
- this.scaleY.range([height / 2 + targetHeight / 2, height / 2 - targetHeight / 2]);
-
- // axis scale
- let domainScale = domainRatio / rangeRatio;
- let domainScaledHeight = domainProfileHeight * domainScale;
- let domainHeightCentroid = (this.rangeY[1] + this.rangeY[0]) / 2;
- this.axisScaleX = d3.scale.linear()
- .domain(this.rangeX)
- .range([0, width]);
- this.axisScaleY = d3.scale.linear()
- .domain([
- domainHeightCentroid - domainScaledHeight / 2 ,
- domainHeightCentroid + domainScaledHeight / 2 ])
- .range([height, 0]);
- }
- this.scaleX.domain(this.rangeX);
- this.scaleY.domain(this.rangeY);
-
-
-
- this.axisZoom = d3.behavior.zoom()
- .x(this.axisScaleX)
- .y(this.axisScaleY)
- .scaleExtent([0,128])
- .size([width, height]);
-
- this.zoom = d3.behavior.zoom()
- .x(this.scaleX)
- .y(this.scaleY)
- .scaleExtent([0,128])
- .size([width, height])
- .on("zoom", () => {
- this.axisZoom.translate(this.zoom.translate());
- this.axisZoom.scale(this.zoom.scale());
-
- let svg = d3.select("svg#profileSVG");
- svg.select(".x.axis").call(xAxis);
- svg.select(".y.axis").call(yAxis);
-
- this.context.clearRect(0, 0, width, height);
- drawPoints(this.points, this.rangeX, this.rangeY);
- });
-
- this.context = d3.select("#profileCanvas")
- .attr("width", width)
- .attr("height", height)
- .call(this.zoom)
- .node().getContext("2d");
-
- d3.select("svg#profileSVG").selectAll("*").remove();
-
- let svg = d3.select("svg#profileSVG")
- .call(this.zoom)
- .attr("width", (width + this.margin.left + this.margin.right).toString())
- .attr("height", (height + this.margin.top + this.margin.bottom).toString())
- .attr("transform", "translate(" + this.margin.left + "," + this.margin.top + ")");
-
- let scope = this;
- d3.select("#profileCanvas").on("mousemove", function(){
- let coord = d3.mouse(this);
- scope.pointHighlight(coord);
- });
-
- // Create x axis
- let xAxis = d3.svg.axis()
- .scale(this.axisScaleX)
- .innerTickSize(-height)
- .outerTickSize(5)
- .orient("bottom")
- .ticks(10, "m");
-
- // Create y axis
- let yAxis = d3.svg.axis()
- .scale(this.axisScaleY)
- .innerTickSize(-width)
- .outerTickSize(5)
- .orient("left")
- .ticks(10, "m");
-
- // Append axis to the chart
- let gx = svg.append("g")
- .attr("class", "x axis")
- .call(xAxis);
-
- svg.append("g")
- .attr("class", "y axis")
- .call(yAxis);
-
- if(navigator.userAgent.indexOf("Firefox") == -1 ) {
- svg.select(".y.axis").attr("transform", "translate("+ (this.margin.left).toString() + "," + this.margin.top.toString() + ")");
- svg.select(".x.axis").attr("transform", "translate(" + this.margin.left.toString() + "," + (height + this.margin.top).toString() + ")");
- } else {
- svg.select(".x.axis").attr("transform", "translate( 0 ," + height.toString() + ")");
- }
-
- drawPoints(this.points, this.rangeX, this.rangeY);
-
- document.getElementById("profile_num_points").innerHTML = Potree.utils.addCommas(this.pointsProcessed) + " ";
- };
-
for(let pointcloud of this.viewer.scene.pointclouds.filter(p => p.visible)){
@@ -548,27 +738,11 @@ Potree.Viewer.Profile = class ProfileWindow{
return;
}
- if(!projectedBoundingBox){
- projectedBoundingBox = event.points.projectedBoundingBox;
- }else{
- projectedBoundingBox.union(event.points.projectedBoundingBox);
- }
+ this.handleNewPoints(event.points);
- let result = this.preparePoints(event.points);
- let points = result.data;
- this.points = this.points.concat(points);
+ this.render();
- let batchRangeX = [d3.min(points, function(d) { return d.distance; }), d3.max(points, function(d) { return d.distance; })];
- let batchRangeY = [d3.min(points, function(d) { return d.altitude; }), d3.max(points, function(d) { return d.altitude; })];
-
- this.rangeX = [ Math.min(this.rangeX[0], batchRangeX[0]), Math.max(this.rangeX[1], batchRangeX[1]) ];
- this.rangeY = [ Math.min(this.rangeY[0], batchRangeY[0]), Math.max(this.rangeY[1], batchRangeY[1]) ];
-
- this.pointsProcessed += result.data.length;
-
- setupAndDraw();
-
- if(this.pointsProcessed > this.threshold){
+ if(this.numPoints > this.threshold){
this.cancel();
}
},
@@ -588,6 +762,7 @@ Potree.Viewer.Profile = class ProfileWindow{
}
}
+
setThreshold(value){
this.threshold = value;
@@ -600,70 +775,80 @@ Potree.Viewer.Profile = class ProfileWindow{
}
let file = "";
- let points = this.points.slice();
- points.sort((a, b) => (a.distance - b.distance));
+ let pointsPerSegment = this.points.segments.map(s => s.points);
+ let points = {};
+ let attributes = Object.keys(pointsPerSegment[0]);
+ for(let attribute of attributes){
+ let arrays = pointsPerSegment.map(p => p[attribute]);
+ points[attribute] = arrays.reduce( (a, v) => a.concat(v));
+ }
{ // header-line
let header = "x, y";
- if(points[0].hasOwnProperty("color")){
+ if(points.hasOwnProperty("color")){
header += ", r, g, b";
}
- if(points[0].hasOwnProperty("intensity")){
+ if(points.hasOwnProperty("intensity")){
header += ", intensity";
}
- if(points[0].hasOwnProperty("classification")){
+ if(points.hasOwnProperty("classification")){
header += ", classification";
}
- if(points[0].hasOwnProperty("numberOfReturns")){
+ if(points.hasOwnProperty("numberOfReturns")){
header += ", numberOfReturns";
}
- if(points[0].hasOwnProperty("pointSourceID")){
+ if(points.hasOwnProperty("pointSourceID")){
header += ", pointSourceID";
}
- if(points[0].hasOwnProperty("returnNumber")){
+ if(points.hasOwnProperty("returnNumber")){
header += ", returnNumber";
}
file += header + "\n";
}
+
+ let numPoints = points.position.length;
// actual data
- for(let point of points){
- let line = point.distance.toFixed(4) + ", ";
- line += point.altitude.toFixed(4) + ", ";
+ for(let i = 0; i < numPoints; i++){
- if(point.hasOwnProperty("color")){
- line += point.color.join(", ");
+ let values = [];
+
+ values.push(points.mileage[i].toFixed(4));
+ values.push(points.position[i].z.toFixed(4));
+
+ if(attributes.includes("color")){
+ values.push(points.color[i].join(", "));
}
- if(point.hasOwnProperty("intensity")){
- line += ", " + point.intensity;
+ if(attributes.includes("intensity")){
+ values.push(points.intensity[i]);
}
- if(point.hasOwnProperty("classification")){
- line += ", " + point.classification;
+ if(attributes.includes("classification")){
+ values.push(points.classification[i]);
}
- if(point.hasOwnProperty("numberOfReturns")){
- line += ", " + point.numberOfReturns;
+ if(attributes.includes("numberOfReturns")){
+ values.push(points.numberOfReturns[i]);
}
- if(point.hasOwnProperty("pointSourceID")){
- line += ", " + point.pointSourceID;
+ if(attributes.includes("pointSourceID")){
+ values.push(points.pointSourceID[i]);
}
- if(point.hasOwnProperty("returnNumber")){
- line += ", " + point.returnNumber;
+ if(attributes.includes("returnNumber")){
+ values.push(points.returnNumber[i]);
}
- line += "\n";
+ let line = values.join(", ") + "\n";
file = file + line;
}
@@ -672,13 +857,24 @@ Potree.Viewer.Profile = class ProfileWindow{
}
getPointsInProfileAsLas(){
- let points = this.points;
+
+ let pointsPerSegment = this.points.segments.map(s => s.points);
+ let points = {};
+ let attributes = Object.keys(pointsPerSegment[0]);
+ for(let attribute of attributes){
+ let arrays = pointsPerSegment.map(p => p[attribute]);
+ points[attribute] = arrays.reduce( (a, v) => a.concat(v));
+ }
+ let numPoints = points.position.length;
+
let boundingBox = new THREE.Box3();
- for(let point of points){
- boundingBox.expandByPoint(point);
+ for(let i = 0; i < numPoints; i++){
+ let position = points.position[i];
+ boundingBox.expandByPoint(position);
}
+
let offset = boundingBox.min.clone();
let diagonal = boundingBox.min.distanceTo(boundingBox.max);
let scale = new THREE.Vector3(0.01, 0.01, 0.01);
@@ -697,10 +893,9 @@ Potree.Viewer.Profile = class ProfileWindow{
}
}
- let buffer = new ArrayBuffer(227 + 28 * points.length);
+ let buffer = new ArrayBuffer(227 + 28 * numPoints);
let view = new DataView(buffer);
let u8View = new Uint8Array(buffer);
- //let u16View = new Uint16Array(buffer);
setString("LASF", 0, buffer);
u8View[24] = 1;
@@ -729,7 +924,7 @@ Potree.Viewer.Profile = class ProfileWindow{
view.setUint16(105, 28, true);
// number of point records 107 4
- view.setUint32(107, points.length, true);
+ view.setUint32(107, numPoints, true);
// number of points by return 111 20
@@ -751,10 +946,16 @@ Potree.Viewer.Profile = class ProfileWindow{
// z offset 171 8
view.setFloat64(171, offset.z, true);
+ let hasIntensity = attributes.includes("intensity");
+ let hasReturnNumber = attributes.includes("returnNumber");
+ let hasClassification = attributes.includes("classification");
+ let hasPointSourceID = attributes.includes("pointSourceID");
+
let boffset = 227;
- for(let i = 0; i < points.length; i++){
- let point = points[i];
- let position = new THREE.Vector3(point.x, point.y, point.z);
+ for(let i = 0; i < numPoints; i++){
+ //let point = points[i];
+ //let position = new THREE.Vector3(point.x, point.y, point.z);
+ let position = points.position[i];
let ux = parseInt((position.x - offset.x) / scale.x);
let uy = parseInt((position.y - offset.y) / scale.y);
@@ -763,21 +964,30 @@ Potree.Viewer.Profile = class ProfileWindow{
view.setUint32(boffset + 0, ux, true);
view.setUint32(boffset + 4, uy, true);
view.setUint32(boffset + 8, uz, true);
+
+ if(hasIntensity){
+ view.setUint16(boffset + 12, (points.intensity[i]), true);
+ }
- view.setUint16(boffset + 12, (point.intensity), true);
- let rt = point.returnNumber;
- rt += (point.numberOfReturns << 3);
- view.setUint8(boffset + 14, rt);
+ if(hasReturnNumber){
+ let rt = points.returnNumber[i];
+ rt += (points.numberOfReturns[i] << 3);
+ view.setUint8(boffset + 14, rt);
+ }
+
+ if(hasClassification){
+ view.setUint8(boffset + 15, points.classification[i]);
+ }
- // classification
- view.setUint8(boffset + 15, point.classification);
// scan angle rank
// user data
// point source id
- view.setUint16(boffset + 18, point.pointSourceID);
- view.setUint16(boffset + 20, (point.color[0] * 255), true);
- view.setUint16(boffset + 22, (point.color[1] * 255), true);
- view.setUint16(boffset + 24, (point.color[2] * 255), true);
+ if(hasPointSourceID){
+ view.setUint16(boffset + 18, points.pointSourceID[i]);
+ }
+ view.setUint16(boffset + 20, (points.color[i][0] * 255), true);
+ view.setUint16(boffset + 22, (points.color[i][1] * 255), true);
+ view.setUint16(boffset + 24, (points.color[i][2] * 255), true);
boffset += 28;
}
diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js
index cadc2b70..86f6fd4f 100644
--- a/src/viewer/viewer.js
+++ b/src/viewer/viewer.js
@@ -1466,14 +1466,22 @@ Potree.Viewer = class PotreeViewer extends THREE.EventDispatcher{
});
let elProfile = $('
').load(new URL(Potree.scriptPath + "/profile.html").href, () => {
- $('#potree_render_area').append(elProfile.children());
- this._2dprofile = new Potree.Viewer.Profile(this, document.getElementById("profile_draw_container"));
+ $(document.body).append(elProfile.children());
+ this._2dprofile = new Potree.Viewer.Profile(this);
+
+ $("#profile_window").draggable({
+ handle: $("#profile_titlebar"),
+ containment: $(document.body)
+ });
+ $("#profile_window").resizable();
if(callback){
$(callback);
}
});
+
+
});