From 00b1e6a9bed04172ad84bdd810f1bd999e8fa0eb Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Mon, 12 Mar 2012 15:02:07 -0700 Subject: bug fixes for spline interpolation AND Laplacian smoothing for denoising AND code cleanup (removing blocks of commented code) --- js/lib/geom/brush-stroke.js | 245 +++++++++++++++----------------------------- 1 file changed, 81 insertions(+), 164 deletions(-) (limited to 'js/lib') diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index a92657a4..595a6a63 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js @@ -32,7 +32,7 @@ var BrushStroke = function GLBrushStroke() { //stroke information this._strokeWidth = 0.0; this._strokeColor = [0.4, 0.4, 0.4, 1.0]; - this._secondStrokeColor = this._strokeColor; + this._secondStrokeColor = [1, 0.4, 0.4, 1.0]; this._strokeHardness = 100; this._strokeMaterial = null; this._strokeStyle = "Solid"; @@ -44,6 +44,12 @@ var BrushStroke = function GLBrushStroke() { //smaller value means more samples for the path this._WETNESS_FACTOR = 0.25; + //threshold that tells us whether two samples are too far apart + this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5; + + //threshold that tells us whether two samples are too close + this._MIN_SAMPLE_DISTANCE_THRESHOLD = 2; + //prevent extremely long paths that can take a long time to render this._MAX_ALLOWED_SAMPLES = 500; @@ -119,7 +125,7 @@ var BrushStroke = function GLBrushStroke() { //add the point only if it is some epsilon away from the previous point var numPoints = this._Points.length; if (numPoints>0) { - var threshold = 2;//this._WETNESS_FACTOR*this._strokeWidth; + var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD;//this._WETNESS_FACTOR*this._strokeWidth; var prevPt = this._Points[numPoints-1]; var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]); @@ -276,13 +282,16 @@ var BrushStroke = function GLBrushStroke() { } } } + //todo 4-point subdivision iterations over continuous regions of 'long' segments // look at http://www.gvu.gatech.edu/~jarek/Split&Tweak/ for formula //**** add samples to the long sections of the path --- Catmull-Rom spline interpolation if (this._strokeDoSmoothing && numPoints>1) { var numInsertedPoints = 0; - var threshold = 5;//0.25*this._strokeWidth; //this determines whether a segment between two sample is too long + var newPoints = []; + var threshold = this._MAX_SAMPLE_DISTANCE_THRESHOLD;//this determines whether a segment between two sample is long enough to warrant checking for angle var prevPt = this._Points[0]; + newPoints.push(this._Points[0]); for (var i=1;i0) { alphaVal = 1.0 - distFromOpaqueRegion/maxTransparentRegionHalfWidth; + alphaVal *= 1.0/ctx.lineWidth; //factor that accounts for lineWidth !== 1 } ctx.save(); - ctx.lineWidth=this._strokeWidth/10;//todo figure out the correct formula for the line width - if (ctx.lineWidth<2) - ctx.lineWidth=2; - if (t===numTraces-1){ - ctx.lineWidth = 1; - } - ctx.lineJoin="bevel"; - ctx.lineCap="butt"; - ctx.globalAlpha = this._strokeColor[3]; - - //if (t