Skip to content

Commit 0d04037

Browse files
committed
feat(PlatonicSolidSource): add vtkPlatonicSolidSource
1 parent 7ca74c6 commit 0d04037

File tree

15 files changed

+699
-0
lines changed

15 files changed

+699
-0
lines changed
4.12 KB
Loading

Documentation/content/examples/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ This will allow you to see the some live code running in your browser. Just pick
144144
[![LineSource Example][LineSource]](./LineSource.html "LineSource")
145145
[![PlaneSource Example][PlaneSource]](./PlaneSource.html "PlaneSource")
146146
[![PointSource Example][PointSource]](./PointSource.html "PointSource")
147+
[![PlatonicSolidSource Example][PlatonicSolidSource]](./PlatonicSolidSource.html "PlatonicSolidSource")
147148
[![SLICSource Example][SLICSource]](./SLICSource.html "SLICSource")
148149
[![SphereSource Example][SphereSource]](./SphereSource.html "SphereSource")
149150
[![WarpScalar Example][WarpScalargif]](./WarpScalar.html "WarpScalar")
@@ -162,6 +163,7 @@ This will allow you to see the some live code running in your browser. Just pick
162163
[LineSource]: ../docs/gallery/LineSource.jpg
163164
[PlaneSource]: ../docs/gallery/PlaneSource.jpg
164165
[PointSource]: ../docs/gallery/PointSource.jpg
166+
[PlatonicSolidSource]: ../docs/gallery/PlatonicSolidSource.jpg
165167
[SLICSource]: ../docs/gallery/SLICSource.jpg
166168
[SphereSource]: ../docs/gallery/SphereSource.gif
167169
[WarpScalargif]: ../docs/gallery/WarpScalar.gif
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export declare enum SolidType {
2+
VTK_SOLID_TETRAHEDRON = 0,
3+
VTK_SOLID_CUBE = 1,
4+
VTK_SOLID_OCTAHEDRON = 2,
5+
VTK_SOLID_ICOSAHEDRON = 3,
6+
VTK_SOLID_DODECAHEDRON = 4,
7+
}
8+
9+
declare const _default: {
10+
SolidType: typeof SolidType;
11+
};
12+
export default _default;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const SolidType = {
2+
VTK_SOLID_TETRAHEDRON: 0,
3+
VTK_SOLID_CUBE: 1,
4+
VTK_SOLID_OCTAHEDRON: 2,
5+
VTK_SOLID_ICOSAHEDRON: 3,
6+
VTK_SOLID_DODECAHEDRON: 4,
7+
};
8+
9+
export default {
10+
SolidType,
11+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<table>
2+
<tr>
3+
<td>Solid Type</td>
4+
<td>
5+
<select name="solidType">
6+
<option value="VTK_SOLID_TETRAHEDRON">Tetrahedron</option>
7+
<option value="VTK_SOLID_CUBE">Cube</option>
8+
<option value="VTK_SOLID_OCTAHEDRON">Octahedron</option>
9+
<option value="VTK_SOLID_DODECAHEDRON">Dodecahedron</option>
10+
<option value="VTK_SOLID_ICOSAHEDRON">Icosahedron</option>
11+
</select>
12+
</td>
13+
</tr>
14+
</table>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
8+
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
9+
import vtkPlatonicSolidSource from '@kitware/vtk.js/Filters/Sources/PlatonicSolidSource';
10+
import { SolidType } from '@kitware/vtk.js/Filters/Sources/PlatonicSolidSource/Constants';
11+
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+
// ----------------------------------------------------------------------------
23+
// Example code
24+
// ----------------------------------------------------------------------------
25+
const platonicSolidSource = vtkPlatonicSolidSource.newInstance({
26+
solidType: SolidType.VTK_SOLID_DODECAHEDRON,
27+
});
28+
29+
const mapper = vtkMapper.newInstance();
30+
const actor = vtkActor.newInstance();
31+
32+
mapper.setInputConnection(platonicSolidSource.getOutputPort());
33+
actor.setMapper(mapper);
34+
35+
renderer.addActor(actor);
36+
renderer.resetCamera();
37+
renderWindow.render();
38+
39+
// -----------------------------------------------------------
40+
// UI control handling
41+
// -----------------------------------------------------------
42+
43+
fullScreenRenderer.addController(controlPanel);
44+
45+
const solidTypeSelect = document.querySelector('select[name="solidType"]');
46+
solidTypeSelect.addEventListener('change', (event) => {
47+
const solidType = event.target.value;
48+
platonicSolidSource.setSolidType(SolidType[solidType.toUpperCase()]);
49+
renderWindow.render();
50+
});
51+
52+
// Set the initial value of the select element
53+
solidTypeSelect.value = 'VTK_SOLID_DODECAHEDRON';
54+
55+
// Render the initial state
56+
renderWindow.render();
57+
58+
// -----------------------------------------------------------
59+
// Make some variables global so that you can inspect and
60+
// modify objects in your browser's developer console:
61+
// -----------------------------------------------------------
62+
63+
global.platonicSolidSource = platonicSolidSource;
64+
global.mapper = mapper;
65+
global.actor = actor;
66+
global.renderer = renderer;
67+
global.renderWindow = renderWindow;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
2+
import { DesiredOutputPrecision } from '../../../Common/DataModel/DataSetAttributes';
3+
import { SolidType } from './Constants';
4+
5+
/**
6+
*
7+
*/
8+
export interface IPlatonicSolidSourceInitialValues {
9+
solidType?: SolidType;
10+
outputPointsPrecision?: DesiredOutputPrecision;
11+
scale?: number;
12+
}
13+
14+
type vtkPlatonicSolidSourceBase = vtkObject &
15+
Omit<
16+
vtkAlgorithm,
17+
| 'getInputData'
18+
| 'setInputData'
19+
| 'setInputConnection'
20+
| 'getInputConnection'
21+
| 'addInputConnection'
22+
| 'addInputData'
23+
>;
24+
25+
export interface vtkPlatonicSolidSource extends vtkPlatonicSolidSourceBase {
26+
/**
27+
* Get the desired output precision.
28+
* @returns {DesiredOutputPrecision}
29+
*/
30+
getOutputPointsPrecision(): DesiredOutputPrecision;
31+
32+
/**
33+
* Get the scale factor of the source.
34+
*/
35+
getScale(): number;
36+
37+
/**
38+
* Get the solid type of the source.
39+
* @returns {SolidType}
40+
*/
41+
getSolidType(): SolidType;
42+
43+
/**
44+
* Request data for the source.
45+
* @param inData
46+
* @param outData
47+
*/
48+
requestData(inData: any, outData: any): void;
49+
50+
/**
51+
* Set the desired output precision.
52+
* @param {DesiredOutputPrecision} outputPointsPrecision
53+
*/
54+
setOutputPointsPrecision(
55+
outputPointsPrecision: DesiredOutputPrecision
56+
): boolean;
57+
58+
/**
59+
* Set the scale factor of the source.
60+
* @param {Number} scale The scale factor.
61+
*/
62+
setScale(scale: number): boolean;
63+
64+
/**
65+
* Set the solid type of the source.
66+
* @param {SolidType} solidType
67+
*/
68+
setSolidType(solidType: SolidType): boolean;
69+
}
70+
71+
/**
72+
* Method used to decorate a given object (publicAPI+model) with vtkPlatonicSolidSource characteristics.
73+
*
74+
* @param publicAPI object on which methods will be bounds (public)
75+
* @param model object on which data structure will be bounds (protected)
76+
* @param {IPlatonicSolidSourceInitialValues} [initialValues] (default: {})
77+
*/
78+
export function extend(
79+
publicAPI: object,
80+
model: object,
81+
initialValues?: IPlatonicSolidSourceInitialValues
82+
): void;
83+
84+
/**
85+
* Method used to create a new instance of vtkPlatonicSolidSource.
86+
* @param {IPlatonicSolidSourceInitialValues} [initialValues] for pre-setting some of its content
87+
*/
88+
export function newInstance(
89+
initialValues?: IPlatonicSolidSourceInitialValues
90+
): vtkPlatonicSolidSource;
91+
92+
/**
93+
* vtkPlatonicSolidSource can generate each of the five Platonic solids:
94+
* tetrahedron, cube, octahedron, icosahedron, and dodecahedron. Each of the
95+
* solids is placed inside a sphere centered at the origin with radius 1.0.
96+
*
97+
* @example
98+
* ```js
99+
* import vtkPlatonicSolidSource from '@kitware/vtk.js/Filters/Sources/RegularPolygonSource';
100+
*
101+
* const regularPolygonSource = vtkPlatonicSolidSource.newInstance();
102+
* const polydata = regularPolygonSource.getOutputData();
103+
* ```
104+
*/
105+
export declare const vtkPlatonicSolidSource: {
106+
newInstance: typeof newInstance;
107+
extend: typeof extend;
108+
};
109+
export default vtkPlatonicSolidSource;

0 commit comments

Comments
 (0)