Exemplo n.º 1
0
        public void Surface_Equal_True_ForTwoTriangles_SharedVertices2()
        {
            // ARRANGE
            ListSurface s1 = new ListSurface();

            s1.AddVertex(new Vector3(0, 0, 0));
            s1.AddVertex(new Vector3(1, 0, 0));
            s1.AddVertex(new Vector3(0, 1, 0));
            s1.AddVertex(new Vector3(1, 1, 0));
            s1.AddTriangle(0, 1, 2);
            s1.AddTriangle(0, 1, 3);
            ListSurface s2 = new ListSurface();

            s2.AddVertex(new Vector3(0, 0, 0));
            s2.AddVertex(new Vector3(1, 0, 0));
            s2.AddVertex(new Vector3(0, 1, 0));
            s2.AddVertex(new Vector3(1, 0, 0));
            s2.AddVertex(new Vector3(1, 1, 0));
            s2.AddTriangle(0, 1, 2);
            s2.AddTriangle(0, 3, 4);

            // ACT
            bool areEqual = ListSurface.AreSurfacesEquivalent(s1, s2);

            // ASSERT
            Assert.IsTrue(areEqual);
        }
Exemplo n.º 2
0
        public void Surface_Equal_False_ForOneVsTwoTriangles()
        {
            // ARRANGE
            ListSurface s1 = new ListSurface();

            s1.AddVertex(new Vector3(0, 0, 0));
            s1.AddVertex(new Vector3(1, 0, 0));
            s1.AddVertex(new Vector3(1, 1, 0));
            s1.AddTriangle(0, 1, 2);
            ListSurface s2 = new ListSurface();

            s2.AddVertex(new Vector3(0, 0, 0));
            s2.AddVertex(new Vector3(1, 0, 0));
            s2.AddVertex(new Vector3(0, 1, 0));
            s2.AddVertex(new Vector3(0, 0, 0));
            s2.AddVertex(new Vector3(1, 0, 0));
            s2.AddVertex(new Vector3(1, 1, 0));
            s2.AddTriangle(0, 1, 2);
            s2.AddTriangle(3, 4, 5);

            // ACT
            bool areEqual = ListSurface.AreSurfacesEquivalent(s1, s2);

            // ASSERT
            Assert.IsFalse(areEqual);
        }
Exemplo n.º 3
0
 public static bool TestSpecific(float[,,] cells, ListSurface expected)
 {
     return(TestSpecific(cells, new List <ListSurface>()
     {
         expected
     }));
 }
Exemplo n.º 4
0
        public void Surface_IsClosed_True_ForEmptySurface()
        {
            // ARRANGE
            ListSurface s = new ListSurface();

            // ACT
            bool isClosed = s.IsClosed();

            // ASSERT
            Assert.IsTrue(isClosed);
        }
Exemplo n.º 5
0
        private void TestDoesntCrash(int a, int b, int c, int d, int e, int f, int g, int h)
        {
            // ARRANGE
            float[,,] cells = new float[, , ] {
                { { a, b }, { c, d } },
                { { e, f }, { g, h } }
            };

            ArrayGrid   grid = new ArrayGrid(cells, Vector3.Zero, Vector3.One);
            ListSurface s    = new ListSurface();

            // ACT & ASSERT
            Assert.DoesNotThrow(() => MarchingCubes.MarchIntoSurface(grid, 0, s));
        }
Exemplo n.º 6
0
        public void Surface_IsClosed_False_ForSingleTriangle()
        {
            // ARRANGE
            ListSurface s = new ListSurface();

            s.AddVertex(0, 0, 0);
            s.AddVertex(0, 1, 0);
            s.AddVertex(1, 0, 0);
            s.AddTriangle(0, 1, 2);

            // ACT
            bool isClosed = s.IsClosed();

            // ASSERT
            Assert.IsFalse(isClosed);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Tests a specific example of a cell. Assumes that delta in the grid is 1, origin is 0 and isovalue is 0
        /// </summary>
        public static bool TestSpecific(float[,,] cells, IEnumerable <ListSurface> expecteds)
        {
            ArrayGrid   grid = new ArrayGrid(cells, Vector3.Zero, Vector3.One);
            ListSurface s    = new ListSurface();

            MarchingCubes.MarchIntoSurface(grid, 0, s);

            foreach (ListSurface e in expecteds)
            {
                if (ListSurface.AreSurfacesEquivalent(e, s))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 8
0
        private void UniformTest(float value, int width, float iso)
        {
            // ARRANGE
            ArrayGrid grid = GenerateUniform(value, width);

            // ACT
            ListSurface s = new ListSurface();

            MarchingCubes.MarchIntoSurface(grid, iso, s);
            int[]     triangles = s.GetTriangles();
            Vector3[] vertices  = s.GetVertices();

            // ASSERT
            Assert.That(triangles, Has.Length.EqualTo(0));
            Assert.That(vertices, Has.Length.EqualTo(0));
        }
Exemplo n.º 9
0
        public void Surface_IsClosed_True_ForBackToBackTriangles()
        {
            // ARRANGE
            ListSurface s = new ListSurface();

            s.AddVertex(0, 0, 0);
            s.AddVertex(0, 1, 0);
            s.AddVertex(1, 0, 0);
            s.AddTriangle(0, 1, 2);
            s.AddTriangle(0, 2, 1);

            // ACT
            bool isClosed = s.IsClosed();

            // ASSERT
            Assert.IsTrue(isClosed);
        }
Exemplo n.º 10
0
        private void SingleNodeCellTest(float valueSingle, float valueOther, int cellVertex, float iso)
        {
            // ARRANGE
            ArrayGrid grid = GenerateSingle(valueSingle, valueOther, cellVertex);

            // ACT
            ListSurface s = new ListSurface();

            MarchingCubes.MarchIntoSurface(grid, iso, s);
            int[]     triangles = s.GetTriangles();
            Vector3[] vertices  = s.GetVertices();

            // ASSERT
            // Should have one triangle with three vertices
            Assert.That(triangles, Has.Length.EqualTo(3));
            Assert.That(vertices, Has.Length.EqualTo(3));
        }
Exemplo n.º 11
0
        private static void JoinInto(ListSurface into, ListSurface from)
        {
            int offset = into.GetVertexCount();

            foreach (Vector3 vertex in from.GetVertices())
            {
                into.AddVertex(vertex);
            }

            int[] triangles = from.GetTriangles();
            for (int i = 0; i < triangles.Length; i += 3)
            {
                into.AddTriangle(triangles[i] + offset,
                                 triangles[i + 1] + offset,
                                 triangles[i + 2] + offset);
            }
        }
Exemplo n.º 12
0
        private static ListSurface GenSurfaceFromEdges(List <Vector3> vertices, List <Tuple <int, int> > edges)
        {
            ListSurface surface = new ListSurface();

            foreach (Vector3 vertex in vertices)
            {
                surface.AddVertex(vertex);
            }

            List <Tuple <int, int, int> > triangles = GenTrianglesFromEdges(edges);

            foreach (Tuple <int, int, int> triangle in triangles)
            {
                surface.AddTriangle(triangle.Item1, triangle.Item2, triangle.Item3);
            }

            return(surface);
        }
Exemplo n.º 13
0
        public void GridGenerateSurface_SingleValue1_OtherValueMinus1_Iso0_GeneratesCorrectTriangle()
        {
            // ARRANGE
            ArrayGrid   grid     = GenerateSingle(1, -1, 0);
            ListSurface expected = new ListSurface();

            expected.AddVertex(new Vector3(0.5f, 0, 0));
            expected.AddVertex(new Vector3(0, 0.5f, 0));
            expected.AddVertex(new Vector3(0, 0, 0.5f));
            expected.AddTriangle(0, 1, 2);

            // ACT
            ListSurface s = new ListSurface();

            MarchingCubes.MarchIntoSurface(grid, 0, s);
            bool areEqual = ListSurface.AreSurfacesEquivalent(expected, s);

            // ASSERT
            Assert.IsTrue(areEqual);
        }
Exemplo n.º 14
0
        public static List <ListSurface> AddAllTriangulations(IEnumerable <ListSurface> surfaces, List <Vector3> polygon)
        {
            List <ListSurface> triangulations = GenAllTriangulations(polygon);

            List <ListSurface> newSurfaces = new List <ListSurface>();

            foreach (ListSurface oldSurface in surfaces)
            {
                int offset = oldSurface.GetVertexCount();
                foreach (ListSurface triangulation in triangulations)
                {
                    ListSurface newSurface = new ListSurface();
                    JoinInto(newSurface, oldSurface);
                    JoinInto(newSurface, triangulation);
                    newSurfaces.Add(newSurface);
                }
            }

            return(newSurfaces);
        }
Exemplo n.º 15
0
        private void TestClosed(int a, int b, int c, int d, int e, int f, int g, int h)
        {
            // ARRANGE
            float[,,] cells = new float[, , ] {
                { { -1, -1, -1, -1 }, { -1, -1, -1, -1 }, { -1, -1, -1, -1 }, { -1, -1, -1, -1 } },
                { { -1, -1, -1, -1 }, { -1, a, b, -1 }, { -1, c, d, -1 }, { -1, -1, -1, -1 } },
                { { -2, -2, -2, -2 }, { -2, e, f, -2 }, { -2, g, h, -2 }, { -2, -2, -2, -2 } },
                { { -2, -2, -2, -2 }, { -2, -2, -2, -2 }, { -2, -2, -2, -2 }, { -2, -2, -2, -2 } },
            };

            // ACT
            ArrayGrid   grid = new ArrayGrid(cells, Vector3.Zero, Vector3.One);
            ListSurface s    = new ListSurface();

            MarchingCubes.MarchIntoSurface(grid, 0, s);
            bool isClosed = s.IsClosed();

            // ASSERT
            Assert.IsTrue(isClosed);
        }
Exemplo n.º 16
0
        public void Surface_TrianglesEqual_FalseForOppositeWindings1()
        {
            // ARRANGE
            Vector3[] t1 = new Vector3[]
            {
                new Vector3(0, 0, 0),
                new Vector3(1, 0, 0),
                new Vector3(0, 1, 0),
            };
            Vector3[] t2 = new Vector3[]
            {
                new Vector3(0, 0, 0),
                new Vector3(0, 1, 0),
                new Vector3(1, 0, 0),
            };

            // ACT
            bool areEqual = ListSurface.AreTrianglesEqual(t1, t2);

            // ASSERT
            Assert.IsFalse(areEqual);
        }
Exemplo n.º 17
0
        public void Surface_Equal_TrueForSameWindingsTriangle2()
        {
            // ARRANGE
            ListSurface s1 = new ListSurface();

            s1.AddVertex(new Vector3(0, 0, 0));
            s1.AddVertex(new Vector3(1, 0, 0));
            s1.AddVertex(new Vector3(0, 1, 0));
            s1.AddTriangle(0, 1, 2);
            ListSurface s2 = new ListSurface();

            s2.AddVertex(new Vector3(0, 0, 0));
            s2.AddVertex(new Vector3(1, 0, 0));
            s2.AddVertex(new Vector3(0, 1, 0));
            s2.AddTriangle(2, 0, 1);

            // ACT
            bool areEqual = ListSurface.AreSurfacesEquivalent(s1, s2);

            // ASSERT
            Assert.IsTrue(areEqual);
        }
Exemplo n.º 18
0
        public void Surface_TrianglesEqual_TrueForSameTriangles()
        {
            // ARRANGE
            Vector3[] t1 = new Vector3[]
            {
                new Vector3(0, 0, 0),
                new Vector3(1, 0, 0),
                new Vector3(0, 1, 0),
            };
            Vector3[] t2 = new Vector3[]
            {
                new Vector3(0, 0, 0),
                new Vector3(1, 0, 0),
                new Vector3(0, 1, 0),
            };

            // ACT
            bool areEqual = ListSurface.AreTrianglesEqual(t1, t2);

            // ASSERT
            Assert.IsTrue(areEqual);
        }
Exemplo n.º 19
0
        public void Surface_Equal_FalseForDifferentWindingsTriangle3()
        {
            // ARRANGE
            ListSurface s1 = new ListSurface();

            s1.AddVertex(new Vector3(0, 0, 0));
            s1.AddVertex(new Vector3(1, 0, 0));
            s1.AddVertex(new Vector3(0, 1, 0));
            s1.AddTriangle(0, 1, 2);
            ListSurface s2 = new ListSurface();

            s2.AddVertex(new Vector3(0, 0, 0));
            s2.AddVertex(new Vector3(1, 0, 0));
            s2.AddVertex(new Vector3(0, 1, 0));
            s2.AddTriangle(1, 0, 2);

            // ACT
            bool areEqual = ListSurface.AreSurfacesEquivalent(s1, s2);

            // ASSERT
            Assert.IsFalse(areEqual);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Получение дорожного покрытия по названию
        /// </summary>
        /// <param name="name">Название</param>
        /// <returns>Дорожное покрытие</returns>
        public static Coating GetCoatingByName(string name)
        {
            List <object> coat = ListSurface.First(coating => coating[0].ToString().Equals(name));

            return(CreateCoating(coat[0].ToString(), double.Parse(coat[1].ToString())));
        }