Skip to content

Commit 1f92f84

Browse files
dakerfloryst
authored andcommitted
feat(IFCImporter): add vtkIFCImporter
This PR adds support for IFC format, the importer allows to merge geometries to reduce the number of actors in the scene. fixes #3156
1 parent 83f04ac commit 1f92f84

File tree

6 files changed

+539
-2
lines changed

6 files changed

+539
-2
lines changed
26.2 KB
Loading

Documentation/content/examples/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ This will allow you to see the some live code running in your browser. Just pick
173173
[![PLYWriter Example][PLYWriterWithIcon]](./PLYWriter.html "PLY writer(ply)")
174174
[![STLReader Example][STLReaderWithIcon]](./STLReader.html "STL reader(stl)")
175175
[![STLWriter Example][STLWriterWithIcon]](./STLWriter.html "STL writer(stl)")
176-
[![GLTFImporter Example][GLTFImporter]](./GLTFImporter.html "GLTF importer(gltf, glb)")
176+
[![GLTFImporter Example][GLTFImporterWithIcon]](./GLTFImporter.html "GLTF importer(gltf, glb)")
177+
[![IFCImporter Example][IFCImporterWithIcon]](./IFCImporter.html "IFC importer(ifc)")
177178
[![PolyDataReader Example][PolyDataReaderWithIcon]](./PolyDataReader.html "VTK legacy reader(VTK)")
178179
[![ElevationReader Example][ElevationReaderWithIcon]](./ElevationReader.html "Elevation reader(CSV, JPG)")
179180
[![OBJReader Example][OBJReaderWithIcon]](./OBJReader.html "OBJ reader(OBJ, MTL, JPG)")
@@ -196,7 +197,8 @@ This will allow you to see the some live code running in your browser. Just pick
196197
[PLYWriterWithIcon]: ../docs/gallery/PLYWriterWithIcon.jpg
197198
[STLReaderWithIcon]: ../docs/gallery/STLReaderWithIcon.jpg
198199
[STLWriterWithIcon]: ../docs/gallery/STLWriterWithIcon.jpg
199-
[GLTFImporter]: ../docs/gallery/GLTFImporterWithIcon.jpg
200+
[GLTFImporterWithIcon]: ../docs/gallery/GLTFImporterWithIcon.jpg
201+
[IFCImporterWithIcon]: ../docs/gallery/IFCImporterWithIcon.jpg
200202
[PolyDataReaderWithIcon]: ../docs/gallery/VTKReaderWithIcon.jpg
201203
[ElevationReaderWithIcon]: ../docs/gallery/ElevationReaderWithIcon.jpg
202204
[OBJReaderWithIcon]: ../docs/gallery/OBJReaderWithIcon.jpg
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import '@kitware/vtk.js/favicon';
2+
3+
// Load the rendering pieces we want to use (for both WebGL and WebGPU)
4+
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
5+
6+
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
7+
import vtkResourceLoader from '@kitware/vtk.js/IO/Core/ResourceLoader';
8+
import vtkIFCImporter from '@kitware/vtk.js/IO/Geometry/IFCImporter';
9+
10+
// ----------------------------------------------------------------------------
11+
// Example code
12+
// ----------------------------------------------------------------------------
13+
14+
const importer = vtkIFCImporter.newInstance({
15+
mergeGeometries: true,
16+
});
17+
18+
// ----------------------------------------------------------------------------
19+
function update() {
20+
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
21+
const renderer = fullScreenRenderer.getRenderer();
22+
const renderWindow = fullScreenRenderer.getRenderWindow();
23+
24+
const resetCamera = renderer.resetCamera;
25+
const render = renderWindow.render;
26+
27+
importer.onReady(() => {
28+
importer.importActors(renderer);
29+
resetCamera();
30+
render();
31+
});
32+
}
33+
34+
// ----------------------------------------------------------------------------
35+
// Importer usage example
36+
// ----------------------------------------------------------------------------
37+
vtkResourceLoader
38+
.loadScript('https://cdn.jsdelivr.net/npm/[email protected]/web-ifc-api-iife.js')
39+
.then(() => {
40+
// Pass WebIFC api to vtkIFCImporter
41+
vtkIFCImporter.setIFCAPI(window.WebIFC);
42+
43+
// Trigger data download
44+
importer
45+
.setUrl(
46+
'https://raw.githubusercontent.com/ThatOpen/engine_web-ifc/refs/heads/main/tests/ifcfiles/public/duplex.ifc'
47+
)
48+
.then(update);
49+
});
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
2+
import vtkRenderer from '../../../Rendering/Core/Renderer';
3+
import HtmlDataAccessHelper from '../../Core/DataAccessHelper/HtmlDataAccessHelper';
4+
import HttpDataAccessHelper from '../../Core/DataAccessHelper/HttpDataAccessHelper';
5+
import JSZipDataAccessHelper from '../../Core/DataAccessHelper/JSZipDataAccessHelper';
6+
import LiteHttpDataAccessHelper from '../../Core/DataAccessHelper/LiteHttpDataAccessHelper';
7+
8+
interface IIFCImporterOptions {
9+
compression?: string;
10+
progressCallback?: any;
11+
}
12+
13+
/**
14+
*
15+
*/
16+
export interface IIFCImporterInitialValues {
17+
mergeGeometries?: boolean;
18+
}
19+
20+
type vtkIFCImporterBase = vtkObject &
21+
Omit<
22+
vtkAlgorithm,
23+
| 'getInputData'
24+
| 'setInputData'
25+
| 'setInputConnection'
26+
| 'getInputConnection'
27+
| 'addInputConnection'
28+
| 'addInputData'
29+
>;
30+
31+
export interface vtkIFCImporter extends vtkIFCImporterBase {
32+
/**
33+
*
34+
*/
35+
getBaseURL(): string;
36+
37+
/**
38+
*
39+
*/
40+
getDataAccessHelper():
41+
| HtmlDataAccessHelper
42+
| HttpDataAccessHelper
43+
| JSZipDataAccessHelper
44+
| LiteHttpDataAccessHelper;
45+
46+
/**
47+
* Get the url of the object to load.
48+
*/
49+
getUrl(): string;
50+
51+
/**
52+
* Import actors into the renderer.
53+
* @param {vtkRenderer} renderer The vtkRenderer to import the actors into.
54+
*/
55+
importActors(renderer: vtkRenderer): void;
56+
57+
/**
58+
* Load the object data.
59+
* @param {IIFCImporterOptions} [options]
60+
*/
61+
loadData(options?: IIFCImporterOptions): Promise<any>;
62+
63+
/**
64+
* Parse data.
65+
* @param {String | ArrayBuffer} content The content to parse.
66+
*/
67+
parse(content: string | ArrayBuffer): void;
68+
69+
/**
70+
* Parse data as ArrayBuffer.
71+
* @param {ArrayBuffer} content The content to parse.
72+
*/
73+
parseAsArrayBuffer(content: ArrayBuffer): void;
74+
75+
/**
76+
*
77+
* @param inData
78+
* @param outData
79+
*/
80+
requestData(inData: any, outData: any): void;
81+
82+
/**
83+
*
84+
* @param dataAccessHelper
85+
*/
86+
setDataAccessHelper(
87+
dataAccessHelper:
88+
| HtmlDataAccessHelper
89+
| HttpDataAccessHelper
90+
| JSZipDataAccessHelper
91+
| LiteHttpDataAccessHelper
92+
): boolean;
93+
94+
/**
95+
* Set the url of the object to load.
96+
* @param {String} url the url of the object to load.
97+
* @param {IIFCImporterOptions} [option] The PLY reader options.
98+
*/
99+
setUrl(url: string, option?: IIFCImporterOptions): Promise<string | any>;
100+
}
101+
102+
/**
103+
* Set WebIFC api to be used by vtkIFCImporter
104+
* @param {object} ifcApi
105+
*/
106+
export function setIFCAPI(ifcApi: any): void;
107+
108+
/**
109+
* Method used to decorate a given object (publicAPI+model) with vtkIFCImporter characteristics.
110+
*
111+
* @param publicAPI object on which methods will be bounds (public)
112+
* @param model object on which data structure will be bounds (protected)
113+
* @param {IIFCImporterInitialValues} [initialValues] (default: {})
114+
*/
115+
export function extend(
116+
publicAPI: object,
117+
model: object,
118+
initialValues?: IIFCImporterInitialValues
119+
): void;
120+
121+
/**
122+
* Method used to create a new instance of vtkIFCImporter
123+
* @param {IIFCImporterInitialValues} [initialValues] for pre-setting some of its content
124+
*/
125+
export function newInstance(
126+
initialValues?: IIFCImporterInitialValues
127+
): vtkIFCImporter;
128+
129+
/**
130+
* vtkIFCImporter is a source object that reads Industry Foundation Class(IFC) files.
131+
*
132+
* The vtkIFCImporter is using web-ifc library to parse the IFC file.
133+
*
134+
* @example
135+
* ```js
136+
* import vtkResourceLoader from '@kitware/vtk.js/IO/Core/ResourceLoader';
137+
* import vtkIFCImporter from '@kitware/vtk.js/IO/Geometry/IFCImporter';
138+
*
139+
* function update() {
140+
* importer.onReady(() => {
141+
* importer.importActors(renderer);
142+
* renderer.resetCamera();
143+
* renderWindow.render();
144+
* });
145+
* }
146+
*
147+
* vtkResourceLoader
148+
* .loadScript('https://cdn.jsdelivr.net/npm/[email protected]/web-ifc-api-iife.js')
149+
* .then(() => {
150+
* // Pass WebIFC api to vtkIFCImporter
151+
* vtkIFCImporter.setIFCAPI(window.WebIFC);
152+
*
153+
* // Trigger data download
154+
* importer.setUrl(`${__BASE_PATH__}/data/ifc/house.ifc`).then(update);
155+
* });
156+
* ```
157+
*/
158+
export declare const vtkIFCImporter: {
159+
newInstance: typeof newInstance;
160+
extend: typeof extend;
161+
setIFCAPI: typeof setIFCAPI;
162+
};
163+
export default vtkIFCImporter;

0 commit comments

Comments
 (0)