Skip to content

Mesh page

There are multiple conditional sections based on options.

  • byte CoordinatePrecision : number of decimal places in node coordinates, allowed null
  • bool EncodeCoordinates : true if CoordinatePrecision is defined, false indicates full precision of coordinates
  • bool IncludeMeshElementId : true if result includes mesh element ids, otherwise false

The pseudo code in this page demonstrates the read logic.

Read single mesh page

fixedNodesInElement = read byte  // valid values are 3,4 
//if value is 0 there is variable node count per element

if  options.EncodeCoordinates
    Read MeshNodesEncoded
else 
    Read MeshFullNodes

Read Elements (fixedNodesInElement)

Read Elements (byte fixedNodesInElement)

elementCount = read VarUInt32
id = 0;
for i = 0 to count-1
    if options.IncludeId
        delta = read VarSInt32;
        if i = 0 
            id = delta 
        else
            id = id + delta;

    if fixedNodesInElement = 0
        nodeCount = read byte
    else    
        nodeCount = fixedNodesInElement

    for j = 0 to nodeCount -1 
        nodeIndices[j] = read byte;

    elements[i] = new MeshElement(id, nodeIndices);

Read SingleFullNode

x=read double 
y=read double
return Node(x,y)

Read MeshFullNodes

nodeCount = read VarUInt32
for  i = 0 to nodeCount -1
    nodes[i] = Read SingleFullNode

Read MeshNodesEncoded

nodeCount = read VarUInt32
nodes[0] = Read SingleFullNode

xDelta = new DoubleDecoderWithPrecision(nodes[0].x)
yDelta = new DoubleDecoderWithPrecision(nodes[0].y)

for ( i = 1 to nodeCount-1)
    var x = xDelta.GetNextValue
    var y = yDelta.GetNextValue
    nodes[i] = new Node(x, y)

DoubleDecoderWithPrecision

Helper class used in MeshNodesEncoded part. Decodes double values with specified precision. In the response, double values are encoded as integer and delta from previous value.

Pseudo code for decoding:

class DoubleDecoderWithPrecision
    Int32 _lastValue
    double _prec

    constructor(double startValue)
        _prec = 10 power options.CoordinatePrecision
        _lastValue = (Int32) (startValue * _prec)

    double NextValue
        delta = read VarSInt32 // read from input stream 
        current = _lastValue + delta
        _lastValue = current
        return ((double)current) / _prec