Skip to content

Commit 6c0c3dd

Browse files
dakerfloryst
authored andcommitted
feat(DiskSource): add vtkDiskSource
1 parent e7705e4 commit 6c0c3dd

File tree

7 files changed

+471
-0
lines changed

7 files changed

+471
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<table>
2+
<tr>
3+
<td>Inner Radius</td>
4+
<td>
5+
<input class="innerRadius" type="range" min="0" max="2.0" step="0.1" value="0.25" />
6+
</td>
7+
</tr>
8+
<tr>
9+
<td>Outer Radius</td>
10+
<td>
11+
<input class="outerRadius" type="range" min="0.5" max="2.0" step="0.1" value="0.5" />
12+
</td>
13+
</tr>
14+
</tr>
15+
<tr>
16+
<td>Radial Resolution</td>
17+
<td>
18+
<input class="radialResolution" type="range" min="1" max="5" step="1" value="1" />
19+
</td>
20+
</tr>
21+
<tr>
22+
<td>Circumferential Resolution</td>
23+
<td>
24+
<input class='circumferentialResolution' type="range" min="6" max="100" step="1" value="6" />
25+
</td>
26+
</tr>
27+
</table>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 vtkDiskSource from '@kitware/vtk.js/Filters/Sources/DiskSource';
9+
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
10+
11+
import controlPanel from './controlPanel.html';
12+
13+
// ----------------------------------------------------------------------------
14+
// Standard rendering code setup
15+
// ----------------------------------------------------------------------------
16+
17+
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
18+
const renderer = fullScreenRenderer.getRenderer();
19+
const renderWindow = fullScreenRenderer.getRenderWindow();
20+
21+
// ----------------------------------------------------------------------------
22+
// Example code
23+
// ----------------------------------------------------------------------------
24+
25+
const diskSource = vtkDiskSource.newInstance();
26+
const actor = vtkActor.newInstance();
27+
const mapper = vtkMapper.newInstance();
28+
29+
actor.setMapper(mapper);
30+
actor.getProperty().setColor(1, 0, 0);
31+
mapper.setInputConnection(diskSource.getOutputPort());
32+
33+
renderer.addActor(actor);
34+
35+
renderer.resetCamera();
36+
renderWindow.render();
37+
38+
// -----------------------------------------------------------
39+
// UI control handling
40+
// -----------------------------------------------------------
41+
42+
fullScreenRenderer.addController(controlPanel);
43+
44+
[
45+
'innerRadius',
46+
'outerRadius',
47+
'radialResolution',
48+
'circumferentialResolution',
49+
].forEach((propertyName) => {
50+
document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
51+
const value = Number(e.target.value);
52+
diskSource.set({ [propertyName]: value });
53+
renderWindow.render();
54+
});
55+
});
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
2+
import { Vector3 } from '../../../types';
3+
4+
/**
5+
*
6+
*/
7+
export interface IDiskSourceInitialValues {
8+
innerRadius?: number;
9+
outerRadius?: number;
10+
center?: Vector3;
11+
normal?: Vector3;
12+
radialResolution?: number;
13+
circumferentialResolution?: number;
14+
pointType?: string;
15+
}
16+
17+
type vtkDiskSourceBase = vtkObject &
18+
Omit<
19+
vtkAlgorithm,
20+
| 'getInputData'
21+
| 'setInputData'
22+
| 'setInputConnection'
23+
| 'getInputConnection'
24+
| 'addInputConnection'
25+
| 'addInputData'
26+
>;
27+
28+
export interface vtkDiskSource extends vtkDiskSourceBase {
29+
/**
30+
* Get the center of the disk.
31+
*/
32+
getCenter(): Vector3;
33+
34+
/**
35+
* Get the circumferential resolution of the disk.
36+
*/
37+
getCircumferentialResolution(): number;
38+
39+
/**
40+
* Get the inner radius of the disk.
41+
*/
42+
getInnerRadius(): number;
43+
44+
/**
45+
* Get the normal of the disk.
46+
*/
47+
getNormal(): Vector3;
48+
49+
/**
50+
* Get the outer radius of the disk.
51+
*/
52+
getOuterRadius(): number;
53+
54+
/**
55+
* Get the point type used for the disk.
56+
*/
57+
getPointType(): string;
58+
59+
/**
60+
* Get the radial resolution of the disk.
61+
*/
62+
getRadialResolution(): number;
63+
64+
/**
65+
* Expose methods
66+
* @param inData
67+
* @param outData
68+
*/
69+
requestData(inData: any, outData: any): void;
70+
71+
/**
72+
* Set the center of the disk.
73+
* @param {Vector3} center
74+
*/
75+
setCenter(center: Vector3): boolean;
76+
77+
/**
78+
* Set the circumferential resolution of the disk.
79+
* @param {number} resolution
80+
*/
81+
setCircumferentialResolution(resolution: number): boolean;
82+
83+
/**
84+
* Set the inner radius of the disk.
85+
* @param {number} radius
86+
*/
87+
setInnerRadius(radius: number): boolean;
88+
89+
/**
90+
* Set the normal of the disk.
91+
* @param {Vector3} normal
92+
*/
93+
setNormal(normal: Vector3): boolean;
94+
95+
/**
96+
* Set the outer radius of the disk.
97+
* @param {number} radius
98+
*/
99+
setOuterRadius(radius: number): boolean;
100+
101+
/**
102+
* Set the point type used for the disk.
103+
* @param {string} type
104+
*/
105+
setPointType(type: string): boolean;
106+
107+
/**
108+
* Set the radial resolution of the disk.
109+
* @param {number} resolution
110+
*/
111+
setRadialResolution(resolution: number): boolean;
112+
}
113+
114+
/**
115+
* Method used to decorate a given object (publicAPI+model) with vtkDiskSource characteristics.
116+
*
117+
* @param publicAPI object on which methods will be bounds (public)
118+
* @param model object on which data structure will be bounds (protected)
119+
* @param {IDiskSourceInitialValues} [initialValues] (default: {})
120+
*/
121+
export function extend(
122+
publicAPI: object,
123+
model: object,
124+
initialValues?: IDiskSourceInitialValues
125+
): void;
126+
127+
/**
128+
* Method used to create a new instance of vtkDiskSource.
129+
* @param {IDiskSourceInitialValues} [initialValues] for pre-setting some of its content
130+
*/
131+
export function newInstance(
132+
initialValues?: IDiskSourceInitialValues
133+
): vtkDiskSource;
134+
135+
/**
136+
* vtkDiskSource creates a polygonal disk with a hole in the center. The disk
137+
* has zero height. The user can specify the inner and outer radius of the disk,
138+
* the radial and circumferential resolution of the polygonal representation,
139+
* and the center and plane normal of the disk (i.e., the center and disk normal
140+
* control the position and orientation of the disk).
141+
*
142+
* @example
143+
* ```js
144+
* import vtkDiskSource from '@kitware/vtk.js/Filters/Sources/DiskSource';
145+
*
146+
* const disk = vtkDiskSource.newInstance({ radius: 1, resolution: 80 });
147+
* const polydata = disk.getOutputData();
148+
* ```
149+
*/
150+
export declare const vtkDiskSource: {
151+
newInstance: typeof newInstance;
152+
extend: typeof extend;
153+
};
154+
export default vtkDiskSource;

0 commit comments

Comments
 (0)