From c70e95d95ba692bdefb5f2ddc851e06bc61aa3fd Mon Sep 17 00:00:00 2001 From: Roy Mdr Date: Sat, 16 Apr 2022 17:49:43 -0500 Subject: [PATCH 1/4] Profile DXF download Added feature: download flat DXF (2D) of the profile view --- resources/icons/file_dxf_2d.svg | 66 +++++++++++++ src/exporter/DXFProfileExporter.js | 145 +++++++++++++++++++++++++++++ src/viewer/profile.html | 4 + src/viewer/profile.js | 14 +++ 4 files changed, 229 insertions(+) create mode 100644 resources/icons/file_dxf_2d.svg create mode 100644 src/exporter/DXFProfileExporter.js diff --git a/resources/icons/file_dxf_2d.svg b/resources/icons/file_dxf_2d.svg new file mode 100644 index 00000000..81ccc062 --- /dev/null +++ b/resources/icons/file_dxf_2d.svg @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/exporter/DXFProfileExporter.js b/src/exporter/DXFProfileExporter.js new file mode 100644 index 00000000..c8d832ee --- /dev/null +++ b/src/exporter/DXFProfileExporter.js @@ -0,0 +1,145 @@ +/** + * + * @author roy.mdr / http://... + * + */ + +export class DXFProfileExporter { + + static toXYZ(points) { + + /* + points: { + ... + data: { + mileage: [0, 1, 2...], -> one per point + position: [0, 0, 0, 1, 1, 1, 2, 2, 2...], -> X, Y, Z + rgba: [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2...] -> R, G, B, A + }, + numPoints: Int + } + */ + + const pointsXYZ = { + x: [], + y: [], + z: [], + numPoints: 0 + }; + + const pData = points.data; + const pMileage = pData.mileage; + const pCoords = pData.position; + const pColor = pData.rgba; + + for (let pIx = 0; pIx < points.numPoints; pIx++) { + + const poMileage = pMileage[pIx]; + // const poCoordX = pCoords[ ((pIx * 3) + 0) ]; + // const poCoordY = pCoords[ ((pIx * 3) + 1) ]; + const poCoordZ = pCoords[ ((pIx * 3) + 2) ]; + // const poColorR = pColor[ ((pIx * 4) + 0) ]; + // const poColorG = pColor[ ((pIx * 4) + 1) ]; + // const poColorB = pColor[ ((pIx * 4) + 2) ]; + // const poColorA = pColor[ ((pIx * 4) + 3) ]; + + + pointsXYZ.x.push(poMileage); + pointsXYZ.y.push(0); + pointsXYZ.z.push(poCoordZ); + + } + + pointsXYZ.numPoints = points.numPoints; + + return pointsXYZ; + } + + static plotPCloudPoint(x, y, z) { + + const dxfSection = `0 +POINT +8 +layer_pointCloud +10 +${x} +20 +${y} +30 +${z} +`; + + return dxfSection; + } + + static toString(points) { + + const pCloud = DXFProfileExporter.toXYZ(points); + + const minX = Math.min(...pCloud.x); + const minY = Math.min(...pCloud.y); + const minZ = Math.min(...pCloud.z); + + const maxX = Math.max(...pCloud.x); + const maxY = Math.max(...pCloud.y); + const maxZ = Math.max(...pCloud.z); + + + const 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 +${minX} +20 +${minY} +30 +${minZ} +9 +$EXTMAX +10 +${maxX} +20 +${maxY} +30 +${maxZ} +0 +ENDSEC +`; + + let dxfBody = `0 +SECTION +2 +ENTITIES +`; + + for (let i = 0; i < pCloud.numPoints; i++) { + dxfBody += DXFProfileExporter.plotPCloudPoint(pCloud.x[i], pCloud.y[i], pCloud.z[i]); + } + + dxfBody += `0 +ENDSEC +`; + + const dxf = dxfHeader + dxfBody + '0\nEOF'; + + return dxf; + } + +} diff --git a/src/viewer/profile.html b/src/viewer/profile.html index 3eead5a3..75d75354 100644 --- a/src/viewer/profile.html +++ b/src/viewer/profile.html @@ -48,6 +48,10 @@ + + + + diff --git a/src/viewer/profile.js b/src/viewer/profile.js index 4fb60cfe..cf6c2d59 100644 --- a/src/viewer/profile.js +++ b/src/viewer/profile.js @@ -2,6 +2,7 @@ import * as THREE from "../../libs/three.js/build/three.module.js"; import {Utils} from "../utils.js"; import {Points} from "../Points.js"; +import {DXFProfileExporter} from "../exporter/DXFProfileExporter.js"; import {CSVExporter} from "../exporter/CSVExporter.js"; import {LASExporter} from "../exporter/LASExporter.js"; import { EventDispatcher } from "../EventDispatcher.js"; @@ -262,6 +263,9 @@ export class ProfileWindow extends EventDispatcher { let backwardIcon = `${exports.resourcePath}/icons/arrow_down.svg`; $('#potree_profile_move_backward').attr('src', backwardIcon); + let dxfIcon = `${exports.resourcePath}/icons/file_dxf_2d.svg`; + $('#potree_download_dxf_icon').attr('src', dxfIcon); + let csvIcon = `${exports.resourcePath}/icons/file_csv_2d.svg`; $('#potree_download_csv_icon').attr('src', csvIcon); @@ -499,6 +503,16 @@ export class ProfileWindow extends EventDispatcher { return points; }; + $('#potree_download_dxf_icon').click(() => { + + const points = getProfilePoints(); + + const string = DXFProfileExporter.toString(points); + + const blob = new Blob([string], {type: "text/string"}); + $('#potree_download_profile_dxf_link').attr('href', URL.createObjectURL(blob)); + }); + $('#potree_download_csv_icon').click(() => { let points = getProfilePoints(); From 99b9e685095d34e55cae4708beaeddb504113d99 Mon Sep 17 00:00:00 2001 From: Roy Mdr Date: Thu, 9 Jun 2022 10:31:17 -0500 Subject: [PATCH 2/4] Added DXF 3D Added the posibility to download the profile pointcloud in 3D real coordinates as DXF (similar to the LAS download available) --- resources/icons/file_dxf_3d.svg | 55 ++++++++++++++++++++++++++++++ src/exporter/DXFProfileExporter.js | 23 ++++++++----- src/viewer/profile.html | 8 +++-- src/viewer/profile.js | 21 +++++++++--- 4 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 resources/icons/file_dxf_3d.svg diff --git a/resources/icons/file_dxf_3d.svg b/resources/icons/file_dxf_3d.svg new file mode 100644 index 00000000..d2785cfc --- /dev/null +++ b/resources/icons/file_dxf_3d.svg @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/exporter/DXFProfileExporter.js b/src/exporter/DXFProfileExporter.js index c8d832ee..38ed005b 100644 --- a/src/exporter/DXFProfileExporter.js +++ b/src/exporter/DXFProfileExporter.js @@ -6,7 +6,7 @@ export class DXFProfileExporter { - static toXYZ(points) { + static toXYZ(points, flatten = false) { /* points: { @@ -35,18 +35,23 @@ export class DXFProfileExporter { for (let pIx = 0; pIx < points.numPoints; pIx++) { const poMileage = pMileage[pIx]; - // const poCoordX = pCoords[ ((pIx * 3) + 0) ]; - // const poCoordY = pCoords[ ((pIx * 3) + 1) ]; + const poCoordX = pCoords[ ((pIx * 3) + 0) ]; + const poCoordY = pCoords[ ((pIx * 3) + 1) ]; const poCoordZ = pCoords[ ((pIx * 3) + 2) ]; // const poColorR = pColor[ ((pIx * 4) + 0) ]; // const poColorG = pColor[ ((pIx * 4) + 1) ]; // const poColorB = pColor[ ((pIx * 4) + 2) ]; // const poColorA = pColor[ ((pIx * 4) + 3) ]; - - pointsXYZ.x.push(poMileage); - pointsXYZ.y.push(0); - pointsXYZ.z.push(poCoordZ); + if (flatten === true) { + pointsXYZ.x.push(poMileage); + pointsXYZ.y.push(0); + pointsXYZ.z.push(poCoordZ); + } else { + pointsXYZ.x.push(poCoordX); + pointsXYZ.y.push(poCoordY); + pointsXYZ.z.push(poCoordZ); + } } @@ -72,9 +77,9 @@ ${z} return dxfSection; } - static toString(points) { + static toString(points, flatten = false) { - const pCloud = DXFProfileExporter.toXYZ(points); + const pCloud = DXFProfileExporter.toXYZ(points, flatten); const minX = Math.min(...pCloud.x); const minY = Math.min(...pCloud.y); diff --git a/src/viewer/profile.html b/src/viewer/profile.html index 75d75354..320c30b3 100644 --- a/src/viewer/profile.html +++ b/src/viewer/profile.html @@ -48,8 +48,12 @@ - - + + + + + + diff --git a/src/viewer/profile.js b/src/viewer/profile.js index cf6c2d59..ce20f8cb 100644 --- a/src/viewer/profile.js +++ b/src/viewer/profile.js @@ -263,8 +263,11 @@ export class ProfileWindow extends EventDispatcher { let backwardIcon = `${exports.resourcePath}/icons/arrow_down.svg`; $('#potree_profile_move_backward').attr('src', backwardIcon); - let dxfIcon = `${exports.resourcePath}/icons/file_dxf_2d.svg`; - $('#potree_download_dxf_icon').attr('src', dxfIcon); + let dxf2DIcon = `${exports.resourcePath}/icons/file_dxf_2d.svg`; + $('#potree_download_dxf2D_icon').attr('src', dxf2DIcon); + + let dxf3DIcon = `${exports.resourcePath}/icons/file_dxf_3d.svg`; + $('#potree_download_dxf3D_icon').attr('src', dxf3DIcon); let csvIcon = `${exports.resourcePath}/icons/file_csv_2d.svg`; $('#potree_download_csv_icon').attr('src', csvIcon); @@ -503,14 +506,24 @@ export class ProfileWindow extends EventDispatcher { return points; }; - $('#potree_download_dxf_icon').click(() => { + $('#potree_download_dxf2D_icon').click(() => { + + const points = getProfilePoints(); + + const string = DXFProfileExporter.toString(points, true); + + const blob = new Blob([string], {type: "text/string"}); + $('#potree_download_profile_dxf2D_link').attr('href', URL.createObjectURL(blob)); + }); + + $('#potree_download_dxf3D_icon').click(() => { const points = getProfilePoints(); const string = DXFProfileExporter.toString(points); const blob = new Blob([string], {type: "text/string"}); - $('#potree_download_profile_dxf_link').attr('href', URL.createObjectURL(blob)); + $('#potree_download_profile_dxf3D_link').attr('href', URL.createObjectURL(blob)); }); $('#potree_download_csv_icon').click(() => { From baa4fe42600d091492b0e01ade8ab1c5beaa156d Mon Sep 17 00:00:00 2001 From: Roy Mdr Date: Fri, 10 Jun 2022 11:39:20 -0500 Subject: [PATCH 3/4] Fixed real coordinates Fixed exporting with real coordinates for DXF 3D, CSV 2D and LAS 3D export. Now multiple pointclouds can be correctly exported. - Changed Float32 to Float64 when getting point coordinates to improve presition and avoid quantization when large coordinates --- src/viewer/profile.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/viewer/profile.js b/src/viewer/profile.js index ce20f8cb..402c4f85 100644 --- a/src/viewer/profile.js +++ b/src/viewer/profile.js @@ -485,19 +485,25 @@ export class ProfileWindow extends EventDispatcher { this.hide(); }); - let getProfilePoints = () => { + let getProfilePoints = (truePosition) => { let points = new Points(); for(let [pointcloud, entry] of this.pointclouds){ for(let pointSet of entry.points){ let originPos = pointSet.data.position; - let trueElevationPosition = new Float32Array(originPos); + let truePointPosition = new Float64Array(originPos); for(let i = 0; i < pointSet.numPoints; i++){ - trueElevationPosition[3 * i + 2] += pointcloud.position.z; + + if (truePosition === true) { + truePointPosition[3 * i + 0] += pointcloud.position.x; + truePointPosition[3 * i + 1] += pointcloud.position.y; + } + + truePointPosition[3 * i + 2] += pointcloud.position.z; } - pointSet.data.position = trueElevationPosition; + pointSet.data.position = truePointPosition; points.add(pointSet); pointSet.data.position = originPos; } @@ -518,7 +524,7 @@ export class ProfileWindow extends EventDispatcher { $('#potree_download_dxf3D_icon').click(() => { - const points = getProfilePoints(); + const points = getProfilePoints(true); const string = DXFProfileExporter.toString(points); @@ -528,7 +534,7 @@ export class ProfileWindow extends EventDispatcher { $('#potree_download_csv_icon').click(() => { - let points = getProfilePoints(); + let points = getProfilePoints(true); let string = CSVExporter.toString(points); @@ -538,7 +544,7 @@ export class ProfileWindow extends EventDispatcher { $('#potree_download_las_icon').click(() => { - let points = getProfilePoints(); + let points = getProfilePoints(true); let buffer = LASExporter.toLAS(points); From cdb783cbcec1a37c16350d61118b9638d64d0999 Mon Sep 17 00:00:00 2001 From: Roy Mdr Date: Wed, 22 Jun 2022 19:43:41 -0500 Subject: [PATCH 4/4] Optimize DXF exporter Now it will calculate the boundaries of the DXF while adding points, effectively avoiding 6 roundtrips through all the points. Altho it might not be faster, it can handle A LOT more points without throwing a maximum call stack error. --- src/exporter/DXFProfileExporter.js | 57 ++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/src/exporter/DXFProfileExporter.js b/src/exporter/DXFProfileExporter.js index 38ed005b..5c120bdb 100644 --- a/src/exporter/DXFProfileExporter.js +++ b/src/exporter/DXFProfileExporter.js @@ -24,6 +24,12 @@ export class DXFProfileExporter { x: [], y: [], z: [], + minX: Number.MAX_VALUE, + minY: Number.MAX_VALUE, + minZ: Number.MAX_VALUE, + maxX: -Number.MAX_VALUE, + maxY: -Number.MAX_VALUE, + maxZ: -Number.MAX_VALUE, numPoints: 0 }; @@ -44,17 +50,47 @@ export class DXFProfileExporter { // const poColorA = pColor[ ((pIx * 4) + 3) ]; if (flatten === true) { + pointsXYZ.x.push(poMileage); pointsXYZ.y.push(0); pointsXYZ.z.push(poCoordZ); + + // Get boundaries X + if (pointsXYZ.maxX < poMileage) pointsXYZ.maxX = poMileage; + if (pointsXYZ.minX > poMileage) pointsXYZ.minX = poMileage; + + // Get boundaries Z + if (pointsXYZ.maxZ < poCoordZ) pointsXYZ.maxZ = poCoordZ; + if (pointsXYZ.minZ > poCoordZ) pointsXYZ.minZ = poCoordZ; + } else { + pointsXYZ.x.push(poCoordX); pointsXYZ.y.push(poCoordY); pointsXYZ.z.push(poCoordZ); + + // Get boundaries X + if (pointsXYZ.maxX < poCoordX) pointsXYZ.maxX = poCoordX; + if (pointsXYZ.minX > poCoordX) pointsXYZ.minX = poCoordX; + + // Get boundaries Y + if (pointsXYZ.maxY < poCoordY) pointsXYZ.maxY = poCoordY; + if (pointsXYZ.minY > poCoordY) pointsXYZ.minY = poCoordY; + + // Get boundaries Z + if (pointsXYZ.maxZ < poCoordZ) pointsXYZ.maxZ = poCoordZ; + if (pointsXYZ.minZ > poCoordZ) pointsXYZ.minZ = poCoordZ; + } } + if (flatten === true) { + // Set boundaries Y + pointsXYZ.maxY = 0; + pointsXYZ.minY = 0; + } + pointsXYZ.numPoints = points.numPoints; return pointsXYZ; @@ -81,15 +117,6 @@ ${z} const pCloud = DXFProfileExporter.toXYZ(points, flatten); - const minX = Math.min(...pCloud.x); - const minY = Math.min(...pCloud.y); - const minZ = Math.min(...pCloud.z); - - const maxX = Math.max(...pCloud.x); - const maxY = Math.max(...pCloud.y); - const maxZ = Math.max(...pCloud.z); - - const dxfHeader = `999 DXF created from potree 0 @@ -111,19 +138,19 @@ $INSBASE 9 $EXTMIN 10 -${minX} +${pCloud.minX} 20 -${minY} +${pCloud.minY} 30 -${minZ} +${pCloud.minZ} 9 $EXTMAX 10 -${maxX} +${pCloud.maxX} 20 -${maxY} +${pCloud.maxY} 30 -${maxZ} +${pCloud.maxZ} 0 ENDSEC `;