예제 #1
0
        public void TestSimpleTriangulation()
        {
            var a = new Point3D(2, 0, 2);
            var b = new Point3D(12, 0, 3);
            var c = new Point3D(10, 10, 1);
            var d = new Point3D(2, 20, 4);
            var e = new Point3D(12, 20, 5);

            var points = new [] { a, b, c, d, e };

            SourceSurface surface = new SourceSurface(points);

            DefaultTriangulation triangulation = new DefaultTriangulation();

            var result = triangulation.GetTriangulatedSurface(surface, triangulation.GetDefaultOptions());

            Triangle3D[] triangles = new [] { new Triangle3D(a, b, c), new Triangle3D(d, e, c), new Triangle3D(a, d, c), new Triangle3D(b, e, c) };

            Assert.AreEqual(triangles.Length, result.Triangles.Length);

            foreach (var triangle in triangles)
            {
                Assert.True(result.Triangles.Any(t => t.AreEqual(triangle)));
            }
        }
예제 #2
0
파일: MathTests.cs 프로젝트: tihilv/Pat
        public void TestRealVolumeDiff()
        {
            CsvDataSource csvDataSource = new CsvDataSource();
            CsvOptions    csvOptions    = (CsvOptions)csvDataSource.GetDefaultOptions();

            csvOptions.FileName  = Path.Combine(TestDir, "depthvalues.csv");
            csvOptions.GridStep  = "200 m";
            csvOptions.Separator = " ";

            DefaultTriangulation triangulation = new DefaultTriangulation();

            SourceSurface surfaceTop             = csvDataSource.GetSurface(csvOptions);
            var           triangulatedSurfaceTop = triangulation.GetTriangulatedSurface(surfaceTop, triangulation.GetDefaultOptions());

            SourceSurfaceMover mover = new SourceSurfaceMover();
            var moverOptions         = (SourceSurfaceMoverOptions)mover.GetDefaultOptions();

            moverOptions.Z = "100 m";
            SourceSurface surfaceBottom             = mover.GetModifiedSurface(surfaceTop, moverOptions);
            var           triangulatedSurfaceBottom = triangulation.GetTriangulatedSurface(surfaceBottom, triangulation.GetDefaultOptions());

            IVolumeService service = new VolumeService();

            var topVolume    = service.GetVolumeUnderSurface(triangulatedSurfaceTop, 10000);
            var bottomVolume = service.GetVolumeUnderSurface(triangulatedSurfaceBottom, 10000);

            var diff = (int)(topVolume - bottomVolume);

            Assert.AreEqual(200 * 200 * 100 * 15 * 25, diff);
        }
예제 #3
0
        public SourceSurface GetModifiedSurface(SourceSurface surface, IOptions options)
        {
            SourceSurfaceMoverOptions smOptions = (SourceSurfaceMoverOptions)options;

            var moveVector = new Point3D(smOptions.X, smOptions.Y, smOptions.Z);

            return(new SourceSurface(surface.Points.Select(p => p + moveVector).ToArray()));
        }
예제 #4
0
        void AssertSimpleSurface(SourceSurface sourceSurface)
        {
            var points = new []
            {
                new Point3D(0, 0, 1), new Point3D(100, 0, 2), new Point3D(200, 0, 3), new Point3D(0, 100, 4), new Point3D(100, 100, 5), new Point3D(200, 100, 6)
            };

            Assert.AreEqual(6, sourceSurface.Points.Length);

            foreach (var point in points)
            {
                Assert.True(sourceSurface.Points.Any(p => p.AreEqual(point)));
            }
        }
예제 #5
0
        public void TestCsvImportSeparator()
        {
            CsvDataSource csvDataSource = new CsvDataSource();
            CsvOptions    options       = (CsvOptions)csvDataSource.GetDefaultOptions();

            options.FileName         = Path.Combine(TestDir, "simpleSurface_separator.csv");
            options.GridStep         = "100 m";
            options.Separator        = ";";
            options.HeightMultiplier = "1 m";

            SourceSurface result = csvDataSource.GetSurface(options);

            AssertSimpleSurface(result);
        }
예제 #6
0
        public void TestRealTriangulation()
        {
            CsvDataSource csvDataSource = new CsvDataSource();
            CsvOptions    options       = (CsvOptions)csvDataSource.GetDefaultOptions();

            options.FileName  = Path.Combine(TestDir, "depthvalues.csv");
            options.GridStep  = "200 ft";
            options.Separator = " ";

            SourceSurface surface = csvDataSource.GetSurface(options);

            DefaultTriangulation triangulation = new DefaultTriangulation();

            var result = triangulation.GetTriangulatedSurface(surface, triangulation.GetDefaultOptions());

            Assert.AreEqual(15 * 25 * 2, result.Triangles.Length); // 16 x 26 points transformed to 15 x 25 rectangles, each is splitted into 2 triangles.
        }
예제 #7
0
        public void TestFailedTriangulation()
        {
            var a = new Point3D(2, 0, 2);
            var b = new Point3D(3, 1, 3);
            var c = new Point3D(4, 2, 1);
            var d = new Point3D(5, 3, 4);
            var e = new Point3D(6, 4, 5);

            var points = new [] { a, b, c, d, e };

            SourceSurface surface = new SourceSurface(points);

            DefaultTriangulation triangulation = new DefaultTriangulation();

            var result = triangulation.GetTriangulatedSurface(surface, triangulation.GetDefaultOptions());

            Assert.AreEqual(0, result.Triangles.Length);
        }
예제 #8
0
        public TriangulatedSurface GetTriangulatedSurface(SourceSurface sourceSurface, IOptions options)
        {
            var vertices = sourceSurface.Points.Select(p => new Vertex(p)).ToList();

            var triangulation = MIConvexHull.Triangulation.CreateDelaunay(vertices, Equality.Epsilon);

            List <Triangle3D> triangles = new List <Triangle3D>();

            foreach (var cell in triangulation.Cells)
            {
                if (cell.Vertices.Length != 3)
                {
                    throw new Exception($"Cell vertices number is not 3. Triangulation failed.");
                }

                triangles.Add(new Triangle3D(cell.Vertices[0].OriginalPoint, cell.Vertices[1].OriginalPoint, cell.Vertices[2].OriginalPoint));
            }

            return(new TriangulatedSurface(triangles.ToArray()));
        }
예제 #9
0
        public void TestSurfaceMover()
        {
            var points = new Point3D[]
            {
                new Point3D(0, 0, 1), new Point3D(100, 0, 2), new Point3D(200, 0, 3), new Point3D(0, 100, 4), new Point3D(100, 100, 5), new Point3D(200, 100, 6)
            };

            SourceSurface surface = new SourceSurface(points);

            SourceSurfaceMover        mover   = new SourceSurfaceMover();
            SourceSurfaceMoverOptions options = (SourceSurfaceMoverOptions)mover.GetDefaultOptions();

            options.X = "10 m";
            options.Y = "8 m";
            options.Z = "3 m";

            var newSurface = mover.GetModifiedSurface(surface, options);

            for (var index = 0; index < points.Length; index++)
            {
                var point = points[index];
                Assert.True(new Point3D(point.X + 10, point.Y + 8, point.Z + 3).AreEqual(newSurface.Points[index]));
            }
        }