Skip to content

Commit

Permalink
feat(IFCImporter): add vtkIFCImporter
Browse files Browse the repository at this point in the history
This PR adds support for IFC format, the importer allows to merge
geometries to reduce the number of actors in the scene.

fixes #3156
  • Loading branch information
daker committed Nov 17, 2024
1 parent 0c3933d commit 9a1a854
Show file tree
Hide file tree
Showing 6 changed files with 539 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions Documentation/content/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ This will allow you to see the some live code running in your browser. Just pick
[![PLYWriter Example][PLYWriterWithIcon]](./PLYWriter.html "PLY writer(ply)")
[![STLReader Example][STLReaderWithIcon]](./STLReader.html "STL reader(stl)")
[![STLWriter Example][STLWriterWithIcon]](./STLWriter.html "STL writer(stl)")
[![GLTFImporter Example][GLTFImporter]](./GLTFImporter.html "GLTF importer(gltf, glb)")
[![GLTFImporter Example][GLTFImporterWithIcon]](./GLTFImporter.html "GLTF importer(gltf, glb)")
[![IFCImporter Example][IFCImporterWithIcon]](./IFCImporter.html "IFC importer(ifc)")
[![PolyDataReader Example][PolyDataReaderWithIcon]](./PolyDataReader.html "VTK legacy reader(VTK)")
[![ElevationReader Example][ElevationReaderWithIcon]](./ElevationReader.html "Elevation reader(CSV, JPG)")
[![OBJReader Example][OBJReaderWithIcon]](./OBJReader.html "OBJ reader(OBJ, MTL, JPG)")
Expand All @@ -196,7 +197,8 @@ This will allow you to see the some live code running in your browser. Just pick
[PLYWriterWithIcon]: ../docs/gallery/PLYWriterWithIcon.jpg
[STLReaderWithIcon]: ../docs/gallery/STLReaderWithIcon.jpg
[STLWriterWithIcon]: ../docs/gallery/STLWriterWithIcon.jpg
[GLTFImporter]: ../docs/gallery/GLTFImporterWithIcon.jpg
[GLTFImporterWithIcon]: ../docs/gallery/GLTFImporterWithIcon.jpg
[IFCImporterWithIcon]: ../docs/gallery/IFCImporterWithIcon.jpg
[PolyDataReaderWithIcon]: ../docs/gallery/VTKReaderWithIcon.jpg
[ElevationReaderWithIcon]: ../docs/gallery/ElevationReaderWithIcon.jpg
[OBJReaderWithIcon]: ../docs/gallery/OBJReaderWithIcon.jpg
Expand Down
49 changes: 49 additions & 0 deletions Sources/IO/Geometry/IFCImporter/example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import '@kitware/vtk.js/favicon';

// Load the rendering pieces we want to use (for both WebGL and WebGPU)
import '@kitware/vtk.js/Rendering/Profiles/Geometry';

import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
import vtkResourceLoader from '@kitware/vtk.js/IO/Core/ResourceLoader';
import vtkIFCImporter from '@kitware/vtk.js/IO/Geometry/IFCImporter';

// ----------------------------------------------------------------------------
// Example code
// ----------------------------------------------------------------------------

const importer = vtkIFCImporter.newInstance({
mergeGeometries: true,
});

// ----------------------------------------------------------------------------
function update() {
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();

const resetCamera = renderer.resetCamera;
const render = renderWindow.render;

importer.onReady(() => {
importer.importActors(renderer);
resetCamera();
render();
});
}

// ----------------------------------------------------------------------------
// Importer usage example
// ----------------------------------------------------------------------------
vtkResourceLoader
.loadScript('https://cdn.jsdelivr.net/npm/[email protected]/web-ifc-api-iife.js')
.then(() => {
// Pass WebIFC api to vtkIFCImporter
vtkIFCImporter.setIFCAPI(window.WebIFC);

// Trigger data download
importer
.setUrl(
'https://raw.githubusercontent.com/ThatOpen/engine_web-ifc/refs/heads/main/tests/ifcfiles/public/duplex.ifc'
)
.then(update);
});
163 changes: 163 additions & 0 deletions Sources/IO/Geometry/IFCImporter/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
import vtkRenderer from '../../../Rendering/Core/Renderer';
import HtmlDataAccessHelper from '../../Core/DataAccessHelper/HtmlDataAccessHelper';
import HttpDataAccessHelper from '../../Core/DataAccessHelper/HttpDataAccessHelper';
import JSZipDataAccessHelper from '../../Core/DataAccessHelper/JSZipDataAccessHelper';
import LiteHttpDataAccessHelper from '../../Core/DataAccessHelper/LiteHttpDataAccessHelper';

interface IIFCImporterOptions {
compression?: string;
progressCallback?: any;
}

/**
*
*/
export interface IIFCImporterInitialValues {
mergeGeometries?: boolean;
}

type vtkIFCImporterBase = vtkObject &
Omit<
vtkAlgorithm,
| 'getInputData'
| 'setInputData'
| 'setInputConnection'
| 'getInputConnection'
| 'addInputConnection'
| 'addInputData'
>;

export interface vtkIFCImporter extends vtkIFCImporterBase {
/**
*
*/
getBaseURL(): string;

/**
*
*/
getDataAccessHelper():
| HtmlDataAccessHelper
| HttpDataAccessHelper
| JSZipDataAccessHelper
| LiteHttpDataAccessHelper;

/**
* Get the url of the object to load.
*/
getUrl(): string;

/**
* Import actors into the renderer.
* @param {vtkRenderer} renderer The vtkRenderer to import the actors into.
*/
importActors(renderer: vtkRenderer): void;

/**
* Load the object data.
* @param {IIFCImporterOptions} [options]
*/
loadData(options?: IIFCImporterOptions): Promise<any>;

/**
* Parse data.
* @param {String | ArrayBuffer} content The content to parse.
*/
parse(content: string | ArrayBuffer): void;

/**
* Parse data as ArrayBuffer.
* @param {ArrayBuffer} content The content to parse.
*/
parseAsArrayBuffer(content: ArrayBuffer): void;

/**
*
* @param inData
* @param outData
*/
requestData(inData: any, outData: any): void;

/**
*
* @param dataAccessHelper
*/
setDataAccessHelper(
dataAccessHelper:
| HtmlDataAccessHelper
| HttpDataAccessHelper
| JSZipDataAccessHelper
| LiteHttpDataAccessHelper
): boolean;

/**
* Set the url of the object to load.
* @param {String} url the url of the object to load.
* @param {IIFCImporterOptions} [option] The PLY reader options.
*/
setUrl(url: string, option?: IIFCImporterOptions): Promise<string | any>;
}

/**
* Set WebIFC api to be used by vtkIFCImporter
* @param {object} ifcApi
*/
export function setIFCAPI(ifcApi: any): void;

/**
* Method used to decorate a given object (publicAPI+model) with vtkIFCImporter characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {IIFCImporterInitialValues} [initialValues] (default: {})
*/
export function extend(
publicAPI: object,
model: object,
initialValues?: IIFCImporterInitialValues
): void;

/**
* Method used to create a new instance of vtkIFCImporter
* @param {IIFCImporterInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(
initialValues?: IIFCImporterInitialValues
): vtkIFCImporter;

/**
* vtkIFCImporter is a source object that reads Industry Foundation Class(IFC) files.
*
* The vtkIFCImporter is using web-ifc library to parse the IFC file.
*
* @example
* ```js
* import vtkResourceLoader from '@kitware/vtk.js/IO/Core/ResourceLoader';
* import vtkIFCImporter from '@kitware/vtk.js/IO/Geometry/IFCImporter';
*
* function update() {
* importer.onReady(() => {
* importer.importActors(renderer);
* renderer.resetCamera();
* renderWindow.render();
* });
* }
*
* vtkResourceLoader
* .loadScript('https://cdn.jsdelivr.net/npm/[email protected]/web-ifc-api-iife.js')
* .then(() => {
* // Pass WebIFC api to vtkIFCImporter
* vtkIFCImporter.setIFCAPI(window.WebIFC);
*
* // Trigger data download
* importer.setUrl(`${__BASE_PATH__}/data/ifc/house.ifc`).then(update);
* });
* ```
*/
export declare const vtkIFCImporter: {
newInstance: typeof newInstance;
extend: typeof extend;
setIFCAPI: typeof setIFCAPI;
};
export default vtkIFCImporter;
Loading

0 comments on commit 9a1a854

Please sign in to comment.