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 25, 2022
1 parent 576cb14 commit 922ec25
Show file tree
Hide file tree
Showing 14 changed files with 5,060 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/Common/Core/DataArray/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ function vtkDataArray(publicAPI, model) {

return sortedObj;
};

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

// ----------------------------------------------------------------------------
Expand Down
66 changes: 66 additions & 0 deletions Sources/Common/DataModel/DataSetAttributes/FieldData.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ function vtkFieldData(publicAPI, model) {
model.arrays = model.arrays.map((item) => ({ data: vtk(item.data) }));
}

function interpolateTuple(tuple1, tuple2, t) {
// t = 0 -> tuple1, t = 1 -> tuple2
// TODO: multiple components
return [
tuple1[0] + (tuple2[0] - tuple1[0])*t,
tuple1[1] + (tuple2[1] - tuple1[1])*t
];
}

publicAPI.initialize = () => {
publicAPI.initializeFields();
publicAPI.copyAllOn();
Expand Down Expand Up @@ -124,6 +133,63 @@ function vtkFieldData(publicAPI, model) {
}
});
};

publicAPI.interpolateData = (other, fromId1 = -1, fromId2 = -1, t = 0.5, toId = -1) => {
// TODO: Implement
// arr.getTuple(fromId1), arr.getTuple(fromId2) and interpolate between the two tuples
// Create a function for that

const tuple1 = [];
const tuple2 = [];
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();
const tId = toId > -1 ? toId : fromId;
if (newSize < tId * ncomps) {
newSize = (tId + 1) * ncomps;
}
destArr = vtkDataArray.newInstance({
name: arr.getName(),
dataType: arr.getDataType(),
numberOfComponents: arr.getNumberOfComponents(),
size: newSize,
});
arr.getTuple(fromId1, tuple1);
arr.getTuple(fromId2, tuple2);
destArr.setTuple(tId, interpolateTuple(tuple1, tuple2, 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
arr.getTuple(fromId1, tuple1);
arr.getTuple(fromId2, tuple2);
destArr.setTuple(tId, interpolateTuple(tuple1, tuple2, 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
Loading

0 comments on commit 922ec25

Please sign in to comment.