public void VerticesTest()
        {
            var model         = DMTModelReader.ReadFile(new FileSystem.File(TestFiles.BoundariesTestSquare));
            var triangleBlock = model.TriangleBlocks.Single();

            var fieldInfo = triangleBlock.GetType().GetField("_triangleVertices", BindingFlags.Instance | BindingFlags.NonPublic);
            var vertices  = (List <Point>)fieldInfo.GetValue(triangleBlock);

            var triangleBlockVertices = triangleBlock.Vertices.Cast <DMTVertex>().ToList();

            Assert.AreEqual(vertices[0].X, triangleBlockVertices[0].Position.X, "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(vertices[0].Y, triangleBlockVertices[0].Position.Y, "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(vertices[0].Z, triangleBlockVertices[0].Position.Z, "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(vertices[3].X, triangleBlockVertices[3].Position.X, "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(vertices[3].Y, triangleBlockVertices[3].Position.Y, "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(vertices[3].Z, triangleBlockVertices[3].Position.Z, "Vertices is not retrieving the correct vertex.");
        }
Exemplo n.º 2
0
        public void WhenAppendingBinarySTLFile_ThenEnsureDuplicatePointsRemoval()
        {
            var      inputFile = new File(TestFiles.FetchTestFile("GetTrianglesByMesh.stl"));
            DMTModel mainMesh  = DMTModelReader.ReadFile(inputFile);

            Assert.AreEqual(944, mainMesh.TotalNoOfTriangles);
            Assert.AreEqual(944, mainMesh.TotalNoOfVertices);

            var exportedFile = File.CreateTemporaryFile("stl", true);

            DMTModelWriter.WriteFile(mainMesh, exportedFile);

            DMTModel exportedMesh = DMTModelReader.ReadFile(inputFile);

            Assert.AreEqual(944, exportedMesh.TotalNoOfTriangles);
            Assert.AreEqual(944, exportedMesh.TotalNoOfVertices);
        }
Exemplo n.º 3
0
        public void WhenWritingSTLFileFromDMTFile_ThenCheckOutput()
        {
            DMTModel importedModel = DMTModelReader.ReadFile(new File(TestFiles.NormalDmt));
            var      outputFile    = new File(string.Format("{0}\\output.stl", Path.GetTempPath()));

            DMTModelWriter.WriteFile(importedModel, outputFile);
            DMTModel writtenModel = DMTModelReader.ReadFile(outputFile);

            // Ensure that model is written correctly
            Assert.AreEqual(importedModel.BoundingBox.MaxX, writtenModel.BoundingBox.MaxX);
            Assert.AreEqual(importedModel.BoundingBox.MaxY, writtenModel.BoundingBox.MaxY);
            Assert.AreEqual(importedModel.BoundingBox.MaxZ, writtenModel.BoundingBox.MaxZ);
            Assert.AreEqual(importedModel.BoundingBox.MinX, writtenModel.BoundingBox.MinX);
            Assert.AreEqual(importedModel.BoundingBox.MinY, writtenModel.BoundingBox.MinY);
            Assert.AreEqual(importedModel.BoundingBox.MinZ, writtenModel.BoundingBox.MinZ);

            outputFile.Delete();
        }
        public void WhenCoincidentPointsInATriangle_ThenStillAppendBinarySTLFile()
        {
            var mesh          = new File(TestFiles.FetchTestFile("CoincidentPointsInATriangle.stl"));
            var importedModel = DMTModelReader.ReadFile(mesh);

            Assert.That(importedModel.TotalNoOfTriangles, Is.EqualTo(3), "Failed expected number of triangles.");
            Assert.That(importedModel.TotalNoOfVertices, Is.EqualTo(3), "Failed expected number of vertices.");

            var expectedOutput =
                DMTModelReader.ReadFile(new File(TestFiles.FetchTestFile("CoincidentPointsInATriangle_Expected.stl")));

            Assert.IsTrue(importedModel.BoundingBox.XSize == expectedOutput.BoundingBox.XSize,
                          "It is not giving the expected bounding box xsize.");
            Assert.IsTrue(importedModel.BoundingBox.YSize == expectedOutput.BoundingBox.YSize,
                          "It is not giving the expected bounding box xsize.");
            Assert.IsTrue(importedModel.BoundingBox.ZSize == expectedOutput.BoundingBox.ZSize,
                          "It is not giving the expected bounding box xsize.");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns a DMT Model of the mesh
        /// </summary>
        /// <returns>A DMT Model of the Mesh</returns>
        public DMTModel ToDMTModel()
        {
            // Select the mesh
            AddToSelection(true);

            // Write to a DMT file
            FileSystem.File tempFile = FileSystem.File.CreateTemporaryFile("dmt");
            WriteToDMTFile(tempFile);

            // Read in the model
            var model = DMTModelReader.ReadFile(tempFile);

            // Delete the file
            tempFile.Delete();

            // Return the model
            return(model);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Exports the model into a DMT file and then reads the DMT model into a DMTModel object.
        /// </summary>
        public DMTModel ToDMTModel()
        {
            try
            {
                // Export the model to a temporary file
                FileSystem.File tempFile = FileSystem.File.CreateTemporaryFile("dmt");
                WriteToDMTFile(tempFile);

                // Read the file in as a DMT Object
                DMTModel objDMTModel = DMTModelReader.ReadFile(tempFile);

                // Delete the file
                tempFile.Delete();
                return(objDMTModel);
            }
            catch
            {
                return(null);
            }
        }
        public void TrianglesTest()
        {
            var model         = DMTModelReader.ReadFile(new FileSystem.File(TestFiles.BoundariesTestSquare));
            var triangleBlock = model.TriangleBlocks.Single();

            var fieldInfo = triangleBlock.GetType().GetField("_triangleVertices", BindingFlags.Instance | BindingFlags.NonPublic);
            var vertices  = (List <Point>)fieldInfo.GetValue(triangleBlock);

            var triangles = triangleBlock.Triangles.Cast <DMTTriangle>().ToList();

            Assert.AreEqual(0,
                            Math.Round(vertices[triangles[0].Vertex1].X.Value),
                            "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(-10,
                            vertices[triangles[0].Vertex1].Y.Value,
                            "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(-10,
                            vertices[triangles[0].Vertex1].Z.Value,
                            "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(0,
                            Math.Round(vertices[triangles[0].Vertex2].X.Value),
                            "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(10,
                            vertices[triangles[0].Vertex2].Y.Value,
                            "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(-10,
                            vertices[triangles[0].Vertex2].Z.Value,
                            "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(0,
                            Math.Round(vertices[triangles[0].Vertex3].X.Value),
                            "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(-10,
                            vertices[triangles[0].Vertex3].Y.Value,
                            "Vertices is not retrieving the correct vertex.");
            Assert.AreEqual(10,
                            vertices[triangles[0].Vertex3].Z.Value,
                            "Vertices is not retrieving the correct vertex.");
        }