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/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 new file mode 100644 index 00000000..5c120bdb --- /dev/null +++ b/src/exporter/DXFProfileExporter.js @@ -0,0 +1,177 @@ +/** + * + * @author roy.mdr / http://... + * + */ + +export class DXFProfileExporter { + + static toXYZ(points, flatten = false) { + + /* + 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: [], + 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 + }; + + 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) ]; + + 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; + } + + static plotPCloudPoint(x, y, z) { + + const dxfSection = `0 +POINT +8 +layer_pointCloud +10 +${x} +20 +${y} +30 +${z} +`; + + return dxfSection; + } + + static toString(points, flatten = false) { + + const pCloud = DXFProfileExporter.toXYZ(points, flatten); + + 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 +${pCloud.minX} +20 +${pCloud.minY} +30 +${pCloud.minZ} +9 +$EXTMAX +10 +${pCloud.maxX} +20 +${pCloud.maxY} +30 +${pCloud.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..320c30b3 100644 --- a/src/viewer/profile.html +++ b/src/viewer/profile.html @@ -48,6 +48,14 @@ + + + + + + + + diff --git a/src/viewer/profile.js b/src/viewer/profile.js index 4fb60cfe..402c4f85 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,12 @@ export class ProfileWindow extends EventDispatcher { let backwardIcon = `${exports.resourcePath}/icons/arrow_down.svg`; $('#potree_profile_move_backward').attr('src', backwardIcon); + 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); @@ -478,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; } @@ -499,9 +512,29 @@ export class ProfileWindow extends EventDispatcher { return points; }; + $('#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(true); + + const string = DXFProfileExporter.toString(points); + + const blob = new Blob([string], {type: "text/string"}); + $('#potree_download_profile_dxf3D_link').attr('href', URL.createObjectURL(blob)); + }); + $('#potree_download_csv_icon').click(() => { - let points = getProfilePoints(); + let points = getProfilePoints(true); let string = CSVExporter.toString(points); @@ -511,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);