override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { int tx = FlipHorizontal ? parms.Width - x - 1 : x; int ty = FlipVertical ? parms.Height - y - 1 : y; mp.Value[x, y] = InputMask[tx, ty]; } } return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { mp.Value[x, y] = mp.Value[x, y] * Gain + Bias; } } return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; int numTimesToRun = parms.Width >> 1; DAGMask outMask = InputMask.Clone();// DAGMask distMask = new DAGMask(parms.Width, parms.Height); int maxRange = 0; for (int i = 0; i < numTimesToRun; i++) { DAGMask smallerMask = new DAGMask(parms.Width, parms.Height); bool madeChange = contractSetValue(ref outMask, ref smallerMask, ref distMask, i); outMask = smallerMask.Clone(); if (madeChange) { maxRange = i; } else { break; } } //normalize our input now... for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { mp.Value[x, y] = distMask[x, y] / (float)maxRange; } } outMask = null; return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } setNoiseParms(); MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; for (int y = 0; y < parms.Height; y++) { for (int x = 0; x < parms.Width; x++) { float x0, y0; float x1, y1; float x2, y2; x0 = x + (12414.0f / 65536.0f); y0 = y + (65124.0f / 65536.0f); x1 = x + (26519.0f / 65536.0f); y1 = y + (18128.0f / 65536.0f); x2 = x + (53820.0f / 65536.0f); y2 = y + (11213.0f / 65536.0f); float xDistort = ((float)(mXDistort.getValue(x0, y0, 0) * Power)); float yDistort = ((float)(mYDistort.getValue(x1, y1, 0) * Power)); int kx = (int)BMathLib.Clamp(x + (int)(xDistort * parms.Width), 0, parms.Width - 1); int ky = (int)BMathLib.Clamp(y + (int)(yDistort * parms.Height), 0, parms.Height - 1); mp.Value[x, y] = InputMask[kx, ky]; } } return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } gatherInputAndParameters(parms); MaskParam mp = ((MaskParam)(connPoint.ParamType)); // mp.Value = InputMask.Clone(); DAGMask baseMask = InputMask.Clone(); DAGMask addMask = new DAGMask(parms.Width, parms.Height); DAGMask subMask = new DAGMask(parms.Width, parms.Height); //if we're doing multiscale erosion if (MultiscaleEnable) { //subtract multiscale mask from our base mask before doing erosion multiscaleDisplace(ref baseMask, ref subMask, ref addMask); } //CLM it actually looks better (less noisy) w/o this high fidelity step! calculateErosion(baseMask, baseMask.Width, baseMask.Height, ref subMask, ref addMask, 0); //calculate our mask 'channels' for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { baseMask[x, y] = baseMask[x, y] + addMask[x, y] - subMask[x, y]; } } //need to find which output this connection point is connected to... mp.Value = baseMask.Clone(); return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; if (ClampType == (int)eMethod.eScale) //scale between the values { float delta = MaxHeight - MinHeight; for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { mp.Value[x, y] = MinHeight + (InputMask[x, y] * delta); } } } else if (ClampType == (int)eMethod.eClamp) //actually clamp { for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { mp.Value[x, y] = BMathLib.Clamp(InputMask[x, y], MinHeight, MaxHeight); } } } return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } //this is a splitter, so we need to duplicate the input values.. MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; DAGMask outMask = InputMask.Clone(); for (int i = 0; i < NumPixels; i++) { DAGMask smallerMask = new DAGMask(parms.Width, parms.Height); contractSetValue(ref outMask, ref smallerMask); outMask = smallerMask.Clone(); } //normalize our input now... for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { mp.Value[x, y] = outMask[x, y]; } } outMask = null; return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; SplineInterpolator interpolator = new SplineInterpolator(); for (int i = 0; i < ControlPointsKeys.Count; ++i) { interpolator.Add(ControlPointsKeys[i], ControlPointsValues[i]); } for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { float v = mp.Value[x, y]; mp.Value[x, y] = (float)interpolator.Interpolate(v); } } interpolator.Clear(); interpolator = null; return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; float modStep = 1.0f / NumTerraces; if (Method == (int)eMethod.eSimple) { for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { float dc = InputMask[x, y] % modStep; mp.Value[x, y] = InputMask[x, y] - dc; } } } else if (Method == (int)eMethod.eSharp) { for (int y = 0; y < parms.Height; y++) { for (int x = 0; x < parms.Width; x++) { //find our low step float val = InputMask[x, y]; float low = val - (val % modStep); float high = low + modStep; float posalpha = (val - low) / (high - low); posalpha *= posalpha; float posVal = ((1.0f - posalpha) * low) + (posalpha * high); float negalpha = (val - low) / (high - low); negalpha = 1.0f - negalpha; { float v = low; low = high; high = v; } negalpha *= negalpha; float negVal = ((1.0f - negalpha) * low) + (negalpha * high); //lerp between neg and pos values mp.Value[x, y] = ((1.0f - TerraceShape) * negVal) + (TerraceShape * posVal); } } } //else if (Method == (int)eMethod.eSmooth) //{ //} return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; /////////////////////////////////////////////////////////////// int width = parms.Width; int height = parms.Height; int rad = Radius; int[] leadingEdgeX = new int[rad + 1]; // approximately (rad + 0.5)^2 int cutoff = ((rad * 2 + 1) * (rad * 2 + 1) + 2) / 4; for (int v = 0; v <= rad; ++v) { for (int u = 0; u <= rad; ++u) { if (u * u + v * v <= cutoff) { leadingEdgeX[v] = u; } } } const int hLength = 256; int[] ha = new int[hLength]; for (int y = 0; y < parms.Height; y++) { //calculate our histogram.. for (int k = 0; k < hLength; k++) { ha[k] = 0; } int area = 0; int maxArea = GetMaxAreaForRadius(rad); int top = -Math.Min(rad, y); int bottom = Math.Min(rad, height - 1 - y); int left = -Math.Min(rad, 0); int right = Math.Min(rad, width - 1); for (int v = top; v <= bottom; ++v) { for (int u = left; u <= right; ++u) { byte psamp = (byte)(InputMask[u, y + v] * 255); if ((u * u + v * v) <= cutoff) { ++area; ++ha[psamp]; } } } for (int x = 0; x < parms.Width; x++) { mp.Value[x, y] = GetPercentile(Percent, area, ref ha) / 255.0f; left = -Math.Min(rad, x); right = Math.Min(rad + 1, width - 1 - x); // Subtract trailing edge top half int v = -1; while (v >= top) { int u = leadingEdgeX[-v]; if (-u >= left) { break; } --v; } while (v >= top) { int u = leadingEdgeX[-v]; byte p = (byte)(InputMask[x - u, y + v] * 255); --ha[p]; --area; --v; } // add leading edge top half v = -1; while (v >= top) { int u = leadingEdgeX[-v]; if (u + 1 <= right) { break; } --v; } while (v >= top) { int u = leadingEdgeX[-v]; byte p = (byte)(InputMask[x + u + 1, y + v] * 255); ++ha[p]; ++area; --v; } // Subtract trailing edge bottom half v = 0; while (v <= bottom) { int u = leadingEdgeX[v]; if (-u >= left) { break; } ++v; } while (v <= bottom) { int u = leadingEdgeX[v]; byte p = (byte)(InputMask[x - u, y + v] * 255); --ha[p]; --area; ++v; } // add leading edge bottom half v = 0; while (v <= bottom) { int u = leadingEdgeX[v]; if (u + 1 <= right) { break; } ++v; } while (v <= bottom) { int u = leadingEdgeX[v]; byte p = (byte)(InputMask[x + u + 1, y + v] * 255); ++ha[p]; ++area; ++v; } } } return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; int r = Radius; int[] w = CreateGaussianBlurRow(r); int wlen = w.Length; DAGMask tmpMask = new DAGMask(parms.Width, parms.Height); { float[] waSums = new float[wlen]; float[] wcSums = new float[wlen]; float[] aSums = new float[wlen]; for (int y = 0; y < parms.Height; ++y) { float waSum = 0; float wcSum = 0; float aSum = 0; int dstx = 0; for (int wx = 0; wx < wlen; ++wx) { int srcX = wx - r; waSums[wx] = 0; wcSums[wx] = 0; aSums[wx] = 0; if (srcX >= 0 && srcX < parms.Width) { for (int wy = 0; wy < wlen; ++wy) { int srcY = y + wy - r; if (srcY >= 0 && srcY < parms.Height) { float c = InputMask[srcX, srcY]; float wp = w[wy]; waSums[wx] += wp; wp *= c;// +(c >> 7); wcSums[wx] += wp; //wp >>= 8; aSums[wx] += wp * c; } } int wwx = w[wx]; waSum += wwx * waSums[wx]; wcSum += wwx * wcSums[wx]; aSum += wwx * aSums[wx]; } } // wcSum >>= 8; if (waSum == 0 || wcSum == 0) { tmpMask[dstx, y] = 0; } else { tmpMask[dstx, y] = aSum / waSum; } ++dstx; for (int x = 1; x < parms.Width; ++x) { for (int i = 0; i < wlen - 1; ++i) { waSums[i] = waSums[i + 1]; wcSums[i] = wcSums[i + 1]; aSums[i] = aSums[i + 1]; } waSum = 0; wcSum = 0; aSum = 0; int wx; for (wx = 0; wx < wlen - 1; ++wx) { float wwx = w[wx]; waSum += wwx * waSums[wx]; wcSum += wwx * wcSums[wx]; aSum += wwx * aSums[wx]; } wx = wlen - 1; waSums[wx] = 0; wcSums[wx] = 0; aSums[wx] = 0; int srcX = x + wx - r; if (srcX >= 0 && srcX < parms.Width) { for (int wy = 0; wy < wlen; ++wy) { int srcY = y + wy - r; if (srcY >= 0 && srcY < parms.Height) { float c = InputMask[srcX, srcY]; float wp = w[wy]; waSums[wx] += wp; wp *= c;// +(c >> 7); wcSums[wx] += wp; //wp >>= 8; aSums[wx] += wp * c; } } int wr = w[wx]; waSum += wr * waSums[wx]; wcSum += wr * wcSums[wx]; aSum += wr * aSums[wx]; } // wcSum >>= 8; if (waSum == 0 || wcSum == 0) { tmpMask[x, y] = 0; } else { tmpMask[x, y] = (aSum / waSum); } ++dstx; } } } //copy back for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { mp.Value[x, y] = tmpMask[x, y]; } } tmpMask = null; return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; ConvMatrix filter = new ConvMatrix(1, 2, 1, 2, 4, 2, 1, 2, 1); filter.mFactor = 16; filter.mOffset = 0; for (int i = 0; i < SmoothPower; i++) { int[] neightbors = new int[] { -1, 1, //top left 0, 1, //top center 1, 1, //top right -1, 0, //mid left 0, 0, //mid center 1, 0, //mid right -1, -1, //bot left 0, -1, //bot center 1, -1, //bot right }; DAGMask tempImgArray = new DAGMask(parms.Width, parms.Height); for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { float total = 0; for (int k = 0; k < 9; k++) { int xIndex = x + neightbors[k * 2]; int zIndex = y + neightbors[k * 2 + 1]; if (xIndex < 0 || xIndex > parms.Width - 1 || zIndex < 0 || zIndex > parms.Height - 1) { continue; } total += filter.mFilterCoeffs[k] * mp.Value[xIndex, zIndex]; } total = total / filter.mFactor + filter.mOffset; if (total > 1.0f) { total = 1.0f; } if (total < 0) { total = 0; } tempImgArray[x, y] = total; } } //send our mask back for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < parms.Height; y++) { mp.Value[x, y] = BMathLib.Clamp(tempImgArray[x, y], 0, 1); } } tempImgArray = null; } return(true); }
override public bool computeOutput(ConnectionPoint connPoint, OutputGenerationParams parms) { if (!verifyInputConnections()) { return(false); } if (!gatherInputAndParameters(parms)) { return(false); } MaskParam mp = ((MaskParam)(connPoint.ParamType)); mp.Value = InputMask.Clone(); mp.Value.mConstraintMask = ConstraintMask; int workWidth = parms.Width - 1; int workHeight = parms.Height - 1; int halfWid = parms.Width >> 1; int halfHei = parms.Height >> 1; if (Method == (int)eMethod.eLeftToRight) { for (int x = 0; x < halfWid; x++) { for (int y = 0; y < parms.Height; y++) { mp.Value[workWidth - x, y] = InputMask[x, y]; } } } else if (Method == (int)eMethod.eRightToLeft) { for (int x = 0; x < halfWid; x++) { for (int y = 0; y < parms.Height; y++) { mp.Value[x, y] = InputMask[workWidth - x, y]; } } } else if (Method == (int)eMethod.eTopToBottom) { for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < halfHei; y++) { mp.Value[x, y] = InputMask[x, workHeight - y]; } } } else if (Method == (int)eMethod.eBottomToTop) { for (int x = 0; x < parms.Width; x++) { for (int y = 0; y < halfHei; y++) { mp.Value[x, workHeight - y] = InputMask[x, y]; } } } return(true); }