Skip to content

Commit

Permalink
Read 3D alignment curves
Browse files Browse the repository at this point in the history
  • Loading branch information
QuimMoya committed Nov 26, 2023
1 parent aaa5e06 commit ae0e1f9
Showing 1 changed file with 104 additions and 27 deletions.
131 changes: 104 additions & 27 deletions src/web-ifc-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,41 +802,118 @@ export class IfcAPI {
* @param modelID model ID
* @returns Lists with horizontal and vertical curves as sets of points
*/
GetAllAlignments(modelID: Number): any
{
const alignments = this.wasmModule.GetAllAlignments(modelID);
GetAllAlignments(modelID: Number): any {
const alignments = this.wasmModule.GetAllAlignments(modelID);
const alignmentList = [];
for (let i = 0; i < alignments.size(); i++) {
const alignment = alignments.get(i);
const horList = [];
const alignment = alignments.get(i);
const horList = [];
for (let j = 0; j < alignment.Horizontal.curves.size(); j++) {
const curve = alignment.Horizontal.curves.get(j);
const ptList = [];
for (let p = 0; p < curve.points.size(); p++) {
const pt = curve.points.get(p);
const newPoint = { x: pt.x, y: pt.y };
ptList.push(newPoint);
}
const newCurve = { points: ptList };
horList.push(newCurve);
}
const verList = [];
for (let j = 0; j < alignment.Vertical.curves.size(); j++) {
const curve = alignment.Vertical.curves.get(j);
const ptList = [];
for (let p = 0; p < curve.points.size(); p++) {
const pt = curve.points.get(p);
const newPoint = { x: pt.x, y: pt.y };
ptList.push(newPoint);
}
const newCurve = { points: ptList };
verList.push(newCurve);
}

const curve3DList = [];
if (
alignment.Horizontal.curves.size() > 0 &&
alignment.Vertical.curves.size() > 0
) {
const startH = { x: 0, y: 0, z: 0 };
const startV = { x: 0, y: 0, z: 0 };

// Construct 3D polyline from horizontal and vertical polylines

let lastx = 0;
let lasty = 0;
let length = 0;
for (let j = 0; j < alignment.Horizontal.curves.size(); j++) {
const curve = alignment.Horizontal.curves.get(j);
const ptList = [];
for (let p = 0; p < curve.points.size(); p++) {
const pt = curve.points.get(p);
const newPoint = { x: pt.x, y: pt.y };
ptList.push(newPoint);
const curve = alignment.Horizontal.curves.get(j);
const points = [];
for (let k = 0; k < curve.points.size(); k++) {
let alt = 0;
const pt = curve.points.get(k);
if (j === 0 && k === 0) {
lastx = pt.x;
lasty = pt.y;
}
const newCurve = { points: ptList };
horList.push(newCurve);
}
const verList = [];
for (let j = 0; j < alignment.Vertical.curves.size(); j++) {
const curve = alignment.Vertical.curves.get(j);
const ptList = [];
for (let p = 0; p < curve.points.size(); p++) {
const pt = curve.points.get(p);
const newPoint = { x: pt.x, y: pt.y };
ptList.push(newPoint);
const valueX = pt.x - lastx;
const valueY = pt.y - lasty;
lastx = pt.x;
lasty = pt.y;
length += Math.sqrt(valueX * valueX + valueY * valueY);
let first = true;
let lastAlt = 0;
let lastX = 0;
let done = false;
for (let ii = 0; ii < alignment.Vertical.curves.size(); ii++) {
const curve = alignment.Vertical.curves.get(ii);
for (let jj = 0; jj < curve.points.size(); jj++) {
const pt = curve.points.get(jj);
if (first) {
first = false;
alt = pt.y;
lastAlt = pt.y;
if (pt.x >= length) {
break;
}
}
if (pt.x >= length) {
const value1 = pt.x - lastX;
const value2 = length - lastX;
const value3 = value2 / value1;
alt = lastAlt * (1 - value3) + pt.y * value3;
done = true;
break;
}
lastAlt = pt.y;
lastX = pt.x;
}
if (done) {
break;
}
}
const newCurve = { points: ptList };
verList.push(newCurve);
points.push({
x: pt.x - startH.x,
y: alt - startV.y,
z: startH.y - pt.y,
});
}
const newCurve = { points: points };
curve3DList.push(newCurve);
}
const align = { origin, horizontal: horList, vertical: verList };
alignmentList.push(align);
}

const align = {
origin,
horizontal: horList,
vertical: verList,
curve3D: curve3DList,
};
alignmentList.push(align);

/////
}
return alignmentList;
}
}

/**
* Set the transformation matrix
Expand Down

0 comments on commit ae0e1f9

Please sign in to comment.