Permalink
Browse files

Clean way of showing/hiding the computing progressbar and fire the ap…

…propriate callbacks.

Unfortunately, the progressbar does not yet have time to update properly. We need to put more timeouts in the computation loop.
  • Loading branch information...
haehn committed Oct 2, 2013
1 parent f82e440 commit d6a14ded6d14596499fe5691543f776249856274
Showing with 92 additions and 25 deletions.
  1. +29 −1 core/event.js
  2. +38 −0 objects/volume.js
  3. +25 −24 visualization/renderer.js
View
@@ -33,6 +33,7 @@ goog.provide('X.event.events');
// events provided
goog.provide('X.event.ComputingEvent');
goog.provide('X.event.ComputingProgressEvent');
goog.provide('X.event.ComputingEndEvent');
goog.provide('X.event.HoverEvent');
goog.provide('X.event.HoverEndEvent');
@@ -142,7 +143,10 @@ X.event.events = {
COMPUTING: X.event.uniqueId('computing'),
// the computing end event
COMPUTING_END: X.event.uniqueId('computing_end')
COMPUTING_END: X.event.uniqueId('computing_end'),
// the computing progress event
COMPUTING_PROGRESS: X.event.uniqueId('computing_progress')
};
@@ -477,6 +481,30 @@ X.event.ComputingEvent = function() {
goog.inherits(X.event.ComputingEvent, X.event);
/**
* This event indicates computing progress for volume rendering.
*
* @constructor
* @extends X.event
*/
X.event.ComputingProgressEvent = function() {
// call the default event constructor
goog.base(this, X.event.events.COMPUTING_PROGRESS);
/**
* The progress in percent
*
* @type {!number}
* @protected
*/
this._value = 0;
};
// inherit from goog.events.Event
goog.inherits(X.event.ComputingProgressEvent, X.event);
/**
* This event indicates the end of computing for volume rendering.
*
View
@@ -1375,10 +1375,14 @@ X.volume.prototype.volumeRendering_ = function(direction) {
var _numberOfSlices = _child._children.length;
var _computing = false;
var _progress = 0;
var i;
for (i = 0; i < _numberOfSlices; i++) {
_progress = Math.floor(((i+1)/_numberOfSlices)*100);
this.onComputingProgress_(_progress);
// RESLICE VOLUME IF NECESSARY!
//loop through slice
if(!goog.isDefAndNotNull(_child._children[i])){
@@ -1415,6 +1419,7 @@ X.volume.prototype.volumeRendering_ = function(direction) {
}
_child._children[i]._visible = true;
}
// store the direction
@@ -1451,6 +1456,24 @@ X.volume.prototype.onComputing_ = function(direction) {
};
/**
* The oncomputingprogress internal callback. Any actions prior to
* firing the public oncomputingprogress callback go here.
*
* @param {!number} progress The progress value in percent.
* @protected
*/
X.volume.prototype.onComputingProgress_ = function(progress) {
var computingProgressEvent = new X.event.ComputingProgressEvent();
computingProgressEvent._value = progress;
this.dispatchEvent(computingProgressEvent);
this['onComputingProgress'](progress);
};
/**
* The oncomputingend internal callback. Any actions prior to firing the
* public oncomputingend callback go here.
@@ -1485,6 +1508,20 @@ X.volume.prototype.onComputing = function(direction) {
};
/**
* This callback gets fired when computation is happening.
*
* @param {!number} progress The current computation progress in percent.
* @public
*
*/
X.volume.prototype.onComputingProgress = function(progress) {
// should be overloaded
};
/**
* This callback gets fired when computation is complete.
*
@@ -1504,4 +1541,5 @@ goog.exportSymbol('X.volume', X.volume);
goog.exportSymbol('X.volume.prototype.modified', X.volume.prototype.modified);
goog.exportSymbol('X.volume.prototype.sliceInfoChanged', X.volume.prototype.sliceInfoChanged);
goog.exportSymbol('X.volume.prototype.onComputing', X.volume.prototype.onComputing);
goog.exportSymbol('X.volume.prototype.onComputingProgress', X.volume.prototype.onComputingProgress);
goog.exportSymbol('X.volume.prototype.onComputingEnd', X.volume.prototype.onComputingEnd);
View
@@ -179,6 +179,14 @@ X.renderer = function() {
*/
this._progressBar = null;
/**
* The progressBar for computing progress.
*
* @type {?X.progressbar}
* @protected
*/
this._progressBar2 = null;
/**
* The rendering context of this renderer.
*
@@ -222,12 +230,7 @@ goog.inherits(X.renderer, X.base);
* @public
*/
X.renderer.prototype.onComputing = function(event) {
this.showProgressBar_();
return;
// // we use the loader to activate the progressbar
// this._loader._jobs.set(event._object._id, false);
window.console.log('aaaaa')
// stop the rendering loop
window.cancelAnimationFrame(this._AnimationFrameID);
@@ -238,7 +241,6 @@ return;
}
};
@@ -251,14 +253,6 @@ return;
*/
X.renderer.prototype.onComputingEnd = function(event) {
this.hideProgressBar_();
return;
// // we use the loader to mark the computation as completed
// this._loader._jobs.set(event._object._id, true);
// only do the following if the progressBar was not turned off
if (this._config['PROGRESSBAR_ENABLED']) {
@@ -280,12 +274,12 @@ return;
}
// // we don't want to call onShowtime again
this._onShowtime = true;
this._loadingCompleted = true;
// // we don't want to call onShowtime again
this._onShowtime = true;
this._loadingCompleted = true;
this.render();
// restart the rendering loop
this.render();
}.bind(this), 700);
// .. and jump out
@@ -299,19 +293,19 @@ return;
/**
* The callback for X.event.events.PROGRESS events which indicate progress
* updates during loading.
* The callback for X.event.events.COMPUTING_PROGRESS events which indicate progress
* updates during computing.
*
* @param {!X.event.ProgressEvent} event The progress event holding the total
* @param {!X.event.ComputingProgressEvent} event The progress event holding the total
* progress value.
* @public
*/
X.renderer.prototype.onComputingProgress = function(event) {
if (this._progressBar) {
if (this._progressBar2) {
var _progress = event._value;
this._progressBar.setValue(_progress * 100);
this._progressBar2.setValue(_progress * 100);
}
@@ -906,6 +900,13 @@ X.renderer.prototype.update_ = function(object) {
}
if(!goog.events.hasListener(object, X.event.events.COMPUTING_PROGRESS)) {
goog.events.listen(object, X.event.events.COMPUTING_PROGRESS, this.onComputingProgress
.bind(this));
}
if(!goog.events.hasListener(object, X.event.events.COMPUTING_END)) {
goog.events.listen(object, X.event.events.COMPUTING_END, this.onComputingEnd

0 comments on commit d6a14de

Please sign in to comment.