in src/engine/actvolume/actvol.js [107:209]
skullRemoveStart(xDim, yDim, zDim, volTexSrc, volTexDst, createType, needLog) {
const TOO_MUCH_SIZE = 8192;
if (createType !== ActiveVolume.REMOVE_SKULL && createType !== ActiveVolume.CREATE_MASK) {
console.log('skullRemoveStart: wrong argument createType');
}
if (xDim >= TOO_MUCH_SIZE || yDim >= TOO_MUCH_SIZE || zDim >= TOO_MUCH_SIZE) {
console.log(`Too bad volume dimension: ${xDim} * ${yDim} * ${zDim}`);
return -1;
}
if (xDim <= 1 || yDim <= 1 || zDim <= 1) {
console.log(`Too bad volume dimension: ${xDim} * ${yDim} * ${zDim}`);
return -1;
}
const volSizeSrc = volTexSrc.length;
const numPixSrc = xDim * yDim * zDim;
if (volSizeSrc !== numPixSrc) {
console.log(`skullRemoveStart: bad vol size = ${volSizeSrc}, expected ${numPixSrc}`);
return -1;
}
const okCreate = this.create(xDim, yDim, zDim, volTexSrc);
if (okCreate !== 1) {
return okCreate;
}
const genTetra = new TetrahedronGenerator();
const vRadius = new THREE.Vector3(0.5, 0.5, 0.5);
const NUM_SUBDIVIDES = 3;
const okCreateTetra = genTetra.create(vRadius, NUM_SUBDIVIDES);
if (okCreateTetra < 1) {
return okCreateTetra;
}
const geoRender = new GeoRender();
const errGeo = geoRender.createFromTetrahedronGenerator(genTetra);
const GEO_OK = 1;
if (errGeo !== GEO_OK) {
const ERR_CREATE_GEO = -3;
return ERR_CREATE_GEO;
}
// get half from volume dimension
const xDim2 = Math.floor((this.m_xDim - 1) * 0.5);
const yDim2 = Math.floor((this.m_yDim - 1) * 0.5);
const zDim2 = Math.floor((this.m_zDim - 1) * 0.5);
// scale geo render vertices
const numVertices = geoRender.getNumVertices();
const vertices = geoRender.getVertices();
const COORDS_IN_VERTEX = 4;
const NUM_0 = 0;
const NUM_1 = 1;
const NUM_2 = 2;
for (let i = 0, i4 = 0; i < numVertices; i++, i4 += COORDS_IN_VERTEX) {
vertices[i4 + NUM_0] = xDim2 + xDim2 * vertices[i4 + NUM_0];
vertices[i4 + NUM_1] = yDim2 + yDim2 * vertices[i4 + NUM_1];
vertices[i4 + NUM_2] = zDim2 + zDim2 * vertices[i4 + NUM_2];
} // for (i) all vertices
// save render geo to obj file
const NEED_SAVE_INITIAL_GEO = false;
if (NEED_SAVE_INITIAL_GEO) {
const TEST_SAVE_INIT_GEO_FILE_NAME = 'geo_init.obj';
geoRender.saveGeoToObjFile(TEST_SAVE_INIT_GEO_FILE_NAME);
}
// Test save bounding sphere
const NEED_SAVE_BOUND_SPHERE = false;
if (NEED_SAVE_BOUND_SPHERE) {
const vMin = new THREE.Vector3();
const vMax = new THREE.Vector3();
ActiveVolume.getBoundingBox(this.m_xDim, this.m_yDim, this.m_zDim, this.m_pixelsSrc, vMin, vMax);
const geoSphere = new GeoRender();
const vCenter = new THREE.Vector3();
const vRad = new THREE.Vector3();
vCenter.x = (vMin.x + vMax.x) * 0.5;
vCenter.y = (vMin.y + vMax.y) * 0.5;
vCenter.z = (vMin.z + vMax.z) * 0.5;
vRad.x = (vMax.x - vMin.x) * 0.5;
vRad.y = (vMax.y - vMin.y) * 0.5;
vRad.z = (vMax.z - vMin.z) * 0.5;
const NUM_SEGM_HOR = 16;
const NUM_SEGM_VER = 8;
geoSphere.createFromEllipse(vCenter, vRad, NUM_SEGM_HOR, NUM_SEGM_VER);
const TEST_SAVE_BSPHERE_GEO_FILE_NAME = 'geo_bsph.obj';
geoSphere.saveGeoToObjFile(TEST_SAVE_BSPHERE_GEO_FILE_NAME);
}
let numPredSteps = this.getPredictedStepsForActiveVolumeUpdate();
const SOME_ADD_STEPS = 12;
numPredSteps += SOME_ADD_STEPS;
const strTypeArr = ['REMOVE_SKULL', 'CREATE_MASK'];
const strType = strTypeArr[createType];
console.log(`skullRemoveStart. Will be ${numPredSteps} updates approximately. In ${strType} mode `);
this.m_updateCounter = 0;
this.m_isFinished = false;
this.m_numPredSteps = numPredSteps;
this.m_createType = createType;
this.m_volTexSrc = volTexSrc;
this.m_volTexDst = volTexDst;
this.m_needLog = needLog;
return geoRender;
}