Example #1
0
 private void setProp(Ellipsoid e, int mode, Object value) {
   // "ax ce co de eq mo on op sc tr"
   //  0  1  2  3  4  5  6  7  8  9
   switch (mode) {
     case 0: // axes
       e.setTensor(
           ((Tensor) Interface.getUtil("Tensor", vwr, "script")).setFromAxes((V3[]) value));
       return;
     case 1: // center
       e.setCenter((P3) value);
       return;
     case 2: // color
       e.colix = C.getColixO(value);
       return;
     case 3: // delete
       simpleEllipsoids.remove(e.id);
       return;
     case 4: // equation
       e.setTensor(
           ((Tensor) Interface.getUtil("Tensor", vwr, "script"))
               .setFromThermalEquation((double[]) value, null));
       return;
     case 5: // modelindex
       e.tensor.modelIndex = ((Integer) value).intValue();
       return;
     case 6: // on
       e.isOn = ((Boolean) value).booleanValue();
       return;
     case 7: // options
       e.options = ((String) value).toLowerCase();
       return;
     case 8: // scale
       e.setScale(((Float) value).floatValue(), false);
       return;
     case 9: // translucency
       e.colix = C.getColixTranslucent3(e.colix, value.equals("translucent"), translucentLevel);
       return;
   }
   return;
 }
  @Override
  protected String readColorData() {
    if (!jvxlDataIsColorMapped) return "";
    // overloads SurfaceReader
    // standard jvxl file read for color

    int vertexCount = jvxlData.vertexCount = meshData.vertexCount;
    // the problem is that the new way to read data in Marching Cubes
    // is to ignore all points that are NaN. But then we also have to
    // remove those points from the color string.

    short[] colixes = meshData.vertexColixes;
    float[] vertexValues = meshData.vertexValues;
    /*
     * haveReadColorData?
     = (isJvxl ? jvxlColorDataRead : "");
    if (isJvxl && strValueTemp.length() == 0) {
      Logger
          .error("You cannot use JVXL data to map onto OTHER data, because it only contains the data for one surface. Use ISOSURFACE \"file.jvxl\" not ISOSURFACE .... MAP \"file.jvxl\".");
      return "";
    }
    */

    if ("none".equals(jvxlColorEncodingRead)) {
      jvxlData.vertexColors = new int[vertexCount];
      int[] nextc = new int[1];
      int n = PT.parseIntNext(jvxlColorDataRead, nextc);
      n = Math.min(n, vertexCount);
      String[] tokens = PT.getTokens(jvxlColorDataRead.substring(nextc[0]));
      boolean haveTranslucent = false;
      float trans = jvxlData.translucency;
      int lastColor = 0;
      for (int i = 0; i < n; i++)
        // colix will be one of 8 shades of translucent if A in ARGB is not FF.
        try {
          int c = getColor(tokens[i]);
          if (c == 0) c = lastColor;
          else lastColor = c;
          colixes[i] = C.getColixTranslucent(jvxlData.vertexColors[i] = c);
          if (C.isColixTranslucent(colixes[i])) haveTranslucent = true;
          else if (trans != 0) colixes[i] = C.getColixTranslucent3(colixes[i], true, trans);
        } catch (Exception e) {
          Logger.info("JvxlXmlReader: Cannot interpret color code: " + tokens[i]);
          // ignore this color if parsing error
        }
      if (haveTranslucent && trans == 0) {
        // set to show in pass2
        jvxlData.translucency = 0.5f;
      }
      return "-";
    }
    if (params.colorEncoder == null) params.colorEncoder = new ColorEncoder(null);
    params.colorEncoder.setColorScheme(null, false);
    params.colorEncoder.setRange(
        params.valueMappedToRed, params.valueMappedToBlue, params.isColorReversed);
    Logger.info(
        "JVXL reading color data mapped min/max: "
            + params.mappedDataMin
            + "/"
            + params.mappedDataMax
            + " for "
            + vertexCount
            + " vertices."
            + " using encoding keys "
            + colorFractionBase
            + " "
            + colorFractionRange);
    Logger.info(
        "mapping red-->blue for "
            + params.valueMappedToRed
            + " to "
            + params.valueMappedToBlue
            + " colorPrecision:"
            + jvxlData.isJvxlPrecisionColor);
    boolean getValues = (Float.isNaN(valueMin));
    if (getValues) setValueMinMax();
    float contourPlaneMinimumValue = Float.MAX_VALUE;
    float contourPlaneMaximumValue = -Float.MAX_VALUE;
    if (colixes == null || colixes.length < vertexCount)
      meshData.vertexColixes = colixes = new short[vertexCount];
    // hasColorData = true;
    short colixNeg = 0, colixPos = 0;
    if (params.colorBySign) {
      colixPos = C.getColix(params.isColorReversed ? params.colorNeg : params.colorPos);
      colixNeg = C.getColix(params.isColorReversed ? params.colorPos : params.colorNeg);
    }
    int vertexIncrement = meshData.vertexIncrement;
    // here's the problem: we are assuming here that vertexCount == nPointsRead
    boolean needContourMinMax = (params.mappedDataMin == Float.MAX_VALUE);
    for (int i = 0; i < vertexCount; i += vertexIncrement) {
      float value;
      if (getValues) value = vertexValues[i] = getNextValue();
      else value = vertexValues[i];
      if (needContourMinMax) {
        if (value < contourPlaneMinimumValue) contourPlaneMinimumValue = value;
        if (value > contourPlaneMaximumValue) contourPlaneMaximumValue = value;
      }
    }
    if (needContourMinMax) {
      params.mappedDataMin = contourPlaneMinimumValue;
      params.mappedDataMax = contourPlaneMaximumValue;
    }
    if (jvxlData.colorScheme != null)
      for (int i = 0; i < vertexCount; i += vertexIncrement) {
        float value = vertexValues[i];
        // note: these are just default colorings
        // orbital color had a bug through 11.2.6/11.3.6
        if (marchingSquares != null && params.isContoured) {
          marchingSquares.setContourData(i, value);
          continue;
        }
        short colix =
            (!params.colorBySign
                ? params.colorEncoder.getColorIndex(value)
                : (params.isColorReversed ? value > 0 : value <= 0) ? colixNeg : colixPos);
        colixes[i] = C.getColixTranslucent3(colix, true, jvxlData.translucency);
      }
    return jvxlColorDataRead + "\n";
  }
Example #3
0
  @Override
  public void setProperty(String propertyName, Object value, BS bs) {
    // System.out.println(propertyName + " " + value + " " + bs);
    if (propertyName == "thisID") {
      if (initEllipsoids(value) && ellipsoidSet.size() == 0) {
        String id = (String) value;
        Ellipsoid e = Ellipsoid.getEmptyEllipsoid(id, vwr.am.cmi);
        ellipsoidSet.addLast(e);
        simpleEllipsoids.put(id, e);
      }
      return;
    }

    if ("atoms" == propertyName) {
      selectedAtoms = (BS) value;
      return;
    }

    if (propertyName == "deleteModelAtoms") {
      int modelIndex = ((int[]) ((Object[]) value)[2])[0];
      Iterator<Ellipsoid> e = simpleEllipsoids.values().iterator();
      while (e.hasNext()) if (e.next().tensor.modelIndex == modelIndex) e.remove();
      e = atomEllipsoids.values().iterator();
      while (e.hasNext()) if (e.next().modelIndex == modelIndex) e.remove();
      ellipsoidSet.clear();
      return;
    }
    int mode = PROPERTY_MODES.indexOf((propertyName + "  ").substring(0, 2));
    if (ellipsoidSet.size() > 0) {
      if ("translucentLevel" == propertyName) {
        setPropS(propertyName, value, bs);
        return;
      }
      if (mode >= 0)
        for (int i = ellipsoidSet.size(); --i >= 0; ) setProp(ellipsoidSet.get(i), mode / 3, value);
      return;
    }

    if ("color" == propertyName) {
      short colix = C.getColixO(value);
      byte pid = PAL.pidOf(value);
      if (selectedAtoms != null) bs = selectedAtoms;
      for (Ellipsoid e : atomEllipsoids.values())
        if (e.tensor.type.equals(typeSelected) && e.tensor.isSelected(bs, -1)) {
          e.colix = getColixI(colix, pid, e.tensor.atomIndex1);
          e.pid = pid;
        }
      return;
    }

    if ("on" == propertyName) {
      boolean isOn = ((Boolean) value).booleanValue();
      if (selectedAtoms != null) bs = selectedAtoms;
      if (isOn) setSize(Integer.MAX_VALUE, bs);
      for (Ellipsoid e : atomEllipsoids.values()) {
        Tensor t = e.tensor;
        if ((t.type.equals(typeSelected) || typeSelected.equals(t.altType))
            && t.isSelected(bs, -1)) {
          e.isOn = isOn;
        }
      }
      return;
    }

    if ("options" == propertyName) {
      String options = ((String) value).toLowerCase().trim();
      if (options.length() == 0) options = null;
      if (selectedAtoms != null) bs = selectedAtoms;
      if (options != null) setSize(Integer.MAX_VALUE, bs);
      for (Ellipsoid e : atomEllipsoids.values())
        if (e.tensor.type.equals(typeSelected) && e.tensor.isSelected(bs, -1)) e.options = options;
      return;
    }

    if ("params" == propertyName) {
      Object[] data = (Object[]) value;
      data[2] = null; // Jmol does not allow setting sizes this way from PyMOL yet
      typeSelected = "0";
      setSize(50, bs);
      // onward...
    }

    if ("points" == propertyName) {
      // Object[] o = (Object[]) value;
      // setPoints((P3[]) o[1], (BS) o[2]);
      return;
    }

    if ("scale" == propertyName) {
      setSize((int) (((Float) value).floatValue() * 100), bs);
      return;
    }

    if ("select" == propertyName) {
      typeSelected = ((String) value).toLowerCase();
      return;
    }

    if ("translucency" == propertyName) {
      boolean isTranslucent = (value.equals("translucent"));
      for (Ellipsoid e : atomEllipsoids.values())
        if (e.tensor.type.equals(typeSelected) && e.tensor.isSelected(bs, -1))
          e.colix = C.getColixTranslucent3(e.colix, isTranslucent, translucentLevel);
      return;
    }
    setPropS(propertyName, value, bs);
  }
Example #4
0
 public void setTranslucent(boolean isTranslucent, float translucentLevel) {
   colix = C.getColixTranslucent3(colix, isTranslucent, translucentLevel);
 }