Skip to content

Commit

Permalink
Merge pull request #546 from ElDeveloper/animation-fixes-tests-cherry…
Browse files Browse the repository at this point in the history
…-pick

Miscellaneous animation fixes
  • Loading branch information
antgonza authored Nov 1, 2016
2 parents fe559e1 + e7775ca commit c76d198
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 73 deletions.
15 changes: 13 additions & 2 deletions emperor/support_files/js/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
* @param {trajectoryCategory} a string with the name of the mapping file
* header where the data that groups the samples is contained, this will
* usually be BODY_SITE, HOST_SUBJECT_ID, etc. (required).
* @param {speed} Positive real number determining the speed of an animation,
* this is reflected in the number of frames produced for each time interval.
*
* @return returns an animation director if the parameters passed in were all
* valid.
Expand All @@ -70,7 +72,7 @@
*
*/
function AnimationDirector(mappingFileHeaders, mappingFileData, coordinatesData,
gradientCategory, trajectoryCategory){
gradientCategory, trajectoryCategory, speed){

// all arguments are required
if (mappingFileHeaders === undefined || mappingFileData === undefined ||
Expand All @@ -92,6 +94,11 @@ function AnimationDirector(mappingFileHeaders, mappingFileData, coordinatesData,
" file");
}

// guard against logical problems with the trajectory object
if (speed <= 0) {
throw new Error("The animation speed cannot be less than or equal to zero");
}

this.mappingFileHeaders = mappingFileHeaders;
this.mappingFileData = mappingFileData;
this.coordinatesData = coordinatesData;
Expand All @@ -102,6 +109,7 @@ function AnimationDirector(mappingFileHeaders, mappingFileData, coordinatesData,
this.maximumTrajectoryLength = null;
this.currentFrame = -1;
this.trajectories = new Array();
this.speed = speed;

this.initializeTrajectories();
this.getMaximumTrajectoryLength();
Expand All @@ -121,6 +129,9 @@ AnimationDirector.prototype.initializeTrajectories = function(){
var coordinatesBuffer = new Array();
var chewedDataBuffer = null;

// frames we want projected in the trajectory's interval
var n = Math.floor((1 / (this.speed)) * 10);

// compute a dictionary from where we will extract the germane data
chewedData = getSampleNamesAndDataForSortedTrajectories(
this.mappingFileHeaders, this.mappingFileData, this.coordinatesData,
Expand Down Expand Up @@ -173,7 +184,7 @@ AnimationDirector.prototype.initializeTrajectories = function(){

// create the trajectory object
trajectoryBuffer = new TrajectoryOfSamples(sampleNamesBuffer, key,
gradientPointsBuffer, coordinatesBuffer, this.minimumDelta);
gradientPointsBuffer, coordinatesBuffer, this.minimumDelta, n);

this.trajectories.push(trajectoryBuffer);

Expand Down
30 changes: 17 additions & 13 deletions emperor/support_files/js/emperor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ function setJqueryUi() {
range: "max",
min: 0.1,
max: 5,
step: 0.1,
value: 1,
slide: function( event, ui ) {
animationSpeedChanged(ui);
Expand Down Expand Up @@ -2454,18 +2455,19 @@ $(document).ready(function() {
// if it's the 1st frame to animate then the director will be null
if (g_animationDirector === null) {

// retrieve the values from the interface
trajectoryCategory = document.getElementById('trajectory-category-drop-down')[document.getElementById('trajectory-category-drop-down').selectedIndex].value;
gradientCategory = document.getElementById('gradient-category-drop-down')[document.getElementById('gradient-category-drop-down').selectedIndex].value;

// initialize the animation director
g_animationDirector = new AnimationDirector(g_mappingFileHeaders,
g_mappingFileData,
g_spherePositions,
gradientCategory,
trajectoryCategory,
10);
g_animationDirector.updateFrame();
// retrieve the values from the interface
trajectoryCategory = document.getElementById('trajectory-category-drop-down')[document.getElementById('trajectory-category-drop-down').selectedIndex].value;
gradientCategory = document.getElementById('gradient-category-drop-down')[document.getElementById('gradient-category-drop-down').selectedIndex].value;

// initialize the animation director
g_animationDirector = new AnimationDirector(g_mappingFileHeaders,
g_mappingFileData,
g_spherePositions,
gradientCategory,
trajectoryCategory,
$('#animation-speed-slider').slider('value'));
$('#animation-speed-slider').slider('option', 'disabled', true);
g_animationDirector.updateFrame();

}
else{
Expand Down Expand Up @@ -2504,6 +2506,7 @@ $(document).ready(function() {
g_animationDirector = null;
g_isPlaying = false;
document.getElementById("play-button").disabled="false";
$('#animation-speed-slider').slider('option', 'disabled', false);

}// animation cycle is done
}// animation director is not null
Expand Down Expand Up @@ -2547,6 +2550,7 @@ function resetAnimation() {
g_isPlaying = false;
g_animationDirector = null;
document.getElementById("play-button").disabled="false";
$('#animation-speed-slider').slider('option', 'disabled', false);

for (var index = 0; index < g_animationLines.length; index++){
g_mainScene.remove(g_animationLines[index]);
Expand Down Expand Up @@ -2589,7 +2593,7 @@ function drawTrajectoryLine(trajectory, currentFrame, color, width){
// the line will contain the two vertices and the described material
// we increase the number of points to have a smoother transition on
// edges i. e. where the trajectory changes the direction it is going
lineGeometry = new THREE.TubeGeometry(path, (points.length-1)*3, g_radius,
lineGeometry = new THREE.TubeGeometry(path, (points.length-1)*3, g_radius * 0.4,
g_segments, false, true);

return new THREE.Mesh(lineGeometry, material);
Expand Down
2 changes: 1 addition & 1 deletion emperor/support_files/js/trajectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function TrajectoryOfSamples(sampleNames, metadataCategoryName, gradientPoints,
// this value determines how fast the animation will run for now let's use
// 5 and stick to it as a good default value; 60 was way too slow
this.suppliedN = suppliedN !== undefined ? suppliedN : 5;
this.maxN = maxN !== undefined ? maxN : 10;
this.maxN = maxN !== undefined ? maxN : 100;

if (this.coordinates.length != this.gradientPoints.length) {
throw new Error("The number of coordinate points and gradient points is"+
Expand Down
21 changes: 19 additions & 2 deletions tests/javascript_tests/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
result = message.data;
failed = !result || result.failed;

phantom.exit(failed ? 1 : 0);
exit(failed ? 1 : 0);
}
}
};

page.open(url, function(status) {
if (status !== 'success') {
console.error('Unable to access network: ' + status);
phantom.exit(1);
exit(1);
} else {
// Cannot do this verification with the 'DOMContentLoaded' handler because it
// will be too late to attach it if a page does not have any script tags.
Expand Down Expand Up @@ -136,4 +136,21 @@
});
}, false);
}

/*
This function was taken from:
https://github.com/jonkemp/qunit-phantomjs-runner
It helps prevent some problems with the output produced by this script.
*/
function exit(code) {
if (page) {
page.close();
}
setTimeout(function () {
phantom.exit(code);
}, 0);
}


})();
35 changes: 24 additions & 11 deletions tests/javascript_tests/test_animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ $(document).ready(function() {

var director = new AnimationDirector(mappingFileHeaders,mappingFileData,
coordinatesData, 'DOB',
'Treatment', 1000, 10);
'Treatment', 8);

// a quick run through all the properties
equal(director.mappingFileHeaders, mappingFileHeaders, 'The mapping '+
Expand All @@ -81,7 +81,7 @@ $(document).ready(function() {
'trajectoryCategory is set correctly');
equal(director.minimumDelta, 92, 'The minimum delta is computed'+
'correctly');
equal(director.maximumTrajectoryLength, 26, 'The maximum trajectory '+
equal(director.maximumTrajectoryLength, 109, 'The maximum trajectory '+
'length value is correct');
equal(director.currentFrame, -1, 'The current frame is correct');
equal(director.trajectories.length, 2, 'The number of trajectories is '+
Expand Down Expand Up @@ -182,6 +182,19 @@ $(document).ready(function() {
Error,
'An error is raised if no the number of frames is not passed'
);

throws(
function (){
resul = new AnimationDirector(mappingFileHeaders,
mappingFileDataShort,
coordinatesDataShort,
'DOB', 'Treatment', -11);
},
Error,
'An error is raised if a negative speed is passed.'
)


});

/**
Expand All @@ -194,21 +207,21 @@ $(document).ready(function() {

var director = new AnimationDirector(mappingFileHeaders, mappingFileData,
coordinatesData, 'DOB',
'Treatment', 1000);
equal(director.getMaximumTrajectoryLength(), 26,
'Treatment', 1);
equal(director.getMaximumTrajectoryLength(), 208,
'Test for the correct getMaximumTrajectoryLength value to be '+
'returned');
var director = new AnimationDirector(mappingFileHeaders, mappingFileData,
coordinatesData, 'DOB',
'Treatment', 10000);
equal(director.getMaximumTrajectoryLength(), 26,
'Treatment', 5);
equal(director.getMaximumTrajectoryLength(), 122,
'Test for the correct getMaximumTrajectoryLength value to be '+
'returned');
var director = new AnimationDirector(mappingFileHeaders,
mappingFileData, coordinatesData,
'DOB', 'LinkerPrimerSequence',
1000);
equal(director.getMaximumTrajectoryLength(), 41,
0.4);
equal(director.getMaximumTrajectoryLength(), 352,
'Test for the correct getMaximumTrajectoryLength value to be '+
'returned');
});
Expand All @@ -222,16 +235,16 @@ $(document).ready(function() {
test('Test the current frame is updated correctly', function() {
var director = new AnimationDirector(mappingFileHeaders,
mappingFileData, coordinatesData,
'DOB', 'Treatment', 1000);
'DOB', 'Treatment', 1);
equal(director.currentFrame, -1, 'The current frame is set correctly');
director.updateFrame();
equal(director.currentFrame, 0, 'The current frame is set correctly');

// make sure the value is topped at the maximum trajectory length
for (var i = 1; i < 1000; i++) {
for (var i = 1; i < 209; i++) {
director.updateFrame();
}
equal(director.currentFrame, 27, 'The current frame is stopped at the'+
equal(director.currentFrame, 208, 'The current frame is stopped at the'+
' maximum trajectory length');
});

Expand Down
94 changes: 50 additions & 44 deletions tests/javascript_tests/test_trajectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,46 +158,52 @@ $(document).ready(function() {

var trajectory;
var expectedInterpolatedCoordinates = [{ "x": 0, "y": 0, "z": 0},
{ "x": 0.1, "y": 0.1, "z": 0.1},
{ "x": 0.2, "y": 0.2, "z": 0.2},
{ "x": 0.30000000000000004, "y": 0.30000000000000004, "z": 0.30000000000000004},
{ "x": 0.4, "y": 0.4, "z": 0.4},
{ "x": 0.5, "y": 0.5, "z": 0.5},
{ "x": 0.6000000000000001, "y": 0.6000000000000001, "z": 0.6000000000000001},
{ "x": 0.7000000000000001, "y": 0.7000000000000001, "z": 0.7000000000000001},
{ "x": 0.8, "y": 0.8, "z": 0.8},
{ "x": 0.9, "y": 0.9, "z": 0.9},
{ "x": 1, "y": 1, "z": 1},
{ "x": 0, "y": 0, "z": 0},
{ "x": -1, "y": -1, "z": -1},
{ "x": -2, "y": -2, "z": -2},
{ "x": -3, "y": -3, "z": -3},
{ "x": -4, "y": -4, "z": -4},
{ "x": -5, "y": -5, "z": -5},
{ "x": -6, "y": -6, "z": -6},
{ "x": -7, "y": -7, "z": -7},
{ "x": -8, "y": -8, "z": -8},
{ "x": -9, "y": -9, "z": -9},
{ "x": -7.8, "y": -7.8, "z": -7.8},
{ "x": -6.6, "y": -6.6, "z": -6.6},
{ "x": -5.4, "y": -5.4, "z": -5.4},
{ "x": -4.2, "y": -4.2, "z": -4.2},
{ "x": -3, "y": -3, "z": -3},
{ "x": -1.8000000000000007, "y": -1.8000000000000007, "z": -1.8000000000000007},
{ "x": -0.5999999999999996, "y": -0.5999999999999996, "z": -0.5999999999999996},
{ "x": 0.5999999999999996, "y": 0.5999999999999996, "z": 0.5999999999999996},
{ "x": 1.799999999999999, "y": 1.799999999999999, "z": 1.799999999999999},
{ "x": 3, "y": 3, "z": 3},
{ "x": 3.5, "y": 3.5, "z": 3.5},
{ "x": 4, "y": 4, "z": 4},
{ "x": 4.5, "y": 4.5, "z": 4.5},
{ "x": 5, "y": 5, "z": 5},
{ "x": 5.5, "y": 5.5, "z": 5.5},
{ "x": 6, "y": 6, "z": 6},
{ "x": 6.5, "y": 6.5, "z": 6.5},
{ "x": 7, "y": 7, "z": 7},
{ "x": 7.5, "y": 7.5, "z": 7.5},
{ "x": 8, "y": 8, "z": 8}];
{"x": 0.06666666666666667, "y": 0.06666666666666667, "z": 0.06666666666666667},
{"x": 0.13333333333333333, "y": 0.13333333333333333, "z": 0.13333333333333333},
{"x": 0.2, "y": 0.2, "z": 0.2},
{"x": 0.26666666666666666, "y": 0.26666666666666666, "z": 0.26666666666666666},
{"x": 0.3333333333333333, "y": 0.3333333333333333, "z": 0.3333333333333333},
{"x": 0.4, "y": 0.4, "z": 0.4},
{"x": 0.4666666666666667, "y": 0.4666666666666667, "z": 0.4666666666666667},
{"x": 0.5333333333333333, "y": 0.5333333333333333, "z": 0.5333333333333333},
{"x": 0.6, "y": 0.6, "z": 0.6},
{"x": 0.6666666666666666, "y": 0.6666666666666666, "z": 0.6666666666666666},
{"x": 0.7333333333333333, "y": 0.7333333333333333, "z": 0.7333333333333333},
{"x": 0.8, "y": 0.8, "z": 0.8},
{"x": 0.8666666666666667, "y": 0.8666666666666667, "z": 0.8666666666666667},
{"x": 0.9333333333333333, "y": 0.9333333333333333, "z": 0.9333333333333333},
{"x": 1, "y": 1, "z": 1},
{"x": 0, "y": 0, "z": 0},
{"x": -1, "y": -1, "z": -1},
{"x": -2, "y": -2, "z": -2},
{"x": -3, "y": -3, "z": -3},
{"x": -4, "y": -4, "z": -4},
{"x": -5, "y": -5, "z": -5},
{"x": -6, "y": -6, "z": -6},
{"x": -7, "y": -7, "z": -7},
{"x": -8, "y": -8, "z": -8},
{"x": -9, "y": -9, "z": -9},
{"x": -7.8, "y": -7.8, "z": -7.8},
{"x": -6.6, "y": -6.6, "z": -6.6},
{"x": -5.4, "y": -5.4, "z": -5.4},
{"x": -4.2, "y": -4.2, "z": -4.2},
{"x": -3, "y": -3, "z": -3},
{"x": -1.8000000000000007, "y": -1.8000000000000007, "z": -1.8000000000000007},
{"x": -0.5999999999999996, "y": -0.5999999999999996, "z": -0.5999999999999996 }, { "x": 0.5999999999999996, "y": 0.5999999999999996, "z": 0.5999999999999996 }, { "x": 1.799999999999999, "y": 1.799999999999999, "z": 1.799999999999999 }, { "x": 3, "y": 3, "z": 3 }, { "x": 3.3333333333333335, "y": 3.3333333333333335, "z": 3.3333333333333335},
{"x": 3.6666666666666665, "y": 3.6666666666666665, "z": 3.6666666666666665},
{"x": 4, "y": 4, "z": 4},
{"x": 4.333333333333333, "y": 4.333333333333333, "z": 4.333333333333333},
{"x": 4.666666666666666, "y": 4.666666666666666, "z": 4.666666666666666},
{"x": 5, "y": 5, "z": 5},
{"x": 5.333333333333333, "y": 5.333333333333333, "z": 5.333333333333333},
{"x": 5.666666666666666, "y": 5.666666666666666, "z": 5.666666666666666},
{"x": 6, "y": 6, "z": 6},
{"x": 6.333333333333333, "y": 6.333333333333333, "z": 6.333333333333333},
{"x": 6.666666666666666, "y": 6.666666666666666, "z": 6.666666666666666},
{"x": 7, "y": 7, "z": 7},
{"x": 7.333333333333333, "y": 7.333333333333333, "z": 7.333333333333333},
{"x": 7.666666666666666, "y": 7.666666666666666, "z": 7.666666666666666},
{"x": 8, "y": 8, "z": 8}];
trajectory = new TrajectoryOfSamples(sampleNames, 'Treatment',
gradientPoints, coordinates, 2,
10);
Expand All @@ -206,10 +212,10 @@ $(document).ready(function() {
deepEqual(trajectory.interpolatedCoordinates,
expectedInterpolatedCoordinates,
'Check the interpolated coordinates are computed correctly');
deepEqual(trajectory._intervalValues, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3] , 'Check the intervals array is '+
'created properyl');
deepEqual(trajectory._intervalValues, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
'Check the intervals array is created properyl');

expectedInterpolatedCoordinates = [{"x": 0, "y": 0, "z": 0},
{"x": 0.25, "y": 0.25, "z": 0.25},
Expand Down

0 comments on commit c76d198

Please sign in to comment.