Commit ea536269 authored by Matthias Betz's avatar Matthias Betz
Browse files

set max translation to 10000 if citygml area is too big

parent cfb9eea3
Pipeline #12351 passed with stages
in 9 seconds
......@@ -286,6 +286,7 @@ parser.onend = function () {
camera.reshape(width, height, cameraViewDistance);
var d = bbox.getDiagonalEdgeLength() / Math.tan(degrees_to_radians(30) / 2);
var translateZ = -d;
translateZ = Math.max(-10000, translateZ);
camera.setDistance(translateZ);
camera.rotate(Math.PI / 2 * 500, 300);
document.getElementById("progressDiv").style.display = "none";
......@@ -293,7 +294,6 @@ parser.onend = function () {
};
function createViewInformation(gl, viewing) {
const center = bbox.getCenter();
var vertexDataCount = 0;
for (const poly of triangulatedPolygons) {
vertexDataCount += poly.triangles.length;
......@@ -304,11 +304,15 @@ function createViewInformation(gl, viewing) {
var counter = 0;
for (const poly of triangulatedPolygons) {
for (var i = 0; i < poly.triangles.length; i++) {
vertexData[counter] = poly.triangles[i] - center[i % 3];
vertexData[counter] = poly.triangles[i];
colorData[counter] = poly.color[i % 3];
counter++;
}
}
var centroidAndClosestPoint = computeCentroidAndClosest(vertexData);
translateByClosestPoint(vertexData, centroidAndClosestPoint.closestIndex);
for (var i = 0; i < elementData.length; i++) {
elementData[i] = i;
}
......@@ -347,6 +351,64 @@ function clearViewing(gl) {
gl.deleteBuffer(viewInfo.indexVbo);
gl.deleteVertexArray(viewInfo.vao);
}
function translateByClosestPoint(vertexData, closestIndex) {
const i = closestIndex * 3;
const ox = vertexData[i];
const oy = vertexData[i + 1];
const oz = vertexData[i + 2];
// Shift every vertex
for (let j = 0, len = vertexData.length; j < len; j += 3) {
vertexData[j] -= ox;
vertexData[j + 1] -= oy;
vertexData[j + 2] -= oz;
}
}
function computeCentroidAndClosest(vertexData) {
const count = vertexData.length / 3;
let cx = 0.0, cy = 0.0, cz = 0.0;
// ---- PASS 1: Compute centroid ----
for (let i = 0; i < vertexData.length; i += 3) {
cx += vertexData[i];
cy += vertexData[i + 1];
cz += vertexData[i + 2];
}
cx /= count;
cy /= count;
cz /= count;
// ---- PASS 2: Find closest point ----
let minDistSq = Infinity;
let closestIndex = 0;
for (let i = 0; i < vertexData.length; i += 3) {
const dx = vertexData[i] - cx;
const dy = vertexData[i + 1] - cy;
const dz = vertexData[i + 2] - cz;
const distSq = dx*dx + dy*dy + dz*dz;
if (distSq < minDistSq) {
minDistSq = distSq;
closestIndex = i;
}
}
return {
centroid: [cx, cy, cz],
closestPoint: [
vertexData[closestIndex],
vertexData[closestIndex + 1],
vertexData[closestIndex + 2]
],
closestIndex: closestIndex / 3
};
}
function redraw(gl) {
......@@ -552,6 +614,7 @@ input.addEventListener("change", function () {
offset = 0;
bbox = new BBox();
setProgress(0);
currentState = State.SEARCH_FOR_SURFACE_OR_GEOMETRY;
document.getElementById("progressDiv").style.removeProperty("display");
triangulatedPolygons = [];
readSlice();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment