Skip to content

Commit 7e25ebd

Browse files
committed
feat(FrustumSource): add vtkFrustumSource
1 parent 7ca74c6 commit 7e25ebd

File tree

6 files changed

+490
-0
lines changed

6 files changed

+490
-0
lines changed
6.08 KB
Loading

Documentation/content/examples/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ This will allow you to see the some live code running in your browser. Just pick
141141
[![CubeSource Example][CubeSource]](./CubeSource.html "CubeSource")
142142
[![Cursor3D Example][Cursor3D]](./Cursor3D.html "Cursor3D")
143143
[![CylinderSource Example][CylinderSource]](./CylinderSource.html "CylinderSource")
144+
[![FrustumSource Example][FrustumSource]](./FrustumSource.html "FrustumSource")
144145
[![LineSource Example][LineSource]](./LineSource.html "LineSource")
145146
[![PlaneSource Example][PlaneSource]](./PlaneSource.html "PlaneSource")
146147
[![PointSource Example][PointSource]](./PointSource.html "PointSource")
@@ -159,6 +160,7 @@ This will allow you to see the some live code running in your browser. Just pick
159160
[CubeSource]: ../docs/gallery/CubeSource.jpg
160161
[Cursor3D]: ../docs/gallery/Cursor3D.gif
161162
[CylinderSource]: ../docs/gallery/CylinderSource.jpg
163+
[FrustumSource]: ../docs/gallery/FrustumSource.jpg
162164
[LineSource]: ../docs/gallery/LineSource.jpg
163165
[PlaneSource]: ../docs/gallery/PlaneSource.jpg
164166
[PointSource]: ../docs/gallery/PointSource.jpg
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.9" />
6+
</td>
7+
</tr>
8+
<tr>
9+
<td>Show Lines</td>
10+
<td colspan="3">
11+
<input class='showLines' type="checkbox" checked />
12+
</td>
13+
</tr>
14+
</table>
15+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 vtkProperty from '@kitware/vtk.js/Rendering/Core/Property';
10+
import vtkCamera from '@kitware/vtk.js/Rendering/Core/Camera';
11+
import vtkPlanes from '@kitware/vtk.js/Common/DataModel/Planes';
12+
import vtkFrustumSource from '@kitware/vtk.js/Filters/Sources/FrustumSource';
13+
import vtkShrinkPolyData from '@kitware/vtk.js/Filters/General/ShrinkPolyData';
14+
import controlPanel from './controlPanel.html';
15+
16+
// ----------------------------------------------------------------------------
17+
// Standard rendering code setup
18+
// ----------------------------------------------------------------------------
19+
20+
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
21+
const renderer = fullScreenRenderer.getRenderer();
22+
const renderWindow = fullScreenRenderer.getRenderWindow();
23+
24+
// ----------------------------------------------------------------------------
25+
// Example code
26+
// ----------------------------------------------------------------------------
27+
28+
const frustum = vtkFrustumSource.newInstance();
29+
const actor = vtkActor.newInstance();
30+
const mapper = vtkMapper.newInstance();
31+
32+
const camera = vtkCamera.newInstance();
33+
camera.setClippingRange(0.1, 0.4);
34+
35+
const planesArray = camera.getFrustumPlanes(1.0);
36+
const planes = vtkPlanes.newInstance();
37+
planes.setFrustumPlanes(planesArray);
38+
39+
frustum.setPlanes(planes);
40+
frustum.setShowLines(false);
41+
42+
const backProperty = vtkProperty.newInstance();
43+
backProperty.setColor(1, 1, 50 / 255);
44+
45+
const shrink = vtkShrinkPolyData.newInstance();
46+
shrink.setShrinkFactor(0.9);
47+
shrink.setInputConnection(frustum.getOutputPort());
48+
mapper.setInputConnection(shrink.getOutputPort());
49+
mapper.setScalarVisibility(false);
50+
actor.setMapper(mapper);
51+
actor.getProperty().setColor(255 / 255, 99 / 255, 71 / 255);
52+
actor.getProperty().setEdgeVisibility(true);
53+
actor.setBackfaceProperty(backProperty);
54+
renderer.addActor(actor);
55+
56+
renderer.getActiveCamera().setPosition(1, 0, 0);
57+
renderer.getActiveCamera().setFocalPoint(0, 0, 0);
58+
renderer.getActiveCamera().setViewUp(0, 1, 0);
59+
renderer.getActiveCamera().azimuth(30);
60+
renderer.getActiveCamera().elevation(30);
61+
62+
renderer.resetCamera();
63+
renderWindow.render();
64+
65+
// -----------------------------------------------------------
66+
// UI control handling
67+
// -----------------------------------------------------------
68+
69+
fullScreenRenderer.addController(controlPanel);
70+
71+
['showLines'].forEach((propertyName) => {
72+
document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
73+
const value = e.target.checked;
74+
frustum.set({ [propertyName]: value });
75+
renderWindow.render();
76+
});
77+
});
78+
79+
['shrinkFactor'].forEach((propertyName) => {
80+
document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
81+
const value = Number(e.target.value);
82+
shrink.set({ [propertyName]: value });
83+
renderWindow.render();
84+
});
85+
});
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { DesiredOutputPrecision } from '../../../Common/DataModel/DataSetAttributes';
2+
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
3+
import vtkPlanes from '../../../Common/DataModel/Planes';
4+
5+
/**
6+
*
7+
*/
8+
export interface IFrustumSourceInitialValues {
9+
planes?: vtkPlanes;
10+
showLines?: boolean;
11+
outputPointsPrecision?: DesiredOutputPrecision;
12+
}
13+
14+
type vtkFrustumSourceBase = vtkObject &
15+
Omit<
16+
vtkAlgorithm,
17+
| 'getInputData'
18+
| 'setInputData'
19+
| 'setInputConnection'
20+
| 'getInputConnection'
21+
| 'addInputConnection'
22+
| 'addInputData'
23+
>;
24+
25+
export interface vtkFrustumSource extends vtkFrustumSourceBase {
26+
/**
27+
* Get the output points precision.
28+
*/
29+
getOutputPointsPrecision(): DesiredOutputPrecision;
30+
31+
/**
32+
* Get the planes defining the frustum.
33+
*/
34+
getPlanes(): vtkPlanes;
35+
36+
/**
37+
* Get whether to show lines.
38+
*/
39+
getShowLines(): boolean;
40+
41+
/**
42+
*
43+
* @param inData
44+
* @param outData
45+
*/
46+
requestData(inData: any, outData: any): void;
47+
48+
/**
49+
* Set the output points precision.
50+
* @param {DesiredOutputPrecision} precision
51+
*/
52+
setOutputPointsPrecision(precision: DesiredOutputPrecision): boolean;
53+
54+
/**
55+
* Set the planes defining the frustum.
56+
* @param {vtkPlanes} planes
57+
*/
58+
setPlanes(planes: vtkPlanes): boolean;
59+
60+
/**
61+
* Set whether to show lines.
62+
* @param {Boolean} showLines
63+
*/
64+
setShowLines(showLines: boolean): boolean;
65+
}
66+
67+
/**
68+
* Method used to decorate a given object (publicAPI+model) with vtkFrustumSource characteristics.
69+
*
70+
* @param publicAPI object on which methods will be bounds (public)
71+
* @param model object on which data structure will be bounds (protected)
72+
* @param {IFrustumSourceInitialValues} [initialValues] (default: {})
73+
*/
74+
export function extend(
75+
publicAPI: object,
76+
model: object,
77+
initialValues?: IFrustumSourceInitialValues
78+
): void;
79+
80+
/**
81+
* Method used to create a new instance of vtkFrustumSource.
82+
* @param {IFrustumSourceInitialValues} [initialValues] for pre-setting some of its content
83+
*/
84+
export function newInstance(
85+
initialValues?: IFrustumSourceInitialValues
86+
): vtkFrustumSource;
87+
88+
/**
89+
* vtkFrustumSource creates a frustum defines by a set of planes. The frustum is
90+
* represented with four-sided polygons. It is possible to specify extra lines
91+
* to better visualize the field of view.
92+
*
93+
* @example
94+
* ```js
95+
* import vtkFrustumSource from '@kitware/vtk.js/Filters/Sources/FrustumSource';
96+
*
97+
* const frustum = vtkFrustumSource.newInstance();
98+
* const camera = vtkCamera.newInstance();
99+
* camera.setClippingRange(0.1, 0.4);
100+
* const planesArray = camera.getFrustumPlanes(1.0);
101+
* const planes = vtkPlanes.newInstance();
102+
* planes.setFrustumPlanes(planesArray);
103+
* frustum.setPlanes(planes);
104+
* frustum.setShowLines(false);
105+
* ```
106+
*/
107+
export declare const vtkFrustumSource: {
108+
newInstance: typeof newInstance;
109+
extend: typeof extend;
110+
};
111+
export default vtkFrustumSource;

0 commit comments

Comments
 (0)