@cornerstonejs/adapters 2.0.0-beta.1 → 2.0.0-beta.10

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.
@@ -1,522 +1,499 @@
1
- import { utilities, derivations, normalizers, data, log } from 'dcmjs';
2
- import ndarray from 'ndarray';
3
- import cloneDeep from 'lodash.clonedeep';
1
+ import dcmjs, { data, utilities, derivations, normalizers, log } from 'dcmjs';
4
2
  import { Buffer } from 'buffer';
3
+ import ndarray from 'ndarray';
5
4
  import { vec3 } from 'gl-matrix';
5
+ import { utilities as utilities$1 } from '@cornerstonejs/tools';
6
6
 
7
- function _iterableToArrayLimit(arr, i) {
8
- var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
9
- if (null != _i) {
10
- var _s,
11
- _e,
12
- _x,
13
- _r,
14
- _arr = [],
15
- _n = !0,
16
- _d = !1;
7
+ function _arrayLikeToArray(r, a) {
8
+ (null == a || a > r.length) && (a = r.length);
9
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10
+ return n;
11
+ }
12
+ function _arrayWithHoles(r) {
13
+ if (Array.isArray(r)) return r;
14
+ }
15
+ function _arrayWithoutHoles(r) {
16
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
17
+ }
18
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
19
+ try {
20
+ var i = n[a](c),
21
+ u = i.value;
22
+ } catch (n) {
23
+ return void e(n);
24
+ }
25
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
26
+ }
27
+ function _asyncToGenerator(n) {
28
+ return function () {
29
+ var t = this,
30
+ e = arguments;
31
+ return new Promise(function (r, o) {
32
+ var a = n.apply(t, e);
33
+ function _next(n) {
34
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
35
+ }
36
+ function _throw(n) {
37
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
38
+ }
39
+ _next(void 0);
40
+ });
41
+ };
42
+ }
43
+ function _classCallCheck(a, n) {
44
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
45
+ }
46
+ function _defineProperties(e, r) {
47
+ for (var t = 0; t < r.length; t++) {
48
+ var o = r[t];
49
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
50
+ }
51
+ }
52
+ function _createClass(e, r, t) {
53
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
54
+ writable: !1
55
+ }), e;
56
+ }
57
+ function _createForOfIteratorHelper(r, e) {
58
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
59
+ if (!t) {
60
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
61
+ t && (r = t);
62
+ var n = 0,
63
+ F = function () {};
64
+ return {
65
+ s: F,
66
+ n: function () {
67
+ return n >= r.length ? {
68
+ done: !0
69
+ } : {
70
+ done: !1,
71
+ value: r[n++]
72
+ };
73
+ },
74
+ e: function (r) {
75
+ throw r;
76
+ },
77
+ f: F
78
+ };
79
+ }
80
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
81
+ }
82
+ var o,
83
+ a = !0,
84
+ u = !1;
85
+ return {
86
+ s: function () {
87
+ t = t.call(r);
88
+ },
89
+ n: function () {
90
+ var r = t.next();
91
+ return a = r.done, r;
92
+ },
93
+ e: function (r) {
94
+ u = !0, o = r;
95
+ },
96
+ f: function () {
97
+ try {
98
+ a || null == t.return || t.return();
99
+ } finally {
100
+ if (u) throw o;
101
+ }
102
+ }
103
+ };
104
+ }
105
+ function _defineProperty(e, r, t) {
106
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
107
+ value: t,
108
+ enumerable: !0,
109
+ configurable: !0,
110
+ writable: !0
111
+ }) : e[r] = t, e;
112
+ }
113
+ function _iterableToArray(r) {
114
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
115
+ }
116
+ function _iterableToArrayLimit(r, l) {
117
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
118
+ if (null != t) {
119
+ var e,
120
+ n,
121
+ i,
122
+ u,
123
+ a = [],
124
+ f = !0,
125
+ o = !1;
17
126
  try {
18
- if (_x = (_i = _i.call(arr)).next, 0 === i) {
19
- if (Object(_i) !== _i) return;
20
- _n = !1;
21
- } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
22
- } catch (err) {
23
- _d = !0, _e = err;
127
+ if (i = (t = t.call(r)).next, 0 === l) {
128
+ if (Object(t) !== t) return;
129
+ f = !1;
130
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
131
+ } catch (r) {
132
+ o = !0, n = r;
24
133
  } finally {
25
134
  try {
26
- if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
135
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
27
136
  } finally {
28
- if (_d) throw _e;
137
+ if (o) throw n;
29
138
  }
30
139
  }
31
- return _arr;
140
+ return a;
32
141
  }
33
142
  }
34
- function ownKeys(object, enumerableOnly) {
35
- var keys = Object.keys(object);
143
+ function _nonIterableRest() {
144
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
145
+ }
146
+ function _nonIterableSpread() {
147
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
148
+ }
149
+ function ownKeys(e, r) {
150
+ var t = Object.keys(e);
36
151
  if (Object.getOwnPropertySymbols) {
37
- var symbols = Object.getOwnPropertySymbols(object);
38
- enumerableOnly && (symbols = symbols.filter(function (sym) {
39
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
40
- })), keys.push.apply(keys, symbols);
152
+ var o = Object.getOwnPropertySymbols(e);
153
+ r && (o = o.filter(function (r) {
154
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
155
+ })), t.push.apply(t, o);
41
156
  }
42
- return keys;
157
+ return t;
43
158
  }
44
- function _objectSpread2(target) {
45
- for (var i = 1; i < arguments.length; i++) {
46
- var source = null != arguments[i] ? arguments[i] : {};
47
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
48
- _defineProperty(target, key, source[key]);
49
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
50
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
159
+ function _objectSpread2(e) {
160
+ for (var r = 1; r < arguments.length; r++) {
161
+ var t = null != arguments[r] ? arguments[r] : {};
162
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
163
+ _defineProperty(e, r, t[r]);
164
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
165
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
51
166
  });
52
167
  }
53
- return target;
168
+ return e;
54
169
  }
55
170
  function _regeneratorRuntime() {
56
171
  _regeneratorRuntime = function () {
57
- return exports;
172
+ return e;
58
173
  };
59
- var exports = {},
60
- Op = Object.prototype,
61
- hasOwn = Op.hasOwnProperty,
62
- defineProperty = Object.defineProperty || function (obj, key, desc) {
63
- obj[key] = desc.value;
174
+ var t,
175
+ e = {},
176
+ r = Object.prototype,
177
+ n = r.hasOwnProperty,
178
+ o = Object.defineProperty || function (t, e, r) {
179
+ t[e] = r.value;
64
180
  },
65
- $Symbol = "function" == typeof Symbol ? Symbol : {},
66
- iteratorSymbol = $Symbol.iterator || "@@iterator",
67
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
68
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
69
- function define(obj, key, value) {
70
- return Object.defineProperty(obj, key, {
71
- value: value,
181
+ i = "function" == typeof Symbol ? Symbol : {},
182
+ a = i.iterator || "@@iterator",
183
+ c = i.asyncIterator || "@@asyncIterator",
184
+ u = i.toStringTag || "@@toStringTag";
185
+ function define(t, e, r) {
186
+ return Object.defineProperty(t, e, {
187
+ value: r,
72
188
  enumerable: !0,
73
189
  configurable: !0,
74
190
  writable: !0
75
- }), obj[key];
191
+ }), t[e];
76
192
  }
77
193
  try {
78
194
  define({}, "");
79
- } catch (err) {
80
- define = function (obj, key, value) {
81
- return obj[key] = value;
195
+ } catch (t) {
196
+ define = function (t, e, r) {
197
+ return t[e] = r;
82
198
  };
83
199
  }
84
- function wrap(innerFn, outerFn, self, tryLocsList) {
85
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
86
- generator = Object.create(protoGenerator.prototype),
87
- context = new Context(tryLocsList || []);
88
- return defineProperty(generator, "_invoke", {
89
- value: makeInvokeMethod(innerFn, self, context)
90
- }), generator;
200
+ function wrap(t, e, r, n) {
201
+ var i = e && e.prototype instanceof Generator ? e : Generator,
202
+ a = Object.create(i.prototype),
203
+ c = new Context(n || []);
204
+ return o(a, "_invoke", {
205
+ value: makeInvokeMethod(t, r, c)
206
+ }), a;
91
207
  }
92
- function tryCatch(fn, obj, arg) {
208
+ function tryCatch(t, e, r) {
93
209
  try {
94
210
  return {
95
211
  type: "normal",
96
- arg: fn.call(obj, arg)
212
+ arg: t.call(e, r)
97
213
  };
98
- } catch (err) {
214
+ } catch (t) {
99
215
  return {
100
216
  type: "throw",
101
- arg: err
217
+ arg: t
102
218
  };
103
219
  }
104
220
  }
105
- exports.wrap = wrap;
106
- var ContinueSentinel = {};
221
+ e.wrap = wrap;
222
+ var h = "suspendedStart",
223
+ l = "suspendedYield",
224
+ f = "executing",
225
+ s = "completed",
226
+ y = {};
107
227
  function Generator() {}
108
228
  function GeneratorFunction() {}
109
229
  function GeneratorFunctionPrototype() {}
110
- var IteratorPrototype = {};
111
- define(IteratorPrototype, iteratorSymbol, function () {
230
+ var p = {};
231
+ define(p, a, function () {
112
232
  return this;
113
233
  });
114
- var getProto = Object.getPrototypeOf,
115
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
116
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
117
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
118
- function defineIteratorMethods(prototype) {
119
- ["next", "throw", "return"].forEach(function (method) {
120
- define(prototype, method, function (arg) {
121
- return this._invoke(method, arg);
234
+ var d = Object.getPrototypeOf,
235
+ v = d && d(d(values([])));
236
+ v && v !== r && n.call(v, a) && (p = v);
237
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
238
+ function defineIteratorMethods(t) {
239
+ ["next", "throw", "return"].forEach(function (e) {
240
+ define(t, e, function (t) {
241
+ return this._invoke(e, t);
122
242
  });
123
243
  });
124
244
  }
125
- function AsyncIterator(generator, PromiseImpl) {
126
- function invoke(method, arg, resolve, reject) {
127
- var record = tryCatch(generator[method], generator, arg);
128
- if ("throw" !== record.type) {
129
- var result = record.arg,
130
- value = result.value;
131
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
132
- invoke("next", value, resolve, reject);
133
- }, function (err) {
134
- invoke("throw", err, resolve, reject);
135
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
136
- result.value = unwrapped, resolve(result);
137
- }, function (error) {
138
- return invoke("throw", error, resolve, reject);
245
+ function AsyncIterator(t, e) {
246
+ function invoke(r, o, i, a) {
247
+ var c = tryCatch(t[r], t, o);
248
+ if ("throw" !== c.type) {
249
+ var u = c.arg,
250
+ h = u.value;
251
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
252
+ invoke("next", t, i, a);
253
+ }, function (t) {
254
+ invoke("throw", t, i, a);
255
+ }) : e.resolve(h).then(function (t) {
256
+ u.value = t, i(u);
257
+ }, function (t) {
258
+ return invoke("throw", t, i, a);
139
259
  });
140
260
  }
141
- reject(record.arg);
261
+ a(c.arg);
142
262
  }
143
- var previousPromise;
144
- defineProperty(this, "_invoke", {
145
- value: function (method, arg) {
263
+ var r;
264
+ o(this, "_invoke", {
265
+ value: function (t, n) {
146
266
  function callInvokeWithMethodAndArg() {
147
- return new PromiseImpl(function (resolve, reject) {
148
- invoke(method, arg, resolve, reject);
267
+ return new e(function (e, r) {
268
+ invoke(t, n, e, r);
149
269
  });
150
270
  }
151
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
271
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
152
272
  }
153
273
  });
154
274
  }
155
- function makeInvokeMethod(innerFn, self, context) {
156
- var state = "suspendedStart";
157
- return function (method, arg) {
158
- if ("executing" === state) throw new Error("Generator is already running");
159
- if ("completed" === state) {
160
- if ("throw" === method) throw arg;
161
- return doneResult();
275
+ function makeInvokeMethod(e, r, n) {
276
+ var o = h;
277
+ return function (i, a) {
278
+ if (o === f) throw Error("Generator is already running");
279
+ if (o === s) {
280
+ if ("throw" === i) throw a;
281
+ return {
282
+ value: t,
283
+ done: !0
284
+ };
162
285
  }
163
- for (context.method = method, context.arg = arg;;) {
164
- var delegate = context.delegate;
165
- if (delegate) {
166
- var delegateResult = maybeInvokeDelegate(delegate, context);
167
- if (delegateResult) {
168
- if (delegateResult === ContinueSentinel) continue;
169
- return delegateResult;
286
+ for (n.method = i, n.arg = a;;) {
287
+ var c = n.delegate;
288
+ if (c) {
289
+ var u = maybeInvokeDelegate(c, n);
290
+ if (u) {
291
+ if (u === y) continue;
292
+ return u;
170
293
  }
171
294
  }
172
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
173
- if ("suspendedStart" === state) throw state = "completed", context.arg;
174
- context.dispatchException(context.arg);
175
- } else "return" === context.method && context.abrupt("return", context.arg);
176
- state = "executing";
177
- var record = tryCatch(innerFn, self, context);
178
- if ("normal" === record.type) {
179
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
295
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
296
+ if (o === h) throw o = s, n.arg;
297
+ n.dispatchException(n.arg);
298
+ } else "return" === n.method && n.abrupt("return", n.arg);
299
+ o = f;
300
+ var p = tryCatch(e, r, n);
301
+ if ("normal" === p.type) {
302
+ if (o = n.done ? s : l, p.arg === y) continue;
180
303
  return {
181
- value: record.arg,
182
- done: context.done
304
+ value: p.arg,
305
+ done: n.done
183
306
  };
184
307
  }
185
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
308
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
186
309
  }
187
310
  };
188
311
  }
189
- function maybeInvokeDelegate(delegate, context) {
190
- var methodName = context.method,
191
- method = delegate.iterator[methodName];
192
- if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
193
- var record = tryCatch(method, delegate.iterator, context.arg);
194
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
195
- var info = record.arg;
196
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
312
+ function maybeInvokeDelegate(e, r) {
313
+ var n = r.method,
314
+ o = e.iterator[n];
315
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
316
+ var i = tryCatch(o, e.iterator, r.arg);
317
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
318
+ var a = i.arg;
319
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
197
320
  }
198
- function pushTryEntry(locs) {
199
- var entry = {
200
- tryLoc: locs[0]
321
+ function pushTryEntry(t) {
322
+ var e = {
323
+ tryLoc: t[0]
201
324
  };
202
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
325
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
203
326
  }
204
- function resetTryEntry(entry) {
205
- var record = entry.completion || {};
206
- record.type = "normal", delete record.arg, entry.completion = record;
327
+ function resetTryEntry(t) {
328
+ var e = t.completion || {};
329
+ e.type = "normal", delete e.arg, t.completion = e;
207
330
  }
208
- function Context(tryLocsList) {
331
+ function Context(t) {
209
332
  this.tryEntries = [{
210
333
  tryLoc: "root"
211
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
334
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
212
335
  }
213
- function values(iterable) {
214
- if (iterable) {
215
- var iteratorMethod = iterable[iteratorSymbol];
216
- if (iteratorMethod) return iteratorMethod.call(iterable);
217
- if ("function" == typeof iterable.next) return iterable;
218
- if (!isNaN(iterable.length)) {
219
- var i = -1,
220
- next = function next() {
221
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
222
- return next.value = undefined, next.done = !0, next;
336
+ function values(e) {
337
+ if (e || "" === e) {
338
+ var r = e[a];
339
+ if (r) return r.call(e);
340
+ if ("function" == typeof e.next) return e;
341
+ if (!isNaN(e.length)) {
342
+ var o = -1,
343
+ i = function next() {
344
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
345
+ return next.value = t, next.done = !0, next;
223
346
  };
224
- return next.next = next;
347
+ return i.next = i;
225
348
  }
226
349
  }
227
- return {
228
- next: doneResult
229
- };
230
- }
231
- function doneResult() {
232
- return {
233
- value: undefined,
234
- done: !0
235
- };
350
+ throw new TypeError(typeof e + " is not iterable");
236
351
  }
237
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
352
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
238
353
  value: GeneratorFunctionPrototype,
239
354
  configurable: !0
240
- }), defineProperty(GeneratorFunctionPrototype, "constructor", {
355
+ }), o(GeneratorFunctionPrototype, "constructor", {
241
356
  value: GeneratorFunction,
242
357
  configurable: !0
243
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
244
- var ctor = "function" == typeof genFun && genFun.constructor;
245
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
246
- }, exports.mark = function (genFun) {
247
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
248
- }, exports.awrap = function (arg) {
358
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
359
+ var e = "function" == typeof t && t.constructor;
360
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
361
+ }, e.mark = function (t) {
362
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
363
+ }, e.awrap = function (t) {
249
364
  return {
250
- __await: arg
365
+ __await: t
251
366
  };
252
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
367
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
253
368
  return this;
254
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
255
- void 0 === PromiseImpl && (PromiseImpl = Promise);
256
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
257
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
258
- return result.done ? result.value : iter.next();
369
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
370
+ void 0 === i && (i = Promise);
371
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
372
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
373
+ return t.done ? t.value : a.next();
259
374
  });
260
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
375
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
261
376
  return this;
262
- }), define(Gp, "toString", function () {
377
+ }), define(g, "toString", function () {
263
378
  return "[object Generator]";
264
- }), exports.keys = function (val) {
265
- var object = Object(val),
266
- keys = [];
267
- for (var key in object) keys.push(key);
268
- return keys.reverse(), function next() {
269
- for (; keys.length;) {
270
- var key = keys.pop();
271
- if (key in object) return next.value = key, next.done = !1, next;
379
+ }), e.keys = function (t) {
380
+ var e = Object(t),
381
+ r = [];
382
+ for (var n in e) r.push(n);
383
+ return r.reverse(), function next() {
384
+ for (; r.length;) {
385
+ var t = r.pop();
386
+ if (t in e) return next.value = t, next.done = !1, next;
272
387
  }
273
388
  return next.done = !0, next;
274
389
  };
275
- }, exports.values = values, Context.prototype = {
390
+ }, e.values = values, Context.prototype = {
276
391
  constructor: Context,
277
- reset: function (skipTempReset) {
278
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
392
+ reset: function (e) {
393
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
279
394
  },
280
395
  stop: function () {
281
396
  this.done = !0;
282
- var rootRecord = this.tryEntries[0].completion;
283
- if ("throw" === rootRecord.type) throw rootRecord.arg;
397
+ var t = this.tryEntries[0].completion;
398
+ if ("throw" === t.type) throw t.arg;
284
399
  return this.rval;
285
400
  },
286
- dispatchException: function (exception) {
287
- if (this.done) throw exception;
288
- var context = this;
289
- function handle(loc, caught) {
290
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
401
+ dispatchException: function (e) {
402
+ if (this.done) throw e;
403
+ var r = this;
404
+ function handle(n, o) {
405
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
291
406
  }
292
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
293
- var entry = this.tryEntries[i],
294
- record = entry.completion;
295
- if ("root" === entry.tryLoc) return handle("end");
296
- if (entry.tryLoc <= this.prev) {
297
- var hasCatch = hasOwn.call(entry, "catchLoc"),
298
- hasFinally = hasOwn.call(entry, "finallyLoc");
299
- if (hasCatch && hasFinally) {
300
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
301
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
302
- } else if (hasCatch) {
303
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
407
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
408
+ var i = this.tryEntries[o],
409
+ a = i.completion;
410
+ if ("root" === i.tryLoc) return handle("end");
411
+ if (i.tryLoc <= this.prev) {
412
+ var c = n.call(i, "catchLoc"),
413
+ u = n.call(i, "finallyLoc");
414
+ if (c && u) {
415
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
416
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
417
+ } else if (c) {
418
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
304
419
  } else {
305
- if (!hasFinally) throw new Error("try statement without catch or finally");
306
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
420
+ if (!u) throw Error("try statement without catch or finally");
421
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
307
422
  }
308
423
  }
309
424
  }
310
425
  },
311
- abrupt: function (type, arg) {
312
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
313
- var entry = this.tryEntries[i];
314
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
315
- var finallyEntry = entry;
426
+ abrupt: function (t, e) {
427
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
428
+ var o = this.tryEntries[r];
429
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
430
+ var i = o;
316
431
  break;
317
432
  }
318
433
  }
319
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
320
- var record = finallyEntry ? finallyEntry.completion : {};
321
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
434
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
435
+ var a = i ? i.completion : {};
436
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
322
437
  },
323
- complete: function (record, afterLoc) {
324
- if ("throw" === record.type) throw record.arg;
325
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
438
+ complete: function (t, e) {
439
+ if ("throw" === t.type) throw t.arg;
440
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
326
441
  },
327
- finish: function (finallyLoc) {
328
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
329
- var entry = this.tryEntries[i];
330
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
442
+ finish: function (t) {
443
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
444
+ var r = this.tryEntries[e];
445
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
331
446
  }
332
447
  },
333
- catch: function (tryLoc) {
334
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
335
- var entry = this.tryEntries[i];
336
- if (entry.tryLoc === tryLoc) {
337
- var record = entry.completion;
338
- if ("throw" === record.type) {
339
- var thrown = record.arg;
340
- resetTryEntry(entry);
448
+ catch: function (t) {
449
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
450
+ var r = this.tryEntries[e];
451
+ if (r.tryLoc === t) {
452
+ var n = r.completion;
453
+ if ("throw" === n.type) {
454
+ var o = n.arg;
455
+ resetTryEntry(r);
341
456
  }
342
- return thrown;
457
+ return o;
343
458
  }
344
459
  }
345
- throw new Error("illegal catch attempt");
460
+ throw Error("illegal catch attempt");
346
461
  },
347
- delegateYield: function (iterable, resultName, nextLoc) {
462
+ delegateYield: function (e, r, n) {
348
463
  return this.delegate = {
349
- iterator: values(iterable),
350
- resultName: resultName,
351
- nextLoc: nextLoc
352
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
464
+ iterator: values(e),
465
+ resultName: r,
466
+ nextLoc: n
467
+ }, "next" === this.method && (this.arg = t), y;
353
468
  }
354
- }, exports;
355
- }
356
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
357
- try {
358
- var info = gen[key](arg);
359
- var value = info.value;
360
- } catch (error) {
361
- reject(error);
362
- return;
363
- }
364
- if (info.done) {
365
- resolve(value);
366
- } else {
367
- Promise.resolve(value).then(_next, _throw);
368
- }
469
+ }, e;
369
470
  }
370
- function _asyncToGenerator(fn) {
371
- return function () {
372
- var self = this,
373
- args = arguments;
374
- return new Promise(function (resolve, reject) {
375
- var gen = fn.apply(self, args);
376
- function _next(value) {
377
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
378
- }
379
- function _throw(err) {
380
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
381
- }
382
- _next(undefined);
383
- });
384
- };
471
+ function _slicedToArray(r, e) {
472
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
385
473
  }
386
- function _classCallCheck(instance, Constructor) {
387
- if (!(instance instanceof Constructor)) {
388
- throw new TypeError("Cannot call a class as a function");
389
- }
474
+ function _toConsumableArray(r) {
475
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
390
476
  }
391
- function _defineProperties(target, props) {
392
- for (var i = 0; i < props.length; i++) {
393
- var descriptor = props[i];
394
- descriptor.enumerable = descriptor.enumerable || false;
395
- descriptor.configurable = true;
396
- if ("value" in descriptor) descriptor.writable = true;
397
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
477
+ function _toPrimitive(t, r) {
478
+ if ("object" != typeof t || !t) return t;
479
+ var e = t[Symbol.toPrimitive];
480
+ if (void 0 !== e) {
481
+ var i = e.call(t, r || "default");
482
+ if ("object" != typeof i) return i;
483
+ throw new TypeError("@@toPrimitive must return a primitive value.");
398
484
  }
485
+ return ("string" === r ? String : Number)(t);
399
486
  }
400
- function _createClass(Constructor, protoProps, staticProps) {
401
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
402
- if (staticProps) _defineProperties(Constructor, staticProps);
403
- Object.defineProperty(Constructor, "prototype", {
404
- writable: false
405
- });
406
- return Constructor;
487
+ function _toPropertyKey(t) {
488
+ var i = _toPrimitive(t, "string");
489
+ return "symbol" == typeof i ? i : i + "";
407
490
  }
408
- function _defineProperty(obj, key, value) {
409
- key = _toPropertyKey(key);
410
- if (key in obj) {
411
- Object.defineProperty(obj, key, {
412
- value: value,
413
- enumerable: true,
414
- configurable: true,
415
- writable: true
416
- });
417
- } else {
418
- obj[key] = value;
491
+ function _unsupportedIterableToArray(r, a) {
492
+ if (r) {
493
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
494
+ var t = {}.toString.call(r).slice(8, -1);
495
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
419
496
  }
420
- return obj;
421
- }
422
- function _slicedToArray(arr, i) {
423
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
424
- }
425
- function _toConsumableArray(arr) {
426
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
427
- }
428
- function _arrayWithoutHoles(arr) {
429
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
430
- }
431
- function _arrayWithHoles(arr) {
432
- if (Array.isArray(arr)) return arr;
433
- }
434
- function _iterableToArray(iter) {
435
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
436
- }
437
- function _unsupportedIterableToArray(o, minLen) {
438
- if (!o) return;
439
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
440
- var n = Object.prototype.toString.call(o).slice(8, -1);
441
- if (n === "Object" && o.constructor) n = o.constructor.name;
442
- if (n === "Map" || n === "Set") return Array.from(o);
443
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
444
- }
445
- function _arrayLikeToArray(arr, len) {
446
- if (len == null || len > arr.length) len = arr.length;
447
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
448
- return arr2;
449
- }
450
- function _nonIterableSpread() {
451
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
452
- }
453
- function _nonIterableRest() {
454
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
455
- }
456
- function _createForOfIteratorHelper(o, allowArrayLike) {
457
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
458
- if (!it) {
459
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
460
- if (it) o = it;
461
- var i = 0;
462
- var F = function () {};
463
- return {
464
- s: F,
465
- n: function () {
466
- if (i >= o.length) return {
467
- done: true
468
- };
469
- return {
470
- done: false,
471
- value: o[i++]
472
- };
473
- },
474
- e: function (e) {
475
- throw e;
476
- },
477
- f: F
478
- };
479
- }
480
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
481
- }
482
- var normalCompletion = true,
483
- didErr = false,
484
- err;
485
- return {
486
- s: function () {
487
- it = it.call(o);
488
- },
489
- n: function () {
490
- var step = it.next();
491
- normalCompletion = step.done;
492
- return step;
493
- },
494
- e: function (e) {
495
- didErr = true;
496
- err = e;
497
- },
498
- f: function () {
499
- try {
500
- if (!normalCompletion && it.return != null) it.return();
501
- } finally {
502
- if (didErr) throw err;
503
- }
504
- }
505
- };
506
- }
507
- function _toPrimitive(input, hint) {
508
- if (typeof input !== "object" || input === null) return input;
509
- var prim = input[Symbol.toPrimitive];
510
- if (prim !== undefined) {
511
- var res = prim.call(input, hint || "default");
512
- if (typeof res !== "object") return res;
513
- throw new TypeError("@@toPrimitive must return a primitive value.");
514
- }
515
- return (hint === "string" ? String : Number)(input);
516
- }
517
- function _toPropertyKey(arg) {
518
- var key = _toPrimitive(arg, "string");
519
- return typeof key === "symbol" ? key : String(key);
520
497
  }
521
498
 
522
499
  var toArray = function (x) { return (Array.isArray(x) ? x : [x]); };
@@ -545,9 +522,34 @@ var graphicTypeEquals = function (graphicType) {
545
522
  };
546
523
  };
547
524
 
525
+ var datasetToDict = data.datasetToDict;
526
+ /**
527
+ * Trigger file download from an array buffer
528
+ * @param bufferOrDataset - ArrayBuffer or DicomDataset
529
+ * @param filename - name of the file to download
530
+ */
531
+ function downloadDICOMData(bufferOrDataset, filename) {
532
+ var blob;
533
+ if (bufferOrDataset instanceof ArrayBuffer) {
534
+ blob = new Blob([bufferOrDataset], { type: "application/dicom" });
535
+ }
536
+ else {
537
+ if (!bufferOrDataset._meta) {
538
+ throw new Error("Dataset must have a _meta property");
539
+ }
540
+ var buffer = Buffer.from(datasetToDict(bufferOrDataset).write());
541
+ blob = new Blob([buffer], { type: "application/dicom" });
542
+ }
543
+ var link = document.createElement("a");
544
+ link.href = window.URL.createObjectURL(blob);
545
+ link.download = filename;
546
+ link.click();
547
+ }
548
+
548
549
  var index$1 = /*#__PURE__*/Object.freeze({
549
550
  __proto__: null,
550
551
  codeMeaningEquals: codeMeaningEquals,
552
+ downloadDICOMData: downloadDICOMData,
551
553
  graphicTypeEquals: graphicTypeEquals,
552
554
  toArray: toArray
553
555
  });
@@ -558,7 +560,7 @@ var StructuredReport$1 = derivations.StructuredReport;
558
560
  var Normalizer$4 = normalizers.Normalizer;
559
561
  var TID1500MeasurementReport$1 = TID1500$1.TID1500MeasurementReport,
560
562
  TID1501MeasurementGroup$1 = TID1500$1.TID1501MeasurementGroup;
561
- var DicomMetaDictionary$3 = data.DicomMetaDictionary;
563
+ var DicomMetaDictionary$4 = data.DicomMetaDictionary;
562
564
  var FINDING$2 = {
563
565
  CodingSchemeDesignator: "DCM",
564
566
  CodeValue: "121071"
@@ -602,7 +604,7 @@ var MeasurementReport$1 = /*#__PURE__*/function () {
602
604
  function MeasurementReport() {
603
605
  _classCallCheck(this, MeasurementReport);
604
606
  }
605
- _createClass(MeasurementReport, null, [{
607
+ return _createClass(MeasurementReport, null, [{
606
608
  key: "getSetupMeasurementData",
607
609
  value: function getSetupMeasurementData(MeasurementGroup) {
608
610
  var ContentSequence = MeasurementGroup.ContentSequence;
@@ -716,7 +718,6 @@ var MeasurementReport$1 = /*#__PURE__*/function () {
716
718
  //SOPInstanceUID: sopInstanceUID, // TODO: Necessary?
717
719
  //SOPClassUID: sopClassUID,
718
720
  };
719
-
720
721
  var _meta = {
721
722
  FileMetaInformationVersion: {
722
723
  Value: [fileMetaInformationVersionArray.buffer],
@@ -729,7 +730,7 @@ var MeasurementReport$1 = /*#__PURE__*/function () {
729
730
  vr: "UI"
730
731
  },
731
732
  ImplementationClassUID: {
732
- Value: [DicomMetaDictionary$3.uid()],
733
+ Value: [DicomMetaDictionary$4.uid()],
733
734
  // TODO: could be git hash or other valid id
734
735
  vr: "UI"
735
736
  },
@@ -749,6 +750,7 @@ var MeasurementReport$1 = /*#__PURE__*/function () {
749
750
  // Merge the derived dataset with the content from the Measurement Report
750
751
  report.dataset = Object.assign(report.dataset, contentItem);
751
752
  report.dataset._meta = _meta;
753
+ report.dataset.SpecificCharacterSet = "ISO_IR 192";
752
754
  return report;
753
755
  }
754
756
 
@@ -814,7 +816,6 @@ var MeasurementReport$1 = /*#__PURE__*/function () {
814
816
  MeasurementReport.MEASUREMENT_BY_TOOLTYPE[toolClass.toolType] = toolClass.utilityToolType;
815
817
  }
816
818
  }]);
817
- return MeasurementReport;
818
819
  }();
819
820
  MeasurementReport$1.MEASUREMENT_BY_TOOLTYPE = {};
820
821
  MeasurementReport$1.CORNERSTONE_TOOL_CLASSES_BY_UTILITY_TYPE = {};
@@ -822,13 +823,13 @@ MeasurementReport$1.CORNERSTONE_TOOL_CLASSES_BY_TOOL_TYPE = {};
822
823
 
823
824
  var CORNERSTONE_4_TAG = "cornerstoneTools@^4.0.0";
824
825
 
825
- var TID300Length$1 = utilities.TID300.Length;
826
+ var TID300Length$2 = utilities.TID300.Length;
826
827
  var LENGTH$1 = "Length";
827
828
  var Length$1 = /*#__PURE__*/function () {
828
829
  function Length() {
829
830
  _classCallCheck(this, Length);
830
831
  }
831
- _createClass(Length, null, [{
832
+ return _createClass(Length, null, [{
832
833
  key: "getMeasurementData",
833
834
  value:
834
835
  // TODO: this function is required for all Cornerstone Tool Adapters, since it is called by MeasurementReport.
@@ -879,11 +880,10 @@ var Length$1 = /*#__PURE__*/function () {
879
880
  };
880
881
  }
881
882
  }]);
882
- return Length;
883
883
  }();
884
884
  Length$1.toolType = LENGTH$1;
885
885
  Length$1.utilityToolType = LENGTH$1;
886
- Length$1.TID300Representation = TID300Length$1;
886
+ Length$1.TID300Representation = TID300Length$2;
887
887
  Length$1.isValidCornerstoneTrackingIdentifier = function (TrackingIdentifier) {
888
888
  if (!TrackingIdentifier.includes(":")) {
889
889
  return false;
@@ -904,7 +904,7 @@ var FreehandRoi = /*#__PURE__*/function () {
904
904
  function FreehandRoi() {
905
905
  _classCallCheck(this, FreehandRoi);
906
906
  }
907
- _createClass(FreehandRoi, null, [{
907
+ return _createClass(FreehandRoi, null, [{
908
908
  key: "getMeasurementData",
909
909
  value: function getMeasurementData(MeasurementGroup) {
910
910
  var _MeasurementReport$ge = MeasurementReport$1.getSetupMeasurementData(MeasurementGroup),
@@ -963,7 +963,6 @@ var FreehandRoi = /*#__PURE__*/function () {
963
963
  };
964
964
  }
965
965
  }]);
966
- return FreehandRoi;
967
966
  }();
968
967
  FreehandRoi.toolType = "FreehandRoi";
969
968
  FreehandRoi.utilityToolType = "FreehandRoi";
@@ -993,7 +992,7 @@ var Bidirectional$1 = /*#__PURE__*/function () {
993
992
  function Bidirectional() {
994
993
  _classCallCheck(this, Bidirectional);
995
994
  }
996
- _createClass(Bidirectional, null, [{
995
+ return _createClass(Bidirectional, null, [{
997
996
  key: "getMeasurementData",
998
997
  value:
999
998
  // TODO: this function is required for all Cornerstone Tool Adapters, since it is called by MeasurementReport.
@@ -1126,7 +1125,6 @@ var Bidirectional$1 = /*#__PURE__*/function () {
1126
1125
  };
1127
1126
  }
1128
1127
  }]);
1129
- return Bidirectional;
1130
1128
  }();
1131
1129
  Bidirectional$1.toolType = BIDIRECTIONAL$1;
1132
1130
  Bidirectional$1.utilityToolType = BIDIRECTIONAL$1;
@@ -1152,7 +1150,7 @@ var EllipticalRoi = /*#__PURE__*/function () {
1152
1150
  function EllipticalRoi() {
1153
1151
  _classCallCheck(this, EllipticalRoi);
1154
1152
  }
1155
- _createClass(EllipticalRoi, null, [{
1153
+ return _createClass(EllipticalRoi, null, [{
1156
1154
  key: "getMeasurementData",
1157
1155
  value:
1158
1156
  // TODO: this function is required for all Cornerstone Tool Adapters, since it is called by MeasurementReport.
@@ -1299,7 +1297,6 @@ var EllipticalRoi = /*#__PURE__*/function () {
1299
1297
  };
1300
1298
  }
1301
1299
  }]);
1302
- return EllipticalRoi;
1303
1300
  }();
1304
1301
  EllipticalRoi.toolType = ELLIPTICALROI$1;
1305
1302
  EllipticalRoi.utilityToolType = ELLIPTICALROI$1;
@@ -1325,7 +1322,7 @@ var CircleRoi = /*#__PURE__*/function () {
1325
1322
  function CircleRoi() {
1326
1323
  _classCallCheck(this, CircleRoi);
1327
1324
  }
1328
- _createClass(CircleRoi, null, [{
1325
+ return _createClass(CircleRoi, null, [{
1329
1326
  key: "getMeasurementData",
1330
1327
  value: /** Gets the measurement data for cornerstone, given DICOM SR measurement data. */
1331
1328
  function getMeasurementData(MeasurementGroup) {
@@ -1409,7 +1406,6 @@ var CircleRoi = /*#__PURE__*/function () {
1409
1406
  };
1410
1407
  }
1411
1408
  }]);
1412
- return CircleRoi;
1413
1409
  }();
1414
1410
  CircleRoi.toolType = CIRCLEROI$1;
1415
1411
  CircleRoi.utilityToolType = CIRCLEROI$1;
@@ -1436,7 +1432,7 @@ var ArrowAnnotate$1 = /*#__PURE__*/function () {
1436
1432
  function ArrowAnnotate() {
1437
1433
  _classCallCheck(this, ArrowAnnotate);
1438
1434
  }
1439
- _createClass(ArrowAnnotate, null, [{
1435
+ return _createClass(ArrowAnnotate, null, [{
1440
1436
  key: "getMeasurementData",
1441
1437
  value: function getMeasurementData(MeasurementGroup) {
1442
1438
  var _MeasurementReport$ge = MeasurementReport$1.getSetupMeasurementData(MeasurementGroup),
@@ -1501,7 +1497,6 @@ var ArrowAnnotate$1 = /*#__PURE__*/function () {
1501
1497
  return TID300RepresentationArguments;
1502
1498
  }
1503
1499
  }]);
1504
- return ArrowAnnotate;
1505
1500
  }();
1506
1501
  ArrowAnnotate$1.toolType = ARROW_ANNOTATE$1;
1507
1502
  ArrowAnnotate$1.utilityToolType = ARROW_ANNOTATE$1;
@@ -1527,7 +1522,7 @@ var CobbAngle$1 = /*#__PURE__*/function () {
1527
1522
  function CobbAngle() {
1528
1523
  _classCallCheck(this, CobbAngle);
1529
1524
  }
1530
- _createClass(CobbAngle, null, [{
1525
+ return _createClass(CobbAngle, null, [{
1531
1526
  key: "getMeasurementData",
1532
1527
  value:
1533
1528
  // TODO: this function is required for all Cornerstone Tool Adapters, since it is called by MeasurementReport.
@@ -1594,7 +1589,6 @@ var CobbAngle$1 = /*#__PURE__*/function () {
1594
1589
  };
1595
1590
  }
1596
1591
  }]);
1597
- return CobbAngle;
1598
1592
  }();
1599
1593
  CobbAngle$1.toolType = COBB_ANGLE;
1600
1594
  CobbAngle$1.utilityToolType = COBB_ANGLE;
@@ -1620,7 +1614,7 @@ var Angle$1 = /*#__PURE__*/function () {
1620
1614
  function Angle() {
1621
1615
  _classCallCheck(this, Angle);
1622
1616
  }
1623
- _createClass(Angle, null, [{
1617
+ return _createClass(Angle, null, [{
1624
1618
  key: "getMeasurementData",
1625
1619
  value:
1626
1620
  /**
@@ -1682,7 +1676,6 @@ var Angle$1 = /*#__PURE__*/function () {
1682
1676
  };
1683
1677
  }
1684
1678
  }]);
1685
- return Angle;
1686
1679
  }();
1687
1680
  Angle$1.toolType = ANGLE;
1688
1681
  Angle$1.utilityToolType = ANGLE;
@@ -1707,7 +1700,7 @@ var RectangleRoi = /*#__PURE__*/function () {
1707
1700
  function RectangleRoi() {
1708
1701
  _classCallCheck(this, RectangleRoi);
1709
1702
  }
1710
- _createClass(RectangleRoi, null, [{
1703
+ return _createClass(RectangleRoi, null, [{
1711
1704
  key: "getMeasurementData",
1712
1705
  value: function getMeasurementData(MeasurementGroup) {
1713
1706
  var _MeasurementReport$ge = MeasurementReport$1.getSetupMeasurementData(MeasurementGroup),
@@ -1774,7 +1767,6 @@ var RectangleRoi = /*#__PURE__*/function () {
1774
1767
  };
1775
1768
  }
1776
1769
  }]);
1777
- return RectangleRoi;
1778
1770
  }();
1779
1771
  RectangleRoi.toolType = "RectangleRoi";
1780
1772
  RectangleRoi.utilityToolType = "RectangleRoi";
@@ -1802,7 +1794,7 @@ var _utilities$orientatio$1 = utilities.orientation,
1802
1794
  var datasetToBlob = utilities.datasetToBlob,
1803
1795
  BitArray$2 = utilities.BitArray,
1804
1796
  DicomMessage$1 = utilities.DicomMessage,
1805
- DicomMetaDictionary$2 = utilities.DicomMetaDictionary;
1797
+ DicomMetaDictionary$3 = utilities.DicomMetaDictionary;
1806
1798
  var Normalizer$3 = normalizers.Normalizer;
1807
1799
  var SegmentationDerivation$2 = derivations.Segmentation;
1808
1800
  var Segmentation$5 = {
@@ -1932,16 +1924,16 @@ function _createSegFromImages$1(images, isMultiframe, options) {
1932
1924
  var image = images[0];
1933
1925
  var arrayBuffer = image.data.byteArray.buffer;
1934
1926
  var dicomData = DicomMessage$1.readFile(arrayBuffer);
1935
- var dataset = DicomMetaDictionary$2.naturalizeDataset(dicomData.dict);
1936
- dataset._meta = DicomMetaDictionary$2.namifyDataset(dicomData.meta);
1927
+ var dataset = DicomMetaDictionary$3.naturalizeDataset(dicomData.dict);
1928
+ dataset._meta = DicomMetaDictionary$3.namifyDataset(dicomData.meta);
1937
1929
  datasets.push(dataset);
1938
1930
  } else {
1939
1931
  for (var i = 0; i < images.length; i++) {
1940
1932
  var _image = images[i];
1941
1933
  var _arrayBuffer = _image.data.byteArray.buffer;
1942
1934
  var _dicomData = DicomMessage$1.readFile(_arrayBuffer);
1943
- var _dataset = DicomMetaDictionary$2.naturalizeDataset(_dicomData.dict);
1944
- _dataset._meta = DicomMetaDictionary$2.namifyDataset(_dicomData.meta);
1935
+ var _dataset = DicomMetaDictionary$3.naturalizeDataset(_dicomData.dict);
1936
+ _dataset._meta = DicomMetaDictionary$3.namifyDataset(_dicomData.meta);
1945
1937
  datasets.push(_dataset);
1946
1938
  }
1947
1939
  }
@@ -1961,8 +1953,8 @@ function _createSegFromImages$1(images, isMultiframe, options) {
1961
1953
  */
1962
1954
  function generateToolState$3(imageIds, arrayBuffer, metadataProvider) {
1963
1955
  var dicomData = DicomMessage$1.readFile(arrayBuffer);
1964
- var dataset = DicomMetaDictionary$2.naturalizeDataset(dicomData.dict);
1965
- dataset._meta = DicomMetaDictionary$2.namifyDataset(dicomData.meta);
1956
+ var dataset = DicomMetaDictionary$3.naturalizeDataset(dicomData.dict);
1957
+ dataset._meta = DicomMetaDictionary$3.namifyDataset(dicomData.meta);
1966
1958
  var multiframe = Normalizer$3.normalizeToDataset([dataset]);
1967
1959
  var imagePlaneModule = metadataProvider.get("imagePlaneModule", imageIds[0]);
1968
1960
  if (!imagePlaneModule) {
@@ -2240,10 +2232,9 @@ var _utilities$orientatio = utilities.orientation,
2240
2232
  flipMatrix2D = _utilities$orientatio.flipMatrix2D,
2241
2233
  rotateMatrix902D = _utilities$orientatio.rotateMatrix902D,
2242
2234
  nearlyEqual = _utilities$orientatio.nearlyEqual;
2243
- var datasetToDict = data.datasetToDict,
2244
- BitArray$1 = data.BitArray,
2235
+ var BitArray$1 = data.BitArray,
2245
2236
  DicomMessage = data.DicomMessage,
2246
- DicomMetaDictionary$1 = data.DicomMetaDictionary;
2237
+ DicomMetaDictionary$2 = data.DicomMetaDictionary;
2247
2238
  var Normalizer$2 = normalizers.Normalizer;
2248
2239
  var SegmentationDerivation$1 = derivations.Segmentation;
2249
2240
  var _utilities$compressio = utilities.compression,
@@ -2280,12 +2271,13 @@ function generateSegmentation$2(images, inputLabelmaps3D) {
2280
2271
  }
2281
2272
 
2282
2273
  /**
2283
- * fillSegmentation - Fills a derived segmentation dataset with cornerstoneTools `LabelMap3D` data.
2274
+ * Fills a given segmentation object with data from the input labelmaps3D
2284
2275
  *
2285
- * @param {object[]} segmentation An empty segmentation derived dataset.
2286
- * @param {Object|Object[]} inputLabelmaps3D The cornerstone `Labelmap3D` object, or an array of objects.
2287
- * @param {Object} userOptions Options object to override default options.
2288
- * @returns {Blob} description
2276
+ * @param segmentation - The segmentation object to be filled.
2277
+ * @param inputLabelmaps3D - An array of 3D labelmaps, or a single 3D labelmap.
2278
+ * @param userOptions - Optional configuration settings. Will override the default options.
2279
+ *
2280
+ * @returns {object} The filled segmentation object.
2289
2281
  */
2290
2282
  function fillSegmentation$1(segmentation, inputLabelmaps3D) {
2291
2283
  var userOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -2361,17 +2353,14 @@ function fillSegmentation$1(segmentation, inputLabelmaps3D) {
2361
2353
  Value: ["1.2.840.10008.1.2.5"],
2362
2354
  vr: "UI"
2363
2355
  };
2356
+ segmentation.dataset.SpecificCharacterSet = "ISO_IR 192";
2364
2357
  segmentation.dataset._vrMap.PixelData = "OB";
2365
2358
  segmentation.dataset.PixelData = rleEncodedFrames;
2366
2359
  } else {
2367
2360
  // If no rleEncoding, at least bitpack the data.
2368
2361
  segmentation.bitPackPixelData();
2369
2362
  }
2370
- var buffer = Buffer.from(datasetToDict(segmentation.dataset).write());
2371
- var segBlob = new Blob([buffer], {
2372
- type: "application/dicom"
2373
- });
2374
- return segBlob;
2363
+ return segmentation;
2375
2364
  }
2376
2365
  function _getLabelmapsFromReferencedFrameIndicies(labelmap3D, referencedFrameIndicies) {
2377
2366
  var labelmaps2D = labelmap3D.labelmaps2D;
@@ -2396,16 +2385,18 @@ function _createSegFromImages(images, isMultiframe, options) {
2396
2385
  var image = images[0];
2397
2386
  var arrayBuffer = image.data.byteArray.buffer;
2398
2387
  var dicomData = DicomMessage.readFile(arrayBuffer);
2399
- var dataset = DicomMetaDictionary$1.naturalizeDataset(dicomData.dict);
2400
- dataset._meta = DicomMetaDictionary$1.namifyDataset(dicomData.meta);
2388
+ var dataset = DicomMetaDictionary$2.naturalizeDataset(dicomData.dict);
2389
+ dataset._meta = DicomMetaDictionary$2.namifyDataset(dicomData.meta);
2390
+ dataset.SpecificCharacterSet = "ISO_IR 192";
2401
2391
  datasets.push(dataset);
2402
2392
  } else {
2403
2393
  for (var i = 0; i < images.length; i++) {
2404
2394
  var _image = images[i];
2405
2395
  var _arrayBuffer = _image.data.byteArray.buffer;
2406
2396
  var _dicomData = DicomMessage.readFile(_arrayBuffer);
2407
- var _dataset = DicomMetaDictionary$1.naturalizeDataset(_dicomData.dict);
2408
- _dataset._meta = DicomMetaDictionary$1.namifyDataset(_dicomData.meta);
2397
+ var _dataset = DicomMetaDictionary$2.naturalizeDataset(_dicomData.dict);
2398
+ _dataset._meta = DicomMetaDictionary$2.namifyDataset(_dicomData.meta);
2399
+ _dataset.SpecificCharacterSet = "ISO_IR 192";
2409
2400
  datasets.push(_dataset);
2410
2401
  }
2411
2402
  }
@@ -2583,14 +2574,14 @@ function generateToolState$2(_x, _x2, _x3, _x4) {
2583
2574
  */
2584
2575
  function _generateToolState() {
2585
2576
  _generateToolState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(imageIds, arrayBuffer, metadataProvider, options) {
2586
- var _options$skipOverlapp, skipOverlapping, _options$tolerance, tolerance, _options$TypedArrayCo, TypedArrayConstructor, _options$maxBytesPerC, maxBytesPerChunk, eventTarget, triggerEvent, dicomData, dataset, multiframe, imagePlaneModule, generalSeriesModule, SeriesInstanceUID, ImageOrientationPatient, validOrientations, sliceLength, segMetadata, TransferSyntaxUID, pixelData, pixelDataChunks, rleEncodedFrames, orientation, sopUIDImageIdIndexMap, overlapping, insertFunction, segmentsOnFrameArray, segmentsOnFrame, arrayBufferLength, labelmapBufferArray, imageIdMaps, segmentsPixelIndices, centroidXYZ;
2577
+ var _options$skipOverlapp, skipOverlapping, _options$tolerance, tolerance, _options$TypedArrayCo, TypedArrayConstructor, _options$maxBytesPerC, maxBytesPerChunk, eventTarget, triggerEvent, dicomData, dataset, multiframe, imagePlaneModule, generalSeriesModule, SeriesInstanceUID, ImageOrientationPatient, validOrientations, sliceLength, segMetadata, TransferSyntaxUID, pixelData, pixelDataChunks, rleEncodedFrames, orientation, sopUIDImageIdIndexMap, overlapping, insertFunction, segmentsOnFrameArray, segmentsOnFrame, arrayBufferLength, labelmapBufferArray, imageIdMaps, segmentsPixelIndices, overlappingSegments, centroidXYZ;
2587
2578
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2588
2579
  while (1) switch (_context.prev = _context.next) {
2589
2580
  case 0:
2590
2581
  _options$skipOverlapp = options.skipOverlapping, skipOverlapping = _options$skipOverlapp === void 0 ? false : _options$skipOverlapp, _options$tolerance = options.tolerance, tolerance = _options$tolerance === void 0 ? 1e-3 : _options$tolerance, _options$TypedArrayCo = options.TypedArrayConstructor, TypedArrayConstructor = _options$TypedArrayCo === void 0 ? Uint8Array : _options$TypedArrayCo, _options$maxBytesPerC = options.maxBytesPerChunk, maxBytesPerChunk = _options$maxBytesPerC === void 0 ? 199000000 : _options$maxBytesPerC, eventTarget = options.eventTarget, triggerEvent = options.triggerEvent;
2591
2582
  dicomData = DicomMessage.readFile(arrayBuffer);
2592
- dataset = DicomMetaDictionary$1.naturalizeDataset(dicomData.dict);
2593
- dataset._meta = DicomMetaDictionary$1.namifyDataset(dicomData.meta);
2583
+ dataset = DicomMetaDictionary$2.naturalizeDataset(dicomData.dict);
2584
+ dataset._meta = DicomMetaDictionary$2.namifyDataset(dicomData.meta);
2594
2585
  multiframe = Normalizer$2.normalizeToDataset([dataset]);
2595
2586
  imagePlaneModule = metadataProvider.get("imagePlaneModule", imageIds[0]);
2596
2587
  generalSeriesModule = metadataProvider.get("generalSeriesModule", imageIds[0]);
@@ -2635,8 +2626,8 @@ function _generateToolState() {
2635
2626
  // and over again.
2636
2627
  sopUIDImageIdIndexMap = imageIds.reduce(function (acc, imageId) {
2637
2628
  var _metadataProvider$get = metadataProvider.get("generalImageModule", imageId),
2638
- sopInstanceUid = _metadataProvider$get.sopInstanceUid;
2639
- acc[sopInstanceUid] = imageId;
2629
+ sopInstanceUID = _metadataProvider$get.sopInstanceUID;
2630
+ acc[sopInstanceUID] = imageId;
2640
2631
  return acc;
2641
2632
  }, {});
2642
2633
  overlapping = false;
@@ -2670,7 +2661,7 @@ function _generateToolState() {
2670
2661
  labelmapBufferArray = [];
2671
2662
  labelmapBufferArray[0] = new ArrayBuffer(arrayBufferLength);
2672
2663
 
2673
- // Precompute the indices and metadata so that we don't have to call
2664
+ // Pre-compute the indices and metadata so that we don't have to call
2674
2665
  // a function for each imageId in the for loop.
2675
2666
  imageIdMaps = imageIds.reduce(function (acc, curr, index) {
2676
2667
  acc.indices[curr] = index;
@@ -2687,6 +2678,7 @@ function _generateToolState() {
2687
2678
  _context.next = 47;
2688
2679
  return insertFunction(segmentsOnFrame, segmentsOnFrameArray, labelmapBufferArray, pixelDataChunks, multiframe, imageIds, validOrientations, metadataProvider, tolerance, TypedArrayConstructor, segmentsPixelIndices, sopUIDImageIdIndexMap, imageIdMaps, eventTarget, triggerEvent);
2689
2680
  case 47:
2681
+ overlappingSegments = _context.sent;
2690
2682
  // calculate the centroid of each segment
2691
2683
  centroidXYZ = new Map();
2692
2684
  segmentsPixelIndices.forEach(function (imageIdIndexBufferIndex, segmentIndex) {
@@ -2706,9 +2698,10 @@ function _generateToolState() {
2706
2698
  segMetadata: segMetadata,
2707
2699
  segmentsOnFrame: segmentsOnFrame,
2708
2700
  segmentsOnFrameArray: segmentsOnFrameArray,
2709
- centroids: centroidXYZ
2701
+ centroids: centroidXYZ,
2702
+ overlappingSegments: overlappingSegments
2710
2703
  });
2711
- case 50:
2704
+ case 51:
2712
2705
  case "end":
2713
2706
  return _context.stop();
2714
2707
  }
@@ -2733,9 +2726,7 @@ function findReferenceSourceImageId(multiframe, frameSegment, imageIds, metadata
2733
2726
  return imageId;
2734
2727
  }
2735
2728
  var frameSourceImageSequence = undefined;
2736
- if (SourceImageSequence && SourceImageSequence.length !== 0) {
2737
- frameSourceImageSequence = SourceImageSequence[frameSegment];
2738
- } else if (PerFrameFunctionalGroup.DerivationImageSequence) {
2729
+ if (PerFrameFunctionalGroup.DerivationImageSequence) {
2739
2730
  var DerivationImageSequence = PerFrameFunctionalGroup.DerivationImageSequence;
2740
2731
  if (Array.isArray(DerivationImageSequence)) {
2741
2732
  if (DerivationImageSequence.length !== 0) {
@@ -2754,6 +2745,9 @@ function findReferenceSourceImageId(multiframe, frameSegment, imageIds, metadata
2754
2745
  }
2755
2746
  }
2756
2747
  }
2748
+ } else if (SourceImageSequence && SourceImageSequence.length !== 0) {
2749
+ console.warn("DerivationImageSequence not present, using SourceImageSequence assuming SEG has the same geometry as the source image.");
2750
+ frameSourceImageSequence = SourceImageSequence[frameSegment];
2757
2751
  }
2758
2752
  if (frameSourceImageSequence) {
2759
2753
  imageId = getImageIdOfSourceImageBySourceImageSequence(frameSourceImageSequence, sopUIDImageIdIndexMap);
@@ -2793,32 +2787,33 @@ function checkSEGsOverlapping(pixelData, multiframe, imageIds, validOrientations
2793
2787
 
2794
2788
  var frameSegmentsMapping = new Map();
2795
2789
  var _loop3 = function _loop3() {
2796
- var segmentIndex = getSegmentIndex(multiframe, frameSegment);
2797
- if (segmentIndex === undefined) {
2798
- console.warn("Could not retrieve the segment index for frame segment " + frameSegment + ", skipping this frame.");
2799
- return "continue";
2800
- }
2801
- var imageId = findReferenceSourceImageId(multiframe, frameSegment, imageIds, metadataProvider, tolerance, sopUIDImageIdIndexMap);
2802
- if (!imageId) {
2803
- console.warn("Image not present in stack, can't import frame : " + frameSegment + ".");
2804
- return "continue";
2805
- }
2806
- var imageIdIndex = imageIds.findIndex(function (element) {
2807
- return element === imageId;
2808
- });
2809
- if (frameSegmentsMapping.has(imageIdIndex)) {
2810
- var segmentArray = frameSegmentsMapping.get(imageIdIndex);
2811
- if (!segmentArray.includes(frameSegment)) {
2812
- segmentArray.push(frameSegment);
2813
- frameSegmentsMapping.set(imageIdIndex, segmentArray);
2790
+ var segmentIndex = getSegmentIndex(multiframe, frameSegment);
2791
+ if (segmentIndex === undefined) {
2792
+ console.warn("Could not retrieve the segment index for frame segment " + frameSegment + ", skipping this frame.");
2793
+ return 0; // continue
2814
2794
  }
2815
- } else {
2816
- frameSegmentsMapping.set(imageIdIndex, [frameSegment]);
2817
- }
2818
- };
2795
+ var imageId = findReferenceSourceImageId(multiframe, frameSegment, imageIds, metadataProvider, tolerance, sopUIDImageIdIndexMap);
2796
+ if (!imageId) {
2797
+ console.warn("Image not present in stack, can't import frame : " + frameSegment + ".");
2798
+ return 0; // continue
2799
+ }
2800
+ var imageIdIndex = imageIds.findIndex(function (element) {
2801
+ return element === imageId;
2802
+ });
2803
+ if (frameSegmentsMapping.has(imageIdIndex)) {
2804
+ var segmentArray = frameSegmentsMapping.get(imageIdIndex);
2805
+ if (!segmentArray.includes(frameSegment)) {
2806
+ segmentArray.push(frameSegment);
2807
+ frameSegmentsMapping.set(imageIdIndex, segmentArray);
2808
+ }
2809
+ } else {
2810
+ frameSegmentsMapping.set(imageIdIndex, [frameSegment]);
2811
+ }
2812
+ },
2813
+ _ret;
2819
2814
  for (var frameSegment = 0; frameSegment < groupsLen; ++frameSegment) {
2820
- var _ret = _loop3();
2821
- if (_ret === "continue") continue;
2815
+ _ret = _loop3();
2816
+ if (_ret === 0) continue;
2822
2817
  }
2823
2818
  var _iterator = _createForOfIteratorHelper(frameSegmentsMapping.entries()),
2824
2819
  _step;
@@ -2874,7 +2869,7 @@ function insertOverlappingPixelDataPlanar(segmentsOnFrame, segmentsOnFrameArray,
2874
2869
  var tempBuffer = labelmapBufferArray[m].slice(0);
2875
2870
 
2876
2871
  // temp list for checking overlaps
2877
- var tempSegmentsOnFrame = cloneDeep(segmentsOnFrameArray[m]);
2872
+ var tempSegmentsOnFrame = structuredClone(segmentsOnFrameArray[m]);
2878
2873
 
2879
2874
  /** split overlapping SEGs algorithm for each segment:
2880
2875
  * A) copy the labelmapBuffer in the array with index 0
@@ -2886,85 +2881,86 @@ function insertOverlappingPixelDataPlanar(segmentsOnFrame, segmentsOnFrameArray,
2886
2881
  var numberOfSegs = multiframe.SegmentSequence.length;
2887
2882
  for (var segmentIndexToProcess = 1; segmentIndexToProcess <= numberOfSegs; ++segmentIndexToProcess) {
2888
2883
  var _loop4 = function _loop4(_i2) {
2889
- var PerFrameFunctionalGroups = PerFrameFunctionalGroupsSequence[_i2];
2890
- var segmentIndex = getSegmentIndex(multiframe, _i2);
2891
- if (segmentIndex === undefined) {
2892
- throw new Error("Could not retrieve the segment index. Aborting segmentation loading.");
2893
- }
2894
- if (segmentIndex !== segmentIndexToProcess) {
2895
- i = _i2;
2896
- return "continue";
2897
- }
2898
- var ImageOrientationPatientI = sharedImageOrientationPatient || PerFrameFunctionalGroups.PlaneOrientationSequence.ImageOrientationPatient;
2899
-
2900
- // Since we moved to the chunks approach, we need to read the data
2901
- // and handle scenarios where the portion of data is in one chunk
2902
- // and the other portion is in another chunk
2903
- var view = readFromUnpackedChunks(pixelData, _i2 * sliceLength, sliceLength);
2904
- var pixelDataI2D = ndarray(view, [Rows, Columns]);
2905
- var alignedPixelDataI = alignPixelDataWithSourceData(pixelDataI2D, ImageOrientationPatientI, validOrientations, tolerance);
2906
- if (!alignedPixelDataI) {
2907
- throw new Error("Individual SEG frames are out of plane with respect to the first SEG frame. " + "This is not yet supported. Aborting segmentation loading.");
2908
- }
2909
- var imageId = findReferenceSourceImageId(multiframe, _i2, imageIds, metadataProvider, tolerance, sopUIDImageIdIndexMap);
2910
- if (!imageId) {
2911
- console.warn("Image not present in stack, can't import frame : " + _i2 + ".");
2912
- i = _i2;
2913
- return "continue";
2914
- }
2915
- var sourceImageMetadata = metadataProvider.get("instance", imageId);
2916
- if (Rows !== sourceImageMetadata.Rows || Columns !== sourceImageMetadata.Columns) {
2917
- throw new Error("Individual SEG frames have different geometry dimensions (Rows and Columns) " + "respect to the source image reference frame. This is not yet supported. " + "Aborting segmentation loading. ");
2918
- }
2919
- var imageIdIndex = imageIds.findIndex(function (element) {
2920
- return element === imageId;
2921
- });
2922
- var byteOffset = sliceLength * imageIdIndex * TypedArrayConstructor.BYTES_PER_ELEMENT;
2923
- var labelmap2DView = new TypedArrayConstructor(tempBuffer, byteOffset, sliceLength);
2924
- var data = alignedPixelDataI.data;
2925
- var segmentOnFrame = false;
2926
- for (var j = 0, len = alignedPixelDataI.data.length; j < len; ++j) {
2927
- if (data[j]) {
2928
- if (labelmap2DView[j] !== 0) {
2929
- m++;
2930
- if (m >= M) {
2931
- labelmapBufferArray[m] = new ArrayBuffer(arrayBufferLength);
2932
- segmentsOnFrameArray[m] = [];
2933
- M++;
2884
+ var PerFrameFunctionalGroups = PerFrameFunctionalGroupsSequence[_i2];
2885
+ var segmentIndex = getSegmentIndex(multiframe, _i2);
2886
+ if (segmentIndex === undefined) {
2887
+ throw new Error("Could not retrieve the segment index. Aborting segmentation loading.");
2888
+ }
2889
+ if (segmentIndex !== segmentIndexToProcess) {
2890
+ i = _i2;
2891
+ return 0; // continue
2892
+ }
2893
+ var ImageOrientationPatientI = sharedImageOrientationPatient || PerFrameFunctionalGroups.PlaneOrientationSequence.ImageOrientationPatient;
2894
+
2895
+ // Since we moved to the chunks approach, we need to read the data
2896
+ // and handle scenarios where the portion of data is in one chunk
2897
+ // and the other portion is in another chunk
2898
+ var view = readFromUnpackedChunks(pixelData, _i2 * sliceLength, sliceLength);
2899
+ var pixelDataI2D = ndarray(view, [Rows, Columns]);
2900
+ var alignedPixelDataI = alignPixelDataWithSourceData(pixelDataI2D, ImageOrientationPatientI, validOrientations, tolerance);
2901
+ if (!alignedPixelDataI) {
2902
+ throw new Error("Individual SEG frames are out of plane with respect to the first SEG frame. " + "This is not yet supported. Aborting segmentation loading.");
2903
+ }
2904
+ var imageId = findReferenceSourceImageId(multiframe, _i2, imageIds, metadataProvider, tolerance, sopUIDImageIdIndexMap);
2905
+ if (!imageId) {
2906
+ console.warn("Image not present in stack, can't import frame : " + _i2 + ".");
2907
+ i = _i2;
2908
+ return 0; // continue
2909
+ }
2910
+ var sourceImageMetadata = metadataProvider.get("instance", imageId);
2911
+ if (Rows !== sourceImageMetadata.Rows || Columns !== sourceImageMetadata.Columns) {
2912
+ throw new Error("Individual SEG frames have different geometry dimensions (Rows and Columns) " + "respect to the source image reference frame. This is not yet supported. " + "Aborting segmentation loading. ");
2913
+ }
2914
+ var imageIdIndex = imageIds.findIndex(function (element) {
2915
+ return element === imageId;
2916
+ });
2917
+ var byteOffset = sliceLength * imageIdIndex * TypedArrayConstructor.BYTES_PER_ELEMENT;
2918
+ var labelmap2DView = new TypedArrayConstructor(tempBuffer, byteOffset, sliceLength);
2919
+ var data = alignedPixelDataI.data;
2920
+ var segmentOnFrame = false;
2921
+ for (var j = 0, len = alignedPixelDataI.data.length; j < len; ++j) {
2922
+ if (data[j]) {
2923
+ if (labelmap2DView[j] !== 0) {
2924
+ m++;
2925
+ if (m >= M) {
2926
+ labelmapBufferArray[m] = new ArrayBuffer(arrayBufferLength);
2927
+ segmentsOnFrameArray[m] = [];
2928
+ M++;
2929
+ }
2930
+ tempBuffer = labelmapBufferArray[m].slice(0);
2931
+ tempSegmentsOnFrame = structuredClone(segmentsOnFrameArray[m]);
2932
+ _i2 = 0;
2933
+ break;
2934
+ } else {
2935
+ labelmap2DView[j] = segmentIndex;
2936
+ segmentOnFrame = true;
2934
2937
  }
2935
- tempBuffer = labelmapBufferArray[m].slice(0);
2936
- tempSegmentsOnFrame = cloneDeep(segmentsOnFrameArray[m]);
2937
- _i2 = 0;
2938
- break;
2939
- } else {
2940
- labelmap2DView[j] = segmentIndex;
2941
- segmentOnFrame = true;
2942
2938
  }
2943
2939
  }
2944
- }
2945
- if (segmentOnFrame) {
2946
- if (!tempSegmentsOnFrame[imageIdIndex]) {
2947
- tempSegmentsOnFrame[imageIdIndex] = [];
2948
- }
2949
- tempSegmentsOnFrame[imageIdIndex].push(segmentIndex);
2950
- if (!segmentsOnFrame[imageIdIndex]) {
2951
- segmentsOnFrame[imageIdIndex] = [];
2940
+ if (segmentOnFrame) {
2941
+ if (!tempSegmentsOnFrame[imageIdIndex]) {
2942
+ tempSegmentsOnFrame[imageIdIndex] = [];
2943
+ }
2944
+ tempSegmentsOnFrame[imageIdIndex].push(segmentIndex);
2945
+ if (!segmentsOnFrame[imageIdIndex]) {
2946
+ segmentsOnFrame[imageIdIndex] = [];
2947
+ }
2948
+ segmentsOnFrame[imageIdIndex].push(segmentIndex);
2952
2949
  }
2953
- segmentsOnFrame[imageIdIndex].push(segmentIndex);
2954
- }
2955
- i = _i2;
2956
- };
2950
+ i = _i2;
2951
+ },
2952
+ _ret2;
2957
2953
  for (var i = 0, groupsLen = PerFrameFunctionalGroupsSequence.length; i < groupsLen; ++i) {
2958
- var _ret2 = _loop4(i);
2959
- if (_ret2 === "continue") continue;
2954
+ _ret2 = _loop4(i);
2955
+ if (_ret2 === 0) continue;
2960
2956
  }
2961
2957
  labelmapBufferArray[m] = tempBuffer.slice(0);
2962
- segmentsOnFrameArray[m] = cloneDeep(tempSegmentsOnFrame);
2958
+ segmentsOnFrameArray[m] = structuredClone(tempSegmentsOnFrame);
2963
2959
 
2964
2960
  // reset temp variables/buffers for new segment
2965
2961
  m = 0;
2966
2962
  tempBuffer = labelmapBufferArray[m].slice(0);
2967
- tempSegmentsOnFrame = cloneDeep(segmentsOnFrameArray[m]);
2963
+ tempSegmentsOnFrame = structuredClone(segmentsOnFrameArray[m]);
2968
2964
  }
2969
2965
  }
2970
2966
  var getSegmentIndex = function getSegmentIndex(multiframe, frame) {
@@ -2985,7 +2981,7 @@ function insertPixelDataPlanar(segmentsOnFrame, segmentsOnFrameArray, labelmapBu
2985
2981
  var chunkSize = Math.ceil(groupsLen / 10); // 10% of total length
2986
2982
 
2987
2983
  var shouldTriggerEvent = triggerEvent && eventTarget;
2988
-
2984
+ var overlapping = false;
2989
2985
  // Below, we chunk the processing of the frames to avoid blocking the main thread
2990
2986
  // if the segmentation is large. We also use a promise to allow the caller to
2991
2987
  // wait for the processing to finish.
@@ -3026,6 +3022,9 @@ function insertPixelDataPlanar(segmentsOnFrame, segmentsOnFrameArray, labelmapBu
3026
3022
  if (data[j]) {
3027
3023
  for (var x = j; x < len; ++x) {
3028
3024
  if (data[x]) {
3025
+ if (!overlapping && labelmap2DView[x] !== 0) {
3026
+ overlapping = true;
3027
+ }
3029
3028
  labelmap2DView[x] = segmentIndex;
3030
3029
  indexCache.push(x);
3031
3030
  }
@@ -3055,7 +3054,7 @@ function insertPixelDataPlanar(segmentsOnFrame, segmentsOnFrameArray, labelmapBu
3055
3054
  setTimeout(processInChunks, 0);
3056
3055
  } else {
3057
3056
  // resolve the Promise when all chunks have been processed
3058
- resolve();
3057
+ resolve(overlapping);
3059
3058
  }
3060
3059
  }
3061
3060
  processInChunks();
@@ -3526,6 +3525,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3526
3525
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3527
3526
  PERFORMANCE OF THIS SOFTWARE.
3528
3527
  ***************************************************************************** */
3528
+ /* global Reflect, Promise, SuppressedError, Symbol */
3529
+
3529
3530
  var __assign = function () {
3530
3531
  __assign = Object.assign || function __assign(t) {
3531
3532
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -3545,6 +3546,10 @@ function __spreadArray(to, from, pack) {
3545
3546
  }
3546
3547
  return to.concat(ar || Array.prototype.slice.call(from));
3547
3548
  }
3549
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
3550
+ var e = new Error(message);
3551
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3552
+ };
3548
3553
 
3549
3554
  var CORNERSTONE_3D_TAG = "Cornerstone3DTools@^0.1.0";
3550
3555
 
@@ -3566,7 +3571,7 @@ var TID1500 = utilities.TID1500, addAccessors = utilities.addAccessors;
3566
3571
  var StructuredReport = derivations.StructuredReport;
3567
3572
  var Normalizer$1 = normalizers.Normalizer;
3568
3573
  var TID1500MeasurementReport = TID1500.TID1500MeasurementReport, TID1501MeasurementGroup = TID1500.TID1501MeasurementGroup;
3569
- var DicomMetaDictionary = data.DicomMetaDictionary;
3574
+ var DicomMetaDictionary$1 = data.DicomMetaDictionary;
3570
3575
  var FINDING = { CodingSchemeDesignator: "DCM", CodeValue: "121071" };
3571
3576
  var FINDING_SITE = { CodingSchemeDesignator: "SCT", CodeValue: "363698007" };
3572
3577
  var FINDING_SITE_OLD = { CodingSchemeDesignator: "SRT", CodeValue: "G-C0E3" };
@@ -3635,7 +3640,7 @@ var MeasurementReport = /** @class */ (function () {
3635
3640
  vr: "UI"
3636
3641
  },
3637
3642
  ImplementationClassUID: {
3638
- Value: [DicomMetaDictionary.uid()],
3643
+ Value: [DicomMetaDictionary$1.uid()], // TODO: could be git hash or other valid id
3639
3644
  vr: "UI"
3640
3645
  },
3641
3646
  ImplementationVersionName: {
@@ -3670,7 +3675,7 @@ var MeasurementReport = /** @class */ (function () {
3670
3675
  description: undefined,
3671
3676
  sopInstanceUid: ReferencedSOPInstanceUID,
3672
3677
  annotation: {
3673
- annotationUID: DicomMetaDictionary.uid(),
3678
+ annotationUID: DicomMetaDictionary$1.uid(),
3674
3679
  metadata: {
3675
3680
  toolName: toolType,
3676
3681
  referencedImageId: referencedImageId,
@@ -3753,6 +3758,7 @@ var MeasurementReport = /** @class */ (function () {
3753
3758
  // Merge the derived dataset with the content from the Measurement Report
3754
3759
  report.dataset = Object.assign(report.dataset, contentItem);
3755
3760
  report.dataset._meta = _meta;
3761
+ report.SpecificCharacterSet = "ISO_IR 192";
3756
3762
  return report;
3757
3763
  };
3758
3764
  /**
@@ -3766,6 +3772,7 @@ var MeasurementReport = /** @class */ (function () {
3766
3772
  var REPORT = "Imaging Measurements";
3767
3773
  var GROUP = "Measurement Group";
3768
3774
  var TRACKING_IDENTIFIER = "Tracking Identifier";
3775
+ var TRACKING_UNIQUE_IDENTIFIER = "Tracking Unique Identifier";
3769
3776
  // Identify the Imaging Measurements
3770
3777
  var imagingMeasurementContent = toArray(dataset.ContentSequence).find(codeMeaningEquals(REPORT));
3771
3778
  // Retrieve the Measurements themselves
@@ -3787,12 +3794,19 @@ var MeasurementReport = /** @class */ (function () {
3787
3794
  TRACKING_IDENTIFIER;
3788
3795
  });
3789
3796
  var TrackingIdentifierValue_1 = TrackingIdentifierGroup.TextValue;
3797
+ var TrackingUniqueIdentifierGroup = measurementGroupContentSequence.find(function (contentItem) {
3798
+ return contentItem.ConceptNameCodeSequence.CodeMeaning ===
3799
+ TRACKING_UNIQUE_IDENTIFIER;
3800
+ });
3801
+ var TrackingUniqueIdentifierValue = TrackingUniqueIdentifierGroup === null || TrackingUniqueIdentifierGroup === void 0 ? void 0 : TrackingUniqueIdentifierGroup.UID;
3790
3802
  var toolClass = ((_a = hooks === null || hooks === void 0 ? void 0 : hooks.getToolClass) === null || _a === void 0 ? void 0 : _a.call(hooks, measurementGroup, dataset, registeredToolClasses)) ||
3791
3803
  registeredToolClasses.find(function (tc) {
3792
3804
  return tc.isValidCornerstoneTrackingIdentifier(TrackingIdentifierValue_1);
3793
3805
  });
3794
3806
  if (toolClass) {
3795
3807
  var measurement = toolClass.getMeasurementData(measurementGroup, sopInstanceUIDToImageIdMap, imageToWorldCoords, metadata);
3808
+ measurement.TrackingUniqueIdentifier =
3809
+ TrackingUniqueIdentifierValue;
3796
3810
  console.log("=== ".concat(toolClass.toolType, " ==="));
3797
3811
  console.log(measurement);
3798
3812
  measurementData[toolClass.toolType].push(measurement);
@@ -3833,14 +3847,14 @@ var MeasurementReport = /** @class */ (function () {
3833
3847
 
3834
3848
  var TID300Point$1 = utilities.TID300.Point;
3835
3849
  var ARROW_ANNOTATE = "ArrowAnnotate";
3836
- var trackingIdentifierTextValue$7 = "".concat(CORNERSTONE_3D_TAG, ":").concat(ARROW_ANNOTATE);
3850
+ var trackingIdentifierTextValue$8 = "".concat(CORNERSTONE_3D_TAG, ":").concat(ARROW_ANNOTATE);
3837
3851
  var codeValues = CodingScheme.codeValues,
3838
3852
  CodingSchemeDesignator = CodingScheme.CodingSchemeDesignator;
3839
3853
  var ArrowAnnotate = /*#__PURE__*/function () {
3840
3854
  function ArrowAnnotate() {
3841
3855
  _classCallCheck(this, ArrowAnnotate);
3842
3856
  }
3843
- _createClass(ArrowAnnotate, null, [{
3857
+ return _createClass(ArrowAnnotate, null, [{
3844
3858
  key: "getMeasurementData",
3845
3859
  value: function getMeasurementData(MeasurementGroup, sopInstanceUIDToImageIdMap, imageToWorldCoords, metadata) {
3846
3860
  var _MeasurementReport$ge = MeasurementReport.getSetupMeasurementData(MeasurementGroup, sopInstanceUIDToImageIdMap, metadata, ArrowAnnotate.toolType),
@@ -3912,7 +3926,7 @@ var ArrowAnnotate = /*#__PURE__*/function () {
3912
3926
  x: pointImage[0],
3913
3927
  y: pointImage[1]
3914
3928
  }],
3915
- trackingIdentifierTextValue: trackingIdentifierTextValue$7,
3929
+ trackingIdentifierTextValue: trackingIdentifierTextValue$8,
3916
3930
  findingSites: findingSites || []
3917
3931
  };
3918
3932
 
@@ -3928,7 +3942,6 @@ var ArrowAnnotate = /*#__PURE__*/function () {
3928
3942
  return TID300RepresentationArguments;
3929
3943
  }
3930
3944
  }]);
3931
- return ArrowAnnotate;
3932
3945
  }();
3933
3946
  ArrowAnnotate.toolType = ARROW_ANNOTATE;
3934
3947
  ArrowAnnotate.utilityToolType = ARROW_ANNOTATE;
@@ -3952,7 +3965,7 @@ var TID300Bidirectional = utilities.TID300.Bidirectional;
3952
3965
  var BIDIRECTIONAL = "Bidirectional";
3953
3966
  var LONG_AXIS = "Long Axis";
3954
3967
  var SHORT_AXIS = "Short Axis";
3955
- var trackingIdentifierTextValue$6 = "".concat(CORNERSTONE_3D_TAG, ":").concat(BIDIRECTIONAL);
3968
+ var trackingIdentifierTextValue$7 = "".concat(CORNERSTONE_3D_TAG, ":").concat(BIDIRECTIONAL);
3956
3969
  var Bidirectional = /** @class */ (function () {
3957
3970
  function Bidirectional() {
3958
3971
  }
@@ -4055,7 +4068,7 @@ var Bidirectional = /** @class */ (function () {
4055
4068
  },
4056
4069
  longAxisLength: length,
4057
4070
  shortAxisLength: width,
4058
- trackingIdentifierTextValue: trackingIdentifierTextValue$6,
4071
+ trackingIdentifierTextValue: trackingIdentifierTextValue$7,
4059
4072
  finding: finding,
4060
4073
  findingSites: findingSites || []
4061
4074
  };
@@ -4079,7 +4092,7 @@ MeasurementReport.registerTool(Bidirectional);
4079
4092
 
4080
4093
  var TID300CobbAngle$1 = utilities.TID300.CobbAngle;
4081
4094
  var MEASUREMENT_TYPE$1 = "Angle";
4082
- var trackingIdentifierTextValue$5 = "".concat(CORNERSTONE_3D_TAG, ":").concat(MEASUREMENT_TYPE$1);
4095
+ var trackingIdentifierTextValue$6 = "".concat(CORNERSTONE_3D_TAG, ":").concat(MEASUREMENT_TYPE$1);
4083
4096
  var Angle = /** @class */ (function () {
4084
4097
  function Angle() {
4085
4098
  }
@@ -4139,7 +4152,7 @@ var Angle = /** @class */ (function () {
4139
4152
  point3: point3,
4140
4153
  point4: point4,
4141
4154
  rAngle: angle,
4142
- trackingIdentifierTextValue: trackingIdentifierTextValue$5,
4155
+ trackingIdentifierTextValue: trackingIdentifierTextValue$6,
4143
4156
  finding: finding,
4144
4157
  findingSites: findingSites || []
4145
4158
  };
@@ -4163,7 +4176,7 @@ MeasurementReport.registerTool(Angle);
4163
4176
 
4164
4177
  var TID300CobbAngle = utilities.TID300.CobbAngle;
4165
4178
  var MEASUREMENT_TYPE = "CobbAngle";
4166
- var trackingIdentifierTextValue$4 = "".concat(CORNERSTONE_3D_TAG, ":").concat(MEASUREMENT_TYPE);
4179
+ var trackingIdentifierTextValue$5 = "".concat(CORNERSTONE_3D_TAG, ":").concat(MEASUREMENT_TYPE);
4167
4180
  var CobbAngle = /** @class */ (function () {
4168
4181
  function CobbAngle() {
4169
4182
  }
@@ -4228,7 +4241,7 @@ var CobbAngle = /** @class */ (function () {
4228
4241
  point3: point3,
4229
4242
  point4: point4,
4230
4243
  rAngle: angle,
4231
- trackingIdentifierTextValue: trackingIdentifierTextValue$4,
4244
+ trackingIdentifierTextValue: trackingIdentifierTextValue$5,
4232
4245
  finding: finding,
4233
4246
  findingSites: findingSites || []
4234
4247
  };
@@ -4492,7 +4505,7 @@ MeasurementReport.registerTool(EllipticalROI);
4492
4505
 
4493
4506
  var TID300Polyline$1 = utilities.TID300.Polyline;
4494
4507
  var TOOLTYPE = "RectangleROI";
4495
- var trackingIdentifierTextValue$3 = "".concat(CORNERSTONE_3D_TAG, ":").concat(TOOLTYPE);
4508
+ var trackingIdentifierTextValue$4 = "".concat(CORNERSTONE_3D_TAG, ":").concat(TOOLTYPE);
4496
4509
  var RectangleROI = /** @class */ (function () {
4497
4510
  function RectangleROI() {
4498
4511
  }
@@ -4555,7 +4568,7 @@ var RectangleROI = /** @class */ (function () {
4555
4568
  ],
4556
4569
  area: area,
4557
4570
  perimeter: perimeter,
4558
- trackingIdentifierTextValue: trackingIdentifierTextValue$3,
4571
+ trackingIdentifierTextValue: trackingIdentifierTextValue$4,
4559
4572
  finding: finding,
4560
4573
  findingSites: findingSites || []
4561
4574
  };
@@ -4577,14 +4590,14 @@ var RectangleROI = /** @class */ (function () {
4577
4590
  }());
4578
4591
  MeasurementReport.registerTool(RectangleROI);
4579
4592
 
4580
- var TID300Length = utilities.TID300.Length;
4593
+ var TID300Length$1 = utilities.TID300.Length;
4581
4594
  var LENGTH = "Length";
4582
- var trackingIdentifierTextValue$2 = "".concat(CORNERSTONE_3D_TAG, ":").concat(LENGTH);
4595
+ var trackingIdentifierTextValue$3 = "".concat(CORNERSTONE_3D_TAG, ":").concat(LENGTH);
4583
4596
  var Length = /*#__PURE__*/function () {
4584
4597
  function Length() {
4585
4598
  _classCallCheck(this, Length);
4586
4599
  }
4587
- _createClass(Length, null, [{
4600
+ return _createClass(Length, null, [{
4588
4601
  key: "getMeasurementData",
4589
4602
  value:
4590
4603
  // TODO: this function is required for all Cornerstone Tool Adapters, since it is called by MeasurementReport.
@@ -4647,17 +4660,16 @@ var Length = /*#__PURE__*/function () {
4647
4660
  point1: point1,
4648
4661
  point2: point2,
4649
4662
  distance: distance,
4650
- trackingIdentifierTextValue: trackingIdentifierTextValue$2,
4663
+ trackingIdentifierTextValue: trackingIdentifierTextValue$3,
4651
4664
  finding: finding,
4652
4665
  findingSites: findingSites || []
4653
4666
  };
4654
4667
  }
4655
4668
  }]);
4656
- return Length;
4657
4669
  }();
4658
4670
  Length.toolType = LENGTH;
4659
4671
  Length.utilityToolType = LENGTH;
4660
- Length.TID300Representation = TID300Length;
4672
+ Length.TID300Representation = TID300Length$1;
4661
4673
  Length.isValidCornerstoneTrackingIdentifier = function (TrackingIdentifier) {
4662
4674
  if (!TrackingIdentifier.includes(":")) {
4663
4675
  return false;
@@ -4675,13 +4687,14 @@ MeasurementReport.registerTool(Length);
4675
4687
 
4676
4688
  var TID300Polyline = utilities.TID300.Polyline;
4677
4689
  var PLANARFREEHANDROI = "PlanarFreehandROI";
4678
- var trackingIdentifierTextValue$1 = "".concat(CORNERSTONE_3D_TAG, ":").concat(PLANARFREEHANDROI);
4690
+ var trackingIdentifierTextValue$2 = "".concat(CORNERSTONE_3D_TAG, ":").concat(PLANARFREEHANDROI);
4679
4691
  var closedContourThreshold = 1e-5;
4680
4692
  var PlanarFreehandROI = /** @class */ (function () {
4681
4693
  function PlanarFreehandROI() {
4682
4694
  }
4683
4695
  PlanarFreehandROI.getMeasurementData = function (MeasurementGroup, sopInstanceUIDToImageIdMap, imageToWorldCoords, metadata) {
4684
- var _a = MeasurementReport.getSetupMeasurementData(MeasurementGroup, sopInstanceUIDToImageIdMap, metadata, PlanarFreehandROI.toolType), defaultState = _a.defaultState, SCOORDGroup = _a.SCOORDGroup, ReferencedFrameNumber = _a.ReferencedFrameNumber;
4696
+ var _a;
4697
+ var _b = MeasurementReport.getSetupMeasurementData(MeasurementGroup, sopInstanceUIDToImageIdMap, metadata, PlanarFreehandROI.toolType), defaultState = _b.defaultState, NUMGroup = _b.NUMGroup, SCOORDGroup = _b.SCOORDGroup, ReferencedFrameNumber = _b.ReferencedFrameNumber;
4685
4698
  var referencedImageId = defaultState.annotation.metadata.referencedImageId;
4686
4699
  var GraphicData = SCOORDGroup.GraphicData;
4687
4700
  var worldCoords = [];
@@ -4705,8 +4718,7 @@ var PlanarFreehandROI = /** @class */ (function () {
4705
4718
  }
4706
4719
  var state = defaultState;
4707
4720
  state.annotation.data = {
4708
- polyline: worldCoords,
4709
- isOpenContour: isOpenContour,
4721
+ contour: { polyline: worldCoords, closed: !isOpenContour },
4710
4722
  handles: {
4711
4723
  points: points,
4712
4724
  activeHandleIndex: null,
@@ -4714,13 +4726,21 @@ var PlanarFreehandROI = /** @class */ (function () {
4714
4726
  hasMoved: false
4715
4727
  }
4716
4728
  },
4729
+ cachedStats: (_a = {},
4730
+ _a["imageId:".concat(referencedImageId)] = {
4731
+ area: NUMGroup
4732
+ ? NUMGroup.MeasuredValueSequence.NumericValue
4733
+ : null
4734
+ },
4735
+ _a),
4717
4736
  frameNumber: ReferencedFrameNumber
4718
4737
  };
4719
4738
  return state;
4720
4739
  };
4721
4740
  PlanarFreehandROI.getTID300RepresentationArguments = function (tool, worldToImageCoords) {
4722
4741
  var data = tool.data, finding = tool.finding, findingSites = tool.findingSites, metadata = tool.metadata;
4723
- var isOpenContour = data.isOpenContour, polyline = data.polyline;
4742
+ var _a = data.contour, polyline = _a.polyline, closed = _a.closed;
4743
+ var isOpenContour = closed !== true;
4724
4744
  var referencedImageId = metadata.referencedImageId;
4725
4745
  if (!referencedImageId) {
4726
4746
  throw new Error("PlanarFreehandROI.getTID300RepresentationArguments: referencedImageId is not defined");
@@ -4734,13 +4754,19 @@ var PlanarFreehandROI = /** @class */ (function () {
4734
4754
  // Explicitly expand to avoid ciruclar references.
4735
4755
  points.push([firstPoint[0], firstPoint[1]]);
4736
4756
  }
4737
- var area = 0; // TODO -> The tool doesn't have these stats yet.
4738
- var perimeter = 0;
4757
+ var _b = data.cachedStats["imageId:".concat(referencedImageId)] || {}, area = _b.area, areaUnit = _b.areaUnit, modalityUnit = _b.modalityUnit, perimeter = _b.perimeter, mean = _b.mean, max = _b.max, stdDev = _b.stdDev;
4739
4758
  return {
4759
+ /** From cachedStats */
4740
4760
  points: points,
4741
4761
  area: area,
4762
+ areaUnit: areaUnit,
4742
4763
  perimeter: perimeter,
4743
- trackingIdentifierTextValue: trackingIdentifierTextValue$1,
4764
+ modalityUnit: modalityUnit,
4765
+ mean: mean,
4766
+ max: max,
4767
+ stdDev: stdDev,
4768
+ /** Other */
4769
+ trackingIdentifierTextValue: trackingIdentifierTextValue$2,
4744
4770
  finding: finding,
4745
4771
  findingSites: findingSites || []
4746
4772
  };
@@ -4764,12 +4790,12 @@ MeasurementReport.registerTool(PlanarFreehandROI);
4764
4790
 
4765
4791
  var TID300Point = utilities.TID300.Point;
4766
4792
  var PROBE = "Probe";
4767
- var trackingIdentifierTextValue = "".concat(CORNERSTONE_3D_TAG, ":").concat(PROBE);
4793
+ var trackingIdentifierTextValue$1 = "".concat(CORNERSTONE_3D_TAG, ":").concat(PROBE);
4768
4794
  var Probe = /*#__PURE__*/function () {
4769
4795
  function Probe() {
4770
4796
  _classCallCheck(this, Probe);
4771
4797
  }
4772
- _createClass(Probe, null, [{
4798
+ return _createClass(Probe, null, [{
4773
4799
  key: "getMeasurementData",
4774
4800
  value: function getMeasurementData(MeasurementGroup, sopInstanceUIDToImageIdMap, imageToWorldCoords, metadata) {
4775
4801
  var _MeasurementReport$ge = MeasurementReport.getSetupMeasurementData(MeasurementGroup, sopInstanceUIDToImageIdMap, metadata, Probe.toolType),
@@ -4817,14 +4843,13 @@ var Probe = /*#__PURE__*/function () {
4817
4843
  });
4818
4844
  var TID300RepresentationArguments = {
4819
4845
  points: pointsImage,
4820
- trackingIdentifierTextValue: trackingIdentifierTextValue,
4846
+ trackingIdentifierTextValue: trackingIdentifierTextValue$1,
4821
4847
  findingSites: findingSites || [],
4822
4848
  finding: finding
4823
4849
  };
4824
4850
  return TID300RepresentationArguments;
4825
4851
  }
4826
4852
  }]);
4827
- return Probe;
4828
4853
  }();
4829
4854
  Probe.toolType = PROBE;
4830
4855
  Probe.utilityToolType = PROBE;
@@ -4844,6 +4869,75 @@ Probe.isValidCornerstoneTrackingIdentifier = function (TrackingIdentifier) {
4844
4869
  };
4845
4870
  MeasurementReport.registerTool(Probe);
4846
4871
 
4872
+ var TID300Length = utilities.TID300.Length;
4873
+ var ULTRASOUND_DIRECTIONAL = "UltrasoundDirectionalTool";
4874
+ var trackingIdentifierTextValue = "".concat(CORNERSTONE_3D_TAG, ":").concat(ULTRASOUND_DIRECTIONAL);
4875
+ var UltrasoundDirectional = /** @class */ (function () {
4876
+ function UltrasoundDirectional() {
4877
+ }
4878
+ // TODO: this function is required for all Cornerstone Tool Adapters, since it is called by MeasurementReport.
4879
+ UltrasoundDirectional.getMeasurementData = function (MeasurementGroup, sopInstanceUIDToImageIdMap, imageToWorldCoords, metadata) {
4880
+ var _a = MeasurementReport.getSetupMeasurementData(MeasurementGroup, sopInstanceUIDToImageIdMap, metadata, UltrasoundDirectional.toolType), defaultState = _a.defaultState, SCOORDGroup = _a.SCOORDGroup, ReferencedFrameNumber = _a.ReferencedFrameNumber;
4881
+ var referencedImageId = defaultState.annotation.metadata.referencedImageId;
4882
+ var GraphicData = SCOORDGroup.GraphicData;
4883
+ var worldCoords = [];
4884
+ for (var i = 0; i < GraphicData.length; i += 2) {
4885
+ var point = imageToWorldCoords(referencedImageId, [
4886
+ GraphicData[i],
4887
+ GraphicData[i + 1]
4888
+ ]);
4889
+ worldCoords.push(point);
4890
+ }
4891
+ var state = defaultState;
4892
+ state.annotation.data = {
4893
+ handles: {
4894
+ points: [worldCoords[0], worldCoords[1]],
4895
+ activeHandleIndex: 0,
4896
+ textBox: {
4897
+ hasMoved: false
4898
+ }
4899
+ },
4900
+ cachedStats: {},
4901
+ frameNumber: ReferencedFrameNumber
4902
+ };
4903
+ return state;
4904
+ };
4905
+ UltrasoundDirectional.getTID300RepresentationArguments = function (tool, worldToImageCoords) {
4906
+ var data = tool.data, finding = tool.finding, findingSites = tool.findingSites, metadata = tool.metadata;
4907
+ var handles = data.handles;
4908
+ var referencedImageId = metadata.referencedImageId;
4909
+ if (!referencedImageId) {
4910
+ throw new Error("UltrasoundDirectionalTool.getTID300RepresentationArguments: referencedImageId is not defined");
4911
+ }
4912
+ var start = worldToImageCoords(referencedImageId, handles.points[0]);
4913
+ var end = worldToImageCoords(referencedImageId, handles.points[1]);
4914
+ var point1 = { x: start[0], y: start[1] };
4915
+ var point2 = { x: end[0], y: end[1] };
4916
+ return {
4917
+ point1: point1,
4918
+ point2: point2,
4919
+ trackingIdentifierTextValue: trackingIdentifierTextValue,
4920
+ finding: finding,
4921
+ findingSites: findingSites || []
4922
+ };
4923
+ };
4924
+ UltrasoundDirectional.toolType = ULTRASOUND_DIRECTIONAL;
4925
+ UltrasoundDirectional.utilityToolType = ULTRASOUND_DIRECTIONAL;
4926
+ UltrasoundDirectional.TID300Representation = TID300Length;
4927
+ UltrasoundDirectional.isValidCornerstoneTrackingIdentifier = function (TrackingIdentifier) {
4928
+ if (!TrackingIdentifier.includes(":")) {
4929
+ return false;
4930
+ }
4931
+ var _a = TrackingIdentifier.split(":"), cornerstone3DTag = _a[0], toolType = _a[1];
4932
+ if (cornerstone3DTag !== CORNERSTONE_3D_TAG) {
4933
+ return false;
4934
+ }
4935
+ return toolType === ULTRASOUND_DIRECTIONAL;
4936
+ };
4937
+ return UltrasoundDirectional;
4938
+ }());
4939
+ MeasurementReport.registerTool(UltrasoundDirectional);
4940
+
4847
4941
  var Normalizer = normalizers.Normalizer;
4848
4942
  var SegmentationDerivation = derivations.Segmentation;
4849
4943
  /**
@@ -4853,6 +4947,7 @@ var SegmentationDerivation = derivations.Segmentation;
4853
4947
  * @param labelmaps - An array of the 3D Volumes that contain the segmentation data.
4854
4948
  */
4855
4949
  function generateSegmentation(images, labelmaps, metadata, options) {
4950
+ if (options === void 0) { options = {}; }
4856
4951
  var segmentation = _createMultiframeSegmentationFromReferencedImages(images, metadata, options);
4857
4952
  return fillSegmentation$1(segmentation, labelmaps, options);
4858
4953
  }
@@ -4872,7 +4967,7 @@ function _createMultiframeSegmentationFromReferencedImages(images, metadata, opt
4872
4967
  var instance = metadata.get("instance", image.imageId);
4873
4968
  return __assign(__assign(__assign({}, image), instance), {
4874
4969
  // Todo: move to dcmjs tag style
4875
- SOPClassUID: instance.SopClassUID, SOPInstanceUID: instance.SopInstanceUID, PixelData: image.getPixelData(), _vrMap: {
4970
+ SOPClassUID: instance.SopClassUID || instance.SOPClassUID, SOPInstanceUID: instance.SopInstanceUID || instance.SOPInstanceUID, PixelData: image.getPixelData(), _vrMap: {
4876
4971
  PixelData: "OW"
4877
4972
  }, _meta: {} });
4878
4973
  });
@@ -4952,6 +5047,318 @@ var Segmentation$1 = /*#__PURE__*/Object.freeze({
4952
5047
  generateToolState: generateToolState
4953
5048
  });
4954
5049
 
5050
+ function getPatientModule(imageId, metadataProvider) {
5051
+ var generalSeriesModule = metadataProvider.get("generalSeriesModule", imageId);
5052
+ var generalStudyModule = metadataProvider.get("generalStudyModule", imageId);
5053
+ var patientStudyModule = metadataProvider.get("patientStudyModule", imageId);
5054
+ var patientModule = metadataProvider.get("patientModule", imageId);
5055
+ var patientDemographicModule = metadataProvider.get("patientDemographicModule", imageId);
5056
+ return {
5057
+ Modality: generalSeriesModule.modality,
5058
+ PatientID: patientModule.patientId,
5059
+ PatientName: patientModule.patientName,
5060
+ PatientBirthDate: "",
5061
+ PatientAge: patientStudyModule.patientAge,
5062
+ PatientSex: patientDemographicModule.patientSex,
5063
+ PatientWeight: patientStudyModule.patientWeight,
5064
+ StudyDate: generalStudyModule.studyDate,
5065
+ StudyTime: generalStudyModule.studyTime,
5066
+ StudyID: "ToDo",
5067
+ AccessionNumber: generalStudyModule.accessionNumber
5068
+ };
5069
+ }
5070
+
5071
+ function getReferencedFrameOfReferenceSequence(metadata, metadataProvider, dataset) {
5072
+ var imageId = metadata.referencedImageId,
5073
+ FrameOfReferenceUID = metadata.FrameOfReferenceUID;
5074
+ var instance = metadataProvider.get("instance", imageId);
5075
+ var SeriesInstanceUID = instance.SeriesInstanceUID;
5076
+ var ReferencedSeriesSequence = dataset.ReferencedSeriesSequence;
5077
+ return [{
5078
+ FrameOfReferenceUID: FrameOfReferenceUID,
5079
+ RTReferencedStudySequence: [{
5080
+ ReferencedSOPClassUID: dataset.SOPClassUID,
5081
+ ReferencedSOPInstanceUID: dataset.SOPInstanceUID,
5082
+ RTReferencedSeriesSequence: [{
5083
+ SeriesInstanceUID: SeriesInstanceUID,
5084
+ ContourImageSequence: _toConsumableArray(ReferencedSeriesSequence[0].ReferencedInstanceSequence)
5085
+ }]
5086
+ }]
5087
+ }];
5088
+ }
5089
+
5090
+ function getReferencedSeriesSequence(metadata, _index, metadataProvider, DicomMetadataStore) {
5091
+ // grab imageId from toolData
5092
+ var imageId = metadata.referencedImageId;
5093
+ var instance = metadataProvider.get("instance", imageId);
5094
+ var SeriesInstanceUID = instance.SeriesInstanceUID,
5095
+ StudyInstanceUID = instance.StudyInstanceUID;
5096
+ var ReferencedSeriesSequence = [];
5097
+ if (SeriesInstanceUID) {
5098
+ var series = DicomMetadataStore.getSeries(StudyInstanceUID, SeriesInstanceUID);
5099
+ var ReferencedSeries = {
5100
+ SeriesInstanceUID: SeriesInstanceUID,
5101
+ ReferencedInstanceSequence: []
5102
+ };
5103
+ series.instances.forEach(function (instance) {
5104
+ var SOPInstanceUID = instance.SOPInstanceUID,
5105
+ SOPClassUID = instance.SOPClassUID;
5106
+ ReferencedSeries.ReferencedInstanceSequence.push({
5107
+ ReferencedSOPClassUID: SOPClassUID,
5108
+ ReferencedSOPInstanceUID: SOPInstanceUID
5109
+ });
5110
+ });
5111
+ ReferencedSeriesSequence.push(ReferencedSeries);
5112
+ }
5113
+ return ReferencedSeriesSequence;
5114
+ }
5115
+
5116
+ function getRTROIObservationsSequence(toolData, index) {
5117
+ return {
5118
+ ObservationNumber: index + 1,
5119
+ ReferencedROINumber: index + 1,
5120
+ RTROIInterpretedType: "Todo: type",
5121
+ ROIInterpreter: "Todo: interpreter"
5122
+ };
5123
+ }
5124
+
5125
+ function getRTSeriesModule(DicomMetaDictionary) {
5126
+ return {
5127
+ SeriesInstanceUID: DicomMetaDictionary.uid(),
5128
+ // generate a new series instance uid
5129
+ SeriesNumber: "99" // Todo:: what should be the series number?
5130
+ };
5131
+ }
5132
+
5133
+ function getStructureSetModule(contour, index) {
5134
+ var FrameOfReferenceUID = contour.metadata.FrameOfReferenceUID;
5135
+ return {
5136
+ ROINumber: index + 1,
5137
+ ROIName: contour.name || "Todo: name ".concat(index + 1),
5138
+ ROIDescription: "Todo: description ".concat(index + 1),
5139
+ ROIGenerationAlgorithm: "Todo: algorithm",
5140
+ ReferencedFrameOfReferenceUID: FrameOfReferenceUID
5141
+ };
5142
+ }
5143
+
5144
+ var _a = utilities$1.contours, generateContourSetsFromLabelmap$1 = _a.generateContourSetsFromLabelmap, AnnotationToPointData = _a.AnnotationToPointData;
5145
+ var DicomMetaDictionary = dcmjs.data.DicomMetaDictionary;
5146
+ /**
5147
+ * Convert handles to RTSS report containing the dcmjs dicom dataset.
5148
+ *
5149
+ * Note: current WIP and using segmentation to contour conversion,
5150
+ * routine that is not fully tested
5151
+ *
5152
+ * @param segmentations - Cornerstone tool segmentations data
5153
+ * @param metadataProvider - Metadata provider
5154
+ * @param DicomMetadataStore - metadata store instance
5155
+ * @param cs - cornerstone instance
5156
+ * @param csTools - cornerstone tool instance
5157
+ * @returns Report object containing the dataset
5158
+ */
5159
+ function generateRTSSFromSegmentations(segmentations, metadataProvider, DicomMetadataStore) {
5160
+ // Convert segmentations to ROIContours
5161
+ var roiContours = [];
5162
+ var contourSets = generateContourSetsFromLabelmap$1({
5163
+ segmentations: segmentations
5164
+ });
5165
+ contourSets.forEach(function (contourSet, segIndex) {
5166
+ // Check contour set isn't undefined
5167
+ if (contourSet) {
5168
+ var contourSequence_1 = [];
5169
+ contourSet.sliceContours.forEach(function (sliceContour) {
5170
+ /**
5171
+ * addContour - Adds a new ROI with related contours to ROIContourSequence
5172
+ *
5173
+ * @param newContour - cornerstoneTools `ROIContour` object
5174
+ *
5175
+ * newContour = {
5176
+ * name: string,
5177
+ * description: string,
5178
+ * contourSequence: array[contour]
5179
+ * color: array[number],
5180
+ * metadata: {
5181
+ * referencedImageId: string,
5182
+ * FrameOfReferenceUID: string
5183
+ * }
5184
+ * }
5185
+ *
5186
+ * contour = {
5187
+ * ContourImageSequence: array[
5188
+ * { ReferencedSOPClassUID: string, ReferencedSOPInstanceUID: string}
5189
+ * ]
5190
+ * ContourGeometricType: string,
5191
+ * NumberOfContourPoints: number,
5192
+ * ContourData: array[number]
5193
+ * }
5194
+ */
5195
+ // Note: change needed if support non-planar contour representation is needed
5196
+ var sopCommon = metadataProvider.get("sopCommonModule", sliceContour.referencedImageId);
5197
+ var ReferencedSOPClassUID = sopCommon.sopClassUID;
5198
+ var ReferencedSOPInstanceUID = sopCommon.sopInstanceUID;
5199
+ var ContourImageSequence = [
5200
+ { ReferencedSOPClassUID: ReferencedSOPClassUID, ReferencedSOPInstanceUID: ReferencedSOPInstanceUID } // NOTE: replace in dcmjs?
5201
+ ];
5202
+ var sliceContourPolyData = sliceContour.polyData;
5203
+ sliceContour.contours.forEach(function (contour, index) {
5204
+ var ContourGeometricType = contour.type;
5205
+ var NumberOfContourPoints = contour.contourPoints.length;
5206
+ var ContourData = [];
5207
+ contour.contourPoints.forEach(function (point) {
5208
+ var pointData = sliceContourPolyData.points[point];
5209
+ pointData[0] = +pointData[0].toFixed(2);
5210
+ pointData[1] = +pointData[1].toFixed(2);
5211
+ pointData[2] = +pointData[2].toFixed(2);
5212
+ ContourData.push(pointData[0]);
5213
+ ContourData.push(pointData[1]);
5214
+ ContourData.push(pointData[2]);
5215
+ });
5216
+ contourSequence_1.push({
5217
+ ContourImageSequence: ContourImageSequence,
5218
+ ContourGeometricType: ContourGeometricType,
5219
+ NumberOfContourPoints: NumberOfContourPoints,
5220
+ ContourNumber: index + 1,
5221
+ ContourData: ContourData
5222
+ });
5223
+ });
5224
+ });
5225
+ var segLabel = contourSet.label || "Segment ".concat(segIndex + 1);
5226
+ var ROIContour = {
5227
+ name: segLabel,
5228
+ description: segLabel,
5229
+ contourSequence: contourSequence_1,
5230
+ color: contourSet.color,
5231
+ metadata: contourSet.metadata
5232
+ };
5233
+ roiContours.push(ROIContour);
5234
+ }
5235
+ });
5236
+ var rtMetadata = {
5237
+ name: segmentations.label,
5238
+ label: segmentations.label
5239
+ };
5240
+ var dataset = _initializeDataset(rtMetadata, roiContours[0].metadata, metadataProvider);
5241
+ roiContours.forEach(function (contour, index) {
5242
+ var roiContour = {
5243
+ ROIDisplayColor: contour.color || [255, 0, 0],
5244
+ ContourSequence: contour.contourSequence,
5245
+ ReferencedROINumber: index + 1
5246
+ };
5247
+ dataset.StructureSetROISequence.push(getStructureSetModule(contour, index));
5248
+ dataset.ROIContourSequence.push(roiContour);
5249
+ // ReferencedSeriesSequence
5250
+ dataset.ReferencedSeriesSequence = getReferencedSeriesSequence(contour.metadata, index, metadataProvider, DicomMetadataStore);
5251
+ // ReferencedFrameOfReferenceSequence
5252
+ dataset.ReferencedFrameOfReferenceSequence =
5253
+ getReferencedFrameOfReferenceSequence(contour.metadata, metadataProvider, dataset);
5254
+ });
5255
+ var fileMetaInformationVersionArray = new Uint8Array(2);
5256
+ fileMetaInformationVersionArray[1] = 1;
5257
+ var _meta = {
5258
+ FileMetaInformationVersion: {
5259
+ Value: [fileMetaInformationVersionArray.buffer],
5260
+ vr: "OB"
5261
+ },
5262
+ TransferSyntaxUID: {
5263
+ Value: ["1.2.840.10008.1.2.1"],
5264
+ vr: "UI"
5265
+ },
5266
+ ImplementationClassUID: {
5267
+ Value: [DicomMetaDictionary.uid()], // TODO: could be git hash or other valid id
5268
+ vr: "UI"
5269
+ },
5270
+ ImplementationVersionName: {
5271
+ Value: ["dcmjs"],
5272
+ vr: "SH"
5273
+ }
5274
+ };
5275
+ dataset._meta = _meta;
5276
+ dataset.SpecificCharacterSet = "ISO_IR 192";
5277
+ return dataset;
5278
+ }
5279
+ /**
5280
+ * Convert handles to RTSSReport report object containing the dcmjs dicom dataset.
5281
+ *
5282
+ * Note: The tool data needs to be formatted in a specific way, and currently
5283
+ * it is limited to the RectangleROIStartEndTool in the Cornerstone.
5284
+ *
5285
+ * @param annotations - Array of Cornerstone tool annotation data
5286
+ * @param metadataProvider - Metadata provider
5287
+ * @returns Report object containing the dataset
5288
+ */
5289
+ function generateRTSSFromAnnotations(annotations, metadataProvider, DicomMetadataStore) {
5290
+ var rtMetadata = {
5291
+ name: "RTSS from Annotations",
5292
+ label: "RTSS from Annotations"
5293
+ };
5294
+ var dataset = _initializeDataset(rtMetadata, annotations[0].metadata, metadataProvider);
5295
+ annotations.forEach(function (annotation, index) {
5296
+ var ContourSequence = AnnotationToPointData.convert(annotation, index, metadataProvider);
5297
+ dataset.StructureSetROISequence.push(getStructureSetModule(annotation, index));
5298
+ dataset.ROIContourSequence.push(ContourSequence);
5299
+ dataset.RTROIObservationsSequence.push(getRTROIObservationsSequence(annotation, index));
5300
+ // ReferencedSeriesSequence
5301
+ // Todo: handle more than one series
5302
+ dataset.ReferencedSeriesSequence = getReferencedSeriesSequence(annotation.metadata, index, metadataProvider, DicomMetadataStore);
5303
+ // ReferencedFrameOfReferenceSequence
5304
+ dataset.ReferencedFrameOfReferenceSequence =
5305
+ getReferencedFrameOfReferenceSequence(annotation.metadata, metadataProvider, dataset);
5306
+ });
5307
+ var fileMetaInformationVersionArray = new Uint8Array(2);
5308
+ fileMetaInformationVersionArray[1] = 1;
5309
+ var _meta = {
5310
+ FileMetaInformationVersion: {
5311
+ Value: [fileMetaInformationVersionArray.buffer],
5312
+ vr: "OB"
5313
+ },
5314
+ TransferSyntaxUID: {
5315
+ Value: ["1.2.840.10008.1.2.1"],
5316
+ vr: "UI"
5317
+ },
5318
+ ImplementationClassUID: {
5319
+ Value: [DicomMetaDictionary.uid()], // TODO: could be git hash or other valid id
5320
+ vr: "UI"
5321
+ },
5322
+ ImplementationVersionName: {
5323
+ Value: ["dcmjs"],
5324
+ vr: "SH"
5325
+ }
5326
+ };
5327
+ dataset._meta = _meta;
5328
+ dataset.SpecificCharacterSet = "ISO_IR 192";
5329
+ return dataset;
5330
+ }
5331
+ // /**
5332
+ // * Generate Cornerstone tool state from dataset
5333
+ // * @param {object} dataset dataset
5334
+ // * @param {object} hooks
5335
+ // * @param {function} hooks.getToolClass Function to map dataset to a tool class
5336
+ // * @returns
5337
+ // */
5338
+ // //static generateToolState(_dataset, _hooks = {}) {
5339
+ // function generateToolState() {
5340
+ // // Todo
5341
+ // console.warn("RTSS.generateToolState not implemented");
5342
+ // }
5343
+ function _initializeDataset(rtMetadata, imgMetadata, metadataProvider) {
5344
+ var rtSOPInstanceUID = DicomMetaDictionary.uid();
5345
+ // get the first annotation data
5346
+ var imageId = imgMetadata.referencedImageId, FrameOfReferenceUID = imgMetadata.FrameOfReferenceUID;
5347
+ var studyInstanceUID = metadataProvider.get("generalSeriesModule", imageId).studyInstanceUID;
5348
+ var patientModule = getPatientModule(imageId, metadataProvider);
5349
+ var rtSeriesModule = getRTSeriesModule(DicomMetaDictionary);
5350
+ return __assign(__assign(__assign({ StructureSetROISequence: [], ROIContourSequence: [], RTROIObservationsSequence: [], ReferencedSeriesSequence: [], ReferencedFrameOfReferenceSequence: [] }, patientModule), rtSeriesModule), { StudyInstanceUID: studyInstanceUID, SOPClassUID: "1.2.840.10008.5.1.4.1.1.481.3", SOPInstanceUID: rtSOPInstanceUID, Manufacturer: "dcmjs", Modality: "RTSTRUCT", FrameOfReferenceUID: FrameOfReferenceUID, PositionReferenceIndicator: "", StructureSetLabel: rtMetadata.label || "", StructureSetName: rtMetadata.name || "", ReferringPhysicianName: "", OperatorsName: "", StructureSetDate: DicomMetaDictionary.date(), StructureSetTime: DicomMetaDictionary.time(), _meta: null });
5351
+ }
5352
+
5353
+ var generateContourSetsFromLabelmap = utilities$1.contours.generateContourSetsFromLabelmap;
5354
+
5355
+ var RTSS = /*#__PURE__*/Object.freeze({
5356
+ __proto__: null,
5357
+ generateContourSetsFromLabelmap: generateContourSetsFromLabelmap,
5358
+ generateRTSSFromAnnotations: generateRTSSFromAnnotations,
5359
+ generateRTSSFromSegmentations: generateRTSSFromSegmentations
5360
+ });
5361
+
4955
5362
  var Cornerstone3DSR = {
4956
5363
  Bidirectional: Bidirectional,
4957
5364
  CobbAngle: CobbAngle,
@@ -4963,6 +5370,7 @@ var Cornerstone3DSR = {
4963
5370
  ArrowAnnotate: ArrowAnnotate,
4964
5371
  Probe: Probe,
4965
5372
  PlanarFreehandROI: PlanarFreehandROI,
5373
+ UltrasoundDirectional: UltrasoundDirectional,
4966
5374
  MeasurementReport: MeasurementReport,
4967
5375
  CodeScheme: CodingScheme,
4968
5376
  CORNERSTONE_3D_TAG: CORNERSTONE_3D_TAG
@@ -4970,6 +5378,9 @@ var Cornerstone3DSR = {
4970
5378
  var Cornerstone3DSEG = {
4971
5379
  Segmentation: Segmentation$1
4972
5380
  };
5381
+ var Cornerstone3DRT = {
5382
+ RTSS: RTSS
5383
+ };
4973
5384
 
4974
5385
  var Colors = data.Colors,
4975
5386
  BitArray = data.BitArray;
@@ -5104,7 +5515,7 @@ var Segmentation = /*#__PURE__*/function () {
5104
5515
  * @param dataset
5105
5516
  * @return {{}}
5106
5517
  */
5107
- _createClass(Segmentation, null, [{
5518
+ return _createClass(Segmentation, null, [{
5108
5519
  key: "generateSegments",
5109
5520
  value: function generateSegments(dataset) {
5110
5521
  if (dataset.SegmentSequence.constructor.name !== "Array") {
@@ -5151,7 +5562,6 @@ var Segmentation = /*#__PURE__*/function () {
5151
5562
  return segments;
5152
5563
  }
5153
5564
  }]);
5154
- return Segmentation;
5155
5565
  }();
5156
5566
 
5157
5567
  var VTKjsSEG = {
@@ -5163,10 +5573,13 @@ var adaptersSR = {
5163
5573
  Cornerstone3D: Cornerstone3DSR
5164
5574
  };
5165
5575
  var adaptersSEG = {
5166
- Cornerstone: CornerstoneSR,
5576
+ Cornerstone: CornerstoneSEG,
5167
5577
  Cornerstone3D: Cornerstone3DSEG,
5168
5578
  VTKjs: VTKjsSEG
5169
5579
  };
5580
+ var adaptersRT = {
5581
+ Cornerstone3D: Cornerstone3DRT
5582
+ };
5170
5583
 
5171
- export { index as Enums, adaptersSEG, adaptersSR, index$1 as helpers };
5584
+ export { index as Enums, adaptersRT, adaptersSEG, adaptersSR, index$1 as helpers };
5172
5585
  //# sourceMappingURL=adapters.es.js.map