WKB

Ganos表面模型支持以二进制的方式进行表达,保留数据精度且方便传输,称为Well-Known Binary(简称 WKB)。

概述

表面模型是通过将SFMesh对象序列化为数值序列来获得从集合中提取的数字类型,然后将每个数字类型序列化为使用字节序。

表面模型通过将SFMesh对象序列化为二进制的方式进行表达。WKB支持两种二进制编码顺序(NDR或XDR),XDR编码为Big Endian,NDR编码为Little Endian。

几何结构

Ganos表面模型中除了支持OGC Simple Feature模型外,还支持以下几何结构:

  • INDEXSURFACE

  • TRIANGLESTRIP

  • TRIANGLEFAN

具体请参见表面网格模型数据类型

数值定义

  • Uint1:8-bit (1byte)无符号整数。

  • Byte:8-bit (1 Byte) 有符号整数。

  • Uint16:16-bit (2 Byte) 无符号整数。

  • Uint32:32-bit (4 Byte) 无符号整数。

  • Float:32-bit (4 Byte) 浮点数,使用IEEE 754表示方法。

  • Double:64-bit (8 Byte) 浮点数,使用IEEE 754表示方法。

说明

以上数值定义均适用于XDR和NDR。

规范

3D Mesh扩展了EWKB格式规范,增加了一些标志位定义。部分成员变量仅在设置了标志位的情况下具备。

定义

通用定义

// Basic Type definitions
// byte : 1 byte
// uint8: 1 byte
// uint16: 2 byte
// uint32 : 32 bit unsigned integer (4 bytes)
// float: single precison number (4 bytes)
// double : double precision number (8 bytes)
enum WKBByteOrder {
    wkbXDR = 0, // Big Endian
    wkbNDR = 1 // Little Endian
}

// point type
Point2D {
    double x;
    double y
}

Point3D {
    double x;
    double y,
    double z
}

Point4D {
    double x;
    double y,
    double z,
    double m
}

Point {
    union
    {
        Point2D point2d;
        Point3D point3d;
        Point4D point4d;
    }
}

// LinearRing
LinearRing {
    uint32 numPoints;
    Point points[numPoints];
}

// Normal Point
NormalPoint {
    float x;
    float y;
    float z;
}

NormalPointArray {
    uint32 numPoints;
    NormalPoint points[numPoints];
}

// Texcoord Point
TexcoordPoint {
    float x;
    float y;
}

TexcoordPointArray {
    uint32 numPoints;
    TexcoordPoint points[numPoints];
}

// String
String
{
    uint32 stringLength;
    byte string[stringLength];
}

// Var int
enum IntType {
    Int8 =1;
    Int16 =2;
    Int32 = 4;
}

varint {
    union {
        uint8   uint8;
        uint16  uint16;
        uint32  uint32;
    }
}

varintArray {
    uint32  numInt;
    byte        intType; // WKBIntType
    varint  values[numInt];
}

几何类型扩展

TriangleStrip

WKBTriangleStrip {
    byte byteOrder;
    static uint32 wkbType = 20;
    /*
    #define WKBZOFFSET  0x80000000
    #define WKBMOFFSET  0x40000000
    #define WKBSRIDFLAG 0x20000000
    */
    uint32 srid; /* if WKBSRIDFLAG */
    uint32 numRings = 1;
    LinearRing ring;
}

TriangleFan

WKBTriangleFan {
    byte byteOrder;
    static uint32 wkbType = 21;
    /*
    #define WKBZOFFSET  0x80000000
    #define WKBMOFFSET  0x40000000
    #define WKBSRIDFLAG 0x20000000
    */
    uint32 srid; /* if WKBSRIDFLAG */
    uint32 numRings = 1;
    LinearRing rings
}

Indexsurface

WKBIndexsurface {
  byte byteOrder;
  static uint32 wkbType = 22;
  /*
#define WKBZOFFSET  0x80000000
#define WKBMOFFSET  0x40000000
#define WKBSRIDFLAG 0x20000000
*/
  uint32 srid; /* if WKBSRIDFLAG */
  LinearRing ring;
  varintArray   VertexIndex;
  varintArray VertexNum;
}

GeometryCollection

WKBGeometry {
    Union {
        WKBPoint point;
        WKBLineString linestring;
        WKBPolygon polygon;
        WKBMultiPoint mpoint;
        WKBMultiLineString mlinestring;
        WKBMultiPolygon mpolygon;
        WKBTriangleStrip strip;
        WKBTriangleFan fan;
        WKBIndexsurface indexsurface;
    }
};


WKBGeometryCollection {
    byte byte_order;
    static uint32 wkbType = 7;
    uint32 numGeometries;
    WKBGeometry geometries[numGeometries];
}

Texture

enum wkbTFormat
{
    wkbTFRaw = 0;
    wkbTFJPG = 1;
    wkbTFPNG = 2;
}

enum wkbTType
{
    wkbTTFile = 1;
    wkbTTDB =2;
    wkbTTBytes = 3;
    wkbTTWeb = 4;
}

WKBTexture {
    byte byteOrder;
    static byte version = 1;
    byte compress = 0;
    byte format; /* wkbTFormat */
    static byte wrap = 0;
    byte type; /* wkbTType */
    byte depth; /* 1, 2, or 4 */
    uint32 width;
    uint32 height;
    uint32 dataLength;
    byte   data[dataLength];
    String name;
}

Material

WKBMaterial {
    byte byteOrder;
    static byte version = 1;
    uint1 type;

    uint4 numTextures;
    WKBTexture textures[numTextures];

    WKBString name;

    WKBString data;
}

Meshgeom

WKBMeshGeom
{
    byte byteOrder;
    uint32 wkbType;

    /*
    #define WKBZOFFSET  0x80000000
    #define WKBMOFFSET  0x40000000
    #define WKBSRIDFLAG 0x20000000
    #define  WKBGEOMFLAG0x04000000
    #define  WKBNORMALFLAG  0x02000000
    #define  WKBTEXCOORDFLAG0x01000000
    #define  WKBREFFLAG 0x00400000
    #define  WKBSOLIDFLAG   0x00200000
    */
    uint32  srid; /* if WKBSRIDFLAG */
    WKBGeometryCollection patches;  /* If WKBGEOMFLAG */

    uint32  numNormalPointArray; /* If WKBNORMALFLAG */
    NormalPointArray normalPoints[numNormalPointArray]; /* If WKBNORMALFLAG */

    uint32  numTexcoordPointArray;  /* If WKBTEXCOORDFLAG */
    TexcoordPointArray texcoordPoints[numTexcoordPointArray]; /* If WKBTEXCOORDFLAG */

    String  path; /* If WKBREFFLAG */    byte byteOrder;
    uint32 wkbType;

    /*
    #define WKBZOFFSET  0x80000000
    #define WKBMOFFSET  0x40000000
    #define WKBSRIDFLAG 0x20000000
    #define  WKBGEOMFLAG0x04000000
    #define  WKBNORMALFLAG  0x02000000
    #define  WKBTEXCOORDFLAG0x01000000
    #define  WKBREFFLAG 0x00400000
    #define  WKBSOLIDFLAG   0x00200000
    */
    uint32  srid; /* if WKBSRIDFLAG */
    WKBGeometryCollection patches;  /* If WKBGEOMFLAG */

    uint32  numNormalPointArray; /* If WKBNORMALFLAG */
    NormalPointArray normalPoints[numNormalPointArray]; /* If WKBNORMALFLAG */

    uint32  numTexcoordPointArray;  /* If WKBTEXCOORDFLAG */
    TexcoordPointArray texcoordPoints[numTexcoordPointArray]; /* If WKBTEXCOORDFLAG */

    String  path; /* If WKBREFFLAG */
}

SFMesh

WKBMatrix {
    double matrix[12];
}

WKBNode
{
    uint8   flags;
    /*
    #define   WKBPRIMITIVEFLAG 0x01u<<0
    #define   WKBMATRIXFLAG 0x01u<<2
    #define   WKBIDFLAG 0x01u<<3
    */
    uint32  primitive; /* if WKBPRIMITIVEFLAG */
    varintArray children; /* if not WKBPRIMITIVEFLAG */
    WKBMatrix   matrix; /* if WKBMATRIXFLAG */
    uint32      id; /* if WKBIDFLAG */
}

WKBPrimitive {
    uint8  flags;
    uint8  reserved;
    uint16 materialId;
    uint32 index;
}


SFMesh
{
    byte   byteOrder;
    static byte magic = 'M'
    static byte version = 1;
    uint16 flags;

    /*
#define WKBMESHZFLAG   0x0001u      /* have z */
#define WKBMESHMFLAG   0x0001u<<1   /* have M */

#define WKBMESHREFFLAG 0x0001u<<4   /* is ref */
#define WKBMESHGEOMFLAG 0x0001u<<5   /* have meshgeom */
#define WKBMESHMESHFLAG 0x0001u<<6   /* have mesh */
#define WKBMESHTEXTUREFLAG 0x0001u<<7   /* have texture */
#define WKBMESHMATERIALFLAG 0x0001u<<8   /* have material */
#define WKBMESHLODFLAG 0x0001u<<9   /* have lod */
#define WKBMESHSRIDFLAG 0x0001u<<11   /* have srid */
#define WKBMESHUSERFLAG 0x0001u<<12   /* have user data */
#define WKBMESHBINFLAG 0x0001u<<13   /* have bin data */
#define WKBMESHEXFLAG 0x0001u<<14    /* have exflags */
#define WKBMESHSYSFLAG 0x0001u<<15   /* have system data */
   */

    uint32 exflags;     /* if WKBMESHEXFLAG */

    uint32 srid;        /* if WKBMESHSRIDFLAG */
    uint16 lod;         /* if WKBMESHLODFLAG */

    uint32 root;        /* If not WKBMESHREFFLAG */

    uint32 numMeshgeom; /* If WKBMESHGEOMFLAG */
    WKBMeshgeom meshgeoms[numMeshgeom];/* If  WKBMESHGEOMFLAG */

    uint32 numSFMesh;   /* if WKBMESHMESHFLAG */
    WKBSFMesh sfmesh[numSFMesh];    /* if WKBMESHMESHFLAG */

    uint32 numTexture;      /* If WKBMESHTEXTUREFLAG */
    WKBTexture textures[numTexture]; /* WKBMESHTEXTUREFLAG */

    uint32 numNode;         /* If not WKBMESHREFFLAG */
    WKBNode nodes[numNode];/* If not WKBMESHREFFLAG */

    uint32 numPrimitives;/* If not WKBMESHREFFLAG */
    WKBPrimitive primitives[numPrimitives];/* If not WKBMESHREFFLAG */

   String path; /* if WKBMESHREFFLAG */
   String userdata; /* if WKBMESHUSERFLAG */
   String bindata;  /* if WKBMESHBINFLAG */
   String sysdata;  /* if WKBMESHSYSFLAG */
}