Esempio n. 1
0
 public MoveParameter(int dir, float spd)
 {
     m_polar   = new PolarCoordinates();
     direction = dir;
     speed     = spd;
     Caluclate();
 }
Esempio n. 2
0
        public static System.Drawing.PointF ToScreenCoordinates(this PolarCoordinates p, System.Drawing.RectangleF rect)
        {
            var rc = new LinearRect(rect.Left, rect.Top, rect.Width, rect.Height);
            var pt = PolarCoordinates.ToLinearCoordinates(p, rc);

            return(new System.Drawing.PointF((float)pt.X, (float)pt.Y));
        }
    public void CoordinateSystemsTestScriptsSimplePasses()
    {
        // Use the Assert class to test conditions.
        for (int test = 0; test < tests; ++test)
        {
            NormalizedCartesianCoordinates cartesian = new NormalizedCartesianCoordinates(Random.onUnitSphere);
            NormalizedCartesianCoordinates reconverted_cartesian;

            // Test cubemap
            CubeUVCoordinates cubemap = cartesian;
            reconverted_cartesian = cubemap;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test octahedron map
            OctahedronUVCoordinates octahedron_map = cartesian;
            reconverted_cartesian = octahedron_map;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test spherical coordinates
            NormalizedSphericalCoordinates sphere = cartesian;
            reconverted_cartesian = sphere;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test stereoscopic coordinates
            StereoscopicProjectionCoordinates stereoscopic = cartesian;
            reconverted_cartesian = stereoscopic;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test polar coordinates
            PolarCoordinates polar = cartesian;
            reconverted_cartesian = polar;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data + " versus " + reconverted_cartesian.data);

            // Test spherical rectangle
            float   x1      = Random.Range(-Mathf.PI, +Mathf.PI); // FIXME: [-PI, +PI]
            float   x2      = Random.Range(-Mathf.PI, +Mathf.PI);
            float   y1      = Random.Range(-Mathf.PI, +Mathf.PI);
            float   y2      = Random.Range(-Mathf.PI, +Mathf.PI);
            Vector2 minimum = new Vector2(Mathf.Min(x1, x2), Mathf.Min(y1, y2));
            Vector2 size    = new Vector2(Mathf.Abs(x2 - x1), Mathf.Abs(y2 - y1));
            Rect    canvas  = new Rect(minimum, size);
            SphericalRectangleUVCoordinates spherical_rectangle = cartesian.to_spherical_rectangle(canvas);
            reconverted_cartesian = spherical_rectangle;
            Assert.IsTrue(Miscellaneous.approximately(cartesian.data, reconverted_cartesian.data), cartesian.data.ToString("F6") + " versus " + reconverted_cartesian.data.ToString("F6") + " intermediate: " + spherical_rectangle.canvas.ToString("F4") + " " + spherical_rectangle.uv.ToString("F4"));

            // Test normalized octahedron
            NormalizedOctahedronCoordinates octahedron = cartesian;
            bool same_signs = Mathf.Sign(octahedron.data.x) == Mathf.Sign(cartesian.data.x) &&
                              Mathf.Sign(octahedron.data.y) == Mathf.Sign(cartesian.data.y) &&
                              Mathf.Sign(octahedron.data.z) == Mathf.Sign(cartesian.data.z);
            Assert.IsTrue(same_signs, cartesian.data + " versus " + reconverted_cartesian.data);

            // Test normalized cube
            NormalizedCubeCoordinates cube = cartesian;
            same_signs = Mathf.Sign(cube.data.x) == Mathf.Sign(cartesian.data.x) &&
                         Mathf.Sign(cube.data.y) == Mathf.Sign(cartesian.data.y) &&
                         Mathf.Sign(cube.data.z) == Mathf.Sign(cartesian.data.z);
            Assert.IsTrue(same_signs, cartesian.data + " versus " + reconverted_cartesian.data);
        }
    }
Esempio n. 4
0
 public MoveParameter(int dir, float spd)
 {
     m_polar = new PolarCoordinates();
     direction = dir;
     speed = spd;
     Caluclate();
 }
Esempio n. 5
0
        public static System.Windows.Point ToScreenCoordinates(this PolarCoordinates p, System.Windows.Rect rect)
        {
            var rc = new LinearRect(rect.Left, rect.Top, rect.Width, rect.Height);
            var pt = PolarCoordinates.ToLinearCoordinates(p, rc);

            return(new System.Windows.Point(pt.X, pt.Y));
        }
Esempio n. 6
0
    // Use this for initialization
    void Start()
    {
        Init();

        state = new MoveState(this);
        PolarCoordinates.RotateAngles(sprite.gameObject.transform, baseParameter.moveParameter.direction);
    }
Esempio n. 7
0
 private int GetHoming()
 {
     Vector2 pos = target.localPosition - stateParent.transform.localPosition;
     PolarCoordinates pol = new PolarCoordinates { direction = stateParent.baseParameter.moveParameter.direction, speed = 1 };
     Vector2 normal = pol.ConvertToPolar();
     float cross = normal.Ccw(pos);
     return cross > 0 ? (int)homingLevel : -(int)homingLevel;
 }
Esempio n. 8
0
 public Gun(long ID, Type type, int level, PolarCoordinates position, double life)
 {
     this.ID = ID;
     this.GunType = type;
     this.Level = level;
     this.Position = position;
     this.Life = life;
 }
Esempio n. 9
0
    // Use this for initialization
    void Start()
    {
        attackParameter.damage      = new Damage(30, false, 20, parent.frontDirection, false);
        baseParameter.moveParameter = new MoveParameter(parent.frontDirection, 2F);

        state = new MoveState(this);
        PolarCoordinates.RotateAngles(sprite.gameObject.transform, baseParameter.moveParameter.direction);
    }
Esempio n. 10
0
        public static Vector2 PolarToRect(PolarCoordinates polar)
        {
            var rect = new Vector2();

            rect.x = polar.radius * Mathf.Cos(polar.degree * Mathf.Deg2Rad);
            rect.y = polar.radius * Mathf.Sin(polar.degree * Mathf.Deg2Rad);
            return(rect);
        }
Esempio n. 11
0
        public static Complex Pow(Complex z, double exponent)
        {
            PolarCoordinates pc = ConvertToPolarCoordinates(z);

            double a = Math.Pow(pc.R, exponent) * Math.Sin(exponent * pc.Theta);
            double b = Math.Pow(pc.R, exponent) * Math.Cos(exponent * pc.Theta);

            return(new Complex(a, b));
        }
Esempio n. 12
0
        public void PolarToCartesianToPolar()
        {
            var polar     = new PolarCoordinates(10, 2);
            var cartesian = polar.ToCartesian();
            var newPolar  = cartesian.ToPolar();

            Assert.Equal(polar.Length, newPolar.Length);
            Assert.Equal(polar.Angle, newPolar.Angle);
        }
Esempio n. 13
0
        /// <summary>
        /// This method converts Polar Coordinates into Cartesian Coordinates
        /// See the following for explanation: https://en.wikipedia.org/wiki/Polar_coordinate_system#Converting_between_polar_and_Cartesian_coordinates
        /// Tip: User angle is provided in Degrees, but needs to be converted to Radians for math to work
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static Response <CartesianCoordinates> PolarToCartesian(PolarCoordinates request)
        {
            var response    = new Response <CartesianCoordinates>();
            var cMethodName = "GeometryService.PolarToCartesian(..)";

            try
            {
                if (request == null)
                {
                    throw new ArgumentException(DomainResource.NullRequest);
                }

                if (request.DistanceFromOrigin == null)
                {
                    throw new ArgumentException(string.Format(DomainResource.XCannotBeNullOrEmpty, "Distance From Origin"));
                }

                if (request.Angle == null)
                {
                    throw new ArgumentException(string.Format(DomainResource.XCannotBeNullOrEmpty, "Angle"));
                }

                if (request.DistanceFromOrigin < 0)
                {
                    throw new ArgumentException(string.Format(DomainResource.XCannotBeNegative, "Distance From Origin"));
                }

                response.Value = new CartesianCoordinates();

                response.Value.XLocation = 0;
                response.Value.YLocation = 0;

                var radians = request.Angle.Value * (Math.PI / 180);

                response.Value.XLocation = request.DistanceFromOrigin * Math.Cos(radians);
                response.Value.YLocation = request.DistanceFromOrigin * Math.Sin(radians);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;

                var logData = new
                {
                    Request   = request,
                    Exception = ex
                };

                var msg = string.Format(DomainResource.ErrorOccuredInXY, cMethodName, ex.Message);

                LoggerService.Log(LogArea.Math, GeneralHelper.ExceptionLogType(ex), msg, logData);
            }

            return(response);
        }
Esempio n. 14
0
    private int GetHoming()
    {
        Vector2          pos = target.localPosition - stateParent.transform.localPosition;
        PolarCoordinates pol = new PolarCoordinates {
            direction = stateParent.baseParameter.moveParameter.direction, speed = 1
        };
        Vector2 normal = pol.ConvertToPolar();
        float   cross  = normal.Ccw(pos);

        return(cross > 0 ? (int)homingLevel : -(int)homingLevel);
    }
Esempio n. 15
0
    // Use this for initialization
    void Start()
    {
        mapManager = GameObject.Find("map_manager").GetComponent <MapManager>();

        attackParameter.damage      = new Damage(20, false, 30, parent.frontDirection, false);
        baseParameter.moveParameter = new MoveParameter(parent.frontDirection, 0F);


        state = new IkariMoveState(this);
        PolarCoordinates.RotateAngles(sprite.gameObject.transform, baseParameter.moveParameter.direction + 180);
    }
        public void PolarToCartesianNullAngleTest()
        {
            var request = new PolarCoordinates
            {
                DistanceFromOrigin = 13
            };

            var response = GeometryService.PolarToCartesian(request);

            Assert.IsNotNull(response, "Response should never be null");
            Assert.IsFalse(response.Success, "Response.Success should be [False] since an invalid request was supplied");
        }
Esempio n. 17
0
        public static PolarCoordinates RectToPolar(Vector2 vec, Vector2 origin)
        {
            var polar = new PolarCoordinates();

            Vector2 deltaPosition = vec - origin;
            float   degree        = Mathf.Atan2(deltaPosition.y, deltaPosition.x) * Mathf.Rad2Deg;
            float   radius        = Mathf.Sqrt(deltaPosition.x * deltaPosition.x + deltaPosition.y * deltaPosition.y);

            polar.radius = radius;
            polar.degree = degree;

            return(polar);
        }
Esempio n. 18
0
        private void init()
        {
            TestCreditState creditsState = new TestCreditState();
            CreditsHaveCompletedEventHandler creditsCompletedEventHandler = CreditsCompletedHandler;
            creditsState.Completed += creditsCompletedEventHandler;

            sub[0] = radialAssault.GetMenu();
            sub[1] = new PolarCoordinates();
            sub[2] = new ViewportHandlerTest();
            sub[3] = creditsState;
            sub[4] = new HardExitGameState();
            sub[5] = new BackMenuOption();
        }
Esempio n. 19
0
    /// <summary>
    /// 自分の向いてる方向にBoxがあったら返す。
    /// </summary>
    /// <returns></returns>
    protected BaseBox GetNearBox()
    {
        //向いてる方向のレイを作る
        Ray        r = new Ray(transform.position, PolarCoordinates.ConvertToPolar(frontDirection, 1F));
        RaycastHit h = new RaycastHit();

        //目の前に箱があった場合
        if (Physics.Raycast(r, out h, 0.05F))
        {
            var script = h.collider.gameObject.GetComponent <BaseBox>();
            return(script is BaseBox ? script : null);
        }

        return(null);
    }
        public void PolarToCartesianOriginTest()
        {
            var request = new PolarCoordinates
            {
                Angle = 0,
                DistanceFromOrigin = 0
            };

            var response = GeometryService.PolarToCartesian(request);

            Assert.IsNotNull(response, "Response should never be null");
            Assert.IsTrue(response.Success, "Response.Success should be true!");
            Assert.IsNotNull(response.Value, "The [Value] property of the Response object should not be null");
            Assert.IsNotNull(response.Value.XLocation, "X Location should not be null");
            Assert.IsNotNull(response.Value.YLocation, "Y Location should not be null");
            Assert.AreEqual(0, response.Value.XLocation.Value, 0.001, "X Location is incorrect");
            Assert.AreEqual(0, response.Value.YLocation.Value, 0.001, "Y Location is incorrect");
        }
Esempio n. 21
0
        public static List <Complex> NthRoots(Complex z, int n)
        {
            PolarCoordinates pc    = ConvertToPolarCoordinates(z);
            double           term1 = Math.Pow(pc.R, 1 / (double)n);

            List <Complex> roots = new List <Complex>();

            for (int i = 0; i < n; i++)
            {
                double a = term1 * Math.Cos((pc.Theta + 2 * i * Math.PI) / n);
                double b = term1 * Math.Sin((pc.Theta + 2 * i * Math.PI) / n);

                Complex root = new Complex(a, b);

                roots.Add(root);
            }

            return(roots);
        }
Esempio n. 22
0
        /// <summary>
        /// Perform a complete recalculation of the control.
        /// </summary>
        /// <remarks></remarks>
        private void Recalculate()
        {
            if (this.DrawingArea is null)
            {
                return;
            }
            _refSize = this.DrawingArea.RenderSize;
            if (_refSize.Height == 0d)
            {
                return;
            }

            // UpdateOutline()

            // ' this is the current angle calculated from the current box dimensions
            var pol = PolarCoordinates.ToPolarCoordinates(_refSize.Width, _refSize.Height);

            _angle = pol.Arc;
            CalculateSections();
        }
Esempio n. 23
0
        private void SetSelectedColor(UniColor?selc = null)
        {
            UniColor clr;

            if (selc != null)
            {
                clr           = (UniColor)selc;
                SelectedColor = Color.FromArgb(clr.A, clr.R, clr.G, clr.B);

                return;
            }
            else if (SelectedColor == null)
            {
                SelectedColorName    = null;
                Point.Visibility     = Surround.Visibility = Visibility.Hidden;
                HuePicker.Visibility = Visibility.Hidden;
                return;
            }

            clr = ((Color)SelectedColor).GetUniColor();

            var nc = NamedColor.FindColor(clr, NameResolution == ColorNameResolution.Closest);

            if (nc != null)
            {
                SelectedColorName = nc.Name;
            }
            else
            {
                SelectedColorName = clr.ToString(UniColorFormatOptions.HexRgbWebFormat);
            }

            if (cpRender == null)
            {
                return;
            }

            HSVDATA  hsv1 = ColorToHSV(clr);
            HSVDATA  hsv2;
            HSVDATA  hsv3;
            HSVDATA? hsv4 = null;
            HSVDATA? hsv5 = null;
            UniColor uc;

            ColorPickerElement cel = new ColorPickerElement();

            foreach (var c in cpRender.Elements)
            {
                uc = c.Color;

                hsv2 = ColorToHSV(uc);
                hsv3 = (hsv1 - hsv2).Abs();

                if (hsv4 == null)
                {
                    hsv4 = hsv3;
                }
                else if (hsv3 < hsv4)
                {
                    hsv5 = hsv2;
                    hsv4 = hsv3;
                    cel  = c;
                }

                if (selc == uc)
                {
                    cel = c;
                    break;
                }
            }

            if (Mode == ColorPickerMode.HueWheel && !double.IsNaN(ActualWidth) && !double.IsNaN(ActualHeight) && ActualWidth != -1 && ActualHeight != -1)
            {
                if (hsv5 is HSVDATA hsv)
                {
                    Point.Visibility     = Surround.Visibility = Visibility.Hidden;
                    HuePicker.Visibility = Visibility.Visible;
                    int hp = HuePointerSize;

                    PolarCoordinates pc = new PolarCoordinates();

                    double arc = hsv.Hue - HueOffset;
                    if (arc < 0)
                    {
                        arc += 360;
                    }

                    int rad;
                    int h = (int)ActualHeight, w = (int)ActualWidth;

                    if (h < w)
                    {
                        rad = h / 2;
                        w   = h;
                    }
                    else
                    {
                        rad = w / 2;
                        h   = w;
                    }

                    pc.Arc    = arc;
                    pc.Radius = rad;

                    var lc = pc.ToScreenCoordinates(new Rect(0, 0, w, h));

                    if (lc.X < (w / 2))
                    {
                        lc.X -= hp;
                    }

                    if (lc.Y < (h / 2))
                    {
                        lc.Y -= hp;
                    }

                    HuePicker.SetValue(Canvas.LeftProperty, lc.X);
                    HuePicker.SetValue(Canvas.TopProperty, lc.Y);

                    HueSize.ScaleX = (HuePointerSize / 5);
                    HueSize.ScaleY = (HuePointerSize / 5);

                    HueAngle.Angle = pc.Arc;
                }
            }
            else
            {
                Point.Visibility     = Surround.Visibility = Visibility.Visible;
                HuePicker.Visibility = Visibility.Hidden;

                Point.SetValue(Canvas.LeftProperty, (double)cel.Center.X);
                Point.SetValue(Canvas.TopProperty, (double)cel.Center.Y);

                Surround.SetValue(Canvas.LeftProperty, (double)cel.Center.X - 8);
                Surround.SetValue(Canvas.TopProperty, (double)cel.Center.Y - 8);

                Surround.Stroke = Point.Stroke = new SolidColorBrush((Color)SelectedColor);
                selectedElement = cel;
            }
        }
Esempio n. 24
0
 public Projectile(long id, int level, PolarCoordinates position)
 {
     this.ID = id;
     this.Level = level;
     this.Position = position;
 }
        public void DrawPolarPlot(double[] mag1, double[] ang1)
        {
            try
            {
                RemovePreviousObjects();
                chartVu = this;

                Font     theLabelFont = new Font("Courier", 10, FontStyle.Regular);
                string[] sarrxlab     = new string[mag1.Length];
                int      nump1        = mag1.Length;

                for (int i = 0; i < nump1; i++)
                {
                    sarrxlab[i] = "Mag " + mag1[i].ToString() + ", Angle " + ang1[i].ToString();
                    ang1[i]     = ChartSupport.ToRadians((double)ang1[i]);
                }
                theFont = new Font("Microsoft Sans Serif", 10, FontStyle.Bold);
                chartVu = this;

                SimpleDataset Dataset1 = new SimpleDataset("First", mag1, ang1);
                pPolarTransform = new PolarCoordinates();
                pPolarTransform.SetGraphBorderDiagonal(0.25, .2, .75, 0.8);

                background = new Background(pPolarTransform, ChartObj.GRAPH_BACKGROUND, GraphBG1, GraphBG2, GraphBGDir);
                chartVu.AddChartObject(background);

                plotbackground = new Background(pPolarTransform, ChartObj.PLOT_BACKGROUND, ChartBG1, ChartBG2, ChartBGDir);
                chartVu.AddChartObject(plotbackground);

                pPolarTransform.AutoScale(Dataset1);

                pPolarAxis = pPolarTransform.GetCompatibleAxes();
                pPolarAxis.SetColor(_AxisColor);
                chartVu.AddChartObject(pPolarAxis);

                pPolarGrid = new PolarGrid(pPolarAxis, PolarGrid.GRID_MAJOR);
                pPolarGrid.SetColor(_AxisColor);
                chartVu.AddChartObject(pPolarGrid);

                pPolarAxisLabels = (PolarAxesLabels)pPolarAxis.GetCompatibleAxesLabels();
                pPolarAxisLabels.SetColor(_AxisColor);
                chartVu.AddChartObject(pPolarAxisLabels);

                ChartAttribute attrib1 = new ChartAttribute(Color.Blue, 2, 0);

                ChartAttribute attrib2 = new ChartAttribute(Color.Red, .5, 0, Color.Red);
                attrib2.SetFillFlag(true);

                thePlot2 = new PolarScatterPlot(pPolarTransform, Dataset1, ChartObj.CIRCLE, attrib2);
                chartVu.AddChartObject(thePlot2);

                PolarLinePlot thePlot1 = new PolarLinePlot(pPolarTransform, Dataset1, attrib1);
                chartVu.AddChartObject(thePlot1);

                findObj = new CustomFindObj1(chartVu, sarrxlab);
                findObj.SetDataToolTipFormat(ChartObj.DATA_TOOLTIP_CUSTOM);
                findObj.SetEnable(true);
                chartVu.SetCurrentMouseListener(findObj);

                if (_ChartFooter != null)
                {
                    ChartTitle footer = new ChartTitle(pPolarTransform, theFont, _ChartFooter);
                    footer.SetColor(Color.Black);
                    footer.SetTitleType(ChartObj.CHART_FOOTER);
                    footer.SetTitlePosition(ChartObj.CENTER_GRAPH);
                    footer.SetTitleOffset(8);
                    chartVu.AddChartObject(footer);
                }
                this.SetResizeMode(ChartObj.NO_RESIZE_OBJECTS);
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Sets the Camera Source to a depth map showing contours.
        /// Directly accesses the underlying image buffer of the DepthFrame to
        /// create a displayable bitmap.
        /// This function requires the /unsafe compiler option as we make use of direct
        /// access to the native memory pointed to by the depthFrameData pointer.
        /// </summary>
        /// <param name="depthFrameData">Pointer to the DepthFrame image data</param>
        /// <param name="depthFrameDataSize">Size of the DepthFrame image data</param>
        /// <param name="minDepth">The minimum reliable depth value for the frame</param>
        /// <param name="maxDepth">The maximum reliable depth value for the frame</param>
        private unsafe void ProcessContourFrameData(DepthFrame depthFrame, IntPtr depthFrameData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth)
        {
            // depth frame data is a 16 bit value
            ushort *frameData = (ushort *)depthFrameData;

            // convert depth to a visual representation

            /*for (int i = 0; i < (int)(depthFrameDataSize / this.depthFrameDescription.BytesPerPixel); ++i)
             * {
             *  // Get the depth for this pixel
             *  ushort depth = frameData[i];
             *
             *  // To convert to a byte, we're mapping the depth value to the byte range.
             *  // Values outside the reliable depth range are mapped to 0 (black).
             *  this.depthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? (depth / MapDepthToByte) : 0);
             * }*/

            int depth;
            int gray;
            int loThreshold   = 25;
            int hiThreshold   = 1600;
            int bytesPerPixel = 4;

            byte[] rgb          = new byte[3];
            byte[] enhPixelData = new byte[depthFrame.FrameDescription.Width * depthFrame.FrameDescription.Height * bytesPerPixel];

            for (int i = 0, j = 0; i < (int)(depthFrameDataSize / this.depthFrameDescription.BytesPerPixel); i++, j += bytesPerPixel)
            {
                depth = frameData[i] >> 1;

                if (depth < loThreshold || depth > hiThreshold)
                {
                    gray = 0xFF;
                    //gray = 0;
                }
                else
                {
                    gray = (255 * depth / 0xFFF);
                }
                enhPixelData[j] = (byte)gray;

                enhPixelData[j + 1] = (byte)gray;
                enhPixelData[j + 2] = (byte)gray;
            }

            /*camera.Source = BitmapSource.Create(depthFrame.FrameDescription.Width, depthFrame.FrameDescription.Height,
             * 96, 96, PixelFormats.Bgr32, null,
             * enhPixelData,
             * depthFrame.FrameDescription.Width * bytesPerPixel);*/
            int width  = depthFrame.FrameDescription.Width;
            int height = depthFrame.FrameDescription.Height;

            System.Windows.Media.PixelFormat format = PixelFormats.Bgr32;
            WriteableBitmap colorBitmap             = new WriteableBitmap(width, height,
                                                                          96.0, 96.0, PixelFormats.Bgr32, null);

            colorBitmap.WritePixels(
                new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
                enhPixelData,
                colorBitmap.PixelWidth * sizeof(int),
                0);


            Bitmap             bmp2 = BitmapFromWriteableBitmap(colorBitmap);
            Image <Bgr, Byte>  img  = new Image <Bgr, Byte>(bmp2);
            Image <Gray, Byte> grey = new Image <Gray, Byte>(bmp2.Size);

            CvInvoke.cvInRangeS(img.Ptr, new MCvScalar(0.0, 0.0, 0.0), new MCvScalar(250.0, 250.0, 250.0), grey.Ptr);


            CvInvoke.cvErode(grey.Ptr, grey.Ptr, (IntPtr)null, 4);

            CvInvoke.cvDilate(grey.Ptr, grey.Ptr, (IntPtr)null, 3);
            Image <Gray, Byte> dst  = new Image <Gray, Byte>(grey.Size);
            Image <Rgba, Byte> dst2 = new Image <Rgba, Byte>(grey.Size);

            CvInvoke.cvCanny(grey.Ptr, dst.Ptr, 50, 200, 3);
            CvInvoke.cvCvtColor(dst, dst2, Emgu.CV.CvEnum.COLOR_CONVERSION.CV_GRAY2BGR);

            //  byte a = grey.Data[200, 200, 0];

            using (MemStorage stor = new MemStorage())
            {
                IntPtr lines = CvInvoke.cvHoughLines2(dst.Ptr, stor.Ptr, Emgu.CV.CvEnum.HOUGH_TYPE.CV_HOUGH_STANDARD, 10, (10 * Math.PI) / 180, 50, 50, 10);

                int maxLines = 100;
                for (int i = 0; i < maxLines; i++)
                {
                    IntPtr line = CvInvoke.cvGetSeqElem(lines, i);

                    if (line == IntPtr.Zero)
                    {
                        // No more lines
                        break;
                    }

                    MCvScalar color = new MCvScalar(255, 0, 0);

                    PolarCoordinates     coords = (PolarCoordinates)System.Runtime.InteropServices.Marshal.PtrToStructure(line, typeof(PolarCoordinates));
                    float                rho = coords.Rho, theta = coords.Theta;
                    System.Drawing.Point pt1 = new System.Drawing.Point();
                    System.Drawing.Point pt2 = new System.Drawing.Point();
                    double               a = Math.Cos(theta), b = Math.Sin(theta);
                    double               x0 = a * rho, y0 = b * rho;
                    pt1.X = (int)(x0 * 10 + 100000 * (-b));
                    pt1.Y = (int)(y0 * 10 + 100000 * (a));
                    pt2.X = (int)(x0 * 10 - 100000 * (-b));
                    pt2.Y = (int)(y0 * 10 - 100000 * (a));

                    //PolarCoordinates coords2= (PolarCoordinates)System.Runtime.InteropServices.Marshal.PtrToStructure(line2, typeof(PolarCoordinates));
                    // CvInvoke.cvLine(dst2, new System.Drawing.Point((int)coords1.Rho, (int)coords1.Theta), new System.Drawing.Point((int)coords2.Rho, (int)coords2.Theta), color, 3, LINE_TYPE.EIGHT_CONNECTED, 8);
                    CvInvoke.cvLine(dst2, pt1, pt2, color, 3, LINE_TYPE.CV_AA, 8);
                    //LineSegment2D line = new LineSegment2D( new System.Drawing.Point((int)coords1.Rho, (int)coords1.Theta), new System.Drawing.Point((int)coords2.Rho, (int)coords2.Theta));
                    //dst2.Draw(line, new Rgba(255, 0, 0,0), 5);
                }
            }
            camera.Source = ToBitmapSource3(dst);
        }
Esempio n. 27
0
        /// <summary>
        /// Calculate and position the polygon sections, based on geometry, for the current size, position, and number of bars.
        /// </summary>
        /// <remarks></remarks>
        private void CalculateSections()
        {
            var             s = _refSize;
            PointCollection pc;
            int             d = (int)(Sections - 1L);
            Polygon         p;
            double          wHeight = s.Height - Blunting;
            double          wWidth  = s.Width;
            SolidColorBrush bc      = (SolidColorBrush)Application.Current.Resources["TrippLiteLcdType"];
            // ' the width of each section will be calculated here, subtracting initial width by the spacing
            var               pol = PolarCoordinates.ToPolarCoordinates(wWidth, wHeight);
            double            w   = (wWidth - SectionSpacing * (Sections - 1L)) / Sections;
            double            sw  = SectionSpacing;
            LinearCoordinates pt;
            int               i;
            double            x = 0d;
            // ' calculate from hypoteneuse side.
            double fr    = pol.Radius / wWidth;
            var    cblin = CalcBars(LoadValue, (int)Sections) - 1;

            this.BarsArea.Children.Clear();

            System.Threading.Thread.Sleep(0);

            var c = (int)(Sections - 1L);

            for (i = 0; i <= c; i++)
            {
                // ' fresh point collection
                pc = new PointCollection();
                p  = _polyCache[i];

                pol.Radius  = x + w;
                pol.Radius *= fr;

                pt = PolarCoordinates.ToLinearCoordinates(pol);

                pc.Add(new Point(x, s.Height));
                pc.Add(new Point(pt.X, s.Height));
                pc.Add(new Point(pt.X, Math.Max(0d, wHeight - pt.Y)));

                pol.Radius  = x;
                pol.Radius *= fr;

                pt = PolarCoordinates.ToLinearCoordinates(pol);

                pc.Add(new Point(pt.X, Math.Max(0d, wHeight - pt.Y)));
                pc.Add(new Point(pt.X, s.Height));

                p.Points = pc;
                p.Fill   = bc;
                p.Effect = this.BackingBar.Effect;

                if (cblin < i)
                {
                    p.Opacity = 0.33d;
                }
                else
                {
                    p.Opacity = 1d;
                }

                this.BarsArea.Children.Add(p);
                x += w;
                x += sw;
            }
        }