Skip to content

Commit

Permalink
Merge pull request #56 from LinkunGao/release/v1.11.8
Browse files Browse the repository at this point in the history
Release/v1.11.8
  • Loading branch information
LinkunGao authored Sep 22, 2022
2 parents a0f113f + b0dcc99 commit 237c8ef
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 36 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'LinkunGao'

# The full version, including alpha/beta/rc tags
release = 'v1.11.7'
release = 'v1.11.8'


# -- General configuration ---------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions docs/source/release/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,20 @@ appRenderer.sceneInfos[0].addPreRenderCallbackFunction(nrrdTools.start);
- Fixed undo issue.

- Optimised dicom loader.

## Release v1.11.8

- fixed dicom loader disoder issue after load all dicom files.
- the default order is ascending order.
- add set order function in copperScene.
```ts
scene.setDicomFilesOrder("descending"); // value => "ascending" | descending
// set order must before load function
scene.loadDicom(
urls,
(mesh) => {
console.log(mesh);
},
gui
);
```
2 changes: 2 additions & 0 deletions docs/source/tutorial/15_texture2d_heartmodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function loadModel(urls: Array<string>, name: string) {

if (scene) {
appRenderer.setCurrentScene(scene);

scene.setDicomFilesOrder("descending");
// load dicom image
scene.loadDicom(
urls,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "copper3d_visualisation",
"description": "A 3d visualisation package base on threejs provides multiple scenes and Nrrd image load funtion.",
"version": "1.11.7",
"version": "1.11.8",
"main": "dist/bundle.umd.js",
"moudle": "dist/bundle.esm.js",
"types": "dist/types/index.d.ts",
Expand Down
55 changes: 27 additions & 28 deletions src/Loader/copperDicomLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,55 @@ export function copperDicomLoader(
) {
loader.load(url, (arrayBuffer) => {
var dicomFileAsBuffer = new Uint8Array(arrayBuffer as ArrayBuffer);

const dataSet = dicomParser.parseDicom(dicomFileAsBuffer);
let tags: any = null;
let w: number;
let h: number;
let invert: boolean;
let windowCenter: number;
let windowWidth: number;
let order: number = 0;

// console.log(dataSet.elements.x00181060);
// console.log(dataSet.elements.x00201041);

// console.log(dataSet.uint16("x00280004"));
// // console.log(dataSet.string("x00201041"));
// console.log(dataSet.string("x00201041"));

try {
tags = dicomParser.explicitDataSetToJS(dataSet);
if (dataSet.elements.x00181060) {
order = parseInt(tags["x00181060"]);
} else if (dataSet.elements.x00201041) {
order = parseInt(tags["x00201041"]);
}
w = parseInt(tags["x00280011"]); //width
h = parseInt(tags["x00280010"]); //height
invert = tags["x00280004"] === "MONOCHROME1" ? true : false; //is invert?
windowCenter = parseInt(tags["x00281050"]); //window center
windowWidth = parseInt(tags["x00281051"]); //window width
} catch {
w = convertImplicitElement(
dataSet.elements.x00280011,
dicomFileAsBuffer
)[0];
h = convertImplicitElement(
dataSet.elements.x00280010,
dicomFileAsBuffer
)[0];
invert =
convertImplicitElement(
dataSet.elements.x00280004,
dicomFileAsBuffer
)[0] === 20301
? false
: true;

windowCenter = 226;
windowWidth = 537;
w = dataSet.uint16("x00280011");
h = dataSet.uint16("x00280010");
invert = dataSet.string("x00280004") === "MONOCHROME1" ? true : false;
windowCenter = parseInt(dataSet.string("x00281050"));
windowWidth = parseInt(dataSet.string("x00281051"));
if (dataSet.elements.x00181060) {
order = parseInt(dataSet.string("x00181060"));
} else if (dataSet.elements.x00201041) {
order = parseInt(dataSet.string("x00201041"));
}
}

if (windowCenter == 0 || windowWidth == 0) {
windowCenter = 226;
windowWidth = 537;
}

let pixelData = dataSet.elements.x7fe00010;
let pixelDataBuffer = dicomParser.sharedCopy(
dicomFileAsBuffer,
pixelData.dataOffset,
pixelData.length
);
let uint16 = new Uint16Array(
pixelDataBuffer.buffer,
pixelDataBuffer.byteOffset,
pixelDataBuffer.byteLength / Uint16Array.BYTES_PER_ELEMENT
);
let uint16 = convertImplicitElement(pixelData, dicomFileAsBuffer);
let voiLUT;
let lut = getLut(uint16, windowWidth, windowCenter, invert, voiLUT);
let uint8 = new Uint8ClampedArray(uint16.length);
Expand All @@ -77,6 +75,7 @@ export function copperDicomLoader(
invert,
uint16,
uint8,
order,
};
callback && callback(copperVolume);
});
Expand Down
29 changes: 26 additions & 3 deletions src/Scene/copperScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default class copperScene extends baseScene {
private depthStep: number = 0.4;
private texture2dMesh: THREE.Mesh | null = null;
private preRenderCallbackFunctions: Array<preRenderCallbackFunctionType> = [];
private sort: boolean = true; //default ascending order

constructor(container: HTMLDivElement, renderer: THREE.WebGLRenderer) {
super(container, renderer);
Expand All @@ -49,6 +50,13 @@ export default class copperScene extends baseScene {
setDepth(value: number) {
this.depthStep = value;
}
setDicomFilesOrder(value: "ascending" | "descending") {
if (value === "ascending") {
this.sort = true;
} else if (value === "descending") {
this.sort = false;
}
}

loadGltf(url: string, callback?: (content: THREE.Group) => void) {
const loader = copperGltfLoader(this.renderer);
Expand Down Expand Up @@ -223,19 +231,34 @@ export default class copperScene extends baseScene {
if (Array.isArray(urls)) {
const depth: number = urls.length;

const copperVolumes: Array<copperVolumeType> = [];
let unit8Arrays: Array<Uint8ClampedArray> = [];
let unit16Arrays: Array<Uint16Array> = [];
urls.forEach((url) => {
copperDicomLoader(url, (copperVolume) => {
unit8Arrays.push(copperVolume.uint8);
unit16Arrays.push(copperVolume.uint16);
if (unit8Arrays.length === depth) {
copperVolumes.push(copperVolume);

if (copperVolumes.length === depth) {
// reorder each dicom file
copperVolumes.sort((a: copperVolumeType, b: copperVolumeType) => {
if (this.sort) {
return a.order - b.order;
} else {
return b.order - a.order;
}
});
copperVolumes.forEach((volume) => {
unit8Arrays.push(volume.uint8);
unit16Arrays.push(volume.uint16);
});

const uint8 = new Uint8ClampedArray(
copperVolume.width * copperVolume.height * depth
);
const uint16 = new Uint16Array(uint8.length);
let base8Index = 0;
let base16Index = 0;

unit8Arrays.forEach((array, index) => {
base8Index = index * copperVolume.width * copperVolume.height;
for (let i = 0; i < array.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import "./css/style.css";

console.log(
"%cMedtech Heart Plugin %cBeta:v1.11.7",
"%cMedtech Heart Plugin %cBeta:v1.11.8",
"padding: 3px;color:white; background:#023047",
"padding: 3px;color:white; background:#f50a25"
);
Expand Down
1 change: 1 addition & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ interface copperVolumeType {
invert: boolean;
uint16: Uint16Array;
uint8: Uint8ClampedArray;
order: number;
}

export type {
Expand Down

0 comments on commit 237c8ef

Please sign in to comment.