in src/engine/tools23d/mprrenderer.js [165:315]
onFileLoaded() {
this.clearScene();
const volTexture = this.m_objGraphics2d.m_volTexture;
const VPORT_SIZE = 1.0;
const Z_COORD = 0.8;
let i;
const SIZE_SCREEN = 2.0;
for (i = 0; i < NUM_PROJECTIONS; i++) {
const XMin = -VPORT_SIZE + ((i + 0) * SIZE_SCREEN) / NUM_PROJECTIONS;
const XMax = -VPORT_SIZE + ((i + 1) * SIZE_SCREEN) / NUM_PROJECTIONS;
// define correct vertical rect dimension
// to look slice proportional
let wPhys = 0,
hPhys = 0;
if (i === PROJECTION_X) {
wPhys = this.m_objGraphics2d.m_volumeBox.y;
hPhys = this.m_objGraphics2d.m_volumeBox.z;
} else if (i === PROJECTION_Y) {
wPhys = this.m_objGraphics2d.m_volumeBox.x;
hPhys = this.m_objGraphics2d.m_volumeBox.z;
} else if (i === PROJECTION_Z) {
wPhys = this.m_objGraphics2d.m_volumeBox.x;
hPhys = this.m_objGraphics2d.m_volumeBox.y;
}
const wPart = this.m_width / NUM_PROJECTIONS;
let wScreen = wPart;
let hScreen = (wScreen * hPhys) / wPhys;
if (hScreen > this.m_height) {
hScreen = this.m_height;
wScreen = (hScreen * wPhys) / hPhys;
}
// console.log(`Proportion is: ${wScreen} * ${hScreen}`);
// normalize to [0..1]
hScreen /= this.m_height;
// no need to normalize to [0..2]
// proportions on height
//
// ^ +--------+
// | | |
// | | +--+ | ^
// 2 | | | | | hScreen
// | | +--+ | v
// | | |
// v +--------+
//
const YMin = -hScreen;
const YMax = +hScreen;
this.m_projectionRect[i] = {
xMin: XMin,
yMin: YMin,
xMax: XMax,
yMax: YMax,
};
// v2 ----- v3
// | |
// | |
// v0 ----- v1
const v0 = new THREE.Vector3(XMin, YMin, Z_COORD);
const v1 = new THREE.Vector3(XMax, YMin, Z_COORD);
const v2 = new THREE.Vector3(XMin, YMax, Z_COORD);
const v3 = new THREE.Vector3(XMax, YMax, Z_COORD);
const geo = this.m_geo[i];
geo.vertices[0] = v0;
geo.vertices[1] = v1;
geo.vertices[2] = v2;
geo.vertices[3] = v3;
// add texture coordinates
//
// (0,2) | (1,0)
// (1,1) |
// ------+------> x
// |
// |
// (0,0) v y (0,1)
// (1,2)
geo.faceVertexUvs[0][0] = [new THREE.Vector2(0.0, 1.0), new THREE.Vector2(1.0, 1.0), new THREE.Vector2(0.0, 0.0)];
geo.faceVertexUvs[0][1] = [new THREE.Vector2(1.0, 0.0), new THREE.Vector2(0.0, 0.0), new THREE.Vector2(1.0, 1.0)];
const normal = new THREE.Vector3();
THREE.Triangle.getNormal(v0, v1, v2, normal);
// eslint-disable-next-line
geo.faces[0] = new THREE.Face3(0, 1, 2, normal);
// eslint-disable-next-line
geo.faces[1] = new THREE.Face3(3, 2, 1, normal);
const matTex2d = new MaterialTex2d();
this.m_material[i] = matTex2d;
const xDim = this.m_objGraphics2d.m_volumeHeader.m_pixelWidth;
const yDim = this.m_objGraphics2d.m_volumeHeader.m_pixelHeight;
const zDim = this.m_objGraphics2d.m_volumeHeader.m_pixelDepth;
// get dim for current slice (one between X, Y or Z) and slice index, based on ratio
let dim = xDim;
dim = i === PROJECTION_Y ? yDim : dim;
dim = i === PROJECTION_Z ? zDim : dim;
const sliceIndex = Math.floor(this.m_sliceRatio[i] * dim);
// console.log(`Create mat. vol ${xDim}*${yDim}*${zDim}. sliceIndex=${sliceIndex} `);
// eslint-disable-next-line
const axisIndex = 2 - i; // inside matTex2d.create it should be X - 0 or Y - 1 or Z - 2
matTex2d.create(volTexture, xDim, yDim, zDim, axisIndex, sliceIndex, this.m_objGraphics2d.m_isRoiVolume);
const mat = matTex2d.m_material;
this.m_meshes[i] = new THREE.Mesh(geo, mat);
this.m_scene.add(this.m_meshes[i]);
} // for (i)
// draw bounding lines
const R_MATERIAL = 0.86;
const G_MATERIAL = 0.59;
const B_MATERIAL = 0.17;
const mat = new MaterialColor2d(R_MATERIAL, G_MATERIAL, B_MATERIAL);
const minCoord = -1 + this.m_vertLineWidth;
const maxCoord = 1 - this.m_vertLineWidth;
const halfLineWidth = this.m_vertLineWidth * 0.5;
this.m_boundLines[0] = new Line2D(this.m_scene, this.m_horLineWidth, minCoord, maxCoord, maxCoord, maxCoord, mat);
this.m_boundLines[1] = new Line2D(this.m_scene, this.m_vertLineWidth, maxCoord, maxCoord, maxCoord, minCoord, mat);
this.m_boundLines[2] = new Line2D(this.m_scene, this.m_horLineWidth, maxCoord, minCoord, minCoord, minCoord, mat);
this.m_boundLines[3] = new Line2D(this.m_scene, this.m_vertLineWidth, minCoord, minCoord, minCoord, maxCoord, mat);
this.m_boundLines[4] = new Line2D(
this.m_scene,
this.m_vertLineWidth,
this.m_projectionRect[0].xMax - halfLineWidth,
minCoord,
this.m_projectionRect[0].xMax - halfLineWidth,
maxCoord,
mat
);
this.m_boundLines[5] = new Line2D(
this.m_scene,
this.m_vertLineWidth,
this.m_projectionRect[1].xMax - halfLineWidth,
minCoord,
this.m_projectionRect[1].xMax - halfLineWidth,
maxCoord,
mat
);
this.m_sliceRatio[PROJECTION_X] = 0.5;
this.m_sliceRatio[PROJECTION_Y] = 0.5;
this.m_sliceRatio[PROJECTION_Z] = 0.5;
this.updateControlLines();
}