Skip to content

Commit

Permalink
feat(vtkClipClosedSurface): Implement vtkClipClosedSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
David Berger committed Jul 28, 2022
1 parent 576cb14 commit 5e244d1
Show file tree
Hide file tree
Showing 24 changed files with 5,644 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Sources/Common/Core/CellArray/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function vtkCellArray(publicAPI, model) {
if (model.cellSizes) {
model.numberOfCells = model.cellSizes.length;
} else {
model.numberOfCells = getNumberOfCells(model.values);
model.numberOfCells = getNumberOfCells(publicAPI.getData());
}
return model.numberOfCells;
};
Expand All @@ -61,7 +61,7 @@ function vtkCellArray(publicAPI, model) {
return model.cellSizes;
}

model.cellSizes = extractCellSizes(model.values);
model.cellSizes = extractCellSizes(publicAPI.getData());
return model.cellSizes;
};

Expand All @@ -80,6 +80,8 @@ function vtkCellArray(publicAPI, model) {
const numberOfPoints = model.values[cellLoc++];
return model.values.subarray(cellLoc, cellLoc + numberOfPoints);
};

publicAPI.insertNextCell = publicAPI.insertNextTuple;
}

// ----------------------------------------------------------------------------
Expand Down
31 changes: 29 additions & 2 deletions Sources/Common/Core/DataArray/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { vtkObject, vtkRange } from "../../../interfaces";
import { TypedArray } from "../../../types";
import { float, int, TypedArray } from "../../../types";


/**
Expand Down Expand Up @@ -125,6 +125,33 @@ export interface vtkDataArray extends vtkObject {
*/
getState(): object;

/**
* Deep copy of another vtkDataArray into this one.
* @param {vtkDataArray} other
*/
deepCopy(other: vtkDataArray): void;

/**
* Interpolate between the tuples retrieved from source1
* and source2 with the resp. indices and set the
* resulting tuple to the idx of this DataArray.
*
* @param {int} idx,
* @param {vtkDataArray} source1,
* @param {int} source1Idx,
* @param {vtkDataArray} source2,
* @param {int} source2Idx,
* @param {float} t
*/
interpolateTuple(
idx: int,
source1: vtkDataArray,
source1Idx: int,
source2: vtkDataArray,
source2Idx: int,
t: float
): void;

// --- via macro --

/**
Expand Down Expand Up @@ -252,7 +279,7 @@ export declare const vtkDataArray: {
// static
computeRange: typeof computeRange,
createRangeHelper: typeof createRangeHelper,
fastComputeRange: typeof fastComputeRange,
fastComputeRange: typeof fastComputeRange,
getDataType: typeof getDataType,
getMaxNorm: typeof getMaxNorm,
// constants
Expand Down
98 changes: 92 additions & 6 deletions Sources/Common/Core/DataArray/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Constants from 'vtk.js/Sources/Common/Core/DataArray/Constants';
import * as macro from 'vtk.js/Sources/macros';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';

const { vtkErrorMacro } = macro;
const { DefaultDataType } = Constants;
const TUPLE_HOLDER = [];

Expand Down Expand Up @@ -157,7 +158,20 @@ function vtkDataArray(publicAPI, model) {
}
};

publicAPI.getData = () => model.values;
publicAPI.getValue = (valueIdx) => {
const idx = valueIdx / model.numberOfComponents;
const comp = valueIdx % model.numberOfComponents;
return publicAPI.getComponent(idx, comp);
};

publicAPI.setValue = (valueIdx, value) => {
const idx = valueIdx / model.numberOfComponents;
const comp = valueIdx % model.numberOfComponents;
publicAPI.setComponent(idx, comp, value);
};

publicAPI.getData = () =>
model.size === 0 ? model.values : model.values.subarray(0, model.size);

publicAPI.getRange = (componentIndex = -1) => {
const rangeIdx =
Expand All @@ -177,7 +191,7 @@ function vtkDataArray(publicAPI, model) {

// Need to compute ranges...
range = computeRange(
model.values,
publicAPI.getData(),
componentIndex,
model.numberOfComponents
);
Expand Down Expand Up @@ -205,6 +219,24 @@ function vtkDataArray(publicAPI, model) {
for (let i = 0; i < model.numberOfComponents; i++) {
model.values[offset + i] = tuple[i];
}
// TODO
// model.size = max(model.size, offset) ?
};

publicAPI.insertNextTuple = (tuple) => {
const idx = model.size / model.numberOfComponents;
model.size += model.numberOfComponents;
if (model.size >= model.values.length) {
// Re-allocate model.values
const oldValues = model.values;
model.values = macro.newTypedArray(
model.dataType,
model.values.length * 2
);
model.values.set(oldValues);
}
publicAPI.setTuple(idx, tuple);
return idx;
};

publicAPI.getTuple = (idx, tupleToFill = TUPLE_HOLDER) => {
Expand Down Expand Up @@ -239,9 +271,8 @@ function vtkDataArray(publicAPI, model) {

publicAPI.getTupleLocation = (idx = 1) => idx * model.numberOfComponents;
publicAPI.getNumberOfComponents = () => model.numberOfComponents;
publicAPI.getNumberOfValues = () => model.values.length;
publicAPI.getNumberOfTuples = () =>
model.values.length / model.numberOfComponents;
publicAPI.getNumberOfValues = () => model.size;
publicAPI.getNumberOfTuples = () => model.size / model.numberOfComponents;
publicAPI.getDataType = () => model.dataType;
/* eslint-disable no-use-before-define */
publicAPI.newClone = () =>
Expand Down Expand Up @@ -307,6 +338,61 @@ function vtkDataArray(publicAPI, model) {

return sortedObj;
};

publicAPI.deepCopy = (other) => {
publicAPI.shallowCopy(other);
publicAPI.setData(other.getData().slice());
};

// TODO: Check
publicAPI.interpolateTuple = (
idx,
source1,
source1Idx,
source2,
source2Idx,
t
) => {
const numberOfComponents = model.numberOfComponents || 1;
if (
numberOfComponents !== source1.getNumberOfComponents() ||
numberOfComponents !== source2.getNumberOfComponents()
) {
vtkErrorMacro('numberOfComponents must match');
}

const tuple1 = [];
const tuple2 = [];
const out = [];
out.length = numberOfComponents;

source1.getTuple(source1Idx, tuple1);
source2.getTuple(source2Idx, tuple2);

// Check most common component sizes first
// to avoid doing a for loop if possible
if (numberOfComponents === 1) {
out[0] = tuple1[0] + (tuple2[0] - tuple1[0]) * t;
} else if (numberOfComponents === 2) {
out[0] = tuple1[0] + (tuple2[0] - tuple1[0]) * t;
out[1] = tuple1[1] + (tuple2[1] - tuple1[1]) * t;
} else if (numberOfComponents === 3) {
out[0] = tuple1[0] + (tuple2[0] - tuple1[0]) * t;
out[1] = tuple1[1] + (tuple2[1] - tuple1[1]) * t;
out[2] = tuple1[2] + (tuple2[2] - tuple1[2]) * t;
} else if (numberOfComponents === 4) {
out[0] = tuple1[0] + (tuple2[0] - tuple1[0]) * t;
out[1] = tuple1[1] + (tuple2[1] - tuple1[1]) * t;
out[2] = tuple1[2] + (tuple2[2] - tuple1[2]) * t;
out[3] = tuple1[3] + (tuple2[3] - tuple1[3]) * t;
} else {
for (let i = 0; i < numberOfComponents; i++) {
out[i] = tuple1[i] + (tuple2[i] - tuple1[i]) * t;
}
}

publicAPI.setTuple(idx, out);
};
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -341,7 +427,7 @@ export function extend(publicAPI, model, initialValues = {}) {
}

if (model.values) {
model.size = model.values.length;
model.size = model.size === 0 ? model.values.length : model.size;
model.dataType = getDataType(model.values);
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/Common/Core/Points/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function vtkPoints(publicAPI, model) {
}
};

publicAPI.insertNextPoint = publicAPI.insertNextTuple;

publicAPI.getPoint = publicAPI.getTuple;

publicAPI.getBounds = () => {
Expand Down
54 changes: 54 additions & 0 deletions Sources/Common/DataModel/DataSetAttributes/FieldData.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,60 @@ function vtkFieldData(publicAPI, model) {
}
});
};

publicAPI.interpolateData = (
other,
fromId1 = -1,
fromId2 = -1,
t = 0.5,
toId = -1
) => {
other.getArrays().forEach((arr) => {
const copyFlag = publicAPI.getFlag(arr.getName());
if (
copyFlag !== false &&
!(model.doCopyAllOff && copyFlag !== true) &&
arr
) {
let destArr = publicAPI.getArrayByName(arr.getName());
if (!destArr) {
if (fromId1 < 0 || fromId2 < 0 || fromId1 > arr.getNumberOfTuples()) {
publicAPI.addArray(arr);
} else {
const ncomps = arr.getNumberOfComponents();
let newSize = arr.getNumberOfValues();
// TODO: Is this supposed to happen?
const tId = toId > -1 ? toId : fromId1;
if (newSize < tId * ncomps) {
newSize = (tId + 1) * ncomps;
}
destArr = vtkDataArray.newInstance({
name: arr.getName(),
dataType: arr.getDataType(),
numberOfComponents: arr.getNumberOfComponents(),
size: newSize,
});
destArr.interpolateTuple(tId, arr, fromId1, arr, fromId2, t);
publicAPI.addArray(destArr);
}
} else if (
arr.getNumberOfComponents() === destArr.getNumberOfComponents()
) {
if (fromId1 > -1 && fromId1 < arr.getNumberOfTuples()) {
const tId = toId > -1 ? toId : fromId1;
// TODO: vtkWarning not supposed to happen
destArr.interpolateTuple(tId, arr, fromId1, arr, fromId2, t);
} else {
// if fromId and not provided, just copy all (or as much possible)
// of arr to destArr.
for (let i = 0; i < arr.getNumberOfTuples(); ++i) {
destArr.setTuple(i, arr.getTuple(i));
}
}
}
}
});
};
publicAPI.copyFieldOn = (arrayName) => {
model.copyFieldFlags[arrayName] = true;
};
Expand Down
6 changes: 6 additions & 0 deletions Sources/Common/DataModel/DataSetAttributes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ function vtkDataSetAttributes(publicAPI, model) {
AttributeTypes[attType]
] = false;
};
publicAPI[`copy${value}On`] = () => {
const attType = value.toUpperCase();
model.copyAttributeFlags[AttributeCopyOperations.PASSDATA][
AttributeTypes[attType]
] = true;
};
});

publicAPI.initializeAttributeCopyFlags = () => {
Expand Down
1 change: 1 addition & 0 deletions Sources/Common/DataModel/IncrementalOctreeNode/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
Loading

0 comments on commit 5e244d1

Please sign in to comment.