improve measurement panel; export whole scene to geojson or DXF

This commit is contained in:
mschuetz 2017-04-21 15:05:43 +02:00
parent e539a04fbc
commit 14c2fcd676
7 changed files with 417 additions and 146 deletions

View File

@ -0,0 +1,12 @@
<html>
<head></head>
<body>
<div style="position: absolute; left: 20%; right: 20%; top: 20%; bottom: 20%">
<iframe src="viewer.html" style="width: 100%; height: 100%"></iframe>
</div>
</body>
</html>

View File

@ -8,109 +8,146 @@
Potree.DXFExporter = class DXFExporter{
static toString(measurement){
let isLine = measurement.showDistances && !measurement.showArea && !measurement.showAngles;
let isPolygon = measurement.showDistances && measurement.showArea && !measurement.showAngles;
static measurementSection(measurement){
if (!isLine && !isPolygon) {
return;
if(measurement.points.length <= 1){
return "";
}
let geomCode = isLine ? 8 : 9;
let dxfBody = '0\n\
SECTION\n\
2\n\
ENTITIES\n\
0\n\
POLYLINE\n\
8\n\
0\n\
62\n\
1\n\
66\n\
1\n\
10\n\
0.0\n\
20\n\
0.0\n\
30\n\
0.0\n\
70\n\
{geomCode}\n'.replace('{geomCode}', geomCode);
// bit code for polygons/polylines:
// https://www.autodesk.com/techpubs/autocad/acad2000/dxf/polyline_dxf_06.htm
let geomCode = 8;
if(measurement.closed){
geomCode += 1;
}
let dxfSection = `0
SECTION
2
ENTITIES
0
POLYLINE
8
0
62
1
66
1
10
0.0
20
0.0
30
0.0
70
${geomCode}
`;
let xMax = 0.0;
let yMax = 0.0;
let zMax = 0.0;
measurement.points.forEach(function (point) {
for(let point of measurement.points){
point = point.position;
xMax = Math.max(xMax, point.x);
yMax = Math.max(yMax, point.y);
zMax = Math.max(zMax, point.z);
dxfBody += '0\n\
VERTEX\n\
8\n\
0\n\
10\n\
{X}\n\
20\n\
{Y}\n\
30\n\
{Z}\n\
70\n\
32\n'.replace('{X}', point.x)
.replace('{Y}', point.y)
.replace('{Z}', point.z);
});
dxfSection += `0
VERTEX
8
0
10
${point.x}
20
${point.y}
30
${point.z}
70
32
`;
dxfBody += '0\n\
SEQEND\n\
0\n\
ENDSEC\n';
dxfSection += `0
SEQEND
0
ENDSEC
`;
}
var dxfHeader = '999\n\
DXF created from potree\n\
0\n\
SECTION\n\
2\n\
HEADER\n\
9\n\
$ACADVER\n\
1\n\
AC1006\n\
9\n\
$INSBASE\n\
10\n\
0.0\n\
20\n\
0.0\n\
30\n\
0.0\n\
9\n\
$EXTMIN\n\
10\n\
0.0\n\
20\n\
0.0\n\
30\n\
0\n\
9\n\
$EXTMAX\n\
10\n\
{xMax}\n\
20\n\
{yMax}\n\
30\n\
{zMax}\n\
0\n\
ENDSEC\n'.replace('{xMax}', xMax)
.replace('{yMax}', yMax)
.replace('{zMax}', zMax);
let dxf = dxfHeader + dxfBody + '0\n\
EOF';
return dxf;
return dxfSection;
}
static toString(measurements){
if(!(measurements instanceof Array)){
measurements = [measurements];
}
measurements = measurements.filter(m => m instanceof Potree.Measure);
let points = measurements.filter(m => (m instanceof Potree.Measure))
.map(m => m.points)
.reduce((a, v) => a.concat(v))
.map(p => p.position);
let min = new THREE.Vector3(Infinity, Infinity, Infinity);
let max = new THREE.Vector3(-Infinity, -Infinity, -Infinity);
for(let point of points){
min.min(point);
max.max(point);
}
let dxfHeader = `999
DXF created from potree
0
SECTION
2
HEADER
9
$ACADVER
1
AC1006
9
$INSBASE
10
0.0
20
0.0
30
0.0
9
$EXTMIN
10
${min.x}
20
${min.y}
30
${min.z}
9
$EXTMAX
10
${max.x}
20
${max.y}
30
${max.z}
0
ENDSEC
`;
let dxfBody = "";
for(let measurement of measurements){
dxfBody += Potree.DXFExporter.measurementSection(measurement);
}
let dxf = dxfHeader + dxfBody + '0\nEOF';
return dxf;
}
}

View File

@ -8,67 +8,69 @@
Potree.GeoJSONExporter = class GeoJSONExporter{
static toString(measurement){
let geojson = {
"type": "FeatureCollection",
"features": []
};
let isLine = measurement.showDistances && !measurement.showArea && !measurement.showAngles;
let isPolygon = measurement.showDistances && measurement.showArea && !measurement.showAngles;
if(isLine){
geojson.features.push({
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": []
},
"properties": {
}
});
}else if (isPolygon) {
geojson.features.push({
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": []
},
"properties": {
}
});
}
static measurementToFeatures(measurement){
let coords = measurement.points.map(e => e.position.toArray());
if(isLine){
geojson.features[0].geometry.coordinates = coords;
}else if(isPolygon){
coords.push(coords[0]);
geojson.features[0].geometry.coordinates.push(coords);
}
let features = [];
measurement.edgeLabels.forEach(function (label) {
var labelPoint = {
if(coords.length === 1){
let feature = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: label.position.toArray(),
coordinates: coords[0],
},
properties: {
name: label.text
name: measurement.name
}
};
geojson.features.push(labelPoint);
});
if (isLine) {
// There is one point more than the number of edges.
geojson.features.pop();
features.push(feature);
}else if(coords.length > 1 && !measurement.closed){
let object = {
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": coords
},
"properties": {
name: measurement.name
}
};
features.push(object);
}else if(coords.length > 1 && measurement.closed){
let object = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[...coords, coords[0]]]
},
"properties": {
name: measurement.name
}
};
features.push(object);
}
if(measurement.showDistances){
measurement.edgeLabels.forEach((label) => {
let labelPoint = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: label.position.toArray(),
},
properties: {
distance: label.text
}
};
features.push(labelPoint);
});
}
if (isPolygon) {
if(measurement.showArea){
var point = measurement.areaLabel.position;
var labelArea = {
type: 'Feature',
@ -77,12 +79,35 @@ Potree.GeoJSONExporter = class GeoJSONExporter{
coordinates: point.toArray(),
},
properties: {
name: measurement.areaLabel.text
area: measurement.areaLabel.text
}
};
geojson.features.push(labelArea);
features.push(labelArea);
}
return features;
}
static toString(measurements){
if(!(measurements instanceof Array)){
measurements = [measurements];
}
measurements = measurements.filter(m => m instanceof Potree.Measure);
let features = [];
for(let measure of measurements){
let f = Potree.GeoJSONExporter.measurementToFeatures(measure);
features = features.concat(f);
}
let geojson = {
"type": "FeatureCollection",
"features": features
};
return JSON.stringify(geojson);
}

59
src/server/getPoints.php Normal file
View File

@ -0,0 +1,59 @@
<?php
// "{693550.968, 3915914.169},{693890.618, 3916387.819},{694584.820, 3916458.180},{694786.239, 3916307.199}"
// width14
// getPoints.php?min=693550.968;3915914.169&max=694584.820;3916458.180&minLevel=0&maxLevel=3
// getPoints.php?pc=../pointclouds/vol_total/cloud.js&min=693550.968;3915914.169&max=694584.820;3916458.180&minLevel=0&maxLevel=5
function toCoordinate($value){
$coord = explode(';', $value);
for($i = 0; $i < count($coord); $i++){
$coord[$i] = (double)$coord[$i];
}
return $coord;
}
$min = toCoordinate($_GET['min']);
$max = toCoordinate($_GET['max']);
$minLevel = isset($_GET['minLevel']) ? (int)$_GET['minLevel'] : 0;
$maxLevel = isset($_GET['maxLevel']) ? (int)$_GET['maxLevel'] : 3;
$path = realpath($_GET['pc']);
$path = str_replace("\\", "/", $path);
//$path = "D:/dev/pointclouds/converted/CA13/cloud.js";
$outputFile = "./result.las";
$yc = ($min[1] + $max[1]) / 2.0;
$sizeY = $max[1] - $min[1];
$coordinates = "{".$min[0].",$yc},{".$max[0].",$yc}";
$width = ($max[1] - $min[1]) / 2.0;
$binary = "D:/dev/workspaces/CPotree/master/bin/Release_x64/PotreeElevationProfile.exe";
$command = "$binary " . escapeshellarg($path) . " "
. "-o " . escapeshellarg($outputFile) . " "
. "--estimate "
. "--coordinates " . escapeshellarg($coordinates) . " "
. "--width " . escapeshellarg($width) . " "
. "--min-level " . escapeshellarg($minLevel) . " "
. "--max-level " . escapeshellarg($maxLevel) . " ";
echo "$command <br/>";
$output = "";
exec($command, $output);
foreach($output as $line){
echo "$line <br/>";
}
$path = realpath($_GET['pc']);
echo($path);
?>

View File

@ -279,7 +279,7 @@ body{
}
.measurement_item{
border-top: 1px solid rgba(0, 0, 0, 0.5);
border-bottom: 1px solid rgba(0, 0, 0, 0.5);
display: block;
position: relative;
}

View File

@ -99,6 +99,8 @@
<!-- <ul class="pv-menu-list selectable" id="measurement_details"></ul> -->
<div id="measurement_list"></div>
<div id="measurement_actions_bottom" style="margin: 6px 2px 6px 2px">
</div>
</div>
<!-- ANNOTATIONS -->

View File

@ -939,10 +939,12 @@ function initMeasurementDetails(){
return table;
};
let createAttributesTable = (point) => {
let createAttributesTable = (measurement) => {
let elTable = $('<table class="measurement_value_table"></table>');
let point = measurement.points[0];
if(point.color){
let color = point.color;
let text = color.join(", ");
@ -1007,13 +1009,15 @@ function initMeasurementDetails(){
this.icon = Potree.resourcePath + "/icons/distance.svg";
this.elIcon.attr("src", this.icon);
let totalDistance = this.measurement.getTotalDistance().toFixed(3);
this.elContent = $(`
<div>
<span class="coordinates_table_container"></span>
<br>
<span>Total Distance:</span> <span id="distance_${this.id}">${totalDistance}</span>
<table id="distances_table_${this.id}" class="measurement_value_table">
</table>
<!-- ACTIONS -->
<div style="display: flex; margin-top: 12px">
@ -1040,9 +1044,38 @@ function initMeasurementDetails(){
elCoordiantesContainer.empty();
elCoordiantesContainer.append(createCoordinatesTable(this.measurement));
let positions = this.measurement.points.map(p => p.position);
let distances = [];
for(let i = 0; i < positions.length - 1; i++){
let d = positions[i].distanceTo(positions[i+1]);
distances.push(d.toFixed(3));
}
let totalDistance = this.measurement.getTotalDistance().toFixed(3);
let elDistance = this.elContent.find(`#distance_${this.id}`);
elDistance.html(totalDistance);
let elDistanceTable = this.elContent.find(`#distances_table_${this.id}`);
elDistanceTable.empty();
for(let i = 0; i < distances.length; i++){
let label = (i === 0) ? "Distances: " : "";
let distance = distances[i];
let elDistance = $(`
<tr>
<th>${label}</th>
<td style="width: 100%; padding-left: 10px">${distance}</td>
</tr>`);
elDistanceTable.append(elDistance);
}
let elTotal = $(`
<tr>
<th>Total: </td><td style="width: 100%; padding-left: 10px">${totalDistance}</th>
</tr>`);
elDistanceTable.append(elTotal);
//let elDistance = this.elContent.find(`#distance_${this.id}`);
//elDistance.html(totalDistance);
}
destroy(){
@ -1071,6 +1104,9 @@ function initMeasurementDetails(){
<br>
<span class="attributes_table_container"></span>
<!-- ACTIONS -->
<div style="display: flex; margin-top: 12px">
<span></span>
@ -1095,6 +1131,10 @@ function initMeasurementDetails(){
let elCoordiantesContainer = this.elContent.find(".coordinates_table_container");
elCoordiantesContainer.empty();
elCoordiantesContainer.append(createCoordinatesTable(this.measurement));
let elAttributesContainer = this.elContent.find(".attributes_table_container");
elAttributesContainer.empty();
elAttributesContainer.append(createAttributesTable(this.measurement));
}
destroy(){
@ -1175,6 +1215,19 @@ function initMeasurementDetails(){
<br>
<table class="measurement_value_table">
<tr>
<th>\u03b1</th>
<th>\u03b2</th>
<th>\u03b3</th>
</tr>
<tr>
<td align="center" id="angle_cell_alpha_${this.id}" style="width: 33%"></td>
<td align="center" id="angle_cell_betta_${this.id}" style="width: 33%"></td>
<td align="center" id="angle_cell_gamma_${this.id}" style="width: 33%"></td>
</tr>
</table>
<!-- ACTIONS -->
<div style="display: flex; margin-top: 12px">
<span></span>
@ -1199,6 +1252,20 @@ function initMeasurementDetails(){
let elCoordiantesContainer = this.elContent.find(".coordinates_table_container");
elCoordiantesContainer.empty();
elCoordiantesContainer.append(createCoordinatesTable(this.measurement));
let angles = [];
for(let i = 0; i < this.measurement.points.length; i++){
angles.push(this.measurement.getAngle(i) * (180.0/Math.PI));
}
angles = angles.map(a => a.toFixed(1) + '\u00B0');
let elAlpha = this.elContent.find(`#angle_cell_alpha_${this.id}`);
let elBetta = this.elContent.find(`#angle_cell_betta_${this.id}`);
let elGamma = this.elContent.find(`#angle_cell_gamma_${this.id}`);
elAlpha.html(angles[0]);
elBetta.html(angles[1]);
elGamma.html(angles[2]);
}
destroy(){
@ -1226,6 +1293,8 @@ function initMeasurementDetails(){
<br>
<span id="height_label_${this.id}">Height: </span><br>
<!-- ACTIONS -->
<div style="display: flex; margin-top: 12px">
<span></span>
@ -1250,6 +1319,21 @@ function initMeasurementDetails(){
let elCoordiantesContainer = this.elContent.find(".coordinates_table_container");
elCoordiantesContainer.empty();
elCoordiantesContainer.append(createCoordinatesTable(this.measurement));
{
let points = this.measurement.points;
let sorted = points.slice().sort( (a, b) => a.position.z - b.position.z );
let lowPoint = sorted[0].position.clone();
let highPoint = sorted[sorted.length - 1].position.clone();
let min = lowPoint.z;
let max = highPoint.z;
let height = max - min;
height = height.toFixed(3);
this.elHeightLabel = this.elContent.find(`#height_label_${this.id}`);
this.elHeightLabel.html(`<b>Height:</b> ${height}`);
}
}
destroy(){
@ -1284,6 +1368,8 @@ function initMeasurementDetails(){
<span style="display:flex; align-items: center; padding-right: 10px">Width: </span>
<input id="${sliderID}" name="${sliderID}" value="5.06" style="flex-grow: 1; width:100%">
</span>
<br>
<input type="button" id="show_2d_profile_${this.id}" value="show 2d profile" style="width: 100%"/>
<!-- ACTIONS -->
<div style="display: flex; margin-top: 12px">
@ -1294,7 +1380,11 @@ function initMeasurementDetails(){
</div>
`);
this.elContentContainer.append(this.elContent);
this.elShow2DProfile = this.elContent.find(`#show_2d_profile_${this.id}`);
this.elShow2DProfile.click(() => {
viewer._2dprofile.show();
viewer._2dprofile.draw(measurement);
});
{ // width spinner
let elWidthLabel = this.elContent.find(`#${labelID}`);
@ -1542,6 +1632,52 @@ function initMeasurementDetails(){
trackScene(viewer.scene);
viewer.addEventListener("scene_changed", (e) => {trackScene(e.scene)});
{ // BOTTOM ACTIONS
let elActionsB = $("#measurement_actions_bottom");
{
let icon = Potree.resourcePath + "/icons/file_geojson.svg";
let elDownload = $(`
<a href="#" download="measure.json" class="measurepanel_downloads">
<img src="${icon}" style="height: 24px" />
</a>`);
elActionsB.append(elDownload);
elDownload.click(function(e){
let scene = viewer.scene;
let measurements = [scene.measurements, scene.profiles, scene.volumes].reduce((a, v) => a.concat(v));
let geojson = Potree.GeoJSONExporter.toString(measurements);
let url = window.URL.createObjectURL(new Blob([geojson], {type: 'data:application/octet-stream'}));
elDownload.attr("href", url);
});
}
{
let icon = Potree.resourcePath + "/icons/file_dxf.svg";
let elDownload = $(`
<a href="#" download="measure.dxf" class="measurepanel_downloads">
<img src="${icon}" style="height: 24px" />
</a>`);
elActionsB.append(elDownload);
elDownload.click(function(e){
let scene = viewer.scene;
let measurements = [scene.measurements, scene.profiles, scene.volumes].reduce((a, v) => a.concat(v));
let dxf = Potree.DXFExporter.toString(measurements);
let url = window.URL.createObjectURL(new Blob([dxf], {type: 'data:application/octet-stream'}));
elDownload.attr("href", url);
});
}
}
};
function initSceneList(){