Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
vEXP
Commits
44db1038
Commit
44db1038
authored
May 18, 2020
by
legoc
Browse files
Corrected use of scale in trajectories
parent
1bc497ef
Changes
4
Hide whitespace changes
Inline
Side-by-side
js/client/utils/shapes/energy-line.js
View file @
44db1038
...
...
@@ -4,15 +4,13 @@ const {scale, vector3WorldToView, scalarWorldToView, vector3ViewToWorld} = requi
const
Color
=
require
(
'
../colors
'
);
const
{
mapColor
}
=
require
(
'
../map-color
'
);
const
{
mode
}
=
require
(
'
../../server-state
'
);
const
{
clientSettings
}
=
require
(
'
../../client-state
'
);
const
THREE
=
require
(
'
three
'
);
class
EnergyLine
extends
TrajectoryLine
{
constructor
(
type
,
parent
,
start
,
end
,
center
,
steps
)
{
super
(
type
,
parent
,
start
,
end
,
center
,
steps
);
// Scale the energy if the local z direction.
this
.
_scale
=
1.0
;
// Material.
this
.
_lineMaterial
=
new
THREE
.
MeshBasicMaterial
({
color
:
Color
.
Q
,
depthTest
:
true
,
transparent
:
false
});
...
...
@@ -32,10 +30,6 @@ class EnergyLine extends TrajectoryLine {
this
.
highlight
(
false
);
this
.
updateLine
();
}
scale
(
value
)
{
this
.
_scale
=
value
;
}
setData
(
data
)
{
...
...
@@ -45,6 +39,24 @@ class EnergyLine extends TrajectoryLine {
}
}
getEnergyScale
()
{
// The scale is only for ki and kf trajectories which are orthogonal to the scattering plane.
// Scale is applied for the direction orthogonal to the plane.
if
(
this
.
_type
==
'
ki
'
||
this
.
_type
==
'
kf
'
)
{
return
clientSettings
.
energyScale
;
}
return
1
;
}
removeSpheres
()
{
// Remove the spheres.
for
(
let
i
=
this
.
_deltaSphereGroup
.
children
.
length
-
1
;
i
>=
0
;
i
--
)
{
this
.
_deltaSphereGroup
.
remove
(
this
.
_deltaSphereGroup
.
children
[
i
]);
}
}
updateDataGroup
()
{
// Reset the group transform.
...
...
@@ -52,18 +64,24 @@ class EnergyLine extends TrajectoryLine {
inv
.
getInverse
(
this
.
_dataGroup
.
matrix
);
this
.
_dataGroup
.
applyMatrix
(
inv
);
// Calculate the rotation matrix between (start, end) and (0, 0, 1)
let
matrix4
=
this
.
calculateSegmentRotationMatrix
(
this
.
_start
,
this
.
_end
);
// Calculate the position of the new frame.
let
start
=
this
.
_start
.
clone
();
// Apply the scale in the z direction.
start
.
setZ
(
start
.
z
*
clientSettings
.
energyScale
);
matrix4
.
setPosition
(
start
);
// Then we can apply the new matrix.
let
matrix4
=
this
.
calculateSegmentMatrix
(
this
.
_start
,
this
.
_end
);
this
.
_dataGroup
.
applyMatrix
(
matrix4
);
// Remove old spheres.
for
(
let
s
of
this
.
_deltaSphereGroup
.
children
)
{
s
.
material
.
dispose
();
this
.
_deltaSphereGroup
.
remove
(
s
);
}
// Remove the old spheres.
this
.
removeSpheres
();
// Calculate length of the segment.
let
length
=
this
.
_end
.
clone
().
sub
(
this
.
_start
).
length
();
// Calculate length of the segment.
Applies the scale.
let
length
=
this
.
_end
.
clone
().
sub
(
this
.
_start
).
length
()
*
this
.
getEnergyScale
()
;
// Calculate delta between spheres.
let
delta
=
length
/
this
.
_intervals
;
...
...
@@ -104,13 +122,15 @@ class EnergyLine extends TrajectoryLine {
// Remove the line from the data group.
if
(
this
.
_line
!==
null
)
{
this
.
_dataGroup
.
remove
(
this
.
_line
.
object3D
);
// Destroy the line segment.
this
.
_line
.
destroy
();
}
// Calculate length of the segment.
let
length
=
this
.
_end
.
clone
().
sub
(
this
.
_start
).
length
();
// Calculate length of the segment.
Applies the scale.
let
length
=
this
.
_end
.
clone
().
sub
(
this
.
_start
).
length
()
*
this
.
getEnergyScale
()
;
// Create a line segment for the line.
let
segment
=
new
LineSegment
(
new
THREE
.
Vector3
(
0
,
0
,
0
),
new
THREE
.
Vector3
(
0
,
0
,
length
),
0.5
/
scale
,
this
.
_lineMaterial
);
let
segment
=
new
LineSegment
(
new
THREE
.
Vector3
(
0
,
0
,
0
),
new
THREE
.
Vector3
(
0
,
0
,
length
),
0.5
/
scale
,
this
.
_lineMaterial
);
this
.
_line
=
segment
;
// Add the line to the data group.
...
...
@@ -152,10 +172,8 @@ class EnergyLine extends TrajectoryLine {
// Destroy the line segment.
this
.
_line
.
destroy
();
// Dispose the materials of the spheres.
for
(
let
s
of
this
.
_deltaSphereGroup
.
children
)
{
s
.
material
.
dispose
();
}
// Remove the spheres.
this
.
removeSpheres
();
}
}
...
...
js/client/utils/shapes/hkl-line.js
View file @
44db1038
...
...
@@ -41,6 +41,20 @@ class HKLLine extends TrajectoryLine {
this
.
updateLine
();
}
removeLineSegments
()
{
// Remove the line segments.
for
(
let
i
=
this
.
_lineGroup
.
children
.
length
-
1
;
i
>=
0
;
i
--
)
{
this
.
_lineGroup
.
remove
(
this
.
_lineGroup
.
children
[
i
]);
}
}
removeSpheres
()
{
// Remove the spheres.
for
(
let
i
=
this
.
_deltaSphereGroup
.
children
.
length
-
1
;
i
>=
0
;
i
--
)
{
this
.
_deltaSphereGroup
.
remove
(
this
.
_deltaSphereGroup
.
children
[
i
]);
}
}
/**
* Update line position and delta spheres.
*/
...
...
@@ -64,14 +78,10 @@ class HKLLine extends TrajectoryLine {
this
.
_line
=
[];
// Remove old line segments.
for
(
let
i
=
this
.
_lineGroup
.
children
.
length
-
1
;
i
>=
0
;
i
--
)
{
this
.
_lineGroup
.
remove
(
this
.
_lineGroup
.
children
[
i
]);
}
this
.
removeLineSegments
();
// Remove old spheres.
for
(
let
i
=
this
.
_deltaSphereGroup
.
children
.
length
-
1
;
i
>=
0
;
i
--
)
{
this
.
_deltaSphereGroup
.
remove
(
this
.
_deltaSphereGroup
.
children
[
i
]);
}
this
.
removeSpheres
();
// Copy the start and end position if they changed.
this
.
_startSphere
.
position
.
copy
(
this
.
_start
.
clone
());
...
...
js/client/utils/shapes/trajectory-line.js
View file @
44db1038
...
...
@@ -104,7 +104,10 @@ class TrajectoryLine {
throw
new
Error
(
'
highlightSpheres must be redefined
'
);
}
calculateSegmentMatrix
(
start
,
end
)
{
/**
* Calculates the rotation matrix between the segment (start, end) and (0, 0, 1).
*/
calculateSegmentRotationMatrix
(
start
,
end
)
{
let
d
=
end
.
clone
().
sub
(
start
).
normalize
();
let
z
=
new
THREE
.
Vector3
(
0
,
0
,
1
);
...
...
@@ -114,8 +117,7 @@ class TrajectoryLine {
let
sMatrix
=
new
THREE
.
Matrix4
();
sMatrix
.
makeRotationFromQuaternion
(
q
);
sMatrix
.
setPosition
(
start
);
return
sMatrix
;
}
...
...
js/client/views/3D/trajectory-view.js
View file @
44db1038
...
...
@@ -31,11 +31,8 @@ class TrajectoryView3D extends View3D {
this
.
_energyViewGroup
=
this
.
createGroup
(
matrix
.
uMatrix_1
);
this
.
_energyViewGroup
.
visible
=
false
;
this
.
_energyScaleGroup
=
new
THREE
.
Group
();
this
.
_energyViewGroup
.
add
(
this
.
_energyScaleGroup
);
this
.
_energyTranslationGroup
=
new
THREE
.
Group
();
this
.
_energy
Scale
Group
.
add
(
this
.
_energyTranslationGroup
);
this
.
_energy
View
Group
.
add
(
this
.
_energyTranslationGroup
);
// Create fake trajectory lines to visualize.
this
.
_hklLine
=
new
HKLLine
(
this
.
_type
,
this
.
_hklViewGroup
,
new
THREE
.
Vector3
(),
new
THREE
.
Vector3
(),
new
THREE
.
Vector3
(),
11
);
...
...
@@ -194,8 +191,8 @@ class TrajectoryView3D extends View3D {
changeSettings
()
{
//
Change the scale on the z direction to change the length of the energy lines
.
this
.
_energyScaleGroup
.
scale
.
z
=
clientSettings
.
energyS
cal
e
;
//
Update the local matrix
.
this
.
update3DLo
cal
()
;
// Iterate on the trajectory lines.
for
(
let
id
in
this
.
_trajectoryLines
)
{
...
...
@@ -208,12 +205,16 @@ class TrajectoryView3D extends View3D {
}
update3DLocal
()
{
// First we reset the group matrix to identity.
let
inv
=
new
THREE
.
Matrix4
();
inv
.
getInverse
(
this
.
_energyTranslationGroup
.
matrix
);
this
.
_energyTranslationGroup
.
applyMatrix
(
inv
);
let
dE
=
this
.
calculateDE
();
// Get the current dE and apply the energy scale.
let
dE
=
this
.
calculateDE
()
*
clientSettings
.
energyScale
;
// Translate the group.
this
.
_energyTranslationGroup
.
translateZ
(
-
scalarWorldToView
(
dE
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment