updateGeo()

in src/engine/actvolume/actvol.js [963:1077]


  updateGeo(geo, method) {
    if (geo === 'undefined') {
      console.log('ActiveVolume. updateGeo: geo undefined');
      const FAIL_UNDEF = -1;
      return FAIL_UNDEF;
    }
    if (geo === null) {
      console.log('ActiveVolume. updateGeo: geo null');
      const FAIL_NULL = -2;
      return FAIL_NULL;
    }

    if (this.m_state === AV_STATE_FINISHED) {
      return 1;
    }
    if (this.m_state === AV_STATE_NOT_STARTED) {
      // first update
      const okCreateNormals = geo.createNormalsForGeometry();
      if (okCreateNormals !== 1) {
        console.log('geo.createNormalsForGeometry returned fail');
        return okCreateNormals;
      }

      this.startImageSmooth();
      this.m_gaussStage = 0;
      this.m_state = AV_STATE_PREPARE_GAUSS;
    }
    if (this.m_state === AV_STATE_PREPARE_GAUSS) {
      const GAUSS_RAD = 2;
      const GAUSS_SIGMA = 1.8;
      const zStart = Math.floor((this.m_zDim * (this.m_gaussStage + 0)) / ActiveVolume.ACT_VOL_NUM_SMOOTH_STAGES);
      const zEnd = Math.floor((this.m_zDim * (this.m_gaussStage + 1)) / ActiveVolume.ACT_VOL_NUM_SMOOTH_STAGES);
      this.applyPartGaussSmooth(zStart, zEnd, GAUSS_RAD, GAUSS_SIGMA);

      this.m_gaussStage++;
      if (this.m_gaussStage >= ActiveVolume.ACT_VOL_NUM_SMOOTH_STAGES) {
        this.m_state = AV_STATE_PREPARE_UNIFORMITY;
        this.m_uniformityStage = 0;
        console.log('UpdateGeo. AV_STATE_PREPARE_UNIFORMITY.');
        return 1;
      }
    }
    if (this.m_state === AV_STATE_PREPARE_UNIFORMITY) {
      const zStart = Math.floor((this.m_zDim * (this.m_uniformityStage + 0)) / ActiveVolume.ACT_VOL_NUM_SMOOTH_STAGES);
      const zEnd = Math.floor((this.m_zDim * (this.m_uniformityStage + 1)) / ActiveVolume.ACT_VOL_NUM_SMOOTH_STAGES);
      const KOEF_UNIFORMITY = 0.07;
      this.makeUniformityImage(
        this.m_imageGauss,
        this.m_xDim,
        this.m_yDim,
        this.m_zDim,
        zStart,
        zEnd,
        this.m_imageGrad,
        this.m_imageUniformity,
        KOEF_UNIFORMITY
      );
      this.m_uniformityStage++;
      if (this.m_uniformityStage >= ActiveVolume.ACT_VOL_NUM_SMOOTH_STAGES) {
        // DEBUG save
        const DEBUG_SAVE_UNI = false;
        if (DEBUG_SAVE_UNI) {
          const TEST_SAVE_UNI_FILE_NAME = 'uni.bmp';
          const TWO = 2;
          const zSlice = this.m_zDim / TWO;
          ActiveVolume.saveVolumeSliceToFile(
            this.m_imageUniformity,
            this.m_xDim,
            this.m_yDim,
            this.m_zDim,
            zSlice,
            TEST_SAVE_UNI_FILE_NAME
          );
        }

        // finally get image histogram
        // console.log('UpdateGeo. getHistogram...');
        this.getHistogram();
        this.stopImageSmooth();
        this.m_geoStage = 0;
        this.m_state = AV_STATE_UPDATE_GEO;
        // console.log('UpdateGeo. AV_STATE_UPDATE_GEO.');
        return 1;
      }
    }

    if (this.m_state === AV_STATE_UPDATE_GEO) {
      if (this.m_verticesNew === null) {
        const numVertices = geo.getNumVertices();
        const COORDS_IN_VERTREX = 4;
        this.m_verticesNew = new Float32Array(numVertices * COORDS_IN_VERTREX);
      }

      const updateNormals = (method & AV_METHOD_NORMALS) !== 0;
      const updateUniformity = (method & AV_METHOD_UNIFORMITY) !== 0;
      const updateColorKoefs = (method & AV_METHOD_COLOR_KOEFS) !== 0;

      const SPEED_NORMALS = 1.1;
      if (updateNormals && !updateUniformity) {
        this.updateGeoByVertexNormals(geo, SPEED_NORMALS);
      }
      if (updateNormals && updateUniformity && !updateColorKoefs) {
        this.updateGeoByVertexNormalsAndUniformity(geo, SPEED_NORMALS);
      }
      if (updateNormals && updateUniformity && updateColorKoefs) {
        const isFinished = this.updateGeoNormalsUniformityColors(geo, SPEED_NORMALS);
        if (isFinished) {
          console.log(`updateGeoNormalsUniformityColors is FINISHED. m_geoStage = ${this.m_geoStage}`);
          this.m_state = AV_STATE_FINISHED;
        }
      }
      this.m_geoStage++;
    } // if state is update geo
    return 1;
  }