Skip to content

Commit 65a78fb

Browse files
committed
feat(RibbonFilter): add vtkRibbonFilter
1 parent 1b45543 commit 65a78fb

File tree

6 files changed

+770
-0
lines changed

6 files changed

+770
-0
lines changed
39.4 KB
Loading

Documentation/content/examples/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ This will allow you to see the some live code running in your browser. Just pick
110110
[![ThresholdPoints Example][ThresholdPoints]](./ThresholdPoints.html "Cut/Treshold points with point data criteria")
111111
[![ShrinkPolyData Example][ShrinkPolyData]](./ShrinkPolyData.html "ShrinkPolyData")
112112
[![CleanPolyData Example][CleanPolyData]](./CleanPolyData.html "CleanPolyData")
113+
[![RibbonFilter Example][RibbonFilter]](./RibbonFilter.html "RibbonFilter")
114+
113115

114116
</div>
115117

@@ -131,6 +133,7 @@ This will allow you to see the some live code running in your browser. Just pick
131133
[ThresholdPoints]: ../docs/gallery/ThresholdPoints.jpg
132134
[ShrinkPolyData]: ../docs/gallery/ShrinkPolyData.jpg
133135
[CleanPolyData]: ../docs/gallery/CleanPolyData.jpg
136+
[RibbonFilter]: ../docs/gallery/RibbonFilter.jpg
134137

135138
# Sources
136139

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
import '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper';
6+
7+
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
8+
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
9+
import vtkRibbonFilter from '@kitware/vtk.js/Filters/Modeling/RibbonFilter';
10+
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
11+
12+
import vtkPoints from '@kitware/vtk.js/Common/Core/Points';
13+
import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
14+
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
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+
// Spiral parameters.
29+
const nV = 256; // Number of vertices
30+
const rS = 2; // Spiral radius
31+
const nCyc = 3; // Number of helical cycles
32+
const h = 10; // Height
33+
34+
const points = vtkPoints.newInstance();
35+
let p = [0, 0, 0];
36+
for (let i = 0; i < nV; i++) {
37+
const angle = (2 * Math.PI * nCyc * i) / (nV - 1);
38+
const vX = rS * Math.cos(angle);
39+
const vY = rS * Math.sin(angle);
40+
const vZ = (h * i) / nV;
41+
p = [vX, vY, vZ];
42+
points.insertPoint(i, p);
43+
}
44+
45+
const v = [nV, ...Array.from({ length: nV }, (_, i) => i)];
46+
const lines = vtkCellArray.newInstance({
47+
values: v,
48+
});
49+
50+
const polyData = vtkPolyData.newInstance();
51+
polyData.setPoints(points);
52+
polyData.setLines(lines);
53+
54+
const lineActor = vtkActor.newInstance();
55+
const lineMapper = vtkMapper.newInstance();
56+
lineMapper.setInputData(polyData);
57+
lineActor.setMapper(lineMapper);
58+
lineActor.getProperty().setColor(1, 0, 0);
59+
lineActor.getProperty().setLineWidth(3);
60+
61+
const ribbonFilter = vtkRibbonFilter.newInstance();
62+
ribbonFilter.setInputData(polyData);
63+
64+
const ribbonActor = vtkActor.newInstance();
65+
const ribbonMapper = vtkMapper.newInstance();
66+
ribbonActor.setMapper(ribbonMapper);
67+
68+
ribbonMapper.setInputConnection(ribbonFilter.getOutputPort());
69+
70+
renderer.addActor(ribbonActor);
71+
renderer.addActor(lineActor);
72+
renderer.resetCamera();
73+
renderWindow.render();
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
2+
import { Vector3 } from '../../../types';
3+
4+
export type IGenerateTCoords =
5+
| 'TCOORDS_OFF'
6+
| 'TCOORDS_FROM_SCALARS'
7+
| 'TCOORDS_FROM_LENGTH'
8+
| 'TCOORDS_FROM_NORMALIZED_LENGTH';
9+
10+
/**
11+
*
12+
*/
13+
export interface IRibbonFilterInitialValues {
14+
useDefaultNormal?: boolean;
15+
width?: number;
16+
varyWidth?: boolean;
17+
angle?: number;
18+
generateTCoords?: IGenerateTCoords;
19+
widthFactor?: number;
20+
textureLength?: number;
21+
defaultNormal?: Vector3;
22+
}
23+
24+
type vtkRibbonFilterBase = vtkObject & vtkAlgorithm;
25+
26+
export interface vtkRibbonFilter extends vtkRibbonFilterBase {
27+
/**
28+
* Get the angle (in degrees) of rotation about the line tangent used to
29+
* orient the ribbon.
30+
*/
31+
getAngle(): number;
32+
33+
/**
34+
* Get the default normal used to orient the ribbon when no normals are
35+
* provided in the input.
36+
*/
37+
getDefaultNormal(): Vector3;
38+
39+
/**
40+
* Get the default normal used to orient the ribbon when no normals are
41+
* provided in the input.
42+
*/
43+
getDefaultNormalByReference(): Vector3;
44+
45+
/**
46+
* Get the method used to generate texture coordinates.
47+
*/
48+
getGenerateTCoords(): IGenerateTCoords;
49+
50+
/**
51+
* Get the method used to generate texture coordinates as a string.
52+
*/
53+
getGenerateTCoordsAsString(): string;
54+
55+
/**
56+
* Get the texture length, used when generating texture coordinates from
57+
* length.
58+
*/
59+
getTextureLength(): number;
60+
61+
/**
62+
* Get whether to use the default normal to orient the ribbon when no
63+
* normals are provided in the input.
64+
*/
65+
getUseDefaultNormal(): boolean;
66+
67+
/**
68+
* Get whether to vary the width of the ribbon using scalar data.
69+
*/
70+
getVaryWidth(): boolean;
71+
72+
/**
73+
* Get the width of the ribbon.
74+
*/
75+
getWidth(): number;
76+
77+
/**
78+
* Get the width factor, used to scale the width when varying the width.
79+
*/
80+
getWidthFactor(): number;
81+
82+
/**
83+
*
84+
* @param inData
85+
* @param outData
86+
*/
87+
requestData(inData: any, outData: any): void;
88+
89+
/**
90+
* Set the angle (in degrees) of rotation about the line tangent used to orient the ribbon.
91+
* Default is 0.0.
92+
* @param angle The angle in degrees.
93+
* @returns true if the angle is set successfully.
94+
*/
95+
setAngle(angle: number): boolean;
96+
97+
/**
98+
* Set the default normal used to orient the ribbon when no normals are provided in the input.
99+
* The default normal is a vector defined by three components (x,y,z). The
100+
* default is (0,0,1).
101+
* @param defaultNormal The default normal as an array of three numbers or a Vector3.
102+
* @returns true if the default normal is set successfully.
103+
*/
104+
setDefaultNormal(defaultNormal: Vector3): boolean;
105+
106+
/**
107+
* Set the default normal used to orient the ribbon when no normals are provided in the input.
108+
* The default normal is a vector defined by three components (x,y,z). The
109+
* default is (0,0,1).
110+
* @returns true if the default normal is set successfully.
111+
*/
112+
setDefaultNormalFrom(defaultNormal: Vector3): boolean;
113+
114+
/**
115+
* Set the method used to generate texture coordinates. By default, texture
116+
* coordinates are not generated.
117+
* @param generateTCoords The method to generate texture coordinates.
118+
* @returns true if the method is set successfully.
119+
*/
120+
setGenerateTCoords(generateTCoords: IGenerateTCoords): boolean;
121+
122+
/**
123+
* Set the texture length, used when generating texture coordinates from length.
124+
* The default is 1.0.
125+
* @param textureLength The texture length.
126+
* @returns true if the texture length is set successfully.
127+
*/
128+
setTextureLength(textureLength: number): boolean;
129+
130+
/**
131+
* Set whether to use the default normal to orient the ribbon when no normals are provided in the input.
132+
* The default is false.
133+
* @param useDefaultNormal Whether to use the default normal.
134+
* @returns true if the flag is set successfully.
135+
*/
136+
setUseDefaultNormal(useDefaultNormal: boolean): boolean;
137+
138+
/**
139+
* Set whether to vary the width of the ribbon using scalar data. By default,
140+
* the width of the ribbon is uniform.
141+
* @param varyWidth Whether to vary the width of the ribbon.
142+
* @returns true if the flag is set successfully.
143+
*/
144+
setVaryWidth(varyWidth: boolean): boolean;
145+
146+
/**
147+
* Set the width of the ribbon. The width is the total width of the ribbon;
148+
* the ribbon extends width/2 on either side of the line. The default is 0.5.
149+
* @param width The width of the ribbon.
150+
* @returns true if the width is set successfully.
151+
*/
152+
setWidth(width: number): boolean;
153+
154+
/**
155+
* Set the width factor, used to scale the width when varying the width.
156+
* The default is 1.0.
157+
* @param widthFactor The width factor.
158+
* @returns true if the width factor is set successfully.
159+
*/
160+
setWidthFactor(widthFactor: number): boolean;
161+
}
162+
163+
/**
164+
* Method used to decorate a given object (publicAPI+model) with vtkRibbonFilter characteristics.
165+
*
166+
* @param publicAPI object on which methods will be bounds (public)
167+
* @param model object on which data structure will be bounds (protected)
168+
* @param {IRibbonFilterInitialValues} [initialValues] (default: {})
169+
*/
170+
export function extend(
171+
publicAPI: object,
172+
model: object,
173+
initialValues?: IRibbonFilterInitialValues
174+
): void;
175+
176+
/**
177+
* Method used to create a new instance of vtkRibbonFilter
178+
* @param {IRibbonFilterInitialValues} [initialValues] for pre-setting some of its content
179+
*/
180+
export function newInstance(
181+
initialValues?: IRibbonFilterInitialValues
182+
): vtkRibbonFilter;
183+
184+
/**
185+
* vtkRibbonFilter is a filter to create oriented ribbons from lines defined in
186+
* polygonal dataset. The orientation of the ribbon is along the line segments
187+
* and perpendicular to "projected" line normals. Projected line normals are the
188+
* original line normals projected to be perpendicular to the local line
189+
* segment. An offset angle can be specified to rotate the ribbon with respect
190+
* to the normal.
191+
*/
192+
export declare const vtkRibbonFilter: {
193+
newInstance: typeof newInstance;
194+
extend: typeof extend;
195+
};
196+
export default vtkRibbonFilter;

0 commit comments

Comments
 (0)