Beispiel #1
0
        /// <summary>
        ///     Returns whether or not an enumeration instance a valid value.
        ///     This method is designed to be used with ValidateValueCallback, and thus
        ///     matches it's prototype.
        /// </summary>
        /// <param name="valueObject">
        ///     Enumeration value to validate.
        /// </param>
        /// <returns> 'true' if the enumeration contains a valid value, 'false' otherwise. </returns>
        public static bool IsEdgeModeValid(object valueObject)
        {
            EdgeMode value = (EdgeMode)valueObject;

            return((value == EdgeMode.Unspecified) ||
                   (value == EdgeMode.Aliased));
        }
Beispiel #2
0
        /// <summary>
        /// Neighbors of the node.
        /// </summary>
        /// <param name="node">Node which neighbors we want to get.</param>
        /// <param name="edgeMode">Out/In/InOut neighbors.</param>
        /// <returns>Neighbors of the given node.</returns>
        public HashSet <Node> Neighbors(Node node, EdgeMode edgeMode)
        {
            if (edgeMode == EdgeMode.In)
            {
                if (!NeighborsIn.ContainsKey(node.Id))
                {
                    return(EmptyNodes);
                }

                return(NeighborsIn[node.Id]);
            }

            if (edgeMode == EdgeMode.Out)
            {
                if (!NeighborsOut.ContainsKey(node.Id))
                {
                    return(EmptyNodes);
                }

                return(NeighborsOut[node.Id]);
            }

            if (edgeMode == EdgeMode.InOut)
            {
                if (!NeighborsAll.ContainsKey(node.Id))
                {
                    return(EmptyNodes);
                }

                return(NeighborsAll[node.Id]);
            }
            return(null);
        }
Beispiel #3
0
 /// <summary>
 /// Writes the attached property EdgeMode to the given object.
 /// </summary>
 public static void SetEdgeMode(DependencyObject target, EdgeMode edgeMode)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     target.SetValue(EdgeModeProperty, edgeMode);
 }
Beispiel #4
0
        private void SetAliasingMode()
        {
            EdgeMode mode = OverlaySettings.EnableAntiAliasing ? EdgeMode.Unspecified : EdgeMode.Aliased;

            foreach (Widget widget in Widgets)
            {
                RenderOptions.SetEdgeMode(widget, mode);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Normal scale>=1
 /// </summary>
 /// <param name="isNormal"></param>
 private void EditorScaleChangeHandler(bool isNormal)
 {
     if (isNormal)
     {
         EdgeMode = EdgeMode.Aliased;
     }
     else
     {
         EdgeMode = EdgeMode.Unspecified;
     }
 }
Beispiel #6
0
        /// <summary>
        /// Returns relevance of the actor on given layer with specific edgemode.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor to get relevance of.</param>
        /// <param name="layer">Layer to calculate relevance on.</param>
        /// <param name="edgeMode">In/Out/InOut edges.</param>
        /// <returns>Relevance of the actor on given layer with specific edgemode.</returns>
        public double Relevance(MultilayerNetwork mnet, Actor actor, Layer layer, EdgeMode edgeMode = EdgeMode.InOut)
        {
            double allLayers      = NeighborhoodCentrality(mnet, actor, mnet.Layers, edgeMode);
            double selectedLayers = NeighborhoodCentrality(mnet, actor, layer, edgeMode);

            if (allLayers == 0)
            {
                return(0);
            }

            return(selectedLayers / allLayers);
        }
Beispiel #7
0
        void IMetroDrawingContext.Push(
            Matrix transform,
            Geometry clip,
            double opacity,
            Brush opacityMask,
            Rect maskBounds,
            bool onePrimitive,

            // serialization attributes
            String nameAttr,
            Visual node,
            Uri navigateUri,
            EdgeMode edgeMode
            )
        {
            m_Flattener.Push(transform, clip, opacity, opacityMask, maskBounds, onePrimitive);
        }
Beispiel #8
0
        public void Push(
            Matrix transform,
            Geometry clip,
            double opacity,
            Brush opacityMask,
            Rect maskBounds,
            bool onePrimitive,

            // serialization attributes
            String nameAttr,
            Visual node,
            Uri navigateUri,
            EdgeMode edgeMode
            )
        {
            opacity = Utility.NormalizeOpacity(opacity);

            int pushCount = 0;

            if (!transform.IsIdentity)
            {
                _context.PushTransform(new MatrixTransform(transform));
                pushCount++;
            }

            if (clip != null)
            {
                _context.PushClip(clip);
                pushCount++;
            }

            if (!Utility.IsOpaque(opacity))
            {
                _context.PushOpacity(opacity);
                pushCount++;
            }

            if (opacityMask != null)
            {
                _context.PushOpacityMask(opacityMask);
                pushCount++;
            }

            _push.Push(pushCount);
        }
Beispiel #9
0
        /// <summary>
        /// Returns degree on provided layer.
        /// </summary>
        /// <param name="mnet">Multlayer network model.</param>
        /// <param name="actor">Actor.</param>
        /// <param name="layer">Single Layer.</param>
        /// <param name="edgeMode">In / Out / All, mode of edge.</param>
        /// <returns>Degree of the Actor.</returns>
        public int Degree(MultilayerNetwork mnet, Actor actor, Layer layer, EdgeMode edgeMode)
        {
            var degree = 0;

            // All nodes with this ACTOR.
            foreach (var node in mnet.GetNodes(actor))
            {
                // All neighbors of this NODE, with the correct edgeMode (In / Out / Or both).
                foreach (var neighbor in mnet.Neighbors(node, edgeMode))
                {
                    // We go through all his neighbors, and if the neighbor is on the provided layer
                    // we increase his degree by 1.
                    if (neighbor.Layer == layer)
                    {
                        degree += 1;
                    }
                }
            }

            return(degree);
        }
Beispiel #10
0
    public tk2dTileMapEditorBrush(tk2dTileMapEditorBrush source)
    {
        this.name      = source.name;
        this.type      = source.type;
        this.paintMode = source.paintMode;

        tiles = new tk2dSparseTile[source.tiles.Length];
        for (int i = 0; i < source.tiles.Length; ++i)
        {
            tiles[i] = new tk2dSparseTile(source.tiles[i]);
        }

        multiSelectTiles = new int[source.multiSelectTiles.Length];
        for (int i = 0; i < source.multiSelectTiles.Length; ++i)
        {
            multiSelectTiles[i] = source.multiSelectTiles[i];
        }

        edgeMode   = source.edgeMode;
        multiLayer = source.multiLayer;
        overrideWithSpriteBounds = source.overrideWithSpriteBounds;
    }
        static extern void gimp_pixel_fetcher_set_edge_mode(IntPtr pf,
							EdgeMode mode);
Beispiel #12
0
 private void ClearEdgeMode()
 {
     _edgeMode = RenderOptions.GetEdgeMode(this);
     RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
 }
Beispiel #13
0
 private void ResetEdgeMode()
 {
     this.EdgeMode = EdgeMode.None;
 }
Beispiel #14
0
 private void ResetEdgeMode()
 {
     EdgeMode = EdgeMode.None;
 }
Beispiel #15
0
        /// <summary>
        /// Returns exclusive relevance of the actor on given layer with specific edgemode.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor to get exclusive relevance of.</param>
        /// <param name="layer">Layer to calculate exclusive relevance on.</param>
        /// <param name="edgeMode">In/Out/InOut edges.</param>
        /// <returns>Exclusive relevance of the actor on given layer with specific edgemode.</returns>
        public double ExclusiveRelevance(MultilayerNetwork mnet, Actor actor, Layer layer, EdgeMode edgeMode = EdgeMode.InOut)
        {
            Layer flattened = mnet.GetLayer("flattened");
            var   test      = new HashSet <Layer>(mnet.GetLayers().Except(new HashSet <Layer>()
            {
                flattened
            }));
            double allLayers = NeighborhoodCentrality(mnet, actor, new HashSet <Layer>(mnet.GetLayers().Except(new HashSet <Layer>()
            {
                flattened
            })), edgeMode);
            double selectedLayers = ExclusiveNeighborhood(mnet, actor, layer, edgeMode);

            if (allLayers == 0)
            {
                return(0);
            }

            return(selectedLayers / allLayers);
        }
Beispiel #16
0
        /// <summary>
        /// Returns means of degrees on the provided layers.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor.</param>
        /// <param name="layers">HashSet of layers.</param>
        /// <param name="edgeMode">In / Out / All, mode of edge.</param>
        /// <returns>Mean of degrees.</returns>
        public double DegreeMean(MultilayerNetwork mnet, Actor actor, HashSet <Layer> layers, EdgeMode edgeMode)
        {
            var degrees = new List <double>();

            foreach (var layer in layers)
            {
                degrees.Add(Degree(mnet, actor, layer, edgeMode));
            }

            return(degrees.Average());
        }
        /// <summary>
        /// Convolve with a kernel consisting of one column.
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="inPixels"></param>
        /// <param name="outPixels"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="alpha"></param>
        /// <param name="edgeAction"></param>
        public static void ConvolveV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, bool alpha, EdgeMode edgeAction) {
            int index = 0;
            float[] matrix = kernel.GetKernel();
            int rows = kernel.Height;
            int rows2 = rows/2;

            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    float r = 0, g = 0, b = 0, a = 0;

                    for (int row = -rows2; row <= rows2; row++) {
                        int iy = y + row;
                        int ioffset;
                        if (iy < 0) {
                            if (edgeAction == EdgeMode.Clamp)
                                ioffset = 0;
                            else if (edgeAction == EdgeMode.Wrap)
                                ioffset = ((y + height)%height)*width;
                            else
                                ioffset = iy*width;
                        }
                        else if (iy >= height) {
                            if (edgeAction == EdgeMode.Clamp)
                                ioffset = (height - 1)*width;
                            else if (edgeAction == EdgeMode.Wrap)
                                ioffset = ((y + height)%height)*width;
                            else
                                ioffset = iy*width;
                        }
                        else
                            ioffset = iy*width;

                        float f = matrix[row + rows2];

                        if (f != 0) {
                            int rgb = inPixels[ioffset + x];
                            a += f*((rgb >> 24) & 0xff);
                            r += f*((rgb >> 16) & 0xff);
                            g += f*((rgb >> 8) & 0xff);
                            b += f*(rgb & 0xff);
                        }
                    }
                    int ia = alpha ? PixelUtils.Clamp((int)(a + 0.5)) : 0xff;
                    int ir = PixelUtils.Clamp((int)(r + 0.5));
                    int ig = PixelUtils.Clamp((int)(g + 0.5));
                    int ib = PixelUtils.Clamp((int)(b + 0.5));
                    outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// Returns exclusive neighborhood of given actor on given layer with specific edgemode.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor to get exclusive neighborhood of.</param>
        /// <param name="layer">Layer to calculate exclusive neighborhood on.</param>
        /// <param name="edgeMode">In/Out/InOut edges.</param>
        /// <returns>Exclusive neighborhood of given actor on given layer with specific edgemode.</returns>
        public int ExclusiveNeighborhood(MultilayerNetwork mnet, Actor actor, Layer layer, EdgeMode edgeMode = EdgeMode.InOut)
        {
            Layer flattened = mnet.GetLayer("flattened");
            // All layers except the layers in parameter.
            var layers = new HashSet <Layer> {
                layer
            };
            var layerSupplement = new HashSet <Layer>(mnet.GetLayers().Except(new HashSet <Layer>()
            {
                flattened
            }).Except(layers));
            var a = Neighbors(mnet, actor, layers, edgeMode);
            var b = Neighbors(mnet, actor, layerSupplement, edgeMode);

            var aMinusB = new HashSet <Actor>(a.Except(b));

            return(aMinusB.Count);
        }
        /// <summary>
        /// Convolve with a 2D kernel.
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="inPixels"></param>
        /// <param name="outPixels"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="alpha"></param>
        /// <param name="edgeAction"></param>
        public static void ConvolveHV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, bool alpha, EdgeMode edgeAction) {
            int index = 0;
            float[] matrix = kernel.GetKernel();
            int rows = kernel.Height;
            int cols = kernel.Width;
            int rows2 = rows/2;
            int cols2 = cols/2;

            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    float r = 0, g = 0, b = 0, a = 0;

                    for (int row = -rows2; row <= rows2; row++) {
                        int iy = y + row;
                        int ioffset;
                        if (0 <= iy && iy < height)
                            ioffset = iy*width;
                        else if (edgeAction == EdgeMode.Clamp)
                            ioffset = y*width;
                        else if (edgeAction == EdgeMode.Wrap)
                            ioffset = ((iy + height)%height)*width;
                        else
                            continue;
                        int moffset = cols*(row + rows2) + cols2;
                        for (int col = -cols2; col <= cols2; col++) {
                            float f = matrix[moffset + col];

                            if (f != 0) {
                                int ix = x + col;
                                if (!(0 <= ix && ix < width)) {
                                    if (edgeAction == EdgeMode.Clamp)
                                        ix = x;
                                    else if (edgeAction == EdgeMode.Wrap)
                                        ix = (x + width)%width;
                                    else
                                        continue;
                                }
                                int rgb = inPixels[ioffset + ix];
                                a += f*((rgb >> 24) & 0xff);
                                r += f*((rgb >> 16) & 0xff);
                                g += f*((rgb >> 8) & 0xff);
                                b += f*(rgb & 0xff);
                            }
                        }
                    }
                    int ia = alpha ? PixelUtils.Clamp((int)(a + 0.5)) : 0xff;
                    int ir = PixelUtils.Clamp((int)(r + 0.5));
                    int ig = PixelUtils.Clamp((int)(g + 0.5));
                    int ib = PixelUtils.Clamp((int)(b + 0.5));
                    outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
                }
            }
        }
        /// <summary>
        /// Convolve with a kernel consisting of one row.
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="inPixels"></param>
        /// <param name="outPixels"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="alpha"></param>
        /// <param name="edgeAction"></param>
        public static void ConvolveH(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, bool alpha, EdgeMode edgeAction) {
            int index = 0;
            float[] matrix = kernel.GetKernel();
            int cols = kernel.Width;
            int cols2 = cols/2;

            for (int y = 0; y < height; y++) {
                int ioffset = y*width;
                for (int x = 0; x < width; x++) {
                    float r = 0, g = 0, b = 0, a = 0;
                    int moffset = cols2;
                    for (int col = -cols2; col <= cols2; col++) {
                        float f = matrix[moffset + col];

                        if (f != 0) {
                            int ix = x + col;
                            if (ix < 0) {
                                if (edgeAction == EdgeMode.Clamp)
                                    ix = 0;
                                else if (edgeAction == EdgeMode.Wrap)
                                    ix = (x + width)%width;
                            }
                            else if (ix >= width) {
                                if (edgeAction == EdgeMode.Clamp)
                                    ix = width - 1;
                                else if (edgeAction == EdgeMode.Wrap)
                                    ix = (x + width)%width;
                            }
                            int rgb = inPixels[ioffset + ix];
                            a += f*((rgb >> 24) & 0xff);
                            r += f*((rgb >> 16) & 0xff);
                            g += f*((rgb >> 8) & 0xff);
                            b += f*(rgb & 0xff);
                        }
                    }
                    int ia = alpha ? PixelUtils.Clamp((int)(a + 0.5)) : 0xff;
                    int ir = PixelUtils.Clamp((int)(r + 0.5));
                    int ig = PixelUtils.Clamp((int)(g + 0.5));
                    int ib = PixelUtils.Clamp((int)(b + 0.5));
                    outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
                }
            }
        }
 /// <summary>
 /// Convolve a block of pixels
 /// </summary>
 /// <param name="kernel"></param>
 /// <param name="inPixels"></param>
 /// <param name="outPixels"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="alpha"></param>
 /// <param name="edgeAction"></param>
 public static void Convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, bool alpha, EdgeMode edgeAction) {
     if (kernel.Height == 1)
         ConvolveH(kernel, inPixels, outPixels, width, height, alpha, edgeAction);
     else if (kernel.Width == 1)
         ConvolveV(kernel, inPixels, outPixels, width, height, alpha, edgeAction);
     else
         ConvolveHV(kernel, inPixels, outPixels, width, height, alpha, edgeAction);
 }
 /// <summary>
 /// Convolve a block of pixels.
 /// </summary>
 /// <param name="kernel"></param>
 /// <param name="inPixels"></param>
 /// <param name="outPixels"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="edgeAction"></param>
 public static void Convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, EdgeMode edgeAction) {
     Convolve(kernel, inPixels, outPixels, width, height, true, edgeAction);
 }
Beispiel #23
0
        public static IReadOnlyCollection <DateTimeWindow> GetWindowsBetween(DateTime start, DateTime end, IReadOnlyCollection <DateTimeRange> granularities, EdgeMode edges = EdgeMode.Shrink)
        {
            var result = new List <DateTimeWindow>();

            if (start >= end || granularities.Count == 0)
            {
                return(result);
            }

            var ranges = granularities.OrderByDescending(g => g).ToArray();

            AppendWindowsBetween(start, end, ranges, 0, result);

            // In 'Grow' mode, ensure the returned list of buckets **at least** covers the start and end times
            if (edges == EdgeMode.Grow)
            {
                var smallestRange = ranges.Last();
                if (result.Count == 0 || result[0].start > start)
                {
                    // No buckets fit, or start bucket starts too late.
                    // Add the smallest bucket starting before the start time
                    var startWindow = DateTimeWindow.Find(start, smallestRange);
                    result.Insert(0, startWindow);
                }

                var lastWindow = result.Last();
                if (lastWindow.end < end)
                {
                    // End bucket finishes too early.
                    // Add the smallest bucket starting before the end time
                    var finalWindow = DateTimeWindow.Find(end, smallestRange);
                    result.Add(finalWindow);
                }
            }

            return(result.AsReadOnly());
        }
Beispiel #24
0
 /// <summary>
 /// Returns neighborhood centrality of given actor on given layer with specific edgemode.
 /// </summary>
 /// <param name="mnet">Multilayer network model.</param>
 /// <param name="actor">Actor to get neighborhood of.</param>
 /// <param name="layer">Layer to get neighborhood on.</param>
 /// <param name="edgeMode">In/Out/InOut edges.</param>
 /// <returns>Neighborhood centrality of given actor on given layer with specific edgemode.</returns>
 public int NeighborhoodCentrality(MultilayerNetwork mnet, Actor actor, Layer layer, EdgeMode edgeMode = EdgeMode.InOut)
 {
     return(Neighbors(mnet, actor, layer, edgeMode).Count);
 }
Beispiel #25
0
 /// <summary>
 /// Writes the attached property EdgeMode to the given object.
 /// </summary>
 public static void SetEdgeMode(DependencyObject target, EdgeMode edgeMode)
 {
     if (target == null) { throw new ArgumentNullException("target"); }
     target.SetValue(EdgeModeProperty, edgeMode);
 }
Beispiel #26
0
 /// <summary>
 /// Returns connective redundancy of given actor on given set of layers with specific edgemode.
 /// </summary>
 /// <param name="mnet">Multilayer network model.</param>
 /// <param name="actor">Actor to get connective redundancy of.</param>
 /// <param name="layers">Layers to get connective redundancy on.</param>
 /// <param name="edgeMode">In/Out/InOut edges.</param>
 /// <returns>Connective redundancy of given actor on given set of layers with specific edgemode.</returns>
 public double ConnectiveRedundancy(MultilayerNetwork mnet, Actor actor, HashSet <Layer> layers, EdgeMode edgeMode = EdgeMode.InOut)
 {
     return(1 - Math.Max((NeighborhoodCentrality(mnet, actor, layers, edgeMode) / Degree(mnet, actor, layers, edgeMode)), 0));
 }
        /// <summary>
        /// Blur and transpose a block of ARGB pixels.
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="inPixels"></param>
        /// <param name="outPixels"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="alpha"></param>
        /// <param name="premultiply"></param>
        /// <param name="unpremultiply"></param>
        /// <param name="edgeAction"></param>
        public static void ConvolveAndTranspose(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, bool alpha, bool premultiply, bool unpremultiply, EdgeMode edgeAction) {
            float[] matrix = kernel.GetKernel();
            int cols = kernel.Width;
            int cols2 = cols/2;

            for (int y = 0; y < height; y++) {
                int index = y;
                int ioffset = y*width;
                for (int x = 0; x < width; x++) {
                    float r = 0, g = 0, b = 0, a = 0;
                    int moffset = cols2;
                    for (int col = -cols2; col <= cols2; col++) {
                        float f = matrix[moffset + col];

                        if (f != 0) {
                            int ix = x + col;
                            if (ix < 0) {
                                if (edgeAction == EdgeMode.Clamp)
                                    ix = 0;
                                else if (edgeAction == EdgeMode.Wrap)
                                    ix = (x + width)%width;
                            }
                            else if (ix >= width) {
                                if (edgeAction == EdgeMode.Clamp)
                                    ix = width - 1;
                                else if (edgeAction == EdgeMode.Wrap)
                                    ix = (x + width)%width;
                            }
                            int rgb = inPixels[ioffset + ix];
                            int pa = (rgb >> 24) & 0xff;
                            int pr = (rgb >> 16) & 0xff;
                            int pg = (rgb >> 8) & 0xff;
                            int pb = rgb & 0xff;
                            if (premultiply) {
                                float a255 = pa*(1.0f/255.0f);
                                pr = (int)(pr*a255);
                                pg = (int)(pg*a255);
                                pb = (int)(pb*a255);
                            }
                            a += f*pa;
                            r += f*pr;
                            g += f*pg;
                            b += f*pb;
                        }
                    }
                    if (unpremultiply && a != 0 && a != 255) {
                        float f = 255.0f/a;
                        r *= f;
                        g *= f;
                        b *= f;
                    }
                    int ia = alpha ? PixelUtils.Clamp((int)(a + 0.5)) : 0xff;
                    int ir = PixelUtils.Clamp((int)(r + 0.5));
                    int ig = PixelUtils.Clamp((int)(g + 0.5));
                    int ib = PixelUtils.Clamp((int)(b + 0.5));
                    outPixels[index] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
                    index += height;
                }
            }
        }
Beispiel #28
0
        public void Push(
            Transform transform,
            Geometry clip,
            double opacity,
            Brush opacityMask,
            Rect maskBounds,
            bool onePrimitive,
            String nameAttr,
            Visual node,
            Uri navigateUri,
            EdgeMode edgeMode)
        {
            Debug.Assert(Utility.IsValid(opacity), "Invalid opacity should clip subtree");

            Matrix mat = Matrix.Identity;

            if (transform != null)
            {
                mat = transform.Value;
            }

            // opacity mask might be VisualBrush, hence ReduceBrush to reduce to DrawingBrush
            Debug.Assert(!BrushProxy.IsEmpty(opacityMask), "empty opacity mask should not result in Push");
            _dc.Push(
                mat,
                clip,
                opacity,
                ReduceBrush(opacityMask, maskBounds),
                maskBounds,
                onePrimitive,
                nameAttr,
                node,
                navigateUri,
                edgeMode
                );

            // prepend to transforms and clipping stack
            mat.Append(Transform);
            _fullTransform.Add(mat);

            // transform clip to world space, intersect with current clip, and push
            if (clip == null)
            {
                // push current clipping
                clip = Clip;
            }
            else
            {
                clip = Utility.TransformGeometry(clip, Transform);

                bool empty;
                clip = Utility.Intersect(clip, Clip, Matrix.Identity, out empty);

                if (empty)
                {
                    clip = Geometry.Empty;
                }
            }

            _fullClip.Add(clip);
        }
Beispiel #29
0
 private void ClearEdgeMode()
 {
     _edgeMode = RenderOptions.GetEdgeMode(this);
     RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
 }
Beispiel #30
0
        /// <summary>
        /// Rasterizes Visual and its descendents with optional bitmap effect. Also handles Visual opacity.
        /// </summary>
        /// <param name="visual"></param>
        /// <param name="nameAttr">Preserve Visual name attribute</param>
        /// <param name="navigateUri">Preserve FixedPage.NavigateUri</param>
        /// <param name="edgeMode">Preserve RenderOptions.EdgeMode</param>
        /// <param name="visualTransform">Visual.Transform</param>
        /// <param name="visualToWorldTransform">Full transform from Visual to world space, including visual transform prepended</param>
        /// <param name="inheritedTransformHint">
        /// Transformation above VisualTreeFlattener instance. This is needed if we're reducing VisualBrush to
        /// DrawingBrush to increase rasterization fidelity if brush is small, but will eventually fill large region.
        /// </param>
        /// <param name="clip">Clip in world space</param>
        /// <param name="effect">Optional bitmap effect</param>
        public void DrawRasterizedVisual(
            Visual visual,
            string nameAttr,
            Uri navigateUri,
            EdgeMode edgeMode,
            Transform visualTransform,
            Matrix visualToWorldTransform,
            Matrix inheritedTransformHint,
            Geometry clip,
            Effect effect
            )
        {
            Debug.Assert(visual != null);

            // Compute the bounding box of the visual and its descendants
            Rect bounds = VisualTreeHelper.GetContentBounds(visual);

            bounds.Union(VisualTreeHelper.GetDescendantBounds(visual));

            if (!Utility.IsRenderVisible(bounds))
            {
                return;
            }

            // transform clip to visual space
            if (clip != null)
            {
                Matrix worldToVisualTransform = visualToWorldTransform;
                worldToVisualTransform.Invert();

                clip = Utility.TransformGeometry(clip, worldToVisualTransform);
            }

            //
            // Clip visual bounds to rasterization clipping geometry.
            // We can't clip to Visual clipping geometry, since bitmap effects are applied
            // without clipping. For example, the blur effect looks different if you clip first
            // then apply effect, compared to applying the effect and then clipping.
            //
            bounds = PerformRasterizationClip(bounds, visualToWorldTransform);

            if (!Utility.IsRenderVisible(bounds))
            {
                return;
            }

            //
            // Rasterize Visual to IMetroDrawingContext with optional banding, depending
            // on whether bitmap effect is present. We can Push/Pop/Draw directly on _dc
            // since the input we provide it is already normalized (no DrawingImage, for example).
            // We also don't need Transform or Clip to be updated.
            //
            _dc.Push(
                visualTransform == null ? Matrix.Identity : visualTransform.Value,
                clip,
                1.0,
                null,
                Rect.Empty,
                /*onePrimitive=*/ false, // we Push and DrawImage below, which counts as 2 primitives
                nameAttr,
                visual,
                navigateUri,
                edgeMode
                );

            Matrix       bitmapToVisualTransform;
            BitmapSource bitmap;

            // If we have an Effect, we may need to inflate the bounds to account for the effect's output.
            if (effect != null)
            {
                bounds = effect.GetRenderBounds(bounds);
            }

            //
            // Rasterize visual in its entirety. Banding is not useful at this point since
            // the resulting bands are all kept in memory anyway. Plus transformation is applied
            // to the band, which causes gaps between bands if they're rotated (bug 1562237).
            //
            // Banding is performed at GDIExporter layer just prior to sending images to the printer.
            //
            bitmap = Utility.RasterizeVisual(
                visual,
                bounds,
                visualToWorldTransform * inheritedTransformHint,
                out bitmapToVisualTransform
                );


            if (bitmap != null)
            {
                _dc.Push(bitmapToVisualTransform, null, 1.0, null, Rect.Empty, /*onePrimitive=*/ true, null, null, null, EdgeMode.Unspecified);
                _dc.DrawImage(bitmap, new Rect(0, 0, bitmap.Width, bitmap.Height));
                _dc.Pop();
            }

            _dc.Pop();
        }
Beispiel #31
0
 /**
  *  Kontruktor pro tridu AutomatEdge.
  *
  *  atribut endState urcuje do ktereho stavu prechod vede
  *  atribut mode urcuje, zda pokud po hrane prejdeme, tak dochazi k zanorovani, ci vynorovani
  **/
 public AutomatEdge(AutomatState endState, EdgeMode mode)
 {
     this.endState = endState;
     this.edgeMode = mode;
 }
Beispiel #32
0
        public static void ConvolveAndTranspose(Kernel kernel, BitmapData inPixels, BitmapData outPixels, int width, int height, bool alpha, bool premultiply, bool unpremultiply, EdgeMode edgeAction)
        {
            unsafe {
                var matrix          = kernel.GetKernel();
                var halfKernalWidth = kernel.Width / 2;

                var bytesPerPixel = Image.GetPixelFormatSize(inPixels.PixelFormat) / 8;

                var hasAlpha = PixelFormat.Alpha.HasFlag(inPixels.PixelFormat);

                var sourceStart      = (byte *)inPixels.Scan0;
                var destinationStart = (byte *)outPixels.Scan0;

                Parallel.For(0, height, y => {
                    var index      = y;
                    var baseOffset = y * width;

                    for (var x = 0; x < width; x++)
                    {
                        var r = 0f;
                        var g = 0f;
                        var b = 0f;
                        var a = 0f;

                        for (var col = -halfKernalWidth; col <= halfKernalWidth; col++)
                        {
                            var f = matrix[halfKernalWidth + col];
                            if (f == 0)
                            {
                                continue;
                            }

                            var offsetX = x + col;
                            if (offsetX < 0)
                            {
                                switch (edgeAction)
                                {
                                case EdgeMode.Clamp:
                                    offsetX = 0;
                                    break;

                                case EdgeMode.Wrap:
                                    offsetX = (x + width) % width;
                                    break;
                                }
                            }
                            else if (offsetX >= width)
                            {
                                switch (edgeAction)
                                {
                                case EdgeMode.Clamp:
                                    offsetX = width - 1;
                                    break;

                                case EdgeMode.Wrap:
                                    offsetX = (x + width) % width;
                                    break;
                                }
                            }
                            var sourceOffset = sourceStart + ((baseOffset + offsetX) * bytesPerPixel);
                            var sourceR      = sourceOffset[0];
                            var sourceG      = sourceOffset[1];
                            var sourceB      = sourceOffset[2];
                            byte sourceA     = 0;
                            if (hasAlpha)
                            {
                                sourceA = sourceOffset[3];
                            }

                            if (premultiply && hasAlpha)
                            {
                                var alphaMultiply = sourceA * (1.0f / 255.0f);
                                sourceR           = (byte)(sourceR * alphaMultiply);
                                sourceG           = (byte)(sourceG * alphaMultiply);
                                sourceB           = (byte)(sourceB * alphaMultiply);
                            }

                            if (hasAlpha)
                            {
                                a += f * sourceA;
                            }
                            r += f * sourceR;
                            g += f * sourceG;
                            b += f * sourceB;
                        }

                        if (unpremultiply && hasAlpha && a != 0 && a != 255)
                        {
                            var f = 255.0f / a;
                            r    *= f;
                            g    *= f;
                            b    *= f;
                        }

                        var destinationA = alpha ? ClampByte((int)(a + 0.5)) : (byte)0xff;
                        var destinationR = ClampByte(r + 0.5);
                        var destinationG = ClampByte(g + 0.5);
                        var destinationB = ClampByte(b + 0.5);

                        var destOffset = destinationStart + (index * bytesPerPixel);

                        destOffset[0] = destinationR;
                        destOffset[1] = destinationG;
                        destOffset[2] = destinationB;
                        if (hasAlpha)
                        {
                            destOffset[3] = destinationA;
                        }
                        index += height;
                    }
                });
            }
        }
Beispiel #33
0
 public static void SetSmallEdgeMode(DependencyObject obj, EdgeMode value)
 {
     obj.SetValue(SmallEdgeModeProperty, value);
 }
Beispiel #34
0
 internal static extern IP_RET SelectiveBlur(ref TMatrix Src, ref TMatrix Dest, int Radius, int Threshold, EdgeMode Edge);
Beispiel #35
0
        // Old implementation.
        private int NeighborhoodCentrality_(MultilayerNetwork mnet, Actor actor, HashSet <Layer> layers, EdgeMode edgeMode = EdgeMode.InOut)
        {
            // Empty hashset to add checked actors.
            var actors       = new HashSet <Actor>();
            var neighborhood = 0;

            // All nodes with this ACTOR.
            foreach (var node in mnet.GetNodes(actor))
            {
                // All neighbors of this NODE, with the correct edgeMode (In / Out / Or both).
                foreach (var neighbor in mnet.Neighbors(node, edgeMode))
                {
                    // If there is a layer with this neighbor it means, that this NODE has this neighbor
                    // on this layer, so we increase his degree by 1 IF actor on this node is still available.
                    if (layers.Contains(neighbor.Layer) && actors.Add(neighbor.Actor))
                    {
                        neighborhood += 1;
                    }
                }
            }

            return(neighborhood);
        }
Beispiel #36
0
        /// <summary>
        /// Convolve with a kernel consisting of one column.
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="inPixels"></param>
        /// <param name="outPixels"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="alpha"></param>
        /// <param name="edgeAction"></param>
        public static void ConvolveV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, bool alpha, EdgeMode edgeAction)
        {
            int index = 0;

            float[] matrix = kernel.GetKernel();
            int     rows   = kernel.Height;
            int     rows2  = rows / 2;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    float r = 0, g = 0, b = 0, a = 0;

                    for (int row = -rows2; row <= rows2; row++)
                    {
                        int iy = y + row;
                        int ioffset;
                        if (iy < 0)
                        {
                            if (edgeAction == EdgeMode.Clamp)
                            {
                                ioffset = 0;
                            }
                            else if (edgeAction == EdgeMode.Wrap)
                            {
                                ioffset = ((y + height) % height) * width;
                            }
                            else
                            {
                                ioffset = iy * width;
                            }
                        }
                        else if (iy >= height)
                        {
                            if (edgeAction == EdgeMode.Clamp)
                            {
                                ioffset = (height - 1) * width;
                            }
                            else if (edgeAction == EdgeMode.Wrap)
                            {
                                ioffset = ((y + height) % height) * width;
                            }
                            else
                            {
                                ioffset = iy * width;
                            }
                        }
                        else
                        {
                            ioffset = iy * width;
                        }

                        float f = matrix[row + rows2];

                        if (f != 0)
                        {
                            int rgb = inPixels[ioffset + x];
                            a += f * ((rgb >> 24) & 0xff);
                            r += f * ((rgb >> 16) & 0xff);
                            g += f * ((rgb >> 8) & 0xff);
                            b += f * (rgb & 0xff);
                        }
                    }
                    int ia = alpha ? PixelUtils.Clamp((int)(a + 0.5)) : 0xff;
                    int ir = PixelUtils.Clamp((int)(r + 0.5));
                    int ig = PixelUtils.Clamp((int)(g + 0.5));
                    int ib = PixelUtils.Clamp((int)(b + 0.5));
                    outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
                }
            }
        }
Beispiel #37
0
        private MathUtils mathUtils = MathUtils.Instance; //new MathUtils();


        #region Degree

        /// <summary>
        /// Returns degree of the actor on provided layers.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor.</param>
        /// <param name="layers">HashSet of layers.</param>
        /// <param name="edgeMode">In / Out / All, mode of edge.</param>
        /// <returns>Degree of the Actor.</returns>
        public int Degree(MultilayerNetwork mnet, Actor actor, HashSet <Layer> layers, EdgeMode edgeMode)
        {
            var degree = 0;

            // All nodes with this ACTOR.
            foreach (var node in mnet.GetNodes(actor))
            {
                // All neighbors of this NODE, with the correct edgeMode (In / Out / Or both).
                foreach (var neighbor in mnet.Neighbors(node, edgeMode))
                {
                    // If there is a layer with this neighbor it means, that this NODE has this neighbor
                    // on this layer, so we increase his degree by 1.
                    if (layers.Contains(neighbor.Layer))
                    {
                        degree += 1;
                    }
                }
            }

            return(degree);
        }
Beispiel #38
0
 static extern void gimp_pixel_fetcher_set_edge_mode(IntPtr pf,
                                                     EdgeMode mode);
    public tk2dTileMapEditorBrush(tk2dTileMapEditorBrush source)
    {
        this.name = source.name;
        this.type = source.type;
        this.paintMode = source.paintMode;

        tiles = new tk2dSparseTile[source.tiles.Length];
        for (int i = 0; i < source.tiles.Length; ++i)
            tiles[i] = new tk2dSparseTile(source.tiles[i]);

        multiSelectTiles = new int[source.multiSelectTiles.Length];
        for (int i = 0; i < source.multiSelectTiles.Length; ++i)
            multiSelectTiles[i] = source.multiSelectTiles[i];

        edgeMode = source.edgeMode;
        multiLayer = source.multiLayer;
        overrideWithSpriteBounds = source.overrideWithSpriteBounds;
    }
 public static void SetEdgeMode(System.Windows.DependencyObject target, EdgeMode edgeMode)
 {
 }
Beispiel #41
0
        /// <summary>
        /// Blur and transpose a block of ARGB pixels.
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="inPixels"></param>
        /// <param name="outPixels"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="alpha"></param>
        /// <param name="premultiply"></param>
        /// <param name="unpremultiply"></param>
        /// <param name="edgeAction"></param>
        public static void ConvolveAndTranspose(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, bool alpha, bool premultiply, bool unpremultiply, EdgeMode edgeAction)
        {
            float[] matrix = kernel.GetKernel();
            int     cols   = kernel.Width;
            int     cols2  = cols / 2;

            for (int y = 0; y < height; y++)
            {
                int index   = y;
                int ioffset = y * width;
                for (int x = 0; x < width; x++)
                {
                    float r = 0, g = 0, b = 0, a = 0;
                    int   moffset = cols2;
                    for (int col = -cols2; col <= cols2; col++)
                    {
                        float f = matrix[moffset + col];

                        if (f != 0)
                        {
                            int ix = x + col;
                            if (ix < 0)
                            {
                                if (edgeAction == EdgeMode.Clamp)
                                {
                                    ix = 0;
                                }
                                else if (edgeAction == EdgeMode.Wrap)
                                {
                                    ix = (x + width) % width;
                                }
                            }
                            else if (ix >= width)
                            {
                                if (edgeAction == EdgeMode.Clamp)
                                {
                                    ix = width - 1;
                                }
                                else if (edgeAction == EdgeMode.Wrap)
                                {
                                    ix = (x + width) % width;
                                }
                            }
                            int rgb = inPixels[ioffset + ix];
                            int pa  = (rgb >> 24) & 0xff;
                            int pr  = (rgb >> 16) & 0xff;
                            int pg  = (rgb >> 8) & 0xff;
                            int pb  = rgb & 0xff;
                            if (premultiply)
                            {
                                float a255 = pa * (1.0f / 255.0f);
                                pr = (int)(pr * a255);
                                pg = (int)(pg * a255);
                                pb = (int)(pb * a255);
                            }
                            a += f * pa;
                            r += f * pr;
                            g += f * pg;
                            b += f * pb;
                        }
                    }
                    if (unpremultiply && a != 0 && a != 255)
                    {
                        float f = 255.0f / a;
                        r *= f;
                        g *= f;
                        b *= f;
                    }
                    int ia = alpha ? PixelUtils.Clamp((int)(a + 0.5)) : 0xff;
                    int ir = PixelUtils.Clamp((int)(r + 0.5));
                    int ig = PixelUtils.Clamp((int)(g + 0.5));
                    int ib = PixelUtils.Clamp((int)(b + 0.5));
                    outPixels[index] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
                    index           += height;
                }
            }
        }
Beispiel #42
0
 private void ResetEdgeMode()
 {
     EdgeMode = EdgeMode.None;
 }
Beispiel #43
0
        /// <summary>
        /// Returns standard deviation of degrees on the provided layers.
        /// </summary>
        /// <param name="mnet">Multilayer network model.</param>
        /// <param name="actor">Actor.</param>
        /// <param name="layers">HashSet of layers.</param>
        /// <param name="edgeMode">In / Out / All, mode of edge.</param>
        /// <returns>Standard deviation of degrees.</returns>
        public double DegreeDeviation(MultilayerNetwork mnet, Actor actor, HashSet <Layer> layers, EdgeMode edgeMode)
        {
            mathUtils = MathUtils.Instance; //new MathUtils();
            var degrees = new List <double>();

            foreach (var layer in layers)
            {
                degrees.Add(Degree(mnet, actor, layer, edgeMode));
            }

            return(mathUtils.Stdev(degrees));
        }
Beispiel #44
0
 /**
  *  Kontruktor pro tridu AutomatEdge.
  *
  *  atribut endState urcuje do ktereho stavu prechod vede
  *  atribut mode urcuje, zda pokud po hrane prejdeme, tak dochazi k zanorovani, ci vynorovani
  *  atribut att Type urcuje, jakyho typu je atribut, pro nejz je konstruovana tato hrana
  **/
 public AutomatEdge(AutomatState endState, EdgeMode mode, AttributeType attType)
 {
     this.endState      = endState;
     this.edgeMode      = mode;
     this.AttributeType = attType;
 }
 public EdgeModeSymbol(string name, Location location, EdgeMode edgeMode) : base(name, location) {
     EdgeMode = edgeMode;
 }