Commit f8e86f3d authored by legoc's avatar legoc
Browse files

Added trajectory data model and started modification of trajectory line with data

parent eac5bf12
......@@ -708,6 +708,34 @@ class TrajectoriesData {
}
}
/**
* Trajectories data data.
*/
class TrajectoriesDataData {
constructor() {
this._trajectoriesData = {};
this._currentId = 0;
}
get trajectoriesData() { return this._trajectoriesData; }
get currentTrajectoryData() {
if (this._currentId !== 0) {
return this._trajectoriesData[this._currentId];
}
return null;
}
update(trajectoriesDataModel) {
this._currentId = trajectoriesDataModel.id;
this._trajectoriesData[this._currentId] = trajectoriesDataModel.data;
return true;
}
}
///////////////////////////////////////////////////////////////////////////////
// Shared objects.
const mode = new Mode();
......@@ -728,8 +756,10 @@ const scattering = new ScatteringData();
const trajectory = new TrajectoriesData();
const trajectoryData = new TrajectoriesDataData();
const matrix = new MatrixData();
const config = {};
module.exports = { mode, expdata, grid, plane, peaks, sample, atoms, scattering, trajectory, matrix, config };
\ No newline at end of file
module.exports = { mode, expdata, grid, plane, peaks, sample, atoms, scattering, trajectory, trajectoryData, matrix, config };
\ No newline at end of file
......@@ -37,6 +37,7 @@ class TrajectoryController extends Controller {
PubSub.subscribe('change-plane', () => { this.planeChange(); });
PubSub.subscribe('update-3D-local', () => { this.update3DLocal(); });
PubSub.subscribe('update-3D-scattering', () => { this.update3DLocal(); });
PubSub.subscribe('update-trajectory-data', () => { this.updateTrajectoryData(); });
}
init() {
......@@ -268,11 +269,13 @@ class TrajectoryController extends Controller {
}
updateTrajectorySettings(values) {
console.log('trajectory settings');
this._trajectory3D.scaleEnergy(values.energyScale);
}
updateTrajectoryData() {
this._trajectory3D.updateData();
}
/**
* Inits the scan spy configuration.
*/
......
......@@ -71,6 +71,7 @@ function synchronizeSpy(data) {
updateTrajectoryNames(data.trajectory);
let updateTrajectories = state.trajectory.update(data.trajectory);
state.trajectoryData.update(data.trajectoryData);
let updateMatrix = state.matrix.update(data.matrix);
......@@ -100,6 +101,8 @@ function synchronizeSpy(data) {
PubSub.publish('change-trajectory', 0);
}
PubSub.publish('update-trajectory-data', 0);
if (updateAtoms) {
PubSub.publish('change-atoms-conf', 0);
PubSub.publish('update-atom-controller', 0);
......
......@@ -35,5 +35,6 @@ module.exports = {
scalarWorldToView: scalarWorldToView,
scalarViewToWorld: scalarViewToWorld,
vector3WorldToView: vector3WorldToView,
vector3ViewToWorld: vector3ViewToWorld
vector3ViewToWorld: vector3ViewToWorld,
scale: SCALE_3D
};
\ No newline at end of file
const {vector3WorldToView, scalarWorldToView, vector3ViewToWorld} = require('../../utils/conversion');
const {scale, vector3WorldToView, scalarWorldToView, vector3ViewToWorld} = require('../../utils/conversion');
const Color = require('../../utils/colors');
const TrajectorySegmentIterator = require('./trajectory-segment-iterator');
const TrajectoryCircleIterator = require('./trajectory-circle-iterator');
......@@ -16,21 +16,21 @@ class TrajectoryLine {
this._steps = steps;
this._setIntervals();
this._type = type;
this._center = vector3WorldToView(center.clone());
this._center = center.clone();
this._deltaSphereGroup = new THREE.Group();
let geometry = new THREE.SphereGeometry(1, 8, 8);
let geometry = new THREE.SphereGeometry(1/scale, 8, 8);
let material = new THREE.MeshBasicMaterial({color: 0x0000ff, opacity: 0.5, transparent: true, depthTest: false});
// Create the trajectory start sphere
this._trajSSphere = new THREE.Mesh(geometry, material);
this._trajSSphere.position.copy(vector3WorldToView(start.clone()));
this._trajSSphere.position.copy(start.clone());
this._trajSSphere.renderOrder = 1;
// Create the trajectory end sphere.
this._trajESphere = new THREE.Mesh(geometry, material);
this._trajESphere.position.copy(vector3WorldToView(end.clone()));
this._trajESphere.position.copy(end.clone());
this._trajESphere.renderOrder = 1;
// Create the line between start and end points.
......@@ -42,13 +42,26 @@ class TrajectoryLine {
this._trajectoryLine.renderOrder = 2;
this.highlight(false);
this.updateLine();
// Create a group for the elements of the line.
this._group = new THREE.Group();
this._group.scale.x = scale;
this._group.scale.y = scale;
this._group.scale.z = scale;
// Add elements to the parent.
this._parent.add(this._group);
this._group.add(this._trajSSphere);
this._group.add(this._trajESphere);
this._group.add(this._trajectoryLine);
this._group.add(this._deltaSphereGroup);
// Add elements to the scene.
this._parent.add(this._trajSSphere);
this._parent.add(this._trajESphere);
this._parent.add(this._trajectoryLine);
this._parent.add(this._deltaSphereGroup);
// Create a group for the data.
this._dataGroup = new THREE.Group();
this._group.add(this._dataGroup);
this.updateLine();
}
_setIntervals() {
......@@ -65,7 +78,7 @@ class TrajectoryLine {
}
set center(value) {
this._center = vector3WorldToView(value.clone());
this._center = value.clone();
}
set steps(value) {
......@@ -76,13 +89,13 @@ class TrajectoryLine {
set start(value) {
this._start = value;
this._trajSSphere.position.copy(vector3WorldToView(value.clone()));
this._trajSSphere.position.copy(value.clone());
this.updateLine();
}
set end(value) {
this._end = value;
this._trajESphere.position.copy(vector3WorldToView(value.clone()));
this._trajESphere.position.copy(value.clone());
this.updateLine();
}
......@@ -110,9 +123,9 @@ class TrajectoryLine {
// Remove the line from the scene before rebuilding it.
// Indeed trying to update the line by updating the vertices does not work.
this._parent.remove(this._trajectoryLine);
this._group.remove(this._trajectoryLine);
let geometry = new THREE.SphereGeometry(0.25, 16, 16);
let geometry = new THREE.SphereGeometry(0.25/scale, 8, 8);
let material = new THREE.MeshBasicMaterial({color: 0xffffff, depthTest: false, transparent: true});
let iterator = null;
......@@ -154,7 +167,75 @@ class TrajectoryLine {
this._trajectoryLine.geometry.verticesNeedUpdate = true;
// Add the newly created line.
this._parent.add(this._trajectoryLine);
this._group.add(this._trajectoryLine);
// Update the data.
//this.updateDataGroup();
}
calculateSegmentMatrix(start, end) {
let d = end.clone().sub(start).normalize();
let z = new THREE.Vector3(0, 0, 1);
let q = new THREE.Quaternion();
q.setFromUnitVectors(z, d);
let sMatrix = new THREE.Matrix4();
sMatrix.makeRotationFromQuaternion(q);
sMatrix.setPosition(start);
return sMatrix;
}
test(start, end) {
let sMatrix = this.calculateSegmentMatrix(start, end);
// Test.
let p = new THREE.Vector3(0, 0, 0);
p.applyMatrix4(sMatrix);
console.log('start = ' + JSON.stringify(start));
console.log('start conv = ' + JSON.stringify(p));
let l = end.clone().sub(start).length();
p = new THREE.Vector3(0, 0, l);
p.applyMatrix4(sMatrix);
console.log('end = ' + JSON.stringify(end));
console.log('end conv = ' + JSON.stringify(p));
}
updateDataGroup() {
// Change the group.
let inv = new THREE.Matrix4();
inv.getInverse(this._dataGroup.matrix);
this._dataGroup.applyMatrix(inv);
// Then we can apply the new matrix.
let matrix4 = this.calculateSegmentMatrix(this._start, this._end);
this._dataGroup.applyMatrix(matrix4);
// Remove old spheres.
for (var i = this._dataGroup.children.length - 1; i >= 0; i--) {
this._dataGroup.remove(this._dataGroup.children[i]);
}
// Calculate delta between spheres.
let length = this._end.clone().sub(this._start).length();
let delta = length / this._intervals;
// Place new spheres.
let geometry = new THREE.SphereGeometry(1/scale, 8, 8);
let material = new THREE.MeshBasicMaterial({color: 0xff0000, depthTest: false, transparent: true});
for (let i = 0; i <= this._intervals; i++) {
let sphere = new THREE.Mesh(geometry, material);
sphere.renderOrder = 3;
sphere.position.copy(new THREE.Vector3(0, 0, i * delta));
this._dataGroup.add(sphere);
}
}
/**
......@@ -184,10 +265,10 @@ class TrajectoryLine {
d.material.dispose();
}
this._parent.remove(this._trajSSphere);
this._parent.remove(this._trajESphere);
this._parent.remove(this._trajectoryLine);
this._parent.remove(this._deltaSphereGroup);
this._group.remove(this._trajSSphere);
this._group.remove(this._trajESphere);
this._group.remove(this._trajectoryLine);
this._group.remove(this._deltaSphereGroup);
}
}
......
......@@ -2,7 +2,7 @@ const View3D = require('./view3d');
const TrajectoryLine = require('../../utils/shapes/trajectory-line');
const { calculateKiKf } = require('../../utils/calculations');
const THREE = require('three');
const { scattering, matrix } = require('../../app-state');
const { scattering, matrix, trajectoryData } = require('../../app-state');
const {scalarWorldToView} = require('../../utils/conversion');
class TrajectoryView3D extends View3D {
......@@ -582,6 +582,13 @@ class TrajectoryView3D extends View3D {
hklLine.end = position;
}
/**
* Update the data of the current trajectory.
*/
updateData() {
//console.log('update data : ' + trajectoryData.currentTrajectoryData);
}
/**
* Update the trajectory line used for edition.
*/
......
......@@ -45,6 +45,7 @@ const SampleModel = require('./model/sample-model');
const ExpDataModel = require('./model/expdata-model');
const ScatteringModel = require('./model/scattering-model');
const TrajectoryModel = require('./model/trajectory-model');
const TrajectoryDataModel = require('./model/trajectory-data-model');
const AtomsModel = require('./model/atoms-model');
const ConfigurationModel = require('./model/configuration-model');
const BackupModel = require('./model/backup-model');
......@@ -58,6 +59,7 @@ let sampleModel = new SampleModel(vEXP.as, vEXP.bs, vEXP.cs, vEXP.aa, vEXP.bb, v
let expDataModel = new ExpDataModel('sqw-none', 'S = exp(-q*q/0.05)', 128, 128, 0, 1, 0, 0.01);
let scatteringModel = new ScatteringModel(vEXP.ki, vEXP.kf, vEXP.ss, vEXP.q_h, vEXP.q_k, vEXP.q_l, vEXP.fx, vEXP.a1, vEXP.a2, vEXP.a3, vEXP.a3p, vEXP.a4, vEXP.a5, vEXP.a6, vEXP.calculationStatus);
let trajectoryModel = new TrajectoryModel(vEXP.xbuPath);
let trajectoryDataModel = new TrajectoryDataModel();
let atomsModel = new AtomsModel();
// Build configuration model with all savables models.
......@@ -407,8 +409,6 @@ receiver.on('exportTrajectory', (msg, data) => {
receiver.on('init', (msg, data) => {
console.log('init');
// Resync in non-spy mode.
// Do not do it in spy mode, otherwise values will be reset.
......@@ -570,6 +570,9 @@ function updateScanTrajectory(clearTrajectories) {
startingTime
);
// Set the current trajectory.
trajectoryDataModel.addTrajectoryData(traj.id);
// Backup the model.
if (backupModel !== null) {
fs.writeFile(backupPath, backupModel.stringify(), () => {});
......@@ -590,6 +593,9 @@ PubSub.subscribe('syncSpy', (message, clearTrajectories) => {
// Set the XBU path.
trajectoryModel.xbuPath = vEXP.xbuPath;
// Set the scan data.
trajectoryDataModel.setDataToCurrentTrajectory(vEXP.dataScan);
// Update the trajectories.
updateScanTrajectory(clearTrajectories);
});
......@@ -605,6 +611,7 @@ receiver.on('updateSpy', (msg, data) => {
//expdata: expDataModel.toObject(),
scattering: scatteringModel.toObject(),
trajectory: trajectoryModel.toObject(),
trajectoryData: trajectoryDataModel.currentToObject(), // We pass only the current trajectory.
atoms: atomsModel.toObject(),
matrix: {
uMatrix: vEXP.uMatrix.toArray(),
......
const Model = require('./model');
class TrajectoryDataModel extends Model {
constructor() {
super();
this._trajectoriesData = {};
this._currentId = 0;
}
get trajectoriesData() { return this._trajectoriesData; }
/**
* Clears the trajectories.
*/
clear() {
this._trajectoriesData = {};
this._currentId = 0;
}
/**
* Add a trajectory data.
*/
addTrajectoryData(id) {
// Initialise an array.
this._trajectoriesData[id] = [];
// Update current id.
this._currentId = id;
}
/**
* Set data to the current trajectory.
*/
setDataToCurrentTrajectory(value) {
if (this._currentId !== 0) {
this._trajectoriesData[this._currentId] = value;
}
}
/**
* Return the trajectory data with the given id.
*/
getTrajectoryDataById(id) { return this._trajectoriesData[id]; }
/**
* Return the current trajectory data if it exists.
*/
getCurrentTrajectoryData() {
if (this._currentId !== 0) {
return this._trajectoriesData[this._currentId];
}
return null;
}
/**
* Cast this instance into a basic JS object.
* Only passes the current data.
*/
currentToObject() {
return {
id: this._currentId,
data: this.getCurrentTrajectoryData()
}
}
/**
* Save the model data into a config object (the saver object).
*/
save(saver) {
saver.trajectoryData = {};
}
/**
* Cast this instance into a basic JS object.
*/
toObject() {
return {
id: this._currentId,
data: this._trajectoriesData
}
}
/**
* Restore the model state saved in the saver object (the configuration object).
*/
restore(saver) {
this._trajectories = {};
}
}
module.exports = TrajectoryDataModel;
\ No newline at end of file
const THREE = require('three');
let trajectoryCount = 0;
// The id starts at 1.
let trajectoryCount = 1;
class Trajectory {
......
......@@ -85,6 +85,7 @@ class VEXPController {
this._runningScan = false;
this._nameScan = "";
this._startingTime = "";
this._dataScan = [];
// Spy.
if (modeModel.spyMode) {
......@@ -168,6 +169,8 @@ class VEXPController {
this._nameScan = this._dataAccessor.nameScan;
this._startingTime = this._dataAccessor.startingTime;
this._dataScan = data.dataScan;
// Update the matrix.
this.updateMatrix();
......@@ -452,6 +455,7 @@ class VEXPController {
get runningScan() { return this._runningScan; }
get nameScan() { return this._nameScan; }
get startingTime() { return this._startingTime; }
get dataScan() { return this._dataScan; }
}
const vEXPController = new VEXPController();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment