Skip to content

Commit

Permalink
fix(src/test): Address lint issues + setup lint/format CI action (#406)
Browse files Browse the repository at this point in the history
* Address lint issues

* fix(src/test): Address lint issues

* Add lint workflow and use yarn

* Update lint rules

* Add prettier check

* Run frmat

* Update action title
  • Loading branch information
igoroctaviano authored Oct 15, 2024
1 parent 96a068e commit 158c396
Show file tree
Hide file tree
Showing 40 changed files with 811 additions and 688 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
},

"rules": {
"no-loss-of-precision": "off"
}
}
27 changes: 27 additions & 0 deletions .github/workflows/lint-and-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run lint and format check

on:
- push
- pull_request

jobs:
lint-and-format:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Install packages
run: yarn install --frozen-lockfile

- name: Run ESLint
run: yarn lint

- name: Check Prettier formatting
run: yarn format:check
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
node-version: 18

- name: Install packages
uses: bahmutov/npm-install@v1
run: yarn install --frozen-lockfile

- name: Run tests
run: npm run test
run: yarn test
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"build:examples": "npm run build && npx cpx 'build/**/*.{js,map}' examples/js",
"start": "rollup -c -w",
"format": "prettier --write 'src/**/*.js' 'test/**/*.js'",
"lint": "eslint --fix ."
"format:check": "prettier --check 'src/**/*.js' 'test/**/*.js'",
"lint": "eslint --fix 'src/**/*.js' 'test/**/*.js'"
},
"repository": {
"type": "git",
Expand Down
4 changes: 3 additions & 1 deletion src/BufferStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ class ReadBufferStream extends BufferStream {
}

writeUint8Repeat(value, count) {
throw new Error(value, "writeUint8Repeat not implemented");
throw new Error(
`writeUint8Repeat not implemented (value: ${value}, count: ${count})`
);
}

writeInt8(value) {
Expand Down
26 changes: 20 additions & 6 deletions src/DicomMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ class DicomMessage {

// apply VR specific formatting to the original _rawValue and compare to the Value
const vr = ValueRepresentation.createByTypeString(vrType);
const originalValue = tagObject._rawValue.map((val) => vr.applyFormatting(val))
const originalValue = tagObject._rawValue.map(val =>
vr.applyFormatting(val)
);

// if Value has not changed, write _rawValue unformatted back into the file
if (deepEqual(tagObject.Value, originalValue)) {
Expand Down Expand Up @@ -366,18 +368,28 @@ class DicomMessage {
var times = length / vr.maxLength,
i = 0;
while (i++ < times) {
const { rawValue, value } = vr.read(stream, vr.maxLength, syntax, options);
const { rawValue, value } = vr.read(
stream,
vr.maxLength,
syntax,
options
);
rawValues.push(rawValue);
values.push(value);
}
} else {
const { rawValue, value } = vr.read(stream, length, syntax, options);
const { rawValue, value } = vr.read(
stream,
length,
syntax,
options
);
if (!vr.isBinary() && singleVRs.indexOf(vr.type) == -1) {
rawValues = rawValue;
values = value
values = value;
if (typeof value === "string") {
const delimiterChar = String.fromCharCode(VM_DELIMITER);
rawValues = vr.dropPadByte(rawValue.split(delimiterChar))
rawValues = vr.dropPadByte(rawValue.split(delimiterChar));
values = vr.dropPadByte(value.split(delimiterChar));
}
} else if (vr.type == "SQ") {
Expand All @@ -388,7 +400,9 @@ class DicomMessage {
values = value;
} else {
Array.isArray(value) ? (values = value) : values.push(value);
Array.isArray(rawValue) ? (rawValues = rawValue) : rawValues.push(rawValue);
Array.isArray(rawValue)
? (rawValues = rawValue)
: rawValues.push(rawValue);
}
}
stream.setEndian(oldEndian);
Expand Down
1 change: 0 additions & 1 deletion src/adapters/Cornerstone/Bidirectional.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class Bidirectional {
isCreating: false,
longestDiameter,
shortestDiameter,
toolType: "Bidirectional",
toolName: "Bidirectional",
visible: true,
finding: findingGroup
Expand Down
3 changes: 0 additions & 3 deletions src/adapters/Cornerstone/EllipticalRoi.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import MeasurementReport from "./MeasurementReport";
import TID300Ellipse from "../../utilities/TID300/Ellipse";
import CORNERSTONE_4_TAG from "./cornerstone4Tag";
import { toArray } from "../helpers.js";

const ELLIPTICALROI = "EllipticalRoi";
const FINDING = "121071";
const FINDING_SITE = "G-C0E3";

class EllipticalRoi {
constructor() {}
Expand Down
3 changes: 0 additions & 3 deletions src/adapters/Cornerstone/Length.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import MeasurementReport from "./MeasurementReport.js";
import TID300Length from "../../utilities/TID300/Length.js";
import CORNERSTONE_4_TAG from "./cornerstone4Tag";
import { toArray } from "../helpers.js";

const LENGTH = "Length";
const FINDING = "121071";
const FINDING_SITE = "G-C0E3";

class Length {
constructor() {}
Expand Down
2 changes: 0 additions & 2 deletions src/adapters/Cornerstone/Segmentation_3X.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,6 @@ function addImageIdSpecificBrushToolState(

const cToolsPixelData = brushDataI.pixelData;

const [rows, cols] = pixelData2D.shape;

for (let p = 0; p < cToolsPixelData.length; p++) {
if (pixelData2D.data[p]) {
cToolsPixelData[p] = 1;
Expand Down
174 changes: 1 addition & 173 deletions src/adapters/Cornerstone/Segmentation_4X.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { DicomMessage } from "../../DicomMessage.js";
import { DicomMetaDictionary } from "../../DicomMetaDictionary.js";
import { Normalizer } from "../../normalizers.js";
import { Segmentation as SegmentationDerivation } from "../../derivations/index.js";
import { mat4 } from "gl-matrix";
import {
rotateDirectionCosinesInPlane,
flipImageOrientationPatient as flipIOP,
Expand Down Expand Up @@ -432,177 +431,6 @@ function generateToolState(
};
}

function insertPixelDataPerpendicular(
segmentsOnFrame,
labelmapBuffer,
pixelData,
multiframe,
imageIds,
validOrientations,
metadataProvider
) {
const {
SharedFunctionalGroupsSequence,
PerFrameFunctionalGroupsSequence,
Rows,
Columns
} = multiframe;

const firstImagePlaneModule = metadataProvider.get(
"imagePlaneModule",
imageIds[0]
);

const lastImagePlaneModule = metadataProvider.get(
"imagePlaneModule",
imageIds[imageIds.length - 1]
);

console.log(firstImagePlaneModule);
console.log(lastImagePlaneModule);

const corners = [
...getCorners(firstImagePlaneModule),
...getCorners(lastImagePlaneModule)
];

console.log(`corners:`);
console.log(corners);

const indexToWorld = mat4.create();

const ippFirstFrame = firstImagePlaneModule.imagePositionPatient;
const rowCosines = Array.isArray(firstImagePlaneModule.rowCosines)
? [...firstImagePlaneModule.rowCosines]
: [
firstImagePlaneModule.rowCosines.x,
firstImagePlaneModule.rowCosines.y,
firstImagePlaneModule.rowCosines.z
];

const columnCosines = Array.isArray(firstImagePlaneModule.columnCosines)
? [...firstImagePlaneModule.columnCosines]
: [
firstImagePlaneModule.columnCosines.x,
firstImagePlaneModule.columnCosines.y,
firstImagePlaneModule.columnCosines.z
];

const { pixelSpacing } = firstImagePlaneModule;

mat4.set(
indexToWorld,
// Column 1
0,
0,
0,
ippFirstFrame[0],
// Column 2
0,
0,
0,
ippFirstFrame[1],
// Column 3
0,
0,
0,
ippFirstFrame[2],
// Column 4
0,
0,
0,
1
);

// TODO -> Get origin and (x,y,z) increments to build a translation matrix:
// TODO -> Equation C.7.6.2.1-1

// | cx*di rx* Xx 0 | |x|
// | cy*di ry Xy 0 | |y|
// | cz*di rz Xz 0 | |z|
// | tx ty tz 1 | |1|

// const [
// 0, 0 , 0 , 0,
// 0, 0 , 0 , 0,
// 0, 0 , 0 , 0,
// ipp[0], ipp[1] , ipp[2] , 1,
// ]

// Each frame:

// Find which corner the first voxel lines up with (one of 8 corners.)

// Find how i,j,k orient with respect to source volume.
// Go through each frame, find location in source to start, and whether to increment +/ix,+/-y,+/-z
// through each voxel.

// [1,0,0,0,1,0]

// const [

// ]

// Invert transformation matrix to get worldToIndex

// Apply world to index on each point to fill up the matrix.

// const sharedImageOrientationPatient = SharedFunctionalGroupsSequence.PlaneOrientationSequence
// ? SharedFunctionalGroupsSequence.PlaneOrientationSequence
// .ImageOrientationPatient
// : undefined;
// const sliceLength = Columns * Rows;
}

function getCorners(imagePlaneModule) {
// console.log(imagePlaneModule);

const {
rows,
columns,
rowCosines,
columnCosines,
imagePositionPatient: ipp,
rowPixelSpacing,
columnPixelSpacing
} = imagePlaneModule;

const rowLength = columns * columnPixelSpacing;
const columnLength = rows * rowPixelSpacing;

const entireRowVector = [
rowLength * columnCosines[0],
rowLength * columnCosines[1],
rowLength * columnCosines[2]
];

const entireColumnVector = [
columnLength * rowCosines[0],
columnLength * rowCosines[1],
columnLength * rowCosines[2]
];

const topLeft = [ipp[0], ipp[1], ipp[2]];
const topRight = [
topLeft[0] + entireRowVector[0],
topLeft[1] + entireRowVector[1],
topLeft[2] + entireRowVector[2]
];
const bottomLeft = [
topLeft[0] + entireColumnVector[0],
topLeft[1] + entireColumnVector[1],
topLeft[2] + entireColumnVector[2]
];

const bottomRight = [
bottomLeft[0] + entireRowVector[0],
bottomLeft[1] + entireRowVector[1],
bottomLeft[2] + entireRowVector[2]
];

return [topLeft, topRight, bottomLeft, bottomRight];
}

/**
* Find the reference frame of the segmentation frame in the source data.
*
Expand Down Expand Up @@ -786,7 +614,7 @@ function checkSEGsOverlapping(
}
}

for (let [user, role] of frameSegmentsMapping.entries()) {
for (let [, role] of frameSegmentsMapping.entries()) {
let temp2DArray = new Uint16Array(sliceLength).fill(0);

for (let i = 0; i < role.length; ++i) {
Expand Down
2 changes: 0 additions & 2 deletions src/adapters/Cornerstone3D/Bidirectional.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { toArray } from "../helpers.js";
const BIDIRECTIONAL = "Bidirectional";
const LONG_AXIS = "Long Axis";
const SHORT_AXIS = "Short Axis";
const FINDING = "121071";
const FINDING_SITE = "G-C0E3";
const trackingIdentifierTextValue = `${CORNERSTONE_3D_TAG}:${BIDIRECTIONAL}`;

class Bidirectional {
Expand Down
4 changes: 1 addition & 3 deletions src/adapters/Cornerstone3D/EllipticalROI.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { vec2, vec3 } from "gl-matrix";
import { vec3 } from "gl-matrix";
import MeasurementReport from "./MeasurementReport";
import TID300Ellipse from "../../utilities/TID300/Ellipse";
import CORNERSTONE_3D_TAG from "./cornerstone3DTag";

const ELLIPTICALROI = "EllipticalROI";
const FINDING = "121071";
const FINDING_SITE = "G-C0E3";
const EPSILON = 1e-4;

const trackingIdentifierTextValue = `${CORNERSTONE_3D_TAG}:${ELLIPTICALROI}`;
Expand Down
2 changes: 0 additions & 2 deletions src/adapters/Cornerstone3D/Length.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import TID300Length from "../../utilities/TID300/Length.js";
import CORNERSTONE_3D_TAG from "./cornerstone3DTag";

const LENGTH = "Length";
const FINDING = "121071";
const FINDING_SITE = "G-C0E3";
const trackingIdentifierTextValue = `${CORNERSTONE_3D_TAG}:${LENGTH}`;

class Length {
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/Cornerstone3D/MeasurementReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export default class MeasurementReport {
measurementData[key] = [];
});

measurementGroups.forEach((measurementGroup, index) => {
measurementGroups.forEach(measurementGroup => {
const measurementGroupContentSequence = toArray(
measurementGroup.ContentSequence
);
Expand Down
Loading

0 comments on commit 158c396

Please sign in to comment.