Пример #1
0
        public void FindFirstPlane_Simplex_ReturnHyperplane(Point[] points, Hyperplane[] expected)
        {
            PlaneFinder planeFinder = new PlaneFinder();

            Hyperplane result = planeFinder.FindFirstPlane(points.ToPlanePoint());

            expected.Should().Contain(result);
        }
Пример #2
0
        public void FindClosestPlane_ToLocation(double locLong, double locLat)
        {
            var loc = new Location()
            {
                Longitude = locLong, Latitude = locLat
            };

            var data = @"{'time':1526079430,'states':[['ab1644','','United States',1526079426,1526079429,-87.8424,42.0282,1013.46,false,118.95,36.03,9.75,null,944.88,'5373',false,0],['ac96b8','AAL2441 ','United States',1526079429,1526079429,-84.9193,35.5556,11277.6,false,224.61,292.63,0,null,11711.94,'1640',true,0]]}";

            var pf = new  PlaneFinder(data, loc, new EuclideanDistanceCalculator());

            var p = pf.FindClosestPlane();

            // output.WriteLine(p.ToString());

            Assert.Equal("United States", p.CountryOfOrigin);
            Assert.Equal("ac96b8", p.ICao24);
        }
Пример #3
0
    /// <summary>
    /// Iterator block which analyzes the spatial mesh to find understandable surface planes.
    /// </summary>
    /// <returns>A completion event</returns>
    private IEnumerator CreateSurfacePlanesRoutine()
    {
        ResetSurfacePlaneContent();

        // Pause work, and continue on the next frame
        yield return(null);

        float start = Time.realtimeSinceStartup;

        // Get the mesh filters from the spatial observer
        List <MeshFilter>           filters  = observer.GetMeshFilters();
        List <PlaneFinder.MeshData> meshData = new List <PlaneFinder.MeshData>();

        foreach (MeshFilter filter in filters)
        {
            // Fix spatial mesh normals to get correct plane orientation
            filter.mesh.RecalculateNormals();
            // Extract the relevant meshdata from the mesh filter
            meshData.Add(new PlaneFinder.MeshData(filter));

            // If too much time has passed, we need to return control to the main game loop.
            if ((Time.realtimeSinceStartup - start) > FRAME_TIME)
            {
                // Pause our work, and continue on the next frame
                yield return(null);

                start = Time.realtimeSinceStartup;
            }
        }

        // Start the find plane task and wait till it returns the bounded planes
        Task <BoundedPlane[]> boundedPlaneFinding = Task.Run(() => PlaneFinder.FindBoundedPlanes(meshData, SNAP_TO_GRAVITY_THRESHOLD, minArea));

        while (boundedPlaneFinding.IsCompleted == false)
        {
            yield return(false);
        }
        BoundedPlane[] boundedPlanes = boundedPlaneFinding.Result;

        // Pause work here, and continue on the next frame.
        yield return(null);

        start = Time.realtimeSinceStartup;

        FindFloorAndCeilingPosition(boundedPlanes);

        // Create a surface plane for each bounded plane and add them to the detected surface planes
        foreach (BoundedPlane boundedPlane in boundedPlanes)
        {
            SurfacePlane surfacePlane = new SurfacePlane(ClassifySurfacePlane(boundedPlane), boundedPlane.Plane, boundedPlane.Bounds, roomTagPrefab, roomTagParent.transform);
            detectedSurfacePlanes.Add(surfacePlane);

            // If too much time has passed, we need to return control to the main game loop
            if ((Time.realtimeSinceStartup - start) > FRAME_TIME)
            {
                // Pause our work here, and continue making additional planes on the next frame
                yield return(null);

                start = Time.realtimeSinceStartup;
            }
        }

        CreateSurfacePlaneObjects();

        Debug.Log("Finished creating surface planes.");
        isCreatingPlanes = false;

        // Creating surface planes is done and triggers the completion event
        EventHandler handler = CreateSurfacePlanesCompletedEvent;

        if (handler != null)
        {
            handler(this, EventArgs.Empty);
        }
    }
Пример #4
0
        public void Test_WhenCall_ReturnIndexVector()
        {
            PlanePoint[] points = new PlanePoint[] {
                new PlanePoint(new double[] { 5, 1, 1, 1, 1 }),
                new PlanePoint(new double[] { 1, 5, 1, 1, 1 }),
                new PlanePoint(new double[] { 5, 5, 1, 1, 1 }),
                new PlanePoint(new double[] { 1, 1, 5, 1, 1 }),
                new PlanePoint(new double[] { 5, 1, 5, 1, 1 }),
                new PlanePoint(new double[] { 1, 5, 5, 1, 1 }),
                new PlanePoint(new double[] { 5, 5, 5, 1, 1 }),
                new PlanePoint(new double[] { 1, 1, 1, 5, 1 }),
                new PlanePoint(new double[] { 5, 1, 1, 5, 1 }),
                new PlanePoint(new double[] { 1, 5, 1, 5, 1 }),
                new PlanePoint(new double[] { 5, 5, 1, 5, 1 }),
                new PlanePoint(new double[] { 1, 1, 5, 5, 1 }),
                new PlanePoint(new double[] { 1, 1, 1, 1, 1 }),
                new PlanePoint(new double[] { 5, 1, 5, 5, 1 }),
                new PlanePoint(new double[] { 1, 5, 5, 5, 1 }),
                new PlanePoint(new double[] { 5, 5, 5, 5, 1 }),
                new PlanePoint(new double[] { 1, 1, 1, 1, 5 }),
                new PlanePoint(new double[] { 5, 1, 1, 1, 5 }),
                new PlanePoint(new double[] { 1, 5, 1, 1, 5 }),
                new PlanePoint(new double[] { 5, 5, 1, 1, 5 }),
                new PlanePoint(new double[] { 1, 1, 5, 1, 5 }),
                new PlanePoint(new double[] { 5, 1, 5, 1, 5 }),
                new PlanePoint(new double[] { 1, 5, 5, 1, 5 }),
                new PlanePoint(new double[] { 5, 5, 5, 1, 5 }),
                new PlanePoint(new double[] { 1, 1, 1, 5, 5 }),
                new PlanePoint(new double[] { 5, 1, 1, 5, 5 }),
                new PlanePoint(new double[] { 1, 5, 1, 5, 5 }),
                new PlanePoint(new double[] { 5, 5, 1, 5, 5 }),
                new PlanePoint(new double[] { 1, 1, 5, 5, 5 }),
                new PlanePoint(new double[] { 5, 1, 5, 5, 5 }),
                new PlanePoint(new double[] { 1, 5, 5, 5, 5 }),
                new PlanePoint(new double[] { 5, 5, 5, 5, 5 }),
            };


            //PlaneFinder planeFinder = new PlaneFinder();
            //Hyperplane result = planeFinder.FindFirstPlane(points.ToPlanePoint());

            Stopwatch sp = new Stopwatch();

            // sp.Start();
            //
            // sp.Stop();
            //
            // double first = sp.ElapsedMilliseconds;
            sp.Reset();
            sp.Start();
            PlaneFinder planeFinder1 = new PlaneFinder();
            Hyperplane  result1      = planeFinder1.FindFirstPlane(points.ToPlanePoint());

            sp.Stop();


            double sec = sp.ElapsedMilliseconds;

            sp.Reset();
            sp.Start();
            PlaneFinder planeFinder2 = new PlaneFinder();
            Hyperplane  result2      = planeFinder1.FindFirstPlane(points.ToPlanePoint());

            sp.Stop();

            double sec2 = sp.ElapsedMilliseconds;

            Assert.AreEqual(points[2], result1);
        }