Skip to content

Commit

Permalink
feat: remove merged fragments (ThatOpen#295)
Browse files Browse the repository at this point in the history
* feat: get rid of merged fragments

* chore: rebuild library
  • Loading branch information
agviegas authored Feb 9, 2024
1 parent 5883f07 commit 27cfe4c
Show file tree
Hide file tree
Showing 38 changed files with 4,574 additions and 11,704 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ out
dist/
resources/asdf.ifc
resources/asdf.frag
resources/asdf.json
resources/asdf.json
resources/bbbb.ifc
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/three": "0.160.0",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"bim-fragment": "1.3.2",
"bim-fragment": "1.3.8",
"cpy-cli": "^3.1.1",
"eslint": "^7.28.0",
"eslint-config-airbnb-base": "^14.2.1",
Expand Down Expand Up @@ -59,7 +59,7 @@
"unzipit": "^1.4.3"
},
"peerDependencies": {
"bim-fragment": "1.3.2",
"bim-fragment": "1.3.8",
"mapbox-gl": "^2.15.0",
"three": "^0.160.1",
"web-ifc": "^0.0.50"
Expand Down
Binary file removed resources/bbbb.frag
Binary file not shown.
1 change: 0 additions & 1 deletion resources/bbbb.json

This file was deleted.

14,713 changes: 4,026 additions & 10,687 deletions resources/openbim-components.js

Large diffs are not rendered by default.

Binary file modified resources/small.frag
Binary file not shown.
4 changes: 2 additions & 2 deletions src/annotation/SVGArrow/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Vector2 } from "three";
import { generateUUID } from "three/src/math/MathUtils";
import {
Component,
Disposable,
SVGAnnotationStyle,
Event,
} from "../../base-types";
import { Components } from "../../core";
import { tooeenRandomId } from "../../utils";

export class SVGArrow extends Component<SVGGElement> implements Disposable {
name: string = "SVGRectangle";
enabled: boolean = true;
id: string = tooeenRandomId();
id: string = generateUUID();

/** {@link Disposable.onDisposed} */
readonly onDisposed = new Event<undefined>();
Expand Down
4 changes: 2 additions & 2 deletions src/annotation/SVGCircle/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Vector2 } from "three";
import { generateUUID } from "three/src/math/MathUtils";
import {
Component,
Disposable,
SVGAnnotationStyle,
Event,
} from "../../base-types";
import { Components } from "../../core";
import { tooeenRandomId } from "../../utils";

export class SVGCircle
extends Component<SVGCircleElement>
implements Disposable
{
id = tooeenRandomId();
id = generateUUID();
name: string = "SVGRectangle";
enabled: boolean = true;

Expand Down
4 changes: 2 additions & 2 deletions src/annotation/SVGRectangle/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Vector2 } from "three";
import { generateUUID } from "three/src/math/MathUtils";
import {
Component,
Disposable,
SVGAnnotationStyle,
Event,
} from "../../base-types";
import { Components } from "../../core";
import { tooeenRandomId } from "../../utils";

export class SVGRectangle
extends Component<SVGRectElement>
implements Disposable
{
id = tooeenRandomId();
id = generateUUID();
name: string = "SVGRectangle";
enabled: boolean = true;

Expand Down
4 changes: 2 additions & 2 deletions src/annotation/SVGText/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Vector2 } from "three";
import { generateUUID } from "three/src/math/MathUtils";
import {
Component,
Disposable,
SVGAnnotationStyle,
Event,
} from "../../base-types";
import { Components } from "../../core";
import { tooeenRandomId } from "../../utils";

export class SVGText extends Component<SVGTextElement> implements Disposable {
id = tooeenRandomId();
id = generateUUID();
name: string = "SVGRectangle";
enabled: boolean = true;

Expand Down
4 changes: 2 additions & 2 deletions src/base-types/base-svg-annotation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generateUUID } from "three/src/math/MathUtils";
import { Disposable, UI, Event } from "./base-types";
import { Component } from "./component";
import { Button } from "../ui";
import { tooeenRandomId } from "../utils/Misc";
import { UIElement } from "./ui-element";

export interface SVGAnnotationStyle {
Expand All @@ -14,7 +14,7 @@ export abstract class BaseSVGAnnotation
extends Component<null>
implements UI, Disposable
{
id = tooeenRandomId();
id = generateUUID();

/** {@link Disposable.onDisposed} */
readonly onDisposed = new Event<undefined>();
Expand Down
2 changes: 1 addition & 1 deletion src/base-types/base-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,5 @@ export interface UI {
* made of multiple fragments, there might be repeated IDs across entries.
*/
export interface FragmentIdMap {
[fragmentID: string]: Set<string>;
[fragmentID: string]: Set<number>;
}
6 changes: 6 additions & 0 deletions src/civil/RoadNavigator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,14 @@
}
})

window.ondblclick = () => {
const result = components.raycaster.castRay();
console.log(result);
}

navigator.loadAnchor();


// Set up stats

const stats = new Stats();
Expand Down
83 changes: 43 additions & 40 deletions src/fragments/FragmentClassifier/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FragmentsGroup } from "bim-fragment";
import { Disposable, FragmentIdMap, Component, Event } from "../../base-types";
import { IfcCategoryMap, IfcPropertiesUtils } from "../../ifc";
import { toCompositeID } from "../../utils";
import { Components, ToolComponent } from "../../core";
import { FragmentManager } from "../FragmentManager";

Expand Down Expand Up @@ -91,14 +90,18 @@ export class FragmentClassifier
const fragList = fragments.list;
for (const id in fragList) {
const fragment = fragList[id];
const items = fragment.items;
const hidden = Object.keys(fragment.hiddenInstances);
result[id] = new Set(...items, ...hidden);
result[id] = new Set(fragment.ids);
}
return result;
}
const size = Object.keys(filter).length;
const models: { [fragmentGuid: string]: { [id: string]: number } } = {};

// There must be as many matches as conditions.
// E.g.: if the filter is "floor 1 and category wall",
// this gets the items with 2 matches (1 match per condition)
const filterCount = Object.keys(filter).length;

const models: { [fragmentGuid: string]: Map<number, number> } = {};

for (const name in filter) {
const values = filter[name];
if (!this._groupSystems[name]) {
Expand All @@ -110,41 +113,37 @@ export class FragmentClassifier
if (found) {
for (const guid in found) {
if (!models[guid]) {
models[guid] = {};
models[guid] = new Map();
}
for (const id of found[guid]) {
if (!models[guid][id]) {
models[guid][id] = 1;
const matchCount = models[guid].get(id);
if (matchCount === undefined) {
models[guid].set(id, 1);
} else {
models[guid][id]++;
models[guid].set(id, matchCount + 1);
}
}
}
}
}
}

const result: FragmentIdMap = {};
for (const guid in models) {
const model = models[guid];
for (const id in model) {
const numberOfMatches = model[id];
if (numberOfMatches === size) {
for (const [id, numberOfMatches] of model) {
if (numberOfMatches === undefined) {
throw new Error("Malformed fragments map!");
}
if (numberOfMatches === filterCount) {
if (!result[guid]) {
result[guid] = new Set();
}
result[guid].add(id);
const fragment = fragments.list[guid];
const composites = fragment.composites[id];
if (composites) {
const idNum = parseInt(id, 10);
for (let i = 1; i < composites; i++) {
const compositeID = toCompositeID(idNum, i);
result[guid].add(compositeID);
}
}
}
}
}

return result;
}

Expand All @@ -157,12 +156,13 @@ export class FragmentClassifier
modelsClassification[modelID] = {};
}
const currentModel = modelsClassification[modelID];
for (const expressID in group.data) {
const keys = group.data[expressID][0];
for (const [expressID, data] of group.data) {
const keys = data[0];
for (const key of keys) {
const fragID = group.keyFragments[key];
const fragID = group.keyFragments.get(key);
if (!fragID) continue;
if (!currentModel[fragID]) {
currentModel[fragID] = new Set<string>();
currentModel[fragID] = new Set<number>();
}
currentModel[fragID].add(expressID);
}
Expand Down Expand Up @@ -193,15 +193,18 @@ export class FragmentClassifier
}
const currentType = currentTypes[predefinedType];

for (const expressID in group.data) {
const keys = group.data[expressID][0];
for (const [_expressID, data] of group.data) {
const keys = data[0];
for (const key of keys) {
const fragmentID = group.keyFragments[key];
const fragmentID = group.keyFragments.get(key);
if (!fragmentID) {
throw new Error("Fragment ID not found!");
}
if (!currentType[fragmentID]) {
currentType[fragmentID] = new Set<string>();
currentType[fragmentID] = new Set<number>();
}
const currentFragment = currentType[fragmentID];
currentFragment.add(String(entity.expressID));
currentFragment.add(entity.expressID);
}
}
}
Expand All @@ -212,8 +215,8 @@ export class FragmentClassifier
this._groupSystems.entities = {};
}

for (const expressID in group.data) {
const rels = group.data[expressID][1];
for (const [expressID, data] of group.data) {
const rels = data[1];
const type = rels[1];
const entity = IfcCategoryMap[type];
this.saveItem(group, "entities", entity, expressID);
Expand All @@ -225,8 +228,8 @@ export class FragmentClassifier
throw new Error("To group by storey, properties are needed");
}

for (const expressID in group.data) {
const rels = group.data[expressID][1];
for (const [expressID, data] of group.data) {
const rels = data[1];
const storeyID = rels[0];
const storey = group.properties[storeyID];
if (storey === undefined) continue;
Expand All @@ -253,7 +256,7 @@ export class FragmentClassifier
group,
systemName,
relatingName ?? "NO REL NAME",
String(expressID)
expressID
);
}
}
Expand All @@ -264,22 +267,22 @@ export class FragmentClassifier
group: FragmentsGroup,
systemName: string,
className: string,
expressID: string
expressID: number
) {
if (!this._groupSystems[systemName]) {
this._groupSystems[systemName] = {};
}
const keys = group.data[expressID as any];
const keys = group.data.get(expressID);
if (!keys) return;
for (const key of keys[0]) {
const fragmentID = group.keyFragments[key];
const fragmentID = group.keyFragments.get(key);
if (fragmentID) {
const system = this._groupSystems[systemName];
if (!system[className]) {
system[className] = {};
}
if (!system[className][fragmentID]) {
system[className][fragmentID] = new Set<string>();
system[className][fragmentID] = new Set<number>();
}
system[className][fragmentID].add(expressID);
}
Expand Down
2 changes: 1 addition & 1 deletion src/fragments/FragmentClipStyler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class FragmentClipStyler
localStorage.setItem(this.localStorageID, this._defaultStyles);
await this.loadCachedStyles();
}
this.onSetup.trigger(this);
await this.onSetup.trigger(this);
}

get() {
Expand Down
Loading

0 comments on commit 27cfe4c

Please sign in to comment.