JvxlCoder
Date: 2019-10-22

org.jmol.jvxl.data

## Class JvxlCoder

- java.lang.Object
- - org.jmol.jvxl.data.JvxlCoder

-     public class JvxlCoder
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `CONTOUR_BITSET`
    `static int` | `CONTOUR_COLIX`
    `static int` | `CONTOUR_COLOR`
    `static int` | `CONTOUR_FDATA`
    `static int` | `CONTOUR_NPOLYGONS`
    `static int` | `CONTOUR_POINTS`
    `static int` | `CONTOUR_VALUE`
    `static int` | `defaultColorFractionBase`
    `static int` | `defaultColorFractionRange`
    `static int` | `defaultEdgeFractionBase`
    `static int` | `defaultEdgeFractionRange`
    `private static boolean` | `haveXMLUtil`
    `static java.lang.String` | `JVXL_VERSION_XML`
    `static java.lang.String` | `JVXL_VERSION1`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JvxlCoder()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private static void` | `addAttrib(javajs.util.Lst<java.lang.String[]> attribs, java.lang.String name, java.lang.String value)`
    `static void` | `appendContourTriangleIntersection(int type, float f1, float f2, javajs.util.SB fData)` appends an integer (3, 5, or 6) representing two sides of a triangle ABC -- AB/BC(3), AB/CA(5), or BC/CA(6) -- along with two fractions along the edges for the intersection point base-90-encoded.
    `private static void` | `appendEncodedBitSetTag(javajs.util.SB sb, java.lang.String name, javajs.util.BS bs, int count, java.lang.Object[] attribs)`
    `private static void` | `appendXmlColorData(javajs.util.SB sb, java.lang.String data, boolean isEncoded, boolean isPrecisionColor, float value1, float value2)`
    `private static void` | `appendXmlEdgeData(javajs.util.SB sb, JvxlData jvxlData)`
    `private static boolean` | `appendXmlTriangleData(javajs.util.SB sb, int[][] triangles, int nData, javajs.util.BS bsSlabDisplay, int[] vertexIdNew, boolean escapeXml)` encode triangle data -- [ia ib ic] [ia ib ic] [ia ib ic] ...
    `private static void` | `appendXmlVertexData(javajs.util.SB sb, JvxlData jvxlData, int[] vertexIdNew, javajs.util.T3[] vertices, float[] vertexValues, int vertexCount, java.lang.String polygonColorData, int polygonCount, javajs.util.BS bsSlabDisplay, int[] vertexColors, boolean addColorData, boolean escapeXml)` encode the vertex data.
    `private static void` | `appendXmlVertexOnlyData(javajs.util.SB sb, JvxlData jvxlData, MeshData meshData, boolean escapeXml)`
    `private static void` | `checkHaveXMLUtil()`
    `private static javajs.util.T3` | `getContourPoint(javajs.util.T3[] vertices, int i, int j, float f)`
    `private static void` | `jvxlAppendCharacter2(float value, float min, float max, int base, int range, javajs.util.SB list1, javajs.util.SB list2)`
    `private static void` | `jvxlAppendCommandState(javajs.util.SB data, java.lang.String cmd, java.lang.String state)`
    `static void` | `jvxlAppendEncodedNumber(javajs.util.SB sb, int n, int base, int range)`
    `static java.lang.String` | `jvxlCompressString(java.lang.String data, boolean escapeXml)`
    `static void` | `jvxlCreateColorData(JvxlData jvxlData, float[] vertexValues)`
    `static void` | `jvxlCreateHeader(VolumeData v, javajs.util.SB sb)` Creates a two-line header for the XJVXL file.
    `static void` | `jvxlCreateHeaderWithoutTitleOrAtoms(VolumeData v, javajs.util.SB bs)`
    `static javajs.util.BS` | `jvxlDecodeBitSet(java.lang.String data)`
    `static javajs.util.BS` | `jvxlDecodeBitSetRange(java.lang.String data, int base, int range)`
    `static java.lang.String` | `jvxlDecompressString(java.lang.String data)`
    `static java.lang.String` | `jvxlEncodeBitSet(javajs.util.BS bs)`
    `static int` | `jvxlEncodeBitSet0(javajs.util.BS bs, int nPoints, javajs.util.SB sb)`
    `static int` | `jvxlEncodeBitSetBuffer(javajs.util.BS bs, int nPoints, javajs.util.SB sb)`
    `private static void` | `jvxlEncodeContourData(javajs.util.Lst<java.lang.Object>[] contours, javajs.util.SB sb)` contour data are appended to a string buffer in the form of a triangle bitset data triangle bitset data triangle bitset data ...
    `static char` | `jvxlFractionAsCharacter(float fraction)`
    `static char` | `jvxlFractionAsCharacterRange(float fraction, int base, int range)`
    `static float` | `jvxlFractionFromCharacter(int ich, int base, int range, float fracOffset)`
    `static float` | `jvxlFractionFromCharacter2(int ich1, int ich2, int base, int range)`
    `static java.lang.String` | `jvxlGetFile(JvxlData jvxlData, MeshData meshData, java.lang.String[] title, java.lang.String msg, boolean includeHeader, int nSurfaces, java.lang.String state, java.lang.String comment)`
    `static java.lang.String` | `jvxlGetFile(VolumeData volumeData, JvxlData jvxlData, java.lang.String[] title)`
    `static java.lang.String` | `jvxlGetInfo(JvxlData jvxlData)`
    `static java.lang.String` | `jvxlGetInfoData(JvxlData jvxlData, boolean vertexDataOnly)`
    `static int` | `jvxlParseEncodedInt(java.lang.String str, int offset, int base, int[] next)`
    `private static java.lang.String` | `jvxlSetCompressionRatio(javajs.util.SB data, JvxlData jvxlData, int len)`
    `static char` | `jvxlValueAsCharacter(float value, float min, float max, int base, int range)`
    `protected static float` | `jvxlValueFromCharacter2(int ich, int ich2, float min, float max, int base, int range)`
    `static void` | `set3dContourVector(javajs.util.Lst<java.lang.Object> v, int[][] polygonIndexes, javajs.util.T3[] vertices)` Interpret fractional data in terms of actual vertex positions and create the elements of a Vector in Vector[] vContours starting at the CONTOUR_POINTS position.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### JVXL_VERSION1

          public static final java.lang.String JVXL_VERSION1

      See Also:
        Constant Field Values

    - #### JVXL_VERSION_XML

          public static final java.lang.String JVXL_VERSION_XML

      See Also:
        Constant Field Values

    - #### haveXMLUtil

          private static boolean haveXMLUtil

    - #### CONTOUR_NPOLYGONS

          public static final int CONTOUR_NPOLYGONS

      See Also:
        Constant Field Values

    - #### CONTOUR_BITSET

          public static final int CONTOUR_BITSET

      See Also:
        Constant Field Values

    - #### CONTOUR_VALUE

          public static final int CONTOUR_VALUE

      See Also:
        Constant Field Values

    - #### CONTOUR_COLIX

          public static final int CONTOUR_COLIX

      See Also:
        Constant Field Values

    - #### CONTOUR_COLOR

          public static final int CONTOUR_COLOR

      See Also:
        Constant Field Values

    - #### CONTOUR_FDATA

          public static final int CONTOUR_FDATA

      See Also:
        Constant Field Values

    - #### CONTOUR_POINTS

          public static final int CONTOUR_POINTS

      See Also:
        Constant Field Values

    - #### defaultEdgeFractionBase

          public static final int defaultEdgeFractionBase

      See Also:
        Constant Field Values

    - #### defaultEdgeFractionRange

          public static final int defaultEdgeFractionRange

      See Also:
        Constant Field Values

    - #### defaultColorFractionBase

          public static final int defaultColorFractionBase

      See Also:
        Constant Field Values

    - #### defaultColorFractionRange

          public static final int defaultColorFractionRange

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### JvxlCoder

          public JvxlCoder()

  - ### Method Detail

    - #### jvxlGetFile

          public static java.lang.String jvxlGetFile(VolumeData volumeData,
                                                     JvxlData jvxlData,
                                                     java.lang.String[] title)

      Parameters:
        `volumeData` -
        `jvxlData` -
        `title` -
      Returns:
        XML string

    - #### jvxlGetFile

          public static java.lang.String jvxlGetFile(JvxlData jvxlData,
                                                     MeshData meshData,
                                                     java.lang.String[] title,
                                                     java.lang.String msg,
                                                     boolean includeHeader,
                                                     int nSurfaces,
                                                     java.lang.String state,
                                                     java.lang.String comment)

      Parameters:
        `jvxlData` -
        `meshData` -
        `title` -
        `msg` -
        `includeHeader` -
        `nSurfaces` -
        `state` -
        `comment` -
      Returns:
        JVXL file XML

    - #### checkHaveXMLUtil

          private static void checkHaveXMLUtil()

    - #### appendEncodedBitSetTag

          private static void appendEncodedBitSetTag(javajs.util.SB sb,
                                                     java.lang.String name,
                                                     javajs.util.BS bs,
                                                     int count,
                                                     java.lang.Object[] attribs)

    - #### jvxlSetCompressionRatio

          private static java.lang.String jvxlSetCompressionRatio(javajs.util.SB data,
                                                                  JvxlData jvxlData,
                                                                  int len)

    - #### appendXmlEdgeData

          private static void appendXmlEdgeData(javajs.util.SB sb,
                                                JvxlData jvxlData)

    - #### jvxlAppendCommandState

          private static void jvxlAppendCommandState(javajs.util.SB data,
                                                     java.lang.String cmd,
                                                     java.lang.String state)

    - #### appendXmlColorData

          private static void appendXmlColorData(javajs.util.SB sb,
                                                 java.lang.String data,
                                                 boolean isEncoded,
                                                 boolean isPrecisionColor,
                                                 float value1,
                                                 float value2)

    - #### jvxlGetInfo

          public static java.lang.String jvxlGetInfo(JvxlData jvxlData)

    - #### jvxlGetInfoData

          public static java.lang.String jvxlGetInfoData(JvxlData jvxlData,
                                                         boolean vertexDataOnly)

    - #### addAttrib

          private static void addAttrib(javajs.util.Lst<java.lang.String[]> attribs,
                                        java.lang.String name,
                                        java.lang.String value)

    - #### jvxlEncodeContourData

          private static void jvxlEncodeContourData(javajs.util.Lst<java.lang.Object>[] contours,
                                                    javajs.util.SB sb)

      contour data are appended to a string buffer in the form of a triangle bitset data triangle bitset data triangle bitset data ... One presumes an ordered set of triangles. The contour intersects these triangles along two edges or at two vertices. (see IsosurfaceMesh for details) Each contour is a Vector containing: 0 Integer number of polygons (length of BitSet) 1 BitSet of critical triangles 2 Float value 3 int[] [colorArgb] 4 StringXBuilder containing encoded data for each segment: char type ('3', '6', '5') indicating which two edges of the triangle are connected: '3' 0x011 AB-BC '5' 0x101 AB-CA '6' 0x110 BC-CA char fraction along first edge (jvxlFractionToCharacter) char fraction along second edge (jvxlFractionToCharacter) 5- stream of pairs of points for rendering (created
      Parameters:
        `contours` -
        `sb` -

    - #### set3dContourVector

          public static void set3dContourVector(javajs.util.Lst<java.lang.Object> v,
                                                int[][] polygonIndexes,
                                                javajs.util.T3[] vertices)

      Interpret fractional data in terms of actual vertex positions and create the elements of a Vector in Vector[] vContours starting at the CONTOUR_POINTS position.
      Parameters:
        `v` -
        `polygonIndexes` -
        `vertices` -

    - #### getContourPoint

          private static javajs.util.T3 getContourPoint(javajs.util.T3[] vertices,
                                                        int i,
                                                        int j,
                                                        float f)

    - #### appendContourTriangleIntersection

          public static void appendContourTriangleIntersection(int type,
                                                               float f1,
                                                               float f2,
                                                               javajs.util.SB fData)

      appends an integer (3, 5, or 6) representing two sides of a triangle ABC -- AB/BC(3), AB/CA(5), or BC/CA(6) -- along with two fractions along the edges for the intersection point base-90-encoded. This version is single precision. type f1 f2 3 AB BC 5 AB CA 6 BC CA
      Parameters:
        `type` -
        `f1` - -- character-encoded fraction
        `f2` - -- character-encoded fraction
        `fData` -

    - #### jvxlCreateColorData

          public static void jvxlCreateColorData(JvxlData jvxlData,
                                                 float[] vertexValues)

      Parameters:
        `jvxlData` -
        `vertexValues` -

    - #### appendXmlVertexOnlyData

          private static void appendXmlVertexOnlyData(javajs.util.SB sb,
                                                      JvxlData jvxlData,
                                                      MeshData meshData,
                                                      boolean escapeXml)

    - #### appendXmlTriangleData

          private static boolean appendXmlTriangleData(javajs.util.SB sb,
                                                       int[][] triangles,
                                                       int nData,
                                                       javajs.util.BS bsSlabDisplay,
                                                       int[] vertexIdNew,
                                                       boolean escapeXml)

      encode triangle data -- [ia ib ic] [ia ib ic] [ia ib ic] ... algorithm written by Bob Hanson, 11/2008. The principle is that not all vertices may be represented -- we only need the used vertices here. Capitalizing on the fact that triangle sets tend to have common edges and similar numbers for sequential triangles. a) Renumbering vertices as they appear in the triangle set [2456 2457 2458] [2456 2459 2458] becomes [ 1 2 3] [ 1 4 3] b) This allows efficient encoding of differences, not absolute numbers. 0 1 2 -2 3 -1 c) Which can then be represented often using a single ASCII character. I chose \ to be 0, and replace that with !. ASCII: -30 -20 -10 0 +10 +20 +30 <=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{| So the above sequence would simply be: !]^Z_[ When the range falls outside of +/-32, we simply use a number. When a positive number follows another number, we add a "+" to it. !]^Z_[-33+250]230-210]] Preliminary trials indicated that on average a triangle can be encoded in about 7 bytes, or roughly half the 12 bytes necessary for standard binary encoding of integers. The advantage here is that we have an ASCII-readable file and no little-/big-endian issue.
      Parameters:
        `sb` -
        `triangles` -
        `nData` -
        `bsSlabDisplay` -
        `vertexIdNew` -
        `escapeXml` -
      Returns:
        (triangles are present)

    - #### appendXmlVertexData

          private static void appendXmlVertexData(javajs.util.SB sb,
                                                  JvxlData jvxlData,
                                                  int[] vertexIdNew,
                                                  javajs.util.T3[] vertices,
                                                  float[] vertexValues,
                                                  int vertexCount,
                                                  java.lang.String polygonColorData,
                                                  int polygonCount,
                                                  javajs.util.BS bsSlabDisplay,
                                                  int[] vertexColors,
                                                  boolean addColorData,
                                                  boolean escapeXml)

      encode the vertex data. This must be done AFTER encoding the triangles, because the triangles redefine the order of vertices. Bob Hanson 11/2008 If another program has created the triangles, we probably do not know the grid that was used for Marching Cubes, or quite possibly no grid was used. In that case, we just save the vertex/triangle/value data in a compact form. For the we use an extension of the way edge points are encoded. We simply identify the minimum and maximum x, y, and z coordinates and then express the point as a fraction along each of those directions. Thus, the x, y, and z coordinate are within the interval [0,1]. We opt for the two-byte double-precision JVXL character compression. This allows a 1 part in 8100 resolution, which is plenty for these purposes. The tag will indicate the minimum and maximum values: The resultant string is really two strings of length nData where the first string lists the "high" part of the positions, and the second string lists the "low" part of the positions.
      Parameters:
        `sb` -
        `jvxlData` -
        `vertexIdNew` -
        `vertices` -
        `vertexValues` -
        `vertexCount` -
        `polygonColorData` -
        `polygonCount` -
        `bsSlabDisplay` -
        `vertexColors` -
        `addColorData` -
        `escapeXml` -

    - #### jvxlFractionAsCharacter

          public static char jvxlFractionAsCharacter(float fraction)

    - #### jvxlFractionAsCharacterRange

          public static char jvxlFractionAsCharacterRange(float fraction,
                                                          int base,
                                                          int range)

    - #### jvxlAppendCharacter2

          private static void jvxlAppendCharacter2(float value,
                                                   float min,
                                                   float max,
                                                   int base,
                                                   int range,
                                                   javajs.util.SB list1,
                                                   javajs.util.SB list2)

    - #### jvxlFractionFromCharacter

          public static float jvxlFractionFromCharacter(int ich,
                                                        int base,
                                                        int range,
                                                        float fracOffset)

    - #### jvxlFractionFromCharacter2

          public static float jvxlFractionFromCharacter2(int ich1,
                                                         int ich2,
                                                         int base,
                                                         int range)

    - #### jvxlValueAsCharacter

          public static char jvxlValueAsCharacter(float value,
                                                  float min,
                                                  float max,
                                                  int base,
                                                  int range)

    - #### jvxlValueFromCharacter2

          protected static float jvxlValueFromCharacter2(int ich,
                                                         int ich2,
                                                         float min,
                                                         float max,
                                                         int base,
                                                         int range)

    - #### jvxlEncodeBitSet0

          public static int jvxlEncodeBitSet0(javajs.util.BS bs,
                                              int nPoints,
                                              javajs.util.SB sb)

    - #### jvxlEncodeBitSet

          public static java.lang.String jvxlEncodeBitSet(javajs.util.BS bs)

    - #### jvxlEncodeBitSetBuffer

          public static int jvxlEncodeBitSetBuffer(javajs.util.BS bs,
                                                   int nPoints,
                                                   javajs.util.SB sb)

    - #### jvxlAppendEncodedNumber

          public static void jvxlAppendEncodedNumber(javajs.util.SB sb,
                                                     int n,
                                                     int base,
                                                     int range)

    - #### jvxlDecodeBitSetRange

          public static javajs.util.BS jvxlDecodeBitSetRange(java.lang.String data,
                                                             int base,
                                                             int range)

    - #### jvxlParseEncodedInt

          public static int jvxlParseEncodedInt(java.lang.String str,
                                                int offset,
                                                int base,
                                                int[] next)

    - #### jvxlDecodeBitSet

          public static javajs.util.BS jvxlDecodeBitSet(java.lang.String data)

    - #### jvxlCompressString

          public static java.lang.String jvxlCompressString(java.lang.String data,
                                                            boolean escapeXml)

    - #### jvxlDecompressString

          public static java.lang.String jvxlDecompressString(java.lang.String data)

    - #### jvxlCreateHeaderWithoutTitleOrAtoms

          public static void jvxlCreateHeaderWithoutTitleOrAtoms(VolumeData v,
                                                                 javajs.util.SB bs)

    - #### jvxlCreateHeader

          public static void jvxlCreateHeader(VolumeData v,
                                              javajs.util.SB sb)

      Creates a two-line header for the XJVXL file. It is no longer necessary to create the atom set or generate the vectors here. Please leave the commented code for posterity.
      Parameters:
        `v` -
        `sb` -