Example #1
0
  void colorIsosurface() {
    if (params.isSquared && volumeData != null) volumeData.filterData(true, Float.NaN);
    /*    if (params.isContoured && marchingSquares == null) {
          //    if (params.isContoured && !(jvxlDataIs2dContour || params.thePlane != null)) {
          Logger.error("Isosurface error: Cannot contour this type of data.");
          return;
        }
    */
    if (meshDataServer != null) {
      meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES, null);
    }

    jvxlData.saveVertexCount = 0;
    if (params.isContoured && marchingSquares != null) {
      initializeMapping();
      params.setMapRanges(this, false);
      marchingSquares.setMinMax(params.valueMappedToRed, params.valueMappedToBlue);
      jvxlData.saveVertexCount = marchingSquares.contourVertexCount;
      contourVertexCount =
          marchingSquares.generateContourData(
              jvxlDataIs2dContour, (params.isSquared ? 1e-8f : 1e-4f));
      jvxlData.contourValuesUsed = marchingSquares.getContourValues();
      minMax = marchingSquares.getMinMax();
      if (meshDataServer != null) meshDataServer.notifySurfaceGenerationCompleted();
      finalizeMapping();
    }

    applyColorScale();
    jvxlData.nContours = (params.contourFromZero ? params.nContours : -1 - params.nContours);
    jvxlData.jvxlFileMessage =
        "mapped: min = " + params.valueMappedToRed + "; max = " + params.valueMappedToBlue;
  }
Example #2
0
 void resetIsosurface() {
   meshData = new MeshData();
   xyzMin = xyzMax = null;
   jvxlData.isBicolorMap = params.isBicolorMap;
   if (meshDataServer != null) meshDataServer.fillMeshData(null, 0, null);
   contourVertexCount = 0;
   if (params.cutoff == Float.MAX_VALUE) params.cutoff = defaultCutoff;
   jvxlData.jvxlSurfaceData = "";
   jvxlData.jvxlEdgeData = "";
   jvxlData.jvxlColorData = "";
   // TODO: more resets of jvxlData?
   edgeCount = 0;
   edgeFractionBase = JvxlCoder.defaultEdgeFractionBase;
   edgeFractionRange = JvxlCoder.defaultEdgeFractionRange;
   colorFractionBase = JvxlCoder.defaultColorFractionBase;
   colorFractionRange = JvxlCoder.defaultColorFractionRange;
   params.mappedDataMin = Float.MAX_VALUE;
 }
Example #3
0
  private void generateSurfaceData() {
    edgeData = "";
    if (vertexDataOnly) {
      try {
        readSurfaceData(false);
      } catch (Exception e) {
        e.printStackTrace();
        Logger.error("Exception in SurfaceReader::readSurfaceData: " + e.getMessage());
      }
      return;
    }
    contourVertexCount = 0;
    int contourType = -1;
    marchingSquares = null;

    if (params.thePlane != null || params.isContoured) {
      marchingSquares =
          new MarchingSquares(
              this,
              volumeData,
              params.thePlane,
              params.contoursDiscrete,
              params.nContours,
              params.thisContour,
              params.contourFromZero);
      contourType = marchingSquares.getContourType();
      marchingSquares.setMinMax(params.valueMappedToRed, params.valueMappedToBlue);
    }
    params.contourType = contourType;
    params.isXLowToHigh = isXLowToHigh;
    marchingCubes = new MarchingCubes(this, volumeData, params, jvxlVoxelBitSet);
    String data = marchingCubes.getEdgeData();
    if (params.thePlane == null) edgeData = data;
    jvxlData.setSurfaceInfoFromBitSet(marchingCubes.getBsVoxels(), params.thePlane);
    jvxlData.jvxlExcluded = params.bsExcluded;
    if (isJvxl) edgeData = jvxlEdgeDataRead;
    postProcessVertices();
  }
Example #4
0
  private void colorData() {

    float[] vertexValues = meshData.vertexValues;
    short[] vertexColixes = meshData.vertexColixes;
    meshData.polygonColixes = null;
    float valueBlue = jvxlData.valueMappedToBlue;
    float valueRed = jvxlData.valueMappedToRed;
    short minColorIndex = jvxlData.minColorIndex;
    short maxColorIndex = jvxlData.maxColorIndex;
    if (params.colorEncoder == null) params.colorEncoder = new ColorEncoder(null);
    params.colorEncoder.setRange(
        params.valueMappedToRed, params.valueMappedToBlue, params.isColorReversed);
    for (int i = meshData.vertexCount; --i >= 0; ) {
      float value = vertexValues[i];
      if (minColorIndex >= 0) {
        if (value <= 0) vertexColixes[i] = minColorIndex;
        else if (value > 0) vertexColixes[i] = maxColorIndex;
      } else {
        if (value <= valueRed) value = valueRed;
        if (value >= valueBlue) value = valueBlue;
        vertexColixes[i] = params.colorEncoder.getColorIndex(value);
      }
    }

    if ((params.nContours > 0 || jvxlData.contourValues != null)
        && jvxlData.contourColixes == null) {
      int n = (jvxlData.contourValues == null ? params.nContours : jvxlData.contourValues.length);
      short[] colors = jvxlData.contourColixes = new short[n];
      float[] values = jvxlData.contourValues;
      if (values == null) values = jvxlData.contourValuesUsed;
      if (jvxlData.contourValuesUsed == null)
        jvxlData.contourValuesUsed = (values == null ? new float[n] : values);
      float dv = (valueBlue - valueRed) / (n + 1);
      // n + 1 because we want n lines between n + 1 slices
      params.colorEncoder.setRange(
          params.valueMappedToRed, params.valueMappedToBlue, params.isColorReversed);
      for (int i = 0; i < n; i++) {
        float v = (values == null ? valueRed + (i + 1) * dv : values[i]);
        jvxlData.contourValuesUsed[i] = v;
        colors[i] = Graphics3D.getColixTranslucent(params.colorEncoder.getArgb(v));
      }
      // TODO -- this strips translucency
      jvxlData.contourColors = Graphics3D.getHexCodes(colors);
    }
  }
Example #5
0
  void applyColorScale() {
    colorFractionBase = jvxlData.colorFractionBase = JvxlCoder.defaultColorFractionBase;
    colorFractionRange = jvxlData.colorFractionRange = JvxlCoder.defaultColorFractionRange;
    if (params.colorPhase == 0) params.colorPhase = 1;
    if (meshDataServer == null) {
      meshData.vertexColixes = new short[meshData.vertexCount];
    } else {
      meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES, null);
      if (params.contactPair == null)
        meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_COLOR_INDEXES, null);
    }
    // colorBySign is true when colorByPhase is true, but not vice-versa
    // old: boolean saveColorData = !(params.colorByPhase && !params.isBicolorMap &&
    // !params.colorBySign); //sorry!
    boolean saveColorData =
        (params.colorDensity || params.isBicolorMap || params.colorBySign || !params.colorByPhase);
    if (params.contactPair != null) saveColorData = false;
    // colors mappable always now
    jvxlData.isJvxlPrecisionColor = true;
    jvxlData.vertexCount = (contourVertexCount > 0 ? contourVertexCount : meshData.vertexCount);
    jvxlData.minColorIndex = -1;
    jvxlData.maxColorIndex = 0;
    jvxlData.contourValues = params.contoursDiscrete;
    jvxlData.isColorReversed = params.isColorReversed;
    if (!params.colorDensity)
      if (params.isBicolorMap && !params.isContoured || params.colorBySign) {
        jvxlData.minColorIndex =
            Graphics3D.getColixTranslucent(
                Graphics3D.getColix(params.isColorReversed ? params.colorPos : params.colorNeg),
                jvxlData.translucency != 0,
                jvxlData.translucency);
        jvxlData.maxColorIndex =
            Graphics3D.getColixTranslucent(
                Graphics3D.getColix(params.isColorReversed ? params.colorNeg : params.colorPos),
                jvxlData.translucency != 0,
                jvxlData.translucency);
      }
    jvxlData.isTruncated = (jvxlData.minColorIndex >= 0 && !params.isContoured);
    boolean useMeshDataValues =
        jvxlDataIs2dContour
            ||
            //      !jvxlDataIs2dContour && (params.isContoured && jvxlData.jvxlPlane != null ||
            hasColorData
            || vertexDataOnly
            || params.colorDensity
            || params.isBicolorMap && !params.isContoured;
    if (!useMeshDataValues) {
      if (haveSurfaceAtoms && meshData.vertexSource == null)
        meshData.vertexSource = new int[meshData.vertexCount];
      float min = Float.MAX_VALUE;
      float max = -Float.MAX_VALUE;
      float value;
      initializeMapping();
      for (int i = meshData.vertexCount; --i >= meshData.mergeVertexCount0; ) {
        /* right, so what we are doing here is setting a range within the
         * data for which we want red-->blue, but returning the actual
         * number so it can be encoded more precisely. This turned out to be
         * the key to making the JVXL contours work.
         *
         */
        if (params.colorBySets) {
          value = meshData.vertexSets[i];
        } else if (params.colorByPhase) {
          value = getPhase(meshData.vertices[i]);
          // else if (jvxlDataIs2dContour)
          // marchingSquares
          //    .getInterpolatedPixelValue(meshData.vertices[i]);
        } else {
          value = volumeData.lookupInterpolatedVoxelValue(meshData.vertices[i]);
          if (haveSurfaceAtoms) meshData.vertexSource[i] = getSurfaceAtomIndex();
        }
        if (value < min) min = value;
        if (value > max && value != Float.MAX_VALUE) max = value;
        meshData.vertexValues[i] = value;
      }
      if (params.rangeSelected && minMax == null) minMax = new float[] {min, max};
      finalizeMapping();
    }
    params.setMapRanges(this, true);
    jvxlData.mappedDataMin = params.mappedDataMin;
    jvxlData.mappedDataMax = params.mappedDataMax;
    jvxlData.valueMappedToRed = params.valueMappedToRed;
    jvxlData.valueMappedToBlue = params.valueMappedToBlue;
    if (params.contactPair == null) colorData();

    JvxlCoder.jvxlCreateColorData(jvxlData, (saveColorData ? meshData.vertexValues : null));

    if (haveSurfaceAtoms && meshDataServer != null)
      meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_VERTICES, null);

    if (meshDataServer != null && params.colorBySets)
      meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_SETS, null);
  }
Example #6
0
  boolean createIsosurface(boolean justForPlane) {
    resetIsosurface();
    jvxlData.cutoff = Float.NaN;
    if (!readAndSetVolumeParameters(justForPlane)) return false;
    if (!justForPlane && !Float.isNaN(params.sigma) && !allowSigma) {
      if (params.sigma > 0)
        Logger.error("Reader does not support SIGMA option -- using cutoff 1.6");
      params.cutoff = 1.6f;
    }
    // negative sigma just ignores the error message
    // and means it was inserted by Jmol as a default option
    if (params.sigma < 0) params.sigma = -params.sigma;
    nPointsX = voxelCounts[0];
    nPointsY = voxelCounts[1];
    nPointsZ = voxelCounts[2];
    jvxlData.isSlabbable = ((params.dataType & Parameters.IS_SLABBABLE) != 0);
    jvxlData.insideOut = params.insideOut;
    jvxlData.dataXYReversed = params.dataXYReversed;
    jvxlData.isBicolorMap = params.isBicolorMap;
    jvxlData.nPointsX = nPointsX;
    jvxlData.nPointsY = nPointsY;
    jvxlData.nPointsZ = nPointsZ;
    jvxlData.jvxlVolumeDataXml = volumeData.xmlData;
    jvxlData.voxelVolume = volumeData.voxelVolume;
    if (justForPlane) {
      // float[][][] voxelDataTemp =  volumeData.voxelData;
      volumeData.setMappingPlane(params.thePlane);
      // volumeData.setDataDistanceToPlane(params.thePlane);
      if (meshDataServer != null)
        meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES, null);
      params.setMapRanges(this, false);
      generateSurfaceData();
      volumeData.setMappingPlane(null);

      // if (volumeData != null)
      //  volumeData.voxelData = voxelDataTemp;
    } else {
      if (!readVolumeData(false)) return false;
      generateSurfaceData();
    }
    if (jvxlFileHeaderBuffer != null) {
      String s = jvxlFileHeaderBuffer.toString();
      int i = s.indexOf('\n', s.indexOf('\n', s.indexOf('\n') + 1) + 1) + 1;
      jvxlData.jvxlFileTitle = s.substring(0, i);
    }
    if (params.contactPair == null) setBoundingBox();
    if (!params.isSilent)
      Logger.info("boundbox corners " + Escape.escape(xyzMin) + " " + Escape.escape(xyzMax));
    jvxlData.boundingBox = new Point3f[] {xyzMin, xyzMax};
    jvxlData.dataMin = dataMin;
    jvxlData.dataMax = dataMax;
    jvxlData.cutoff = (isJvxl ? jvxlCutoff : params.cutoff);
    jvxlData.isCutoffAbsolute = params.isCutoffAbsolute;
    jvxlData.pointsPerAngstrom = 1f / volumeData.volumetricVectorLengths[0];
    jvxlData.jvxlColorData = "";
    jvxlData.jvxlPlane = params.thePlane;
    jvxlData.jvxlEdgeData = edgeData;
    jvxlData.isBicolorMap = params.isBicolorMap;
    jvxlData.isContoured = params.isContoured;
    jvxlData.colorDensity = params.colorDensity;
    if (jvxlData.vContours != null) params.nContours = jvxlData.vContours.length;
    jvxlData.nContours = (params.contourFromZero ? params.nContours : -1 - params.nContours);
    jvxlData.nEdges = edgeCount;
    jvxlData.edgeFractionBase = edgeFractionBase;
    jvxlData.edgeFractionRange = edgeFractionRange;
    jvxlData.colorFractionBase = colorFractionBase;
    jvxlData.colorFractionRange = colorFractionRange;
    jvxlData.jvxlDataIs2dContour = jvxlDataIs2dContour;
    jvxlData.jvxlDataIsColorMapped = jvxlDataIsColorMapped;
    jvxlData.jvxlDataIsColorDensity = jvxlDataIsColorDensity;
    jvxlData.isXLowToHigh = isXLowToHigh;
    jvxlData.vertexDataOnly = vertexDataOnly;
    jvxlData.saveVertexCount = 0;

    if (jvxlDataIsColorMapped || jvxlData.nVertexColors > 0) {
      if (meshDataServer != null) {
        meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES, null);
        meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_COLOR_INDEXES, null);
      }
      jvxlData.jvxlColorData = readColorData();
      updateSurfaceData();
      if (meshDataServer != null) meshDataServer.notifySurfaceMappingCompleted();
    }
    return true;
  }