Skip to content

Commit 1b45543

Browse files
dakerfinetjul
authored andcommitted
feat(CleanPolyData): add vtkCleanPolyData
1 parent 348f7f3 commit 1b45543

File tree

15 files changed

+1170
-37
lines changed

15 files changed

+1170
-37
lines changed
26.7 KB
Loading

Documentation/content/examples/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ This will allow you to see the some live code running in your browser. Just pick
109109
[![PolyDataNormals Example][PolyDataNormals]](./PolyDataNormals.html "PolyDataNormals")
110110
[![ThresholdPoints Example][ThresholdPoints]](./ThresholdPoints.html "Cut/Treshold points with point data criteria")
111111
[![ShrinkPolyData Example][ShrinkPolyData]](./ShrinkPolyData.html "ShrinkPolyData")
112+
[![CleanPolyData Example][CleanPolyData]](./CleanPolyData.html "CleanPolyData")
112113

113114
</div>
114115

@@ -129,6 +130,7 @@ This will allow you to see the some live code running in your browser. Just pick
129130
[PolyDataNormals]: ../docs/gallery/PolyDataNormals.jpg
130131
[ThresholdPoints]: ../docs/gallery/ThresholdPoints.jpg
131132
[ShrinkPolyData]: ../docs/gallery/ShrinkPolyData.jpg
133+
[CleanPolyData]: ../docs/gallery/CleanPolyData.jpg
132134

133135
# Sources
134136

Sources/Common/Core/CellArray/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export interface vtkCellArray extends vtkDataArray {
4646
* @returns {Number} Idx of where the cell was inserted
4747
*/
4848
insertNextCell(cellPointIds: number[]): number;
49+
50+
/**
51+
* Get the maximum cell size.
52+
*/
53+
getMaxCellSize(): number;
4954
}
5055

5156
/**

Sources/Common/Core/CellArray/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ function vtkCellArray(publicAPI, model) {
117117
}
118118
return cellId;
119119
};
120+
121+
publicAPI.getMaxCellSize = () =>
122+
publicAPI.getCellSizes().reduce((a, b) => Math.max(a, b), 0);
120123
}
121124

122125
// ----------------------------------------------------------------------------

Sources/Common/DataModel/BoundingBox/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ export const STATIC = {
993993
getLengths,
994994
getMaxLength,
995995
getDiagonalLength,
996+
getDiagonalLength2,
996997
getMinPoint,
997998
getMaxPoint,
998999
getXRange,

Sources/Common/DataModel/DataSet/index.js

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,10 @@
11
import macro from 'vtk.js/Sources/macros';
22
import vtk from 'vtk.js/Sources/vtk';
3+
import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
34
import vtkDataSetAttributes from 'vtk.js/Sources/Common/DataModel/DataSetAttributes';
5+
import vtkMath from 'vtk.js/Sources/Common/Core/Math';
46
import Constants from 'vtk.js/Sources/Common/DataModel/DataSet/Constants';
57

6-
// import vtkBoundingBox from '../BoundingBox';
7-
// import * as vtkMath from '../../Core/Math';
8-
//
9-
// function getBounds(dataset) {
10-
// if (dataset.bounds) {
11-
// return dataset.bounds;
12-
// }
13-
// if (dataset.type && dataset[dataset.type]) {
14-
// const ds = dataset[dataset.type];
15-
// if (ds.bounds) {
16-
// return ds.bounds;
17-
// }
18-
// if (ds.Points && ds.Points.bounds) {
19-
// return ds.Points.bounds;
20-
// }
21-
22-
// if (ds.Points && ds.Points.values) {
23-
// const array = ds.Points.values;
24-
// const bbox = [...vtkBoundingBox.INIT_BOUNDS];
25-
// const size = array.length;
26-
// const delta = ds.Points.numberOfComponents ? ds.Points.numberOfComponents : 3;
27-
// for (let idx = 0; idx < size; idx += delta) {
28-
// vtkBoundingBox.addPoint(bbox, array[idx * delta], array[(idx * delta) + 1], array[(idx * delta) + 2]);
29-
// }
30-
// ds.Points.bounds = bbox;
31-
// return ds.Points.bounds;
32-
// }
33-
// }
34-
// return vtkMath.createUninitializedBounds();
35-
// }
36-
378
// ----------------------------------------------------------------------------
389
// Global methods
3910
// ----------------------------------------------------------------------------
@@ -57,6 +28,73 @@ function vtkDataSet(publicAPI, model) {
5728
}
5829
});
5930

31+
//------------------------------------------------------------------------------
32+
// Compute the data bounding box from data points.
33+
publicAPI.computeBounds = () => {
34+
if (
35+
(model.modifiedTime &&
36+
model.computeTime &&
37+
model.modifiedTime > model.computeTime) ||
38+
!model.computeTime
39+
) {
40+
const points = publicAPI.getPoints();
41+
if (points?.getNumberOfPoints()) {
42+
// Compute bounds from points
43+
vtkBoundingBox.setBounds(model.bounds, points.getBoundsByReference());
44+
} else {
45+
model.bounds = vtkMath.createUninitializedBounds();
46+
}
47+
// Update computeTime
48+
model.computeTime = macro.getCurrentGlobalMTime();
49+
}
50+
};
51+
52+
/**
53+
* Returns the squared length of the diagonal of the bounding box
54+
*/
55+
publicAPI.getLength2 = () => {
56+
const bounds = publicAPI.getBoundsByReference();
57+
if (!bounds || bounds.length !== 6) return 0;
58+
return vtkBoundingBox.getDiagonalLength2(bounds);
59+
};
60+
61+
/**
62+
* Returns the length of the diagonal of the bounding box
63+
*/
64+
publicAPI.getLength = () => Math.sqrt(publicAPI.getLength2());
65+
66+
/**
67+
* Returns the center of the bounding box as [x, y, z]
68+
*/
69+
publicAPI.getCenter = () => {
70+
const bounds = publicAPI.getBoundsByReference();
71+
if (!bounds || bounds.length !== 6) return [0, 0, 0];
72+
return vtkBoundingBox.getCenter(bounds);
73+
};
74+
75+
/**
76+
* Get the bounding box of a cell with the given cellId
77+
* @param {Number} cellId - The id of the cell
78+
* @returns {Number[]} - The bounds as [xmin, xmax, ymin, ymax, zmin, zmax]
79+
*/
80+
publicAPI.getCellBounds = (cellId) => {
81+
const cell = publicAPI.getCell(cellId);
82+
if (cell) {
83+
return cell.getBounds();
84+
}
85+
return vtkMath.createUninitializedBounds();
86+
};
87+
88+
publicAPI.getBounds = macro.chain(
89+
() => publicAPI.computeBounds,
90+
publicAPI.getBounds
91+
);
92+
93+
publicAPI.getBoundsByReference = macro.chain(
94+
() => publicAPI.computeBounds,
95+
publicAPI.getBoundsByReference
96+
);
97+
6098
const superShallowCopy = publicAPI.shallowCopy;
6199
publicAPI.shallowCopy = (other, debug = false) => {
62100
superShallowCopy(other, debug);
@@ -98,7 +136,7 @@ export function extend(publicAPI, model, initialValues = {}) {
98136
// Object methods
99137
macro.obj(publicAPI, model);
100138
macro.setGet(publicAPI, model, DATASET_FIELDS);
101-
139+
macro.getArray(publicAPI, model, ['bounds'], 6);
102140
// Object specific methods
103141
vtkDataSet(publicAPI, model);
104142
}

Sources/Common/DataModel/DataSetAttributes/FieldData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function vtkFieldData(publicAPI, model) {
3232
publicAPI.copyStructure = (other) => {
3333
publicAPI.initializeFields();
3434
model.copyFieldFlags = other.getCopyFieldFlags().map((x) => x); // Deep-copy
35-
model.arrays = other.arrays().map((x) => ({ array: x })); // Deep-copy
35+
model.arrays = other.getArrays().map((x) => ({ data: x })); // Deep-copy
3636
// TODO: Copy array information objects (once we support information objects)
3737
};
3838

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ export interface vtkPolyData extends vtkPointSet {
6666
getLines(): vtkCellArray;
6767

6868
/**
69-
*
69+
* Get the links between points and cells.
7070
*/
71-
getLinks(): any;
71+
getLinks(): any; // vtkCellLinks
72+
73+
/**
74+
* Get the maximum cell size.
75+
* Returns 0 if there is no cell.
76+
*/
77+
getMaxCellSize(): number;
7278

7379
/**
7480
* Determine the number of cells composing the polydata.
@@ -104,7 +110,7 @@ export interface vtkPolyData extends vtkPointSet {
104110
* Topological inquiry to get cells using point.
105111
* @param ptId
106112
*/
107-
getPointCells(ptId: any): void;
113+
getPointCells(ptId: number): void;
108114

109115
/**
110116
* Get the cell array defining polys.

Sources/Common/DataModel/PolyData/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ import vtkCellLinks from 'vtk.js/Sources/Common/DataModel/CellLinks';
55
import vtkCellTypes from 'vtk.js/Sources/Common/DataModel/CellTypes';
66
import vtkLine from 'vtk.js/Sources/Common/DataModel/Line';
77
import vtkPointSet from 'vtk.js/Sources/Common/DataModel/PointSet';
8+
import vtkPolyLine from 'vtk.js/Sources/Common/DataModel/PolyLine';
9+
import vtkPolygon from 'vtk.js/Sources/Common/DataModel/Polygon';
10+
import vtkQuad from 'vtk.js/Sources/Common/DataModel/Quad';
811
import vtkTriangle from 'vtk.js/Sources/Common/DataModel/Triangle';
9-
12+
import vtkTriangleStrip from 'vtk.js/Sources/Common/DataModel/TriangleStrip';
1013
import { CellType } from 'vtk.js/Sources/Common/DataModel/CellTypes/Constants';
1114
import { POLYDATA_FIELDS } from 'vtk.js/Sources/Common/DataModel/PolyData/Constants';
1215

1316
const { vtkWarningMacro } = macro;
1417

1518
export const CELL_FACTORY = {
1619
[CellType.VTK_LINE]: vtkLine,
20+
[CellType.VTK_QUAD]: vtkQuad,
1721
[CellType.VTK_POLY_LINE]: vtkLine,
1822
[CellType.VTK_TRIANGLE]: vtkTriangle,
23+
[CellType.VTK_TRIANGLE_STRIP]: vtkTriangleStrip,
24+
[CellType.VTK_POLY_LINE]: vtkPolyLine,
25+
[CellType.VTK_POLYGON]: vtkPolygon,
1926
};
2027

2128
// ----------------------------------------------------------------------------
@@ -242,6 +249,12 @@ function vtkPolyData(publicAPI, model) {
242249
cell.initialize(publicAPI.getPoints(), cellInfo.cellPointIds);
243250
return cell;
244251
};
252+
253+
publicAPI.getMaxCellSize = () =>
254+
POLYDATA_FIELDS.reduce(
255+
(max, type) => Math.max(max, model[type]?.getMaxCellSize?.() ?? 0),
256+
0
257+
);
245258
}
246259

247260
// ----------------------------------------------------------------------------
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<table>
2+
<tr>
3+
<td colspan="5"><b>Before(Left Cube)<b></td>
4+
</tr>
5+
<tr>
6+
<td style="padding: 5px;">Points : <span class="initial-points">0</span></td>
7+
<td style="padding: 5px;">Cells : <span class="initial-cells">0</span></td>
8+
<td style="padding: 5px;">Lines : <span class="initial-lines">0</span></td>
9+
<td style="padding: 5px;">Polys : <span class="initial-polys">0</span></td>
10+
<td style="padding: 5px;">Strips : <span class="initial-strips">0</span></td>
11+
</tr>
12+
<tr>
13+
<td colspan="5"><b>After(Right Cube)<b></td>
14+
</tr>
15+
<tr>
16+
<td style="padding: 5px;">Points : <span class="final-points">0</span></td>
17+
<td style="padding: 5px;">Cells : <span class="final-cells">0</span></td>
18+
<td style="padding: 5px;">Lines : <span class="final-lines">0</span></td>
19+
<td style="padding: 5px;">Polys : <span class="final-polys">0</span></td>
20+
<td style="padding: 5px;">Strips : <span class="final-strips">0</span></td>
21+
</tr>
22+
</table>

0 commit comments

Comments
 (0)