Skip to content

Commit b27ae42

Browse files
authored
Merge pull request #2601 from finetjul/2570-fix-clip-closed-surface
Fix clip closed surface
2 parents 19ed33d + d6e5879 commit b27ae42

File tree

7 files changed

+145
-27
lines changed

7 files changed

+145
-27
lines changed

Sources/Common/DataModel/BoundingBox/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ export function reset(bounds) {
4545
return setBounds(bounds, INIT_BOUNDS);
4646
}
4747

48-
export function addPoint(bounds, ...xyz) {
48+
export function addPoint(bounds, x, y, z) {
4949
const [xMin, xMax, yMin, yMax, zMin, zMax] = bounds;
50-
bounds[0] = xMin < xyz[0] ? xMin : xyz[0];
51-
bounds[1] = xMax > xyz[0] ? xMax : xyz[0];
52-
bounds[2] = yMin < xyz[1] ? yMin : xyz[1];
53-
bounds[3] = yMax > xyz[1] ? yMax : xyz[1];
54-
bounds[4] = zMin < xyz[2] ? zMin : xyz[2];
55-
bounds[5] = zMax > xyz[2] ? zMax : xyz[2];
50+
bounds[0] = xMin < x ? xMin : x;
51+
bounds[1] = xMax > x ? xMax : x;
52+
bounds[2] = yMin < y ? yMin : y;
53+
bounds[3] = yMax > y ? yMax : y;
54+
bounds[4] = zMin < z ? zMin : z;
55+
bounds[5] = zMax > z ? zMax : z;
5656
return bounds;
5757
}
5858

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ export interface vtkIncrementalOctreeNode extends vtkObject {
4848
*/
4949
getBounds(bounds: Bounds): void;
5050

51+
/**
52+
* @param {Vector3} point
53+
*/
54+
getChildIndex(point: Vector3): number;
55+
56+
/**
57+
* @param {Vector3} point
58+
*/
59+
containsPoint(point: Vector3): boolean;
60+
61+
/**
62+
* @param {Vector3} point
63+
*/
64+
containsPointByData(point: Vector3): boolean;
65+
5166
/**
5267
* Given a point inserted to either this node (a leaf node) or a descendant
5368
* leaf (of this node --- when this node is a non-leaf node), update the

Sources/Common/DataModel/IncrementalOctreeNode/index.js

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,33 @@ function vtkIncrementalOctreeNode(publicAPI, model) {
106106
bounds[5] = model.maxBounds[2];
107107
};
108108

109+
publicAPI.getChildIndex = (point) =>
110+
Number(point[0] > model.children[0].getMaxBoundsByReference()[0]) +
111+
// eslint-disable-next-line no-bitwise
112+
(Number(point[1] > model.children[0].getMaxBoundsByReference()[1]) << 1) +
113+
// eslint-disable-next-line no-bitwise
114+
(Number(point[2] > model.children[0].getMaxBoundsByReference()[2]) << 2);
115+
116+
publicAPI.containsPoint = (pnt) =>
117+
model.minBounds[0] < pnt[0] &&
118+
pnt[0] <= model.maxBounds[0] &&
119+
model.minBounds[1] < pnt[1] &&
120+
pnt[1] <= model.maxBounds[1] &&
121+
model.minBounds[2] < pnt[2] &&
122+
pnt[2] <= model.maxBounds[2]
123+
? 1
124+
: 0;
125+
126+
publicAPI.containsPointByData = (pnt) =>
127+
model.minDataBounds[0] <= pnt[0] &&
128+
pnt[0] <= model.maxDataBounds[0] &&
129+
model.minDataBounds[1] <= pnt[1] &&
130+
pnt[1] <= model.maxDataBounds[1] &&
131+
model.minDataBounds[2] <= pnt[2] &&
132+
pnt[2] <= model.maxDataBounds[2]
133+
? 1
134+
: 0;
135+
109136
//------------------------------------------------------------------------------
110137
publicAPI.updateCounterAndDataBounds = (point, nHits, updateData) => {
111138
model.numberOfPoints += nHits;
@@ -183,6 +210,7 @@ function vtkIncrementalOctreeNode(publicAPI, model) {
183210
publicAPI.getChild = (i) => model.children[i];
184211

185212
//------------------------------------------------------------------------------
213+
/* eslint-disable no-use-before-define */
186214
publicAPI.separateExactlyDuplicatePointsFromNewInsertion = (
187215
points,
188216
pntIds,
@@ -222,14 +250,14 @@ function vtkIncrementalOctreeNode(publicAPI, model) {
222250
// create eight child nodes
223251
// FIXME: May be too slow to use vtk newInstance()
224252
ocNode.children = [
225-
vtkIncrementalOctreeNode.newInstance(),
226-
vtkIncrementalOctreeNode.newInstance(),
227-
vtkIncrementalOctreeNode.newInstance(),
228-
vtkIncrementalOctreeNode.newInstance(),
229-
vtkIncrementalOctreeNode.newInstance(),
230-
vtkIncrementalOctreeNode.newInstance(),
231-
vtkIncrementalOctreeNode.newInstance(),
232-
vtkIncrementalOctreeNode.newInstance(),
253+
newInstance(),
254+
newInstance(),
255+
newInstance(),
256+
newInstance(),
257+
newInstance(),
258+
newInstance(),
259+
newInstance(),
260+
newInstance(),
233261
];
234262
for (i = 0; i < 8; i++) {
235263
// x-bound: axis 0
@@ -244,7 +272,7 @@ function vtkIncrementalOctreeNode(publicAPI, model) {
244272
octMin[2] = boxPtr[OCTREE_CHILD_BOUNDS_LUT[i][2][0]][2];
245273
octMax[2] = boxPtr[OCTREE_CHILD_BOUNDS_LUT[i][2][1]][2];
246274

247-
ocNode.children[i] = vtkIncrementalOctreeNode.newInstance();
275+
ocNode.children[i] = newInstance();
248276
ocNode.children[i].setParent(ocNode);
249277
ocNode.children[i].setBounds(
250278
octMin[0],
@@ -284,6 +312,7 @@ function vtkIncrementalOctreeNode(publicAPI, model) {
284312
);
285313
return pointIdx;
286314
};
315+
/* eslint-enable no-use-before-define */
287316

288317
//------------------------------------------------------------------------------
289318
publicAPI.createChildNodes = (
@@ -355,8 +384,9 @@ function vtkIncrementalOctreeNode(publicAPI, model) {
355384
octMax[2] = boxPtr[OCTREE_CHILD_BOUNDS_LUT[i][2][1]][2];
356385

357386
// This call internally sets the cener and default data bounding box, too.
358-
model.children[i] = vtkIncrementalOctreeNode.newInstance();
359-
model.children[i].iD = nbNodes++;
387+
// eslint-disable-next-line no-use-before-define
388+
model.children[i] = newInstance();
389+
// model.children[i].iD = nbNodes++;
360390
model.children[i].setParent(publicAPI);
361391
model.children[i].setBounds(
362392
octMin[0],
@@ -380,7 +410,7 @@ function vtkIncrementalOctreeNode(publicAPI, model) {
380410
tempId = pntIds[i];
381411
points.getPoint(tempId, tempPt);
382412
target = publicAPI.getChildIndex(tempPt);
383-
model.children[target].getPointIdSet().insertNextId(tempId);
413+
model.children[target].getPointIdSet().push(tempId);
384414
model.children[target].updateCounterAndDataBounds(tempPt);
385415
numIds[target]++;
386416
}
@@ -435,7 +465,7 @@ function vtkIncrementalOctreeNode(publicAPI, model) {
435465
// objects at hand.
436466
for (i = 0; i < 8; i++) {
437467
if (numIds[i] === 0 || i === dvidId) {
438-
model.children[i].deletePointIdSet();
468+
model.children[i].getPointIdSet().length = 0;
439469
}
440470
}
441471

@@ -763,7 +793,7 @@ export function extend(publicAPI, model, initialValues = {}) {
763793
6
764794
);
765795

766-
macro.get(publicAPI, model, ['pointIdSet']);
796+
macro.get(publicAPI, model, ['pointIdSet', 'numberOfPoints']);
767797

768798
// TODO: No get?
769799
macro.set(publicAPI, model, ['parent']);

Sources/Common/DataModel/IncrementalOctreePointLocator/index.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,66 @@ function vtkIncrementalOctreePointLocator(publicAPI, model) {
6363
return [pntIdx, dist2];
6464
};
6565

66+
publicAPI.findClosestPointInSphere = (point, radius2, maskNode, refDist2) => {
67+
let pointIndx = -1;
68+
let minDist2 = Number.MAX_VALUE;
69+
70+
const nodesBase = [];
71+
nodesBase.push(model.octreeRootNode);
72+
73+
let checkNode;
74+
let childNode;
75+
let distToData;
76+
let tempDist2;
77+
let tempPntId;
78+
79+
while (!nodesBase.length === 0 && minDist2 > 0.0) {
80+
checkNode = nodesBase.top();
81+
nodesBase.pop();
82+
83+
if (!checkNode.isLeaf()) {
84+
for (let i = 0; i < 8; i++) {
85+
childNode = checkNode.getChild(i);
86+
87+
// use ( radius2 + radius2 ) to skip empty nodes
88+
distToData = childNode.getNumberOfPoints()
89+
? childNode.getDistance2ToBoundary(point, model.octreeRootNode, 1)
90+
: radius2 + radius2;
91+
92+
// If a child node is not the mask node AND its distance, specifically
93+
// the data bounding box (determined by the points inside or under) to
94+
// the point, is less than the threshold radius (one exception is the
95+
// point's container nodes), it is pushed to the stack as a suspect.
96+
if (
97+
childNode !== maskNode &&
98+
(distToData <= refDist2 || childNode.containsPoint(point) === 1)
99+
) {
100+
nodesBase.push(childNode);
101+
}
102+
103+
childNode = null;
104+
}
105+
} else {
106+
// now that the node under check is a leaf, let's find the closest
107+
// point therein and the minimum distance
108+
109+
[tempPntId, tempDist2] = publicAPI.findClosestPointInLeafNode(
110+
checkNode,
111+
point
112+
);
113+
114+
if (tempDist2 < minDist2) {
115+
minDist2 = tempDist2;
116+
pointIndx = tempPntId;
117+
}
118+
}
119+
120+
checkNode = null;
121+
}
122+
123+
return [minDist2 <= radius2 ? pointIndx : -1, minDist2];
124+
};
125+
66126
//------------------------------------------------------------------------------
67127
publicAPI.initPointInsertion = (points, bounds, estNumPts = 0) => {
68128
let i = 0;
@@ -128,6 +188,19 @@ function vtkIncrementalOctreePointLocator(publicAPI, model) {
128188
return true;
129189
};
130190

191+
publicAPI.findClosestPointInSphereWithTolerance = (
192+
point,
193+
radius2,
194+
maskNode
195+
) =>
196+
publicAPI.findClosestPointInSphere(
197+
point,
198+
radius2,
199+
maskNode,
200+
model.octreeMaxDimSize * model.octreeMaxDimSize * 4.0,
201+
radius2
202+
);
203+
131204
//------------------------------------------------------------------------------
132205
publicAPI.findDuplicateFloatTypePointInVisitedLeafNode = (
133206
leafNode,

Sources/Common/DataModel/Polygon/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ export function getBounds(poly, points, bounds) {
166166

167167
for (let j = 1; j < n; j++) {
168168
points.getPoint(poly[j], p);
169-
vtkBoundingBox.addPoint(bounds, p);
169+
vtkBoundingBox.addPoint(bounds, ...p);
170170
}
171-
const length = vtkBoundingBox.getLength(bounds);
171+
const length = vtkBoundingBox.getLengths(bounds);
172172
return vtkMath.dot(length, length);
173173
}
174174

Sources/Filters/General/ClipClosedSurface/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,9 +1080,9 @@ const DEFAULT_VALUES = {
10801080
generateFaces: true,
10811081
activePlaneId: -1,
10821082

1083-
baseColor: null,
1084-
clipColor: null,
1085-
activePlaneColor: null,
1083+
baseColor: [255 / 255, 99 / 255, 71 / 255], // Tomato
1084+
clipColor: [244 / 255, 164 / 255, 96 / 255], // Sandy brown
1085+
activePlaneColor: [227 / 255, 207 / 255, 87 / 255], // Banana
10861086

10871087
triangulationErrorDisplay: false,
10881088
// _idList: null,

Sources/Filters/General/ContourTriangulator/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ export function vtkCCSMakePolysFromLines(
463463
}
464464
}
465465

466-
if (!matches.length === 0) {
466+
if (matches.length > 0) {
467467
// Multiple matches mean we need to decide which path to take
468468
if (matches.length > 1) {
469469
// Remove double-backs

0 commit comments

Comments
 (0)