SkScalar SkPerlinNoiseShader::PerlinNoiseShaderContext::noise2D( int channel, const StitchData& stitchData, const SkPoint& noiseVector) const { struct Noise { int noisePositionIntegerValue; int nextNoisePositionIntegerValue; SkScalar noisePositionFractionValue; Noise(SkScalar component) { SkScalar position = component + kPerlinNoise; noisePositionIntegerValue = SkScalarFloorToInt(position); noisePositionFractionValue = position - SkIntToScalar(noisePositionIntegerValue); nextNoisePositionIntegerValue = noisePositionIntegerValue + 1; } }; Noise noiseX(noiseVector.x()); Noise noiseY(noiseVector.y()); SkScalar u, v; const SkPerlinNoiseShader& perlinNoiseShader = static_cast<const SkPerlinNoiseShader&>(fShader); // If stitching, adjust lattice points accordingly. if (perlinNoiseShader.fStitchTiles) { noiseX.noisePositionIntegerValue = checkNoise(noiseX.noisePositionIntegerValue, stitchData.fWrapX, stitchData.fWidth); noiseY.noisePositionIntegerValue = checkNoise(noiseY.noisePositionIntegerValue, stitchData.fWrapY, stitchData.fHeight); noiseX.nextNoisePositionIntegerValue = checkNoise(noiseX.nextNoisePositionIntegerValue, stitchData.fWrapX, stitchData.fWidth); noiseY.nextNoisePositionIntegerValue = checkNoise(noiseY.nextNoisePositionIntegerValue, stitchData.fWrapY, stitchData.fHeight); } noiseX.noisePositionIntegerValue &= kBlockMask; noiseY.noisePositionIntegerValue &= kBlockMask; noiseX.nextNoisePositionIntegerValue &= kBlockMask; noiseY.nextNoisePositionIntegerValue &= kBlockMask; int i = fPaintingData->fLatticeSelector[noiseX.noisePositionIntegerValue]; int j = fPaintingData->fLatticeSelector[noiseX.nextNoisePositionIntegerValue]; int b00 = (i + noiseY.noisePositionIntegerValue) & kBlockMask; int b10 = (j + noiseY.noisePositionIntegerValue) & kBlockMask; int b01 = (i + noiseY.nextNoisePositionIntegerValue) & kBlockMask; int b11 = (j + noiseY.nextNoisePositionIntegerValue) & kBlockMask; SkScalar sx = smoothCurve(noiseX.noisePositionFractionValue); SkScalar sy = smoothCurve(noiseY.noisePositionFractionValue); // This is taken 1:1 from SVG spec: http://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement SkPoint fractionValue = SkPoint::Make(noiseX.noisePositionFractionValue, noiseY.noisePositionFractionValue); // Offset (0,0) u = fPaintingData->fGradient[channel][b00].dot(fractionValue); fractionValue.fX -= SK_Scalar1; // Offset (-1,0) v = fPaintingData->fGradient[channel][b10].dot(fractionValue); SkScalar a = SkScalarInterp(u, v, sx); fractionValue.fY -= SK_Scalar1; // Offset (-1,-1) v = fPaintingData->fGradient[channel][b11].dot(fractionValue); fractionValue.fX = noiseX.noisePositionFractionValue; // Offset (0,-1) u = fPaintingData->fGradient[channel][b01].dot(fractionValue); SkScalar b = SkScalarInterp(u, v, sx); return SkScalarInterp(a, b, sy); }
//------------------------------------------------------------------------------ f32 biLinearInterpolationSmooth( const f32 x0y0, const f32 x1y0, const f32 x0y1, const f32 x1y1, const f32 x, const f32 y) { const f32 tx = smoothCurve(x); const f32 ty = smoothCurve(y); const f32 u = linearInterpolation(x0y0,x1y0, tx); const f32 v = linearInterpolation(x0y1,x1y1, tx); return linearInterpolation(u,v,ty); }
float FETurbulence::noise2D(int channel, PaintingData& paintingData, const FloatPoint& noiseVector) { struct Noise { int noisePositionIntegerValue; float noisePositionFractionValue; Noise(float component) { float position = component + s_perlinNoise; noisePositionIntegerValue = static_cast<int>(position); noisePositionFractionValue = position - noisePositionIntegerValue; } }; Noise noiseX(noiseVector.x()); Noise noiseY(noiseVector.y()); float* q; float sx, sy, a, b, u, v; // If stitching, adjust lattice points accordingly. if (m_stitchTiles) { checkNoise(noiseX.noisePositionIntegerValue, paintingData.wrapX, paintingData.width); checkNoise(noiseY.noisePositionIntegerValue, paintingData.wrapY, paintingData.height); } noiseX.noisePositionIntegerValue &= s_blockMask; noiseY.noisePositionIntegerValue &= s_blockMask; int latticeIndex = paintingData.latticeSelector[noiseX.noisePositionIntegerValue]; int nextLatticeIndex = paintingData.latticeSelector[(noiseX.noisePositionIntegerValue + 1) & s_blockMask]; sx = smoothCurve(noiseX.noisePositionFractionValue); sy = smoothCurve(noiseY.noisePositionFractionValue); // This is taken 1:1 from SVG spec: http://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement. int temp = paintingData.latticeSelector[latticeIndex + noiseY.noisePositionIntegerValue]; q = paintingData.gradient[channel][temp]; u = noiseX.noisePositionFractionValue * q[0] + noiseY.noisePositionFractionValue * q[1]; temp = paintingData.latticeSelector[nextLatticeIndex + noiseY.noisePositionIntegerValue]; q = paintingData.gradient[channel][temp]; v = (noiseX.noisePositionFractionValue - 1) * q[0] + noiseY.noisePositionFractionValue * q[1]; a = linearInterpolation(sx, u, v); temp = paintingData.latticeSelector[latticeIndex + noiseY.noisePositionIntegerValue + 1]; q = paintingData.gradient[channel][temp]; u = noiseX.noisePositionFractionValue * q[0] + (noiseY.noisePositionFractionValue - 1) * q[1]; temp = paintingData.latticeSelector[nextLatticeIndex + noiseY.noisePositionIntegerValue + 1]; q = paintingData.gradient[channel][temp]; v = (noiseX.noisePositionFractionValue - 1) * q[0] + (noiseY.noisePositionFractionValue - 1) * q[1]; b = linearInterpolation(sx, u, v); return linearInterpolation(sy, a, b); }
// ********** Functions ********** void CurveInput::main() { boolean choice = chooseCurve(); loadCurve(choice); smoothCurve(); sendTimesAndTemps(); }
void BezierCurve::createCurve(QList<QPointF>& pointList, QList<qreal>& pressureList ) { int p = 0; int n = pointList.size(); // generate the Bezier (cubic) curve from the simplified path and mouse pressure // first, empty everything while (c1.size()>0) c1.removeAt(0); while (c2.size()>0) c2.removeAt(0); while (vertex.size()>0) vertex.removeAt(0); while (selected.size()>0) selected.removeAt(0); while (pressure.size()>0) pressure.removeAt(0); setOrigin( pointList.at(0) ); selected.append(false); pressure.append(pressureList.at(0)); for(p=1; p<n; p++) { c1.append(pointList.at(p)); c2.append(pointList.at(p)); vertex.append(pointList.at(p)); pressure.append(pressureList.at(p)); selected.append(false); } smoothCurve(); //colourNumber = 0; feather = 0; }
void xray_jit_levelsetseg_calculate_ndim(t_xray_jit_levelsetseg *obj, long dimcount, long *dim, long planecount, t_jit_matrix_info *in1_minfo, char *bip1, t_jit_matrix_info *phi_minfo, char *phi_bp, t_jit_matrix_info *out1_minfo, char *bop1, t_jit_matrix_info *out2_minfo, char *bop2) { long x, y; uchar *ip1, *op2; char *phi; long height,width; long inrowspan, phi_rowspan; long out2rowspan; t_RegionStats *inside, *outside; float *fop1; if (dimcount<1) return; //safety switch(dimcount) { case 1: dim[1]=1; case 2: width = in1_minfo->dim[0]; height = in1_minfo->dim[1]; inrowspan = in1_minfo->dimstride[1]; phi_rowspan = phi_minfo->dimstride[1]; out2rowspan = out2_minfo->dimstride[1]; if (out2_minfo->type==_jit_sym_char) { inside = obj->inside; outside = obj->outside; if( !(obj->evolve) ) { DLLfreeListNodes(obj->L_in); DLLfreeListNodes(obj->L_out); clearRegionDistribution(inside); clearRegionDistribution(outside); for(x=0; x < obj->pointcount/2; x++) { createCircle(obj, obj->point[2*x], obj->point[2*x+1], obj->L_in, obj->L_out, phi_bp, phi_minfo); } for(y=0; y < in1_minfo->dim[1]; y++) { ip1 = (uchar *)(bip1 + y*inrowspan); phi = (phi_bp + y*phi_rowspan); for(x=0; x < in1_minfo->dim[0]; x++) { if(phi[x] >= L_OUT) { outside->sum += (double)ip1[x]; outside->sumSq += (double)ip1[x]*(double)ip1[x]; outside->count++; } else { inside->sum += (double)ip1[x]; inside->sumSq += (double)ip1[x]*(double)ip1[x]; inside->count++; } } } calcRegionStats(inside); calcRegionStats(outside); } for(y=0; y < obj->cycles; y++) { for(x=0; x < obj->Na; x++) { evolveCurve(obj->L_in, obj->L_out, inside, outside, bip1, in1_minfo, phi_bp, phi_minfo); adjustRegionStats(inside, outside); } for(x=0; x < obj->Ns; x++) { smoothCurve(obj->L_in, obj->L_out, inside, outside, bip1, in1_minfo, phi_bp, phi_minfo, obj->Ng, obj->gaussKernel); adjustRegionStats(inside, outside); } if( stoppingConditions(obj->L_in, obj->L_out, inside, outside, bip1, in1_minfo, phi_bp, phi_minfo) ) { break; } } for(y=0; y < out2_minfo->dim[1]; y++) { ip1 = (uchar *)(phi_bp + y*(phi_minfo->dimstride[1])); op2 = (uchar *)(bop2 + y*(out2_minfo->dimstride[1])); for(x=0; x < out2_minfo->dim[0]; x++) { op2[x] = ip1[x]; } } for(y=0; y < out2_minfo->dim[1]; y++) { ip1 = (uchar *)(bip1 + y*(in1_minfo->dimstride[1])); fop1 = (float *)(bop1 + y*(out1_minfo->dimstride[1])); for(x=0; x < out2_minfo->dim[0]; x++) { //fop1[x] = calcProb(inside, outside, ip1[x]); } } } break; default: ; } }