[Smtk-developers] nlohmann_json and SMTK

David Thompson david.thompson at kitware.com
Mon Sep 18 09:38:20 EDT 2017


Hi all,

I've pushed a branch here:

    https://gitlab.kitware.com/dcthomp/smtk/tree/nlohmann-json

that adds some nlohmann_json converters along the lines we discussed. It gets a surprising amount done with very little code and could be much smaller if we were willing to change the JSON file format.

See

smtk/io/jsonUUID.h
smtk/io/jsonTessellation.h
smtk/io/jsonEntity.h
smtk/io/jsonModelCollection.h

for what happens when this line (njson jmmgr = sm):

https://gitlab.kitware.com/dcthomp/smtk/blob/nlohmann-json/smtk/io/testing/cxx/exploreNLohmannJSON.cxx#L107

is evaluated. A sample of some of the output (running the exploreNLohmannJSON test on a polygon model) is below. Note that it is not precisely like existing JSON in that

1. arrangement information is not included (just not implemented yet) and
2. the entity type bit data (the "e" key) is presented as a string, not an integer; this would be easy to change but does improve legibility.

	David

{
  "models": {
    "ad1e2e89-ba18-4b2f-9570-eedc24f758ac": {
      "00377c6b-0956-4975-baf4-56c1c892219a": {
        "d": 1,
        "e": "vertex",
        "f": {
          "_boundingBox": [ 254.499935, 254.499935, 82.999971, 82.999971, 0.0, 0.0 ]
        },
        "i": {
          "_tessgen": [ 3 ],
          "block_index": [ 62 ],
          "pedigree id": [ 32 ],
          "visible": [ 0 ]
        },
        "r": [
          null,
          null,
          "6de5744d-525f-4b26-87ac-c99573813fa2",
          null,
          null,
          null,
          "d876e692-f7f6-4723-988a-1a4f428ed6f9",
          null,
          "af19eb3d-9bd5-43d4-832e-a5d0cbf5753b"
        ],
        "s": {
          "name": [
            "vertex 32"
          ]
        },
        "t": {
          "faces": [
            512,
            0
          ],
          "metadata": [
            "formatVersion",
            "3"
          ],
          "vertices": [
            254.499935,
            82.999971,
            0.0
          ]
        }
      },
      "015fb605-9bba-4eb6-9229-63011491d4c8": {
        "d": 2,
        "e": "edge_use",
        "i": {
          "pedigree id": [
            30
          ]
        },
        "r": [
          "af19eb3d-9bd5-43d4-832e-a5d0cbf5753b",
          "2a8c6e26-01ed-4823-ad2d-9bf1efaaaca4"
        ],
        "s": {
          "name": [
            "edge use 30"
          ]
        }
      },
      "020e48a9-bb4c-46e2-b7c5-510a4dc12247": {
        "d": 0,
        "e": "group|nodim",
        "i": {
          "membership mask": [
            271
          ],
          "visible": [
            1
          ]
        },
        "r": [
          "36ccbcf5-240a-4f99-88ba-c5418fcfef10",
          "ad1e2e89-ba18-4b2f-9570-eedc24f758ac",
          "3885d08e-c9bb-4d29-aa80-0143e50bea81"
        ],
        "s": {
          "name": [
            "drum"
          ]
        }
      },
      "04fa7479-5d03-4b7c-8fbd-1a3e2341baf6": {
        "d": 4,
        "e": "face",
        "f": {
          "_boundingBox": [ 299.499977, 347.499973, 107.499992, 175.499987, 0.0, 0.0 ],
          "color": [ 0.529412, 0.784314, 0.509804, 1.0 ]
        },
        "i": {
          "_tessgen": [ 0 ],
          "block_index": [ 9 ],
          "pedigree id": [ 20 ],
          "visible": [ 1 ]
        },
        "r": [
          "32391f3a-b8f8-46b6-af94-a6e84163de5c",
          "ad1e2e89-ba18-4b2f-9570-eedc24f758ac",
          "54350ca2-4701-4a87-91f6-452c265c2a28"
        ],
        "s": {
          "name": [ "face 20" ]
        },
        "t": {
          "faces": [ 0, 0, 1, 2, 0, 0, 2, 3, 0, 0, 3, 4, 0, 5, 6, 7, 0, 5, 7, 8, 0, 5, 8,
            9, 0, 10, 11, 12, 0, 10, 12, 13, 0, 10, 13, 14, 0, 15, 16, 17, 0, 15, 17, 18,
            ...  0, 543, 547, 548
          ],
          "metadata": [
            "formatVersion",
            "3"
          ],
          "vertices": [ 299.999977, 120.499991, 0.0, 299.499977, 119.999991, 0.0, 299.499977,
            118.999991, 0.0, 299.999977, 118.499991, 0.0, 299.999977, 120.499991, 0.0, 300.499977,
            120.999991, 0.0, 299.999977, 120.499991, 0.0, 299.999977, 118.499991, 0.0, 300.499977,
            ...  0.0, 347.499973, 169.999987, 0.0, 347.499973, 170.999987, 0.0
          ]
        },
        ...
      }
    }
  }
}



More information about the Smtk-developers mailing list