Skip to content

Commit 8f045da

Browse files
committed
feat(RegularPolygonSource): add vtkRegularPolygonSource
1 parent 1b45543 commit 8f045da

File tree

10 files changed

+490
-3
lines changed

10 files changed

+490
-3
lines changed
10.6 KB
Loading

Documentation/content/examples/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ This will allow you to see the some live code running in your browser. Just pick
151151
[![PlaneSource Example][PlaneSource]](./PlaneSource.html "PlaneSource")
152152
[![PointSource Example][PointSource]](./PointSource.html "PointSource")
153153
[![PlatonicSolidSource Example][PlatonicSolidSource]](./PlatonicSolidSource.html "PlatonicSolidSource")
154+
[![RegularPolygonSource Example][RegularPolygonSource]](./RegularPolygonSource.html "RegularPolygonSource")
154155
[![SLICSource Example][SLICSource]](./SLICSource.html "SLICSource")
155156
[![SphereSource Example][SphereSource]](./SphereSource.html "SphereSource")
156157
[![WarpScalar Example][WarpScalargif]](./WarpScalar.html "WarpScalar")
@@ -173,6 +174,7 @@ This will allow you to see the some live code running in your browser. Just pick
173174
[PlaneSource]: ../docs/gallery/PlaneSource.jpg
174175
[PointSource]: ../docs/gallery/PointSource.jpg
175176
[PlatonicSolidSource]: ../docs/gallery/PlatonicSolidSource.jpg
177+
[RegularPolygonSource]: ../docs/gallery/RegularPolygonSource.jpg
176178
[SLICSource]: ../docs/gallery/SLICSource.jpg
177179
[SphereSource]: ../docs/gallery/SphereSource.gif
178180
[WarpScalargif]: ../docs/gallery/WarpScalar.gif

Sources/Filters/Sources/PlatonicSolidSource/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ export function newInstance(
9696
*
9797
* @example
9898
* ```js
99-
* import vtkPlatonicSolidSource from '@kitware/vtk.js/Filters/Sources/RegularPolygonSource';
99+
* import vtkPlatonicSolidSource from '@kitware/vtk.js/Filters/Sources/PlatonicSolidSource';
100100
*
101-
* const regularPolygonSource = vtkPlatonicSolidSource.newInstance();
102-
* const polydata = regularPolygonSource.getOutputData();
101+
* const platonicSolidSource = vtkPlatonicSolidSource.newInstance();
102+
* const polydata = platonicSolidSource.getOutputData();
103103
* ```
104104
*/
105105
export declare const vtkPlatonicSolidSource: {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<table>
2+
<tr>
3+
<td>Number Of Sides</td>
4+
<td>
5+
<input class='numberOfSides' type="range" min="3" max="100" step="1" value="6" />
6+
</td>
7+
</tr>
8+
</table>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 vtkRegularPolygonSource from '@kitware/vtk.js/Filters/Sources/RegularPolygonSource';
9+
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
10+
import { Representation } from '@kitware/vtk.js/Rendering/Core/Property/Constants';
11+
12+
import controlPanel from './controlPanel.html';
13+
14+
// ----------------------------------------------------------------------------
15+
// Standard rendering code setup
16+
// ----------------------------------------------------------------------------
17+
18+
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
19+
const renderer = fullScreenRenderer.getRenderer();
20+
const renderWindow = fullScreenRenderer.getRenderWindow();
21+
22+
// ----------------------------------------------------------------------------
23+
// Example code
24+
// ----------------------------------------------------------------------------
25+
const regularPolygonSource = vtkRegularPolygonSource.newInstance();
26+
27+
const mapper = vtkMapper.newInstance();
28+
const actor = vtkActor.newInstance();
29+
30+
actor.getProperty().setRepresentation(Representation.WIREFRAME);
31+
32+
mapper.setInputConnection(regularPolygonSource.getOutputPort());
33+
actor.setMapper(mapper);
34+
35+
renderer.addActor(actor);
36+
renderer.resetCamera();
37+
renderWindow.render();
38+
39+
// -----------------------------------------------------------
40+
// UI control handling
41+
// -----------------------------------------------------------
42+
43+
fullScreenRenderer.addController(controlPanel);
44+
45+
['numberOfSides'].forEach((propertyName) => {
46+
document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
47+
const value = Number(e.target.value);
48+
regularPolygonSource.set({ [propertyName]: value });
49+
renderWindow.render();
50+
});
51+
});
52+
53+
// -----------------------------------------------------------
54+
// Make some variables global so that you can inspect and
55+
// modify objects in your browser's developer console:
56+
// -----------------------------------------------------------
57+
58+
global.regularPolygonSource = regularPolygonSource;
59+
global.mapper = mapper;
60+
global.actor = actor;
61+
global.renderer = renderer;
62+
global.renderWindow = renderWindow;
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
2+
import { Vector3 } from '../../../types';
3+
import { DesiredOutputPrecision } from '../../../Common/DataModel/DataSetAttributes';
4+
5+
/**
6+
*
7+
*/
8+
export interface IPlaneSourceInitialValues {
9+
numberOfSides?: number;
10+
center?: Vector3;
11+
normal?: Vector3;
12+
radius?: number;
13+
generatePolygon?: boolean;
14+
generatePolyline?: boolean;
15+
outputPointsPrecision?: DesiredOutputPrecision;
16+
}
17+
18+
type vtkRegularPolygonSourceBase = vtkObject &
19+
Omit<
20+
vtkAlgorithm,
21+
| 'getInputData'
22+
| 'setInputData'
23+
| 'setInputConnection'
24+
| 'getInputConnection'
25+
| 'addInputConnection'
26+
| 'addInputData'
27+
>;
28+
29+
export interface vtkRegularPolygonSource extends vtkRegularPolygonSourceBase {
30+
/**
31+
* Get the center of the regular polygon.
32+
* @returns {Vector3} center of the polygon
33+
*/
34+
getCenter(): Vector3;
35+
36+
/**
37+
* Get a reference to the center of the regular polygon.
38+
* @returns {Vector3} reference to the center of the polygon
39+
*/
40+
getCenterByReference(): Vector3;
41+
42+
/**
43+
* Get whether to generate polygon points.
44+
* @returns {Boolean} true if polygon points are generated, false otherwise
45+
*/
46+
getGeneratePolygon(): boolean;
47+
48+
/**
49+
* Get whether to generate polyline points.
50+
* @returns {Boolean} true if polyline points are generated, false otherwise
51+
*/
52+
getGeneratePolyline(): boolean;
53+
54+
/**
55+
* Get the normal of the regular polygon.
56+
* @returns {Vector3} normal of the polygon
57+
*/
58+
getNormal(): Vector3;
59+
60+
/**
61+
* Get a reference to the normal of the regular polygon.
62+
* @returns {Vector3} reference to the normal of the polygon
63+
*/
64+
getNormalByReference(): Vector3;
65+
66+
/**
67+
* Get the number of sides for the regular polygon.
68+
* @returns {Number} number of sides
69+
*/
70+
getNumberOfSides(): number;
71+
72+
/**
73+
* Get the output points precision.
74+
* @returns {DesiredOutputPrecision} the output points precision
75+
*/
76+
getOutputPointsPrecision(): DesiredOutputPrecision;
77+
78+
/**
79+
* Get the radius of the regular polygon.
80+
* @returns {Number} radius of the polygon
81+
*/
82+
getRadius(): number;
83+
84+
/**
85+
*
86+
* @param inData
87+
* @param outData
88+
*/
89+
requestData(inData: any, outData: any): void;
90+
91+
/**
92+
* Set the center of the regular polygon.
93+
* @param {Vector3} center
94+
* @returns {Boolean} true if the value was changed, false otherwise
95+
*/
96+
setCenter(center: Vector3): boolean;
97+
98+
/**
99+
* Set whether to generate polygon points.
100+
* @param generatePolygon
101+
* @returns {Boolean} true if the value was changed, false otherwise
102+
*/
103+
setGeneratePolygon(generatePolygon: boolean): boolean;
104+
105+
/**
106+
* Set whether to generate polyline points.
107+
* @param generatePolyline
108+
* @returns {Boolean} true if the value was changed, false otherwise
109+
*/
110+
setGeneratePolyline(generatePolyline: boolean): boolean;
111+
112+
/**
113+
* Set the normal of the regular polygon.
114+
* @param {Vector3} normal
115+
* @returns {Boolean} true if the value was changed, false otherwise
116+
*/
117+
setNormal(normal: Vector3): boolean;
118+
119+
/**
120+
* Set the number of sides for the regular polygon.
121+
* @param numberOfSides
122+
* @returns {Boolean} true if the value was changed, false otherwise
123+
*/
124+
setNumberOfSides(numberOfSides: number): boolean;
125+
126+
/**
127+
* Set the output points precision.
128+
* @param outputPointsPrecision
129+
* @returns {Boolean} true if the value was changed, false otherwise
130+
*/
131+
setOutputPointsPrecision(
132+
outputPointsPrecision: DesiredOutputPrecision
133+
): boolean;
134+
135+
/**
136+
* Set the radius of the regular polygon.
137+
* @param radius
138+
* @returns {Boolean} true if the value was changed, false otherwise
139+
*/
140+
setRadius(radius: number): boolean;
141+
}
142+
143+
/**
144+
* Method used to decorate a given object (publicAPI+model) with vtkRegularPolygonSource characteristics.
145+
*
146+
* @param publicAPI object on which methods will be bounds (public)
147+
* @param model object on which data structure will be bounds (protected)
148+
* @param {IPlaneSourceInitialValues} [initialValues] (default: {})
149+
*/
150+
export function extend(
151+
publicAPI: object,
152+
model: object,
153+
initialValues?: IPlaneSourceInitialValues
154+
): void;
155+
156+
/**
157+
* Method used to create a new instance of vtkRegularPolygonSource.
158+
* @param {IPlaneSourceInitialValues} [initialValues] for pre-setting some of its content
159+
*/
160+
export function newInstance(
161+
initialValues?: IPlaneSourceInitialValues
162+
): vtkRegularPolygonSource;
163+
164+
/**
165+
* vtkRegularPolygonSource is a source object that creates a single n-sided
166+
* polygon and/or polyline. The polygon is centered at a specified point,
167+
* orthogonal to a specified normal, and with a circumscribing radius set by the
168+
* user. The user can also specify the number of sides of the polygon ranging
169+
* from [3,N].
170+
*
171+
* @example
172+
* ```js
173+
* import vtkRegularPolygonSource from '@kitware/vtk.js/Filters/Sources/RegularPolygonSource';
174+
*
175+
* const regularPolygonSource = vtkRegularPolygonSource.newInstance();
176+
* const polydata = regularPolygonSource.getOutputData();
177+
* ```
178+
*/
179+
export declare const vtkRegularPolygonSource: {
180+
newInstance: typeof newInstance;
181+
extend: typeof extend;
182+
};
183+
export default vtkRegularPolygonSource;

0 commit comments

Comments
 (0)