Skip to content

Instantly share code, notes, and snippets.

@xavArtley
Last active November 24, 2019 12:17
Show Gist options
  • Save xavArtley/6165a6ab1f0f73b1e0fa4542fb479072 to your computer and use it in GitHub Desktop.
Save xavArtley/6165a6ab1f0f73b1e0fa4542fb479072 to your computer and use it in GitHub Desktop.
Vtk serilization change lookuptable
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<script src='https://unpkg.com/vtk.js'></script>
</head>
<body>
<script>
vtkFullScreenRenderWindow = vtk.Rendering.Misc.vtkFullScreenRenderWindow
const actorJSON = JSON.parse(`
{
"allocatedRenderTime": 10,
"bounds": [-0.5, 0.5, -0.5, 0.5, -0.5, 0.5],
"boundsMTime": {
"classHierarchy": ["vtkObject"],
"mtime": 561,
"vtkClass": "vtkObject"
},
"classHierarchy": ["vtkObject", "vtkProp", "vtkProp3D", "vtkActor"],
"dragable": true,
"estimatedRenderTime": 0,
"forceOpaque": false,
"forceTranslucent": false,
"isIdentity": true,
"mapper": {
"bounds": [-0.5, 0.5, -0.5, 0.5, -0.5, 0.5],
"center": [0, 0],
"classHierarchy": ["vtkObject", "vtkMapper"],
"colorMode": 1,
"fieldDataTupleId": -1,
"forceCompileOnly": 0,
"inputArrayToProcess": [],
"inputConnection": [null],
"inputData": [{
"cellData": {
"activeGlobalIds": -1,
"activeNormals": -1,
"activePedigreeIds": -1,
"activeScalars": 0,
"activeTCoords": -1,
"activeTensors": -1,
"activeVectors": -1,
"arrays": [{
"data": {
"classHierarchy": ["vtkObject", "vtkDataArray"],
"dataType": "Float32Array",
"mtime": 553,
"name": "temp",
"numberOfComponents": 1,
"size": 25,
"values": [0.4945269525051117, 0.9051258563995361, 0.20178239047527313, 0.25008419156074524, 0.6825500726699829, 0.6665751934051514, 0.6896824240684509, 0.3268996775150299, 0.88401859998703, 0.9641408920288086, 0.2844676077365875, 0.5107138752937317, 0.06342488527297974, 0.3234332501888275, 0.711337685585022, 0.2414875477552414, 0.7309854030609131, 0.8149802088737488, 0.5051003694534302, 0.3436082899570465, 0.9637079834938049, 0.27523142099380493, 0.8384449481964111, 0.10200495272874832, 0.30800673365592957],
"vtkClass": "vtkDataArray"
}
}],
"classHierarchy": ["vtkObject", "vtkFieldData", "vtkDataSetAttributes"],
"copyFieldFlags": [],
"doCopyAllOff": false,
"doCopyAllOn": true,
"mtime": 556,
"vtkClass": "vtkDataSetAttributes"
},
"classHierarchy": ["vtkObject", "vtkDataSet", "vtkPointSet", "vtkPolyData"],
"fieldData": {
"activeGlobalIds": -1,
"activeNormals": -1,
"activePedigreeIds": -1,
"activeScalars": -1,
"activeTCoords": -1,
"activeTensors": -1,
"activeVectors": -1,
"arrays": [],
"classHierarchy": ["vtkObject", "vtkFieldData", "vtkDataSetAttributes"],
"copyFieldFlags": [],
"doCopyAllOff": false,
"doCopyAllOn": true,
"mtime": 553,
"vtkClass": "vtkDataSetAttributes"
},
"lines": {
"classHierarchy": ["vtkObject", "vtkDataArray"],
"dataType": "Float32Array",
"empty": true,
"mtime": 553,
"numberOfComponents": 1,
"values": [],
"vtkClass": "vtkCellArray"
},
"mtime": 555,
"pointData": {
"activeGlobalIds": -1,
"activeNormals": -1,
"activePedigreeIds": -1,
"activeScalars": -1,
"activeTCoords": -1,
"activeTensors": -1,
"activeVectors": -1,
"arrays": [],
"classHierarchy": ["vtkObject", "vtkFieldData", "vtkDataSetAttributes"],
"copyFieldFlags": [],
"doCopyAllOff": false,
"doCopyAllOn": true,
"mtime": 553,
"vtkClass": "vtkDataSetAttributes"
},
"points": {
"dataType": "Float32Array",
"numberOfComponents": 3,
"size": 75,
"values": [0.5, 0, 0, -0.5, 0.5, 0, -0.5, 0.4829629063606262, 0.129409521818161, -0.5, 0.4330126941204071, 0.25, -0.5, 0.3535533845424652, 0.3535533845424652, -0.5, 0.25, 0.4330126941204071, -0.5, 0.129409521818161, 0.4829629063606262, -0.5, 3.0616171314629196e-17, 0.5, -0.5, -0.129409521818161, 0.4829629063606262, -0.5, -0.25, 0.4330126941204071, -0.5, -0.3535533845424652, 0.3535533845424652, -0.5, -0.4330126941204071, 0.25, -0.5, -0.4829629063606262, 0.129409521818161, -0.5, -0.5, 6.123234262925839e-17, -0.5, -0.4829629063606262, -0.129409521818161, -0.5, -0.4330126941204071, -0.25, -0.5, -0.3535533845424652, -0.3535533845424652, -0.5, -0.25, -0.4330126941204071, -0.5, -0.129409521818161, -0.4829629063606262, -0.5, -9.184850732644269e-17, -0.5, -0.5, 0.129409521818161, -0.4829629063606262, -0.5, 0.25, -0.4330126941204071, -0.5, 0.3535533845424652, -0.3535533845424652, -0.5, 0.4330126941204071, -0.25, -0.5, 0.4829629063606262, -0.129409521818161],
"vtkClass": "vtkPoints"
},
"polys": {
"classHierarchy": ["vtkObject", "vtkDataArray"],
"dataType": "Uint32Array",
"empty": true,
"mtime": 552,
"numberOfComponents": 1,
"size": 121,
"values": [24, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 3, 0, 1, 2, 3, 0, 2, 3, 3, 0, 3, 4, 3, 0, 4, 5, 3, 0, 5, 6, 3, 0, 6, 7, 3, 0, 7, 8, 3, 0, 8, 9, 3, 0, 9, 10, 3, 0, 10, 11, 3, 0, 11, 12, 3, 0, 12, 13, 3, 0, 13, 14, 3, 0, 14, 15, 3, 0, 15, 16, 3, 0, 16, 17, 3, 0, 17, 18, 3, 0, 18, 19, 3, 0, 19, 20, 3, 0, 20, 21, 3, 0, 21, 22, 3, 0, 22, 23, 3, 0, 23, 24, 3, 0, 24, 1],
"vtkClass": "vtkCellArray"
},
"strips": {
"classHierarchy": ["vtkObject", "vtkDataArray"],
"dataType": "Float32Array",
"empty": true,
"mtime": 553,
"numberOfComponents": 1,
"values": [],
"vtkClass": "vtkCellArray"
},
"verts": {
"classHierarchy": ["vtkObject", "vtkDataArray"],
"dataType": "Float32Array",
"empty": true,
"mtime": 553,
"numberOfComponents": 1,
"values": [],
"vtkClass": "vtkCellArray"
},
"vtkClass": "vtkPolyData"
}],
"interpolateScalarsBeforeMapping": false,
"lookupTable": {
"aboveRangeColor": [1, 1, 1, 1],
"alpha": 1,
"alphaRange": [1, 1],
"belowRangeColor": [0, 0, 0, 1],
"buildTime": {
"classHierarchy": ["vtkObject"],
"mtime": 61,
"vtkClass": "vtkObject"
},
"classHierarchy": ["vtkObject", "vtkLookupTable"],
"hueRange": [0, 0.66667],
"mappingRange": [0, 1],
"mtime": 60,
"nanColor": [0.5, 0, 0, 1],
"numberOfColors": 256,
"opaqueFlagBuildTime": {
"classHierarchy": ["vtkObject"],
"mtime": 60,
"vtkClass": "vtkObject"
},
"saturationRange": [1, 1],
"table": [68.5, 1.5, 84.5, 255.5, 68.5, 2.5, 85.5, 255.5, 68.5, 3.5, 87.5, 255.5, 69.5, 5.5, 88.5, 255.5, 69.5, 6.5, 90.5, 255.5, 69.5, 8.5, 91.5, 255.5, 70.5, 9.5, 92.5, 255.5, 70.5, 11.5, 94.5, 255.5, 70.5, 12.5, 95.5, 255.5, 70.5, 14.5, 97.5, 255.5, 71.5, 15.5, 98.5, 255.5, 71.5, 17.5, 99.5, 255.5, 71.5, 18.5, 101.5, 255.5, 71.5, 20.5, 102.5, 255.5, 71.5, 21.5, 103.5, 255.5, 71.5, 22.5, 105.5, 255.5, 71.5, 24.5, 106.5, 255.5, 72.5, 25.5, 107.5, 255.5, 72.5, 26.5, 108.5, 255.5, 72.5, 28.5, 110.5, 255.5, 72.5, 29.5, 111.5, 255.5, 72.5, 30.5, 112.5, 255.5, 72.5, 32.5, 113.5, 255.5, 72.5, 33.5, 114.5, 255.5, 72.5, 34.5, 115.5, 255.5, 72.5, 35.5, 116.5, 255.5, 71.5, 37.5, 117.5, 255.5, 71.5, 38.5, 118.5, 255.5, 71.5, 39.5, 119.5, 255.5, 71.5, 40.5, 120.5, 255.5, 71.5, 42.5, 121.5, 255.5, 71.5, 43.5, 122.5, 255.5, 71.5, 44.5, 123.5, 255.5, 70.5, 45.5, 124.5, 255.5, 70.5, 47.5, 124.5, 255.5, 70.5, 48.5, 125.5, 255.5, 70.5, 49.5, 126.5, 255.5, 69.5, 50.5, 127.5, 255.5, 69.5, 52.5, 127.5, 255.5, 69.5, 53.5, 128.5, 255.5, 69.5, 54.5, 129.5, 255.5, 68.5, 55.5, 129.5, 255.5, 68.5, 57.5, 130.5, 255.5, 67.5, 58.5, 131.5, 255.5, 67.5, 59.5, 131.5, 255.5, 67.5, 60.5, 132.5, 255.5, 66.5, 61.5, 132.5, 255.5, 66.5, 62.5, 133.5, 255.5, 66.5, 64.5, 133.5, 255.5, 65.5, 65.5, 134.5, 255.5, 65.5, 66.5, 134.5, 255.5, 64.5, 67.5, 135.5, 255.5, 64.5, 68.5, 135.5, 255.5, 63.5, 69.5, 135.5, 255.5, 63.5, 71.5, 136.5, 255.5, 62.5, 72.5, 136.5, 255.5, 62.5, 73.5, 137.5, 255.5, 61.5, 74.5, 137.5, 255.5, 61.5, 75.5, 137.5, 255.5, 61.5, 76.5, 137.5, 255.5, 60.5, 77.5, 138.5, 255.5, 60.5, 78.5, 138.5, 255.5, 59.5, 80.5, 138.5, 255.5, 59.5, 81.5, 138.5, 255.5, 58.5, 82.5, 139.5, 255.5, 58.5, 83.5, 139.5, 255.5, 57.5, 84.5, 139.5, 255.5, 57.5, 85.5, 139.5, 255.5, 56.5, 86.5, 139.5, 255.5, 56.5, 87.5, 140.5, 255.5, 55.5, 88.5, 140.5, 255.5, 55.5, 89.5, 140.5, 255.5, 54.5, 90.5, 140.5, 255.5, 54.5, 91.5, 140.5, 255.5, 53.5, 92.5, 140.5, 255.5, 53.5, 93.5, 140.5, 255.5, 52.5, 94.5, 141.5, 255.5, 52.5, 95.5, 141.5, 255.5, 51.5, 96.5, 141.5, 255.5, 51.5, 97.5, 141.5, 255.5, 50.5, 98.5, 141.5, 255.5, 50.5, 99.5, 141.5, 255.5, 49.5, 100.5, 141.5, 255.5, 49.5, 101.5, 141.5, 255.5, 49.5, 102.5, 141.5, 255.5, 48.5, 103.5, 141.5, 255.5, 48.5, 104.5, 141.5, 255.5, 47.5, 105.5, 141.5, 255.5, 47.5, 106.5, 141.5, 255.5, 46.5, 107.5, 142.5, 255.5, 46.5, 108.5, 142.5, 255.5, 46.5, 109.5, 142.5, 255.5, 45.5, 110.5, 142.5, 255.5, 45.5, 111.5, 142.5, 255.5, 44.5, 112.5, 142.5, 255.5, 44.5, 113.5, 142.5, 255.5, 44.5, 114.5, 142.5, 255.5, 43.5, 115.5, 142.5, 255.5, 43.5, 116.5, 142.5, 255.5, 42.5, 117.5, 142.5, 255.5, 42.5, 118.5, 142.5, 255.5, 42.5, 119.5, 142.5, 255.5, 41.5, 120.5, 142.5, 255.5, 41.5, 121.5, 142.5, 255.5, 40.5, 122.5, 142.5, 255.5, 40.5, 122.5, 142.5, 255.5, 40.5, 123.5, 142.5, 255.5, 39.5, 124.5, 142.5, 255.5, 39.5, 125.5, 142.5, 255.5, 39.5, 126.5, 142.5, 255.5, 38.5, 127.5, 142.5, 255.5, 38.5, 128.5, 142.5, 255.5, 38.5, 129.5, 142.5, 255.5, 37.5, 130.5, 142.5, 255.5, 37.5, 131.5, 141.5, 255.5, 36.5, 132.5, 141.5, 255.5, 36.5, 133.5, 141.5, 255.5, 36.5, 134.5, 141.5, 255.5, 35.5, 135.5, 141.5, 255.5, 35.5, 136.5, 141.5, 255.5, 35.5, 137.5, 141.5, 255.5, 34.5, 137.5, 141.5, 255.5, 34.5, 138.5, 141.5, 255.5, 34.5, 139.5, 141.5, 255.5, 33.5, 140.5, 141.5, 255.5, 33.5, 141.5, 140.5, 255.5, 33.5, 142.5, 140.5, 255.5, 32.5, 143.5, 140.5, 255.5, 32.5, 144.5, 140.5, 255.5, 32.5, 145.5, 140.5, 255.5, 31.5, 146.5, 140.5, 255.5, 31.5, 147.5, 139.5, 255.5, 31.5, 148.5, 139.5, 255.5, 31.5, 149.5, 139.5, 255.5, 31.5, 150.5, 139.5, 255.5, 30.5, 151.5, 138.5, 255.5, 30.5, 152.5, 138.5, 255.5, 30.5, 153.5, 138.5, 255.5, 30.5, 153.5, 138.5, 255.5, 30.5, 154.5, 137.5, 255.5, 30.5, 155.5, 137.5, 255.5, 30.5, 156.5, 137.5, 255.5, 30.5, 157.5, 136.5, 255.5, 30.5, 158.5, 136.5, 255.5, 30.5, 159.5, 136.5, 255.5, 30.5, 160.5, 135.5, 255.5, 31.5, 161.5, 135.5, 255.5, 31.5, 162.5, 134.5, 255.5, 31.5, 163.5, 134.5, 255.5, 32.5, 164.5, 133.5, 255.5, 32.5, 165.5, 133.5, 255.5, 33.5, 166.5, 133.5, 255.5, 33.5, 167.5, 132.5, 255.5, 34.5, 167.5, 132.5, 255.5, 35.5, 168.5, 131.5, 255.5, 35.5, 169.5, 130.5, 255.5, 36.5, 170.5, 130.5, 255.5, 37.5, 171.5, 129.5, 255.5, 38.5, 172.5, 129.5, 255.5, 39.5, 173.5, 128.5, 255.5, 40.5, 174.5, 127.5, 255.5, 41.5, 175.5, 127.5, 255.5, 42.5, 176.5, 126.5, 255.5, 43.5, 177.5, 125.5, 255.5, 44.5, 177.5, 125.5, 255.5, 46.5, 178.5, 124.5, 255.5, 47.5, 179.5, 123.5, 255.5, 48.5, 180.5, 122.5, 255.5, 50.5, 181.5, 122.5, 255.5, 51.5, 182.5, 121.5, 255.5, 53.5, 183.5, 120.5, 255.5, 54.5, 184.5, 119.5, 255.5, 56.5, 185.5, 118.5, 255.5, 57.5, 185.5, 118.5, 255.5, 59.5, 186.5, 117.5, 255.5, 61.5, 187.5, 116.5, 255.5, 62.5, 188.5, 115.5, 255.5, 64.5, 189.5, 114.5, 255.5, 66.5, 190.5, 113.5, 255.5, 68.5, 190.5, 112.5, 255.5, 69.5, 191.5, 111.5, 255.5, 71.5, 192.5, 110.5, 255.5, 73.5, 193.5, 109.5, 255.5, 75.5, 194.5, 108.5, 255.5, 77.5, 194.5, 107.5, 255.5, 79.5, 195.5, 105.5, 255.5, 81.5, 196.5, 104.5, 255.5, 83.5, 197.5, 103.5, 255.5, 85.5, 198.5, 102.5, 255.5, 87.5, 198.5, 101.5, 255.5, 89.5, 199.5, 100.5, 255.5, 91.5, 200.5, 98.5, 255.5, 94.5, 201.5, 97.5, 255.5, 96.5, 201.5, 96.5, 255.5, 98.5, 202.5, 95.5, 255.5, 100.5, 203.5, 93.5, 255.5, 103.5, 204.5, 92.5, 255.5, 105.5, 204.5, 91.5, 255.5, 107.5, 205.5, 89.5, 255.5, 109.5, 206.5, 88.5, 255.5, 112.5, 206.5, 86.5, 255.5, 114.5, 207.5, 85.5, 255.5, 116.5, 208.5, 84.5, 255.5, 119.5, 208.5, 82.5, 255.5, 121.5, 209.5, 81.5, 255.5, 124.5, 210.5, 79.5, 255.5, 126.5, 210.5, 78.5, 255.5, 129.5, 211.5, 76.5, 255.5, 131.5, 211.5, 75.5, 255.5, 134.5, 212.5, 73.5, 255.5, 136.5, 213.5, 71.5, 255.5, 139.5, 213.5, 70.5, 255.5, 141.5, 214.5, 68.5, 255.5, 144.5, 214.5, 67.5, 255.5, 146.5, 215.5, 65.5, 255.5, 149.5, 215.5, 63.5, 255.5, 151.5, 216.5, 62.5, 255.5, 154.5, 216.5, 60.5, 255.5, 157.5, 217.5, 58.5, 255.5, 159.5, 217.5, 56.5, 255.5, 162.5, 218.5, 55.5, 255.5, 165.5, 218.5, 53.5, 255.5, 167.5, 219.5, 51.5, 255.5, 170.5, 219.5, 50.5, 255.5, 173.5, 220.5, 48.5, 255.5, 175.5, 220.5, 46.5, 255.5, 178.5, 221.5, 44.5, 255.5, 181.5, 221.5, 43.5, 255.5, 183.5, 221.5, 41.5, 255.5, 186.5, 222.5, 39.5, 255.5, 189.5, 222.5, 38.5, 255.5, 191.5, 223.5, 36.5, 255.5, 194.5, 223.5, 34.5, 255.5, 197.5, 223.5, 33.5, 255.5, 199.5, 224.5, 31.5, 255.5, 202.5, 224.5, 30.5, 255.5, 205.5, 224.5, 29.5, 255.5, 207.5, 225.5, 28.5, 255.5, 210.5, 225.5, 27.5, 255.5, 212.5, 225.5, 26.5, 255.5, 215.5, 226.5, 25.5, 255.5, 218.5, 226.5, 24.5, 255.5, 220.5, 226.5, 24.5, 255.5, 223.5, 227.5, 24.5, 255.5, 225.5, 227.5, 24.5, 255.5, 228.5, 227.5, 24.5, 255.5, 231.5, 228.5, 25.5, 255.5, 233.5, 228.5, 25.5, 255.5, 236.5, 228.5, 26.5, 255.5, 238.5, 229.5, 27.5, 255.5, 241.5, 229.5, 28.5, 255.5, 243.5, 229.5, 30.5, 255.5, 246.5, 230.5, 31.5, 255.5, 248.5, 230.5, 33.5, 255.5, 250.5, 230.5, 34.5, 255.5, 253.5, 231.5, 36.5, 255.5, 0.5, 0.5, 0.5, 255.5, 255.5, 255.5, 255.5, 255.5, 169.5, 169.5, 169.5, 255.5],
"useAboveRangeColor": false,
"useBelowRangeColor": false,
"valueRange": [1, 1],
"vectorComponent": 0,
"vectorMode": 1,
"vectorSize": -1,
"vtkClass": "vtkLookupTable"
},
"mtime": 2,
"output": [],
"renderTime": 0,
"resolveCoincidentTopology": false,
"scalarMode": 0,
"scalarRange": [0, 1],
"scalarVisibility": true,
"static": false,
"topologyOffset": {
"Polygon": {
"factor": 0,
"unit": 0
},
"Line": {
"factor": 0,
"unit": 0
},
"Point": {
"factor": 0,
"unit": 0
}
},
"useInvertibleColors": false,
"useLookupTableScalarRange": false,
"vtkClass": "vtkMapper"
},
"mapperBounds": [-0.5, 0.5, -0.5, 0.5, -0.5, 0.5],
"matrix": {
"0": 1,
"1": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 1,
"6": 0,
"7": 0,
"8": 0,
"9": 0,
"10": 1,
"11": 0,
"12": 0,
"13": 0,
"14": 0,
"15": 1
},
"matrixMTime": {
"classHierarchy": ["vtkObject"],
"mtime": 2,
"vtkClass": "vtkObject"
},
"mtime": 3,
"orientation": [0, 0, 0],
"origin": [0, 0, 0],
"pickable": true,
"position": [0, 0, 0],
"property": {
"ambient": 0,
"ambientColor": [1, 1, 1],
"backfaceCulling": false,
"classHierarchy": ["vtkObject", "vtkProperty"],
"color": [1, 1, 1],
"diffuse": 1,
"diffuseColor": [1, 1, 1],
"edgeColor": [0, 0, 0],
"edgeVisibility": false,
"frontfaceCulling": false,
"interpolation": 1,
"lighting": true,
"lineWidth": 1,
"mtime": 60,
"opacity": 1,
"pointSize": 1,
"representation": 2,
"shading": false,
"specular": 0,
"specularColor": [1, 1, 1],
"specularPower": 1,
"vtkClass": "vtkProperty"
},
"renderTimeMultiplier": 1,
"savedEstimatedRenderTime": 0,
"scale": [1, 1, 1],
"textures": [],
"useBounds": true,
"visibility": true,
"vtkClass": "vtkActor"
}
`)
// ----------------------------------------------------------------------------
// Standard rendering code setup
// ----------------------------------------------------------------------------
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();
const actor = vtk(actorJSON);
const lut = actor.getMapper().getLookupTable();
renderer.addActor(actor);
renderer.resetCamera();
renderWindow.render();
//-------------------------------------------------------------------------------
// Need to change the table and update the render
//-------------------------------------------------------------------------------
// lut.set({'table': actorJSON.mapper.lookupTable.table})
// actor.modified();
// renderWindow.render();
//-------------------------------------------------------------------------------
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment