Skip to content

Commit

Permalink
don't overwrite alpha channel when setting selection
Browse files Browse the repository at this point in the history
  • Loading branch information
biasmv committed Jul 7, 2015
1 parent 9756bd8 commit d874a21
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion select.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ viewer.options('selectionColor', '#f00');

pv.io.fetchPdb('/pdbs/1crn.pdb', function(s) {
viewer.on('viewerReady', function() {
var go = viewer.lineTrace('crambin', s, { showRelated: '1'});
var go = viewer.cartoon('crambin', s, { showRelated: '1'});
go.setSelection(go.select({rnumRange : [15,20]}));
viewer.autoZoom();
});
Expand Down
20 changes: 20 additions & 0 deletions src/geom.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,33 @@ var buildRotation = (function() {
;
})();

// linearly interpolates the array of values and returns it as an Float32Array
function interpolateScalars(values, num) {
var out = new Float32Array(num*(values.length-1) + 1);
var index = 0;
var bf = 0.0, af = 0.0;
var delta = 1/num;
for (var i = 0; i < values.length-1; ++i) {
bf = values[i];
af = values[i + 1];
for (var j = 0; j < num; ++j) {
var t = delta * j;
out[index+0] = bf*(1-t)+af*t;
index+=1;
}
}
out[index+0] = af;
return out;
}

return {
signedAngle : signedAngle,
axisRotation : axisRotation,
ortho : ortho,
diagonalizer : diagonalizer,
catmullRomSpline : catmullRomSpline,
cubicHermiteInterpolate : cubicHermiteInterpolate,
interpolateScalars : interpolateScalars,
catmullRomSplineNumPoints : catmullRomSplineNumPoints,
Sphere : Sphere,
buildRotation : buildRotation
Expand Down
18 changes: 9 additions & 9 deletions src/gfx/vert-assoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// DEALINGS IN THE SOFTWARE.

define(
['../color'], function(color) {
['../color', '../geom'], function(color, geom) {

"use strict";

Expand Down Expand Up @@ -226,32 +226,32 @@ TraceVertexAssoc.prototype = {
},

setSelection : function(view) {
var colorData = [];
var selData = [];
var i, j;
var traces = this._structure.backboneTraces();
for (i = 0; i < traces.length; ++i) {
// get current residue colors
var data = this._perResidueColors[i];
var data = new Float32Array(this._perResidueColors[i].length);
var index = 0;
var trace = traces[i];
for (j = 0; j < trace.length(); ++j) {
var selected = view.containsResidue(trace.residueAt(j)) ? 1.0 : 0.0;
data[index + 3] = selected;
index+=4;
data[index] = selected;
index+=1;
}
if (this._interpolation > 1) {
colorData.push(color.interpolateColor(data, this._interpolation));
selData.push(geom.interpolateScalars(data, this._interpolation));
} else {
colorData.push(data);
selData.push(data);
}
}

// store the color in the actual interleaved vertex array.
for (i = 0; i < this._assocs.length; ++i) {
var assoc = this._assocs[i];
var ai = assoc.slice;
var newColors = colorData[assoc.traceIndex];
var a = newColors[ai*4+3];
var sel = selData[assoc.traceIndex];
var a = sel[ai];
var va = assoc.vertexArray;
for (j = assoc.vertStart ; j < assoc.vertEnd; ++j) {
va.setSelected(j, a);
Expand Down

0 comments on commit d874a21

Please sign in to comment.