GeometryDataModel

GeometryDataModel

import GeometryDataModel from 'paraviewweb/src/IO/Core/GeometryDataModel';

geometryDataModel = new GeometryDataModel('/dataset');

constructor(basepath)

Create a geometryDataModel instance ready for fetching remote files that
will construct one or many 3D objects.

loadScene(scene)

The scene object is a JSON structure that describe the setting of the 3D scene
and which piece is needed for what (geometry, topology, fields, objects…).

Here is an example of a scene composed of a single object:

[
{
"fields": {
"ACCL": "fields/ACCL_00ef44b0f987708feb631bb8a82c2a21.Float32Array",
"VEL": "fields/VEL_d39000e259b144a63244325378d8496b.Float32Array",
"DISPL": "fields/DISPL_a7e4b3b8c7e653562d3fce0b2af72ae7.Float32Array"
},
"points": "points/7caae253277ef21512ab83c4368d5a33.Float32Array",
"name": "Can",
"index": "index/94cd4b75ca2a6360686d2f73baa069c5.Uint32Array"
}
]

onGeometryReady(callback) : subscription

Register callback for when a geometry object become ready.
(All its data is actually available)

geometryReady(obj)

Trigger event with the given geometry.

colorGeometryBy(objectName, fieldName)

Update the colorBy field of an object. Once the corresponding
color/field data became available (after download), then a
geometryReady event get triggered.

Source

index.js
import Monologue from 'monologue.js';
import DataManager from 'paraviewweb/src/IO/Core/DataManager';

const dataManager = new DataManager();
const OBJECT_READY_TOPIC = 'object-ready';

let geometryDataModelCounter = 0;

export default class GeometryDataModel {
constructor(basepath) {
geometryDataModelCounter += 1;

this.basepath = basepath; // Needed for cloning
this.id = ['GeometryDataModel', geometryDataModelCounter].join('_');
this.coloByMapping = {};
this.currentScene = null;
this.sceneData = {};
this.dataMapping = {};

dataManager.on(this.id, (data, envelope) => {
const url = data.requestedURL;
const dataDescription = this.dataMapping[url];

if (dataDescription) {
const obj = this.sceneData[dataDescription.name];
let objectComplete = true;

this.sceneData[dataDescription.name][
dataDescription.field
] = new window[dataDescription.type](data.data);

Object.keys(obj).forEach((key) => {
if (obj[key] === null) {
objectComplete = false;
}
});
if (objectComplete) {
this.geometryReady(obj);
}
}
});
}

onGeometryReady(callback) {
return this.on(OBJECT_READY_TOPIC, callback);
}

geometryReady(obj) {
this.emit(OBJECT_READY_TOPIC, obj);
}

colorGeometryBy(objectName, fieldName) {
let changeDetected = false;
if (fieldName) {
changeDetected = this.coloByMapping[objectName] !== fieldName;
this.coloByMapping[objectName] = fieldName;
} else {
delete this.coloByMapping[objectName];
}

if (changeDetected) {
this.loadScene(this.currentScene);
}
}

loadScene(scene) {
this.currentScene = scene;
if (scene) {
// Reset data
this.dataMapping = {};
this.sceneData = {};
const sceneData = this.sceneData;

// Fill data with expected
scene.forEach((obj) => {
const name = obj.name;
const urls = [];
let url = null;

// Init structure
sceneData[name] = {
name,
points: null,
index: null,
};

// Register urls
url = this.basepath + obj.points;
this.dataMapping[url] = {
name,
field: 'points',
type: obj.points.split('.').slice(-1)[0],
};
urls.push(url);

url = this.basepath + obj.index;
this.dataMapping[url] = {
name,
field: 'index',
type: obj.index.split('.').slice(-1)[0],
};
urls.push(url);

if (this.coloByMapping[name]) {
sceneData[name].field = null;
sceneData[name].fieldName = this.coloByMapping[name];

url = this.basepath + obj.fields[this.coloByMapping[name]];
this.dataMapping[url] = {
name,
field: 'field',
type: obj.fields[this.coloByMapping[name]].split('.').slice(-1)[0],
};
urls.push(url);
}

// Make the requests
urls.forEach((urlToFecth) => {
dataManager.fetchURL(urlToFecth, 'array', null, this.id);
});
});
}
}
}

// Add Observer pattern using Monologue.js
Monologue.mixInto(GeometryDataModel);