Skip to content

Commit 7188a57

Browse files
committed
fix(dataobject): add initialize() to clear vtkDataSet
Previous outData must be cleared before populated by requestData
1 parent aa3138f commit 7188a57

File tree

65 files changed

+194
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+194
-146
lines changed

Sources/Common/Core/DataArray/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ function vtkDataArray(publicAPI, model) {
198198
return false;
199199
};
200200

201-
// FIXME, to rename into "clear()" or "reset()"
201+
// Restore the array to initial state
202202
publicAPI.initialize = () => {
203203
publicAPI.resize(0);
204+
return publicAPI;
204205
};
205206

206207
publicAPI.getElementComponentSize = () => model.values.BYTES_PER_ELEMENT;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import { FieldAssociations, FieldDataTypes } from './Constants';
88
export interface IDataSetInitialValues {}
99

1010
export interface vtkDataSet extends vtkObject {
11+
/**
12+
* Initialize the field, cell and point data.
13+
* @see vtkDataSetAttributes::initialize()
14+
* @see vtkFieldData::initialize()
15+
*/
16+
initialize(): void;
17+
1118
/**
1219
* Get dataset's cell data
1320
*/

Sources/Common/DataModel/DataSet/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ function vtkDataSet(publicAPI, model) {
7373
Math.max(mTime, model[fieldName]?.getMTime() ?? mTime),
7474
superGetMTime()
7575
);
76+
77+
publicAPI.initialize = () => {
78+
DATASET_FIELDS.forEach((fieldName) => model[fieldName]?.initialize());
79+
return publicAPI;
80+
};
7681
}
7782

7883
// ----------------------------------------------------------------------------

Sources/Common/DataModel/DataSetAttributes/FieldData.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ interface IArrayWithIndex {
2222

2323
export interface vtkFieldData extends vtkObject {
2424
/**
25-
*
25+
* Initialize fields, clear flags and restore copy beahvior.
26+
* @see initializeFields
27+
* @see clearFieldFlags
28+
* @see copyAllOn
2629
*/
2730
initialize(): void;
2831

2932
/**
30-
*
33+
* Delete all arrays and clear flags.
34+
* @see initialize
3135
*/
3236
initializeFields(): void;
3337

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ export interface vtkDataSetAttributes extends vtkFieldData {
229229
removeArrayByIndex(arrayIdx: number): void;
230230

231231
/**
232-
*
232+
* Called when initialize() is called.
233+
* @see initialize
233234
*/
234235
initializeAttributeCopyFlags(): void;
235236

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ interface IComputeHistogram {
2020
}
2121

2222
export interface vtkImageData extends vtkDataSet {
23+
/**
24+
* Reinitialize the state (direction, spacing, origin, extent, etc.)
25+
* and the data set.
26+
* @see vtkDataSet::initialize()
27+
*/
28+
initialize(): void;
29+
2330
/**
2431
* Returns an object with `{ minimum, maximum, average, variance, sigma, count }`
2532
* of the imageData points found within the provided `worldBounds`.

Sources/Common/DataModel/ImageData/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,18 @@ function vtkImageData(publicAPI, model) {
393393
.getScalars()
394394
.getComponent(offsetIndex, comp);
395395
};
396+
397+
const superInitialize = publicAPI.initialize;
398+
publicAPI.initialize = () => {
399+
publicAPI.set({
400+
direction: mat3.identity(model.direction),
401+
spacing: [1.0, 1.0, 1.0],
402+
origin: [0.0, 0.0, 0.0],
403+
extent: [0, -1, 0, -1, 0, -1],
404+
dataDescription: StructuredType.EMPTY,
405+
});
406+
return superInitialize();
407+
};
396408
}
397409

398410
// ----------------------------------------------------------------------------

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import vtkDataSet, { IDataSetInitialValues } from '../DataSet';
88
export interface IPointSetInitialValues extends IDataSetInitialValues {}
99

1010
export interface vtkPointSet extends vtkDataSet {
11+
/**
12+
* Empty the points and initialize the data set and .
13+
* @see vtkDataSet::initialize()
14+
*/
15+
initialize(): void;
16+
1117
/**
1218
* Compute the (X, Y, Z) bounds of the data.
1319
*/

Sources/Common/DataModel/PointSet/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ function vtkPointSet(publicAPI, model) {
4242
const mTime = superGetMTime();
4343
return Math.max(mTime, model.points?.getMTime() ?? mTime);
4444
};
45+
46+
const superInitialize = publicAPI.initialize;
47+
publicAPI.initialize = () => {
48+
model.points?.initialize();
49+
return superInitialize();
50+
};
4551
}
4652

4753
// ----------------------------------------------------------------------------

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import vtkPointSet, { IPointSetInitialValues } from '../PointSet';
88
export interface IPolyDataInitialValues extends IPointSetInitialValues {}
99

1010
export interface vtkPolyData extends vtkPointSet {
11+
/**
12+
* Empty the cells and initialize the point set.
13+
* @see vtkPointSet::initialize()
14+
*/
15+
initialize(): void;
16+
1117
/**
1218
* Create data structure that allows random access of cells.
1319
*/

0 commit comments

Comments
 (0)