@kitware/vtk.js 23.4.2 → 23.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/Common/Core/Math/Constants.js +12 -0
  2. package/Common/Core/Math/index.js +1 -1
  3. package/Common/Core/Math.js +1 -1
  4. package/Common/Core/ScalarsToColors/Constants.d.ts +18 -0
  5. package/Common/DataModel/AbstractPointLocator.d.ts +54 -0
  6. package/Common/DataModel/AbstractPointLocator.js +40 -0
  7. package/Common/DataModel/BoundingBox.d.ts +659 -0
  8. package/Common/DataModel/Collection.d.ts +118 -0
  9. package/Common/DataModel/Collection.js +113 -0
  10. package/Common/DataModel/DataSet/Constants.d.ts +27 -0
  11. package/Common/DataModel/EdgeLocator.d.ts +79 -0
  12. package/Common/DataModel/EdgeLocator.js +85 -0
  13. package/Common/DataModel/ITKHelper.d.ts +54 -0
  14. package/Common/DataModel/IncrementalOctreeNode.d.ts +297 -0
  15. package/Common/DataModel/IncrementalOctreeNode.js +640 -0
  16. package/Common/DataModel/IncrementalOctreePointLocator.d.ts +61 -0
  17. package/Common/DataModel/IncrementalOctreePointLocator.js +398 -0
  18. package/Common/DataModel/Locator.d.ts +43 -0
  19. package/Common/DataModel/Locator.js +37 -0
  20. package/Common/DataModel/Plane.js +1 -1
  21. package/Common/DataModel/PolyData/Constants.d.ts +6 -0
  22. package/Common/DataModel/PolyLine.d.ts +63 -0
  23. package/Common/DataModel/PolyLine.js +77 -0
  24. package/Common/DataModel/Polygon/Constants.js +12 -0
  25. package/Common/DataModel/Polygon.js +1 -1
  26. package/Common/DataModel/Quad/Constants.js +9 -0
  27. package/Common/DataModel/Quad.d.ts +91 -0
  28. package/Common/DataModel/Quad.js +235 -0
  29. package/Common/DataModel/SelectionNode/Constants.d.ts +27 -0
  30. package/Common/DataModel/Spline1D/Constants.js +17 -0
  31. package/Common/DataModel/Spline3D/Constants.d.ts +9 -0
  32. package/Common/Transform/Transform.js +51 -0
  33. package/Filters/Core/PolyDataNormals.js +124 -0
  34. package/Filters/General/ClipClosedSurface/Constants.js +10 -0
  35. package/Filters/General/ClipClosedSurface.d.ts +95 -0
  36. package/Filters/General/ClipClosedSurface.js +972 -0
  37. package/Filters/General/ContourTriangulator/Constants.js +6 -0
  38. package/Filters/General/ContourTriangulator/helper.js +1951 -0
  39. package/Filters/General/ContourTriangulator.d.ts +136 -0
  40. package/Filters/General/ContourTriangulator.js +202 -0
  41. package/Filters/General/ImageMarchingCubes.js +1 -1
  42. package/Filters/General/MoleculeToRepresentation.js +1 -1
  43. package/Filters/General/OBBTree/OBBNode.js +82 -0
  44. package/Filters/General/OBBTree/helper.js +92 -0
  45. package/Filters/General/OBBTree.js +1243 -0
  46. package/Filters/General/TubeFilter.js +1 -1
  47. package/Filters/Sources/LineSource.js +1 -1
  48. package/Filters/Sources/PlaneSource.js +1 -1
  49. package/Filters/Texture/TextureMapToPlane.js +1 -1
  50. package/Interaction/Manipulators/CompositeCameraManipulator.d.ts +68 -0
  51. package/Interaction/Manipulators/CompositeGestureManipulator.d.ts +168 -0
  52. package/Interaction/Manipulators/CompositeKeyboardManipulator.d.ts +48 -0
  53. package/Interaction/Manipulators/CompositeMouseManipulator.d.ts +149 -0
  54. package/Interaction/Manipulators/CompositeVRManipulator.d.ts +44 -0
  55. package/Interaction/Manipulators/GestureCameraManipulator.d.ts +34 -0
  56. package/Interaction/Manipulators/KeyboardCameraManipulator.js +1 -1
  57. package/Interaction/Manipulators/MouseBoxSelectorManipulator.d.ts +88 -0
  58. package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +1 -1
  59. package/Interaction/Manipulators/MouseCameraTrackballMultiRotateManipulator.d.ts +32 -0
  60. package/Interaction/Manipulators/MouseCameraTrackballPanManipulator.d.ts +33 -0
  61. package/Interaction/Manipulators/MouseCameraTrackballPanManipulator.js +1 -1
  62. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.d.ts +33 -0
  63. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.d.ts +67 -0
  64. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +1 -1
  65. package/Interaction/Manipulators/MouseCameraTrackballZoomManipulator.d.ts +45 -0
  66. package/Interaction/Manipulators/MouseCameraTrackballZoomToMouseManipulator.d.ts +26 -0
  67. package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +1 -1
  68. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +1 -1
  69. package/Interaction/Manipulators/MouseRangeManipulator.d.ts +53 -0
  70. package/Interaction/Style/InteractorStyleImage.d.ts +107 -0
  71. package/Interaction/Style/InteractorStyleMPRSlice.js +1 -1
  72. package/Interaction/Style/InteractorStyleManipulator.d.ts +348 -0
  73. package/Interaction/Style/InteractorStyleTrackballCamera.d.ts +170 -0
  74. package/Interaction/Widgets/ImageCroppingRegionsWidget.js +1 -1
  75. package/Interaction/Widgets/LabelRepresentation.js +1 -1
  76. package/Interaction/Widgets/OrientationMarkerWidget/Constants.d.ts +11 -0
  77. package/Interaction/Widgets/ResliceCursor/ResliceCursor.js +1 -1
  78. package/Interaction/Widgets/ResliceCursor/ResliceCursorLineRepresentation.js +1 -1
  79. package/Interaction/Widgets/ResliceCursor/ResliceCursorRepresentation.js +1 -1
  80. package/Proxy/Core/AbstractRepresentationProxy.d.ts +24 -0
  81. package/Proxy/Core/LookupTableProxy.d.ts +45 -0
  82. package/Proxy/Core/PiecewiseFunctionProxy.d.ts +62 -0
  83. package/Proxy/Core/ProxyManager.d.ts +115 -0
  84. package/Proxy/Core/SourceProxy.d.ts +22 -0
  85. package/Proxy/Core/View2DProxy.d.ts +7 -0
  86. package/Proxy/Core/View2DProxy.js +1 -1
  87. package/Proxy/Core/ViewProxy.d.ts +86 -0
  88. package/Proxy/Representations/SliceRepresentationProxy.d.ts +27 -0
  89. package/Proxy/Representations/VolumeRepresentationProxy.d.ts +44 -0
  90. package/README.md +2 -2
  91. package/Rendering/Core/AbstractImageMapper/helper.js +127 -0
  92. package/Rendering/Core/AbstractImageMapper.d.ts +82 -0
  93. package/Rendering/Core/AbstractImageMapper.js +44 -0
  94. package/Rendering/Core/Camera.js +1 -1
  95. package/Rendering/Core/CellPicker.js +1 -1
  96. package/Rendering/Core/ColorTransferFunction/ColorMaps.d.ts +24 -0
  97. package/Rendering/Core/ColorTransferFunction/Constants.d.ts +17 -0
  98. package/Rendering/Core/ColorTransferFunction.js +1 -1
  99. package/Rendering/Core/Coordinate/Constants.d.ts +14 -0
  100. package/Rendering/Core/Coordinate.js +1 -1
  101. package/Rendering/Core/Glyph3DMapper/Constants.d.ts +17 -0
  102. package/Rendering/Core/Glyph3DMapper.js +1 -1
  103. package/Rendering/Core/HardwareSelector.d.ts +84 -0
  104. package/Rendering/Core/ImageArrayMapper.d.ts +253 -0
  105. package/Rendering/Core/ImageArrayMapper.js +242 -0
  106. package/Rendering/Core/ImageMapper/Constants.d.ts +14 -0
  107. package/Rendering/Core/ImageMapper.js +1 -1
  108. package/Rendering/Core/ImageProperty/Constants.d.ts +9 -0
  109. package/Rendering/Core/ImageResliceMapper/Constants.d.ts +11 -0
  110. package/Rendering/Core/ImageResliceMapper/Constants.js +11 -0
  111. package/Rendering/Core/ImageResliceMapper.d.ts +245 -0
  112. package/Rendering/Core/ImageResliceMapper.js +70 -0
  113. package/Rendering/Core/InteractorObserver.d.ts +132 -0
  114. package/Rendering/Core/InteractorStyle/Constants.d.ts +16 -0
  115. package/Rendering/Core/InteractorStyle.d.ts +229 -0
  116. package/Rendering/Core/Light.js +1 -1
  117. package/Rendering/Core/Mapper/Constants.d.ts +26 -0
  118. package/Rendering/Core/Mapper.js +1 -1
  119. package/Rendering/Core/Picker.js +1 -1
  120. package/Rendering/Core/Prop/Constants.d.ts +9 -0
  121. package/Rendering/Core/Prop/Constants.js +9 -0
  122. package/Rendering/Core/Property/Constants.d.ts +24 -0
  123. package/Rendering/Core/Property2D/Constants.d.ts +9 -0
  124. package/Rendering/Core/RenderWindow.js +1 -1
  125. package/Rendering/Core/RenderWindowInteractor/Constants.d.ts +31 -0
  126. package/Rendering/Core/Renderer.js +1 -1
  127. package/Rendering/Core/VolumeMapper/Constants.d.ts +20 -0
  128. package/Rendering/Core/VolumeMapper.js +1 -1
  129. package/Rendering/Core/VolumeProperty/Constants.d.ts +16 -0
  130. package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager/CameraSynchronizer.js +129 -0
  131. package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager.js +131 -0
  132. package/Rendering/Misc/SynchronizableRenderWindow/ObjectManager.d.ts +80 -0
  133. package/Rendering/Misc/SynchronizableRenderWindow/ObjectManager.js +763 -0
  134. package/Rendering/OpenGL/HardwareSelector/Constants.d.ts +8 -0
  135. package/Rendering/OpenGL/HardwareSelector.d.ts +339 -0
  136. package/Rendering/OpenGL/ImageResliceMapper.js +996 -0
  137. package/Rendering/OpenGL/PolyDataMapper.js +1 -1
  138. package/Rendering/OpenGL/PolyDataMapper2D.js +1 -1
  139. package/Rendering/OpenGL/RenderWindow/Constants.d.ts +10 -0
  140. package/Rendering/OpenGL/RenderWindow/Constants.js +13 -0
  141. package/Rendering/OpenGL/RenderWindow/ContextProxy.js +70 -0
  142. package/Rendering/OpenGL/RenderWindow.d.ts +9 -2
  143. package/Rendering/OpenGL/RenderWindow.js +2 -1
  144. package/Rendering/OpenGL/glsl/vtkImageResliceMapperFS.glsl.js +3 -0
  145. package/Rendering/OpenGL/glsl/vtkImageResliceMapperVS.glsl.js +3 -0
  146. package/Rendering/WebGPU/Actor2D.js +151 -0
  147. package/Rendering/WebGPU/BufferManager.js +1 -1
  148. package/Rendering/WebGPU/CellArrayMapper.js +853 -0
  149. package/Rendering/WebGPU/IndexBuffer.js +397 -0
  150. package/Rendering/WebGPU/PolyDataMapper2D.js +99 -0
  151. package/Rendering/WebGPU/RenderWindow.js +3 -1
  152. package/Rendering/WebGPU/SimpleMapper.js +290 -0
  153. package/Widgets/Core/AbstractWidget.d.ts +187 -0
  154. package/Widgets/Core/AbstractWidgetFactory.d.ts +131 -0
  155. package/Widgets/Core/StateBuilder/color3Mixin.js +24 -0
  156. package/Widgets/Core/StateBuilder/orientationMixin.js +1 -1
  157. package/Widgets/Core/StateBuilder.d.ts +29 -0
  158. package/Widgets/Core/WidgetManager/Constants.d.ts +27 -0
  159. package/Widgets/Core/WidgetManager.d.ts +231 -0
  160. package/Widgets/Core/WidgetState.d.ts +81 -0
  161. package/Widgets/Manipulators/AbstractManipulator.d.ts +221 -0
  162. package/Widgets/Manipulators/AbstractManipulator.js +57 -0
  163. package/Widgets/Manipulators/LineManipulator.js +1 -1
  164. package/Widgets/Manipulators/TrackballManipulator.js +1 -1
  165. package/Widgets/Representations/GlyphRepresentation.js +325 -0
  166. package/Widgets/Representations/LineHandleRepresentation.js +116 -0
  167. package/Widgets/Representations/ResliceCursorContextRepresentation.js +1 -1
  168. package/Widgets/Representations/WidgetRepresentation.js +1 -1
  169. package/Widgets/Widgets3D/AngleWidget.js +1 -1
  170. package/Widgets/Widgets3D/InteractiveOrientationWidget.d.ts +40 -0
  171. package/Widgets/Widgets3D/LabelWidget/behavior.js +157 -0
  172. package/Widgets/Widgets3D/LabelWidget/state.js +22 -0
  173. package/Widgets/Widgets3D/LabelWidget.js +78 -0
  174. package/Widgets/Widgets3D/LineWidget/behavior.js +1 -1
  175. package/Widgets/Widgets3D/LineWidget/helpers.js +1 -1
  176. package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +1 -1
  177. package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -1
  178. package/Widgets/Widgets3D/ResliceCursorWidget.js +1 -1
  179. package/index.d.ts +133 -74
  180. package/package.json +1 -1
@@ -0,0 +1,972 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
3
+ import macro from '../../macros.js';
4
+ import { d as dot, e as distance2BetweenPoints } from '../../Common/Core/Math/index.js';
5
+ import vtkCellArray from '../../Common/Core/CellArray.js';
6
+ import vtkDataArray from '../../Common/Core/DataArray.js';
7
+ import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
8
+ import vtkPoints from '../../Common/Core/Points.js';
9
+ import vtkDataSetAttributes from '../../Common/DataModel/DataSetAttributes.js';
10
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
11
+ import vtkContourTriangulator from './ContourTriangulator.js';
12
+ import vtkEdgeLocator from '../../Common/DataModel/EdgeLocator.js';
13
+ import Constants from './ClipClosedSurface/Constants.js';
14
+
15
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
+
17
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
+ var vtkErrorMacro = macro.vtkErrorMacro,
19
+ capitalize = macro.capitalize;
20
+ var ScalarMode = Constants.ScalarMode;
21
+
22
+ function vtkClipClosedSurface(publicAPI, model) {
23
+ // Set our className
24
+ model.classHierarchy.push('vtkClipClosedSurface');
25
+
26
+ publicAPI.getMTime = function () {
27
+ return model.clippingPlanes.reduce(function (a, b) {
28
+ return b.getMTime() > a ? b.getMTime() : a;
29
+ }, model.mtime);
30
+ };
31
+ /**
32
+ * Take three colors as doubles, and convert to unsigned char.
33
+ *
34
+ * @param {Number} color1
35
+ * @param {Number} color2
36
+ * @param {Number} color3
37
+ * @param {Number[3][3]} colors
38
+ */
39
+
40
+
41
+ function createColorValues(color1, color2, color3, colors) {
42
+ var dcolors = [color1, color2, color3];
43
+
44
+ var clamp = function clamp(n, min, max) {
45
+ return Math.min(Math.max(n, min), max);
46
+ };
47
+
48
+ for (var i = 0; i < 3; i++) {
49
+ for (var j = 0; j < 3; j++) {
50
+ colors[i][j] = Math.round(clamp(dcolors[i][j], 0, 1) * 255);
51
+ }
52
+ }
53
+ }
54
+ /**
55
+ * Point interpolation for clipping and contouring, given the scalar
56
+ * values (v0, v1) for the two endpoints (p0, p1). The use of this
57
+ * function guarantees perfect consistency in the results.
58
+ *
59
+ * @param {vtkPoints} points
60
+ * @param {vtkDataArray} pointData
61
+ * @param {CCSEdgeLocator} locator
62
+ * @param {Number} tol
63
+ * @param {Number} i0
64
+ * @param {Number} i1
65
+ * @param {Number} v0
66
+ * @param {Number} v1
67
+ * @param {Number} i
68
+ * @returns {Number}
69
+ */
70
+
71
+
72
+ function interpolateEdge(points, pointData, locator, tol, i0, i1, v0, v1) {
73
+ // This swap guarantees that exactly the same point is computed
74
+ // for both line directions, as long as the endpoints are the same.
75
+ if (v1 > 0) {
76
+ // eslint-disable-next-line no-param-reassign
77
+ var _ref = [i1, i0];
78
+ i0 = _ref[0];
79
+ i1 = _ref[1];
80
+ var _ref2 = [v1, v0];
81
+ v0 = _ref2[0];
82
+ v1 = _ref2[1];
83
+ } // After the above swap, i0 will be kept, and i1 will be clipped
84
+ // Check to see if this point has already been computed
85
+
86
+
87
+ var edge = locator.insertUniqueEdge(i0, i1);
88
+
89
+ if (edge.value != null) {
90
+ return edge.value;
91
+ } // Get the edge and interpolate the new point
92
+
93
+
94
+ var p0 = points.getPoint(i0);
95
+ var p1 = points.getPoint(i1);
96
+ var f = v0 / (v0 - v1);
97
+ var s = 1.0 - f;
98
+ var t = 1.0 - s;
99
+ var p = [s * p0[0] + t * p1[0], s * p0[1] + t * p1[1], s * p0[2] + t * p1[2]];
100
+ var tol2 = tol * tol; // Make sure that new point is far enough from kept point
101
+
102
+ if (distance2BetweenPoints(p, p0) < tol2) {
103
+ edge.value = i0;
104
+ return i0;
105
+ }
106
+
107
+ if (distance2BetweenPoints(p, p1) < tol2) {
108
+ edge.value = i1;
109
+ return i1;
110
+ }
111
+
112
+ edge.value = points.insertNextTuple(p);
113
+ pointData.interpolateData(pointData, i0, i1, edge.value, t);
114
+ return edge.value;
115
+ }
116
+ /**
117
+ * Method for clipping lines and copying the scalar data.
118
+ *
119
+ * @param {vtkPoints} points
120
+ * @param {vtkDataArray} pointScalars
121
+ * @param {vtkDataSetAttributesk} pointData
122
+ * @param {vtkEdgeLocator} edgeLocator
123
+ * @param {vtkCellArray} inputLines
124
+ * @param {vtkCellArray} outputLines
125
+ * @param {vtkDataSetAttributes} inLineData
126
+ * @param {vtkDataSetAttributes} outLineData
127
+ */
128
+
129
+
130
+ function clipLines(points, pointScalars, pointData, edgeLocator, inputLines, outputLines, inLineData, outLineData) {
131
+ var numPts;
132
+ var i0;
133
+ var i1;
134
+ var v0;
135
+ var v1;
136
+ var c0;
137
+ var c1;
138
+ var linePts = [];
139
+ var values = inputLines.getData();
140
+ var cellId = 0;
141
+
142
+ for (var i = 0; i < values.length; i += numPts + 1, cellId++) {
143
+ numPts = values[i];
144
+ i1 = values[i + 1];
145
+ v1 = pointScalars.getData()[i1];
146
+ c1 = v1 > 0;
147
+
148
+ for (var j = 2; j <= numPts; j++) {
149
+ i0 = i1;
150
+ v0 = v1;
151
+ c0 = c1;
152
+ i1 = values[i + j];
153
+ v1 = pointScalars.getData()[i1];
154
+ c1 = v1 > 0; // If at least one point wasn't clipped
155
+
156
+ if (c0 || c1) {
157
+ // If only one end was clipped, interpolate new point
158
+ if (c0 ? !c1 : c1) {
159
+ linePts[c0 ? 1 : 0] = interpolateEdge(points, pointData, edgeLocator, model.tolerance, i0, i1, v0, v1);
160
+ } // If endpoints are different, insert the line segment
161
+
162
+
163
+ if (i0 !== i1) {
164
+ linePts[0] = i0;
165
+ linePts[1] = i1;
166
+ var newCellId = outputLines.insertNextCell(linePts); // outLineData.copyData(inLineData, cellId, newCellId);
167
+
168
+ outLineData.passData(inLineData, cellId, newCellId);
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
174
+ /**
175
+ * Break polylines into individual lines, copying scalar values from
176
+ * inputScalars starting at firstLineScalar. If inputScalars is zero,
177
+ * then scalars will be set to color. If scalars is zero, then no
178
+ * scalars will be generated.
179
+ *
180
+ * @param {vtkCellArray} inputLines
181
+ * @param {vtkCellArray} outputLines
182
+ * @param {vtkDataArray} inputScalars
183
+ * @param {Number} firstLineScalar
184
+ * @param {vtkDataArray} scalars
185
+ * @param {Vector3} color
186
+ */
187
+
188
+
189
+ function breakPolylines(inputLines, outputLines, inputScalars, firstLineScalar, scalars, color) {
190
+ var cellColor = _toConsumableArray(color);
191
+
192
+ var cellId = 0;
193
+ var values = inputLines.getData();
194
+ var numPts;
195
+
196
+ for (var i = 0; i < values.length; i += numPts + 1) {
197
+ numPts = values[i];
198
+
199
+ if (inputScalars) {
200
+ inputScalars.getTuple(firstLineScalar + cellId++, cellColor);
201
+ }
202
+
203
+ for (var j = 1; j < numPts; j++) {
204
+ outputLines.insertNextCell([values[i + j], values[i + j + 1]]);
205
+
206
+ if (scalars) {
207
+ scalars.insertNextTuple(cellColor);
208
+ }
209
+ }
210
+ }
211
+ }
212
+ /**
213
+ * Copy polygons and their associated scalars to a new array.
214
+ * If inputScalars is set to zero, set polyScalars to color instead.
215
+ * If polyScalars is set to zero, don't generate scalars.
216
+ *
217
+ * @param {vtkCellArray} inputPolys
218
+ * @param {vtkCellArray} outputPolys
219
+ * @param {vtkDataArray} inputScalars
220
+ * @param {Number} firstPolyScalar
221
+ * @param {vtkDataArray} polyScalars
222
+ * @param {Vector3} color
223
+ */
224
+
225
+
226
+ function copyPolygons(inputPolys, outputPolys, inputScalars, firstPolyScalar, polyScalars, color) {
227
+ if (!inputPolys) {
228
+ return;
229
+ }
230
+
231
+ outputPolys.deepCopy(inputPolys);
232
+
233
+ if (polyScalars) {
234
+ var scalarValue = _toConsumableArray(color);
235
+
236
+ var n = outputPolys.getNumberOfCells();
237
+ polyScalars.insertTuple(n - 1, scalarValue);
238
+
239
+ if (inputScalars) {
240
+ for (var i = 0; i < n; i++) {
241
+ inputScalars.getTuple(i + firstPolyScalar, scalarValue);
242
+ polyScalars.setTuple(i, scalarValue);
243
+ }
244
+ } else {
245
+ for (var _i = 0; _i < n; _i++) {
246
+ polyScalars.setTuple(_i, scalarValue);
247
+ }
248
+ }
249
+ }
250
+ }
251
+
252
+ function breakTriangleStrips(inputStrips, polys, inputScalars, firstStripScalar, polyScalars, color) {
253
+ if (inputStrips.getNumberOfCells() === 0) {
254
+ return;
255
+ }
256
+
257
+ var values = inputStrips.getData();
258
+ var cellId = firstStripScalar;
259
+ var numPts;
260
+
261
+ for (var i = 0; i < values.length; i += numPts + 1, cellId++) {
262
+ numPts = values[i]; // vtkTriangleStrip.decomposeStrip(numPts, values, polys);
263
+
264
+ var p1 = values[i + 1];
265
+ var p2 = values[i + 2];
266
+
267
+ for (var j = 0; j < numPts - 2; j++) {
268
+ var p3 = values[i + j + 3];
269
+
270
+ if (j % 2) {
271
+ polys.insertNextCell([p2, p1, p3]);
272
+ } else {
273
+ polys.insertNextCell([p1, p2, p3]);
274
+ }
275
+
276
+ p1 = p2;
277
+ p2 = p3;
278
+ }
279
+
280
+ if (polyScalars) {
281
+ var scalarValue = _toConsumableArray(color);
282
+
283
+ if (inputScalars) {
284
+ // If there are input scalars, use them instead of "color"
285
+ inputScalars.getTuple(cellId, scalarValue);
286
+ }
287
+
288
+ var n = numPts - 3;
289
+ var m = polyScalars.getNumberOfTuples();
290
+
291
+ if (n >= 0) {
292
+ // First insert is just to allocate space
293
+ polyScalars.insertTuple(m + n, scalarValue);
294
+
295
+ for (var k = 0; k < n; k++) {
296
+ polyScalars.setTuple(m + k, scalarValue);
297
+ }
298
+ }
299
+ }
300
+ }
301
+ }
302
+ /**
303
+ * Given some closed contour lines, create a triangle mesh that
304
+ * fills those lines. The input lines must be single-segment lines,
305
+ * not polylines. The input lines do not have to be in order.
306
+ * Only lines from firstLine to will be used. Specify the normal
307
+ * of the clip plane, which will be opposite the normals
308
+ * of the polys that will be produced. If outCD has scalars, then color
309
+ * scalars will be added for each poly that is created.
310
+ *
311
+ * @param {vtkPolyData} polyData
312
+ * @param {Number} firstLine
313
+ * @param {Number} numLines
314
+ * @param {vtkCellArray} outputPolys
315
+ * @param {Vector3} normal
316
+ */
317
+
318
+
319
+ function triangulateContours(polyData, firstLine, numLines, outputPolys, normal) {
320
+ // If no cut lines were generated, there's nothing to do
321
+ if (numLines <= 0) {
322
+ return;
323
+ }
324
+
325
+ var triangulationError = !vtkContourTriangulator.triangulateContours(polyData, firstLine, numLines, outputPolys, [-normal[0], -normal[1], -normal[2]]);
326
+
327
+ if (triangulationError && model.triangulationErrorDisplay) {
328
+ vtkErrorMacro('Triangulation failed, polyData may not be watertight.');
329
+ }
330
+ }
331
+ /**
332
+ * Break polylines into individual lines, copying scalar values from
333
+ * inputScalars starting at firstLineScalar. If inputScalars is zero,
334
+ * then scalars will be set to color. If scalars is zero, then no
335
+ * scalars will be generated.
336
+ *
337
+ * @param {Number[]} polygon
338
+ * @param {vtkPoints} points
339
+ * @param {vtkCellArray} triangles
340
+ * @returns {Boolean}
341
+ */
342
+
343
+
344
+ function triangulatePolygon(polygon, points, triangles) {
345
+ return vtkContourTriangulator.triangulatePolygon(polygon, points, triangles);
346
+ }
347
+ /**
348
+ * Clip and contour polys in one step, in order to guarantee
349
+ * that the contour lines exactly match the new free edges of
350
+ * the clipped polygons. This exact correspondence is necessary
351
+ * in order to guarantee that the surface remains closed.
352
+ *
353
+ * @param {vtkPoints} points
354
+ * @param {vtkDataArray} pointScalars
355
+ * @param {vtkDataSetAttributes} pointData
356
+ * @param {vtkEdgeLocator} edgeLocator
357
+ * @param {Number} triangulate
358
+ * @param {vtkCellArray} inputPolys
359
+ * @param {vtkCellArray} outputPolys
360
+ * @param {vtkCellArray} outputLines
361
+ * @param {vtkDataSetAttributes} inCellData
362
+ * @param {vtkDataSetAttributes} outPolyData
363
+ * @param {vtkDataSetAttributes} outLineData
364
+ */
365
+
366
+
367
+ function clipAndContourPolys(points, pointScalars, pointData, edgeLocator, triangulate, inputPolys, outputPolys, outputLines, inCellData, outPolyData, outLineData) {
368
+ var idList = model._idList; // How many sides for output polygons?
369
+
370
+ var polyMax = Number.MAX_VALUE;
371
+
372
+ if (triangulate) {
373
+ if (triangulate < 4) {
374
+ // triangles only
375
+ polyMax = 3;
376
+ } else if (triangulate === 4) {
377
+ // allow triangles and quads
378
+ polyMax = 4;
379
+ }
380
+ } // eslint-disable-next-line prefer-const
381
+
382
+
383
+ var triangulationFailure = false; // Go through all cells and clip them
384
+
385
+ var values = inputPolys.getData();
386
+ var linePts = [];
387
+ var cellId = 0;
388
+ var numPts;
389
+
390
+ for (var i = 0; i < values.length; i += numPts + 1, cellId++) {
391
+ numPts = values[i];
392
+ var i1 = values[i + numPts];
393
+ var v1 = pointScalars.getData()[i1];
394
+ var c1 = v1 > 0; // The ids for the current edge: init j0 to -1 if i1 will be clipped
395
+
396
+ var j0 = c1 ? i1 : -1;
397
+ var j1 = 0; // To store the ids of the contour line
398
+
399
+ linePts[0] = 0;
400
+ linePts[1] = 0;
401
+ var idListIdx = 0;
402
+
403
+ for (var j = 1; j <= numPts; j++) {
404
+ // Save previous point info
405
+ var i0 = i1;
406
+ var v0 = v1;
407
+ var c0 = c1; // Generate new point info
408
+
409
+ i1 = values[i + j];
410
+ v1 = pointScalars.getData()[i1];
411
+ c1 = v1 > 0; // If at least one edge end point wasn't clipped
412
+
413
+ if (c0 || c1) {
414
+ // If only one end was clipped, interpolate new point
415
+ if (c0 ? !c1 : c1) {
416
+ j1 = interpolateEdge(points, pointData, edgeLocator, model.tolerance, i0, i1, v0, v1);
417
+
418
+ if (j1 !== j0) {
419
+ idList[idListIdx++] = j1;
420
+ j0 = j1;
421
+ } // Save as one end of the contour line
422
+
423
+
424
+ linePts[c0 ? 1 : 0] = j1;
425
+ }
426
+
427
+ if (c1) {
428
+ j1 = i1;
429
+
430
+ if (j1 !== j0) {
431
+ idList[idListIdx++] = j1;
432
+ j0 = j1;
433
+ }
434
+ }
435
+ }
436
+ } // Insert the clipped poly
437
+
438
+
439
+ var numPoints = idListIdx;
440
+ idList.length = numPoints;
441
+
442
+ if (model.triangulatePolys && numPoints > polyMax) {
443
+ // TODO: Support triangulatePolygon
444
+ var newCellId = outputPolys.getNumberOfCells(); // Triangulate the poly and insert triangles into output.
445
+
446
+ var success = triangulatePolygon(idList, points, outputPolys);
447
+
448
+ if (!success) {
449
+ triangulationFailure = true;
450
+ } // Copy the attribute data to the triangle cells
451
+
452
+
453
+ var ncells = outputPolys.getNumberOfCells();
454
+
455
+ for (; newCellId < ncells; newCellId++) {
456
+ outPolyData.passData(inCellData, cellId, newCellId);
457
+ }
458
+ } else if (numPoints > 2) {
459
+ // Insert the polygon without triangulating it
460
+ var _newCellId = outputPolys.insertNextCell(idList);
461
+
462
+ outPolyData.passData(inCellData, cellId, _newCellId);
463
+ } // Insert the contour line if one was created
464
+
465
+
466
+ if (linePts[0] !== linePts[1]) {
467
+ var _newCellId2 = outputLines.insertNextCell(linePts);
468
+
469
+ outLineData.passData(inCellData, cellId, _newCellId2);
470
+ }
471
+ }
472
+
473
+ if (triangulationFailure && model.triangulationErrorDisplay) {
474
+ vtkErrorMacro('Triangulation failed, output may not be watertight');
475
+ }
476
+ }
477
+ /**
478
+ * Squeeze the points and store them in the output. Only the points that
479
+ * are used by the cells will be saved, and the pointIds of the cells will
480
+ * be modified.
481
+ *
482
+ * @param {vtkPolyData} output
483
+ * @param {vtkPoints} points
484
+ * @param {vtkDataSetAttributes} pointData
485
+ * @param {String} outputPointDataType
486
+ */
487
+
488
+
489
+ function squeezeOutputPoints(output, points, pointData, outputPointDataType) {
490
+ // Create a list of points used by cells
491
+ var n = points.getNumberOfPoints();
492
+ var numNewPoints = 0;
493
+ var outPointData = output.getPointData();
494
+ var pointMap = [];
495
+ pointMap.length = n;
496
+ var cellArrays = [output.getVerts(), output.getLines(), output.getPolys(), output.getStrips()]; // Find all the newPoints that are used by cells
497
+
498
+ cellArrays.forEach(function (cellArray) {
499
+ if (!cellArray) {
500
+ return;
501
+ }
502
+
503
+ var values = cellArray.getData();
504
+ var numPts;
505
+ var pointId;
506
+
507
+ for (var i = 0; i < values.length; i += numPts + 1) {
508
+ numPts = values[i];
509
+
510
+ for (var j = 1; j <= numPts; j++) {
511
+ pointId = values[i + j];
512
+
513
+ if (pointMap[pointId] === undefined) {
514
+ pointMap[pointId] = numNewPoints++;
515
+ }
516
+ }
517
+ }
518
+ }); // Create exactly the number of points that are required
519
+
520
+ var newPoints = vtkPoints.newInstance({
521
+ size: numNewPoints * 3,
522
+ dataType: outputPointDataType
523
+ }); // outPointData.copyAllocate(pointData, numNewPoints, 0);
524
+
525
+ var p = [];
526
+ var newPointId;
527
+
528
+ for (var pointId = 0; pointId < n; pointId++) {
529
+ newPointId = pointMap[pointId];
530
+
531
+ if (newPointId !== undefined) {
532
+ points.getPoint(pointId, p);
533
+ newPoints.setTuple(newPointId, p);
534
+ outPointData.passData(pointData, pointId, newPointId); // outPointData.copyData(pointData, pointId, newPointId);
535
+ }
536
+ } // Change the cell pointIds to reflect the new point array
537
+
538
+
539
+ cellArrays.forEach(function (cellArray) {
540
+ if (!cellArray) {
541
+ return;
542
+ }
543
+
544
+ var values = cellArray.getData();
545
+ var numPts;
546
+ var pointId;
547
+
548
+ for (var i = 0; i < values.length; i += numPts + 1) {
549
+ numPts = values[i];
550
+
551
+ for (var j = 1; j <= numPts; j++) {
552
+ pointId = values[i + j];
553
+ values[i + j] = pointMap[pointId];
554
+ }
555
+ }
556
+ });
557
+ output.setPoints(newPoints);
558
+ }
559
+
560
+ publicAPI.requestData = function (inData, outData) {
561
+ var _input$getVerts, _input$getStrips;
562
+
563
+ // implement requestData
564
+ var input = inData[0];
565
+ var output = vtkPolyData.newInstance();
566
+ outData[0] = output;
567
+
568
+ if (!input) {
569
+ vtkErrorMacro('Invalid or missing input');
570
+ return;
571
+ }
572
+
573
+ if (model._idList == null) {
574
+ model._idList = [];
575
+ } else {
576
+ model._idList.length = 0;
577
+ } // Get the input points
578
+
579
+
580
+ var inputPoints = input.getPoints();
581
+ var numPts = 0;
582
+ var inputPointsType = VtkDataTypes.FLOAT;
583
+
584
+ if (inputPoints) {
585
+ numPts = inputPoints.getNumberOfPoints();
586
+ inputPointsType = inputPoints.getDataType();
587
+ } // Force points to double precision, copy the point attributes
588
+
589
+
590
+ var points = vtkPoints.newInstance({
591
+ size: numPts * 3,
592
+ dataType: VtkDataTypes.DOUBLE
593
+ });
594
+ var pointData = vtkDataSetAttributes.newInstance();
595
+ var inPointData = null;
596
+
597
+ if (model.passPointData) {
598
+ inPointData = input.getPointData(); // pointData.interpolateAllocate(inPointData, numPts, 0);
599
+ }
600
+
601
+ var point = [];
602
+
603
+ for (var ptId = 0; ptId < numPts; ptId++) {
604
+ inputPoints.getPoint(ptId, point);
605
+ points.setTuple(ptId, point);
606
+
607
+ if (inPointData) {
608
+ // pointData.copyData(inPointData, ptId, ptId);
609
+ pointData.passData(inPointData, ptId, ptId);
610
+ }
611
+ } // An edge locator to avoid point duplication while clipping
612
+
613
+
614
+ var edgeLocator = vtkEdgeLocator.newInstance(); // A temporary polydata for the contour lines that are triangulated
615
+
616
+ var tmpContourData = vtkPolyData.newInstance(); // The cell scalars
617
+
618
+ var lineScalars;
619
+ var polyScalars;
620
+ var inputScalars; // For input scalars: the offsets to the various cell types
621
+
622
+ var firstLineScalar = 0;
623
+ var firstPolyScalar = 0;
624
+ var firstStripScalar = 0; // Make the colors to be used on the data
625
+
626
+ var numberOfScalarComponents = 1;
627
+ var colors = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
628
+
629
+ if (model.scalarMode === ScalarMode.COLORS) {
630
+ numberOfScalarComponents = 3;
631
+ createColorValues(model.baseColor, model.clipColor, model.activePlaneColor, colors);
632
+ } else if (model.scalarMode === ScalarMode.LABELS) {
633
+ colors[0][0] = 0;
634
+ colors[1][0] = 1;
635
+ colors[2][0] = 2;
636
+ } // This is set if we have to work with scalars. The input scalars
637
+ // will be copied if they are unsigned char with 3 components, otherwise
638
+ // new scalars will be generated.
639
+
640
+
641
+ var numVerts = ((_input$getVerts = input.getVerts()) === null || _input$getVerts === void 0 ? void 0 : _input$getVerts.getNumberOfCells()) || 0;
642
+ var inputLines = input.getLines();
643
+ var numLines = (inputLines === null || inputLines === void 0 ? void 0 : inputLines.getNumberOfCells()) || 0;
644
+ var inputPolys = input.getPolys();
645
+ var numPolys = (inputPolys === null || inputPolys === void 0 ? void 0 : inputPolys.getNumberOfCells()) || 0;
646
+ var numStrips = ((_input$getStrips = input.getStrips()) === null || _input$getStrips === void 0 ? void 0 : _input$getStrips.getNumberOfCells()) || 0;
647
+
648
+ if (model.scalarMode !== ScalarMode.NONE) {
649
+ lineScalars = vtkDataArray.newInstance({
650
+ dataType: VtkDataTypes.UNSIGNED_CHAR,
651
+ empty: true,
652
+ // size: 0,
653
+ // values: new Uint8Array(numLines * 3),
654
+ numberOfComponents: numberOfScalarComponents
655
+ });
656
+ var tryInputScalars = input.getCellData().getScalars(); // Get input scalars if they are RGB color scalars
657
+
658
+ if (tryInputScalars && tryInputScalars.getDataType() === VtkDataTypes.UNSIGNED_CHAR && numberOfScalarComponents === 3 && tryInputScalars.getNumberOfComponents() === 3) {
659
+ inputScalars = input.getCellData().getScalars();
660
+ firstLineScalar = numVerts;
661
+ firstPolyScalar = numVerts + numLines;
662
+ firstStripScalar = numVerts + numLines + numPolys;
663
+ }
664
+ } // Break the input lines into segments, generate scalars for lines
665
+
666
+
667
+ var lines;
668
+
669
+ if (numLines > 0) {
670
+ lines = vtkCellArray.newInstance({
671
+ dataType: inputLines.getDataType(),
672
+ values: new Uint8Array(numLines * 3),
673
+ // we will have at least that amount of lines
674
+ size: 0
675
+ });
676
+ breakPolylines(inputLines, lines, inputScalars, firstLineScalar, lineScalars, colors[0]);
677
+ } else {
678
+ lines = vtkCellArray.newInstance({
679
+ empty: true
680
+ });
681
+ }
682
+
683
+ var polys = null;
684
+ var polyMax = 3;
685
+
686
+ if (numPolys > 0 || numStrips > 0) {
687
+ // If there are line scalars, then poly scalars are needed too
688
+ if (lineScalars) {
689
+ polyScalars = vtkDataArray.newInstance({
690
+ dataType: VtkDataTypes.UNSIGNED_CHAR,
691
+ empty: true,
692
+ // size: 0,
693
+ // values: new Uint8Array(inputPolys.getNumberOfCells(false) * 3),
694
+ numberOfComponents: numberOfScalarComponents
695
+ });
696
+ }
697
+
698
+ polys = vtkCellArray.newInstance();
699
+ copyPolygons(inputPolys, polys, inputScalars, firstPolyScalar, polyScalars, colors[0]); // TODO: Support triangle strips
700
+
701
+ breakTriangleStrips(input.getStrips(), polys, inputScalars, firstStripScalar, polyScalars, colors[0]); // Check if the input has polys and quads or just triangles
702
+
703
+ polyMax = inputPolys.getCellSizes().reduce(function (a, b) {
704
+ return a > b ? a : b;
705
+ }, 0);
706
+ } // Arrays for storing the clipped lines and polys
707
+
708
+
709
+ var newLines = vtkCellArray.newInstance({
710
+ dataType: lines.getDataType(),
711
+ empty: true
712
+ });
713
+ var newPolys = null;
714
+
715
+ if (polys) {
716
+ newPolys = vtkCellArray.newInstance({
717
+ dataType: polys.getDataType(),
718
+ empty: true
719
+ });
720
+ } // The line scalars, for coloring the outline
721
+
722
+
723
+ var inLineData = vtkDataSetAttributes.newInstance();
724
+ inLineData.copyScalarsOn();
725
+ inLineData.setScalars(lineScalars); // The poly scalars, for coloring the faces
726
+
727
+ var inPolyData = vtkDataSetAttributes.newInstance();
728
+ inPolyData.copyScalarsOn();
729
+ inPolyData.setScalars(polyScalars); // Also create output attribute data
730
+
731
+ var outLineData = vtkDataSetAttributes.newInstance();
732
+ outLineData.copyScalarsOn();
733
+ var outPolyData = vtkDataSetAttributes.newInstance();
734
+ outPolyData.copyScalarsOn();
735
+ var planes = model.clippingPlanes; // Go through the clipping planes and clip the input with each plane
736
+
737
+ for (var planeId = 0; planeId < planes.length; planeId++) {
738
+ var plane = planes[planeId];
739
+ var triangulate = 5;
740
+
741
+ if (planeId === planes.length - 1) {
742
+ triangulate = polyMax;
743
+ }
744
+
745
+ var active = planeId === model.activePlaneId; // Convert the plane into an easy-to-evaluate function
746
+
747
+ var pc = plane.getNormal(); // OK to modify pc because vtkPlane.getNormal() returns a copy
748
+
749
+ pc[3] = -dot(pc, plane.getOrigin()); // Create the clip scalars by evaluating the plane at each point
750
+
751
+ var numPoints = points.getNumberOfPoints(); // The point scalars, needed for clipping (not for the output!)
752
+
753
+ var pointScalars = vtkDataArray.newInstance({
754
+ dataType: VtkDataTypes.DOUBLE,
755
+ size: numPoints
756
+ });
757
+ var pointScalarsData = pointScalars.getData();
758
+ var pointsData = points.getData();
759
+ var i = 0;
760
+
761
+ for (var pointId = 0; pointId < numPoints; pointId) {
762
+ pointScalarsData[pointId++] = pointsData[i++] * pc[0] + pointsData[i++] * pc[1] + pointsData[i++] * pc[2] + pc[3];
763
+ } // Prepare the output scalars
764
+ // outLineData.copyAllocate(inLineData, 0, 0);
765
+ // outPolyData.copyAllocate(inPolyData, 0, 0);
766
+ // Reset the locator
767
+
768
+
769
+ edgeLocator.initialize(); // Clip the lines
770
+
771
+ clipLines(points, pointScalars, pointData, edgeLocator, lines, newLines, inLineData, outLineData); // Clip the polys
772
+
773
+ if (polys) {
774
+ // Get the number of lines remaining after the clipping
775
+ var numClipLines = newLines.getNumberOfCells(); // Cut the polys to generate more lines
776
+
777
+ clipAndContourPolys(points, pointScalars, pointData, edgeLocator, triangulate, polys, newPolys, newLines, inPolyData, outPolyData, outLineData); // Add scalars for the newly-created contour lines
778
+
779
+ var _scalars = outLineData.getScalars();
780
+
781
+ if (_scalars) {
782
+ // Set the color to the active color if plane is active
783
+ var color = colors[1 + (active ? 1 : 0)];
784
+ var activeColor = colors[2];
785
+ var numNewLines = newLines.getNumberOfCells();
786
+ var oldColor = [];
787
+
788
+ for (var lineId = numClipLines; lineId < numNewLines; lineId++) {
789
+ _scalars.getTuple(lineId, oldColor);
790
+
791
+ if (numberOfScalarComponents !== 3 || oldColor[0] !== activeColor[0] || oldColor[1] !== activeColor[1] || oldColor[2] !== activeColor[2]) {
792
+ _scalars.setTuple(lineId, color);
793
+ }
794
+ }
795
+ } // Generate new polys from the cut lines
796
+
797
+
798
+ var cellId = newPolys.getNumberOfCells();
799
+ var numClipAndContourLines = newLines.getNumberOfCells(); // Create a polydata for the lines
800
+
801
+ tmpContourData.setPoints(points);
802
+ tmpContourData.setLines(newLines);
803
+ tmpContourData.buildCells();
804
+ triangulateContours(tmpContourData, numClipLines, numClipAndContourLines - numClipLines, newPolys, pc); // Add scalars for the newly-created polys
805
+
806
+ _scalars = outPolyData.getScalars();
807
+
808
+ if (_scalars) {
809
+ var _color = colors[1 + (active ? 1 : 0)];
810
+ var numCells = newPolys.getNumberOfCells();
811
+
812
+ if (numCells > cellId) {
813
+ // The insert allocates space up to numCells - 1
814
+ _scalars.insertTuple(numCells - 1, _color);
815
+
816
+ for (; cellId < numCells; cellId++) {
817
+ _scalars.setTuple(cellId, _color);
818
+ }
819
+ }
820
+ } // Add scalars to any diagnostic lines that added by
821
+ // triangulateContours(). In usual operation, no lines are added.
822
+
823
+
824
+ _scalars = outLineData.getScalars();
825
+
826
+ if (_scalars) {
827
+ var _color2 = [0, 255, 255];
828
+
829
+ var _numCells = newLines.getNumberOfCells();
830
+
831
+ if (_numCells > numClipAndContourLines) {
832
+ // The insert allocates space up to numCells - 1
833
+ _scalars.insertTuple(_numCells - 1, _color2);
834
+
835
+ for (var lineCellId = numClipAndContourLines; lineCellId < _numCells; lineCellId++) {
836
+ _scalars.setTuple(lineCellId, _color2);
837
+ }
838
+ }
839
+ }
840
+ } // Swap the lines, points, etcetera: old output becomes new input
841
+
842
+
843
+ var _ref3 = [newLines, lines];
844
+ lines = _ref3[0];
845
+ newLines = _ref3[1];
846
+ newLines.initialize();
847
+
848
+ if (polys) {
849
+ var _ref4 = [newPolys, polys];
850
+ polys = _ref4[0];
851
+ newPolys = _ref4[1];
852
+ newPolys.initialize();
853
+ }
854
+
855
+ var _ref5 = [outLineData, inLineData];
856
+ inLineData = _ref5[0];
857
+ outLineData = _ref5[1];
858
+ outLineData.initialize();
859
+ var _ref6 = [outPolyData, inPolyData];
860
+ inPolyData = _ref6[0];
861
+ outPolyData = _ref6[1];
862
+ outPolyData.initialize();
863
+ } // Get the line scalars
864
+
865
+
866
+ var scalars = inLineData.getScalars();
867
+
868
+ if (model.generateOutline) {
869
+ output.setLines(lines);
870
+ } else if (scalars) {
871
+ scalars.initialize();
872
+ }
873
+
874
+ if (model.generateFaces) {
875
+ output.setPolys(polys);
876
+
877
+ if (polys && scalars) {
878
+ var pScalars = inPolyData.getScalars();
879
+ var m = scalars.getNumberOfTuples();
880
+ var n = pScalars.getNumberOfTuples();
881
+
882
+ if (n > 0) {
883
+ var _color3 = [0, 0, 0]; // This is just to expand the array
884
+
885
+ scalars.insertTuple(n + m - 1, _color3); // Fill in the poly scalars
886
+
887
+ for (var _i2 = 0; _i2 < n; _i2++) {
888
+ pScalars.getTuple(_i2, _color3);
889
+ scalars.setTuple(_i2 + m, _color3);
890
+ }
891
+ }
892
+ }
893
+ }
894
+
895
+ if (scalars && model.scalarMode === ScalarMode.COLORS) {
896
+ scalars.setName('Colors');
897
+ output.getCellData().setScalars(scalars);
898
+ } else if (model.scalarMode === ScalarMode.LABELS) {
899
+ // Don't use VTK_UNSIGNED_CHAR or they will look like color scalars
900
+ // const categories = vtkSignedCharArray.newInstance();
901
+ // categories.deepCopy(scalars);
902
+ // categories.setName("Labels");
903
+ // output.getCellData().setScalars(categories);
904
+ // categories.delete();
905
+ // TODO: Check
906
+ var categories = scalars.newClone();
907
+ categories.setData(scalars.getData().slice());
908
+ categories.setName('Labels');
909
+ output.getCellData().setScalars(categories);
910
+ } else {
911
+ output.getCellData().setScalars(null);
912
+ } // Finally, store the points in the output
913
+
914
+
915
+ squeezeOutputPoints(output, points, pointData, inputPointsType); // TODO: Check
916
+ // output.squeeze();
917
+
918
+ outData[0] = output;
919
+ };
920
+
921
+ Object.keys(ScalarMode).forEach(function (key) {
922
+ var name = capitalize(key.toLowerCase());
923
+
924
+ publicAPI["setScalarModeTo".concat(name)] = function () {
925
+ model.scalarMode = ScalarMode[key];
926
+ };
927
+ });
928
+ } // ----------------------------------------------------------------------------
929
+ // Object factory
930
+ // ----------------------------------------------------------------------------
931
+
932
+
933
+ var DEFAULT_VALUES = {
934
+ clippingPlanes: null,
935
+ tolerance: 1e-6,
936
+ passPointData: false,
937
+ triangulatePolys: false,
938
+ scalarMode: ScalarMode.NONE,
939
+ generateOutline: false,
940
+ generateFaces: true,
941
+ activePlaneId: -1,
942
+ baseColor: [255 / 255, 99 / 255, 71 / 255],
943
+ // Tomato
944
+ clipColor: [244 / 255, 164 / 255, 96 / 255],
945
+ // Sandy brown
946
+ activePlaneColor: [227 / 255, 207 / 255, 87 / 255],
947
+ // Banana
948
+ triangulationErrorDisplay: false // _idList: null,
949
+
950
+ }; // ----------------------------------------------------------------------------
951
+
952
+ function extend(publicAPI, model) {
953
+ var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
954
+ Object.assign(model, DEFAULT_VALUES, initialValues); // Make this a VTK object
955
+
956
+ macro.obj(publicAPI, model); // Also make it an algorithm with one input and one output
957
+
958
+ macro.algo(publicAPI, model, 1, 1);
959
+ macro.setGet(publicAPI, model, ['clippingPlanes', 'tolerance', 'passPointData', 'triangulatePolys', 'scalarMode', 'generateOutline', 'generateFaces', 'activePlaneId', 'triangulationErrorDisplay']);
960
+ macro.setGetArray(publicAPI, model, ['baseColor', 'clipColor', 'activePlaneColor'], 3); // Object specific methods
961
+
962
+ vtkClipClosedSurface(publicAPI, model);
963
+ } // ----------------------------------------------------------------------------
964
+
965
+ var newInstance = macro.newInstance(extend, 'vtkClipClosedSurface'); // ----------------------------------------------------------------------------
966
+
967
+ var vtkClipClosedSurface$1 = _objectSpread({
968
+ newInstance: newInstance,
969
+ extend: extend
970
+ }, Constants);
971
+
972
+ export { vtkClipClosedSurface$1 as default, extend, newInstance };