Skip to content

Commit

Permalink
feat: store spatial elements within fragment group
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Jul 18, 2024
1 parent 19bb220 commit 6ec2e7b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 16 deletions.
25 changes: 21 additions & 4 deletions packages/core/src/fragments/Classifier/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ export class Classifier extends Component implements Disposable {
* Classifies fragments based on their spatial structure in the IFC model.
*
* @param model - The FragmentsGroup containing the fragments to be classified.
* @param config - The configuration for the classifier. It includes "useProperties" (if false, the classification will use the expressIDs instead of the names)
* @param config - The configuration for the classifier. It includes "useProperties", which is true by default
* (if false, the classification will use the expressIDs instead of the names), and "isolate", which will make
* the classifier just pick the WEBIFC categories provided.
*
* @remarks
* This method iterates through the relations of the fragments in the provided group,
Expand All @@ -354,7 +356,7 @@ export class Classifier extends Component implements Disposable {
*/
async bySpatialStructure(
model: FRAGS.FragmentsGroup,
config: { useProperties: boolean } = { useProperties: true },
config: { useProperties?: boolean; isolate?: Set<number> },
) {
const indexer = this.components.get(IfcRelationsIndexer);
const modelRelations = indexer.relationMaps[model.uuid];
Expand All @@ -364,7 +366,22 @@ export class Classifier extends Component implements Disposable {
);
}
const systemName = "spatialStructures";

// If useProperties is undefined, use properties by default
const propsUndefined = config.useProperties === undefined;
const useProperties = propsUndefined || config.useProperties;

for (const [expressID] of modelRelations) {
// E.g. if the user just wants the building storeys
if (config.isolate) {
const data = model.data.get(expressID);
if (!data) continue;
const category = data[1][1];
if (category === undefined || !config.isolate.has(category)) {
continue;
}
}

const spatialRels = indexer.getEntityRelations(
model,
expressID,
Expand All @@ -375,7 +392,7 @@ export class Classifier extends Component implements Disposable {
if (spatialRels) {
for (const id of spatialRels) {
let relName = id.toString();
if (config.useProperties) {
if (useProperties) {
const spatialRelAttrs = await model.getProperties(id);
if (!spatialRelAttrs) {
continue;
Expand All @@ -398,7 +415,7 @@ export class Classifier extends Component implements Disposable {
}

let relName = expressID.toString();
if (config.useProperties) {
if (useProperties) {
const relAttrs = await model.getProperties(expressID);
if (!relAttrs) {
continue;
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/fragments/Exploder/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ Before being able to use it, we will need to get the classifier to classify the
*/

const classifier = components.get(OBC.Classifier);
await classifier.bySpatialStructure(model);
await classifier.bySpatialStructure(model, {
isolate: new Set([WEBIFC.IFCBUILDINGSTOREY]),
});

/* MD
### ⏱️ Measuring the performance (optional)
Expand Down
17 changes: 10 additions & 7 deletions packages/core/src/fragments/IfcGeometryTiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SpatialStructure,
CivilReader,
IfcMetadataReader,
SpatialIdsFinder,
} from "../IfcLoader/src";

export * from "./src";
Expand Down Expand Up @@ -278,13 +279,15 @@ export class IfcGeometryTiler extends Component implements Disposable {
}

// Delete assets that have no geometric representation
const ids = group.data.keys();
for (const id of ids) {
const [keys] = group.data.get(id)!;
if (!keys.length) {
group.data.delete(id);
}
}
// const ids = group.data.keys();
// for (const id of ids) {
// const [keys] = group.data.get(id)!;
// if (!keys.length) {
// group.data.delete(id);
// }
// }

SpatialIdsFinder.get(group, this.webIfc);

const matrix = this.webIfc.GetCoordinationMatrix(0);
group.coordinationMatrix.fromArray(matrix);
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/fragments/IfcLoader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CivilReader, IfcFragmentSettings, IfcMetadataReader } from "./src";
import { FragmentsManager } from "../FragmentsManager";
import { Component, Components, Event, Disposable } from "../../core";
import { IfcJsonExporter } from "../../ifc/IfcJsonExporter";
import { SpatialIdsFinder } from "./src/spatial-ids-finder.ts";

export * from "./src/ifc-fragment-settings";

Expand Down Expand Up @@ -126,8 +127,6 @@ export class IfcLoader extends Component implements Disposable {
const properties = await jsonExporter.export(this.webIfc, 0);
group.setLocalProperties(properties);

this.cleanUp();

const fragments = this.components.get(FragmentsManager);
fragments.groups.set(group.uuid, group);

Expand All @@ -139,7 +138,9 @@ export class IfcLoader extends Component implements Disposable {

fragments.onFragmentsLoaded.trigger(group);

if (coordinate) fragments.coordinate([group]);
if (coordinate) {
fragments.coordinate([group]);
}

for (const [expressID] of group.data) {
const props = properties[expressID];
Expand All @@ -148,6 +149,10 @@ export class IfcLoader extends Component implements Disposable {
group.globalToExpressIDs.set(globalID, expressID);
}

SpatialIdsFinder.get(group, this.webIfc);

this.cleanUp();

console.log(`Streaming the IFC took ${performance.now() - before} ms!`);

return group;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/fragments/IfcLoader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./ifc-fragment-settings";
export * from "./spatial-structure";
export * from "./civil-reader";
export * from "./ifc-metadata-reader";
export * from "./spatial-ids-finder";
31 changes: 31 additions & 0 deletions packages/core/src/fragments/IfcLoader/src/spatial-ids-finder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as FRAGS from "@thatopen/fragments";
import * as WEBIFC from "web-ifc";

export class SpatialIdsFinder {
static get(model: FRAGS.FragmentsGroup, webIfc: WEBIFC.IfcAPI) {
const spatialTypes = [
WEBIFC.IFCPROJECT,
WEBIFC.IFCSITE,
WEBIFC.IFCBUILDING,
WEBIFC.IFCBUILDINGSTOREY,
WEBIFC.IFCSPACE,
WEBIFC.IFCROAD,
WEBIFC.IFCFACILITY,
WEBIFC.IFCFACILITYPART,
WEBIFC.IFCBRIDGE,
];

const data = model.data;

for (const category of spatialTypes) {
const ids = webIfc.GetLineIDsWithType(0, category);
const size = ids.size();
for (let i = 0; i < size; i++) {
const id = ids.get(i);
if (!data.has(id)) {
data.set(id, [[], [0, category]]);
}
}
}
}
}
Binary file modified resources/small.frag
Binary file not shown.
2 changes: 1 addition & 1 deletion resources/small.json

Large diffs are not rendered by default.

Binary file modified resources/streaming/small.ifc-processed-global
Binary file not shown.

0 comments on commit 6ec2e7b

Please sign in to comment.