Commit a3d1a922 authored by legoc's avatar legoc
Browse files

Reorganised hkl and energy line

parent 53f92bfd
......@@ -16,15 +16,18 @@ class EnergyLine extends TrajectoryLine {
this._dataGroup = new THREE.Group();
this._group.add(this._dataGroup);
this.highlight(false);
this.updateLine();
}
setData(data) {
this._data = data;
}
highlightSpheres(value) {
this._dataGroup.visible = value;
}
updateDataGroup() {
// Change the group.
......@@ -46,19 +49,28 @@ class EnergyLine extends TrajectoryLine {
let delta = length / this._intervals;
// Place new spheres.
let geometry = new THREE.SphereGeometry(0.5 * delta, 8, 8);
let dataGeometry = new THREE.SphereGeometry(0.5 * delta, 8, 8);
let pointGeometry = new THREE.SphereGeometry(0.25/scale, 8, 8);
for (let i = 0; i < this._data.length; i++) {
let material = new THREE.MeshBasicMaterial({color: 0xffffff, depthTest: true, transparent: false});
const color = mapColor(this._data[i], 0, 500);
material.color.setRGB(color.r, color.g, color.b);
let sphere = new THREE.Mesh(geometry, material);
for (let i = 0; i < this._intervals + 1; i++) {
let sphere;
if (i < this._data.length) {
let dataMaterial = new THREE.MeshBasicMaterial({color: 0xffffff, depthTest: true, transparent: false});
const color = mapColor(this._data[i], 0, 500);
dataMaterial.color.setRGB(color.r, color.g, color.b);
sphere = new THREE.Mesh(dataGeometry, dataMaterial);
}
else {
let pointMaterial = new THREE.MeshBasicMaterial({color: 0xffffff, depthTest: true, transparent: false});
sphere = new THREE.Mesh(pointGeometry, pointMaterial);
}
sphere.renderOrder = 4;
sphere.position.copy(new THREE.Vector3(0, 0, i * delta));
this._dataGroup.add(sphere);
}
}
/**
......@@ -66,28 +78,16 @@ class EnergyLine extends TrajectoryLine {
*/
updateLine() {
// First copy the start and end position if they changed.
this._trajSSphere.position.copy(this._start.clone());
this._trajESphere.position.copy(this._end.clone());
// Remove the line from the scene before rebuilding it.
// Indeed trying to update the line by updating the vertices does not work.
this._group.remove(this._trajectoryLine);
let geometry = new THREE.SphereGeometry(0.25/scale, 8, 8);
let material = new THREE.MeshBasicMaterial({color: 0xffffff, depthTest: true, transparent: false});
let iterator = null;
if (this._type == 'q') {
iterator = new TrajectorySegmentIterator(this._trajSSphere.position, this._trajESphere.position, this._intervals);
iterator = new TrajectorySegmentIterator(this._start, this._end, this._intervals);
}
else if (this._type == 'ki' || this._type == 'kf') {
iterator = new TrajectoryCircleIterator(this._center, this._trajSSphere.position, this._trajESphere.position, this._intervals);
}
// Remove old spheres.
for (var i = this._deltaSphereGroup.children.length - 1; i >= 0; i--) {
this._deltaSphereGroup.remove(this._deltaSphereGroup.children[i]);
iterator = new TrajectoryCircleIterator(this._center, this._start, this._end, this._intervals);
}
// Create the line.
......@@ -102,12 +102,7 @@ class EnergyLine extends TrajectoryLine {
// Place new spheres.
for(let i = 0; i < this._intervals; i++) {
let stepSphere = new THREE.Mesh(geometry, material);
stepSphere.renderOrder = 3;
stepSphere.position.copy(iterator.value());
this._trajectoryLine.geometry.vertices.push(iterator.value());
this._deltaSphereGroup.add(stepSphere);
iterator.next();
}
......@@ -122,6 +117,26 @@ class EnergyLine extends TrajectoryLine {
this.updateDataGroup();
}
/**
* Set line visibility.
*/
setVisibility(visibility) {
this._trajectoryLine.visible = visibility;
//this._dataGroup.visible = visibility;
}
/**
* Remove this trajectory properly.
*/
destroy() {
this._trajectoryLine.geometry.dispose();
this._trajectoryLine.material.dispose();
for (let d of this._dataGroup.children) {
d.geometry.dispose();
d.material.dispose();
}
}
}
module.exports = EnergyLine;
\ No newline at end of file
......@@ -8,10 +8,33 @@ const THREE = require('three');
class HKLLine extends TrajectoryLine {
constructor(type, parent, start, end, center, steps) {
super(type, parent, start, end, center, steps);
let geometry = new THREE.SphereGeometry(1/scale, 8, 8);
let material = new THREE.MeshBasicMaterial({color: 0x0000ff, opacity: 0.5, depthTest: true, transparent: false});
// Create the trajectory start sphere
this._trajSSphere = new THREE.Mesh(geometry, material);
this._trajSSphere.renderOrder = 1;
// Create the trajectory end sphere.
this._trajESphere = new THREE.Mesh(geometry, material);
this._trajESphere.renderOrder = 1;
this._deltaSphereGroup = new THREE.Group();
this._group.add(this._trajSSphere);
this._group.add(this._trajESphere);
this._group.add(this._deltaSphereGroup);
this.highlight(false);
this.updateLine();
}
highlightSpheres(value) {
this._deltaSphereGroup.visible = value;
}
/**
* Update line position and delta spheres.
*/
......@@ -30,10 +53,10 @@ class HKLLine extends TrajectoryLine {
let iterator = null;
if (this._type == 'q') {
iterator = new TrajectorySegmentIterator(this._trajSSphere.position, this._trajESphere.position, this._intervals);
iterator = new TrajectorySegmentIterator(this._start, this._end, this._intervals);
}
else if (this._type == 'ki' || this._type == 'kf') {
iterator = new TrajectoryCircleIterator(this._center, this._trajSSphere.position, this._trajESphere.position, this._intervals);
iterator = new TrajectoryCircleIterator(this._center, this._start, this._end, this._intervals);
}
// Remove old spheres.
......@@ -70,6 +93,33 @@ class HKLLine extends TrajectoryLine {
this._group.add(this._trajectoryLine);
}
/**
* Set line visibility.
*/
setVisibility(visibility) {
this._trajectoryLine.visible = visibility;
this._trajSSphere.visible = visibility;
this._trajESphere.visible = visibility;
this._deltaSphereGroup.visible = visibility;
}
/**
* Remove this trajectory properly.
*/
destroy() {
this._trajSSphere.geometry.dispose();
this._trajESphere.geometry.dispose();
this._trajSSphere.material.dispose();
this._trajESphere.material.dispose();
this._trajectoryLine.geometry.dispose();
this._trajectoryLine.material.dispose();
for(let d of this._deltaSphereGroup.children) {
d.geometry.dispose();
d.material.dispose();
}
}
}
module.exports = HKLLine;
\ No newline at end of file
......@@ -16,19 +16,6 @@ class TrajectoryLine {
this._type = type;
this._center = center.clone();
this._scale = 1.0;
this._deltaSphereGroup = new THREE.Group();
let geometry = new THREE.SphereGeometry(1/scale, 8, 8);
let material = new THREE.MeshBasicMaterial({color: 0x0000ff, opacity: 0.5, depthTest: true, transparent: false});
// Create the trajectory start sphere
this._trajSSphere = new THREE.Mesh(geometry, material);
this._trajSSphere.renderOrder = 1;
// Create the trajectory end sphere.
this._trajESphere = new THREE.Mesh(geometry, material);
this._trajESphere.renderOrder = 1;
// Create the line between start and end points.
let lineGeo = new THREE.Geometry();
......@@ -37,8 +24,6 @@ class TrajectoryLine {
this._trajectoryLine = new THREE.Line(lineGeo, lineMaterial);
this._trajectoryLine.geometry.verticesNeedUpdate = true;
this._trajectoryLine.renderOrder = 2;
this.highlight(false);
// Create a group for the elements of the line.
this._group = new THREE.Group();
......@@ -49,10 +34,7 @@ class TrajectoryLine {
// 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);
}
_setIntervals() {
......@@ -106,7 +88,11 @@ class TrajectoryLine {
}
// Set the points visible or not.
this._deltaSphereGroup.visible = value;
this.highlightSpheres(value);
}
highlightSpheres(value) {
throw new Error('updateSpheres must be redefined');
}
/**
......@@ -135,38 +121,6 @@ class TrajectoryLine {
return sMatrix;
}
/**
* Set line visibility.
*/
setVisibility(visibility) {
this._trajectoryLine.visible = visibility;
this._trajSSphere.visible = visibility;
this._trajESphere.visible = visibility;
this._deltaSphereGroup.visible = visibility;
}
/**
* Remove this trajectory properly.
*/
destroy() {
this._trajSSphere.geometry.dispose();
this._trajESphere.geometry.dispose();
this._trajSSphere.material.dispose();
this._trajESphere.material.dispose();
this._trajectoryLine.geometry.dispose();
this._trajectoryLine.material.dispose();
for(let d of this._deltaSphereGroup.children) {
d.geometry.dispose();
d.material.dispose();
}
this._group.remove(this._trajSSphere);
this._group.remove(this._trajESphere);
this._group.remove(this._trajectoryLine);
this._group.remove(this._deltaSphereGroup);
}
}
module.exports = TrajectoryLine;
\ No newline at end of file
......@@ -310,7 +310,7 @@ class TrajectoryView3D extends View3D {
// Reset old highlighted lines.
let lines = this._trajectoryLines[this._highlightId];
if (lines !== null) {
if (lines !== undefined) {
if (lines.hkl !== null) {
lines.hkl.highlight(false);
}
......
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