Skip to content

Commit 76f0e3a

Browse files
committed
Added some methods to disconnect slice viewer view from events when not shown, to reload data when changing time and area, do clean up in general as loaded volumes do slow the browser considerably
1 parent a6123d9 commit 76f0e3a

File tree

4 files changed

+98
-17
lines changed

4 files changed

+98
-17
lines changed

app/scripts/contrib/SliceViewer/SliceView.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ define([
2424

2525
this.currentToI = null;
2626
// Set a default AoI and Layer as the timeline can be changed even if no AoI and Layer is selected in the WebClient:
27-
this.currentAoI = [17.6726953125, 56.8705859375, 19.3865625, 58.12302734375];
27+
this.currentAoI = null;
2828

2929
// FIXXME: read from config!
3030
var backend = this.legacyContext().backendConfig['MeshFactory'];
@@ -146,10 +146,11 @@ define([
146146

147147
toi = this.currentToI = starttime.toISOString() + '/' + endtime.toISOString();
148148
}
149-
150-
// Remove all currently shown volumes and request the new data to update the view:
151-
this._update();
149+
} else {
150+
this.currentToI = null;
152151
}
152+
// Remove all currently shown volumes and request the new data to update the view:
153+
this._update();
153154
},
154155

155156
_onTimeChange: function(time) {
@@ -163,29 +164,33 @@ define([
163164
},
164165

165166
_update: function() {
166-
// if (this.getViewer()) {
167-
// this.getViewer().reset();
168-
// }
167+
if (this.getViewer()) {
168+
this.getViewer().reset();
169+
}
170+
171+
if (this.currentAoI != null && this.currentToI != null){
169172

170173
_.forEach(this.selectedLayers(), function(layer_info, key) {
171-
var view = this.supportsLayer(layer_info.model);
172-
if (view) {
173-
this._addVolume(view.id);
174-
console.log('[SliceView::_udpate] added layer: ' + view.id);
175-
}
176-
}.bind(this));
174+
var view = this.supportsLayer(layer_info.model);
175+
if (view) {
176+
this._addVolume(view.id);
177+
console.log('[SliceView::_udpate] added layer: ' + view.id);
178+
}
179+
}.bind(this));
180+
}
177181
},
178182

179183
_createViewer: function() {
180184
return new XTKViewer({
181185
elem: this.el,
182186
backgroundColor: [0.005, 0.005, 0.005],
183187
// cameraPosition: [120, 80, 160]
184-
cameraPosition: [2, 10, 10]
188+
cameraPosition: [500, 0, 500]
185189
});
186190
},
187191

188192
_addVolume: function(layer) {
193+
189194
this.enableEmptyView(false);
190195
this.onShow();
191196

@@ -320,6 +325,16 @@ define([
320325

321326
_removeVolume: function(layer_name) {
322327
this.getViewer().removeObject(layer_name);
328+
},
329+
330+
onClose: function(){
331+
if (this.getViewer()) {
332+
this.getViewer().reset();
333+
}
334+
this.stopListening();
335+
this.remove();
336+
this.unbind();
337+
this.isClosed = true;
323338
}
324339
});
325340

app/scripts/contrib/SliceViewer/XTKViewer/Viewer.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ define([
1717

1818
this.mainGUI = null;
1919
this.idx = 0;
20+
this.renderer = null;
2021
this.cameraPosition = opts.cameraPosition || [120, 80, 160];
2122
this.backgroundColor = opts.backgroundColor || [1, 1, 1];
23+
this.container = opts.elem;
2224

2325
// create and initialize a 3D renderer
2426
var r = this.renderer = new X.renderer3D();
2527
r.container = opts.elem;
2628
r.bgColor = this.backgroundColor;
29+
2730
r.init();
2831

2932
this.volumes = {};
@@ -35,6 +38,15 @@ define([
3538
r.camera.position = this.cameraPosition;
3639
};
3740

41+
XTKViewer.prototype.createRenderer = function() {
42+
// create and initialize a 3D renderer
43+
var r = this.renderer = new X.renderer3D();
44+
r.container = this.container;
45+
r.bgColor = this.backgroundColor;
46+
r.init();
47+
r.camera.position = this.cameraPosition;
48+
};
49+
3850
XTKViewer.prototype.onResize = function() {
3951
this.renderer.resetBoundingBox();
4052
this.renderer.resetViewAndRender();
@@ -52,6 +64,11 @@ define([
5264
// Takes (multiple) obj/mtl pairs with textures and adds them to the viewer.
5365
// NOTE: Currently only the first obj/mtl pair is displayed!
5466
XTKViewer.prototype.addMesh = function(opts) {
67+
68+
if(typeof this.renderer === 'undefined' || this.renderer == null)
69+
this.createRenderer();
70+
71+
5572
var modelnames = Object.keys(opts.models[0]),
5673
modeldata = opts.models[0][modelnames[0]],
5774
mtldata = opts.mtls[0][(modelnames[0].split('.')[0] + ".mtl")];
@@ -134,6 +151,7 @@ define([
134151
this.renderer._onShowtime = false;
135152

136153
this.renderer.onShowtime = function() {
154+
137155
if (!this.mainGUI) {
138156
var gui = this.mainGUI = new dat.GUI({
139157
autoPlace: true
@@ -173,8 +191,13 @@ define([
173191
};
174192

175193
XTKViewer.prototype.addVolume = function(opts) {
194+
195+
if(typeof this.renderer === 'undefined' || this.renderer == null)
196+
this.createRenderer();
176197
// FIXXME: define an array with supported mimetypes to not have to hardcode
177198
// the mimetypes here and below!
199+
200+
//this.createRenderer();
178201
var volumes = null;
179202
if (opts.data['application/x-nifti']) {
180203
volumes = opts.data['application/x-nifti'];
@@ -244,6 +267,7 @@ define([
244267
this.renderer._onShowtime = false;
245268

246269
this.renderer.onShowtime = function(entries) {
270+
247271
if (!this.mainGUI) {
248272
var gui = this.mainGUI = new dat.GUI({
249273
autoPlace: true
@@ -337,6 +361,26 @@ define([
337361
};
338362

339363
XTKViewer.prototype.reset = function() {
364+
_.each(_.keys(this.volumes), function(v){
365+
this.removeObject(v);
366+
},this);
367+
_.each(_.keys(this.meshes), function(v){
368+
this.removeObject(v);
369+
},this);
370+
371+
if (this.mainGUI) {
372+
this.removeGui(this.mainGUI);
373+
}
374+
};
375+
376+
XTKViewer.prototype.destroy = function() {
377+
_.each(_.keys(this.volumes), function(v){
378+
this.removeObject(v);
379+
},this);
380+
_.each(_.keys(this.meshes), function(v){
381+
this.removeObject(v);
382+
},this);
383+
340384
this.renderer.destroy();
341385
if (this.mainGUI) {
342386
this.removeGui(this.mainGUI);

app/scripts/vendor/rectangularboxviewer/RectangularBoxViewer-deps.debug.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60359,9 +60359,26 @@ I._texture&&W&&!a?(this._context.uniform1i(D,!0),this._context.activeTexture(thi
6035960359
parseFloat(J._opacity)):T&&T._visible&&(J=I._labelmap._id,this._context.uniform1i(C,!0),this._context.activeTexture(this._context.TEXTURE1),this._context.bindTexture(this._context.TEXTURE_2D,this._textures.get(J)),this._context.uniform1i(Q,1),this._context.uniform1f(H,T._opacity),this._context.uniform4fv(z,T._showOnlyColor)));this._context.uniformMatrix4fv(da,!1,I._transform._matrix);J=1;I._type==X.displayable.types.POINTS&&(J=I._pointsize);this._context.uniform1f(ea,J);J=-1;I._type==X.displayable.types.TRIANGLES?
6036060360
(J=this._context.TRIANGLES,f&&(j+=M._itemCount/3)):I._type==X.displayable.types.LINES?(this._context.lineWidth(I._linewidth),J=this._context.LINES,f&&(k+=M._itemCount/2)):I._type==X.displayable.types.POINTS?(J=this._context.POINTS,f&&(m+=M._itemCount)):I._type==X.displayable.types.TRIANGLE_STRIPS?(J=this._context.TRIANGLE_STRIP,f&&(j+=M._itemCount/3)):I._type==X.displayable.types.POLYGONS&&(J=0==M._itemCount%3?this._context.TRIANGLES:this._context.TRIANGLE_FAN,f&&(j+=M._itemCount/3));f&&(h+=M._itemCount);
6036160361
this._context.drawArrays(J,0,M._itemCount)}}}while(--e);f&&(c="Objects: "+d+" | "+("Vertices: "+h+" | "),c+="Triangles: "+Math.round(j)+" | ",c+="Lines: "+k+" | ",c+="Points: "+m+" | ",c+="Textures: "+this._textures.getCount(),window.console.log(c))}};
60362-
X.renderer3D.prototype.remove=function(a){X.renderer3D.superClass_.remove.call(this,a);if(0<a._children.length)for(var b=a._children,c=b.length,d=0,d=0;d<c;d++)this.remove(b[d]);b=a._id;c=this._texturePositionBuffers.get(b);goog.isDefAndNotNull(c)&&this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);if(a._texture&&(c=this._textures.get(a._texture._id)))this._context.deleteTexture(c),this._textures.remove(a._texture._id);c=this._vertexBuffers.get(b);goog.isDefAndNotNull(c)&&
60363-
this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);c=this._normalBuffers.get(b);goog.isDefAndNotNull(c)&&this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);c=this._colorBuffers.get(b);goog.isDefAndNotNull(c)&&this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);c=this._scalarBuffers.get(b);goog.isDefAndNotNull(c)&&this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);this._vertexBuffers.remove(b);this._normalBuffers.remove(b);
60364-
this._colorBuffers.remove(b);this._texturePositionBuffers.remove(b);this._scalarBuffers.remove(b);this._objects.remove(a);return!0};X.renderer3D.prototype.destroy=function(){this._shaders=null;delete this._shaders;this._context.clear(this._context.COLOR_BUFFER_BIT|this._context.DEPTH_BUFFER_BIT);X.renderer3D.superClass_.destroy.call(this)};X.renderer3D.prototype.__defineGetter__("bgColor",function(){return this._bgColor});
60362+
60363+
X.renderer3D.prototype.remove=function(a){
60364+
if(a){
60365+
X.renderer3D.superClass_.remove.call(this,a);
60366+
if(0<a._children.length)for(var b=a._children,c=b.length,d=0,d=0;d<c;d++)this.remove(b[d]);
60367+
b=a._id;
60368+
c=this._texturePositionBuffers.get(b);
60369+
goog.isDefAndNotNull(c)&&this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);
60370+
if(a._texture&&(c=this._textures.get(a._texture._id)))this._context.deleteTexture(c),this._textures.remove(a._texture._id);
60371+
c=this._vertexBuffers.get(b);goog.isDefAndNotNull(c)&&
60372+
this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);
60373+
c=this._normalBuffers.get(b);goog.isDefAndNotNull(c)&&this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);
60374+
c=this._colorBuffers.get(b);goog.isDefAndNotNull(c)&&this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);
60375+
c=this._scalarBuffers.get(b);goog.isDefAndNotNull(c)&&this._context.isBuffer(c._glBuffer)&&this._context.deleteBuffer(c._glBuffer);
60376+
this._vertexBuffers.remove(b);this._normalBuffers.remove(b);
60377+
this._colorBuffers.remove(b);this._texturePositionBuffers.remove(b);this._scalarBuffers.remove(b);this._objects.remove(a);return!0
60378+
}
60379+
};
60380+
60381+
X.renderer3D.prototype.destroy=function(){this._shaders=null;delete this._shaders;this._context.clear(this._context.COLOR_BUFFER_BIT|this._context.DEPTH_BUFFER_BIT);X.renderer3D.superClass_.destroy.call(this)};X.renderer3D.prototype.__defineGetter__("bgColor",function(){return this._bgColor});
6036560382
X.renderer3D.prototype.__defineSetter__("bgColor",function(a){this._bgColor=a});X.renderer3D.prototype.ray_intersect_box_=function(a,b,c){for(var d=[],e=[],f=0;6>f;f++){var g=Math.floor(f/2),h=(g+1)%3,j=(g+2)%3,k=(2+2*g)%6,m=(4+2*g)%6,l=(a[f]-b[g])*(1/c[g]);if(Infinity!=l&&-Infinity!=l){var n=b[h]+c[h]*l,l=b[j]+c[j]*l;n>=a[k]&&n<=a[k+1]&&l>=a[m]&&l<=a[m+1]?(k=[],k[g]=a[f],k[h]=n,k[j]=l,d.push(k)):(k=[],k[g]=a[f],k[h]=n,k[j]=l,e.push(k))}}return[d,e]};
6036660383
X.renderer3D.prototype.pick3d=function(a,b,c,d,e){goog.isDefAndNotNull(c)||(c=4);goog.isDefAndNotNull(d)||(d=2);if(!goog.isDefAndNotNull(e)){e=this.pick(a,b);if(-1==e)return null;e=this.get(e);if(!e)return null}var f=this._camera.unproject_(2*(a/this._width)-1,2*((this._height-b)/this._height)-1,0);a=this._camera.unproject_(2*(a/this._width)-1,2*((this._height-b)/this._height)-1,1);f[0]+=this._center[0];f[1]+=this._center[1];f[2]+=this._center[2];a[0]+=this._center[0];a[1]+=this._center[1];a[2]+=
6036760384
this._center[2];b=[e._points._minA,e._points._minB,e._points._minC];var g=[e._points._maxA,e._points._minB,e._points._minC],h=[e._points._maxA,e._points._maxB,e._points._minC],j=[e._points._minA,e._points._maxB,e._points._minC],k=[e._points._minA,e._points._maxB,e._points._maxC],m=[e._points._minA,e._points._minB,e._points._maxC],l=[e._points._maxA,e._points._maxB,e._points._maxC],n=[e._points._maxA,e._points._minB,e._points._maxC];b=[X.matrix.multiplyByVector(e._transform._matrix,b[0],b[1],b[2]),

app/styles/sliceviewer.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@
1919
.selector {
2020
width: auto !important;
2121
}
22+
23+
24+
.progress-bar-horizontal {
25+
display: none !important;;
26+
}

0 commit comments

Comments
 (0)