public void FitTopCircle()
    {
        boundary2 = IExtension.GetBoundary(img);
        topCircle = SolveTopCircle();
        m_renderEngine.DrawPoints(topCircle.CirclePoints, Color.yellow);
        //List<Vector2> circle2d = m_projector.GetProjectionPoints_2D(topCircle.CirclePoints);
        //Image<Bgr, byte> blobimg = new Image<Bgr, byte>(this.img.Width, this.img.Height);

        //foreach (Vector2 p in circle2d)
        //{
        //    int i = (int)p.y;
        //    int j = (int)p.x;
        //    blobimg[i, j] = new Bgr(255, 255, 255);
        //}

        //blobimg.Save("C:/Users/Dell/Desktop/blob.jpg");
        //foreach (Vector2 p in boundary2)
        //{
        //    int i = (int)p.y;
        //    int j = (int)p.x;
        //    blobimg[i, j] = new Bgr(0, 0, 255);
        //}
        //blobimg.Save("C:/Users/Dell/Desktop/blob2.jpg");


        Optimize();
        ReOptimize();
        //topCircle.Save(imgPath);
    }
Exemplo n.º 2
0
 // Token: 0x060000CA RID: 202 RVA: 0x000049EF File Offset: 0x00002BEF
 public CircleCurve3(Circle3 circle)
 {
     this.Origin = circle.Center;
     this.UnitX  = circle.UnitU;
     this.UnitY  = circle.UnitV;
     this.Radius = circle.Radius;
 }
    public void Optimize()
    {
        // Init FOV
        m_engine.m_fovOptimizer.SetFOV(20);

        double thetax, thetay, thetaz;

        Utility.NormalToRotation(topCircle.Normal, out thetax, out thetay, out thetaz);
        start_dire = ComputeStartDirecFromAxis(axis);
        float fov_init = m_projector.m_mainCamera.fieldOfView;

        // Optimal Solution
        double[] bndl = new double[] { 0, 0, 0, 0.001, 1 / fov_optimal_scale };
        double[] x    = new double[] { thetax, thetay, thetaz, topCircle.Radius, fov_init / fov_optimal_scale }; //add center
        double[] bndu = new double[] { Mathf.PI, Mathf.PI, Mathf.PI, 10, 179 / fov_optimal_scale };

        int funNum = 4;

        double diffstep = 0.0002;
        double epsg     = 0.000000000001;
        double epsf     = 0;
        double epsx     = 0;
        int    maxits   = 0;

        alglib.minlmstate  state;
        alglib.minlmreport rep;

        //set timer
        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        stopwatch.Start();
        Inter_Num = 0;
        // Do the optima
        alglib.minlmcreatev(funNum, x, diffstep, out state);
        alglib.minlmsetbc(state, bndl, bndu);
        alglib.minlmsetcond(state, epsg, epsf, epsx, maxits);
        alglib.minlmoptimize(state, function_project, null, null);
        alglib.minlmresults(state, out x, out rep);
        stopwatch.Stop();
        if (!m_engine.m_is_quiet)
        {
            Debug.Log("End fitting , Total time:" + stopwatch.ElapsedMilliseconds / 1000.0 + "s");
        }

        // Update FOV
        m_engine.m_fovOptimizer.SetFOV((float)x[4] * fov_optimal_scale);
        fov_face = (float)x[4] * fov_optimal_scale;

        // Update Circle
        Vector3 center = Utility.NewVector3(topCircle.Center);

        Vector3 normal = Utility.RotationToNormal(x[0], x[1], x[2]); normal.Normalize();
        //Vector3 normal = new Vector3((float)x[0], (float)x[1], (float)x[2]); normal.Normalize();
        float radius = (float)x[3];

        topCircle       = new Circle3(center, radius, new Plane(normal, center));
        CirclePoints_2d = m_projector.WorldToImage(topCircle.CirclePoints);

        m_renderEngine.DrawLine(axis.First(), axis.First() + 500 * start_dire.normalized, Color.red);
        m_renderEngine.DrawLine(topCircle.Center, topCircle.Center + 2 * topCircle.Normal, Color.blue);
    }
Exemplo n.º 4
0
        private void OnDrawGizmos()
        {
            Vector3   v0       = V0.position;
            Vector3   v1       = V1.position;
            Vector3   v2       = V2.position;
            Triangle3 triangle = CreateTriangle3(V0, V1, V2);

            Circle3 circumscribed;
            bool    b0 = Circle3.CreateCircumscribed(v0, v1, v2, out circumscribed);
            Circle3 inscribed;
            bool    b1 = Circle3.CreateInscribed(v0, v1, v2, out inscribed);

            FiguresColor();
            DrawTriangle(ref triangle);

            ResultsColor();
            if (b0)
            {
                DrawCircle(ref circumscribed);
            }
            if (b1)
            {
                DrawCircle(ref inscribed);
            }

            LogInfo("Circumscribed: " + b0 + "   Inscribed: " + b1);
        }
Exemplo n.º 5
0
        internal SphereArc GetArc(GraphicsDevice graphicsDevice, double x1, double y1, double x2, double y2)
        {
            Vector3  across       = Unproject(graphicsDevice, new Vector3((float)x2, (float)y2, 1)) - Unproject(graphicsDevice, new Vector3((float)x1, (float)y1, 1));
            Vector3d into         = CastFromCamera(graphicsDevice, new Vector2((float)x1, (float)y1)).Direction; // any vector along our slice that points away from the camera
            Vector3d normal       = Vector3d.Cross(new Vector3d(across), into);
            Vector3d center       = CastFromCamera(graphicsDevice, new Vector2((float)x1, (float)y1)).Position;
            var      plane        = new ZMath.Plane(center, normal);
            Circle3  intersection = plane.GetUnitSphereIntersection();

            if (intersection == null)
            {
                return(null);
            }
            Vector3d[] tangents  = intersection.GetTangents(GetPosition(graphicsDevice));
            Vector3[]  projected = tangents.Select(x => Project(graphicsDevice, x.ToVector3())).ToArray();
            Vector3d   xy1       = GetUnitSphereIntersection(graphicsDevice, x1, y1);
            Vector3d   xy2       = GetUnitSphereIntersection(graphicsDevice, x2, y2);

            // TODO: correctly assign start/stop (I think our current logic works for our uses)
            if ((projected[0] - new Vector3((float)x1, (float)y1, 0)).Length() > (projected[1] - new Vector3((float)x1, (float)y1, 0)).Length())
            {
                var temp = tangents[0];
                tangents[0] = tangents[1];
                tangents[1] = temp;
            }
            if (xy1 == null || xy2 == null)
            {
                return(new SphereArc(intersection, tangents[0], tangents[1], true));
            }
            return(new SphereArc(intersection, xy1, xy2, true));
        }
Exemplo n.º 6
0
        private void OnDrawGizmos()
        {
            if (_frames != null)
            {
                for (int i = 0; i < ParametrizationCount; ++i)
                {
                    Vector3 pos = _frames[i].Position;

                    Gizmos.color = Color.red;
                    if (DrawTangents)
                    {
                        Gizmos.DrawLine(pos, pos + _frames[i].Tangent * .5f);
                    }

                    Gizmos.color = Color.green;
                    if (DrawNormals)
                    {
                        Gizmos.DrawLine(pos, pos + _frames[i].Normal * .5f);
                    }

                    Gizmos.color = Color.white;
                    Gizmos.DrawWireSphere(pos, .05f);
                }

                if (DrawCurvatures)
                {
                    Gizmos.color = Color.yellow;
                    CurveFrame frame = _frames[CurvatureIndex];

                    float   rad    = 1f / _curvatures[CurvatureIndex];
                    Circle3 circle = new Circle3(frame.Position + frame.Normal * rad, frame.Binormal, rad);
                    DrawCircle(ref circle, 100);
                }
            }
        }
Exemplo n.º 7
0
        public void TestPlaneDistance()
        {
            Plane  plane    = new Plane(new Vector3d(-0.5 + 5, -0.5 - 5, 20), new Vector3d(1, 1, 0));
            double distance = plane.GetDistanceFromPoint(new Vector3d(0, 0, 0));

            ZAssert.AssertIsClose(distance, 0.5 * Math.Sqrt(2));
            Circle3 intersection = plane.GetUnitSphereIntersection();

            ZAssert.AssertIsClose(intersection.radius, 0.5 * Math.Sqrt(2));
        }
Exemplo n.º 8
0
 // Token: 0x06000108 RID: 264 RVA: 0x00005284 File Offset: 0x00003484
 public Edge3(Circle3 circle)
 {
     this.Orientation    = Orientation.Forward;
     this.CurveOnSurface = null;
     this.Curve          = new CircleCurve3(circle);
     this.StartParameter = 0.0;
     this.EndParameter   = 6.2831853071795862;
     this.StartVertex    = this.Curve.EvalAt(this.StartParameter);
     this.EndVertex      = this.Curve.EvalAt(this.EndParameter);
 }
Exemplo n.º 9
0
    public void DrawCircle(ref Circle3 c, Color color)
    {
        for (int i = 0; i < c.CirclePoints.Count; i++)
        {
            Vertex_Line_Real.Add(c.CirclePoints[i]);
            Color_Line_Real.Add(color);

            int indexNext = (i + 1) % c.CirclePoints.Count;
            Vertex_Line_Real.Add(c.CirclePoints[indexNext]);
            Color_Line_Real.Add(color);
        }
    }
        protected void DrawCircle(ref Circle3 circle, int count = 20)
        {
            float   delta = 2f * Mathf.PI / count;
            Vector3 prev  = circle.Eval(0);

            for (int i = 1; i <= count; ++i)
            {
                Vector3 curr = circle.Eval(i * delta);
                Gizmos.DrawLine(prev, curr);
                prev = curr;
            }
        }
        private void OnDrawGizmos()
        {
            Circle3 circle      = new Circle3(Vector3ex.Zero, Vector3ex.UnitY, Rho);
            Vector3 cartesian   = Mathfex.CylindricalToCartesian(new Vector3(Rho, Phi, Height));
            Vector3 cylindrical = Mathfex.CartesianToCylindrical(cartesian);

            FiguresColor();
            DrawCircle(ref circle);
            ResultsColor();
            DrawSegment(new Vector3(cartesian.x, 0f, cartesian.z), cartesian);
            DrawPoint(cartesian);

            LogInfo("Cartesian: " + cartesian.ToStringEx() + "   Cylindrical: " + cylindrical.ToStringEx());
        }
 private void True_Intersect(Sphere sphereA, Sphere sphereB, Circle3 expected)
 {
     Assert.True(Intersect.SphereSphere(sphereA, sphereB));
     Assert.True(Intersect.SphereSphere(sphereA, sphereB, out IntersectionSphereSphere intersection));
     Assert.AreEqual(IntersectionType.Circle, intersection.type);
     AreEqual(intersection.point, expected.center);
     AreEqual(intersection.normal, expected.normal);
     AreEqual(intersection.radius, expected.radius);
     Assert.True(Intersect.SphereSphere(sphereB, sphereA));
     Assert.True(Intersect.SphereSphere(sphereB, sphereA, out intersection));
     Assert.AreEqual(IntersectionType.Circle, intersection.type);
     AreEqual(intersection.point, expected.center);
     AreEqual(intersection.normal, -expected.normal);
     AreEqual(intersection.radius, expected.radius);
 }
    private void function_withcenter(double[] x, double[] fi, object obj)
    {
        Inter_Num++;
        Vector3 center = new Vector3((float)x[0], (float)x[1], (float)x[2]);
        Vector3 normal = topCircle.Normal;
        double  radius = topCircle.Radius;
        Circle3 myC    = new Circle3(center, (float)radius, new Plane(normal, center), this.boundary2.Count);

        CirclePoints_2d = m_projector.WorldToImage(myC.CirclePoints);
        //double dist_all = 0;
        //for (int i = 0; i < CirclePoints_2d.Count; i++)
        //{
        //    double dist = double.MaxValue;
        //    for (int j = 0; j < boundary2.Count; j++)
        //    {
        //        dist = Math.Min(dist, (CirclePoints_2d[i] - boundary2[j]).sqrMagnitude);
        //    }
        //    dist_all += dist;
        //}

        //// Set Cost function
        //fi[0] = dist_all;

        int notinmask_count = 0;

        for (int i = 0; i < CirclePoints_2d.Count; i++)
        {
            int xx = (int)CirclePoints_2d[i].x;
            xx = Math.Max(0, xx);
            xx = Math.Min(xx, this.img.Width - 1);

            int yy = (int)CirclePoints_2d[i].y;
            yy = Math.Max(0, yy);
            yy = Math.Min(xx, this.img.Height - 1);

            //Debug.Log(yy + " " + xx);

            if (!this.img[yy, xx].Equals(new Gray(255)))
            {
                notinmask_count++;
            }
        }
        fi[0] = notinmask_count / CirclePoints_2d.Count;


        // if (Inter_Num % 20 == 0)
        //Debug.Log(Inter_Num + "|| N: " + x[0] + " " + x[1] + " " + x[2] + " cost:" + dist_all);
    }
Exemplo n.º 14
0
    public void DrawCircle(ref Circle3 c)
    {
        if (c == null)
        {
            return;
        }
        for (int i = 0; i < c.CirclePoints.Count; i++)
        {
            Vertex_Line_Real.Add(c.CirclePoints[i]);
            Color_Line_Real.Add(Color_default);

            int indexNext = (i + 1) % c.CirclePoints.Count;
            Vertex_Line_Real.Add(c.CirclePoints[indexNext]);
            Color_Line_Real.Add(Color_default);
        }
    }
Exemplo n.º 15
0
        private void OnDrawGizmos()
        {
            Vector3 point  = Point.position;
            Circle3 circle = CreateCircle3(Circle);

            Vector3 closestPoint;
            float   dist  = Distance.Point3Circle3(ref point, ref circle, out closestPoint, false);
            float   dist1 = Distance.SqrPoint3Circle3(ref point, ref circle, false);
            float   dist2 = circle.DistanceTo(point, false);

            FiguresColor();
            DrawCircle(ref circle);

            ResultsColor();
            DrawPoint(closestPoint);

            LogInfo(dist + " " + Mathf.Sqrt(dist1) + " " + dist2);
        }
    public void ReOptimize()
    {
        double[] bndl = new double[] { -10, -10, 0 };
        double[] x    = new double[] { topCircle.Center.x, topCircle.Center.y, topCircle.Center.z }; //add center
        double[] bndu = new double[] { 10, 10, 20 };

        int funNum = 1;

        double diffstep = 0.00002;
        double epsg     = 0.000000000001;
        double epsf     = 0;
        double epsx     = 0;
        int    maxits   = 0;

        alglib.minlmstate  state;
        alglib.minlmreport rep;

        //set timer
        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        stopwatch.Start();
        Inter_Num = 0;

        // Do the optima
        alglib.minlmcreatev(funNum, x, diffstep, out state);
        alglib.minlmsetbc(state, bndl, bndu);
        alglib.minlmsetcond(state, epsg, epsf, epsx, maxits);
        alglib.minlmoptimize(state, function_withcenter, null, null);
        alglib.minlmresults(state, out x, out rep);
        stopwatch.Stop();
        if (!m_engine.m_is_quiet)
        {
            Debug.Log("End fitting center, Total time:" + stopwatch.ElapsedMilliseconds / 1000.0 + "s");
        }

        // Update Circle
        Vector3 center = new Vector3((float)x[0], (float)x[1], (float)x[2]);
        Vector3 normal = topCircle.Normal;
        double  radius = topCircle.Radius;

        topCircle       = new Circle3(center, (float)radius, new Plane(normal, center));
        CirclePoints_2d = m_projector.WorldToImage(topCircle.CirclePoints);
    }
        private void OnDrawGizmos()
        {
            Ray3    ray    = CreateRay3(Ray);
            Circle3 circle = CreateCircle3(Circle);

            Ray3Circle3Intr info;
            bool            find = Intersection.FindRay3Circle3(ref ray, ref circle, out info);

            FiguresColor();
            DrawCircle(ref circle);
            DrawRay(ref ray);

            if (find)
            {
                ResultsColor();
                DrawPoint(info.Point);
            }

            LogInfo(info.IntersectionType);
        }
Exemplo n.º 18
0
        private void OnDrawGizmos()
        {
            Line3   line   = CreateLine3(Line);
            Circle3 circle = CreateCircle3(Circle);

            Line3Circle3Intr info;
            bool             find = Intersection.FindLine3Circle3(ref line, ref circle, out info);

            FiguresColor();
            DrawCircle(ref circle);
            DrawLine(ref line);

            if (find)
            {
                ResultsColor();
                DrawPoint(info.Point);
            }

            LogInfo(info.IntersectionType);
        }
Exemplo n.º 19
0
        private void OnDrawGizmos()
        {
            Segment3 segment = CreateSegment3(P0, P1);
            Circle3  circle  = CreateCircle3(Circle);

            Segment3Circle3Intr info;
            bool find = Intersection.FindSegment3Circle3(ref segment, ref circle, out info);

            FiguresColor();
            DrawCircle(ref circle);
            DrawSegment(ref segment);

            if (find)
            {
                ResultsColor();
                DrawPoint(info.Point);
            }

            LogInfo(info.IntersectionType);
        }
Exemplo n.º 20
0
        private void SendButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            FileInfo file = null;

            if (File.Exists(FilePath))
            {
                file = new FileInfo(FilePath);
            }

            if (file != null && file.Length > 0)
            {
                Task.Run(() =>
                {
                    Dispatcher.Invoke(() => SetupPage.IsEnabled   = false);
                    Dispatcher.Invoke(() => SenderPage.IsEnabled  = true);
                    Dispatcher.Invoke(() => CloseButton.IsEnabled = true);
                    for (int i = 0; i < 10; i++)
                    {
                        Dispatcher.Invoke(() => SetupPage.Opacity   -= 0.1);
                        Dispatcher.Invoke(() => CloseButton.Opacity += 0.1);
                        Dispatcher.Invoke(() => MainBorder.Margin    = new Thickness(MainBorder.Margin.Left, MainBorder.Margin.Top, MainBorder.Margin.Right, MainBorder.Margin.Bottom + 12.5));
                        Dispatcher.Invoke(() => MainGrid.Margin      = new Thickness(MainGrid.Margin.Left, MainGrid.Margin.Top + 12.5, MainGrid.Margin.Right, MainGrid.Margin.Bottom));
                        Thread.Sleep(17);
                    }

                    for (int i = 0; i < 10; i++)
                    {
                        Dispatcher.Invoke(() => SenderPage.Opacity += 0.1);
                        Thread.Sleep(17);
                    }

                    Connection.SendMessage(new MessageClass(Connection.ID, UserID, Commands.RFileSend, ID, System.IO.Path.GetFileName(FilePath)));

                    Dispatcher.Invoke(() =>
                    {
                        var opacityAnim            = new DoubleAnimation();
                        opacityAnim.From           = 1;
                        opacityAnim.To             = 0;
                        opacityAnim.Duration       = TimeSpan.FromSeconds(2);
                        opacityAnim.RepeatBehavior = RepeatBehavior.Forever;
                        Circle1.BeginAnimation(Ellipse.OpacityProperty, opacityAnim);

                        var circleAnim            = new DoubleAnimation();
                        circleAnim.From           = 20;
                        circleAnim.To             = 80;
                        circleAnim.Duration       = TimeSpan.FromSeconds(2);
                        circleAnim.RepeatBehavior = RepeatBehavior.Forever;
                        Circle1.BeginAnimation(Ellipse.WidthProperty, circleAnim);
                        Circle1.BeginAnimation(Ellipse.HeightProperty, circleAnim);
                    });

                    Thread.Sleep(670);

                    Dispatcher.Invoke(() =>
                    {
                        var opacityAnim            = new DoubleAnimation();
                        opacityAnim.From           = 1;
                        opacityAnim.To             = 0;
                        opacityAnim.Duration       = TimeSpan.FromSeconds(2);
                        opacityAnim.RepeatBehavior = RepeatBehavior.Forever;
                        Circle2.BeginAnimation(Ellipse.OpacityProperty, opacityAnim);

                        var circleAnim            = new DoubleAnimation();
                        circleAnim.From           = 20;
                        circleAnim.To             = 80;
                        circleAnim.Duration       = TimeSpan.FromSeconds(2);
                        circleAnim.RepeatBehavior = RepeatBehavior.Forever;
                        Circle2.BeginAnimation(Ellipse.WidthProperty, circleAnim);
                        Circle2.BeginAnimation(Ellipse.HeightProperty, circleAnim);
                    });

                    Thread.Sleep(670);

                    Dispatcher.Invoke(() =>
                    {
                        var opacityAnim            = new DoubleAnimation();
                        opacityAnim.From           = 1;
                        opacityAnim.To             = 0;
                        opacityAnim.Duration       = TimeSpan.FromSeconds(2);
                        opacityAnim.RepeatBehavior = RepeatBehavior.Forever;
                        Circle3.BeginAnimation(Ellipse.OpacityProperty, opacityAnim);

                        var circleAnim            = new DoubleAnimation();
                        circleAnim.From           = 20;
                        circleAnim.To             = 80;
                        circleAnim.Duration       = TimeSpan.FromSeconds(2);
                        circleAnim.RepeatBehavior = RepeatBehavior.Forever;
                        Circle3.BeginAnimation(Ellipse.WidthProperty, circleAnim);
                        Circle3.BeginAnimation(Ellipse.HeightProperty, circleAnim);
                    });

                    /*
                     * while (true)
                     * {
                     *  try
                     *  {
                     *      Dispatcher.Invoke(() => Circle1.Width += 1);
                     *      Dispatcher.Invoke(() => Circle1.Height += 1);
                     *      Dispatcher.Invoke(() => Circle1.Opacity -= 0.017);
                     *      if (Dispatcher.Invoke(() => Circle1.Opacity <= 0))
                     *      {
                     *          Dispatcher.Invoke(() => Circle1.Width = 20);
                     *          Dispatcher.Invoke(() => Circle1.Height = 20);
                     *          Dispatcher.Invoke(() => Circle1.Opacity = 1);
                     *      }
                     *      Dispatcher.Invoke(() => Circle2.Width += 1);
                     *      Dispatcher.Invoke(() => Circle2.Height += 1);
                     *      Dispatcher.Invoke(() => Circle2.Opacity -= 0.017);
                     *      if (Dispatcher.Invoke(() => Circle2.Opacity <= 0))
                     *      {
                     *          Dispatcher.Invoke(() => Circle2.Width = 20);
                     *          Dispatcher.Invoke(() => Circle2.Height = 20);
                     *          Dispatcher.Invoke(() => Circle2.Opacity = 1);
                     *      }
                     *      Dispatcher.Invoke(() => Circle3.Width += 1);
                     *      Dispatcher.Invoke(() => Circle3.Height += 1);
                     *      Dispatcher.Invoke(() => Circle3.Opacity -= 0.017);
                     *      if (Dispatcher.Invoke(() => Circle3.Opacity <= 0))
                     *      {
                     *          Dispatcher.Invoke(() => Circle3.Width = 20);
                     *          Dispatcher.Invoke(() => Circle3.Height = 20);
                     *          Dispatcher.Invoke(() => Circle3.Opacity = 1);
                     *      }
                     *
                     *      Thread.Sleep(36);
                     *  }
                     *  catch
                     *  {
                     *      break;
                     *  }
                     * }*/
                }
                         );
            }
            else
            {
                Task.Run(() =>
                {
                    for (int i = 0; i < 10; i++)
                    {
                        Dispatcher.Invoke(() => PathLabel.Opacity -= 0.1);
                        Thread.Sleep(17);
                    }
                    for (int i = 0; i < 10; i++)
                    {
                        Dispatcher.Invoke(() => ErrorLabel.Opacity += 0.1);
                        Thread.Sleep(17);
                    }
                    Thread.Sleep(500);
                    for (int i = 0; i < 10; i++)
                    {
                        Dispatcher.Invoke(() => ErrorLabel.Opacity -= 0.1);
                        Thread.Sleep(17);
                    }
                    for (int i = 0; i < 10; i++)
                    {
                        Dispatcher.Invoke(() => PathLabel.Opacity += 0.1);
                        Thread.Sleep(17);
                    }
                }
                         );
            }
        }
    private void function_project(double[] x, double[] fi, object obj)
    {
        m_engine.m_fovOptimizer.SetFOV((float)x[4] * fov_optimal_scale);
        topCircle = SolveTopCircle();

        // Step 1: Init Params
        Inter_Num++;
        Vector3 center = Utility.NewVector3(topCircle.Center);
        Vector3 normal = Utility.NewVector3(Utility.RotationToNormal(x[0], x[1], x[2])); normal.Normalize();

        double  radius = x[3];
        Circle3 myC    = new Circle3(center, (float)radius, new Plane(normal, center), this.boundary2.Count);

        // Step 2: Do projection
        CirclePoints_2d = m_projector.WorldToImage(myC.CirclePoints);

        // Step 3: Do the evaluation
        //double dist_all = 0;
        //for (int i = 0; i < CirclePoints_2d.Count; i++)
        //{
        //    double dist = double.MaxValue;
        //    for (int j = 0; j < boundary2.Count; j++)
        //    {
        //        dist = Math.Min(dist, (CirclePoints_2d[i] - boundary2[j]).sqrMagnitude);
        //    }
        //    dist_all += dist;
        //}
        //fi[0] = dist_all;

        // Step 3': Mask cover
        int notinmask_count = 0;

        for (int i = 0; i < CirclePoints_2d.Count; i++)
        {
            int xx = (int)CirclePoints_2d[i].x;
            xx = Math.Max(0, xx);
            xx = Math.Min(xx, this.img.Width - 1);

            int yy = (int)CirclePoints_2d[i].y;
            yy = Math.Max(0, yy);
            yy = Math.Min(xx, this.img.Height - 1);

            //Debug.Log(yy + " " + xx);

            if (!this.img[yy, xx].Equals(new Gray(255)))
            {
                notinmask_count++;
            }
        }

        // Step 4: FOV Axis 3D
        //Vector3 sectionNormal = Vector3.Cross(Vector3.Cross(normal, new Vector3(1, 0, 1).normalized),normal);
        //Plane sectionPlane = new Plane(sectionNormal.normalized, center);
        //Vector3 axis_dire = m_projector.Proj2dToPlane_v(sectionPlane, m_projector.WorldToImage(center), start_dire);
        //fi[3] = 10f * Mathf.Min(180 - Vector2.Angle(axis_dire.normalized, normal.normalized), Vector2.Angle(axis_dire.normalized, normal.normalized));
        //fi[3] = 1 / Mathf.Abs(Vector3.Dot(axis_dire.normalized, normal.normalized));

        // Step 4': FOV Axis 2D
        Vector2 center2 = m_projector.WorldToImage(center);
        Vector2 end2    = m_projector.WorldToImage(center + 100 * normal);
        Vector2 normal2 = (end2 - center2).normalized;

        // Set Cost function
        fi[0] = notinmask_count / CirclePoints_2d.Count;
        fi[1] = normal.sqrMagnitude - 1;
        fi[2] = 1 / 40 * radius;
        fi[3] = Mathf.Min(180 - Vector2.Angle(normal2, start_dire.normalized), Vector2.Angle(normal2, start_dire.normalized));
        //Debug.Log("FOV: " + x[4] * fov_optimal_scale + " Cost: " + fi[3]);
    }
Exemplo n.º 22
0
        private SectorBounds GetSectorBounds(GraphicsDevice graphicsDevice, ISector rootSector)
        {
            // apparently we don't want to call this after changing our render target
            double           w         = graphicsDevice.Viewport.Width;
            double           h         = graphicsDevice.Viewport.Height;
            var              leftArc   = camera.GetArc(graphicsDevice, 0, h, 0, 0);
            var              rightArc  = camera.GetArc(graphicsDevice, w, 0, w, h);
            var              topArc    = camera.GetArc(graphicsDevice, 0, 0, w, 0);
            var              bottomArc = camera.GetArc(graphicsDevice, w, h, 0, h);
            List <SphereArc> arcs      = new List <SphereArc>();

            if (leftArc != null)
            {
                arcs.Add(leftArc);
            }
            if (topArc != null)
            {
                arcs.Add(topArc);
            }
            if (rightArc != null)
            {
                arcs.Add(rightArc);
            }
            if (bottomArc != null)
            {
                arcs.Add(bottomArc);
            }
            Circle3 visible = camera.GetUnitSphereVisibleCircle(graphicsDevice);
            double  minX, maxX, minY, maxY;

            if (arcs.Count > 0)
            {
                int cnt = arcs.Count;
                // try and construct the arc segments that connect our disconnected arcs if they are
                for (int i = 0; i < cnt; i++)
                {
                    SphereArc arc1   = arcs[i];
                    SphereArc arc2   = arcs[(i + 1) % cnt];
                    Vector3d  close1 = arc1.stop;
                    Vector3d  close2 = arc2.start;
                    if ((close1 - close2).Length() > 0.01)
                    {
                        Vector3d halfway = (close1 + close2).Normalized();
                        if (close1.Cross(halfway).Dot(camera.GetPosition(graphicsDevice)) > 0)
                        {
                            halfway = -halfway;
                        }
                        arcs.Add(new SphereArc(visible, close1, halfway, true));
                        arcs.Add(new SphereArc(visible, halfway, close2, true));
                    }
                }
                minX = arcs.Min(x => x.Min(y => rootSector.ProjectToLocalCoordinates(y).X));
                maxX = arcs.Max(x => x.Max(y => rootSector.ProjectToLocalCoordinates(y).X));
                minY = arcs.Min(x => x.Min(y => rootSector.ProjectToLocalCoordinates(y).Y));
                maxY = arcs.Max(x => x.Max(y => rootSector.ProjectToLocalCoordinates(y).Y));
            }
            else
            {
                minX = visible.Min(x => rootSector.ProjectToLocalCoordinates(x).X);
                maxX = visible.Max(x => rootSector.ProjectToLocalCoordinates(x).X);
                minY = visible.Min(x => rootSector.ProjectToLocalCoordinates(x).Y);
                maxY = visible.Max(x => rootSector.ProjectToLocalCoordinates(x).Y);
            }
            if (rootSector is MercatorSector)
            {
                if (camera.IsUnitSpherePointVisible(graphicsDevice, new Vector3d(0, 0, 1)))
                {
                    minY = 0;
                    minX = 0;
                    maxX = 1;
                }
                if (camera.IsUnitSpherePointVisible(graphicsDevice, new Vector3d(0, 0, -1)))
                {
                    maxY = 1;
                    minX = 0;
                    maxX = 1;
                }
            }
            return(new SectorBounds(Math.Max(minX, 0), Math.Min(maxX, 1), Math.Max(minY, 0), Math.Min(maxY, 1)));
        }
Exemplo n.º 23
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            NameLabel.Content  = FileName;
            LoadingBar.Maximum = FileSize;

            SmallSize          = SetSmallSize(FileSize);
            BytesLabel.Content = "0 / " + SmallSize.ToString("0.00") + PostSize;

            Connection.SendMessage(new MessageClass(Connection.ID, UserID, Commands.FileOK, ID));
            LastTime = DateTime.Now;
            LastNow  = 0;

            Task.Run(() =>
            {
                Dispatcher.Invoke(() =>
                {
                    var opacityAnim            = new DoubleAnimation();
                    opacityAnim.From           = 0;
                    opacityAnim.To             = 1;
                    opacityAnim.Duration       = TimeSpan.FromSeconds(2);
                    opacityAnim.RepeatBehavior = RepeatBehavior.Forever;
                    Circle1.BeginAnimation(System.Windows.Shapes.Ellipse.OpacityProperty, opacityAnim);

                    var circleAnim            = new DoubleAnimation();
                    circleAnim.From           = 80;
                    circleAnim.To             = 20;
                    circleAnim.Duration       = TimeSpan.FromSeconds(2);
                    circleAnim.RepeatBehavior = RepeatBehavior.Forever;
                    Circle1.BeginAnimation(System.Windows.Shapes.Ellipse.WidthProperty, circleAnim);
                    Circle1.BeginAnimation(System.Windows.Shapes.Ellipse.HeightProperty, circleAnim);
                });

                Thread.Sleep(670);

                Dispatcher.Invoke(() =>
                {
                    var opacityAnim            = new DoubleAnimation();
                    opacityAnim.From           = 0;
                    opacityAnim.To             = 1;
                    opacityAnim.Duration       = TimeSpan.FromSeconds(2);
                    opacityAnim.RepeatBehavior = RepeatBehavior.Forever;
                    Circle2.BeginAnimation(System.Windows.Shapes.Ellipse.OpacityProperty, opacityAnim);

                    var circleAnim            = new DoubleAnimation();
                    circleAnim.From           = 80;
                    circleAnim.To             = 20;
                    circleAnim.Duration       = TimeSpan.FromSeconds(2);
                    circleAnim.RepeatBehavior = RepeatBehavior.Forever;
                    Circle2.BeginAnimation(System.Windows.Shapes.Ellipse.WidthProperty, circleAnim);
                    Circle2.BeginAnimation(System.Windows.Shapes.Ellipse.HeightProperty, circleAnim);
                });

                Thread.Sleep(670);

                Dispatcher.Invoke(() =>
                {
                    var opacityAnim            = new DoubleAnimation();
                    opacityAnim.From           = 0;
                    opacityAnim.To             = 1;
                    opacityAnim.Duration       = TimeSpan.FromSeconds(2);
                    opacityAnim.RepeatBehavior = RepeatBehavior.Forever;
                    Circle3.BeginAnimation(System.Windows.Shapes.Ellipse.OpacityProperty, opacityAnim);

                    var circleAnim            = new DoubleAnimation();
                    circleAnim.From           = 80;
                    circleAnim.To             = 20;
                    circleAnim.Duration       = TimeSpan.FromSeconds(2);
                    circleAnim.RepeatBehavior = RepeatBehavior.Forever;
                    Circle3.BeginAnimation(System.Windows.Shapes.Ellipse.WidthProperty, circleAnim);
                    Circle3.BeginAnimation(System.Windows.Shapes.Ellipse.HeightProperty, circleAnim);
                });

                /*
                 * while (true)
                 * {
                 *  try
                 *  {
                 *      Dispatcher.Invoke(() => Circle1.Width -= 1);
                 *      Dispatcher.Invoke(() => Circle1.Height -= 1);
                 *      Dispatcher.Invoke(() => Circle1.Opacity += 0.017);
                 *      if (Dispatcher.Invoke(() => Circle1.Opacity >= 1))
                 *      {
                 *          Dispatcher.Invoke(() => Circle1.Width = 79);
                 *          Dispatcher.Invoke(() => Circle1.Height = 79);
                 *          Dispatcher.Invoke(() => Circle1.Opacity = 0);
                 *      }
                 *      Dispatcher.Invoke(() => Circle2.Width -= 1);
                 *      Dispatcher.Invoke(() => Circle2.Height -= 1);
                 *      Dispatcher.Invoke(() => Circle2.Opacity += 0.017);
                 *      if (Dispatcher.Invoke(() => Circle2.Opacity >= 1))
                 *      {
                 *          Dispatcher.Invoke(() => Circle2.Width = 79);
                 *          Dispatcher.Invoke(() => Circle2.Height = 79);
                 *          Dispatcher.Invoke(() => Circle2.Opacity = 0);
                 *      }
                 *      Dispatcher.Invoke(() => Circle3.Width -= 1);
                 *      Dispatcher.Invoke(() => Circle3.Height -= 1);
                 *      Dispatcher.Invoke(() => Circle3.Opacity += 0.017);
                 *      if (Dispatcher.Invoke(() => Circle3.Opacity >= 1))
                 *      {
                 *          Dispatcher.Invoke(() => Circle3.Width = 79);
                 *          Dispatcher.Invoke(() => Circle3.Height = 79);
                 *          Dispatcher.Invoke(() => Circle3.Opacity = 0);
                 *      }
                 *
                 *      Thread.Sleep(36);
                 *  }
                 *  catch
                 *  {
                 *      break;
                 *  }
                 * }*/
            });
        }