Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        static public void resizeF32Img(DAGMask inputTexture, DAGMask outputTexture, int inputWidth, int inputHeight, int newWidth, int newHeight, eFilterType method)
        {
            if (outputTexture == null)
            {
                outputTexture = new DAGMask(newWidth, newHeight);
            }
            if (inputWidth == newWidth && inputHeight == newHeight)
            {
                outputTexture = inputTexture.Clone();
                return;
            }
            float xFactor = (float)inputWidth / newWidth;
            float yFactor = (float)inputHeight / newHeight;

            int dstOffset = inputWidth - newWidth;

            //create a new texture of new size

            switch (method)
            {
            case eFilterType.cFilter_Nearest:
            {
                int ox, oy;


                // for each line
                for (int y = 0; y < newHeight; y++)
                {
                    // Y coordinate of the nearest point
                    oy = (int)(y * yFactor);

                    // for each pixel
                    for (int x = 0; x < newWidth; x++)
                    {
                        // X coordinate of the nearest point
                        ox = (int)(x * xFactor);

                        int srcIndex = oy * inputWidth + ox;

                        outputTexture[x, y] = inputTexture[ox, oy];
                    }
                    //     dstIndex += dstOffset;
                }
                break;
            }

            case eFilterType.cFilter_Linear:
            {
                float ox, oy, dx1, dy1, dx2, dy2;
                int   ox1, oy1, ox2, oy2;
                int   ymax = inputHeight - 1;
                int   xmax = inputWidth - 1;
                float v1, v2;


                // for each line
                for (int y = 0; y < newHeight; y++)
                {
                    // Y coordinates
                    oy  = (float)y * yFactor;
                    oy1 = (int)oy;
                    oy2 = (oy1 == ymax) ? oy1 : oy1 + 1;
                    dy1 = oy - (float)oy1;
                    dy2 = 1.0f - dy1;

                    // for each pixel
                    for (int x = 0; x < newWidth; x++)
                    {
                        // X coordinates
                        ox  = (float)x * xFactor;
                        ox1 = (int)ox;
                        ox2 = (ox1 == xmax) ? ox1 : ox1 + 1;
                        dx1 = ox - (float)ox1;
                        dx2 = 1.0f - dx1;


                        // interpolate using 4 points
                        {
                            v1 = (float)(dx2 * (inputTexture[ox1, oy1]) + dx1 * (inputTexture[ox2, oy1]));
                            v2 = (float)(dx2 * (inputTexture[ox1, oy2]) + dx1 * (inputTexture[ox2, oy2]));
                            outputTexture[x, y] = (float)(dy2 * v1 + dy1 * v2);
                        }
                    }
                    //  dstIndex += dstOffset;
                }
                break;
            }
            }
            ;
        }