dwv 0.37.0-beta.11 → 0.37.0-beta.13

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 +1 @@
1
- {"version":3,"file":"assets/workers/labeling.worker.min.js","mappings":"AAMO,MAAMA,EAOXC,GAOAC,GAMA,WAAAC,CAAYF,EAAGC,GACbE,MAAKH,EAAKA,EACVG,MAAKF,EAAKA,CACZ,CAOA,IAAAG,GACE,OAAOD,MAAKH,CACd,CAOA,IAAAK,GACE,OAAOF,MAAKF,CACd,CAOA,SAAAK,GACE,MAAO,CAACH,MAAKH,EAAIG,MAAKF,EACxB,CAOA,WAAAM,GACE,OAAOJ,IACT,CAQA,MAAAK,CAAOC,GACL,OAAOA,SAELN,MAAKH,IAAOS,EAAIL,QAChBD,MAAKF,IAAOQ,EAAIJ,MACpB,CAOA,QAAAK,GACE,MAAO,IAAIP,MAAKH,MAAOG,MAAKF,IAC9B,CAQA,WAAAU,CAAYC,GACV,MAAMC,EAAKV,MAAKH,EAAKY,EAAQR,OACvBU,EAAKX,MAAKF,EAAKW,EAAQP,OAC7B,OAAOU,KAAKC,KAAKH,EAAKA,EAAKC,EAAKA,EAClC,ECvFK,MAAMG,EAOX,WAAAC,CAAYC,GACV,IAAK,IAAIC,EAAI,EAAGA,EAAID,EAAYE,OAAQD,IAClCD,EAAYC,IAAM,MACpBD,EAAYC,GAAKD,EAAYC,GAAK,IAGxC,CAYA,EAAAE,CAAyBC,EAAOC,EAAaC,GAK3C,OAHGD,EAAY,GAAKT,KAAKW,MAAMH,EAAMnB,OAASqB,EAAQ,IACnDD,EAAY,GAAKT,KAAKW,MAAMH,EAAMlB,OAASoB,EAAQ,GAGxD,CAaA,EAAAE,CAAaR,EAAaK,EAAaC,EAASG,EAAMC,GACpD,MAAMC,EAAKF,EAAKG,WACVC,EAAKJ,EAAKK,SACVpB,EAAKe,EAAKM,YACVpB,EAAKC,KAAKoB,IAAIP,EAAKQ,aACzB,IA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P,QAAmC,IAAxBzH,EAAamC,GAAwB,CAC9C,MAAMuF,EAAY1H,EAAamC,UAGxBuF,EAAUhD,UACVgD,EAAUpH,cAGVoH,EAAUrH,MAAMxB,KACnB6I,EAAUnH,cACLmH,EAAUnH,MAAM1B,KAGzB4I,EAAUC,UAAYA,CACxB,CAEA,OAAOD,CAAS,IAiBxB,EChrBFE,KAAKC,iBAAiB,WAAW,SAAUC,GAEzC,MAAMC,EAAS,IAAIhG,EACnB,GAAI+F,EAAML,KAAKO,aAAc,CAC3B,MAAOA,cAAcC,UAACA,EAASC,OAAEA,GAAOrF,UACtCA,EAASnE,YAAEA,EAAWqB,MAAEA,EAAKpB,QAAEA,GAAWmJ,EAAML,KAC5CU,EAAYzJ,EAAYA,EAAYH,OAAS,GAC7C6J,EAAM,IAAIC,WAAWxF,GAC3B,IAAK,MAAMyF,WAACA,EAAUb,KAAEA,KAASS,EAAQ,CACvC,MAAMzI,EAAS6I,EAAaH,EAC5B,IAAK,IAAII,EAAI,EAAGA,EAAId,EAAKlJ,SAAUgK,EACjB,IAAZd,EAAKc,KACPH,EAAI3I,EAAS8I,GAAKN,EAGxB,CACAL,KAAKY,YAAYT,EAAOP,IACtB,CAACnJ,YAAa+J,EAAK1J,cAAaqB,QAAOpB,UAASkE,cAEpD,MACE+E,KAAKY,YAAYT,EAAOP,IAAIM,EAAML,MAGtC,IAAG","sources":["webpack://dwv/./src/math/point.js","webpack://dwv/./src/image/labelingDebug.js","webpack://dwv/./src/math/line.js","webpack://dwv/./src/image/labelingFilter.js","webpack://dwv/./src/image/labeling.worker.js"],"sourcesContent":["import {isSimilar} from './number.js';\nimport {Vector3D} from './vector.js';\n\n/**\n * Immutable 2D point.\n */\nexport class Point2D {\n\n /**\n * X position.\n *\n * @type {number}\n */\n #x;\n\n /**\n * Y position.\n *\n * @type {number}\n */\n #y;\n\n /**\n * @param {number} x The X coordinate for the point.\n * @param {number} y The Y coordinate for the point.\n */\n constructor(x, y) {\n this.#x = x;\n this.#y = y;\n }\n\n /**\n * Get the X position of the point.\n *\n * @returns {number} The X position of the point.\n */\n getX() {\n return this.#x;\n }\n\n /**\n * Get the Y position of the point.\n *\n * @returns {number} The Y position of the point.\n */\n getY() {\n return this.#y;\n }\n\n /**\n * Get the values of this point.\n *\n * @returns {number[]} The array of values.\n */\n getValues() {\n return [this.#x, this.#y];\n }\n\n /**\n * Get the centroid of the point, ie itself.\n *\n * @returns {Point2D} The centroid point.\n */\n getCentroid() {\n return this;\n }\n\n /**\n * Check for Point2D equality.\n *\n * @param {Point2D} rhs The other point to compare to.\n * @returns {boolean} True if both points are equal.\n */\n equals(rhs) {\n return rhs !== null &&\n typeof rhs !== 'undefined' &&\n this.#x === rhs.getX() &&\n this.#y === rhs.getY();\n }\n\n /**\n * Get a string representation of the Point2D.\n *\n * @returns {string} The point as a string.\n */\n toString() {\n return `(${this.#x}, ${this.#y})`;\n }\n\n /**\n * Get the distance to another Point2D.\n *\n * @param {Point2D} point2D The input point.\n * @returns {number} Ths distance to the input point.\n */\n getDistance(point2D) {\n const dx = this.#x - point2D.getX();\n const dy = this.#y - point2D.getY();\n return Math.sqrt(dx * dx + dy * dy);\n }\n\n} // Point2D class\n\n/**\n * Immutable 3D point.\n */\nexport class Point3D {\n\n /**\n * X position.\n *\n * @type {number}\n */\n #x;\n\n /**\n * Y position.\n *\n * @type {number}\n */\n #y;\n\n /**\n * Z position.\n *\n * @type {number}\n */\n #z;\n\n /**\n * @param {number} x The X coordinate for the point.\n * @param {number} y The Y coordinate for the point.\n * @param {number} z The Z coordinate for the point.\n */\n constructor(x, y, z) {\n this.#x = x;\n this.#y = y;\n this.#z = z;\n }\n\n /**\n * Get the X position of the point.\n *\n * @returns {number} The X position of the point.\n */\n getX() {\n return this.#x;\n }\n\n /**\n * Get the Y position of the point.\n *\n * @returns {number} The Y position of the point.\n */\n getY() {\n return this.#y;\n }\n\n /**\n * Get the Z position of the point.\n *\n * @returns {number} The Z position of the point.\n */\n getZ() {\n return this.#z;\n }\n\n /**\n * Get the values of this point.\n *\n * @returns {number[]} The array of values.\n */\n getValues() {\n return [this.#x, this.#y, this.#z];\n }\n\n /**\n * Check for Point3D equality.\n *\n * @param {Point3D} rhs The other point to compare to.\n * @returns {boolean} True if both points are equal.\n */\n equals(rhs) {\n return rhs !== null &&\n this.#x === rhs.getX() &&\n this.#y === rhs.getY() &&\n this.#z === rhs.getZ();\n }\n\n /**\n * Check for Point3D similarity.\n *\n * @param {Point3D} rhs The other point to compare to.\n * @param {number} [tol] Optional number comparison tolerance,\n * defaults to Number.EPSILON.\n * @returns {boolean} True if both points are similar.\n */\n isSimilar(rhs, tol) {\n return rhs !== null &&\n isSimilar(this.#x, rhs.getX(), tol) &&\n isSimilar(this.#y, rhs.getY(), tol) &&\n isSimilar(this.#z, rhs.getZ(), tol);\n }\n\n /**\n * Get a string representation of the Point3D.\n *\n * @returns {string} The point as a string.\n */\n toString() {\n return `(${ this.#x\n }, ${ this.#y\n }, ${this.#z})`;\n }\n\n /**\n * Get the distance to another Point3D.\n *\n * @param {Point3D} point3D The input point.\n * @returns {number} Ths distance to the input point.\n */\n getDistance(point3D) {\n return Math.sqrt(this.#getSquaredDistance(point3D));\n }\n\n /**\n * Get the square of the distance between this and\n * an input point. Used for sorting.\n *\n * @param {Point3D} point3D The input point.\n * @returns {number} The square of the distance.\n */\n #getSquaredDistance(point3D) {\n const dx = this.#x - point3D.getX();\n const dy = this.#y - point3D.getY();\n const dz = this.#z - point3D.getZ();\n return dx * dx + dy * dy + dz * dz;\n }\n\n /**\n * Get the closest point to this in a Point3D list.\n *\n * @param {Point3D[]} pointList The list to check.\n * @returns {number} The index of the closest point in the input list.\n */\n getClosest(pointList) {\n let minIndex = 0;\n // the order between squared distances and distances is the same\n let minDist = this.#getSquaredDistance(pointList[minIndex]);\n for (let i = 0; i < pointList.length; ++i) {\n const dist = this.#getSquaredDistance(pointList[i]);\n if (dist < minDist) {\n minIndex = i;\n minDist = dist;\n }\n }\n return minIndex;\n }\n\n /**\n * Get the difference to another Point3D.\n *\n * @param {Point3D} point3D The input point.\n * @returns {Vector3D} The 3D vector from the input point to this one.\n */\n minus(point3D) {\n return new Vector3D(\n (this.#x - point3D.getX()),\n (this.#y - point3D.getY()),\n (this.#z - point3D.getZ()));\n }\n\n} // Point3D class\n\n/**\n * Get an array find callback for an equal input point.\n *\n * @param {Point3D} point The point to compare to.\n * @returns {Function} A function that compares, using `equals`,\n * its input point to the one given as input to this function.\n */\nexport function getEqualPoint3DFunction(point) {\n return function (element) {\n return element.equals(point);\n };\n}\n\n/**\n * Immutable point.\n * Warning: the input array is NOT cloned, modifying it will\n * modify the point values.\n */\nexport class Point {\n\n /**\n * Point values.\n *\n * @type {number[]}\n */\n #values;\n\n /**\n * @param {number[]} values The point values.\n */\n constructor(values) {\n if (!values || typeof values === 'undefined') {\n throw new Error('Cannot create point with no values.');\n }\n if (values.length === 0) {\n throw new Error('Cannot create point with empty values.');\n }\n const valueCheck = function (val) {\n return !isNaN(val);\n };\n if (!values.every(valueCheck)) {\n throw new Error('Cannot create point with non number values.');\n }\n this.#values = values;\n }\n\n /**\n * Get the point value at the given array index.\n *\n * @param {number} i The index to get.\n * @returns {number} The value.\n */\n get(i) {\n return this.#values[i];\n }\n\n /**\n * Get the length of the point.\n *\n * @returns {number} The length.\n */\n length() {\n return this.#values.length;\n }\n\n /**\n * Get a string representation of the point.\n *\n * @returns {string} The point as a string.\n */\n toString() {\n return `(${this.#values.toString()})`;\n }\n\n /**\n * Get the values of this point.\n *\n * @returns {number[]} The array of values.\n */\n getValues() {\n return this.#values.slice();\n }\n\n /**\n * Check if the input point can be compared to this one.\n *\n * @param {Point} rhs The point to compare to.\n * @returns {boolean} True if both points are comparable.\n */\n canCompare(rhs) {\n // check input\n if (!rhs) {\n return false;\n }\n // check length\n if (this.length() !== rhs.length()) {\n return false;\n }\n // seems ok!\n return true;\n }\n\n /**\n * Check for Point equality.\n *\n * @param {Point} rhs The point to compare to.\n * @returns {boolean} True if both points are equal.\n */\n equals(rhs) {\n // check if can compare\n if (!this.canCompare(rhs)) {\n return false;\n }\n // check values\n for (let i = 0, leni = this.length(); i < leni; ++i) {\n if (this.get(i) !== rhs.get(i)) {\n return false;\n }\n }\n // seems ok!\n return true;\n }\n\n /**\n * Compare points and return different dimensions.\n *\n * @param {Point} rhs The point to compare to.\n * @returns {number[]} The list of different dimensions.\n */\n compare(rhs) {\n // check if can compare\n if (!this.canCompare(rhs)) {\n return null;\n }\n // check values\n const diffDims = [];\n for (let i = 0, leni = this.length(); i < leni; ++i) {\n if (this.get(i) !== rhs.get(i)) {\n diffDims.push(i);\n }\n }\n return diffDims;\n }\n\n /**\n * Get the 3D part of this point.\n *\n * @returns {Point3D} The Point3D.\n */\n get3D() {\n return new Point3D(this.get(0), this.get(1), this.get(2));\n }\n\n /**\n * Add another point to this one.\n *\n * @param {Point} rhs The point to add.\n * @returns {Point} The point representing the sum of both points.\n */\n add(rhs) {\n // check if can compare\n if (!this.canCompare(rhs)) {\n return null;\n }\n const values = [];\n const values0 = this.getValues();\n const values1 = rhs.getValues();\n for (let i = 0; i < values0.length; ++i) {\n values.push(values0[i] + values1[i]);\n }\n return new Point(values);\n }\n\n /**\n * Merge this point with a Point3D to create a new point.\n *\n * @param {Point3D} rhs The Point3D to merge with.\n * @returns {Point} The merge result.\n */\n mergeWith3D(rhs) {\n const values = this.getValues();\n values[0] = rhs.getX();\n values[1] = rhs.getY();\n values[2] = rhs.getZ();\n return new Point(values);\n }\n\n} // Point class\n","import {Point2D} from '../math/point.js';\n\n/**\n * @import {Line} from '../math/line.js';\n */\n\n/**\n * Helper for the LabelingFilter, provides a debug display for diameters and\n * contours.\n *\n * Temporary until a proper way of rendering them is added.\n */\nexport class LabelingDebug {\n\n /**\n * Cleans buffer of debug lines before calculations.\n *\n * @param {Uint8Array} imageBuffer The image buffer to clean.\n */\n cleanBuffer(imageBuffer) {\n for (let i = 0; i < imageBuffer.length; i++) {\n if (imageBuffer[i] >= 128) {\n imageBuffer[i] = imageBuffer[i] - 128;\n }\n }\n }\n\n /**\n * Convert a slice local world coordinate to a slice local offset value.\n *\n * @param {Point2D} point Point on the slice, scaled.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n *\n * @returns {number} Offset relative to the offset at the start of the slice.\n */\n #sliceWorldToSliceOffset(point, unitVectors, spacing) {\n const offset =\n (unitVectors[0] * Math.round(point.getX() / spacing[0])) +\n (unitVectors[1] * Math.round(point.getY() / spacing[1]));\n\n return offset;\n }\n\n /**\n * Draw a debug line segment of an angle less that 45 degrees.\n * Points should be in slice world space.\n *\n * @param {Uint8Array} imageBuffer The image buffer to draw debug lines on.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {Line} line The line segment to plot.\n * @param {number} z The slice index.\n */\n #plotLineLow(imageBuffer, unitVectors, spacing, line, z) {\n const p0 = line.getBegin();\n const p1 = line.getEnd();\n const dx = line.getDeltaX();\n const dy = Math.abs(line.getDeltaY());\n let D = 2 * dy - dx;\n let y = p0.getY();\n const yi = (p0.getY() < p1.getY()) ? 1 : -1;\n\n for (let x = p0.getX(); x <= p1.getX(); x++) {\n const sliceOffset =\n this.#sliceWorldToSliceOffset(new Point2D(x, y), unitVectors, spacing);\n const offset = sliceOffset + (unitVectors[2] * z);\n imageBuffer[offset] = imageBuffer[offset] + 128;\n\n if (D > 0) {\n y = y + yi;\n D = D - 2 * dx;\n }\n D = D + 2 * dy;\n }\n }\n\n /**\n * Draw a debug line segment of an angle greater that 45 degrees.\n * Points should be in slice world space.\n *\n * @param {Uint8Array} imageBuffer The image buffer to draw debug lines on.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {Line} line The line segment to plot.\n * @param {number} z The slice index.\n */\n #plotLineHigh(imageBuffer, unitVectors, spacing, line, z) {\n const p0 = line.getBegin();\n const p1 = line.getEnd();\n const dx = Math.abs(line.getDeltaX());\n const dy = line.getDeltaY();\n let D = 2 * dx - dy;\n let x = p0.getX();\n const xi = (p0.getX() < p1.getX()) ? 1 : -1;\n\n for (let y = p0.getY(); y <= p1.getY(); y++) {\n const sliceOffset =\n this.#sliceWorldToSliceOffset(new Point2D(x, y), unitVectors, spacing);\n const offset = sliceOffset + (unitVectors[2] * z);\n imageBuffer[offset] = imageBuffer[offset] + 128;\n\n if (D > 0) {\n x = x + xi;\n D = D - 2 * dy;\n }\n D = D + 2 * dx;\n }\n }\n\n /**\n * Draw a debug line segment.\n * Points should be in slice world space.\n *\n * @param {Uint8Array} imageBuffer The image buffer to draw debug lines on.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {Line} line The line segment to plot.\n * @param {number} z The slice index.\n */\n #plotPoints(imageBuffer, unitVectors, spacing, line, z) {\n const p0 = line.getBegin();\n const p1 = line.getEnd();\n if (Math.abs(line.getDeltaY()) < Math.abs(line.getDeltaX())) {\n if (p0.getX() < p1.getX()) {\n this.#plotLineLow(\n imageBuffer,\n unitVectors,\n spacing,\n line,\n z\n );\n } else {\n this.#plotLineLow(\n imageBuffer,\n unitVectors,\n spacing,\n line.getFlipped(),\n z\n );\n }\n } else if (p0.getY() < p1.getY()) {\n this.#plotLineHigh(\n imageBuffer,\n unitVectors,\n spacing,\n line,\n z\n );\n } else {\n this.#plotLineHigh(\n imageBuffer,\n unitVectors,\n spacing,\n line.getFlipped(),\n z\n );\n }\n }\n\n /**\n * Renders debug lines for contours and diameters.\n * The pixel value of the debug lines are the segmentation label of the\n * segment + 128.\n *\n * @param {Uint8Array} imageBuffer The image buffer to draw debug lines on.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} sizes The image dimensions.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {Int32Array} borders The buffer containing the border pixel arrays.\n * @param {object} maxDiameters The dictionary of calculated diameters.\n */\n drawDebugLines(\n imageBuffer,\n unitVectors,\n sizes,\n spacing,\n borders,\n maxDiameters\n ) {\n Object.values(maxDiameters).map((diameter) => {\n this.#plotPoints(\n imageBuffer,\n unitVectors,\n spacing,\n diameter.major.line,\n diameter.zIndex\n );\n\n if (typeof diameter.minor !== 'undefined') {\n this.#plotPoints(\n imageBuffer,\n unitVectors,\n spacing,\n diameter.minor.line,\n diameter.zIndex\n );\n }\n });\n }\n\n} //class LabelingDebug","import {Point2D} from './point.js';\nimport {\n isSimilar,\n REAL_WORLD_EPSILON,\n} from './number.js';\n\n/**\n * @import {ViewController} from '../app/viewController.js';\n * @import {Scalar2D} from './scalar.js';\n * @import {NumberValue} from './number.js';\n */\n\n/**\n * Line shape.\n */\nexport class Line {\n\n /**\n * Line begin point.\n *\n * @type {Point2D}\n */\n #begin;\n\n /**\n * Line end point.\n *\n * @type {Point2D}\n */\n #end;\n\n /**\n * @param {Point2D} begin A Point2D representing the beginning\n * of the line.\n * @param {Point2D} end A Point2D representing the end of the line.\n */\n constructor(begin, end) {\n this.#begin = begin;\n this.#end = end;\n }\n\n /**\n * Get the begin point of the line.\n *\n * @returns {Point2D} The beginning point of the line.\n */\n getBegin() {\n return this.#begin;\n }\n\n /**\n * Get the end point of the line.\n *\n * @returns {Point2D} The ending point of the line.\n */\n getEnd() {\n return this.#end;\n }\n\n /**\n * Check for equality.\n *\n * @param {Line} rhs The object to compare to.\n * @returns {boolean} True if both objects are equal.\n */\n equals(rhs) {\n return rhs !== null &&\n this.getBegin().equals(rhs.getBegin()) &&\n this.getEnd().equals(rhs.getEnd());\n }\n\n /**\n * Get the line delta in the X direction.\n *\n * @returns {number} The delta in the X direction.\n */\n getDeltaX() {\n return this.getEnd().getX() - this.getBegin().getX();\n }\n\n /**\n * Get the line delta in the Y direction.\n *\n * @returns {number} The delta in the Y direction.\n */\n getDeltaY() {\n return this.getEnd().getY() - this.getBegin().getY();\n }\n\n /**\n * Get the length of the line.\n *\n * @returns {number} The length of the line.\n */\n getLength() {\n return Math.sqrt(\n this.getDeltaX() * this.getDeltaX() +\n this.getDeltaY() * this.getDeltaY()\n );\n }\n\n /**\n * Get the length of the line according to a spacing.\n *\n * @param {Scalar2D} spacing2D The 2D spacing.\n * @returns {number} The length of the line with spacing\n * or null for null spacings.\n */\n getWorldLength(spacing2D) {\n let wlen = null;\n if (spacing2D !== null) {\n const dxs = this.getDeltaX() * spacing2D.x;\n const dys = this.getDeltaY() * spacing2D.y;\n wlen = Math.sqrt(dxs * dxs + dys * dys);\n }\n return wlen;\n }\n\n /**\n * Get the mid point of the line.\n *\n * @returns {Point2D} The mid point of the line.\n * @deprecated Since v0.36, please use getCentroid instead.\n */\n getMidpoint() {\n return this.getCentroid();\n }\n\n /**\n * Get the centroid of the line.\n *\n * @returns {Point2D} THe centroid point.\n */\n getCentroid() {\n return new Point2D(\n (this.getBegin().getX() + this.getEnd().getX()) / 2,\n (this.getBegin().getY() + this.getEnd().getY()) / 2\n );\n }\n\n /**\n * Get the slope of the line.\n *\n * @returns {number} The slope of the line.\n */\n getSlope() {\n return this.getDeltaY() / this.getDeltaX();\n }\n\n /**\n * Get the intercept of the line.\n *\n * @returns {number} The slope of the line.\n */\n getIntercept() {\n return (\n this.getEnd().getX() * this.getBegin().getY() -\n this.getBegin().getX() * this.getEnd().getY()\n ) / this.getDeltaX();\n }\n\n /**\n * Get the inclination of the line.\n *\n * @returns {number} The inclination of the line.\n */\n getInclination() {\n // tan(theta) = slope\n const angle =\n Math.atan2(this.getDeltaY(), this.getDeltaX()) * 180 / Math.PI;\n // shift?\n return 180 - angle;\n }\n\n /**\n * Get a new line with the start and end flipped.\n *\n * @returns {Line} The new flipped line.\n */\n getFlipped() {\n return new Line(this.#end, this.#begin);\n }\n\n /**\n * Quantify a line according to view information.\n *\n * @param {ViewController} viewController The associated view controller.\n * @returns {Record<string, NumberValue>} A quantification object.\n */\n quantify(viewController) {\n // length\n const spacing2D = viewController.get2DSpacing();\n const worldLength = this.getWorldLength(spacing2D);\n let length;\n if (worldLength !== null) {\n length = {\n value: worldLength,\n unit: viewController.getLengthUnit()\n };\n }\n // return\n return {length};\n }\n\n} // Line class\n\n/**\n * Get the angle between two lines in degree.\n *\n * @param {Line} line0 The first line.\n * @param {Line} line1 The second line.\n * @returns {number} The angle.\n */\nexport function getAngle(line0, line1) {\n const dx0 = line0.getDeltaX();\n const dy0 = line0.getDeltaY();\n const dx1 = line1.getDeltaX();\n const dy1 = line1.getDeltaY();\n // dot = ||a||*||b||*cos(theta)\n const dot = dx0 * dx1 + dy0 * dy1;\n // cross = ||a||*||b||*sin(theta)\n const det = dx0 * dy1 - dy0 * dx1;\n // tan = sin / cos\n const angle = Math.atan2(det, dot) * 180 / Math.PI;\n // complementary angle\n // shift?\n return 360 - (180 - angle);\n}\n\n/**\n * Check if two lines are orthogonal.\n *\n * @param {Line} line0 The first line.\n * @param {Line} line1 The second line.\n * @returns {boolean} True if both lines are orthogonal.\n */\nexport function areOrthogonal(line0, line1) {\n const dx0 = line0.getDeltaX();\n const dy0 = line0.getDeltaY();\n const dx1 = line1.getDeltaX();\n const dy1 = line1.getDeltaY();\n // dot = ||a||*||b||*cos(theta)\n return (dx0 * dx1 + dy0 * dy1) === 0;\n}\n\n/**\n * Check if a point is in a line coordinate range.\n *\n * @param {Point2D} point The input point.\n * @param {Line} line The input line.\n * @returns {boolean} True if the input point is in the line coordinate range.\n */\nexport function isPointInLineRange(point, line) {\n const minX = Math.min(line.getBegin().getX(), line.getEnd().getX());\n const maxX = Math.max(line.getBegin().getX(), line.getEnd().getX());\n const minY = Math.min(line.getBegin().getY(), line.getEnd().getY());\n const maxY = Math.max(line.getBegin().getY(), line.getEnd().getY());\n return point.getX() >= minX &&\n point.getX() <= maxX &&\n point.getY() >= minY &&\n point.getY() <= maxY;\n}\n\n/**\n * Get a perpendicular line to an input one at a given point.\n *\n * @param {Line} line The line to be perpendicular to.\n * @param {Point2D} point The middle point of the perpendicular line.\n * @param {number} length The length of the perpendicular line.\n * @param {Scalar2D} [spacing] Optional image spacing, default to [1,1].\n * @returns {Line} The perpendicular line.\n */\nexport function getPerpendicularLine(line, point, length, spacing) {\n if (typeof spacing === 'undefined') {\n spacing = {x: 1, y: 1};\n }\n const sx2 = spacing.x * spacing.x;\n const sy2 = spacing.y * spacing.y;\n // a0 * a1 = -1 (in square space)\n const perpSlope = -sx2 / (sy2 * line.getSlope());\n // y0 = a1*x0 + b1 -> b1 = y0 - a1*x0\n const prepIntercept = point.getY() - perpSlope * point.getX();\n // return\n return getLineFromEquation(perpSlope, prepIntercept, point, length, spacing);\n}\n\n/**\n * Get a perpendicular line to an input one at a given distance\n * of its begin point.\n *\n * @param {Line} line The line to be perpendicular to.\n * @param {number} distance The distance to the input line begin point.\n * @param {number} length The length of the perpendicular line.\n * @param {Scalar2D} [spacing] Optional image spacing, default to [1,1].\n * @returns {Line} The perpendicular line.\n */\nexport function getPerpendicularLineAtDistance(\n line, distance, length, spacing) {\n // get a line along the input one and centered on begin point\n const lineFromEq = getLineFromEquation(\n line.getSlope(),\n line.getIntercept(),\n line.getBegin(),\n distance,\n spacing\n );\n // select the point on the input line\n let startPoint;\n if (isPointInLineRange(lineFromEq.getBegin(), line)) {\n startPoint = lineFromEq.getBegin();\n } else {\n startPoint = lineFromEq.getEnd();\n }\n // use it as base for a perpendicular line\n return getPerpendicularLine(line, startPoint, length, spacing);\n}\n\n/**\n * Get a line from an equation, a middle point and a length.\n *\n * @param {number} slope The line slope.\n * @param {number} intercept The line intercept.\n * @param {Point2D} point The middle point of the line.\n * @param {number} length The line length.\n * @param {Scalar2D} [spacing] Optional image spacing, default to [1,1].\n * @returns {Line} The resulting line.\n */\nexport function getLineFromEquation(slope, intercept, point, length, spacing) {\n if (typeof spacing === 'undefined') {\n spacing = {x: 1, y: 1};\n }\n // begin point\n let beginX;\n let beginY;\n // end point\n let endX;\n let endY;\n\n if (isSimilar(slope, 0, REAL_WORLD_EPSILON)) {\n // slope = ~0 -> horizontal input line\n beginX = point.getX() - length / (2 * spacing.x);\n beginY = point.getY();\n endX = point.getX() + length / (2 * spacing.x);\n endY = point.getY();\n } else if (Math.abs(slope) > 1e6) {\n // slope = ~(+/-)Infinity -> vertical input line\n beginX = point.getX();\n beginY = point.getY() - length / (2 * spacing.y);\n endX = point.getX();\n endY = point.getY() + length / (2 * spacing.y);\n } else {\n const sx2 = spacing.x * spacing.x;\n const sy2 = spacing.y * spacing.y;\n\n // 1. [length] sx^2 * (x - x0)^2 + sy^2 * (y - y0)^2 = d^2\n // 2. [slope] a = (y - y0) / (x - x0) -> y - y0 = a*(x - x0)\n // -> sx^2 * (x - x0)^2 + sy^2 * a^2 * (x - x0)^2 = d^2\n // -> (x - x0)^2 = d^2 / (sx^2 + sy^2 * a^2)\n // -> x = x0 +- d / sqrt(sx^2 + sy^2 * a^2)\n\n // length is the distance between begin and end,\n // point is half way between both -> d = length / 2\n const dx = length / (2 * Math.sqrt(sx2 + sy2 * slope * slope));\n\n // begin point\n beginX = point.getX() - dx;\n beginY = slope * beginX + intercept;\n // end point\n endX = point.getX() + dx;\n endY = slope * endX + intercept;\n }\n return new Line(\n new Point2D(beginX, beginY),\n new Point2D(endX, endY));\n}\n","import {LabelingDebug} from './labelingDebug.js';\nimport {Point2D} from '../math/point.js';\nimport {Line} from '../math/line.js';\n\n// Set this to true to show the debug contour and diameter display\nconst DIAMETER_DEBUG = false;\n\n/**\n * Filter for calculating labels.\n *\n * Labels a buffer using the Hoshen–Kopelman\n * algorithm to first label all of the connected components, then does\n * a second pass to count the number of voxels in each unique label.\n *\n * The Hoshen–Kopelman labelling is slightly modified to work with\n * non-binary 3D data, but is otherwise structured the same way.\n *\n * Ref: {@link https://en.wikipedia.org/wiki/Hoshen%E2%80%93Kopelman_algorithm}.\n */\nexport class LabelingFilter {\n /**\n * The last known image size.\n *\n * @type {number}\n */\n #lastKnownTotalSize;\n\n /**\n * A union-find (disjoint-set) representing the available labels.\n *\n * @type {Int32Array}\n */\n #unionFind;\n\n /**\n * A buffer containing the labels for each voxel.\n *\n * @type {Int32Array}\n */\n #labels;\n\n /**\n * A buffer containing a list of border pixels for each layer.\n *\n * @type {Int32Array}\n */\n #borders;\n\n /**\n * Union-find find operation.\n * Ref: {@link https://en.wikipedia.org/wiki/Disjoint-set_data_structure}.\n *\n * @param {number} label The label to find the root of.\n * @returns {number} The root label.\n */\n #find(label) {\n if (label < 0) {\n return label;\n }\n\n // Find the root label\n let currentLabel = label;\n while (this.#unionFind[currentLabel] !== currentLabel) {\n currentLabel = this.#unionFind[currentLabel];\n }\n\n // Do an update pass to make this faster next time\n let updateLabel = label;\n while (this.#unionFind[updateLabel] !== updateLabel) {\n const newLabel = this.#unionFind[updateLabel];\n this.#unionFind[updateLabel] = currentLabel;\n updateLabel = newLabel;\n }\n\n return currentLabel;\n }\n\n /**\n * Union-find union operation.\n *\n * @param {number} label1 The child label to union.\n * @param {number} label2 The parent label to union.\n */\n #union(label1, label2) {\n // This will break if a non-label (-1) get passed in\n // however with the current implmentation this should never happen\n this.#unionFind[this.#find(label1)] = this.#find(label2);\n }\n\n /**\n * Label the buffer using the Hoshen–Kopelman algorithm.\n *\n * @param {Uint8Array} buffer The image buffer to regenerate the labels for.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} sizes The image dimensions.\n * @param {number} totalSize The total length of the buffer.\n */\n #regenerateLabels(buffer, unitVectors, sizes, totalSize) {\n // If we are re-calcing the labels of the same sized image as last time we\n // can save a little time on re-initializing memory. Makes it slightly\n // faster to use a seperate worker object per segmentation, at the\n // cost of extra memory.\n if (typeof this.#lastKnownTotalSize === 'undefined' ||\n this.#lastKnownTotalSize !== totalSize) {\n // The size of the image has changed, we need to reinitialize everything.\n this.#lastKnownTotalSize = totalSize;\n\n // Performance trade-off means this can use a fair bit of memory\n // on large images.\n this.#unionFind = new Int32Array(totalSize);\n this.#labels = new Int32Array(totalSize);\n this.#borders = new Int32Array(totalSize);\n }\n\n // Generate the Hoshen–Kopelman labels\n for (let z = 0; z < sizes[2]; z++) {\n\n let borderOffset = 0;\n\n for (let x = 0; x < sizes[0]; x++) {\n for (let y = 0; y < sizes[1]; y++) {\n\n const thisOffset =\n (unitVectors[0] * x) +\n (unitVectors[1] * y) +\n (unitVectors[2] * z);\n\n // Reset labels.\n this.#unionFind[thisOffset] = thisOffset;\n this.#labels[thisOffset] = -1;\n\n const thisValue = buffer[thisOffset];\n\n if (thisValue > 0) {\n // Neighbor offsets\n const xOffset = thisOffset - unitVectors[0];\n const yOffset = thisOffset - unitVectors[1];\n const zOffset = thisOffset - unitVectors[2];\n\n const xOffsetp = thisOffset + unitVectors[0];\n const yOffsetp = thisOffset + unitVectors[1];\n\n // Neighbor values\n let xValue = 0;\n if (x > 0) {\n xValue = buffer[xOffset];\n };\n let yValue = 0;\n if (y > 0) {\n yValue = buffer[yOffset];\n };\n let zValue = 0;\n if (z > 0) {\n zValue = buffer[zOffset];\n };\n\n let xValuep = 0;\n if (x < sizes[0] - 1) {\n xValuep = buffer[xOffsetp];\n };\n let yValuep = 0;\n if (y < sizes[1] - 1) {\n yValuep = buffer[yOffsetp];\n };\n\n // Neighbor labels\n let xLabel = 0;\n if (x > 0) {\n xLabel = this.#labels[xOffset];\n };\n let yLabel = 0;\n if (y > 0) {\n yLabel = this.#labels[yOffset];\n };\n let zLabel = 0;\n if (z > 0) {\n zLabel = this.#labels[zOffset];\n };\n\n // No neighbors with matching values\n if (\n xValue !== thisValue &&\n yValue !== thisValue &&\n zValue !== thisValue\n ) {\n this.#labels[thisOffset] = thisOffset; // Guaranteed unique label.\n\n // One neighbor with matching values\n } else if (\n xValue === thisValue &&\n yValue !== thisValue &&\n zValue !== thisValue\n ) {\n this.#labels[thisOffset] = this.#find(xLabel);\n } else if (\n xValue !== thisValue &&\n yValue === thisValue &&\n zValue !== thisValue\n ) {\n this.#labels[thisOffset] = this.#find(yLabel);\n } else if (\n xValue !== thisValue &&\n yValue !== thisValue &&\n zValue === thisValue\n ) {\n this.#labels[thisOffset] = this.#find(zLabel);\n\n // Two neighbor with matching values\n } else if (\n xValue !== thisValue &&\n yValue === thisValue &&\n zValue === thisValue\n ) {\n this.#union(yLabel, zLabel);\n this.#labels[thisOffset] = this.#find(yLabel);\n } else if (\n xValue === thisValue &&\n yValue !== thisValue &&\n zValue === thisValue\n ) {\n this.#union(xLabel, zLabel);\n this.#labels[thisOffset] = this.#find(xLabel);\n } else if (\n xValue === thisValue &&\n yValue === thisValue &&\n zValue !== thisValue\n ) {\n this.#union(xLabel, yLabel);\n this.#labels[thisOffset] = this.#find(xLabel);\n\n // All neighbors with matching values\n } else if (\n xValue === thisValue &&\n yValue === thisValue &&\n zValue === thisValue\n ) {\n this.#union(xLabel, yLabel);\n this.#union(xLabel, zLabel);\n this.#labels[thisOffset] = this.#find(xLabel);\n }\n\n // Border check\n if (\n xValue !== thisValue ||\n yValue !== thisValue ||\n xValuep !== thisValue ||\n yValuep !== thisValue\n ) {\n this.#borders[(unitVectors[2] * z) + borderOffset] = thisOffset;\n borderOffset++;\n }\n }\n }\n }\n\n this.#borders[(unitVectors[2] * z) + borderOffset] = -1;\n\n }\n }\n\n /**\n * Convert an offset in memory to an index.\n *\n * @param {number} offset The offset to convert.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @returns {number[]} The index.\n */\n #offsetToIndex(offset, unitVectors) {\n const values = new Array(unitVectors.length);\n let off = offset;\n let dimSize;\n for (let i = unitVectors.length - 1; i > 0; --i) {\n dimSize = unitVectors[i];\n values[i] = Math.floor(off / dimSize);\n off = off - values[i] * dimSize;\n }\n values[0] = off;\n return values;\n }\n\n /**\n * Quantify labels: count items, calculate centroid, and calculate height.\n *\n * @param {Uint8Array} buffer The image buffer to quantify the labels for.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n *\n * @returns {object} The dictionary of quantified labels.\n */\n #quantifyLabels(\n buffer,\n unitVectors,\n spacing\n ) {\n const detailledInfos = {};\n\n // Count the number of voxels per unique label,\n // this has to be done as a second pass.\n for (let o = 0; o < this.#labels.length; o++) {\n const labelValue = this.#find(this.#labels[o]);\n\n if (labelValue >= 0) {\n const index = this.#offsetToIndex(o, unitVectors);\n const info = detailledInfos[labelValue];\n if (typeof info === 'undefined') {\n const sliceCounts = {};\n sliceCounts[index[2]] = 1;\n detailledInfos[labelValue] = {\n id: buffer[o],\n sum: index,\n count: 1,\n sliceCounts,\n maxZ: index[2],\n minZ: index[2]\n };\n } else {\n info.sum[0] += index[0];\n info.sum[1] += index[1];\n info.sum[2] += index[2];\n info.count++;\n if (typeof info.sliceCounts[index[2]] !== 'undefined') {\n info.sliceCounts[index[2]]++;\n } else {\n info.sliceCounts[index[2]] = 1;\n }\n info.maxZ = Math.max(info.maxZ, index[2]);\n info.minZ = Math.min(info.minZ, index[2]);\n }\n }\n }\n\n const labelsInfo = {};\n\n for (const [label, detailledInfo] of Object.entries(detailledInfos)) {\n const index = Array(detailledInfo.sum.length).fill(0);\n for (let d = 0; d < detailledInfo.sum.length; d++) {\n index[d] = detailledInfo.sum[d] / detailledInfo.count;\n }\n\n const sliceCounts = Object.entries(detailledInfo.sliceCounts);\n const largestSliceZ = (() => {\n if (sliceCounts.length > 1) {\n const largest =\n sliceCounts\n .reduce((\n [largestSlice, largestCount],\n [currentSlice, currentCount]\n ) => {\n if (currentCount > largestCount) {\n return [currentSlice, currentCount];\n }\n return [largestSlice, largestCount];\n })[0];\n return Number(largest);\n }\n return Number(sliceCounts[0][0]);\n })();\n\n labelsInfo[label] = {\n id: detailledInfo.id,\n centroidIndex: index,\n count: detailledInfo.count,\n largestSliceZ,\n height: (detailledInfo.maxZ - detailledInfo.minZ + 1) * spacing[2]\n };\n }\n\n return labelsInfo;\n }\n\n /**\n * Convert a slice local offset value to a slice local world coordinate.\n *\n * @param {number} sliceOffset Offset relative to the offset at the\n * start of the slice.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n *\n * @returns {Point2D} Point on the slice, scaled.\n */\n #sliceOffsetToSliceWorld(sliceOffset, unitVectors, spacing) {\n let x;\n let y;\n if (unitVectors[0] > unitVectors[1]) {\n y = (sliceOffset % unitVectors[0]) / unitVectors[1];\n x = Math.floor(sliceOffset / unitVectors[0]);\n } else {\n x = (sliceOffset % unitVectors[1]) / unitVectors[0];\n y = Math.floor(sliceOffset / unitVectors[1]);\n }\n\n x = x * spacing[0];\n y = y * spacing[1];\n\n return new Point2D(x, y);\n }\n\n /**\n * Check if an angle is reasonably close to 90 degrees.\n *\n * @param {number} angle The angle to test.\n * @param {number} epsilon How close to 90 degrees it needs to be.\n * @returns {boolean} Is the angle close enough to 90 degrees.\n */\n #goodPerpendicularAngle(angle, epsilon) {\n return angle > (90 - epsilon) && angle < (90 + epsilon);\n }\n\n /**\n * Calculate the major and minor (perpendicular) diameters of each segment.\n *\n * @param {Uint8Array} buffer The image buffer to calculate diameters for.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} sizes The image dimensions.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {object} labelInfos The quantified labelInfos of the segments.\n *\n * @returns {object} The dictionary of calculated diameters.\n */\n #calculateDiameters(\n buffer,\n unitVectors,\n sizes,\n spacing,\n labelInfos\n ) {\n const maxDiameters = {};\n\n // Get the major diameter\n for (let z = 0; z < sizes[2]; z++) {\n const zOffset = unitVectors[2] * z;\n\n // TODO: It would be more efficient to calculate the convex hull, use\n // rotating calipers to get antipodal points, and then calculate the\n // major diameter from those.\n // For now the naive way is fast enough for an initial implementation.\n\n let borderOffset1 = 0;\n while (this.#borders[zOffset + borderOffset1] >= 0) {\n const offset1 = this.#borders[zOffset + borderOffset1];\n const label1 = this.#find(this.#labels[offset1]);\n\n // We only care about the diameter of the largest slice,\n // we can skip everything else.\n if (\n typeof labelInfos[label1] !== 'undefined' &&\n labelInfos[label1].largestSliceZ === z\n ) {\n const sliceOffset1 = offset1 - zOffset;\n const slicePosition1 =\n this.#sliceOffsetToSliceWorld(sliceOffset1, unitVectors, spacing);\n\n let borderOffset2 = 0;\n while (this.#borders[zOffset + borderOffset2] >= 0) {\n const offset2 = this.#borders[zOffset + borderOffset2];\n const label2 = this.#find(this.#labels[offset2]);\n\n if (label1 === label2) {\n const sliceOffset2 = offset2 - zOffset;\n const slicePosition2 =\n this.#sliceOffsetToSliceWorld(\n sliceOffset2,\n unitVectors,\n spacing\n );\n\n const sliceLine = new Line(slicePosition1, slicePosition2);\n const distance = sliceLine.getLength();\n\n const maxDiameter = maxDiameters[label1];\n if (\n typeof maxDiameter === 'undefined' ||\n maxDiameter.major.diameter < distance\n ) {\n maxDiameters[label1] = {\n id: buffer[offset1],\n major: {\n diameter: distance,\n line: sliceLine,\n offset1,\n offset2,\n },\n zIndex: z\n };\n }\n }\n\n borderOffset2++;\n }\n\n }\n\n borderOffset1++;\n }\n }\n\n // Get the minor (perpendicular) diameter\n for (const [label, diameter] of Object.entries(maxDiameters)) {\n const zOffset = unitVectors[2] * diameter.zIndex;\n const diameterLine = diameter.major.line;\n const diameterAngle = diameterLine.getInclination();\n\n // TODO: This could also be made faster by using a modified antipodal\n // point algorithm that uses perpedicularity to the initial diameter\n // instead of parallel tangents (we can't use the convex hull for this\n // one, so the normal algorithm doesn't work).\n // For now the naive way is fast enough for an initial implementation.\n\n let borderOffset1 = 0;\n while (this.#borders[zOffset + borderOffset1] >= 0) {\n const offset1 = this.#borders[zOffset + borderOffset1];\n const label1 = this.#find(this.#labels[offset1]);\n\n if (label1.toString() !== label) {\n borderOffset1++;\n continue;\n }\n\n const sliceOffset1 = offset1 - zOffset;\n const slicePosition1 =\n this.#sliceOffsetToSliceWorld(sliceOffset1, unitVectors, spacing);\n\n let borderOffset2 = 0;\n while (this.#borders[zOffset + borderOffset2] >= 0) {\n const offset2 = this.#borders[zOffset + borderOffset2];\n const label2 = this.#find(this.#labels[offset2]);\n if (label2.toString() === label && label1 === label2) {\n const sliceOffset2 = offset2 - zOffset;\n const slicePosition2 =\n this.#sliceOffsetToSliceWorld(\n sliceOffset2,\n unitVectors,\n spacing\n );\n\n // Check angle for perpendicularity\n const sliceLine = new Line(slicePosition1, slicePosition2);\n const angle = sliceLine.getInclination();\n\n const angleDifference = Math.abs(angle - diameterAngle);\n\n const distance = sliceLine.getLength();\n\n const isGoodAngle =\n this.#goodPerpendicularAngle(angleDifference, 0.5);\n\n // If we can't find any angles close to 90 degrees then\n // prioritize finding something remotely useable.\n // This only really happens on very small/thin segments.\n const isReasonableWithoutBetter =\n typeof diameter.minor !== 'undefined' &&\n (!this.#goodPerpendicularAngle(\n diameter.minor.angleDiff,\n 0.5\n )) &&\n (this.#goodPerpendicularAngle(\n angleDifference,\n 10\n ));\n\n if (\n typeof diameter.minor === 'undefined' ||\n (\n diameter.minor.diameter < distance &&\n isReasonableWithoutBetter\n ) ||\n (\n diameter.minor.diameter < distance &&\n isGoodAngle\n )\n ) {\n diameter.minor = {\n diameter: distance,\n line: sliceLine,\n offset1,\n offset2,\n angleDiff: angleDifference\n };\n }\n }\n\n borderOffset2++;\n }\n\n borderOffset1++;\n }\n }\n\n return maxDiameters;\n }\n\n /**\n * Run the filter.\n *\n * @param {object} data The input data.\n * @returns {object} The list of quantified labels.\n */\n run(data) {\n const imageBuffer = data.imageBuffer;\n const unitVectors = data.unitVectors;\n const sizes = data.sizes;\n const spacing = data.spacing;\n const totalSize = data.totalSize;\n\n //TODO: This is temporary until a proper method of displaying\n // them is implmented.\n // ------\n const debug = new LabelingDebug();\n if (DIAMETER_DEBUG) {\n debug.cleanBuffer(imageBuffer);\n }\n // ------\n\n // generate labels\n this.#regenerateLabels(\n imageBuffer,\n unitVectors,\n sizes,\n totalSize\n );\n\n // quantify labels\n const labelsInfo = this.#quantifyLabels(\n imageBuffer,\n unitVectors,\n spacing\n );\n\n // calculate diameters\n const maxDiameters = this.#calculateDiameters(\n imageBuffer,\n unitVectors,\n sizes,\n spacing,\n labelsInfo\n );\n\n //TODO: This is temporary until a proper method of displaying\n // them is implmented.\n // ------\n if (DIAMETER_DEBUG) {\n debug.drawDebugLines(\n imageBuffer,\n unitVectors,\n sizes,\n spacing,\n this.#borders,\n maxDiameters\n );\n }\n // ------\n\n // merge calculations\n const mergedLabelsInfo =\n Object.entries(labelsInfo).map(\n ([label, labelInfo]) => {\n if (typeof maxDiameters[label] !== 'undefined') {\n const diameters = maxDiameters[label];\n\n // Duplicate information\n delete diameters.id;\n delete diameters.zIndex;\n\n // These are in weird units and aren't helpful to pass back\n delete diameters.major.line;\n if (diameters.minor) {\n delete diameters.minor.line;\n }\n\n labelInfo.diameters = diameters;\n }\n\n return labelInfo;\n }\n );\n\n const returnEvent = {\n labels: mergedLabelsInfo,\n };\n\n //TODO: This is temporary until a proper method of displaying\n // them is implmented.\n // ------\n if (DIAMETER_DEBUG) {\n returnEvent.buffer = imageBuffer;\n }\n // ------\n\n return returnEvent;\n }\n} // class labelingFilter\n","/**\n * Labeling filter worker.\n */\n\nimport {LabelingFilter} from './labelingFilter.js';\n\nself.addEventListener('message', function (event) {\n\n const filter = new LabelingFilter();\n if (event.data.segmentSlice) {\n const {segmentSlice: {segNumber, slices},\n totalSize, unitVectors, sizes, spacing} = event.data;\n const sliceSize = unitVectors[unitVectors.length - 1];\n const buf = new Uint8Array(totalSize);\n for (const {sliceIndex, data} of slices) {\n const offset = sliceIndex * sliceSize;\n for (let l = 0; l < data.length; ++l) {\n if (data[l] !== 0) {\n buf[offset + l] = segNumber;\n }\n }\n }\n self.postMessage(filter.run(\n {imageBuffer: buf, unitVectors, sizes, spacing, totalSize}\n ));\n } else {\n self.postMessage(filter.run(event.data));\n }\n\n}, false);\n"],"names":["Point2D","x","y","constructor","this","getX","getY","getValues","getCentroid","equals","rhs","toString","getDistance","point2D","dx","dy","Math","sqrt","LabelingDebug","cleanBuffer","imageBuffer","i","length","sliceWorldToSliceOffset","point","unitVectors","spacing","round","plotLineLow","line","z","p0","getBegin","p1","getEnd","getDeltaX","abs","getDeltaY","D","yi","offset","plotLineHigh","xi","plotPoints","getFlipped","drawDebugLines","sizes","borders","maxDiameters","Object","values","map","diameter","major","zIndex","minor","Line","begin","end","getLength","getWorldLength","spacing2D","wlen","dxs","dys","getMidpoint","getSlope","getIntercept","getInclination","atan2","PI","quantify","viewController","get2DSpacing","worldLength","value","unit","getLengthUnit","LabelingFilter","lastKnownTotalSize","unionFind","labels","find","label","currentLabel","updateLabel","newLabel","union","label1","label2","regenerateLabels","buffer","totalSize","Int32Array","borderOffset","thisOffset","thisValue","xOffset","yOffset","zOffset","xOffsetp","yOffsetp","xValue","yValue","zValue","xValuep","yValuep","xLabel","yLabel","zLabel","offsetToIndex","Array","dimSize","off","floor","quantifyLabels","detailledInfos","o","labelValue","index","info","sliceCounts","id","sum","count","maxZ","minZ","max","min","labelsInfo","detailledInfo","entries","fill","d","largestSliceZ","largest","reduce","largestSlice","largestCount","currentSlice","currentCount","Number","centroidIndex","height","sliceOffsetToSliceWorld","sliceOffset","goodPerpendicularAngle","angle","epsilon","calculateDiameters","labelInfos","borderOffset1","offset1","sliceOffset1","slicePosition1","borderOffset2","offset2","sliceOffset2","slicePosition2","sliceLine","distance","maxDiameter","diameterAngle","angleDifference","isGoodAngle","isReasonableWithoutBetter","angleDiff","run","data","labelInfo","diameters","self","addEventListener","event","filter","segmentSlice","segNumber","slices","sliceSize","buf","Uint8Array","sliceIndex","l","postMessage"],"sourceRoot":""}
1
+ {"version":3,"file":"assets/workers/labeling.worker.min.js","mappings":"AAMO,MAAMA,EAOXC,GAOAC,GAMA,WAAAC,CAAYF,EAAGC,GACbE,MAAKH,EAAKA,EACVG,MAAKF,EAAKA,CACZ,CAOA,IAAAG,GACE,OAAOD,MAAKH,CACd,CAOA,IAAAK,GACE,OAAOF,MAAKF,CACd,CAOA,SAAAK,GACE,MAAO,CAACH,MAAKH,EAAIG,MAAKF,EACxB,CAOA,WAAAM,GACE,OAAOJ,IACT,CAQA,MAAAK,CAAOC,GACL,OAAOA,SAELN,MAAKH,IAAOS,EAAIL,QAChBD,MAAKF,IAAOQ,EAAIJ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Ub,KAAEA,KAASS,EAAQ,CACvC,MAAMzI,EAAS6I,EAAaH,EAC5B,IAAK,IAAII,EAAI,EAAGA,EAAId,EAAKlJ,SAAUgK,EACjB,IAAZd,EAAKc,KACPH,EAAI3I,EAAS8I,GAAKN,EAGxB,CACAL,KAAKY,YAAYT,EAAOP,IACtB,CAACnJ,YAAa+J,EAAK1J,cAAaqB,QAAOpB,UAASkE,cAEpD,MACE+E,KAAKY,YAAYT,EAAOP,IAAIM,EAAML,MAGtC,GAAG","sources":["webpack://dwv/./src/math/point.js","webpack://dwv/./src/image/labelingDebug.js","webpack://dwv/./src/math/line.js","webpack://dwv/./src/image/labelingFilter.js","webpack://dwv/./src/image/labeling.worker.js"],"sourcesContent":["import {isSimilar} from './number.js';\nimport {Vector3D} from './vector.js';\n\n/**\n * Immutable 2D point.\n */\nexport class Point2D {\n\n /**\n * X position.\n *\n * @type {number}\n */\n #x;\n\n /**\n * Y position.\n *\n * @type {number}\n */\n #y;\n\n /**\n * @param {number} x The X coordinate for the point.\n * @param {number} y The Y coordinate for the point.\n */\n constructor(x, y) {\n this.#x = x;\n this.#y = y;\n }\n\n /**\n * Get the X position of the point.\n *\n * @returns {number} The X position of the point.\n */\n getX() {\n return this.#x;\n }\n\n /**\n * Get the Y position of the point.\n *\n * @returns {number} The Y position of the point.\n */\n getY() {\n return this.#y;\n }\n\n /**\n * Get the values of this point.\n *\n * @returns {number[]} The array of values.\n */\n getValues() {\n return [this.#x, this.#y];\n }\n\n /**\n * Get the centroid of the point, ie itself.\n *\n * @returns {Point2D} The centroid point.\n */\n getCentroid() {\n return this;\n }\n\n /**\n * Check for Point2D equality.\n *\n * @param {Point2D} rhs The other point to compare to.\n * @returns {boolean} True if both points are equal.\n */\n equals(rhs) {\n return rhs !== null &&\n typeof rhs !== 'undefined' &&\n this.#x === rhs.getX() &&\n this.#y === rhs.getY();\n }\n\n /**\n * Get a string representation of the Point2D.\n *\n * @returns {string} The point as a string.\n */\n toString() {\n return `(${this.#x}, ${this.#y})`;\n }\n\n /**\n * Get the distance to another Point2D.\n *\n * @param {Point2D} point2D The input point.\n * @returns {number} Ths distance to the input point.\n */\n getDistance(point2D) {\n const dx = this.#x - point2D.getX();\n const dy = this.#y - point2D.getY();\n return Math.sqrt(dx * dx + dy * dy);\n }\n\n} // Point2D class\n\n/**\n * Immutable 3D point.\n */\nexport class Point3D {\n\n /**\n * X position.\n *\n * @type {number}\n */\n #x;\n\n /**\n * Y position.\n *\n * @type {number}\n */\n #y;\n\n /**\n * Z position.\n *\n * @type {number}\n */\n #z;\n\n /**\n * @param {number} x The X coordinate for the point.\n * @param {number} y The Y coordinate for the point.\n * @param {number} z The Z coordinate for the point.\n */\n constructor(x, y, z) {\n this.#x = x;\n this.#y = y;\n this.#z = z;\n }\n\n /**\n * Get the X position of the point.\n *\n * @returns {number} The X position of the point.\n */\n getX() {\n return this.#x;\n }\n\n /**\n * Get the Y position of the point.\n *\n * @returns {number} The Y position of the point.\n */\n getY() {\n return this.#y;\n }\n\n /**\n * Get the Z position of the point.\n *\n * @returns {number} The Z position of the point.\n */\n getZ() {\n return this.#z;\n }\n\n /**\n * Get the values of this point.\n *\n * @returns {number[]} The array of values.\n */\n getValues() {\n return [this.#x, this.#y, this.#z];\n }\n\n /**\n * Check for Point3D equality.\n *\n * @param {Point3D} rhs The other point to compare to.\n * @returns {boolean} True if both points are equal.\n */\n equals(rhs) {\n return rhs !== null &&\n this.#x === rhs.getX() &&\n this.#y === rhs.getY() &&\n this.#z === rhs.getZ();\n }\n\n /**\n * Check for Point3D similarity.\n *\n * @param {Point3D} rhs The other point to compare to.\n * @param {number} [tol] Optional number comparison tolerance,\n * defaults to Number.EPSILON.\n * @returns {boolean} True if both points are similar.\n */\n isSimilar(rhs, tol) {\n return rhs !== null &&\n isSimilar(this.#x, rhs.getX(), tol) &&\n isSimilar(this.#y, rhs.getY(), tol) &&\n isSimilar(this.#z, rhs.getZ(), tol);\n }\n\n /**\n * Get a string representation of the Point3D.\n *\n * @returns {string} The point as a string.\n */\n toString() {\n return `(${ this.#x\n }, ${ this.#y\n }, ${this.#z})`;\n }\n\n /**\n * Get the distance to another Point3D.\n *\n * @param {Point3D} point3D The input point.\n * @returns {number} Ths distance to the input point.\n */\n getDistance(point3D) {\n return Math.sqrt(this.#getSquaredDistance(point3D));\n }\n\n /**\n * Get the square of the distance between this and\n * an input point. Used for sorting.\n *\n * @param {Point3D} point3D The input point.\n * @returns {number} The square of the distance.\n */\n #getSquaredDistance(point3D) {\n const dx = this.#x - point3D.getX();\n const dy = this.#y - point3D.getY();\n const dz = this.#z - point3D.getZ();\n return dx * dx + dy * dy + dz * dz;\n }\n\n /**\n * Get the closest point to this in a Point3D list.\n *\n * @param {Point3D[]} pointList The list to check.\n * @returns {number} The index of the closest point in the input list.\n */\n getClosest(pointList) {\n let minIndex = 0;\n // the order between squared distances and distances is the same\n let minDist = this.#getSquaredDistance(pointList[minIndex]);\n for (let i = 0; i < pointList.length; ++i) {\n const dist = this.#getSquaredDistance(pointList[i]);\n if (dist < minDist) {\n minIndex = i;\n minDist = dist;\n }\n }\n return minIndex;\n }\n\n /**\n * Get the difference to another Point3D.\n *\n * @param {Point3D} point3D The input point.\n * @returns {Vector3D} The 3D vector from the input point to this one.\n */\n minus(point3D) {\n return new Vector3D(\n (this.#x - point3D.getX()),\n (this.#y - point3D.getY()),\n (this.#z - point3D.getZ()));\n }\n\n} // Point3D class\n\n/**\n * Get an array find callback for an equal input point.\n *\n * @param {Point3D} point The point to compare to.\n * @returns {(element: Point3D) => boolean} A function that compares,\n * using `equals`, its input point to the one given as input to\n * this function.\n */\nexport function getEqualPoint3DFunction(point) {\n return function (element) {\n return element.equals(point);\n };\n}\n\n/**\n * Check if an array of Point3D includes a given one.\n *\n * @param {Point3D[]} arr The array of Point3D.\n * @param {Point3D} val The Point3D to look for.\n * @returns {boolean} True if included.\n */\nexport function includesPoint3D(arr, val) {\n return arr.some(function (arrVal) {\n return val.equals(arrVal);\n });\n}\n\n/**\n * Create a {@link Point3D} from an array.\n *\n * @param {number[]} arr The input array.\n * @returns {Point3D} The point.\n */\nexport function point3DFromArray(arr) {\n return new Point3D(arr[0], arr[1], arr[2]);\n}\n\n/**\n * Immutable point.\n * Warning: the input array is NOT cloned, modifying it will\n * modify the point values.\n */\nexport class Point {\n\n /**\n * Point values.\n *\n * @type {number[]}\n */\n #values;\n\n /**\n * @param {number[]} values The point values.\n */\n constructor(values) {\n if (!values || typeof values === 'undefined') {\n throw new Error('Cannot create point with no values.');\n }\n if (values.length === 0) {\n throw new Error('Cannot create point with empty values.');\n }\n const valueCheck = function (val) {\n return !isNaN(val);\n };\n if (!values.every(valueCheck)) {\n throw new Error('Cannot create point with non number values.');\n }\n this.#values = values;\n }\n\n /**\n * Get the point value at the given array index.\n *\n * @param {number} i The index to get.\n * @returns {number} The value.\n */\n get(i) {\n return this.#values[i];\n }\n\n /**\n * Get the length of the point.\n *\n * @returns {number} The length.\n */\n length() {\n return this.#values.length;\n }\n\n /**\n * Get a string representation of the point.\n *\n * @returns {string} The point as a string.\n */\n toString() {\n return `(${this.#values.toString()})`;\n }\n\n /**\n * Get the values of this point.\n *\n * @returns {number[]} The array of values.\n */\n getValues() {\n return this.#values.slice();\n }\n\n /**\n * Check if the input point can be compared to this one.\n *\n * @param {Point} rhs The point to compare to.\n * @returns {boolean} True if both points are comparable.\n */\n canCompare(rhs) {\n // check input\n if (!rhs) {\n return false;\n }\n // check length\n if (this.length() !== rhs.length()) {\n return false;\n }\n // seems ok!\n return true;\n }\n\n /**\n * Check for Point equality.\n *\n * @param {Point} rhs The point to compare to.\n * @returns {boolean} True if both points are equal.\n */\n equals(rhs) {\n // check if can compare\n if (!this.canCompare(rhs)) {\n return false;\n }\n // check values\n for (let i = 0, leni = this.length(); i < leni; ++i) {\n if (this.get(i) !== rhs.get(i)) {\n return false;\n }\n }\n // seems ok!\n return true;\n }\n\n /**\n * Compare points and return different dimensions.\n *\n * @param {Point} rhs The point to compare to.\n * @returns {number[]} The list of different dimensions.\n */\n compare(rhs) {\n // check if can compare\n if (!this.canCompare(rhs)) {\n return null;\n }\n // check values\n const diffDims = [];\n for (let i = 0, leni = this.length(); i < leni; ++i) {\n if (this.get(i) !== rhs.get(i)) {\n diffDims.push(i);\n }\n }\n return diffDims;\n }\n\n /**\n * Get the 3D part of this point.\n *\n * @returns {Point3D} The Point3D.\n */\n get3D() {\n return new Point3D(this.get(0), this.get(1), this.get(2));\n }\n\n /**\n * Add another point to this one.\n *\n * @param {Point} rhs The point to add.\n * @returns {Point} The point representing the sum of both points.\n */\n add(rhs) {\n // check if can compare\n if (!this.canCompare(rhs)) {\n return null;\n }\n const values = [];\n const values0 = this.getValues();\n const values1 = rhs.getValues();\n for (let i = 0; i < values0.length; ++i) {\n values.push(values0[i] + values1[i]);\n }\n return new Point(values);\n }\n\n /**\n * Merge this point with a Point3D to create a new point.\n *\n * @param {Point3D} rhs The Point3D to merge with.\n * @returns {Point} The merge result.\n */\n mergeWith3D(rhs) {\n const values = this.getValues();\n values[0] = rhs.getX();\n values[1] = rhs.getY();\n values[2] = rhs.getZ();\n return new Point(values);\n }\n\n} // Point class\n","import {Point2D} from '../math/point.js';\n\n/**\n * @import {Line} from '../math/line.js';\n */\n\n/**\n * Helper for the LabelingFilter, provides a debug display for diameters and\n * contours.\n *\n * Temporary until a proper way of rendering them is added.\n */\nexport class LabelingDebug {\n\n /**\n * Cleans buffer of debug lines before calculations.\n *\n * @param {Uint8Array} imageBuffer The image buffer to clean.\n */\n cleanBuffer(imageBuffer) {\n for (let i = 0; i < imageBuffer.length; i++) {\n if (imageBuffer[i] >= 128) {\n imageBuffer[i] = imageBuffer[i] - 128;\n }\n }\n }\n\n /**\n * Convert a slice local world coordinate to a slice local offset value.\n *\n * @param {Point2D} point Point on the slice, scaled.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n *\n * @returns {number} Offset relative to the offset at the start of the slice.\n */\n #sliceWorldToSliceOffset(point, unitVectors, spacing) {\n const offset =\n (unitVectors[0] * Math.round(point.getX() / spacing[0])) +\n (unitVectors[1] * Math.round(point.getY() / spacing[1]));\n\n return offset;\n }\n\n /**\n * Draw a debug line segment of an angle less that 45 degrees.\n * Points should be in slice world space.\n *\n * @param {Uint8Array} imageBuffer The image buffer to draw debug lines on.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {Line} line The line segment to plot.\n * @param {number} z The slice index.\n */\n #plotLineLow(imageBuffer, unitVectors, spacing, line, z) {\n const p0 = line.getBegin();\n const p1 = line.getEnd();\n const dx = line.getDeltaX();\n const dy = Math.abs(line.getDeltaY());\n let D = 2 * dy - dx;\n let y = p0.getY();\n const yi = (p0.getY() < p1.getY()) ? 1 : -1;\n\n for (let x = p0.getX(); x <= p1.getX(); x++) {\n const sliceOffset =\n this.#sliceWorldToSliceOffset(new Point2D(x, y), unitVectors, spacing);\n const offset = sliceOffset + (unitVectors[2] * z);\n imageBuffer[offset] = imageBuffer[offset] + 128;\n\n if (D > 0) {\n y = y + yi;\n D = D - 2 * dx;\n }\n D = D + 2 * dy;\n }\n }\n\n /**\n * Draw a debug line segment of an angle greater that 45 degrees.\n * Points should be in slice world space.\n *\n * @param {Uint8Array} imageBuffer The image buffer to draw debug lines on.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {Line} line The line segment to plot.\n * @param {number} z The slice index.\n */\n #plotLineHigh(imageBuffer, unitVectors, spacing, line, z) {\n const p0 = line.getBegin();\n const p1 = line.getEnd();\n const dx = Math.abs(line.getDeltaX());\n const dy = line.getDeltaY();\n let D = 2 * dx - dy;\n let x = p0.getX();\n const xi = (p0.getX() < p1.getX()) ? 1 : -1;\n\n for (let y = p0.getY(); y <= p1.getY(); y++) {\n const sliceOffset =\n this.#sliceWorldToSliceOffset(new Point2D(x, y), unitVectors, spacing);\n const offset = sliceOffset + (unitVectors[2] * z);\n imageBuffer[offset] = imageBuffer[offset] + 128;\n\n if (D > 0) {\n x = x + xi;\n D = D - 2 * dy;\n }\n D = D + 2 * dx;\n }\n }\n\n /**\n * Draw a debug line segment.\n * Points should be in slice world space.\n *\n * @param {Uint8Array} imageBuffer The image buffer to draw debug lines on.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {Line} line The line segment to plot.\n * @param {number} z The slice index.\n */\n #plotPoints(imageBuffer, unitVectors, spacing, line, z) {\n const p0 = line.getBegin();\n const p1 = line.getEnd();\n if (Math.abs(line.getDeltaY()) < Math.abs(line.getDeltaX())) {\n if (p0.getX() < p1.getX()) {\n this.#plotLineLow(\n imageBuffer,\n unitVectors,\n spacing,\n line,\n z\n );\n } else {\n this.#plotLineLow(\n imageBuffer,\n unitVectors,\n spacing,\n line.getFlipped(),\n z\n );\n }\n } else if (p0.getY() < p1.getY()) {\n this.#plotLineHigh(\n imageBuffer,\n unitVectors,\n spacing,\n line,\n z\n );\n } else {\n this.#plotLineHigh(\n imageBuffer,\n unitVectors,\n spacing,\n line.getFlipped(),\n z\n );\n }\n }\n\n /**\n * Renders debug lines for contours and diameters.\n * The pixel value of the debug lines are the segmentation label of the\n * segment + 128.\n *\n * @param {Uint8Array} imageBuffer The image buffer to draw debug lines on.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} sizes The image dimensions.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {Int32Array} borders The buffer containing the border pixel arrays.\n * @param {object} maxDiameters The dictionary of calculated diameters.\n */\n drawDebugLines(\n imageBuffer,\n unitVectors,\n sizes,\n spacing,\n borders,\n maxDiameters\n ) {\n Object.values(maxDiameters).map((diameter) => {\n this.#plotPoints(\n imageBuffer,\n unitVectors,\n spacing,\n diameter.major.line,\n diameter.zIndex\n );\n\n if (typeof diameter.minor !== 'undefined') {\n this.#plotPoints(\n imageBuffer,\n unitVectors,\n spacing,\n diameter.minor.line,\n diameter.zIndex\n );\n }\n });\n }\n\n} //class LabelingDebug","import {Point2D} from './point.js';\nimport {\n isSimilar,\n REAL_WORLD_EPSILON,\n} from './number.js';\n\n/**\n * @import {ViewController} from '../app/viewController.js';\n * @import {Scalar2D} from './scalar.js';\n * @import {NumberValue} from './number.js';\n */\n\n/**\n * Line shape.\n */\nexport class Line {\n\n /**\n * Line begin point.\n *\n * @type {Point2D}\n */\n #begin;\n\n /**\n * Line end point.\n *\n * @type {Point2D}\n */\n #end;\n\n /**\n * @param {Point2D} begin A Point2D representing the beginning\n * of the line.\n * @param {Point2D} end A Point2D representing the end of the line.\n */\n constructor(begin, end) {\n this.#begin = begin;\n this.#end = end;\n }\n\n /**\n * Get the begin point of the line.\n *\n * @returns {Point2D} The beginning point of the line.\n */\n getBegin() {\n return this.#begin;\n }\n\n /**\n * Get the end point of the line.\n *\n * @returns {Point2D} The ending point of the line.\n */\n getEnd() {\n return this.#end;\n }\n\n /**\n * Check for equality.\n *\n * @param {Line} rhs The object to compare to.\n * @returns {boolean} True if both objects are equal.\n */\n equals(rhs) {\n return rhs !== null &&\n this.getBegin().equals(rhs.getBegin()) &&\n this.getEnd().equals(rhs.getEnd());\n }\n\n /**\n * Get the line delta in the X direction.\n *\n * @returns {number} The delta in the X direction.\n */\n getDeltaX() {\n return this.getEnd().getX() - this.getBegin().getX();\n }\n\n /**\n * Get the line delta in the Y direction.\n *\n * @returns {number} The delta in the Y direction.\n */\n getDeltaY() {\n return this.getEnd().getY() - this.getBegin().getY();\n }\n\n /**\n * Get the length of the line.\n *\n * @returns {number} The length of the line.\n */\n getLength() {\n return Math.sqrt(\n this.getDeltaX() * this.getDeltaX() +\n this.getDeltaY() * this.getDeltaY()\n );\n }\n\n /**\n * Get the length of the line according to a spacing.\n *\n * @param {Scalar2D} spacing2D The 2D spacing.\n * @returns {number} The length of the line with spacing\n * or null for null spacings.\n */\n getWorldLength(spacing2D) {\n let wlen = null;\n if (spacing2D !== null) {\n const dxs = this.getDeltaX() * spacing2D.x;\n const dys = this.getDeltaY() * spacing2D.y;\n wlen = Math.sqrt(dxs * dxs + dys * dys);\n }\n return wlen;\n }\n\n /**\n * Get the mid point of the line.\n *\n * @returns {Point2D} The mid point of the line.\n * @deprecated Since v0.36, please use getCentroid instead.\n */\n getMidpoint() {\n return this.getCentroid();\n }\n\n /**\n * Get the centroid of the line.\n *\n * @returns {Point2D} THe centroid point.\n */\n getCentroid() {\n return new Point2D(\n (this.getBegin().getX() + this.getEnd().getX()) / 2,\n (this.getBegin().getY() + this.getEnd().getY()) / 2\n );\n }\n\n /**\n * Get the slope of the line.\n *\n * @returns {number} The slope of the line.\n */\n getSlope() {\n return this.getDeltaY() / this.getDeltaX();\n }\n\n /**\n * Get the intercept of the line.\n *\n * @returns {number} The slope of the line.\n */\n getIntercept() {\n return (\n this.getEnd().getX() * this.getBegin().getY() -\n this.getBegin().getX() * this.getEnd().getY()\n ) / this.getDeltaX();\n }\n\n /**\n * Get the inclination of the line.\n *\n * @returns {number} The inclination of the line.\n */\n getInclination() {\n // tan(theta) = slope\n const angle =\n Math.atan2(this.getDeltaY(), this.getDeltaX()) * 180 / Math.PI;\n // shift?\n return 180 - angle;\n }\n\n /**\n * Get a new line with the start and end flipped.\n *\n * @returns {Line} The new flipped line.\n */\n getFlipped() {\n return new Line(this.#end, this.#begin);\n }\n\n /**\n * Quantify a line according to view information.\n *\n * @param {ViewController} viewController The associated view controller.\n * @returns {Record<string, NumberValue>} A quantification object.\n */\n quantify(viewController) {\n // length\n const spacing2D = viewController.get2DSpacing();\n const worldLength = this.getWorldLength(spacing2D);\n let length;\n if (worldLength !== null) {\n length = {\n value: worldLength,\n unit: viewController.getLengthUnit()\n };\n }\n // return\n return {length};\n }\n\n} // Line class\n\n/**\n * Get the angle between two lines in degree.\n *\n * @param {Line} line0 The first line.\n * @param {Line} line1 The second line.\n * @returns {number} The angle.\n */\nexport function getAngle(line0, line1) {\n const dx0 = line0.getDeltaX();\n const dy0 = line0.getDeltaY();\n const dx1 = line1.getDeltaX();\n const dy1 = line1.getDeltaY();\n // dot = ||a||*||b||*cos(theta)\n const dot = dx0 * dx1 + dy0 * dy1;\n // cross = ||a||*||b||*sin(theta)\n const det = dx0 * dy1 - dy0 * dx1;\n // tan = sin / cos\n const angle = Math.atan2(det, dot) * 180 / Math.PI;\n // complementary angle\n // shift?\n return 360 - (180 - angle);\n}\n\n/**\n * Check if two lines are orthogonal.\n *\n * @param {Line} line0 The first line.\n * @param {Line} line1 The second line.\n * @returns {boolean} True if both lines are orthogonal.\n */\nexport function areOrthogonal(line0, line1) {\n const dx0 = line0.getDeltaX();\n const dy0 = line0.getDeltaY();\n const dx1 = line1.getDeltaX();\n const dy1 = line1.getDeltaY();\n // dot = ||a||*||b||*cos(theta)\n return (dx0 * dx1 + dy0 * dy1) === 0;\n}\n\n/**\n * Check if a point is in a line coordinate range.\n *\n * @param {Point2D} point The input point.\n * @param {Line} line The input line.\n * @returns {boolean} True if the input point is in the line coordinate range.\n */\nexport function isPointInLineRange(point, line) {\n const minX = Math.min(line.getBegin().getX(), line.getEnd().getX());\n const maxX = Math.max(line.getBegin().getX(), line.getEnd().getX());\n const minY = Math.min(line.getBegin().getY(), line.getEnd().getY());\n const maxY = Math.max(line.getBegin().getY(), line.getEnd().getY());\n return point.getX() >= minX &&\n point.getX() <= maxX &&\n point.getY() >= minY &&\n point.getY() <= maxY;\n}\n\n/**\n * Get a perpendicular line to an input one at a given point.\n *\n * @param {Line} line The line to be perpendicular to.\n * @param {Point2D} point The middle point of the perpendicular line.\n * @param {number} length The length of the perpendicular line.\n * @param {Scalar2D} [spacing] Optional image spacing, default to [1,1].\n * @returns {Line} The perpendicular line.\n */\nexport function getPerpendicularLine(line, point, length, spacing) {\n if (typeof spacing === 'undefined') {\n spacing = {x: 1, y: 1};\n }\n const sx2 = spacing.x * spacing.x;\n const sy2 = spacing.y * spacing.y;\n // a0 * a1 = -1 (in square space)\n const perpSlope = -sx2 / (sy2 * line.getSlope());\n // y0 = a1*x0 + b1 -> b1 = y0 - a1*x0\n const prepIntercept = point.getY() - perpSlope * point.getX();\n // return\n return getLineFromEquation(perpSlope, prepIntercept, point, length, spacing);\n}\n\n/**\n * Get a perpendicular line to an input one at a given distance\n * of its begin point.\n *\n * @param {Line} line The line to be perpendicular to.\n * @param {number} distance The distance to the input line begin point.\n * @param {number} length The length of the perpendicular line.\n * @param {Scalar2D} [spacing] Optional image spacing, default to [1,1].\n * @returns {Line} The perpendicular line.\n */\nexport function getPerpendicularLineAtDistance(\n line, distance, length, spacing) {\n // get a line along the input one and centered on begin point\n const lineFromEq = getLineFromEquation(\n line.getSlope(),\n line.getIntercept(),\n line.getBegin(),\n distance,\n spacing\n );\n // select the point on the input line\n let startPoint;\n if (isPointInLineRange(lineFromEq.getBegin(), line)) {\n startPoint = lineFromEq.getBegin();\n } else {\n startPoint = lineFromEq.getEnd();\n }\n // use it as base for a perpendicular line\n return getPerpendicularLine(line, startPoint, length, spacing);\n}\n\n/**\n * Get a line from an equation, a middle point and a length.\n *\n * @param {number} slope The line slope.\n * @param {number} intercept The line intercept.\n * @param {Point2D} point The middle point of the line.\n * @param {number} length The line length.\n * @param {Scalar2D} [spacing] Optional image spacing, default to [1,1].\n * @returns {Line} The resulting line.\n */\nexport function getLineFromEquation(slope, intercept, point, length, spacing) {\n if (typeof spacing === 'undefined') {\n spacing = {x: 1, y: 1};\n }\n // begin point\n let beginX;\n let beginY;\n // end point\n let endX;\n let endY;\n\n if (isSimilar(slope, 0, REAL_WORLD_EPSILON)) {\n // slope = ~0 -> horizontal input line\n beginX = point.getX() - length / (2 * spacing.x);\n beginY = point.getY();\n endX = point.getX() + length / (2 * spacing.x);\n endY = point.getY();\n } else if (Math.abs(slope) > 1e6) {\n // slope = ~(+/-)Infinity -> vertical input line\n beginX = point.getX();\n beginY = point.getY() - length / (2 * spacing.y);\n endX = point.getX();\n endY = point.getY() + length / (2 * spacing.y);\n } else {\n const sx2 = spacing.x * spacing.x;\n const sy2 = spacing.y * spacing.y;\n\n // 1. [length] sx^2 * (x - x0)^2 + sy^2 * (y - y0)^2 = d^2\n // 2. [slope] a = (y - y0) / (x - x0) -> y - y0 = a*(x - x0)\n // -> sx^2 * (x - x0)^2 + sy^2 * a^2 * (x - x0)^2 = d^2\n // -> (x - x0)^2 = d^2 / (sx^2 + sy^2 * a^2)\n // -> x = x0 +- d / sqrt(sx^2 + sy^2 * a^2)\n\n // length is the distance between begin and end,\n // point is half way between both -> d = length / 2\n const dx = length / (2 * Math.sqrt(sx2 + sy2 * slope * slope));\n\n // begin point\n beginX = point.getX() - dx;\n beginY = slope * beginX + intercept;\n // end point\n endX = point.getX() + dx;\n endY = slope * endX + intercept;\n }\n return new Line(\n new Point2D(beginX, beginY),\n new Point2D(endX, endY));\n}\n","import {LabelingDebug} from './labelingDebug.js';\nimport {Point2D} from '../math/point.js';\nimport {Line} from '../math/line.js';\n\n// Set this to true to show the debug contour and diameter display\nconst DIAMETER_DEBUG = false;\n\n/**\n * Filter for calculating labels.\n *\n * Labels a buffer using the Hoshen–Kopelman\n * algorithm to first label all of the connected components, then does\n * a second pass to count the number of voxels in each unique label.\n *\n * The Hoshen–Kopelman labelling is slightly modified to work with\n * non-binary 3D data, but is otherwise structured the same way.\n *\n * Ref: {@link https://en.wikipedia.org/wiki/Hoshen%E2%80%93Kopelman_algorithm}.\n */\nexport class LabelingFilter {\n /**\n * The last known image size.\n *\n * @type {number}\n */\n #lastKnownTotalSize;\n\n /**\n * A union-find (disjoint-set) representing the available labels.\n *\n * @type {Int32Array}\n */\n #unionFind;\n\n /**\n * A buffer containing the labels for each voxel.\n *\n * @type {Int32Array}\n */\n #labels;\n\n /**\n * A buffer containing a list of border pixels for each layer.\n *\n * @type {Int32Array}\n */\n #borders;\n\n /**\n * Union-find find operation.\n * Ref: {@link https://en.wikipedia.org/wiki/Disjoint-set_data_structure}.\n *\n * @param {number} label The label to find the root of.\n * @returns {number} The root label.\n */\n #find(label) {\n if (label < 0) {\n return label;\n }\n\n // Find the root label\n let currentLabel = label;\n while (this.#unionFind[currentLabel] !== currentLabel) {\n currentLabel = this.#unionFind[currentLabel];\n }\n\n // Do an update pass to make this faster next time\n let updateLabel = label;\n while (this.#unionFind[updateLabel] !== updateLabel) {\n const newLabel = this.#unionFind[updateLabel];\n this.#unionFind[updateLabel] = currentLabel;\n updateLabel = newLabel;\n }\n\n return currentLabel;\n }\n\n /**\n * Union-find union operation.\n *\n * @param {number} label1 The child label to union.\n * @param {number} label2 The parent label to union.\n */\n #union(label1, label2) {\n // This will break if a non-label (-1) get passed in\n // however with the current implmentation this should never happen\n this.#unionFind[this.#find(label1)] = this.#find(label2);\n }\n\n /**\n * Label the buffer using the Hoshen–Kopelman algorithm.\n *\n * @param {Uint8Array} buffer The image buffer to regenerate the labels for.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} sizes The image dimensions.\n * @param {number} totalSize The total length of the buffer.\n */\n #regenerateLabels(buffer, unitVectors, sizes, totalSize) {\n // If we are re-calcing the labels of the same sized image as last time we\n // can save a little time on re-initializing memory. Makes it slightly\n // faster to use a seperate worker object per segmentation, at the\n // cost of extra memory.\n if (typeof this.#lastKnownTotalSize === 'undefined' ||\n this.#lastKnownTotalSize !== totalSize) {\n // The size of the image has changed, we need to reinitialize everything.\n this.#lastKnownTotalSize = totalSize;\n\n // Performance trade-off means this can use a fair bit of memory\n // on large images.\n this.#unionFind = new Int32Array(totalSize);\n this.#labels = new Int32Array(totalSize);\n this.#borders = new Int32Array(totalSize);\n }\n\n // Generate the Hoshen–Kopelman labels\n for (let z = 0; z < sizes[2]; z++) {\n\n let borderOffset = 0;\n\n for (let x = 0; x < sizes[0]; x++) {\n for (let y = 0; y < sizes[1]; y++) {\n\n const thisOffset =\n (unitVectors[0] * x) +\n (unitVectors[1] * y) +\n (unitVectors[2] * z);\n\n // Reset labels.\n this.#unionFind[thisOffset] = thisOffset;\n this.#labels[thisOffset] = -1;\n\n const thisValue = buffer[thisOffset];\n\n if (thisValue > 0) {\n // Neighbor offsets\n const xOffset = thisOffset - unitVectors[0];\n const yOffset = thisOffset - unitVectors[1];\n const zOffset = thisOffset - unitVectors[2];\n\n const xOffsetp = thisOffset + unitVectors[0];\n const yOffsetp = thisOffset + unitVectors[1];\n\n // Neighbor values\n let xValue = 0;\n if (x > 0) {\n xValue = buffer[xOffset];\n };\n let yValue = 0;\n if (y > 0) {\n yValue = buffer[yOffset];\n };\n let zValue = 0;\n if (z > 0) {\n zValue = buffer[zOffset];\n };\n\n let xValuep = 0;\n if (x < sizes[0] - 1) {\n xValuep = buffer[xOffsetp];\n };\n let yValuep = 0;\n if (y < sizes[1] - 1) {\n yValuep = buffer[yOffsetp];\n };\n\n // Neighbor labels\n let xLabel = 0;\n if (x > 0) {\n xLabel = this.#labels[xOffset];\n };\n let yLabel = 0;\n if (y > 0) {\n yLabel = this.#labels[yOffset];\n };\n let zLabel = 0;\n if (z > 0) {\n zLabel = this.#labels[zOffset];\n };\n\n // No neighbors with matching values\n if (\n xValue !== thisValue &&\n yValue !== thisValue &&\n zValue !== thisValue\n ) {\n this.#labels[thisOffset] = thisOffset; // Guaranteed unique label.\n\n // One neighbor with matching values\n } else if (\n xValue === thisValue &&\n yValue !== thisValue &&\n zValue !== thisValue\n ) {\n this.#labels[thisOffset] = this.#find(xLabel);\n } else if (\n xValue !== thisValue &&\n yValue === thisValue &&\n zValue !== thisValue\n ) {\n this.#labels[thisOffset] = this.#find(yLabel);\n } else if (\n xValue !== thisValue &&\n yValue !== thisValue &&\n zValue === thisValue\n ) {\n this.#labels[thisOffset] = this.#find(zLabel);\n\n // Two neighbor with matching values\n } else if (\n xValue !== thisValue &&\n yValue === thisValue &&\n zValue === thisValue\n ) {\n this.#union(yLabel, zLabel);\n this.#labels[thisOffset] = this.#find(yLabel);\n } else if (\n xValue === thisValue &&\n yValue !== thisValue &&\n zValue === thisValue\n ) {\n this.#union(xLabel, zLabel);\n this.#labels[thisOffset] = this.#find(xLabel);\n } else if (\n xValue === thisValue &&\n yValue === thisValue &&\n zValue !== thisValue\n ) {\n this.#union(xLabel, yLabel);\n this.#labels[thisOffset] = this.#find(xLabel);\n\n // All neighbors with matching values\n } else if (\n xValue === thisValue &&\n yValue === thisValue &&\n zValue === thisValue\n ) {\n this.#union(xLabel, yLabel);\n this.#union(xLabel, zLabel);\n this.#labels[thisOffset] = this.#find(xLabel);\n }\n\n // Border check\n if (\n xValue !== thisValue ||\n yValue !== thisValue ||\n xValuep !== thisValue ||\n yValuep !== thisValue\n ) {\n this.#borders[(unitVectors[2] * z) + borderOffset] = thisOffset;\n borderOffset++;\n }\n }\n }\n }\n\n this.#borders[(unitVectors[2] * z) + borderOffset] = -1;\n\n }\n }\n\n /**\n * Convert an offset in memory to an index.\n *\n * @param {number} offset The offset to convert.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @returns {number[]} The index.\n */\n #offsetToIndex(offset, unitVectors) {\n const values = new Array(unitVectors.length);\n let off = offset;\n let dimSize;\n for (let i = unitVectors.length - 1; i > 0; --i) {\n dimSize = unitVectors[i];\n values[i] = Math.floor(off / dimSize);\n off = off - values[i] * dimSize;\n }\n values[0] = off;\n return values;\n }\n\n /**\n * Quantify labels: count items, calculate centroid, and calculate height.\n *\n * @param {Uint8Array} buffer The image buffer to quantify the labels for.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n *\n * @returns {object} The dictionary of quantified labels.\n */\n #quantifyLabels(\n buffer,\n unitVectors,\n spacing\n ) {\n const detailledInfos = {};\n\n // Count the number of voxels per unique label,\n // this has to be done as a second pass.\n for (let o = 0; o < this.#labels.length; o++) {\n const labelValue = this.#find(this.#labels[o]);\n\n if (labelValue >= 0) {\n const index = this.#offsetToIndex(o, unitVectors);\n const info = detailledInfos[labelValue];\n if (typeof info === 'undefined') {\n const sliceCounts = {};\n sliceCounts[index[2]] = 1;\n detailledInfos[labelValue] = {\n id: buffer[o],\n sum: index,\n count: 1,\n sliceCounts,\n maxZ: index[2],\n minZ: index[2]\n };\n } else {\n info.sum[0] += index[0];\n info.sum[1] += index[1];\n info.sum[2] += index[2];\n info.count++;\n if (typeof info.sliceCounts[index[2]] !== 'undefined') {\n info.sliceCounts[index[2]]++;\n } else {\n info.sliceCounts[index[2]] = 1;\n }\n info.maxZ = Math.max(info.maxZ, index[2]);\n info.minZ = Math.min(info.minZ, index[2]);\n }\n }\n }\n\n const labelsInfo = {};\n\n for (const [label, detailledInfo] of Object.entries(detailledInfos)) {\n const index = Array(detailledInfo.sum.length).fill(0);\n for (let d = 0; d < detailledInfo.sum.length; d++) {\n index[d] = detailledInfo.sum[d] / detailledInfo.count;\n }\n\n const sliceCounts = Object.entries(detailledInfo.sliceCounts);\n const largestSliceZ = (() => {\n if (sliceCounts.length > 1) {\n const largest =\n sliceCounts\n .reduce((\n [largestSlice, largestCount],\n [currentSlice, currentCount]\n ) => {\n if (currentCount > largestCount) {\n return [currentSlice, currentCount];\n }\n return [largestSlice, largestCount];\n })[0];\n return Number(largest);\n }\n return Number(sliceCounts[0][0]);\n })();\n\n labelsInfo[label] = {\n id: detailledInfo.id,\n centroidIndex: index,\n count: detailledInfo.count,\n largestSliceZ,\n height: (detailledInfo.maxZ - detailledInfo.minZ + 1) * spacing[2]\n };\n }\n\n return labelsInfo;\n }\n\n /**\n * Convert a slice local offset value to a slice local world coordinate.\n *\n * @param {number} sliceOffset Offset relative to the offset at the\n * start of the slice.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} spacing The pixel spacing of the image.\n *\n * @returns {Point2D} Point on the slice, scaled.\n */\n #sliceOffsetToSliceWorld(sliceOffset, unitVectors, spacing) {\n let x;\n let y;\n if (unitVectors[0] > unitVectors[1]) {\n y = (sliceOffset % unitVectors[0]) / unitVectors[1];\n x = Math.floor(sliceOffset / unitVectors[0]);\n } else {\n x = (sliceOffset % unitVectors[1]) / unitVectors[0];\n y = Math.floor(sliceOffset / unitVectors[1]);\n }\n\n x = x * spacing[0];\n y = y * spacing[1];\n\n return new Point2D(x, y);\n }\n\n /**\n * Check if an angle is reasonably close to 90 degrees.\n *\n * @param {number} angle The angle to test.\n * @param {number} epsilon How close to 90 degrees it needs to be.\n * @returns {boolean} Is the angle close enough to 90 degrees.\n */\n #goodPerpendicularAngle(angle, epsilon) {\n return angle > (90 - epsilon) && angle < (90 + epsilon);\n }\n\n /**\n * Calculate the major and minor (perpendicular) diameters of each segment.\n *\n * @param {Uint8Array} buffer The image buffer to calculate diameters for.\n * @param {number[]} unitVectors The unit vectors for index to offset\n * conversion.\n * @param {number[]} sizes The image dimensions.\n * @param {number[]} spacing The pixel spacing of the image.\n * @param {object} labelInfos The quantified labelInfos of the segments.\n *\n * @returns {object} The dictionary of calculated diameters.\n */\n #calculateDiameters(\n buffer,\n unitVectors,\n sizes,\n spacing,\n labelInfos\n ) {\n const maxDiameters = {};\n\n // Get the major diameter\n for (let z = 0; z < sizes[2]; z++) {\n const zOffset = unitVectors[2] * z;\n\n // TODO: It would be more efficient to calculate the convex hull, use\n // rotating calipers to get antipodal points, and then calculate the\n // major diameter from those.\n // For now the naive way is fast enough for an initial implementation.\n\n let borderOffset1 = 0;\n while (this.#borders[zOffset + borderOffset1] >= 0) {\n const offset1 = this.#borders[zOffset + borderOffset1];\n const label1 = this.#find(this.#labels[offset1]);\n\n // We only care about the diameter of the largest slice,\n // we can skip everything else.\n if (\n typeof labelInfos[label1] !== 'undefined' &&\n labelInfos[label1].largestSliceZ === z\n ) {\n const sliceOffset1 = offset1 - zOffset;\n const slicePosition1 =\n this.#sliceOffsetToSliceWorld(sliceOffset1, unitVectors, spacing);\n\n let borderOffset2 = 0;\n while (this.#borders[zOffset + borderOffset2] >= 0) {\n const offset2 = this.#borders[zOffset + borderOffset2];\n const label2 = this.#find(this.#labels[offset2]);\n\n if (label1 === label2) {\n const sliceOffset2 = offset2 - zOffset;\n const slicePosition2 =\n this.#sliceOffsetToSliceWorld(\n sliceOffset2,\n unitVectors,\n spacing\n );\n\n const sliceLine = new Line(slicePosition1, slicePosition2);\n const distance = sliceLine.getLength();\n\n const maxDiameter = maxDiameters[label1];\n if (\n typeof maxDiameter === 'undefined' ||\n maxDiameter.major.diameter < distance\n ) {\n maxDiameters[label1] = {\n id: buffer[offset1],\n major: {\n diameter: distance,\n line: sliceLine,\n offset1,\n offset2,\n },\n zIndex: z\n };\n }\n }\n\n borderOffset2++;\n }\n\n }\n\n borderOffset1++;\n }\n }\n\n // Get the minor (perpendicular) diameter\n for (const [label, diameter] of Object.entries(maxDiameters)) {\n const zOffset = unitVectors[2] * diameter.zIndex;\n const diameterLine = diameter.major.line;\n const diameterAngle = diameterLine.getInclination();\n\n // TODO: This could also be made faster by using a modified antipodal\n // point algorithm that uses perpedicularity to the initial diameter\n // instead of parallel tangents (we can't use the convex hull for this\n // one, so the normal algorithm doesn't work).\n // For now the naive way is fast enough for an initial implementation.\n\n let borderOffset1 = 0;\n while (this.#borders[zOffset + borderOffset1] >= 0) {\n const offset1 = this.#borders[zOffset + borderOffset1];\n const label1 = this.#find(this.#labels[offset1]);\n\n if (label1.toString() !== label) {\n borderOffset1++;\n continue;\n }\n\n const sliceOffset1 = offset1 - zOffset;\n const slicePosition1 =\n this.#sliceOffsetToSliceWorld(sliceOffset1, unitVectors, spacing);\n\n let borderOffset2 = 0;\n while (this.#borders[zOffset + borderOffset2] >= 0) {\n const offset2 = this.#borders[zOffset + borderOffset2];\n const label2 = this.#find(this.#labels[offset2]);\n if (label2.toString() === label && label1 === label2) {\n const sliceOffset2 = offset2 - zOffset;\n const slicePosition2 =\n this.#sliceOffsetToSliceWorld(\n sliceOffset2,\n unitVectors,\n spacing\n );\n\n // Check angle for perpendicularity\n const sliceLine = new Line(slicePosition1, slicePosition2);\n const angle = sliceLine.getInclination();\n\n const angleDifference = Math.abs(angle - diameterAngle);\n\n const distance = sliceLine.getLength();\n\n const isGoodAngle =\n this.#goodPerpendicularAngle(angleDifference, 0.5);\n\n // If we can't find any angles close to 90 degrees then\n // prioritize finding something remotely useable.\n // This only really happens on very small/thin segments.\n const isReasonableWithoutBetter =\n typeof diameter.minor !== 'undefined' &&\n (!this.#goodPerpendicularAngle(\n diameter.minor.angleDiff,\n 0.5\n )) &&\n (this.#goodPerpendicularAngle(\n angleDifference,\n 10\n ));\n\n if (\n typeof diameter.minor === 'undefined' ||\n (\n diameter.minor.diameter < distance &&\n isReasonableWithoutBetter\n ) ||\n (\n diameter.minor.diameter < distance &&\n isGoodAngle\n )\n ) {\n diameter.minor = {\n diameter: distance,\n line: sliceLine,\n offset1,\n offset2,\n angleDiff: angleDifference\n };\n }\n }\n\n borderOffset2++;\n }\n\n borderOffset1++;\n }\n }\n\n return maxDiameters;\n }\n\n /**\n * Run the filter.\n *\n * @param {object} data The input data.\n * @returns {object} The list of quantified labels.\n */\n run(data) {\n const imageBuffer = data.imageBuffer;\n const unitVectors = data.unitVectors;\n const sizes = data.sizes;\n const spacing = data.spacing;\n const totalSize = data.totalSize;\n\n //TODO: This is temporary until a proper method of displaying\n // them is implmented.\n // ------\n const debug = new LabelingDebug();\n if (DIAMETER_DEBUG) {\n debug.cleanBuffer(imageBuffer);\n }\n // ------\n\n // generate labels\n this.#regenerateLabels(\n imageBuffer,\n unitVectors,\n sizes,\n totalSize\n );\n\n // quantify labels\n const labelsInfo = this.#quantifyLabels(\n imageBuffer,\n unitVectors,\n spacing\n );\n\n // calculate diameters\n const maxDiameters = this.#calculateDiameters(\n imageBuffer,\n unitVectors,\n sizes,\n spacing,\n labelsInfo\n );\n\n //TODO: This is temporary until a proper method of displaying\n // them is implmented.\n // ------\n if (DIAMETER_DEBUG) {\n debug.drawDebugLines(\n imageBuffer,\n unitVectors,\n sizes,\n spacing,\n this.#borders,\n maxDiameters\n );\n }\n // ------\n\n // merge calculations\n const mergedLabelsInfo =\n Object.entries(labelsInfo).map(\n ([label, labelInfo]) => {\n if (typeof maxDiameters[label] !== 'undefined') {\n const diameters = maxDiameters[label];\n\n // Duplicate information\n delete diameters.id;\n delete diameters.zIndex;\n\n // These are in weird units and aren't helpful to pass back\n delete diameters.major.line;\n if (diameters.minor) {\n delete diameters.minor.line;\n }\n\n labelInfo.diameters = diameters;\n }\n\n return labelInfo;\n }\n );\n\n const returnEvent = {\n labels: mergedLabelsInfo,\n };\n\n //TODO: This is temporary until a proper method of displaying\n // them is implmented.\n // ------\n if (DIAMETER_DEBUG) {\n returnEvent.buffer = imageBuffer;\n }\n // ------\n\n return returnEvent;\n }\n} // class labelingFilter\n","/**\n * Labeling filter worker.\n */\n\nimport {LabelingFilter} from './labelingFilter.js';\n\nself.addEventListener('message', function (event) {\n\n const filter = new LabelingFilter();\n if (event.data.segmentSlice) {\n const {segmentSlice: {segNumber, slices},\n totalSize, unitVectors, sizes, spacing} = event.data;\n const sliceSize = unitVectors[unitVectors.length - 1];\n const buf = new Uint8Array(totalSize);\n for (const {sliceIndex, data} of slices) {\n const offset = sliceIndex * sliceSize;\n for (let l = 0; l < data.length; ++l) {\n if (data[l] !== 0) {\n buf[offset + l] = segNumber;\n }\n }\n }\n self.postMessage(filter.run(\n {imageBuffer: buf, unitVectors, sizes, spacing, totalSize}\n ));\n } else {\n self.postMessage(filter.run(event.data));\n }\n\n}, false);\n"],"names":["Point2D","x","y","constructor","this","getX","getY","getValues","getCentroid","equals","rhs","toString","getDistance","point2D","dx","dy","Math","sqrt","LabelingDebug","cleanBuffer","imageBuffer","i","length","sliceWorldToSliceOffset","point","unitVectors","spacing","round","plotLineLow","line","z","p0","getBegin","p1","getEnd","getDeltaX","abs","getDeltaY","D","yi","offset","plotLineHigh","xi","plotPoints","getFlipped","drawDebugLines","sizes","borders","maxDiameters","Object","values","map","diameter","major","zIndex","minor","Line","begin","end","getLength","getWorldLength","spacing2D","wlen","dxs","dys","getMidpoint","getSlope","getIntercept","getInclination","atan2","PI","quantify","viewController","get2DSpacing","worldLength","value","unit","getLengthUnit","LabelingFilter","lastKnownTotalSize","unionFind","labels","find","label","currentLabel","updateLabel","newLabel","union","label1","label2","regenerateLabels","buffer","totalSize","Int32Array","borderOffset","thisOffset","thisValue","xOffset","yOffset","zOffset","xOffsetp","yOffsetp","xValue","yValue","zValue","xValuep","yValuep","xLabel","yLabel","zLabel","offsetToIndex","Array","dimSize","off","floor","quantifyLabels","detailledInfos","o","labelValue","index","info","sliceCounts","id","sum","count","maxZ","minZ","max","min","labelsInfo","detailledInfo","entries","fill","d","largestSliceZ","largest","reduce","largestSlice","largestCount","currentSlice","currentCount","Number","centroidIndex","height","sliceOffsetToSliceWorld","sliceOffset","goodPerpendicularAngle","angle","epsilon","calculateDiameters","labelInfos","borderOffset1","offset1","sliceOffset1","slicePosition1","borderOffset2","offset2","sliceOffset2","slicePosition2","sliceLine","distance","maxDiameter","diameterAngle","angleDifference","isGoodAngle","isReasonableWithoutBetter","angleDiff","run","data","labelInfo","diameters","self","addEventListener","event","filter","segmentSlice","segNumber","slices","sliceSize","buf","Uint8Array","sliceIndex","l","postMessage"],"sourceRoot":""}
@@ -1,2 +1,2 @@
1
- class t{#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r}getX(){return this.#t}getY(){return this.#e}getZ(){return this.#r}equals(t){return null!==t&&this.#t===t.getX()&&this.#e===t.getY()&&this.#r===t.getZ()}toString(){return`(${this.#t}, ${this.#e}, ${this.#r})`}norm(){return Math.sqrt(this.#t*this.#t+this.#e*this.#e+this.#r*this.#r)}crossProduct(e){return new t(this.#e*e.getZ()-e.getY()*this.#r,this.#r*e.getX()-e.getZ()*this.#t,this.#t*e.getY()-e.getX()*this.#e)}dotProduct(t){return this.#t*t.getX()+this.#e*t.getY()+this.#r*t.getZ()}isCodirectional(t){return this.dotProduct(t)>0}}class e{success;message;constructor(t){this.success=t}}const r=1e4*Number.EPSILON;function s(t,e,r){return void 0===r&&(r=Number.EPSILON),Math.abs(t-e)<r}function n(t,r,s,n){return function(t,r,s){void 0===r&&(r=Number.EPSILON),void 0===s&&(s=1);const n=Math.abs(t)/r,i=n<s,a=new e(i);return i||(a.message=`${function(t){const e=Math.pow(10,2),r=.01/e;return Math.round(t*e+r)/e}(n)}`),a}(t-r,s,n)}class i{#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r}getX(){return this.#t}getY(){return this.#e}getZ(){return this.#r}getValues(){return[this.#t,this.#e,this.#r]}equals(t){return null!==t&&this.#t===t.getX()&&this.#e===t.getY()&&this.#r===t.getZ()}isSimilar(t,e){return null!==t&&s(this.#t,t.getX(),e)&&s(this.#e,t.getY(),e)&&s(this.#r,t.getZ(),e)}toString(){return`(${this.#t}, ${this.#e}, ${this.#r})`}getDistance(t){return Math.sqrt(this.#s(t))}#s(t){const e=this.#t-t.getX(),r=this.#e-t.getY(),s=this.#r-t.getZ();return e*e+r*r+s*s}getClosest(t){let e=0,r=this.#s(t[e]);for(let s=0;s<t.length;++s){const n=this.#s(t[s]);n<r&&(e=s,r=n)}return e}minus(e){return new t(this.#t-e.getX(),this.#e-e.getY(),this.#r-e.getZ())}}class a{#n;constructor(t){if(!t||void 0===t)throw new Error("Cannot create index with no values.");if(0===t.length)throw new Error("Cannot create index with empty values.");if(!t.every((function(t){return!isNaN(t)})))throw new Error("Cannot create index with non number values.");this.#n=t}get(t){return this.#n[t]}length(){return this.#n.length}toString(){return`(${this.#n.toString()})`}getValues(){return this.#n.slice()}canCompare(t){return!!t&&this.length()===t.length()}equals(t){if(!this.canCompare(t))return!1;for(let e=0,r=this.length();e<r;++e)if(this.get(e)!==t.get(e))return!1;return!0}compare(t){if(!this.canCompare(t))return null;const e=[];for(let r=0,s=this.length();r<s;++r)this.get(r)!==t.get(r)&&e.push(r);return e}add(t){if(!this.canCompare(t))return null;const e=[];for(let r=0,s=this.length();r<s;++r)e.push(this.get(r)+t.get(r));return new a(e)}#i(t,e){const r=this.#n.slice();return t<r.length?r[t]+=e:console.warn("Cannot add to given dimension: ",t,r.length),new a(r)}next(t){return this.#i(t,1)}previous(t){return this.#i(t,-1)}getWithNew2D(t,e){const r=[t,e];for(let t=2,e=this.length();t<e;++t)r.push(this.get(t));return new a(r)}}const l={levels:{TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4},level:3,trace(t){this.level<=this.levels.TRACE&&console.trace(t)},debug(t){this.level<=this.levels.DEBUG&&console.debug(t)},info(t){this.level<=this.levels.INFO&&console.info(t)},warn(t){this.level<=this.levels.WARN&&console.warn(t)},error(t){this.level<=this.levels.ERROR&&console.error(t)}};class o{#n;#a;constructor(t){this.#n=t}get(t,e){return this.#n[3*t+e]}getInverse(){return void 0===this.#a&&(this.#a=function(t){const e=t.get(0,0),r=t.get(0,1),s=t.get(0,2),n=t.get(1,0),i=t.get(1,1),a=t.get(1,2),h=t.get(2,0),u=t.get(2,1),g=t.get(2,2),c=i*g-a*u,f=a*h-n*g,v=n*u-i*h;let d=e*c+r*f+s*v;if(0!==d)return d=1/d,new o([d*c,d*(s*u-r*g),d*(r*a-s*i),d*f,d*(e*g-s*h),d*(s*n-e*a),d*v,d*(r*h-e*u),d*(e*i-r*n)]);l.warn("Cannot invert 3*3 matrix with zero determinant.")}(this)),this.#a}equals(t){for(let e=0;e<3;++e)for(let r=0;r<3;++r)if(this.get(e,r)!==t.get(e,r))return!1;return!0}isSimilar(t,e){for(let r=0;r<3;++r)for(let n=0;n<3;++n)if(!s(this.get(r,n),t.get(r,n),e))return!1;return!0}isSimilarProgressive(t,e){let r;for(let s=0;s<3;++s)for(let i=0;i<3;++i){const a=n(this.get(s,i),t.get(s,i),e,10);if(!a.success)return!1;if(void 0!==a.message){const t=parseInt(a.message,10);(void 0===r||t>r)&&(r=t)}}return void 0!==r&&l.warn(`Using larger tolerance for matrix similarity: max diff is ~${r} times tolerance`),!0}toString(){let t="[";for(let e=0;e<3;++e){0!==e&&(t+=", \n ");for(let r=0;r<3;++r)0!==r&&(t+=", "),t+=this.get(e,r)}return t+="]",t}multiply(t){const e=[];for(let r=0;r<3;++r)for(let s=0;s<3;++s){let n=0;for(let e=0;e<3;++e)n+=this.get(r,e)*t.get(e,s);e.push(n)}return new o(e)}getAbs(){const t=[];for(let e=0;e<3;++e)for(let r=0;r<3;++r)t.push(Math.abs(this.get(e,r)));return new o(t)}multiplyArray3D(t){if(3!==t.length)throw new Error(`Cannot multiply 3x3 matrix with non 3D array: ${t.length}`);const e=t[0],r=t[1],s=t[2],n=new Array(3);return n[0]=this.#n[0]*e+this.#n[1]*r+this.#n[2]*s,n[1]=this.#n[3]*e+this.#n[4]*r+this.#n[5]*s,n[2]=this.#n[6]*e+this.#n[7]*r+this.#n[8]*s,n}multiplyTypedArray3D(t,e){const r=t[0],s=t[1],n=t[2];e[0]=this.#n[0]*r+this.#n[1]*s+this.#n[2]*n,e[1]=this.#n[3]*r+this.#n[4]*s+this.#n[5]*n,e[2]=this.#n[6]*r+this.#n[7]*s+this.#n[8]*n}multiplyVector3D(e){const r=this.multiplyArray3D([e.getX(),e.getY(),e.getZ()]);return new t(r[0],r[1],r[2])}multiplyPoint3D(t){const e=this.multiplyArray3D([t.getX(),t.getY(),t.getZ()]);return new i(e[0],e[1],e[2])}multiplyIndex3D(t){const e=this.multiplyArray3D(t.getValues());return new a(e)}getRowAbsMax(t){const e=[Math.abs(this.get(t,0)),Math.abs(this.get(t,1)),Math.abs(this.get(t,2))],r=Math.max.apply(null,e),s=e.indexOf(r);return{value:this.get(t,s),index:s}}getColAbsMax(t){const e=[Math.abs(this.get(0,t)),Math.abs(this.get(1,t)),Math.abs(this.get(2,t))],r=Math.max.apply(null,e),s=e.indexOf(r);return{value:this.get(s,t),index:s}}asOneAndZeros(){const t=[];for(let e=0;e<3;++e){const r=this.getRowAbsMax(e),s=r.value>0?1:-1;for(let e=0;e<3;++e)e===r.index?t.push(s):t.push(0)}return new o(t)}getThirdColMajorDirection(){return this.getColAbsMax(2).index}getValues(){return this.#n.slice()}}String.fromCharCode("u200B");class h{#l(t,e,r,s,n){const i=Math.floor(t[0]),a=Math.floor(t[1]),l=Math.floor(t[2]),o=i<0?0:i,h=i+1>=r[0]?i:i+1,u=a<0?0:a,g=a+1>=r[1]?a:a+1,c=l<0?0:l,f=l+1>=r[2]?l:l+1,v=o*s[0],d=h*s[0],y=u*s[1],m=g*s[1],w=c*s[2],p=f*s[2],x=v+y+w+n,M=v+y+p+n,b=v+m+w+n,A=v+m+p+n,S=d+y+w+n,z=d+y+p+n,D=d+m+w+n,C=d+m+p+n,E=o>=0&&o<r[0],R=h>=0&&h<r[0],I=u>=0&&u<r[1],O=g>=0&&g<r[1],N=c>=0&&c<r[2],Y=f>=0&&f<r[2],Z=E&&I&&N?e[x]:0,X=E&&I&&Y?e[M]:0,$=E&&O&&N?e[b]:0,q=E&&O&&Y?e[A]:0,T=R&&I&&N?e[S]:0,B=R&&I&&Y?e[z]:0,P=R&&O&&N?e[D]:0,U=R&&O&&Y?e[C]:0,V=Math.abs(t[0]-i),L=Math.abs(t[1]-a),j=Math.abs(t[2]-l),W=1-V,F=1-L,G=1-j;return Z*(W*F*G)+X*(W*F*j)+$*(W*L*G)+q*(W*L*j)+T*(V*F*G)+B*(V*F*j)+P*(V*L*G)+U*(V*L*j)}#o(t){const e=Math.round(t);return Math.abs(t-e)<r?e:t}#h(t,e,r,s){const n=s[2]*r[2],i=function(t,e,r){let s=null;try{1===t||8===t?s=0===e?new Uint8Array(r):new Int8Array(r):16===t?s=0===e?new Uint16Array(r):new Int16Array(r):32===t&&(s=0===e?new Uint32Array(r):new Int32Array(r))}catch(t){if(t instanceof RangeError){const t=Math.floor(Math.log(r)/Math.log(2));l.error(`Cannot allocate array of size: ${r} (>2^${t}).`)}}return s}(8*t.BYTES_PER_ELEMENT,e,n);if(null===i)throw new Error("Cannot reallocate data for image resampling.");return i.fill(0),i}run(t){const e=t.sourceSize,r=t.targetSize,s=t.sourceUnitVectors,n=t.targetUnitVectors,i=t.sourceSpacing,a=t.targetSpacing,l=t.sourceImageBuffer,h=t.pixelRepresentation,u=this.#h(l,h,r,n),g=t.sourceStartOffset,c=t.targetStartOffset,f=t.interpolate,v=t.jobId,d=t.frame,y=new o(t.sourceOrientation),m=new o(t.targetOrientation),w=y.getInverse(),p=m.multiply(w),x=[(r[0]-1)/2,(r[1]-1)/2,(r[2]-1)/2],M=[(e[0]-1)/2,(e[1]-1)/2,(e[2]-1)/2],b=new Array(3),A=new Array(3),S=new Array(3);let z,D,C;for(let o=0;o<r[0];o++){b[0]=(o-x[0])*a[0],z=n[0]*o;for(let o=0;o<r[1];o++){b[1]=(o-x[1])*a[1],D=z+n[1]*o;for(let o=0;o<r[2];o++)if(b[2]=(o-x[2])*a[2],p.multiplyTypedArray3D(b,A),S[0]=this.#o(A[0]/i[0]+M[0]),S[1]=this.#o(A[1]/i[1]+M[1]),S[2]=this.#o(A[2]/i[2]+M[2]),S[0]>=0&&S[0]<e[0]&&S[1]>=0&&S[1]<e[1]&&S[2]>=0&&S[2]<e[2])if(C=D+n[2]*o,f){const t=this.#l(S,l,e,s,g);u[C]=t}else{const e=s[0]*Math.round(S[0])+s[1]*Math.round(S[1])+s[2]*Math.round(S[2])+g;u[C]=t.sourceImageBuffer[e]}}}return{targetImageBuffer:u,startOffset:c,jobId:v,frame:d}}}self.addEventListener("message",(function(t){const e=(new h).run(t.data);self.postMessage(e)}),!1);
1
+ class t{#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r}getX(){return this.#t}getY(){return this.#e}getZ(){return this.#r}equals(t){return null!==t&&this.#t===t.getX()&&this.#e===t.getY()&&this.#r===t.getZ()}toString(){return`(${this.#t}, ${this.#e}, ${this.#r})`}norm(){return Math.sqrt(this.#t*this.#t+this.#e*this.#e+this.#r*this.#r)}crossProduct(e){return new t(this.#e*e.getZ()-e.getY()*this.#r,this.#r*e.getX()-e.getZ()*this.#t,this.#t*e.getY()-e.getX()*this.#e)}dotProduct(t){return this.#t*t.getX()+this.#e*t.getY()+this.#r*t.getZ()}isCodirectional(t){return this.dotProduct(t)>0}}class e{success;message;constructor(t){this.success=t}}const r=1e4*Number.EPSILON;function s(t,e,r){return void 0===r&&(r=Number.EPSILON),Math.abs(t-e)<r}function n(t,r,s,n){return function(t,r,s){void 0===r&&(r=Number.EPSILON),void 0===s&&(s=1);const n=Math.abs(t)/r,i=n<s,a=new e(i);return i||(a.message=`${function(t){const e=Math.pow(10,2),r=.01/e;return Math.round(t*e+r)/e}(n)}`),a}(t-r,s,n)}class i{#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r}getX(){return this.#t}getY(){return this.#e}getZ(){return this.#r}getValues(){return[this.#t,this.#e,this.#r]}equals(t){return null!==t&&this.#t===t.getX()&&this.#e===t.getY()&&this.#r===t.getZ()}isSimilar(t,e){return null!==t&&s(this.#t,t.getX(),e)&&s(this.#e,t.getY(),e)&&s(this.#r,t.getZ(),e)}toString(){return`(${this.#t}, ${this.#e}, ${this.#r})`}getDistance(t){return Math.sqrt(this.#s(t))}#s(t){const e=this.#t-t.getX(),r=this.#e-t.getY(),s=this.#r-t.getZ();return e*e+r*r+s*s}getClosest(t){let e=0,r=this.#s(t[e]);for(let s=0;s<t.length;++s){const n=this.#s(t[s]);n<r&&(e=s,r=n)}return e}minus(e){return new t(this.#t-e.getX(),this.#e-e.getY(),this.#r-e.getZ())}}class a{#n;constructor(t){if(!t||void 0===t)throw new Error("Cannot create index with no values.");if(0===t.length)throw new Error("Cannot create index with empty values.");if(!t.every(function(t){return!isNaN(t)}))throw new Error("Cannot create index with non number values.");this.#n=t}get(t){return this.#n[t]}length(){return this.#n.length}toString(){return`(${this.#n.toString()})`}getValues(){return this.#n.slice()}canCompare(t){return!!t&&this.length()===t.length()}equals(t){if(!this.canCompare(t))return!1;for(let e=0,r=this.length();e<r;++e)if(this.get(e)!==t.get(e))return!1;return!0}compare(t){if(!this.canCompare(t))return null;const e=[];for(let r=0,s=this.length();r<s;++r)this.get(r)!==t.get(r)&&e.push(r);return e}add(t){if(!this.canCompare(t))return null;const e=[];for(let r=0,s=this.length();r<s;++r)e.push(this.get(r)+t.get(r));return new a(e)}#i(t,e){const r=this.#n.slice();return t<r.length?r[t]+=e:console.warn("Cannot add to given dimension: ",t,r.length),new a(r)}next(t){return this.#i(t,1)}previous(t){return this.#i(t,-1)}getWithNew2D(t,e){const r=[t,e];for(let t=2,e=this.length();t<e;++t)r.push(this.get(t));return new a(r)}}const l={levels:{TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4},level:3,trace(t){this.level<=this.levels.TRACE&&console.trace(t)},debug(t){this.level<=this.levels.DEBUG&&console.debug(t)},info(t){this.level<=this.levels.INFO&&console.info(t)},warn(t){this.level<=this.levels.WARN&&console.warn(t)},error(t){this.level<=this.levels.ERROR&&console.error(t)}};class o{#n;#a;constructor(t){this.#n=t}get(t,e){return this.#n[3*t+e]}getInverse(){return void 0===this.#a&&(this.#a=function(t){const e=t.get(0,0),r=t.get(0,1),s=t.get(0,2),n=t.get(1,0),i=t.get(1,1),a=t.get(1,2),h=t.get(2,0),u=t.get(2,1),g=t.get(2,2),c=i*g-a*u,f=a*h-n*g,v=n*u-i*h;let d=e*c+r*f+s*v;if(0!==d)return d=1/d,new o([d*c,d*(s*u-r*g),d*(r*a-s*i),d*f,d*(e*g-s*h),d*(s*n-e*a),d*v,d*(r*h-e*u),d*(e*i-r*n)]);l.warn("Cannot invert 3*3 matrix with zero determinant.")}(this)),this.#a}equals(t){for(let e=0;e<3;++e)for(let r=0;r<3;++r)if(this.get(e,r)!==t.get(e,r))return!1;return!0}isSimilar(t,e){for(let r=0;r<3;++r)for(let n=0;n<3;++n)if(!s(this.get(r,n),t.get(r,n),e))return!1;return!0}isSimilarProgressive(t,e){let r;for(let s=0;s<3;++s)for(let i=0;i<3;++i){const a=n(this.get(s,i),t.get(s,i),e,10);if(!a.success)return!1;if(void 0!==a.message){const t=parseInt(a.message,10);(void 0===r||t>r)&&(r=t)}}return void 0!==r&&l.warn(`Using larger tolerance for matrix similarity: max diff is ~${r} times tolerance`),!0}toString(){let t="[";for(let e=0;e<3;++e){0!==e&&(t+=", \n ");for(let r=0;r<3;++r)0!==r&&(t+=", "),t+=this.get(e,r)}return t+="]",t}multiply(t){const e=[];for(let r=0;r<3;++r)for(let s=0;s<3;++s){let n=0;for(let e=0;e<3;++e)n+=this.get(r,e)*t.get(e,s);e.push(n)}return new o(e)}getAbs(){const t=[];for(let e=0;e<3;++e)for(let r=0;r<3;++r)t.push(Math.abs(this.get(e,r)));return new o(t)}multiplyArray3D(t){if(3!==t.length)throw new Error(`Cannot multiply 3x3 matrix with non 3D array: ${t.length}`);const e=t[0],r=t[1],s=t[2],n=new Array(3);return n[0]=this.#n[0]*e+this.#n[1]*r+this.#n[2]*s,n[1]=this.#n[3]*e+this.#n[4]*r+this.#n[5]*s,n[2]=this.#n[6]*e+this.#n[7]*r+this.#n[8]*s,n}multiplyTypedArray3D(t,e){const r=t[0],s=t[1],n=t[2];e[0]=this.#n[0]*r+this.#n[1]*s+this.#n[2]*n,e[1]=this.#n[3]*r+this.#n[4]*s+this.#n[5]*n,e[2]=this.#n[6]*r+this.#n[7]*s+this.#n[8]*n}multiplyVector3D(e){const r=this.multiplyArray3D([e.getX(),e.getY(),e.getZ()]);return new t(r[0],r[1],r[2])}multiplyPoint3D(t){const e=this.multiplyArray3D([t.getX(),t.getY(),t.getZ()]);return new i(e[0],e[1],e[2])}multiplyIndex3D(t){const e=this.multiplyArray3D(t.getValues());return new a(e)}getRowAbsMax(t){const e=[Math.abs(this.get(t,0)),Math.abs(this.get(t,1)),Math.abs(this.get(t,2))],r=Math.max.apply(null,e),s=e.indexOf(r);return{value:this.get(t,s),index:s}}getColAbsMax(t){const e=[Math.abs(this.get(0,t)),Math.abs(this.get(1,t)),Math.abs(this.get(2,t))],r=Math.max.apply(null,e),s=e.indexOf(r);return{value:this.get(s,t),index:s}}asOneAndZeros(){const t=[];for(let e=0;e<3;++e){const r=this.getRowAbsMax(e),s=r.value>0?1:-1;for(let e=0;e<3;++e)e===r.index?t.push(s):t.push(0)}return new o(t)}getThirdColMajorDirection(){return this.getColAbsMax(2).index}getValues(){return this.#n.slice()}}String.fromCharCode("u200B");class h{#l(t,e,r,s,n){const i=Math.floor(t[0]),a=Math.floor(t[1]),l=Math.floor(t[2]),o=i<0?0:i,h=i+1>=r[0]?i:i+1,u=a<0?0:a,g=a+1>=r[1]?a:a+1,c=l<0?0:l,f=l+1>=r[2]?l:l+1,v=o*s[0],d=h*s[0],y=u*s[1],m=g*s[1],w=c*s[2],p=f*s[2],x=v+y+w+n,M=v+y+p+n,b=v+m+w+n,A=v+m+p+n,S=d+y+w+n,z=d+y+p+n,D=d+m+w+n,C=d+m+p+n,E=o>=0&&o<r[0],R=h>=0&&h<r[0],I=u>=0&&u<r[1],O=g>=0&&g<r[1],N=c>=0&&c<r[2],Y=f>=0&&f<r[2],Z=E&&I&&N?e[x]:0,X=E&&I&&Y?e[M]:0,$=E&&O&&N?e[b]:0,q=E&&O&&Y?e[A]:0,T=R&&I&&N?e[S]:0,B=R&&I&&Y?e[z]:0,P=R&&O&&N?e[D]:0,U=R&&O&&Y?e[C]:0,V=Math.abs(t[0]-i),L=Math.abs(t[1]-a),j=Math.abs(t[2]-l),W=1-V,F=1-L,G=1-j;return Z*(W*F*G)+X*(W*F*j)+$*(W*L*G)+q*(W*L*j)+T*(V*F*G)+B*(V*F*j)+P*(V*L*G)+U*(V*L*j)}#o(t){const e=Math.round(t);return Math.abs(t-e)<r?e:t}#h(t,e,r,s){const n=s[2]*r[2],i=function(t,e,r){let s=null;try{1===t||8===t?s=0===e?new Uint8Array(r):new Int8Array(r):16===t?s=0===e?new Uint16Array(r):new Int16Array(r):32===t&&(s=0===e?new Uint32Array(r):new Int32Array(r))}catch(t){if(t instanceof RangeError){const t=Math.floor(Math.log(r)/Math.log(2));l.error(`Cannot allocate array of size: ${r} (>2^${t}).`)}}return s}(8*t.BYTES_PER_ELEMENT,e,n);if(null===i)throw new Error("Cannot reallocate data for image resampling.");return i.fill(0),i}run(t){const e=t.sourceSize,r=t.targetSize,s=t.sourceUnitVectors,n=t.targetUnitVectors,i=t.sourceSpacing,a=t.targetSpacing,l=t.sourceImageBuffer,h=t.pixelRepresentation,u=this.#h(l,h,r,n),g=t.sourceStartOffset,c=t.targetStartOffset,f=t.interpolate,v=t.jobId,d=t.frame,y=new o(t.sourceOrientation),m=new o(t.targetOrientation),w=y.getInverse(),p=m.multiply(w),x=[(r[0]-1)/2,(r[1]-1)/2,(r[2]-1)/2],M=[(e[0]-1)/2,(e[1]-1)/2,(e[2]-1)/2],b=new Array(3),A=new Array(3),S=new Array(3);let z,D,C;for(let o=0;o<r[0];o++){b[0]=(o-x[0])*a[0],z=n[0]*o;for(let o=0;o<r[1];o++){b[1]=(o-x[1])*a[1],D=z+n[1]*o;for(let o=0;o<r[2];o++)if(b[2]=(o-x[2])*a[2],p.multiplyTypedArray3D(b,A),S[0]=this.#o(A[0]/i[0]+M[0]),S[1]=this.#o(A[1]/i[1]+M[1]),S[2]=this.#o(A[2]/i[2]+M[2]),S[0]>=0&&S[0]<e[0]&&S[1]>=0&&S[1]<e[1]&&S[2]>=0&&S[2]<e[2])if(C=D+n[2]*o,f){const t=this.#l(S,l,e,s,g);u[C]=t}else{const e=s[0]*Math.round(S[0])+s[1]*Math.round(S[1])+s[2]*Math.round(S[2])+g;u[C]=t.sourceImageBuffer[e]}}}return{targetImageBuffer:u,startOffset:c,jobId:v,frame:d}}}self.addEventListener("message",function(t){const e=(new h).run(t.data);self.postMessage(e)},!1);
2
2
  //# sourceMappingURL=resampling.worker.min.js.map