Profile DXF download

Added feature: download flat DXF (2D) of the profile view
This commit is contained in:
Roy Mdr 2022-04-16 17:49:43 -05:00
parent e86cae71f2
commit c70e95d95b
4 changed files with 229 additions and 0 deletions

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 26.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
version="1.0"
id="svg3797"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px"
y="0px"
width="42"
height="16"
viewBox="0 0 42 16"
style="enable-background:new 0 0 42 16;"
xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
</style>
<sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="layer1" inkscape:cx="37.553698" inkscape:cy="-22.077233" inkscape:document-units="px" inkscape:grid-bbox="true" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="1137" inkscape:window-maximized="1" inkscape:window-width="1600" inkscape:window-x="2552" inkscape:window-y="-8" inkscape:zoom="5.5989008" pagecolor="#ffffff" showgrid="true">
<inkscape:grid empspacing="5" enabled="true" id="grid3805" snapvisiblegridlinesonly="true" type="xygrid" visible="true">
</inkscape:grid>
</sodipodi:namedview>
<g>
<path d="M39.1,5.8c-0.3-0.8-0.7-1.6-1.2-2.3c-0.2-0.3-0.6-0.6-1.1-0.6H36c-0.4,0-0.9,0.2-1.1,0.6c0,0.1-0.1,0.1-0.1,0.2
c-0.3-0.2-0.6-0.4-1-0.5C33.4,3,32.9,3,32.2,3h-2.4c-0.5,0-0.8,0.2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.7,0.2-1s0.1-0.7,0.1-1c0-0.7-0.1-1.4-0.2-2
c-0.2-0.6-0.4-1.4-0.8-2.3h0.8c0.4,0.6,0.8,1.3,1,2c0.2,0.7,0.4,1.4,0.4,2.1c0,0.6-0.1,1.3-0.3,2c-0.2,0.8-0.6,1.6-1.1,2.3H36z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -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;
}
}

View File

@ -48,6 +48,10 @@
<img id="potree_profile_move_forward" class="text-icon"/>
<img id="potree_profile_move_backward" class="text-icon"/>
<a id="potree_download_profile_dxf_link" href="#" download="profile.dxf">
<img id="potree_download_dxf_icon" class="text-icon"/>
</a>
<a id="potree_download_profile_ortho_link" href="#" download="profile.csv">
<img id="potree_download_csv_icon" class="text-icon"/>
</a>

View File

@ -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();