profile clipping

This commit is contained in:
Markus Schuetz 2017-05-17 12:50:57 +02:00
parent 9606ee598e
commit 317ffac5ab
2 changed files with 142 additions and 1 deletions

View File

@ -31,6 +31,46 @@ Potree.Profile = class extends THREE.Object3D{
return sphereMaterial;
};
getSegments(){
let segments = [];
for(let i = 0; i < this.points.length - 1; i++){
let start = this.points[i].clone();
let end = this.points[i+1].clone();
segments.push({start: start, end: end});
}
return segments;
}
getSegmentMatrices(){
let segments = this.getSegments();
let matrices = [];
for(let segment of segments){
let {start, end} = segment;
let box = new THREE.Object3D();
let length = start.clone().setZ(0).distanceTo(end.clone().setZ(0));
box.scale.set(length, 1000000, this.width);
box.up.set(0, 0, 1);
let center = new THREE.Vector3().addVectors(start, end).multiplyScalar(0.5);
let diff = new THREE.Vector3().subVectors(end, start);
let target = new THREE.Vector3(diff.y, -diff.x, 0);
box.position.set(0,0,0);
box.lookAt(target);
box.position.copy(center);
box.updateMatrixWorld();
matrices.push(box.matrixWorld);
}
return matrices;
}
addMarker(point){
this.points.push(point);

View File

@ -1017,6 +1017,12 @@ function initMeasurementDetails(){
<input id="${sliderID}" name="${sliderID}" value="5.06" style="flex-grow: 1; width:100%">
</span>
<br>
<input type="button" value="Prepare Download" id="download_profile_${this.id}"/>
<span id="download_profile_status_${this.id}"></span>
<br>
<input type="button" id="show_2d_profile_${this.id}" value="show 2d profile" style="width: 100%"/>
<!-- ACTIONS -->
@ -1035,6 +1041,16 @@ function initMeasurementDetails(){
//viewer.profileWindow.draw(measurement);
});
{ // download
this.elDownloadButton = this.elContent.find(`#download_profile_${this.id}`);
if(viewer.server){
this.elDownloadButton.click(() => this.download());
}else{
this.elDownloadButton.hide();
}
}
{ // width spinner
let elWidthLabel = this.elContent.find(`#${labelID}`);
let elWidthSlider = this.elContent.find(`#${sliderID}`);
@ -1101,6 +1117,91 @@ function initMeasurementDetails(){
elCoordiantesContainer.append(createCoordinatesTable(this.measurement));
}
download(){
let profile = this.measurement;
let boxes = profile.getSegmentMatrices()
.map(m => m.elements.join(", "))
.join(", ");
let minLOD = 0;
let maxLOD = 100;
let urlIsAbsolute = new RegExp('^(?:[a-z]+:)?//', 'i').test(this.scene.pointclouds[0].pcoGeometry.url);
let pc = "";
if(urlIsAbsolute){
pc = this.scene.pointclouds[0].pcoGeometry.url;
}else{
pc = `${window.location.href}/${viewer.scene.pointclouds[0].pcoGeometry.url}`;
}
let request = `${viewer.server}/start_extract_region_worker?minLOD=${minLOD}&maxLOD=${maxLOD}&box=${boxes}&pointCloud=${pc}`;
console.log(request);
let elMessage = this.elContent.find(`#download_profile_status_${this.id}`);
elMessage.html("sending request...");
let workerID = null;
let start = new Date().getTime();
let checkUntilFinished = () => {
//http://localhost:3000/get_status?workerID=ef7bd824-a32d-4086-9547-09dfdf700c19
if(!workerID){
return;
}
let request = `${viewer.server}/get_status?workerID=${workerID}`;
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == XMLHttpRequest.DONE) {
//alert(xhr.responseText);
let res = JSON.parse(xhr.responseText);
console.log(res);
if(!res.finished){
//elMessage.html(`request status: ${res.status}`);
let end = new Date().getTime();
let duration = (end - start);
let seconds = parseInt(duration / 1000);
elMessage.html(`<br>preparing download... ${seconds}s`);
//checkUntilFinished();
setTimeout(checkUntilFinished, 500);
}else{
elMessage.html(`<br><a href="${viewer.server}/get_las?workerID=${workerID}">Download ready</a>`);
}
}
}
xhr.open('GET', request, true);
xhr.send(null)
};
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == XMLHttpRequest.DONE) {
//alert(xhr.responseText);
let res = JSON.parse(xhr.responseText);
console.log(res);
if(res.status === "OK"){
workerID = res.workerID;
elMessage.html("request is being processed");
checkUntilFinished();
}else if(res.status === "ERROR_POINT_PROCESSED_ESTIMATE_TOO_LARGE"){
elMessage.html("Too many candidate points in selection.");
}else{
elMessage.html(`${res.status}`);
}
}
}
xhr.open('GET', request, true);
xhr.send(null);
}
destroy(){
this.elPanel.remove();
@ -1301,7 +1402,7 @@ function initMeasurementDetails(){
//let box = volume.boundingBox.clone().applyMatrix4(volume.matrixWorld);
let box = volume.matrixWorld.elements.join(", ");
let minLOD = 0;
let maxLOD = 8;
let maxLOD = 100;
let urlIsAbsolute = new RegExp('^(?:[a-z]+:)?//', 'i').test(this.scene.pointclouds[0].pcoGeometry.url);
let pc = "";