Skip to content

Commit

Permalink
ADD: initial support for picking of volume data
Browse files Browse the repository at this point in the history
  • Loading branch information
arose committed Aug 13, 2015
1 parent 55b7d52 commit 4fbcc5c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 13 deletions.
9 changes: 8 additions & 1 deletion js/ngl/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,14 @@ NGL.Examples = {

stage.loadFile( "data://3pqr.ccp4.gz", function( o ){

o.addRepresentation( "surface", { wireframe: true } );
o.addRepresentation( "surface", {
wireframe: true,
visible: false
} );
o.addRepresentation( "dot", {
dotType: "sphere",
radius: 0.3
} );
o.centerView();

} );
Expand Down
6 changes: 6 additions & 0 deletions js/ngl/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ NGL.ToolbarWidget = function( stage ){
d.bond.atom1.qualifiedName() + " - " + d.bond.atom2.qualifiedName() +
" (" + d.bond.atom1.residue.chain.model.structure.name + ")";

}else if( d.volume ){

msg = "Picked volume: " +
d.volume.value.toPrecision( 3 ) +
" (" + d.volume.volume.name + ")";

}else{

msg = "Nothing to pick";
Expand Down
2 changes: 1 addition & 1 deletion js/ngl/representation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5427,7 +5427,7 @@ NGL.DotRepresentation.prototype = NGL.createObject(
this.surface.getDataPosition(),
this.surface.getDataColor( this.getColorParams() ),
this.surface.getDataSize( this.radius, this.scale ),
undefined,
this.surface.getPickingDataColor( this.getColorParams() ),
{
sphereDetail: this.sphereDetail,
transparent: this.transparent,
Expand Down
20 changes: 19 additions & 1 deletion js/ngl/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ NGL.Stage = function( eid ){

atomPicked: new SIGNALS.Signal(),
bondPicked: new SIGNALS.Signal(),
volumePicked: new SIGNALS.Signal(),
nothingPicked: new SIGNALS.Signal(),
onPicking: new SIGNALS.Signal(),

Expand Down Expand Up @@ -534,6 +535,7 @@ NGL.PickingControls = function( viewer, stage ){

var pickedAtom = undefined;
var pickedBond = undefined;
var pickedVolume = undefined;

var picked = NGL.GidPool.getByGid( gid );

Expand All @@ -545,11 +547,17 @@ NGL.PickingControls = function( viewer, stage ){

pickedBond = picked;

}else if( picked && picked.volume instanceof NGL.Volume ){

pickedVolume = picked;

}

//

if( ( pickedAtom || pickedBond ) && e.which === NGL.MiddleMouseButton ){
if( ( pickedAtom || pickedBond || pickedVolume ) &&
e.which === NGL.MiddleMouseButton
){

if( pickedAtom ){

Expand All @@ -561,6 +569,10 @@ NGL.PickingControls = function( viewer, stage ){
.addVectors( pickedBond.atom1, pickedBond.atom2 )
.multiplyScalar( 0.5 );

}else if( pickedVolume ){

position.copy( pickedVolume );

}

if( instance ){
Expand All @@ -583,6 +595,10 @@ NGL.PickingControls = function( viewer, stage ){

stage.signals.bondPicked.dispatch( pickedBond );

}else if( pickedVolume ){

stage.signals.volumePicked.dispatch( pickedVolume );

}else{

stage.signals.nothingPicked.dispatch();
Expand All @@ -593,6 +609,7 @@ NGL.PickingControls = function( viewer, stage ){

"atom": pickedAtom,
"bond": pickedBond,
"volume": pickedVolume,
"instance": instance

} );
Expand All @@ -603,6 +620,7 @@ NGL.PickingControls = function( viewer, stage ){

NGL.log( "picked atom", pickedAtom );
NGL.log( "picked bond", pickedBond );
NGL.log( "picked volume", pickedVolume );

}

Expand Down
52 changes: 44 additions & 8 deletions js/ngl/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ NGL.GidPool = {

},

updateObject: function( object ){
updateObject: function( object, silent ){

var idx = NGL.GidPool.objectList.indexOf( object );

Expand All @@ -447,7 +447,11 @@ NGL.GidPool = {

}else{

NGL.warn( "NGL.GidPool.updateObject: object not found." );
if( !silent ){

NGL.warn( "NGL.GidPool.updateObject: object not found." );

}

}

Expand All @@ -467,6 +471,10 @@ NGL.GidPool = {

count = object.bondCount;

}else if( object instanceof NGL.Volume ){

count = object.__data.length;

}

return count;
Expand Down Expand Up @@ -527,7 +535,7 @@ NGL.GidPool = {

var entity;

NGL.GidPool.objectList.forEach( function( o ){
NGL.GidPool.objectList.forEach( function( o, i ){

if( o instanceof NGL.Structure ){

Expand All @@ -549,6 +557,25 @@ NGL.GidPool = {

} );

}else if( o instanceof NGL.Volume ){

var range = NGL.GidPool.rangeList[ i ];

if( gid >= range[ 0 ] && gid < range[ 1 ] ){

var offset = gid - range[ 0 ];

entity = {
volume: o,
index: offset,
value: o.data[ offset ],
x: o.dataPosition[ offset * 3 ],
y: o.dataPosition[ offset * 3 + 1 ],
z: o.dataPosition[ offset * 3 + 2 ],
};

}

}

} );
Expand Down Expand Up @@ -797,6 +824,7 @@ NGL.ColorMaker = function( params ){

this.structure = p.structure;
this.bondSet = p.bondSet;
this.volume = p.volume;
this.surface = p.surface;

};
Expand Down Expand Up @@ -864,15 +892,15 @@ NGL.ColorMaker.prototype = {

},

valueColor: function( v ){
volumeColor: function( i ){

return 0xFFFFFF;

},

valueColorToArray: function( v, array, offset ){
volumeColorToArray: function( i, array, offset ){

var c = this.valueColor( v );
var c = this.volumeColor( i );

if( array === undefined ) array = [];
if( offset === undefined ) offset = 0;
Expand All @@ -894,9 +922,9 @@ NGL.ValueColorMaker = function( params ){

var valueScale = this.getScale();

this.valueColor = function( v ){
this.volumeColor = function( i ){

return valueScale( v );
return valueScale( this.volume.data[ i ] );

};

Expand All @@ -923,6 +951,12 @@ NGL.PickingColorMaker = function( params ){

};

this.volumeColor = function( i ){

return NGL.GidPool.getGid( this.volume, i );

};

};

NGL.PickingColorMaker.prototype = NGL.ColorMaker.prototype;
Expand Down Expand Up @@ -2660,6 +2694,8 @@ NGL.Structure.prototype = {
this.center = new THREE.Vector3();
this.boundingBox = new THREE.Box3();

NGL.GidPool.updateObject( this, true );

},

setDefaultAssembly: function( value ){
Expand Down
19 changes: 17 additions & 2 deletions js/ngl/surface.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ NGL.Volume = function( name, path, data, nx, ny, nz ){

this.setData( data, nx, ny, nz );

NGL.GidPool.addObject( this );

};

NGL.Volume.prototype = {
Expand Down Expand Up @@ -294,6 +296,8 @@ NGL.Volume.prototype = {

if( this.worker ) this.worker.terminate();

NGL.GidPool.updateObject( this, true );

},

setMatrix: function( matrix ){
Expand Down Expand Up @@ -646,26 +650,35 @@ NGL.Volume.prototype = {
getDataColor: function( params ){

var p = params || {};
p.volume = this;
p.scale = p.scale || 'Spectral';
p.mode = p.mode || 'lch';
p.domain = p.domain || [ this.getDataMin(), this.getDataMax() ];

var colorMaker = NGL.ColorMakerRegistry.getScheme( p );

var n = this.dataPosition.length / 3;
var data = this.data;
var array = new Float32Array( n * 3 );

for( var i = 0; i < n; ++i ){

colorMaker.valueColorToArray( data[ i ], array, i * 3 );
colorMaker.volumeColorToArray( i, array, i * 3 );

}

return array;

},

getPickingDataColor: function( params ){

var p = Object.assign( params || {} );
p.scheme = "picking";

return this.getDataColor( p );

},

getDataSize: function( size, scale ){

var n = this.dataPosition.length / 3;
Expand Down Expand Up @@ -907,6 +920,8 @@ NGL.Volume.prototype = {

if( this.worker ) this.worker.terminate();

NGL.GidPool.removeObject( this );

}

};
Expand Down

0 comments on commit 4fbcc5c

Please sign in to comment.