Exemplo n.º 1
0
 /**
  * decode triangle data found within <jvxlTriangleData> element as created with
  * jvxlEncodeTriangleData (see above)
  *
  * @param tdata tag and contents
  * @param edgeData
  * @param colorData
  * @throws Exception
  */
 void jvxlDecodeTriangleData(String tdata, String edgeData, String colorData) throws Exception {
   int nTriangles = parseIntStr(XmlReader.getXmlAttrib(tdata, "count"));
   if (nTriangles < 0) return;
   int[] nextc = new int[1];
   int nColors = (colorData == null ? -1 : PT.parseIntNext(colorData, nextc));
   int color = 0;
   Logger.info("Reading " + nTriangles + " triangles");
   String encoding = getEncoding(tdata);
   tdata = getData(tdata, "jvxlTriangleData");
   String edata = getData(edgeData, "jvxlTriangleEdgeData");
   int[] vertex = new int[3];
   int[] nextp = new int[1];
   int[] nexte = null;
   int edgeMask = 7;
   boolean haveEdgeInfo;
   boolean haveEncoding = !"none".equals(encoding);
   if (haveEncoding) {
     tdata = JvxlCoder.jvxlDecompressString(tdata);
     edata = JvxlCoder.jvxlDecompressString(edata).trim();
     haveEdgeInfo = (edata.length() == nTriangles);
   } else {
     int n = PT.parseIntNext(tdata, nextp);
     haveEdgeInfo = (edata.length() > 0);
     if (haveEdgeInfo) {
       nexte = new int[1];
       PT.parseIntNext(edata, nexte); // throw away count
     } else if (n > 0) {
       Logger.info("JvxlXmlReader: jvxlTriangleEdgeData count=" + n + "; expected " + nTriangles);
     }
   }
   for (int i = 0, v = 0, p = 0, pt = -1; i < nTriangles; ) {
     if (haveEncoding) {
       char ch = tdata.charAt(++pt);
       int diff;
       switch (ch) {
         case '!':
           diff = 0;
           break;
         case '+':
         case '.':
         case ' ':
         case '\n':
         case '\r':
         case '\t':
         case ',':
           continue;
         case '-':
         case '0':
         case '1':
         case '2':
         case '3':
         case '4':
         case '5':
         case '6':
         case '7':
         case '8':
         case '9':
           nextp[0] = pt;
           diff = PT.parseIntNext(tdata, nextp);
           pt = nextp[0] - 1;
           break;
         default:
           diff = ch - 92; // '\' character
       }
       v += diff;
     } else {
       v = PT.parseIntNext(tdata, nextp) - 1;
     }
     vertex[p] = v;
     if (++p == 3) {
       p = 0;
       if (haveEdgeInfo) {
         edgeMask =
             (nexte == null ? edata.charAt(i) - '0' : javajs.util.PT.parseIntNext(edata, nexte));
         if (edgeMask < 0 || edgeMask > 7) edgeMask = 7;
       }
       if (nColors > 0) {
         int c = PT.parseIntNext(colorData, nextc);
         if (c == Integer.MIN_VALUE) nColors = 0;
         else color = c;
         nColors--;
       }
       addTriangleCheck(vertex[0], vertex[1], vertex[2], edgeMask, 0, false, color);
       i++;
     }
   }
 }
Exemplo n.º 2
0
  @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";
  }