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); } }
protected void jvxlDecodeContourData(JvxlData jvxlData, String data) throws Exception { List<List<Object>> vs = new List<List<Object>>(); SB values = new SB(); SB colors = new SB(); int pt = -1; jvxlData.vContours = null; if (data == null) return; while ((pt = data.indexOf("<jvxlContour", pt + 1)) >= 0) { List<Object> v = new List<Object>(); String s = xr.getXmlData("jvxlContour", data.substring(pt), true, false); float value = parseFloatStr(XmlReader.getXmlAttrib(s, "value")); values.append(" ").appendF(value); int color = getColor(XmlReader.getXmlAttrib(s, "color")); short colix = C.getColix(color); colors.append(" ").append(Escape.escapeColor(color)); String fData = JvxlCoder.jvxlDecompressString(XmlReader.getXmlAttrib(s, "data")); BS bs = JvxlCoder.jvxlDecodeBitSet(xr.getXmlData("jvxlContour", s, false, false)); int n = bs.length(); IsosurfaceMesh.setContourVector(v, n, bs, value, colix, color, SB.newS(fData)); vs.addLast(v); } int n = vs.size(); if (n > 0) { jvxlData.vContours = AU.createArrayOfArrayList(n); // 3D contour values and colors jvxlData.contourColixes = params.contourColixes = new short[n]; jvxlData.contourValues = params.contoursDiscrete = new float[n]; for (int i = 0; i < n; i++) { jvxlData.vContours[i] = vs.get(i); jvxlData.contourValues[i] = ((Float) jvxlData.vContours[i].get(2)).floatValue(); jvxlData.contourColixes[i] = ((short[]) jvxlData.vContours[i].get(3))[0]; } jvxlData.contourColors = C.getHexCodes(jvxlData.contourColixes); Logger.info("JVXL read: " + n + " discrete contours"); Logger.info("JVXL read: contour values: " + values); Logger.info("JVXL read: contour colors: " + colors); } }