Skip to content

feat(FrustumSource): add vtkFrustumSource #3301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Documentation/content/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ This will allow you to see the some live code running in your browser. Just pick
[![Cursor3D Example][Cursor3D]](./Cursor3D.html "Cursor3D")
[![CylinderSource Example][CylinderSource]](./CylinderSource.html "CylinderSource")
[![EllipseArcSource Example][EllipseArcSource]](./EllipseArcSource.html "EllipseArcSource")
[![FrustumSource Example][FrustumSource]](./FrustumSource.html "FrustumSource")
[![LineSource Example][LineSource]](./LineSource.html "LineSource")
[![PlaneSource Example][PlaneSource]](./PlaneSource.html "PlaneSource")
[![PointSource Example][PointSource]](./PointSource.html "PointSource")
Expand All @@ -164,6 +165,7 @@ This will allow you to see the some live code running in your browser. Just pick
[Cursor3D]: ../docs/gallery/Cursor3D.gif
[CylinderSource]: ../docs/gallery/CylinderSource.jpg
[EllipseArcSource]: ../docs/gallery/EllipseArcSource.jpg
[FrustumSource]: ../docs/gallery/FrustumSource.jpg
[LineSource]: ../docs/gallery/LineSource.jpg
[PlaneSource]: ../docs/gallery/PlaneSource.jpg
[PointSource]: ../docs/gallery/PointSource.jpg
Expand Down
15 changes: 15 additions & 0 deletions Sources/Filters/Sources/FrustumSource/example/controlPanel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<table>
<tr>
<td>Shrink Factor</td>
<td colspan="3">
<input class='shrinkFactor' type="range" min="0.1" max="1" step="0.1" value="0.9" />
</td>
</tr>
<tr>
<td>Show Lines</td>
<td colspan="3">
<input class='showLines' type="checkbox" checked />
</td>
</tr>
</table>

85 changes: 85 additions & 0 deletions Sources/Filters/Sources/FrustumSource/example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import '@kitware/vtk.js/favicon';

// Load the rendering pieces we want to use (for both WebGL and WebGPU)
import '@kitware/vtk.js/Rendering/Profiles/Geometry';

import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
import vtkProperty from '@kitware/vtk.js/Rendering/Core/Property';
import vtkCamera from '@kitware/vtk.js/Rendering/Core/Camera';
import vtkPlanes from '@kitware/vtk.js/Common/DataModel/Planes';

Check failure on line 11 in Sources/Filters/Sources/FrustumSource/example/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-24.04 and node 22

Unable to resolve path to module '@kitware/vtk.js/Common/DataModel/Planes'
import vtkFrustumSource from '@kitware/vtk.js/Filters/Sources/FrustumSource';
import vtkShrinkPolyData from '@kitware/vtk.js/Filters/General/ShrinkPolyData';
import controlPanel from './controlPanel.html';

// ----------------------------------------------------------------------------
// Standard rendering code setup
// ----------------------------------------------------------------------------

const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();

// ----------------------------------------------------------------------------
// Example code
// ----------------------------------------------------------------------------

const frustum = vtkFrustumSource.newInstance();
const actor = vtkActor.newInstance();
const mapper = vtkMapper.newInstance();

const camera = vtkCamera.newInstance();
camera.setClippingRange(0.1, 0.4);

const planesArray = camera.getFrustumPlanes(1.0);
const planes = vtkPlanes.newInstance();
planes.setFrustumPlanes(planesArray);

frustum.setPlanes(planes);
frustum.setShowLines(false);

const backProperty = vtkProperty.newInstance();
backProperty.setColor(1, 1, 50 / 255);

const shrink = vtkShrinkPolyData.newInstance();
shrink.setShrinkFactor(0.9);
shrink.setInputConnection(frustum.getOutputPort());
mapper.setInputConnection(shrink.getOutputPort());
mapper.setScalarVisibility(false);
actor.setMapper(mapper);
actor.getProperty().setColor(255 / 255, 99 / 255, 71 / 255);
actor.getProperty().setEdgeVisibility(true);
actor.setBackfaceProperty(backProperty);
renderer.addActor(actor);

renderer.getActiveCamera().setPosition(1, 0, 0);
renderer.getActiveCamera().setFocalPoint(0, 0, 0);
renderer.getActiveCamera().setViewUp(0, 1, 0);
renderer.getActiveCamera().azimuth(30);
renderer.getActiveCamera().elevation(30);

renderer.resetCamera();
renderWindow.render();

// -----------------------------------------------------------
// UI control handling
// -----------------------------------------------------------

fullScreenRenderer.addController(controlPanel);

['showLines'].forEach((propertyName) => {
document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
const value = e.target.checked;
frustum.set({ [propertyName]: value });
renderWindow.render();
});
});

['shrinkFactor'].forEach((propertyName) => {
document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
const value = Number(e.target.value);
shrink.set({ [propertyName]: value });
renderWindow.render();
});
});
111 changes: 111 additions & 0 deletions Sources/Filters/Sources/FrustumSource/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { DesiredOutputPrecision } from '../../../Common/DataModel/DataSetAttributes';
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
import vtkPlanes from '../../../Common/DataModel/Planes';

/**
*
*/
export interface IFrustumSourceInitialValues {
planes?: vtkPlanes;
showLines?: boolean;
outputPointsPrecision?: DesiredOutputPrecision;
}

type vtkFrustumSourceBase = vtkObject &
Omit<
vtkAlgorithm,
| 'getInputData'
| 'setInputData'
| 'setInputConnection'
| 'getInputConnection'
| 'addInputConnection'
| 'addInputData'
>;

export interface vtkFrustumSource extends vtkFrustumSourceBase {
/**
* Get the output points precision.
*/
getOutputPointsPrecision(): DesiredOutputPrecision;

/**
* Get the planes defining the frustum.
*/
getPlanes(): vtkPlanes;

/**
* Get whether to show lines.
*/
getShowLines(): boolean;

/**
*
* @param inData
* @param outData
*/
requestData(inData: any, outData: any): void;

/**
* Set the output points precision.
* @param {DesiredOutputPrecision} precision
*/
setOutputPointsPrecision(precision: DesiredOutputPrecision): boolean;

/**
* Set the planes defining the frustum.
* @param {vtkPlanes} planes
*/
setPlanes(planes: vtkPlanes): boolean;

/**
* Set whether to show lines.
* @param {Boolean} showLines
*/
setShowLines(showLines: boolean): boolean;
}

/**
* Method used to decorate a given object (publicAPI+model) with vtkFrustumSource characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {IFrustumSourceInitialValues} [initialValues] (default: {})
*/
export function extend(
publicAPI: object,
model: object,
initialValues?: IFrustumSourceInitialValues
): void;

/**
* Method used to create a new instance of vtkFrustumSource.
* @param {IFrustumSourceInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(
initialValues?: IFrustumSourceInitialValues
): vtkFrustumSource;

/**
* vtkFrustumSource creates a frustum defines by a set of planes. The frustum is
* represented with four-sided polygons. It is possible to specify extra lines
* to better visualize the field of view.
*
* @example
* ```js
* import vtkFrustumSource from '@kitware/vtk.js/Filters/Sources/FrustumSource';
*
* const frustum = vtkFrustumSource.newInstance();
* const camera = vtkCamera.newInstance();
* camera.setClippingRange(0.1, 0.4);
* const planesArray = camera.getFrustumPlanes(1.0);
* const planes = vtkPlanes.newInstance();
* planes.setFrustumPlanes(planesArray);
* frustum.setPlanes(planes);
* frustum.setShowLines(false);
* ```
*/
export declare const vtkFrustumSource: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkFrustumSource;
Loading
Loading