Skip to content

Commit 01d527d

Browse files
committed
feat(ShrinkPolyData): add vtkShrinkPolyData
1 parent 06b05f9 commit 01d527d

File tree

6 files changed

+546
-0
lines changed

6 files changed

+546
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<table>
2+
<tr>
3+
<td>Shrink Factor</td>
4+
<td colspan="3">
5+
<input class='shrinkFactor' type="range" min="0.1" max="1" step="0.1" value="0.25" />
6+
</td>
7+
</tr>
8+
</table>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
import '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper';
6+
7+
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
8+
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
9+
import vtkHttpDataSetReader from '@kitware/vtk.js/IO/Core/HttpDataSetReader';
10+
import vtkShrinkPolyData from '@kitware/vtk.js/Filters/General/ShrinkPolyData';
11+
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
12+
import controlPanel from './controlPanel.html';
13+
14+
// ----------------------------------------------------------------------------
15+
// Standard rendering code setup
16+
// ----------------------------------------------------------------------------
17+
18+
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
19+
const renderer = fullScreenRenderer.getRenderer();
20+
const renderWindow = fullScreenRenderer.getRenderWindow();
21+
22+
fullScreenRenderer.addController(controlPanel);
23+
24+
// ----------------------------------------------------------------------------
25+
// Example code
26+
// ----------------------------------------------------------------------------
27+
const shrinkPolyData = vtkShrinkPolyData.newInstance();
28+
shrinkPolyData.setShrinkFactor(0.25);
29+
30+
const actor = vtkActor.newInstance();
31+
const mapper = vtkMapper.newInstance();
32+
mapper.setInputConnection(shrinkPolyData.getOutputPort());
33+
actor.setMapper(mapper);
34+
35+
const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true });
36+
shrinkPolyData.setInputConnection(reader.getOutputPort());
37+
38+
reader.setUrl(`${__BASE_PATH__}/data/cow.vtp`).then(() => {
39+
reader.loadData().then(() => {
40+
renderer.addActor(actor);
41+
renderer.resetCamera();
42+
renderWindow.render();
43+
});
44+
});
45+
46+
['shrinkFactor'].forEach((propertyName) => {
47+
document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
48+
const value = Number(e.target.value);
49+
shrinkPolyData.set({ [propertyName]: value });
50+
renderWindow.render();
51+
});
52+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { DesiredOutputPrecision } from '../../../Common/DataModel/DataSetAttributes';
2+
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
3+
4+
/**
5+
*
6+
*/
7+
export interface IShrinkPolyDataInitialValues {
8+
shrinkFactor?: number;
9+
}
10+
11+
type vtkShrinkPolyDataBase = vtkObject & vtkAlgorithm;
12+
13+
export interface vtkShrinkPolyData extends vtkShrinkPolyDataBase {
14+
/**
15+
* Expose methods
16+
* @param inData
17+
* @param outData
18+
*/
19+
requestData(inData: any, outData: any): void;
20+
21+
/**
22+
* Get the shrink factor.
23+
*/
24+
getShrinkFactor(): number;
25+
26+
/**
27+
* Set the shrink factor.
28+
* @param {Number} shrinkFactor
29+
*/
30+
setShrinkFactor(shrinkFactor: number): boolean;
31+
}
32+
33+
/**
34+
* Method used to decorate a given object (publicAPI+model) with vtkShrinkPolyData characteristics.
35+
*
36+
* @param publicAPI object on which methods will be bounds (public)
37+
* @param model object on which data structure will be bounds (protected)
38+
* @param {IShrinkPolyDataInitialValues} [initialValues] (default: {})
39+
*/
40+
export function extend(
41+
publicAPI: object,
42+
model: object,
43+
initialValues?: IShrinkPolyDataInitialValues
44+
): void;
45+
46+
/**
47+
* Method used to create a new instance of vtkShrinkPolyData.
48+
* @param {IShrinkPolyDataInitialValues} [initialValues] for pre-setting some of its content
49+
*/
50+
export function newInstance(
51+
initialValues?: IShrinkPolyDataInitialValues
52+
): vtkShrinkPolyData;
53+
54+
/**
55+
* vtkShrinkPolyData shrinks cells composing a polygonal dataset (e.g.,
56+
* vertices, lines, polygons, and triangle strips) towards their centroid. The
57+
* centroid of a cell is computed as the average position of the cell points.
58+
* Shrinking results in disconnecting the cells from one another. The output
59+
* dataset type of this filter is polygonal data.
60+
*
61+
* During execution the filter passes its input cell data to its output. Point
62+
* data attributes are copied to the points created during the shrinking
63+
* process.
64+
*/
65+
export declare const vtkShrinkPolyData: {
66+
newInstance: typeof newInstance;
67+
extend: typeof extend;
68+
};
69+
export default vtkShrinkPolyData;

0 commit comments

Comments
 (0)