Skip to content

Commit

Permalink
console messages, streamline outline
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoes committed Jul 26, 2024
1 parent 55ee641 commit f2206bb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 93 deletions.
27 changes: 8 additions & 19 deletions src/VolumeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class VolumeData {
str = new TextDecoder("utf-8").decode(inflate(str));
}
} catch (err) {
console.log(err);
console.error(err);
}
}

Expand Down Expand Up @@ -92,7 +92,6 @@ export class VolumeData {
total += diff * diff; //variance is ave of squared difference with mean
}
var variance = total / this.data.length;
//console.log("Computed variance: "+variance);
//now normalize
for (let i = 0, n = this.data.length; i < n; i++) {
this.data[i] = (this.data[i] - mean) / variance;
Expand Down Expand Up @@ -180,7 +179,7 @@ export class VolumeData {
var natoms = atomicData.length;

if (natoms == 0) {
console.log("No good formating of CHG or CHGCAR file, not atomic information provided in the file.");
console.warn("No good formating of CHG or CHGCAR file, not atomic information provided in the file.");
this.data = [];
return;
}
Expand Down Expand Up @@ -259,15 +258,6 @@ export class VolumeData {
}

this.data = preConvertedData;

//console.log(xVec);
//console.log(yVec);
//console.log(zVec);
//console.log(this.unit);
//console.log(this.origin);
//console.log(this.matrix);
//console.log(this.data);

};

// parse dx data - does not support all features of the file format
Expand All @@ -291,32 +281,32 @@ export class VolumeData {
else if ((m = redelta.exec(line))) {
var xunit = parseFloat(m[1]);
if (parseFloat(m[2]) != 0 || parseFloat(m[3]) != 0) {
console.log("Non-orthogonal delta matrix not currently supported in dx format");
console.warn("Non-orthogonal delta matrix not currently supported in dx format");
}
i += 1;
line = lines[i];
m = redelta.exec(line);
if (m == null) {
console.log("Parse error in dx delta matrix");
console.error("Parse error in dx delta matrix");
return;
}

var yunit = parseFloat(m[2]);
if (parseFloat(m[1]) != 0 || parseFloat(m[3]) != 0) {
console.log("Non-orthogonal delta matrix not currently supported in dx format");
console.warn("Non-orthogonal delta matrix not currently supported in dx format");
}

i += 1;
line = lines[i];
m = redelta.exec(line);
if (m == null) {
console.log("Parse error in dx delta matrix");
console.error("Parse error in dx delta matrix");
return;
}

var zunit = parseFloat(m[3]);
if (parseFloat(m[1]) != 0 || parseFloat(m[2]) != 0) {
console.log("Non-orthogonal delta matrix not currently supported in dx format");
console.warn("Non-orthogonal delta matrix not currently supported in dx format");
}
this.unit = new Vector3(xunit, yunit, zunit);
}
Expand All @@ -331,7 +321,7 @@ export class VolumeData {
}
i += 1;
if (!this.size || !this.origin || !this.unit || !this.size) {
console.log("Error parsing dx format");
console.error("Error parsing dx format");
return;
}
var raw = lines.splice(i).join(" ");
Expand Down Expand Up @@ -484,7 +474,6 @@ export class VolumeData {

// 56 NLABL Number of labels being used
// 57-256 LABEL(20,10) 10 80 character text labels (ie. A4 format)
//console.log("Map has min,mean,average,rmsddv: "+header.DMIN+","+header.DMAX+","+header.DMEAN+","+header.ARMS);

//create transformation matrix, code mostly copied from ngl
var h = header;
Expand Down
123 changes: 55 additions & 68 deletions src/WebGL/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ export class Renderer {

this._canvas.id = parameters.id;

if(parameters.containerWidth == 0 || parameters.containerHeight == 0) {
if (parameters.containerWidth == 0 || parameters.containerHeight == 0) {
return; //start lost
}
this.initGL();
this.setDefaultGLState();

this.context = this._gl;
if(this.isWebGL1()) {
if (this.isWebGL1()) {
this._extInstanced = this._gl.getExtension("ANGLE_instanced_arrays");
} else { //no longer an extension, wrap
this._extInstanced = {
Expand Down Expand Up @@ -228,7 +228,7 @@ export class Renderer {
getCanvas() {
return this._canvas;
}

isLost() {
return this._gl == null || this._gl.isContextLost();
}
Expand All @@ -240,7 +240,7 @@ export class Renderer {
setClearColorHex(hex, alpha) {
this._clearColor.setHex(hex);
this._clearAlpha = alpha;
if(!this.isLost()) {
if (!this.isLost()) {
this._gl.clearColor(this._clearColor.r, this._clearColor.g, this._clearColor.b, this._clearAlpha);
}
}
Expand Down Expand Up @@ -273,7 +273,7 @@ export class Renderer {
this._viewportWidth = wid;
this._viewportHeight = hei;

if(!this.isLost()) {
if (!this.isLost()) {
this._gl.enable(this._gl.SCISSOR_TEST);
this._gl.scissor(wid * this.col, hei * this.row, wid, hei);
this._gl.viewport(wid * this.col, hei * this.row, wid, hei);
Expand Down Expand Up @@ -314,7 +314,7 @@ export class Renderer {
this._canvas.style.width = width + "px";
this._canvas.style.height = height + "px";

if(!this.isLost()) {
if (!this.isLost()) {
this._gl.viewport(0, 0, this._gl.drawingBufferWidth, this._gl.drawingBufferHeight);
}
}
Expand Down Expand Up @@ -440,7 +440,7 @@ export class Renderer {
// program
// Also sets appropriate uniform variables
program = this.setProgram(camera, lights, fog, material, object, this);
if(!program) return;
if (!program) return;

attributes = program.attributes;

Expand Down Expand Up @@ -616,7 +616,7 @@ export class Renderer {
camera.matrixWorldInverse
);

if(this.isLost()) {
if (this.isLost()) {
return;
}
// update WebGL objects
Expand Down Expand Up @@ -1264,7 +1264,7 @@ export class Renderer {
// Set up new program and compile shaders

program = this._gl.createProgram();
if(program == null) return null;
if (program == null) return null;

// set up precision
var precision = this._precision;
Expand All @@ -1290,8 +1290,8 @@ export class Renderer {
);
var glVertexShader = this.getShader("vertex", prefix_vertex + vertexShader);

if(glVertexShader != null) this._gl.attachShader(program, glVertexShader);
if(glFragmentShader != null) this._gl.attachShader(program, glFragmentShader);
if (glVertexShader != null) this._gl.attachShader(program, glVertexShader);
if (glFragmentShader != null) this._gl.attachShader(program, glFragmentShader);

this._gl.linkProgram(program);

Expand Down Expand Up @@ -1364,7 +1364,7 @@ export class Renderer {
this.initMaterial(material, lights, fog, object);
material.needsUpdate = false;
}
if( material.program == null) return null;
if (material.program == null) return null;

var refreshMaterial = false;

Expand Down Expand Up @@ -1967,69 +1967,56 @@ export class Renderer {
this.setMaterialFaces(material, reflected);

this.renderBuffer(camera, lights, fog, material, buffer, object);
if (this._outlineEnabled || material.outline) {

if ((this._outlineEnabled || material.outline) &&
!material.wireframe &&
material.shaderID !== "basic" &&
material.opacity !== 0.0) {
let outmat: any = this._outlineMaterial;
if (material.shaderID == "sphereimposter") {
this.renderBuffer(
camera,
lights,
fog,
this._outlineSphereImposterMaterial,
buffer,
object
);
outmat = this._outlineSphereImposterMaterial;
} else if (material.shaderID == "stickimposter") {
this.renderBuffer(
camera,
lights,
fog,
this._outlineStickImposterMaterial,
buffer,
object
);
} else if (
!material.wireframe &&
material.shaderID !== "basic" &&
material.opacity !== 0.0
) {
this.renderBuffer(
camera,
lights,
fog,
this._outlineMaterial,
buffer,
object
);
outmat = this._outlineStickImposterMaterial;
}

this.renderBuffer(
camera,
lights,
fog,
outmat,
buffer,
object
);
}
}
}
}

private renderSprites(scene, camera, inFront) {
// Reset state once regardless
// This should also fix cartoon render bug (after transparent surface
// render)

this._currentGeometryGroupHash = -1;
this._currentProgram = null;
this._currentCamera = null;
this._oldDepthWrite = -1;
this._oldDepthTest = -1;
this._oldDoubleSided = -1;
this._currentMaterialId = -1;
this._oldFlipSided = -1;
this._lightsNeedUpdate = true;

this.sprites.render(scene, camera, this._currentWidth, this._currentHeight, inFront);

// Reset state a
this._currentGeometryGroupHash = -1;
this._currentProgram = null;
this._currentCamera = null;
this._oldDepthWrite = -1;
this._oldDepthTest = -1;
this._oldDoubleSided = -1;
this._currentMaterialId = -1;
this._oldFlipSided = -1;
}
// Reset state once regardless
// This should also fix cartoon render bug (after transparent surface
// render)

this._currentGeometryGroupHash = -1;
this._currentProgram = null;
this._currentCamera = null;
this._oldDepthWrite = -1;
this._oldDepthTest = -1;
this._oldDoubleSided = -1;
this._currentMaterialId = -1;
this._oldFlipSided = -1;
this._lightsNeedUpdate = true;

this.sprites.render(scene, camera, this._currentWidth, this._currentHeight, inFront);

// Reset state a
this._currentGeometryGroupHash = -1;
this._currentProgram = null;
this._currentCamera = null;
this._oldDepthWrite = -1;
this._oldDepthTest = -1;
this._oldDoubleSided = -1;
this._currentMaterialId = -1;
this._oldFlipSided = -1;
}
}
12 changes: 6 additions & 6 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export function download(query, viewer, options, callback?) {
}
}
if (query.substring(0,5) == 'mmtf:') {
console.log('WARNING: MMTF now deprecated. Reverting to bcif.');
console.warn('WARNING: MMTF now deprecated. Reverting to bcif.');
query = 'bcif:' + query.slice(5);
}
if (query.substring(0, 5) === 'bcif:') {
Expand All @@ -437,7 +437,7 @@ export function download(query, viewer, options, callback?) {
viewer.zoomTo();
viewer.render();
resolve(m);
}, function () { console.log("fetch of " + uri + " failed."); });
}, function () { console.error("fetch of " + uri + " failed."); });
});
}
else {
Expand Down Expand Up @@ -493,14 +493,14 @@ export function download(query, viewer, options, callback?) {
pdbUri = options && options.pdbUri ? options.pdbUri : "https://files.rcsb.org/view/";
uri = pdbUri + query + ".pdb";
type = "pdb";
console.log("falling back to pdb format");
console.warn("falling back to pdb format");
get(uri).then(function (data) {
handler(data);
resolve(m);
}).catch(function (e) {
handler("");
resolve(m);
console.log("fetch of " + uri + " failed: " + e.statusText);
console.error("fetch of " + uri + " failed: " + e.statusText);
});
}); //an error msg has already been printed
}
Expand All @@ -511,7 +511,7 @@ export function download(query, viewer, options, callback?) {
}).catch(function (e) {
handler("");
resolve(m);
console.log("fetch of " + uri + " failed: " + e.statusText);
console.error("fetch of " + uri + " failed: " + e.statusText);
});
}
});
Expand Down Expand Up @@ -591,7 +591,7 @@ export function getColorFromStyle(atom, style): Color {
//actual color scheme provided
color = style.colorscheme[atom.elem];
} else {
console.log("Could not interpret colorscheme " + scheme);
console.warn("Could not interpret colorscheme " + scheme);
}
} else if (typeof style.colorfunc != "undefined") {
//this is a user provided function for turning an atom into a color
Expand Down

0 comments on commit f2206bb

Please sign in to comment.