Skip to content
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.
3 changes: 3 additions & 0 deletions Documentation/content/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ This will allow you to see the some live code running in your browser. Just pick
[![ThresholdPoints Example][ThresholdPoints]](./ThresholdPoints.html "Cut/Treshold points with point data criteria")
[![ShrinkPolyData Example][ShrinkPolyData]](./ShrinkPolyData.html "ShrinkPolyData")
[![CleanPolyData Example][CleanPolyData]](./CleanPolyData.html "CleanPolyData")
[![RibbonFilter Example][RibbonFilter]](./RibbonFilter.html "RibbonFilter")


</div>

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

# Sources

Expand Down
73 changes: 73 additions & 0 deletions Sources/Filters/Modeling/RibbonFilter/example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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 '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper';

import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import vtkRibbonFilter from '@kitware/vtk.js/Filters/Modeling/RibbonFilter';
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';

import vtkPoints from '@kitware/vtk.js/Common/Core/Points';
import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';

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

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

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

// Spiral parameters.
const nV = 256; // Number of vertices
const rS = 2; // Spiral radius
const nCyc = 3; // Number of helical cycles
const h = 10; // Height

const points = vtkPoints.newInstance();
let p = [0, 0, 0];
for (let i = 0; i < nV; i++) {
const angle = (2 * Math.PI * nCyc * i) / (nV - 1);
const vX = rS * Math.cos(angle);
const vY = rS * Math.sin(angle);
const vZ = (h * i) / nV;
p = [vX, vY, vZ];
points.insertPoint(i, p);
}

const v = [nV, ...Array.from({ length: nV }, (_, i) => i)];
const lines = vtkCellArray.newInstance({
values: v,
});

const polyData = vtkPolyData.newInstance();
polyData.setPoints(points);
polyData.setLines(lines);

const lineActor = vtkActor.newInstance();
const lineMapper = vtkMapper.newInstance();
lineMapper.setInputData(polyData);
lineActor.setMapper(lineMapper);
lineActor.getProperty().setColor(1, 0, 0);
lineActor.getProperty().setLineWidth(3);

const ribbonFilter = vtkRibbonFilter.newInstance();
ribbonFilter.setInputData(polyData);

const ribbonActor = vtkActor.newInstance();
const ribbonMapper = vtkMapper.newInstance();
ribbonActor.setMapper(ribbonMapper);

ribbonMapper.setInputConnection(ribbonFilter.getOutputPort());

renderer.addActor(ribbonActor);
renderer.addActor(lineActor);
renderer.resetCamera();
renderWindow.render();
196 changes: 196 additions & 0 deletions Sources/Filters/Modeling/RibbonFilter/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
import { Vector3 } from '../../../types';

export type IGenerateTCoords =
| 'TCOORDS_OFF'
| 'TCOORDS_FROM_SCALARS'
| 'TCOORDS_FROM_LENGTH'
| 'TCOORDS_FROM_NORMALIZED_LENGTH';

/**
*
*/
export interface IRibbonFilterInitialValues {
useDefaultNormal?: boolean;
width?: number;
varyWidth?: boolean;
angle?: number;
generateTCoords?: IGenerateTCoords;
widthFactor?: number;
textureLength?: number;
defaultNormal?: Vector3;
}

type vtkRibbonFilterBase = vtkObject & vtkAlgorithm;

export interface vtkRibbonFilter extends vtkRibbonFilterBase {
/**
* Get the angle (in degrees) of rotation about the line tangent used to
* orient the ribbon.
*/
getAngle(): number;

/**
* Get the default normal used to orient the ribbon when no normals are
* provided in the input.
*/
getDefaultNormal(): Vector3;

/**
* Get the default normal used to orient the ribbon when no normals are
* provided in the input.
*/
getDefaultNormalByReference(): Vector3;

/**
* Get the method used to generate texture coordinates.
*/
getGenerateTCoords(): IGenerateTCoords;

/**
* Get the method used to generate texture coordinates as a string.
*/
getGenerateTCoordsAsString(): string;

/**
* Get the texture length, used when generating texture coordinates from
* length.
*/
getTextureLength(): number;

/**
* Get whether to use the default normal to orient the ribbon when no
* normals are provided in the input.
*/
getUseDefaultNormal(): boolean;

/**
* Get whether to vary the width of the ribbon using scalar data.
*/
getVaryWidth(): boolean;

/**
* Get the width of the ribbon.
*/
getWidth(): number;

/**
* Get the width factor, used to scale the width when varying the width.
*/
getWidthFactor(): number;

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

/**
* Set the angle (in degrees) of rotation about the line tangent used to orient the ribbon.
* Default is 0.0.
* @param angle The angle in degrees.
* @returns true if the angle is set successfully.
*/
setAngle(angle: number): boolean;

/**
* Set the default normal used to orient the ribbon when no normals are provided in the input.
* The default normal is a vector defined by three components (x,y,z). The
* default is (0,0,1).
* @param defaultNormal The default normal as an array of three numbers or a Vector3.
* @returns true if the default normal is set successfully.
*/
setDefaultNormal(defaultNormal: Vector3): boolean;

/**
* Set the default normal used to orient the ribbon when no normals are provided in the input.
* The default normal is a vector defined by three components (x,y,z). The
* default is (0,0,1).
* @returns true if the default normal is set successfully.
*/
setDefaultNormalFrom(defaultNormal: Vector3): boolean;

/**
* Set the method used to generate texture coordinates. By default, texture
* coordinates are not generated.
* @param generateTCoords The method to generate texture coordinates.
* @returns true if the method is set successfully.
*/
setGenerateTCoords(generateTCoords: IGenerateTCoords): boolean;

/**
* Set the texture length, used when generating texture coordinates from length.
* The default is 1.0.
* @param textureLength The texture length.
* @returns true if the texture length is set successfully.
*/
setTextureLength(textureLength: number): boolean;

/**
* Set whether to use the default normal to orient the ribbon when no normals are provided in the input.
* The default is false.
* @param useDefaultNormal Whether to use the default normal.
* @returns true if the flag is set successfully.
*/
setUseDefaultNormal(useDefaultNormal: boolean): boolean;

/**
* Set whether to vary the width of the ribbon using scalar data. By default,
* the width of the ribbon is uniform.
* @param varyWidth Whether to vary the width of the ribbon.
* @returns true if the flag is set successfully.
*/
setVaryWidth(varyWidth: boolean): boolean;

/**
* Set the width of the ribbon. The width is the total width of the ribbon;
* the ribbon extends width/2 on either side of the line. The default is 0.5.
* @param width The width of the ribbon.
* @returns true if the width is set successfully.
*/
setWidth(width: number): boolean;

/**
* Set the width factor, used to scale the width when varying the width.
* The default is 1.0.
* @param widthFactor The width factor.
* @returns true if the width factor is set successfully.
*/
setWidthFactor(widthFactor: number): boolean;
}

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

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

/**
* vtkRibbonFilter is a filter to create oriented ribbons from lines defined in
* polygonal dataset. The orientation of the ribbon is along the line segments
* and perpendicular to "projected" line normals. Projected line normals are the
* original line normals projected to be perpendicular to the local line
* segment. An offset angle can be specified to rotate the ribbon with respect
* to the normal.
*/
export declare const vtkRibbonFilter: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkRibbonFilter;
Loading