From 40f3fc5feae866c99af818a886e8bf9d8cf2b8dd Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Tue, 6 Mar 2012 17:23:58 -0800 Subject: merge Valerio's architecture changes into pen tool --- js/lib/geom/sub-path.js | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'js/lib/geom') diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js index ab54d1e9..0a65511b 100755 --- a/js/lib/geom/sub-path.js +++ b/js/lib/geom/sub-path.js @@ -584,6 +584,90 @@ GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) { return selAnchorIndex; }; +GLSubpath.prototype.isWithinBBox =function(x,y,z){ + if (this._BBoxMin[0]>x || this._BBoxMin[1]>y || this._BBoxMin[2]>z){ + return false; + } + if (this._BBoxMax[0]=0 && this._selectedAnchorIndex=0 && selAnchorIndex === -1) { + var distSq = this._Anchors[this._selectedAnchorIndex].getPrevDistanceSq(pickX, pickY, pickZ); + if (distSq < minDistance && distSq < radSq){ + selAnchorIndex = this._selectedAnchorIndex; + minDistance = distSq; + } else { + //check the next for this anchor point + distSq = this._Anchors[this._selectedAnchorIndex].getNextDistanceSq(pickX, pickY, pickZ); + if (distSq0) { - var threshold = this._WETNESS_FACTOR*this._strokeWidth; + var threshold = 1;//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]); @@ -173,6 +175,14 @@ var BrushStroke = function GLBrushStroke() { this._strokeColor = c; }; + this.setSecondStrokeColor = function(c){ + this._secondStrokeColor=c; + } + + this.setStrokeHardness = function(h){ + this._strokeHardness=h; + } + this.getStrokeStyle = function () { return this._strokeStyle; }; @@ -219,7 +229,8 @@ var BrushStroke = function GLBrushStroke() { var numPoints = this._Points.length; //**** add samples to the path if needed...linear interpolation for now - if (numPoints>1) { + //if (numPoints>1) { + if (0){ var threshold = this._WETNESS_FACTOR*this._strokeWidth; var prevPt = this._Points[0]; var prevIndex = 0; @@ -250,6 +261,44 @@ var BrushStroke = function GLBrushStroke() { } } } + //**** add samples to the long sections of the path --- Catmull-Rom spline interpolation + if (numPoints>1) { + var numInsertedPoints = 0; + var threshold = 5;//0.25*this._strokeWidth; //this determines whether a segment between two sample is too long + var prevPt = this._Points[0]; + for (var i=1;ithreshold){ + //build the control polygon for the Catmull-Rom spline (prev. 2 points and next 2 points) + var prev = (i===1) ? i-1 : i-2; + var next = (i===numPoints-1) ? i : i+1; + var ctrlPts = [this._Points[prev], this._Points[i-1], this._Points[i], this._Points[next]]; + //insert points along the prev. to current point + var numNewPoints = Math.floor(distance/threshold); + for (var j=0;j this._MAX_ALLOWED_SAMPLES){ + console.log("leaving the resampling because numPoints is greater than limit:"+this._MAX_ALLOWED_SAMPLES); + break; + } + } + console.log("Inserted "+numInsertedPoints+" additional CatmullRom points"); + } // *** compute the bounding box ********* this._BBoxMin = [Infinity, Infinity, Infinity]; @@ -412,7 +461,7 @@ var BrushStroke = function GLBrushStroke() { } */ - + /* var R2 = this._strokeWidth; var R = R2*0.5; var hardness = 0; //for a pencil, this is always 1 //TODO get hardness parameter from user interface @@ -440,6 +489,109 @@ var BrushStroke = function GLBrushStroke() { //ctx.globalCompositeOperation = 'source-in'; //ctx.rect(x-R, y-R, R2, R2); } + */ + + /* + //build the stamp for the brush stroke + //todo get this directly from the UI + var t=0; + var numTraces = this._strokeWidth; + var halfNumTraces = numTraces/2; + var startPos = [-this._strokeWidth/2,0]; + var brushStamp = []; + + //build an angled (calligraphic) brush stamp + var deltaDisplacement = [1,1];//[this._strokeWidth/numTraces, 0]; //a horizontal line brush + for (t=0;t1) { + 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 prevPt = this._Points[0]; @@ -507,35 +512,6 @@ var BrushStroke = function GLBrushStroke() { brushStamp.push(brushPt); } - - //make a circular brush stamp - brushStamp=[]; - numTraces = this._strokeWidth*Math.PI; //figure out how to - var radius = this._strokeWidth/2; - for (t=0;t0) { - var threshold = 1;//this._WETNESS_FACTOR*this._strokeWidth; + var threshold = 2;//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]); @@ -188,6 +190,14 @@ var BrushStroke = function GLBrushStroke() { this._strokeDoSmoothing = s; } + this.setStrokeUseCalligraphic = function(c){ + this._strokeUseCalligraphic = c; + } + + this.setStrokeAngle = function(a){ + this._strokeAngle = a; + } + this.getStrokeStyle = function () { return this._strokeStyle; }; @@ -266,6 +276,8 @@ 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; @@ -496,75 +508,84 @@ var BrushStroke = function GLBrushStroke() { } */ - /* - //build the stamp for the brush stroke - //todo get this directly from the UI - var t=0; - var numTraces = this._strokeWidth; - var halfNumTraces = numTraces/2; - var startPos = [-this._strokeWidth/2,0]; - var brushStamp = []; - - //build an angled (calligraphic) brush stamp - var deltaDisplacement = [1,1];//[this._strokeWidth/numTraces, 0]; //a horizontal line brush - for (t=0;t0) { + alphaVal = 1.0 - distFromOpaqueRegion/maxTransparentRegionHalfWidth; + } + + 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 */ var MaterialsModel = require("js/models/materials-model").MaterialsModel; +var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; +var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial; +var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial; +var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial; +var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial; +var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial; +var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial; +var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; +var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; +var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial; +var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; +var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; +var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; +var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial; +var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial; +var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial; +var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMaterial; +var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial; +var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial; +var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial; + /////////////////////////////////////////////////////////////////////// // Class GLGeomObj // Super class for all geometry classes @@ -235,7 +256,26 @@ var GeomObj = function GLGeomObj() { var materialType = this.getPropertyFromString( "material: ", importStr ); switch (materialType) { - case "flat": mat = new FlatMaterial(); break; + case "flat": mat = new FlatMaterial(); break; + case "radialGradient": mat = new RadialGradientMaterial(); break; + case "linearGradient": mat = new LinearGradientMaterial(); break; + case "bumpMetal": mat = new BumpMetalMaterial(); break; + case "uber": mat = new UberMaterial(); break; + case "plasma": mat = new PlasmaMaterial(); break; + case "deform": mat = new DeformMaterial(); break; + case "water": mat = new WaterMaterial(); break; + case "tunnel": mat = new TunnelMaterial(); break; + case "reliefTunnel": mat = new ReliefTunnelMaterial(); break; + case "squareTunnel": mat = new SquareTunnelMaterial(); break; + case "twist": mat = new TwiseMaterial(); break; + case "fly": mat = new FlyMaterial(); break; + case "julia": mat = new JuliaMaterial(); break; + case "mandel": mat = new MandelMaterial(); break; + case "star": mat = new StarMaterial(); break; + case "zinvert": mat = new ZInvertMaterial(); break; + case "keleidoscope": mat = new KeleidoscopeMaterial(); break; + case "radialBlur": mat = new RadialBlurMaterial(); break; + case "pulse": mat = new PulseMaterial(); break; default: console.log( "material type: " + materialType + " is not supported" ); diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index f91e830c..370bb257 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js @@ -79,6 +79,8 @@ var Rectangle = function GLRectangle() { } else { this._fillMaterial = MaterialsModel.exportFlatMaterial(); } + + this.exportMaterials(); }; /////////////////////////////////////////////////////////////////////// @@ -264,8 +266,9 @@ var Rectangle = function GLRectangle() { console.log( "object material not found in library: " + fillMaterialName ); fillMat = MaterialsModel.exportFlatMaterial(); } - this._fillMaterial = fillMat; + + this.importMaterials( importStr ); }; this.buildBuffers = function() { -- cgit v1.2.3 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/geom') 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