コード例 #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo    = null;
            Bitmap  bitmap = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref bitmap))
            {
                return;
            }

            Corners corners = new Corners(bitmap);

            double threshold = 1.0;

            DA.GetData(2, ref threshold);
            corners.Threshold = (int)(threshold * 255.0);

            double valueModifier = 1.0;

            if (DA.GetData(3, ref valueModifier))
            {
                corners.Value = valueModifier;
            }

            int mode = 0;

            DA.GetData(1, ref mode);

            List <Point3d> points = new List <Point3d>();

            switch ((CornerModes)mode)
            {
            default:
                points = corners.GetSusanCorners();
                break;

            case CornerModes.Fast:
                points = corners.GetFastCorners();
                break;

            case CornerModes.Harris:
                points = corners.GetHarrisCorners();
                break;

            case CornerModes.Morvec:
                points = corners.GetMorvacCorners();
                break;
            }

            DA.SetDataList(0, points);
        }
コード例 #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo    = null;
            Bitmap  bitmap = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref bitmap))
            {
                return;
            }

            int mode = 0;

            DA.GetData(1, ref mode);

            switch ((ValueModes)mode)
            {
            default:
                DA.SetDataList(0, bitmap.GetColorValues());
                break;

            case ValueModes.Alpha:
                DA.SetDataList(0, bitmap.GetAValues());
                break;

            case ValueModes.Red:
                DA.SetDataList(0, bitmap.GetRValues());
                break;

            case ValueModes.Green:
                DA.SetDataList(0, bitmap.GetGValues());
                break;

            case ValueModes.Blue:
                DA.SetDataList(0, bitmap.GetBValues());
                break;

            case ValueModes.Hue:
                DA.SetDataList(0, bitmap.GetHueValues());
                break;

            case ValueModes.Saturation:
                DA.SetDataList(0, bitmap.GetSaturationValues());
                break;

            case ValueModes.Brightness:
                DA.SetDataList(0, bitmap.GetBrightnessValues());
                break;
            }
        }
コード例 #3
0
ファイル: AddLayer.cs プロジェクト: interopxyz/Macaw.GH
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo    = null;
            Bitmap  bitmap = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref bitmap))
            {
                return;
            }

            Ml.Layer layer = new Ml.Layer(bitmap);

            IGH_Goo gooM    = null;
            Bitmap  bitmapM = new Bitmap(100, 100);

            if (DA.GetData(1, ref gooM))
            {
                if (goo.TryGetBitmap(ref bitmapM))
                {
                    layer.Mask = bitmapM;
                }
            }

            int blendMode = 0;

            DA.GetData(2, ref blendMode);

            double opacity = 1.0;

            DA.GetData(3, ref opacity);

            layer.BlendMode = (Ml.Layer.BlendModes)blendMode;
            layer.Opacity   = 100 * opacity;

            DA.SetData(0, layer);
        }
コード例 #4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo    = null;
            Bitmap  bitmap = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref bitmap))
            {
                return;
            }

            Blobs blobs = new Blobs();

            Interval width = new Interval(5, 100);

            DA.GetData(1, ref width);
            blobs.MinWidth = (int)width.T0;
            blobs.MaxWidth = (int)width.T1;

            Interval height = new Interval(5, 100);

            DA.GetData(2, ref height);
            blobs.MinHeight = (int)height.T0;
            blobs.MaxHeight = (int)height.T1;

            Color color = Color.DarkGray;

            DA.GetData(3, ref color);
            blobs.BackgroundColor = color;

            bool limit = false;

            DA.GetData(4, ref limit);
            blobs.Coupled = limit;

            blobs.CalculateBlobs(bitmap);

            DA.SetDataList(0, blobs.GetBoundaries());
            DA.SetDataList(1, blobs.GetImages());
            DA.SetDataList(2, blobs.GetColors());
            DA.SetDataList(3, blobs.GetPoints());
        }
コード例 #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo    = null;
            Bitmap  bitmap = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref bitmap))
            {
                return;
            }

            DA.SetData(0, bitmap.Width);
            DA.SetData(1, bitmap.Height);
            DA.SetData(2, bitmap.HorizontalResolution);
            DA.SetData(3, bitmap.VerticalResolution);
        }
コード例 #6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo    = null;
            Bitmap  bitmap = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref bitmap))
            {
                return;
            }

            Bitmap bmp = bitmap.ToAccordBitmap(Filter.ImageTypes.Rgb32bpp);

            int mode = 0;

            DA.GetData(1, ref mode);

            int size = 10;

            DA.GetData(2, ref size);

            double tolerance = 1.0;

            DA.GetData(3, ref tolerance);

            double threshold = 1.0;

            DA.GetData(4, ref threshold);

            double alpha = 1.0;

            DA.GetData(5, ref alpha);

            List <Polyline> polylines = bmp.TraceToRhino(threshold, alpha, tolerance, size, false, (TraceBitmap.TurnModes)mode);

            DA.SetDataList(0, polylines);
        }
コード例 #7
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo    = null;
            Bitmap  bitmap = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref bitmap))
            {
                return;
            }

            int mode = 0;

            DA.GetData(1, ref mode);

            bool unitize = false;

            DA.GetData(2, ref unitize);

            List <Point3d> points = new List <Point3d>();

            if (!DA.GetDataList(3, points))
            {
                return;
            }

            List <Color>  colors  = new List <Color>();
            List <int>    ints    = new List <int>();
            List <double> numbers = new List <double>();

            double w = 1;

            if (unitize)
            {
                w = bitmap.Width - 1;
            }
            double h = 1;

            if (unitize)
            {
                h = bitmap.Height - 1;
            }

            switch ((ValueModes)mode)
            {
            default:
                foreach (Point3d point in points)
                {
                    colors.Add(bitmap.GetPixel((int)(point.X * w), (int)(point.Y * h)));
                }
                DA.SetDataList(0, colors);
                break;

            case ValueModes.Alpha:
                foreach (Point3d point in points)
                {
                    ints.Add(bitmap.GetPixel((int)(point.X * w), (int)(point.Y * h)).A);
                }
                DA.SetDataList(0, ints);
                break;

            case ValueModes.Red:
                foreach (Point3d point in points)
                {
                    ints.Add(bitmap.GetPixel((int)(point.X * w), (int)(point.Y * h)).R);
                }
                DA.SetDataList(0, ints);
                break;

            case ValueModes.Green:
                foreach (Point3d point in points)
                {
                    ints.Add(bitmap.GetPixel((int)(point.X * w), (int)(point.Y * h)).G);
                }
                DA.SetDataList(0, ints);
                break;

            case ValueModes.Blue:
                foreach (Point3d point in points)
                {
                    ints.Add(bitmap.GetPixel((int)(point.X * w), (int)(point.Y * h)).B);
                }
                DA.SetDataList(0, ints);
                break;

            case ValueModes.Hue:
                foreach (Point3d point in points)
                {
                    numbers.Add(bitmap.GetPixel((int)(point.X * w), (int)(point.Y * h)).GetHue());
                }
                DA.SetDataList(0, numbers);
                break;

            case ValueModes.Saturation:
                foreach (Point3d point in points)
                {
                    numbers.Add(bitmap.GetPixel((int)(point.X * w), (int)(point.Y * h)).GetSaturation());
                }
                DA.SetDataList(0, numbers);
                break;

            case ValueModes.Brightness:
                foreach (Point3d point in points)
                {
                    numbers.Add(bitmap.GetPixel((int)(point.X * w), (int)(point.Y * h)).GetBrightness());
                }
                DA.SetDataList(0, numbers);
                break;
            }
        }
コード例 #8
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo    = null;
            Bitmap  bitmap = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref bitmap))
            {
                return;
            }

            string path      = "C:\\Users\\Public\\Documents\\";
            string name      = DateTime.UtcNow.ToString("yyyy-dd-M_HH-mm-ss");;
            int    extension = 0;
            string format    = ".png";
            bool   save      = false;

            bool hasPath = DA.GetData(1, ref path);
            bool hasName = DA.GetData(2, ref name);

            if (!DA.GetData(3, ref extension))
            {
                return;
            }
            if (!DA.GetData(4, ref save))
            {
                return;
            }

            Si.ImageFormat encoding = Si.ImageFormat.Png;

            switch (extension)
            {
            case 1:
                encoding = Si.ImageFormat.Jpeg;
                format   = ".jpeg";
                break;

            case 2:
                encoding = Si.ImageFormat.Bmp;
                format   = ".bmp";
                break;

            case 3:
                encoding = Si.ImageFormat.Tiff;
                format   = ".tiff";
                break;

            case 4:
                encoding = Si.ImageFormat.Gif;
                format   = ".gif";
                break;
            }

            Bitmap bmp = (Bitmap)bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), Si.PixelFormat.Format32bppArgb);

            if (!hasPath)
            {
                if (this.OnPingDocument().FilePath != null)
                {
                    path = Path.GetDirectoryName(this.OnPingDocument().FilePath) + "\\";
                }
            }
            else
            {
                path += "//";
            }

            string filepath = path + name + format;

            if (save)
            {
                bmp.Save(filepath, encoding);
                bmp.Dispose();
            }

            DA.SetData(0, filepath);
        }
コード例 #9
0
ファイル: GetShapes.cs プロジェクト: interopxyz/Macaw.GH
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo    = null;
            Bitmap  bitmap = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref bitmap))
            {
                return;
            }

            Shapes shapes = new Shapes(bitmap);

            Interval width = new Interval();

            if (DA.GetData(1, ref width))
            {
                shapes.MinWidth = (int)width.T0;
                shapes.MaxWidth = (int)width.T1;
            }

            Interval height = new Interval();

            if (DA.GetData(2, ref height))
            {
                shapes.MinHeight = (int)height.T0;
                shapes.MaxHeight = (int)height.T1;
            }

            Color color = new Color();

            if (DA.GetData(3, ref color))
            {
                shapes.BackgroundColor = color;
            }

            bool limit = false;

            if (DA.GetData(4, ref limit))
            {
                shapes.Coupled = limit;
            }

            double angle = -1;

            if (DA.GetData(5, ref angle))
            {
                shapes.Angle = angle;
            }
            double distance = -1;

            if (DA.GetData(6, ref distance))
            {
                shapes.Length = distance;
            }
            double deviation = -1;

            if (DA.GetData(7, ref deviation))
            {
                shapes.Distortion = deviation;
            }

            shapes.CalculateShapes();

            DA.SetDataList(0, shapes.GetCircles);
            DA.SetDataList(1, shapes.GetTriangles);
            DA.SetDataList(2, shapes.GetQuadrilaterals);
        }
コード例 #10
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo = null;
            Bitmap  top = new Bitmap(100, 100);

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetBitmap(ref top))
            {
                return;
            }

            Mp.Layer topLayer = new Mp.Layer(top);

            IGH_Goo gooT   = null;
            Bitmap  bottom = new Bitmap(100, 100);

            if (!DA.GetData(1, ref gooT))
            {
                return;
            }
            if (!gooT.TryGetBitmap(ref bottom))
            {
                return;
            }

            Mp.Layer bottomLayer = new Mp.Layer(bottom);

            IGH_Goo gooM    = null;
            Image   img     = new Image();
            bool    hasMask = false;
            Bitmap  mask    = new Bitmap(100, 100);

            if (DA.GetData(2, ref gooM))
            {
                if (gooM.TryGetImage(ref img))
                {
                    hasMask = true;
                    img.SwapChannel(Image.Channels.Luminance, Image.Channels.Alpha);
                    mask = img.Bitmap;
                }
            }

            int blendMode = 0;

            DA.GetData(3, ref blendMode);

            double opacity = 1.0;

            DA.GetData(4, ref opacity);

            topLayer.BlendMode = (Mp.Layer.BlendModes)blendMode;
            topLayer.Opacity   = 100 * opacity;
            if (hasMask)
            {
                topLayer.Mask = mask;
            }

            Mp.Composition composition = new Mp.Composition();
            composition.Layers.Add(bottomLayer);
            composition.Layers.Add(topLayer);

            DA.SetData(0, new Image(composition.GetBitmap()));
        }
コード例 #11
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo   = null;
            Image   image = new Image();

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetImage(ref image))
            {
                return;
            }

            int mode = 0;

            DA.GetData(1, ref mode);

            IGH_Goo gooA    = null;
            Bitmap  overlay = new Bitmap(100, 100);

            if (DA.GetData(2, ref gooA))
            {
                if (goo.TryGetBitmap(ref overlay))
                {
                    ;
                }
            }

            double numVal = 1.0;

            DA.GetData(3, ref numVal);

            Filter filter = new Filter();

            switch ((FilterModes)mode)
            {
            case FilterModes.Add:
                filter = new Add(overlay);
                image.Filters.Add(new Add(overlay));
                break;

            case FilterModes.Subtract:
                filter = new Subtract(overlay);
                image.Filters.Add(new Subtract(overlay));
                break;

            case FilterModes.Multiply:
                filter = new Multiply(overlay);
                image.Filters.Add(new Multiply(overlay));
                break;

            case FilterModes.Divide:
                filter = new Divide(overlay);
                image.Filters.Add(new Divide(overlay));
                break;

            case FilterModes.Euclidean:
                filter = new Euclidean(overlay, (int)numVal);
                image.Filters.Add(new Euclidean(overlay, (int)numVal));
                break;

            case FilterModes.FlatField:
                filter = new FlatField(overlay);
                image.Filters.Add(new FlatField(overlay));
                break;

            case FilterModes.Intersect:
                filter = new Intersect(overlay);
                image.Filters.Add(new Intersect(overlay));
                break;

            case FilterModes.Merge:
                filter = new Merge(overlay);
                image.Filters.Add(new Merge(overlay));
                break;

            case FilterModes.Morph:
                filter = new Morph(overlay, numVal);
                image.Filters.Add(new Morph(overlay, numVal));
                break;

            case FilterModes.MoveTowards:
                filter = new MoveTowards(overlay, (int)numVal);
                image.Filters.Add(new MoveTowards(overlay, (int)numVal));
                break;

            case FilterModes.Simple:
                filter = new Simple(overlay, (int)numVal);
                image.Filters.Add(new Simple(overlay, (int)numVal));
                break;
            }

            message = ((FilterModes)mode).ToString();
            UpdateMessage();

            DA.SetData(0, image);
            DA.SetData(1, filter);
        }