Skip to content

feat(PlatonicSolidSource): add vtkPlatonicSolidSource #3308

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

Merged
merged 1 commit into from
Aug 12, 2025
Merged
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
[![LineSource Example][LineSource]](./LineSource.html "LineSource")
[![PlaneSource Example][PlaneSource]](./PlaneSource.html "PlaneSource")
[![PointSource Example][PointSource]](./PointSource.html "PointSource")
[![PlatonicSolidSource Example][PlatonicSolidSource]](./PlatonicSolidSource.html "PlatonicSolidSource")
[![SLICSource Example][SLICSource]](./SLICSource.html "SLICSource")
[![SphereSource Example][SphereSource]](./SphereSource.html "SphereSource")
[![WarpScalar Example][WarpScalargif]](./WarpScalar.html "WarpScalar")
Expand All @@ -162,6 +163,7 @@ This will allow you to see the some live code running in your browser. Just pick
[LineSource]: ../docs/gallery/LineSource.jpg
[PlaneSource]: ../docs/gallery/PlaneSource.jpg
[PointSource]: ../docs/gallery/PointSource.jpg
[PlatonicSolidSource]: ../docs/gallery/PlatonicSolidSource.jpg
[SLICSource]: ../docs/gallery/SLICSource.jpg
[SphereSource]: ../docs/gallery/SphereSource.gif
[WarpScalargif]: ../docs/gallery/WarpScalar.gif
Expand Down
12 changes: 12 additions & 0 deletions Sources/Filters/Sources/PlatonicSolidSource/Constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export declare enum SolidType {
VTK_SOLID_TETRAHEDRON = 0,
VTK_SOLID_CUBE = 1,
VTK_SOLID_OCTAHEDRON = 2,
VTK_SOLID_ICOSAHEDRON = 3,
VTK_SOLID_DODECAHEDRON = 4,
}

declare const _default: {
SolidType: typeof SolidType;
};
export default _default;
11 changes: 11 additions & 0 deletions Sources/Filters/Sources/PlatonicSolidSource/Constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const SolidType = {
VTK_SOLID_TETRAHEDRON: 0,
VTK_SOLID_CUBE: 1,
VTK_SOLID_OCTAHEDRON: 2,
VTK_SOLID_ICOSAHEDRON: 3,
VTK_SOLID_DODECAHEDRON: 4,
};

export default {
SolidType,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<table>
<tr>
<td>Solid Type</td>
<td>
<select name="solidType">
<option value="VTK_SOLID_TETRAHEDRON">Tetrahedron</option>
<option value="VTK_SOLID_CUBE">Cube</option>
<option value="VTK_SOLID_OCTAHEDRON">Octahedron</option>
<option value="VTK_SOLID_DODECAHEDRON">Dodecahedron</option>
<option value="VTK_SOLID_ICOSAHEDRON">Icosahedron</option>
</select>
</td>
</tr>
</table>
67 changes: 67 additions & 0 deletions Sources/Filters/Sources/PlatonicSolidSource/example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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 vtkPlatonicSolidSource from '@kitware/vtk.js/Filters/Sources/PlatonicSolidSource';
import { SolidType } from '@kitware/vtk.js/Filters/Sources/PlatonicSolidSource/Constants';

import controlPanel from './controlPanel.html';

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

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

// ----------------------------------------------------------------------------
// Example code
// ----------------------------------------------------------------------------
const platonicSolidSource = vtkPlatonicSolidSource.newInstance({
solidType: SolidType.VTK_SOLID_DODECAHEDRON,
});

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

mapper.setInputConnection(platonicSolidSource.getOutputPort());
actor.setMapper(mapper);

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

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

fullScreenRenderer.addController(controlPanel);

const solidTypeSelect = document.querySelector('select[name="solidType"]');
solidTypeSelect.addEventListener('change', (event) => {
const solidType = event.target.value;
platonicSolidSource.setSolidType(SolidType[solidType.toUpperCase()]);
renderWindow.render();
});

// Set the initial value of the select element
solidTypeSelect.value = 'VTK_SOLID_DODECAHEDRON';

// Render the initial state
renderWindow.render();

// -----------------------------------------------------------
// Make some variables global so that you can inspect and
// modify objects in your browser's developer console:
// -----------------------------------------------------------

global.platonicSolidSource = platonicSolidSource;
global.mapper = mapper;
global.actor = actor;
global.renderer = renderer;
global.renderWindow = renderWindow;
109 changes: 109 additions & 0 deletions Sources/Filters/Sources/PlatonicSolidSource/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
import { DesiredOutputPrecision } from '../../../Common/DataModel/DataSetAttributes';
import { SolidType } from './Constants';

/**
*
*/
export interface IPlatonicSolidSourceInitialValues {
solidType?: SolidType;
outputPointsPrecision?: DesiredOutputPrecision;
scale?: number;
}

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

export interface vtkPlatonicSolidSource extends vtkPlatonicSolidSourceBase {
/**
* Get the desired output precision.
* @returns {DesiredOutputPrecision}
*/
getOutputPointsPrecision(): DesiredOutputPrecision;

/**
* Get the scale factor of the source.
*/
getScale(): number;

/**
* Get the solid type of the source.
* @returns {SolidType}
*/
getSolidType(): SolidType;

/**
* Request data for the source.
* @param inData
* @param outData
*/
requestData(inData: any, outData: any): void;

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

/**
* Set the scale factor of the source.
* @param {Number} scale The scale factor.
*/
setScale(scale: number): boolean;

/**
* Set the solid type of the source.
* @param {SolidType} solidType
*/
setSolidType(solidType: SolidType): boolean;
}

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

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

/**
* vtkPlatonicSolidSource can generate each of the five Platonic solids:
* tetrahedron, cube, octahedron, icosahedron, and dodecahedron. Each of the
* solids is placed inside a sphere centered at the origin with radius 1.0.
*
* @example
* ```js
* import vtkPlatonicSolidSource from '@kitware/vtk.js/Filters/Sources/RegularPolygonSource';
*
* const regularPolygonSource = vtkPlatonicSolidSource.newInstance();
* const polydata = regularPolygonSource.getOutputData();
* ```
*/
export declare const vtkPlatonicSolidSource: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkPlatonicSolidSource;
Loading