diff --git a/Documentation/content/docs/gallery/PlatonicSolidSource.jpg b/Documentation/content/docs/gallery/PlatonicSolidSource.jpg new file mode 100644 index 00000000000..3082388d1ac Binary files /dev/null and b/Documentation/content/docs/gallery/PlatonicSolidSource.jpg differ diff --git a/Documentation/content/examples/index.md b/Documentation/content/examples/index.md index 4e81c621d59..433bca0e13b 100644 --- a/Documentation/content/examples/index.md +++ b/Documentation/content/examples/index.md @@ -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") @@ -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 diff --git a/Sources/Filters/Sources/PlatonicSolidSource/Constants.d.ts b/Sources/Filters/Sources/PlatonicSolidSource/Constants.d.ts new file mode 100644 index 00000000000..9b69e18a3d9 --- /dev/null +++ b/Sources/Filters/Sources/PlatonicSolidSource/Constants.d.ts @@ -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; diff --git a/Sources/Filters/Sources/PlatonicSolidSource/Constants.js b/Sources/Filters/Sources/PlatonicSolidSource/Constants.js new file mode 100644 index 00000000000..d2e82518246 --- /dev/null +++ b/Sources/Filters/Sources/PlatonicSolidSource/Constants.js @@ -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, +}; diff --git a/Sources/Filters/Sources/PlatonicSolidSource/example/controlPanel.html b/Sources/Filters/Sources/PlatonicSolidSource/example/controlPanel.html new file mode 100644 index 00000000000..0506bcb182e --- /dev/null +++ b/Sources/Filters/Sources/PlatonicSolidSource/example/controlPanel.html @@ -0,0 +1,14 @@ + + + + + +
Solid Type + +
diff --git a/Sources/Filters/Sources/PlatonicSolidSource/example/index.js b/Sources/Filters/Sources/PlatonicSolidSource/example/index.js new file mode 100644 index 00000000000..88bcb618a0d --- /dev/null +++ b/Sources/Filters/Sources/PlatonicSolidSource/example/index.js @@ -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; diff --git a/Sources/Filters/Sources/PlatonicSolidSource/index.d.ts b/Sources/Filters/Sources/PlatonicSolidSource/index.d.ts new file mode 100644 index 00000000000..659e4de6e84 --- /dev/null +++ b/Sources/Filters/Sources/PlatonicSolidSource/index.d.ts @@ -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; diff --git a/Sources/Filters/Sources/PlatonicSolidSource/index.js b/Sources/Filters/Sources/PlatonicSolidSource/index.js new file mode 100644 index 00000000000..6eb7c485c24 --- /dev/null +++ b/Sources/Filters/Sources/PlatonicSolidSource/index.js @@ -0,0 +1,276 @@ +import macro from 'vtk.js/Sources/macros'; +import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; +import vtkPoints from 'vtk.js/Sources/Common/Core/Points'; +import vtkCellArray from 'vtk.js/Sources/Common/Core/CellArray'; +import { SolidType } from 'vtk.js/Sources/Filters/Sources/PlatonicSolidSource/Constants'; +import { DesiredOutputPrecision } from 'vtk.js/Sources/Common/DataModel/DataSetAttributes/Constants'; +import { VtkDataTypes } from 'vtk.js/Sources/Common/Core/DataArray/Constants'; + +const a = 0.61803398875; +const b = 0.38196601125; +const c = 0.5; +const d = 0.30901699; +const e = Math.sqrt(2); +const f = Math.sqrt(3.0); + +const geometries = { + tetrahedron: { + points: [1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1], + cells: [0, 2, 1, 1, 2, 3, 0, 3, 2, 0, 1, 3], + numPoints: 4, + cellSize: 3, + numCells: 4, + scale: 1.0 / f, + }, + + cube: { + points: [ + -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 1, 1, + -1, 1, 1, + ], + cells: [ + 0, 1, 5, 4, 0, 4, 7, 3, 4, 5, 6, 7, 3, 7, 6, 2, 1, 2, 6, 5, 0, 3, 2, 1, + ], + numPoints: 8, + cellSize: 4, + numCells: 6, + scale: 1.0 / f, + }, + + octahedron: { + points: [-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0, 0, 0, -e, 0, 0, e], + cells: [ + 4, 1, 0, 4, 2, 1, 4, 3, 2, 4, 0, 3, 0, 1, 5, 1, 2, 5, 2, 3, 5, 3, 0, 5, + ], + numPoints: 6, + cellSize: 3, + numCells: 8, + scale: 1.0 / e, + }, + + icosahedron: { + points: [ + 0, + d, + -c, + 0, + d, + c, + 0, + -d, + c, + -d, + c, + 0, + -d, + -c, + 0, + d, + c, + 0, + d, + -c, + 0, + 0, + -d, + -c, + c, + 0, + d, + -c, + 0, + d, + -c, + 0, + -d, + c, + 0, + -d, + ], + cells: [ + 0, 3, 5, 1, 5, 3, 1, 9, 2, 1, 2, 8, 0, 11, 7, 0, 7, 10, 2, 4, 6, 7, 6, 4, + 3, 10, 9, 4, 9, 10, 5, 8, 11, 6, 11, 8, 1, 3, 9, 1, 8, 5, 0, 10, 3, 0, 5, + 11, 7, 4, 10, 7, 11, 6, 2, 9, 4, 2, 6, 8, + ], + numPoints: 12, + cellSize: 3, + numCells: 20, + scale: 1.0 / 0.58778524999243, + }, + + dodecahedron: { + points: [ + b, + 0, + 1, + -b, + 0, + 1, + b, + 0, + -1, + -b, + 0, + -1, + 0, + 1, + -b, + 0, + 1, + b, + 0, + -1, + -b, + 0, + -1, + b, + 1, + b, + 0, + 1, + -b, + 0, + -1, + b, + 0, + -1, + -b, + 0, + -a, + a, + a, + a, + -a, + a, + -a, + -a, + -a, + a, + a, + -a, + a, + a, + a, + -a, + a, + -a, + -a, + -a, + a, + a, + -a, + -a, + ], + cells: [ + 0, 16, 5, 12, 1, 1, 18, 7, 13, 0, 2, 19, 6, 14, 3, 3, 17, 4, 15, 2, 4, 5, + 16, 8, 15, 5, 4, 17, 10, 12, 6, 7, 18, 11, 14, 7, 6, 19, 9, 13, 8, 16, 0, + 13, 9, 9, 19, 2, 15, 8, 10, 17, 3, 14, 11, 11, 18, 1, 12, 10, + ], + numPoints: 20, + cellSize: 5, + numCells: 12, + scale: 1.0 / 1.070466269319, + }, +}; + +// ---------------------------------------------------------------------------- +// vtkPlatonicSolidSource methods +// ---------------------------------------------------------------------------- + +function vtkPlatonicSolidSource(publicAPI, model) { + // Set our className + model.classHierarchy.push('vtkPlatonicSolidSource'); + + publicAPI.requestData = (inData, outData) => { + const output = outData[0] || vtkPolyData.newInstance(); + + let solidData; + switch (model.solidType) { + case SolidType.VTK_SOLID_TETRAHEDRON: + solidData = geometries.tetrahedron; + break; + case SolidType.VTK_SOLID_CUBE: + solidData = geometries.cube; + break; + case SolidType.VTK_SOLID_OCTAHEDRON: + solidData = geometries.octahedron; + break; + case SolidType.VTK_SOLID_ICOSAHEDRON: + solidData = geometries.icosahedron; + break; + case SolidType.VTK_SOLID_DODECAHEDRON: + solidData = geometries.dodecahedron; + break; + default: + solidData = geometries.tetrahedron; + break; + } + + let pointType; + if (model.outputPointsPrecision === DesiredOutputPrecision.SINGLE) { + pointType = VtkDataTypes.FLOAT; + } else if (model.outputPointsPrecision === DesiredOutputPrecision.DOUBLE) { + pointType = VtkDataTypes.DOUBLE; + } + + const points = vtkPoints.newInstance({ + dataType: pointType, + numberOfPoints: solidData.numPoints, + }); + + for (let i = 0; i < solidData.points.length; i += 3) { + points.insertNextPoint( + solidData.scale * solidData.points[i] * model.scale, + solidData.scale * solidData.points[i + 1] * model.scale, + solidData.scale * solidData.points[i + 2] * model.scale + ); + } + + const polys = vtkCellArray.newInstance(); + for (let i = 0; i < solidData.cells.length; i += solidData.cellSize) { + const cell = solidData.cells.slice(i, i + solidData.cellSize); + polys.insertNextCell(cell); + } + + output.setPoints(points); + output.setPolys(polys); + + outData[0] = output; + }; +} + +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +const DEFAULT_VALUES = { + solidType: SolidType.VTK_SOLID_TETRAHEDRON, + outputPointsPrecision: DesiredOutputPrecision.DEFAULT, + scale: 1, +}; + +// ---------------------------------------------------------------------------- + +export function extend(publicAPI, model, initialValues = {}) { + Object.assign(model, DEFAULT_VALUES, initialValues); + + // Build VTK API + macro.obj(publicAPI, model); + macro.setGet(publicAPI, model, [ + 'solidType', + 'outputPointsPrecision', + 'scale', + ]); + macro.algo(publicAPI, model, 0, 1); + + // Object methods + vtkPlatonicSolidSource(publicAPI, model); +} + +// ---------------------------------------------------------------------------- + +export const newInstance = macro.newInstance(extend, 'vtkPlatonicSolidSource'); + +// ---------------------------------------------------------------------------- + +export default { newInstance, extend, SolidType }; diff --git a/Sources/Filters/Sources/PlatonicSolidSource/test/testCube.png b/Sources/Filters/Sources/PlatonicSolidSource/test/testCube.png new file mode 100644 index 00000000000..b7f1fec3618 Binary files /dev/null and b/Sources/Filters/Sources/PlatonicSolidSource/test/testCube.png differ diff --git a/Sources/Filters/Sources/PlatonicSolidSource/test/testDodecahedron.png b/Sources/Filters/Sources/PlatonicSolidSource/test/testDodecahedron.png new file mode 100644 index 00000000000..fe44ba34f24 Binary files /dev/null and b/Sources/Filters/Sources/PlatonicSolidSource/test/testDodecahedron.png differ diff --git a/Sources/Filters/Sources/PlatonicSolidSource/test/testIcosahedron.png b/Sources/Filters/Sources/PlatonicSolidSource/test/testIcosahedron.png new file mode 100644 index 00000000000..104e7e53fba Binary files /dev/null and b/Sources/Filters/Sources/PlatonicSolidSource/test/testIcosahedron.png differ diff --git a/Sources/Filters/Sources/PlatonicSolidSource/test/testOctahedron.png b/Sources/Filters/Sources/PlatonicSolidSource/test/testOctahedron.png new file mode 100644 index 00000000000..fe9ed35b7af Binary files /dev/null and b/Sources/Filters/Sources/PlatonicSolidSource/test/testOctahedron.png differ diff --git a/Sources/Filters/Sources/PlatonicSolidSource/test/testPlatonicSolid.js b/Sources/Filters/Sources/PlatonicSolidSource/test/testPlatonicSolid.js new file mode 100644 index 00000000000..3e90dc18123 --- /dev/null +++ b/Sources/Filters/Sources/PlatonicSolidSource/test/testPlatonicSolid.js @@ -0,0 +1,284 @@ +import test from 'tape'; +import testUtils from 'vtk.js/Sources/Testing/testUtils'; + +import 'vtk.js/Sources/Rendering/Misc/RenderingAPIs'; +import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow'; +import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer'; +import vtkPlatonicSolidSource from 'vtk.js/Sources/Filters/Sources/PlatonicSolidSource'; +import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'; +import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper'; +import { SolidType } from 'vtk.js/Sources/Filters/Sources/PlatonicSolidSource/Constants'; + +import baseline1 from './testTetrahedron.png'; +import baseline2 from './testCube.png'; +import baseline3 from './testOctahedron.png'; +import baseline4 from './testIcosahedron.png'; +import baseline5 from './testDodecahedron.png'; + +test.onlyIfWebGL('Test vtkPlatonicSolidSource Tetrahedron Rendering', (t) => { + const gc = testUtils.createGarbageCollector(); + t.ok('rendering', 'vtkPlatonicSolidSource Rendering'); + + // Create some control UI + const container = document.querySelector('body'); + const renderWindowContainer = gc.registerDOMElement( + document.createElement('div') + ); + container.appendChild(renderWindowContainer); + + // create what we will view + const renderWindow = gc.registerResource(vtkRenderWindow.newInstance()); + const renderer = gc.registerResource(vtkRenderer.newInstance()); + renderWindow.addRenderer(renderer); + renderer.setBackground(0.32, 0.34, 0.43); + + const actor = gc.registerResource(vtkActor.newInstance()); + + renderer.addActor(actor); + + const mapper = gc.registerResource(vtkMapper.newInstance()); + actor.setMapper(mapper); + + const regularPolygonSource = gc.registerResource( + vtkPlatonicSolidSource.newInstance() + ); + mapper.setInputConnection(regularPolygonSource.getOutputPort()); + actor.rotateX(-30); + + // now create something to view it, in this case webgl + const glwindow = gc.registerResource(renderWindow.newAPISpecificView()); + glwindow.setContainer(renderWindowContainer); + renderWindow.addView(glwindow); + glwindow.setSize(400, 400); + + const promise = glwindow + .captureNextImage() + .then((image) => + testUtils.compareImages( + image, + [baseline1], + 'Filters/Sources/platonicSolidSource/testTetrahedron', + t, + 2.5 + ) + ) + .finally(gc.releaseResources); + renderWindow.render(); + return promise; +}); + +test.onlyIfWebGL('Test vtkPlatonicSolidSource Cube Rendering', (t) => { + const gc = testUtils.createGarbageCollector(); + t.ok('rendering', 'vtkPlatonicSolidSource Rendering'); + + // Create some control UI + const container = document.querySelector('body'); + const renderWindowContainer = gc.registerDOMElement( + document.createElement('div') + ); + container.appendChild(renderWindowContainer); + + // create what we will view + const renderWindow = gc.registerResource(vtkRenderWindow.newInstance()); + const renderer = gc.registerResource(vtkRenderer.newInstance()); + renderWindow.addRenderer(renderer); + renderer.setBackground(0.32, 0.34, 0.43); + + const actor = gc.registerResource(vtkActor.newInstance()); + + renderer.addActor(actor); + + const mapper = gc.registerResource(vtkMapper.newInstance()); + actor.setMapper(mapper); + + const regularPolygonSource = gc.registerResource( + vtkPlatonicSolidSource.newInstance({ + solidType: SolidType.VTK_SOLID_CUBE, + }) + ); + mapper.setInputConnection(regularPolygonSource.getOutputPort()); + actor.rotateX(-30); + + // now create something to view it, in this case webgl + const glwindow = gc.registerResource(renderWindow.newAPISpecificView()); + glwindow.setContainer(renderWindowContainer); + renderWindow.addView(glwindow); + glwindow.setSize(400, 400); + + const promise = glwindow + .captureNextImage() + .then((image) => + testUtils.compareImages( + image, + [baseline2], + 'Filters/Sources/platonicSolidSource/testCube', + t, + 2.5 + ) + ) + .finally(gc.releaseResources); + renderWindow.render(); + return promise; +}); + +test.onlyIfWebGL('Test vtkPlatonicSolidSource Octahedron Rendering', (t) => { + const gc = testUtils.createGarbageCollector(); + t.ok('rendering', 'vtkPlatonicSolidSource Rendering'); + + // Create some control UI + const container = document.querySelector('body'); + const renderWindowContainer = gc.registerDOMElement( + document.createElement('div') + ); + container.appendChild(renderWindowContainer); + + // create what we will view + const renderWindow = gc.registerResource(vtkRenderWindow.newInstance()); + const renderer = gc.registerResource(vtkRenderer.newInstance()); + renderWindow.addRenderer(renderer); + renderer.setBackground(0.32, 0.34, 0.43); + + const actor = gc.registerResource(vtkActor.newInstance()); + + renderer.addActor(actor); + + const mapper = gc.registerResource(vtkMapper.newInstance()); + actor.setMapper(mapper); + + const regularPolygonSource = gc.registerResource( + vtkPlatonicSolidSource.newInstance({ + solidType: SolidType.VTK_SOLID_OCTAHEDRON, + }) + ); + mapper.setInputConnection(regularPolygonSource.getOutputPort()); + actor.rotateX(-30); + + // now create something to view it, in this case webgl + const glwindow = gc.registerResource(renderWindow.newAPISpecificView()); + glwindow.setContainer(renderWindowContainer); + renderWindow.addView(glwindow); + glwindow.setSize(400, 400); + + const promise = glwindow + .captureNextImage() + .then((image) => + testUtils.compareImages( + image, + [baseline3], + 'Filters/Sources/platonicSolidSource/testOctahedron', + t, + 2.5 + ) + ) + .finally(gc.releaseResources); + renderWindow.render(); + return promise; +}); + +test.onlyIfWebGL('Test vtkPlatonicSolidSource Icosahedron Rendering', (t) => { + const gc = testUtils.createGarbageCollector(); + t.ok('rendering', 'vtkPlatonicSolidSource Rendering'); + + // Create some control UI + const container = document.querySelector('body'); + const renderWindowContainer = gc.registerDOMElement( + document.createElement('div') + ); + container.appendChild(renderWindowContainer); + + // create what we will view + const renderWindow = gc.registerResource(vtkRenderWindow.newInstance()); + const renderer = gc.registerResource(vtkRenderer.newInstance()); + renderWindow.addRenderer(renderer); + renderer.setBackground(0.32, 0.34, 0.43); + + const actor = gc.registerResource(vtkActor.newInstance()); + + renderer.addActor(actor); + + const mapper = gc.registerResource(vtkMapper.newInstance()); + actor.setMapper(mapper); + + const regularPolygonSource = gc.registerResource( + vtkPlatonicSolidSource.newInstance({ + solidType: SolidType.VTK_SOLID_ICOSAHEDRON, + }) + ); + mapper.setInputConnection(regularPolygonSource.getOutputPort()); + actor.rotateX(-30); + + // now create something to view it, in this case webgl + const glwindow = gc.registerResource(renderWindow.newAPISpecificView()); + glwindow.setContainer(renderWindowContainer); + renderWindow.addView(glwindow); + glwindow.setSize(400, 400); + + const promise = glwindow + .captureNextImage() + .then((image) => + testUtils.compareImages( + image, + [baseline4], + 'Filters/Sources/platonicSolidSource/testIcosahedron', + t, + 2.5 + ) + ) + .finally(gc.releaseResources); + renderWindow.render(); + return promise; +}); + +test.onlyIfWebGL('Test vtkPlatonicSolidSource Dodecahedron Rendering', (t) => { + const gc = testUtils.createGarbageCollector(); + t.ok('rendering', 'vtkPlatonicSolidSource Rendering'); + + // Create some control UI + const container = document.querySelector('body'); + const renderWindowContainer = gc.registerDOMElement( + document.createElement('div') + ); + container.appendChild(renderWindowContainer); + + // create what we will view + const renderWindow = gc.registerResource(vtkRenderWindow.newInstance()); + const renderer = gc.registerResource(vtkRenderer.newInstance()); + renderWindow.addRenderer(renderer); + renderer.setBackground(0.32, 0.34, 0.43); + + const actor = gc.registerResource(vtkActor.newInstance()); + + renderer.addActor(actor); + + const mapper = gc.registerResource(vtkMapper.newInstance()); + actor.setMapper(mapper); + + const regularPolygonSource = gc.registerResource( + vtkPlatonicSolidSource.newInstance({ + solidType: SolidType.VTK_SOLID_DODECAHEDRON, + }) + ); + mapper.setInputConnection(regularPolygonSource.getOutputPort()); + actor.rotateX(-30); + + // now create something to view it, in this case webgl + const glwindow = gc.registerResource(renderWindow.newAPISpecificView()); + glwindow.setContainer(renderWindowContainer); + renderWindow.addView(glwindow); + glwindow.setSize(400, 400); + + const promise = glwindow + .captureNextImage() + .then((image) => + testUtils.compareImages( + image, + [baseline5], + 'Filters/Sources/platonicSolidSource/testDodecahedron', + t, + 2.5 + ) + ) + .finally(gc.releaseResources); + renderWindow.render(); + return promise; +}); diff --git a/Sources/Filters/Sources/PlatonicSolidSource/test/testTetrahedron.png b/Sources/Filters/Sources/PlatonicSolidSource/test/testTetrahedron.png new file mode 100644 index 00000000000..794325d8264 Binary files /dev/null and b/Sources/Filters/Sources/PlatonicSolidSource/test/testTetrahedron.png differ diff --git a/Sources/Filters/Sources/index.js b/Sources/Filters/Sources/index.js index 51624152d23..58198f90f11 100644 --- a/Sources/Filters/Sources/index.js +++ b/Sources/Filters/Sources/index.js @@ -9,6 +9,7 @@ import vtkDiskSource from './DiskSource'; import vtkImageGridSource from './ImageGridSource'; import vtkLineSource from './LineSource'; import vtkPlaneSource from './PlaneSource'; +import vtkPlatonicSolidSource from './PlatonicSolidSource'; import vtkPointSource from './PointSource'; import vtkRTAnalyticSource from './RTAnalyticSource'; import vtkSLICSource from './SLICSource'; @@ -26,6 +27,7 @@ export default { vtkImageGridSource, vtkLineSource, vtkPlaneSource, + vtkPlatonicSolidSource, vtkPointSource, vtkRTAnalyticSource, vtkSLICSource,