Skip to content

Commit 3b54de3

Browse files
dakerfinetjul
authored andcommitted
feat(FillHolesFilter): add vtkFillHolesFilter
1 parent 86b85f7 commit 3b54de3

8 files changed

Lines changed: 580 additions & 5 deletions

File tree

Data/stl/spherewithholes.stl

56 KB
Binary file not shown.
31.4 KB
Loading
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import { vtkObject } from '../../../interfaces';
2+
import { Nullable } from '../../../types';
3+
4+
export interface ICellLinksInitialValues {}
5+
6+
/**
7+
* Link record for a point: number of incident cells and their ids.
8+
*/
9+
export interface ICellLink {
10+
/**
11+
* Number of cells using the point.
12+
*/
13+
ncells: number;
14+
/**
15+
* Cell ids that use the point.
16+
*/
17+
cells: Nullable<number[]>;
18+
}
19+
20+
export interface vtkCellLinks extends vtkObject {
21+
/**
22+
* Build the link list array from the input dataset.
23+
* The resulting structure maps each point id to the cells that reference it.
24+
*/
25+
buildLinks(data: any): void;
26+
27+
/**
28+
* Allocate storage for a number of links (typically the number of points).
29+
* @param {Number} numLinks Number of point links to allocate.
30+
* @param {Number} [extSize=1000] Growth factor used for future extensions.
31+
*/
32+
allocate(numLinks: number, extSize?: number): void;
33+
34+
/**
35+
* Allocate per-point cell-id arrays based on precomputed link counts.
36+
* @param {Number} n Number of links (points).
37+
*/
38+
allocateLinks(n: number): void;
39+
40+
/**
41+
* Clear out previously allocated link structures.
42+
*/
43+
initialize(): void;
44+
45+
/**
46+
* Get the full link structure for a point id.
47+
* @param {Number} ptId Point id.
48+
*/
49+
getLink(ptId: number): ICellLink;
50+
51+
/**
52+
* Get the number of cells using the point.
53+
* @param {Number} ptId Point id.
54+
*/
55+
getNcells(ptId: number): number;
56+
57+
/**
58+
* Return the list of cell ids that use the point.
59+
* @param {Number} ptId Point id.
60+
*/
61+
getCells(ptId: number): Nullable<number[]>;
62+
63+
/**
64+
* Insert a new point entry into the links structure.
65+
* @param {Number} numLinks Initial size of the point's cell-id list.
66+
*/
67+
insertNextPoint(numLinks: number): void;
68+
69+
/**
70+
* Append a cell id to the point's cell-id list.
71+
* @param {Number} ptId Point id.
72+
* @param {Number} cellId Cell id.
73+
*/
74+
insertNextCellReference(ptId: number, cellId: number): void;
75+
76+
/**
77+
* Delete a point by removing all links to using cells.
78+
* @param {Number} ptId Point id.
79+
*/
80+
deletePoint(ptId: number): void;
81+
82+
/**
83+
* Remove the reference from a point to a cell.
84+
* @param {Number} cellId Cell id.
85+
* @param {Number} ptId Point id.
86+
*/
87+
removeCellReference(cellId: number, ptId: number): void;
88+
89+
/**
90+
* Add a reference from a point to a cell.
91+
* @param {Number} cellId Cell id.
92+
* @param {Number} ptId Point id.
93+
*/
94+
addCellReference(cellId: number, ptId: number): void;
95+
96+
/**
97+
* Resize a point's cell-id list.
98+
* @param {Number} ptId Point id.
99+
* @param {Number} size New list size.
100+
*/
101+
resizeCellList(ptId: number, size: number): void;
102+
103+
/**
104+
* Reclaim unused memory.
105+
*/
106+
squeeze(): void;
107+
108+
/**
109+
* Reset to an empty state without freeing memory.
110+
*/
111+
reset(): void;
112+
113+
/**
114+
* Deep-copy from another cell-links instance.
115+
* @param src Source object.
116+
*/
117+
deepCopy(src: any): void;
118+
119+
/**
120+
* Increment the count of cells using a point.
121+
* @param {Number} ptId Point id.
122+
*/
123+
incrementLinkCount(ptId: number): void;
124+
125+
/**
126+
* Insert a cell id into a point's cell-id list at a specific position.
127+
* @param {Number} ptId Point id.
128+
* @param {Number} pos Position inside the point's list.
129+
* @param {Number} cellId Cell id.
130+
*/
131+
insertCellReference(ptId: number, pos: number, cellId: number): void;
132+
}
133+
134+
/**
135+
* Method used to decorate a given object (publicAPI+model) with vtkCellLinks characteristics.
136+
*
137+
* @param publicAPI object on which methods will be bounds (public)
138+
* @param model object on which data structure will be bounds (protected)
139+
* @param {ICellLinksInitialValues} [initialValues] (default: {})
140+
*/
141+
export function extend(
142+
publicAPI: object,
143+
model: object,
144+
initialValues?: ICellLinksInitialValues
145+
): void;
146+
147+
/**
148+
* Method used to create a new instance of vtkCellLinks.
149+
* @param {ICellLinksInitialValues} [initialValues] for pre-setting some of its content
150+
*/
151+
export function newInstance(
152+
initialValues?: ICellLinksInitialValues
153+
): vtkCellLinks;
154+
155+
/**
156+
* vtkCellLinks maps each point to the cells that reference it.
157+
*/
158+
export declare const vtkCellLinks: {
159+
newInstance: typeof newInstance;
160+
extend: typeof extend;
161+
};
162+
export default vtkCellLinks;

Sources/Common/DataModel/PolyData/index.d.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CellType, Vector3 } from '../../../types';
1+
import { CellType } from '../../../types';
22
import vtkCellArray from '../../Core/CellArray';
33
import vtkPointSet, { IPointSetInitialValues } from '../PointSet';
44

@@ -36,10 +36,15 @@ export interface vtkPolyData extends vtkPointSet {
3636
/**
3737
* Get the neighbors at an edge.
3838
* @param {Number} cellId The Id of the cell.
39-
* @param {Vector3} point1 The first point coordinate.
40-
* @param {Vector3} point2 The second point coordinate.
41-
*/
42-
getCellEdgeNeighbors(cellId: number, point1: Vector3, point2: Vector3): void;
39+
* @param {Number} point1 The first point id.
40+
* @param {Number} point2 The second point id.
41+
* @returns {Number[]} Neighbor cell ids.
42+
*/
43+
getCellEdgeNeighbors(
44+
cellId: number,
45+
point1: number,
46+
point2: number
47+
): number[];
4348

4449
/**
4550
* Get a list of point ids that define a cell.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 vtkFillHolesFilter from '@kitware/vtk.js/Filters/Modeling/FillHolesFilter';
10+
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
11+
import vtkRenderer from '@kitware/vtk.js/Rendering/Core/Renderer';
12+
import vtkSTLReader from '@kitware/vtk.js/IO/Geometry/STLReader';
13+
14+
// ----------------------------------------------------------------------------
15+
// Example code
16+
// ----------------------------------------------------------------------------
17+
18+
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
19+
const leftRenderer = fullScreenRenderer.getRenderer();
20+
const renderWindow = fullScreenRenderer.getRenderWindow();
21+
const rightRenderer = vtkRenderer.newInstance();
22+
renderWindow.addRenderer(rightRenderer);
23+
leftRenderer.setViewport(0, 0, 0.5, 1);
24+
rightRenderer.setViewport(0.5, 0, 1, 1);
25+
leftRenderer.setBackground(0.32, 0.34, 0.43);
26+
rightRenderer.setBackground(0.32, 0.34, 0.43);
27+
28+
const reader = vtkSTLReader.newInstance({
29+
removeDuplicateVertices: true,
30+
merging: true,
31+
});
32+
const fillHolesFilter = vtkFillHolesFilter.newInstance();
33+
fillHolesFilter.setHoleSize(1000.0);
34+
fillHolesFilter.setInputConnection(reader.getOutputPort());
35+
36+
const readerActor = vtkActor.newInstance();
37+
const readerMapper = vtkMapper.newInstance({ scalarVisibility: false });
38+
readerActor.setMapper(readerMapper);
39+
readerMapper.setInputConnection(reader.getOutputPort());
40+
leftRenderer.addActor(readerActor);
41+
42+
const filledActor = vtkActor.newInstance();
43+
const filledMapper = vtkMapper.newInstance({ scalarVisibility: false });
44+
filledActor.setMapper(filledMapper);
45+
filledMapper.setInputConnection(fillHolesFilter.getOutputPort());
46+
rightRenderer.addActor(filledActor);
47+
48+
reader.setUrl(`${__BASE_PATH__}/data/stl/spherewithholes.stl`).then(() => {
49+
leftRenderer.resetCamera();
50+
rightRenderer.setActiveCamera(leftRenderer.getActiveCamera());
51+
rightRenderer.resetCamera();
52+
renderWindow.render();
53+
});
54+
55+
leftRenderer.resetCamera();
56+
rightRenderer.setActiveCamera(leftRenderer.getActiveCamera());
57+
renderWindow.render();
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
2+
3+
/**
4+
* Initial values for vtkFillHolesFilter.
5+
*/
6+
export interface IFillHolesFilterInitialValues {
7+
holeSize?: number;
8+
}
9+
10+
type vtkFillHolesFilterBase = vtkObject & vtkAlgorithm;
11+
12+
export interface vtkFillHolesFilter extends vtkFillHolesFilterBase {
13+
/**
14+
* Expose methods.
15+
* @param inData
16+
* @param outData
17+
*/
18+
requestData(inData: any, outData: any): void;
19+
20+
/**
21+
* Get the maximum hole size to fill.
22+
*/
23+
getHoleSize(): number;
24+
25+
/**
26+
* Set the maximum hole size to fill.
27+
* @param holeSize
28+
*/
29+
setHoleSize(holeSize: number): boolean;
30+
}
31+
32+
/**
33+
* Method used to decorate a given object (publicAPI+model) with vtkFillHolesFilter characteristics.
34+
*
35+
* @param publicAPI object on which methods will be bounds (public)
36+
* @param model object on which data structure will be bounds (protected)
37+
* @param {IFillHolesFilterInitialValues} [initialValues] (default: {})
38+
*/
39+
export function extend(
40+
publicAPI: object,
41+
model: object,
42+
initialValues?: IFillHolesFilterInitialValues
43+
): void;
44+
45+
/**
46+
* Method used to create a new instance of vtkFillHolesFilter.
47+
* @param {IFillHolesFilterInitialValues} [initialValues] for pre-setting some of its content
48+
*/
49+
export function newInstance(
50+
initialValues?: IFillHolesFilterInitialValues
51+
): vtkFillHolesFilter;
52+
53+
/**
54+
* vtkFillHolesFilter is a filter that identifies and fills holes in input vtkPolyData meshes.
55+
* Holes are identified by locating boundary edges, linking them together into loops,
56+
* and then triangulating the resulting loops. Note that you can specify an approximate
57+
* limit to the size of the hole that can be filled.
58+
*
59+
* The VTK.js implementation follows the same algorithmic approach as VTK C++.
60+
*/
61+
export declare const vtkFillHolesFilter: {
62+
newInstance: typeof newInstance;
63+
extend: typeof extend;
64+
};
65+
export default vtkFillHolesFilter;

0 commit comments

Comments
 (0)