示例#1
0
        public void TestSize()
        {
            Solid solid;

            using (var str = Utils.OpenDataStream("block.stl"))
                using (var reader = new StlReader(str))
                    solid = reader.ReadSolid();

            SolidSize size = solid.GetSize();

            Assert.Equal(new Vertex(-1.968504f, -1.968504f, -1.968504f), size.Min);
            Assert.Equal(new Vertex(1.968504f, 1.968504f, 1.968504f), size.Max);
            Assert.Equal(new Vertex(3.937008f, 3.937008f, 3.937008f), size.Size);
            Assert.Equal(6.81909771961959, size.BoudingDiameter, 14);

            size = Calculator.CalculateSize(null);
            Assert.NotNull(size);
            Assert.Equal(new Vertex(), size.Min);
            Assert.Equal(new Vertex(), size.Max);
            Assert.Equal(new Vertex(), size.Size);
            Assert.Equal(0, size.BoudingDiameter, 14);

            size = Calculator.CalculateSize(new Facet[0]);
            Assert.NotNull(size);
            Assert.Equal(new Vertex(), size.Min);
            Assert.Equal(new Vertex(), size.Max);
            Assert.Equal(new Vertex(), size.Size);
            Assert.Equal(0, size.BoudingDiameter, 14);
        }
示例#2
0
        public void TestReader_ReadFacets()
        {
            IList <Facet> facets;

            using (var str = Utils.OpenDataStream("ASCII.stl"))
                using (var reader = new StlReader(str))
                    facets = reader.ReadFacets().ToList();

            Assert.Equal(12, facets.Count);
            foreach (Facet facet in facets)
            {
                Assert.Equal(3, facet.Vertices.Count);
            }

            using (var str = Utils.OpenDataStream("Binary.stl"))
                using (var reader = new StlReader(str))
                    facets = reader.ReadFacets().ToList();

            Assert.Equal(12, facets.Count);
            foreach (Facet facet in facets)
            {
                Assert.Equal(3, facet.Vertices.Count);
            }

            using (var str = new MemoryStream(new byte[4]))
                using (var reader = new StlReader(str))
                    Assert.Throws <FormatException>(() => reader.ReadFacets().ToList());
        }
示例#3
0
        public void TestReader()
        {
            Solid solid;

            using (var str = Utils.OpenDataStream("ASCII.stl"))
                using (var reader = new StlReader(str))
                    solid = reader.ReadSolid();

            Assert.NotNull(solid);
            Assert.Equal(SolidFormat.Ascii, solid.Format);
            Assert.Equal(12, solid.Facets.Count);
            foreach (Facet facet in solid.Facets)
            {
                Assert.Equal(3, facet.Vertices.Count);
            }

            using (var str = Utils.OpenDataStream("Binary.stl"))
                using (var reader = new StlReader(str))
                    solid = reader.ReadSolid();

            Assert.NotNull(solid);
            Assert.Equal(SolidFormat.Binary, solid.Format);
            Assert.Equal(12, solid.Facets.Count);
            foreach (Facet facet in solid.Facets)
            {
                Assert.Equal(3, facet.Vertices.Count);
            }

            using (var str = new MemoryStream(new byte[4]))
                using (var reader = new StlReader(str))
                    Assert.Throws <FormatException>(() => reader.ReadSolid());
        }
        public void TestSize()
        {

            Solid solid;
            using (var str = Utils.OpenDataStream("block.stl"))
            using (var reader = new StlReader(str))
                solid = reader.ReadSolid();

            SolidSize size = solid.GetSize();
            Assert.Equal(new Vertex(-1.968504f, -1.968504f, -1.968504f), size.Min);
            Assert.Equal(new Vertex(1.968504f, 1.968504f, 1.968504f), size.Max);
            Assert.Equal(new Vertex(3.937008f, 3.937008f, 3.937008f), size.Size);
            Assert.Equal(6.81909771961959, size.BoudingDiameter, 14);

            size = Calculator.CalculateSize(null);
            Assert.NotNull(size);
            Assert.Equal(new Vertex(), size.Min);
            Assert.Equal(new Vertex(), size.Max);
            Assert.Equal(new Vertex(), size.Size);
            Assert.Equal(0, size.BoudingDiameter, 14);

            size = Calculator.CalculateSize(new Facet[0]);
            Assert.NotNull(size);
            Assert.Equal(new Vertex(), size.Min);
            Assert.Equal(new Vertex(), size.Max);
            Assert.Equal(new Vertex(), size.Size);
            Assert.Equal(0, size.BoudingDiameter, 14);
        }
示例#5
0
 public void IsAsciiTest(string test)
 {
     using (StlReader reader = new StlReader(test, onNotification))
     {
         Assert.False(reader.IsBinary());
     }
 }
示例#6
0
 private Mesh readFile(string path)
 {
     using (StlReader reader = new StlReader(path, onNotification))
     {
         return(reader.Read());
     }
 }
示例#7
0
        public void TestReader()
        {
            Solid solid;
            using (var str = Utils.OpenDataStream("ASCII.stl"))
            using (var reader = new StlReader(str))
                solid = reader.ReadSolid();

            Assert.NotNull(solid);
            Assert.Equal(SolidFormat.Ascii, solid.Format);
            Assert.Equal(12, solid.Facets.Count);
            foreach (Facet facet in solid.Facets)
                Assert.Equal(3, facet.Vertices.Count);

            using (var str = Utils.OpenDataStream("Binary.stl"))
            using (var reader = new StlReader(str))
                solid = reader.ReadSolid();

            Assert.NotNull(solid);
            Assert.Equal(SolidFormat.Binary, solid.Format);
            Assert.Equal(12, solid.Facets.Count);
            foreach (Facet facet in solid.Facets)
                Assert.Equal(3, facet.Vertices.Count);

            using (var str = new MemoryStream(new byte[4]))
            using (var reader = new StlReader(str))
                Assert.Throws<FormatException>(() => reader.ReadSolid());

        }
示例#8
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Title = "SimpleSTLReader";

            StlModel stlModel = new StlReader().Read($@"{Environment.CurrentDirectory}\Utah_teapot.stl");

            _vertices = stlModel.Vertices.Select(vertex => new Vector3((float)vertex.X, (float)vertex.Y, (float)vertex.Z))
                        .ToArray();

            GL.GenVertexArrays(1, out _vertexAttribute);
            GL.BindVertexArray(_vertexAttribute);

            // position attribute
            GL.GenBuffers(1, out _positionBuffer);
            GL.BindBuffer(BufferTarget.ArrayBuffer, _positionBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, Vector3.SizeInBytes * _vertices.Length, _vertices, BufferUsageHint.StaticDraw);

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
            GL.EnableVertexAttribArray(0);

            // projection
            GL.MatrixMode(MatrixMode.Projection);
            GL.Ortho(-10, 10, -10, 10, -10, 10);

            GL.Viewport(0, 0, Width, Height);
        }
示例#9
0
 public static ReaderBase FindReaderForExtension(string extension)
 {
     if (((IList)FbxReader.GetExtensions()).Contains(extension))
     {
         return(new FbxReader());
     }
     if (((IList)GltfReader.GetExtensions()).Contains(extension))
     {
         return(new GltfReader());
     }
     if (((IList)ObjReader.GetExtensions()).Contains(extension))
     {
         return(new ObjReader());
     }
     if (((IList)StlReader.GetExtensions()).Contains(extension))
     {
         return(new StlReader());
     }
     if (((IList)PlyReader.GetExtensions()).Contains(extension))
     {
         return(new PlyReader());
     }
     if (((IList)ThreeMfReader.GetExtensions()).Contains(extension))
     {
         return(new ThreeMfReader());
     }
     return(null);
 }
示例#10
0
        public void TestCreateReader()
        {
            using (var str = Utils.OpenDataStream("ASCII.stl"))
            {
                using (var reader = new StlReader(str))
                    reader.ReadSolid();
                Assert.Throws <ObjectDisposedException>(() => str.ReadByte());
            }

            Assert.Throws <ArgumentNullException>(() => new StlReader(null));
        }
示例#11
0
        public void TestCreateReader()
        {
            using (var str = Utils.OpenDataStream("ASCII.stl"))
            {
                using (var reader = new StlReader(str))
                    reader.ReadSolid();
                Assert.Throws<ObjectDisposedException>(() => str.ReadByte());
            }

            Assert.Throws<ArgumentNullException>(() => new StlReader(null));

        }
示例#12
0
        public static GpuShape LoadShape(string path, DiscreteBounds size, int borderSize)
        {
            var normalizedBounds = new Bounds
            {
                MinX = size.MinX + borderSize,
                MinY = size.MinY + borderSize,
                MinZ = size.MinZ + borderSize,
                MaxX = size.MaxX - borderSize,
                MaxY = size.MaxY - borderSize,
                MaxZ = size.MaxZ - borderSize,
            };

            var stlShape        = StlReader.LoadShape(path);
            var normalizedShape = ShapeNormalizer.NormalizeShape(stlShape, normalizedBounds);
            var voxelizedShape  = VoxelSpaceBuilder.Build(normalizedShape, size);

            return(new GpuShape(voxelizedShape));
        }
示例#13
0
        public void TestVolume()
        {

            Solid solid;
            using (var str = Utils.OpenDataStream("ASCII.stl"))
            using (var reader = new StlReader(str))
                solid = reader.ReadSolid();
            Assert.Equal(1000f, Calculator.CalculateVolume(solid.Facets), 2);

            using (var str = Utils.OpenDataStream("Binary.stl"))
            using (var reader = new StlReader(str))
                solid = reader.ReadSolid();
            Assert.Equal(1000f, Calculator.CalculateVolume(solid.Facets), 2);

            using (var str = Utils.OpenDataStream("block.stl"))
            using (var reader = new StlReader(str))
                solid = reader.ReadSolid();
            Assert.Equal(61.02375f, Calculator.CalculateVolume(solid.Facets), 5);
            Assert.Equal(0f, Calculator.CalculateVolume(new Facet[0]));
            Assert.Equal(0f, Calculator.CalculateVolume(null));
        }
示例#14
0
        public void TestArea()
        {
            Solid solid;

            using (var str = Utils.OpenDataStream("ASCII.stl"))
                using (var reader = new StlReader(str))
                    solid = reader.ReadSolid();
            Assert.Equal(600f, Calculator.CalculateSurfaceArea(solid.Facets));

            using (var str = Utils.OpenDataStream("Binary.stl"))
                using (var reader = new StlReader(str))
                    solid = reader.ReadSolid();
            Assert.Equal(600f, Calculator.CalculateSurfaceArea(solid.Facets));

            using (var str = Utils.OpenDataStream("block.stl"))
                using (var reader = new StlReader(str))
                    solid = reader.ReadSolid();
            Assert.Equal(93.00019f, Calculator.CalculateSurfaceArea(solid.Facets));
            Assert.Equal(0f, Calculator.CalculateSurfaceArea(null));
            Assert.Equal(0f, Calculator.CalculateArea(null));
        }
示例#15
0
        public void TestVolume()
        {
            Solid solid;

            using (var str = Utils.OpenDataStream("ASCII.stl"))
                using (var reader = new StlReader(str))
                    solid = reader.ReadSolid();
            Assert.Equal(1000f, Calculator.CalculateVolume(solid.Facets), 2);

            using (var str = Utils.OpenDataStream("Binary.stl"))
                using (var reader = new StlReader(str))
                    solid = reader.ReadSolid();
            Assert.Equal(1000f, Calculator.CalculateVolume(solid.Facets), 2);

            using (var str = Utils.OpenDataStream("block.stl"))
                using (var reader = new StlReader(str))
                    solid = reader.ReadSolid();
            Assert.Equal(61.02375f, Calculator.CalculateVolume(solid.Facets), 5);
            Assert.Equal(0f, Calculator.CalculateVolume(new Facet[0]));
            Assert.Equal(0f, Calculator.CalculateVolume(null));
        }
示例#16
0
        public void TestTextWriter()
        {
            Solid solid1 = new Solid("test", new List <Facet>()
            {
                new Facet(new Vertex(0.23f, 0, 1), new Vertex[]
                {
                    new Vertex(0, 0, 0),
                    new Vertex(-10.123f, -10, 0),
                    new Vertex(-10.123f, 0, 0)
                }, 0)
            });

            byte[] data;
            string dataString1;

            using (MemoryStream stream = new MemoryStream())
                using (var writer = new StlTextWriter(stream))
                {
                    writer.WriteSolid(solid1);
                    data        = stream.ToArray();
                    dataString1 = Consts.FileEncoding.GetString(data);
                }

            Solid solid2;

            using (MemoryStream stream = new MemoryStream(data))
                using (var reader = new StlReader(stream))
                {
                    solid2 = reader.ReadSolid();
                }

            Assert.Equal(solid1.Name, solid2.Name);
            Assert.Equal(solid1.Facets.Count, solid2.Facets.Count);
            for (int i = 0; i < solid1.Facets.Count; i++)
            {
                Assert.True(solid1.Facets[i].Equals(solid2.Facets[i]));
            }
        }
示例#17
0
        public void TestTextWriter()
        {
            Solid solid1 = new Solid("test", new List<Facet>()
            {
                new Facet(new Vertex( 0.23f, 0, 1), new Vertex[]
                {
                    new Vertex( 0, 0, 0),
                    new Vertex(-10.123f, -10, 0),
                    new Vertex(-10.123f, 0, 0)
                }, 0)
            });

            byte[] data;
            string dataString1;

            using (MemoryStream stream = new MemoryStream())
            using (var writer = new StlTextWriter(stream))
            {
                writer.WriteSolid(solid1);
                data = stream.ToArray();
                dataString1 = Consts.FileEncoding.GetString(data);
            }

            Solid solid2;

            using (MemoryStream stream = new MemoryStream(data))
            using (var reader = new StlReader(stream))
            {
                solid2 = reader.ReadSolid();
            }

            Assert.Equal(solid1.Name, solid2.Name);
            Assert.Equal(solid1.Facets.Count, solid2.Facets.Count);
            for (int i = 0; i < solid1.Facets.Count; i++)
                Assert.True(solid1.Facets[i].Equals(solid2.Facets[i]));

        }
示例#18
0
        public void TestBinaryWriter()
        {
            Solid solid1 = new Solid("test", new Facet[]
            {
                new Facet(new Vertex(0, 0, 1), new Vertex[]
                {
                    new Vertex(0, 0, 0),
                    new Vertex(-10, -10, 0),
                    new Vertex(-10, 0, 0)
                }, 0)
            });

            byte[] data;

            using (MemoryStream stream = new MemoryStream())
                using (var writer = new StlBinaryWriter(stream))
                {
                    writer.WriteSolid(solid1);
                    data = stream.ToArray();
                }

            Solid solid2;

            using (MemoryStream stream = new MemoryStream(data))
                using (var reader = new StlReader(stream))
                {
                    solid2 = reader.ReadSolid();
                }

            Assert.NotEqual(solid1.Name, solid2.Name);
            Assert.Null(solid2.Name);
            Assert.Equal(solid1.Facets.Count, solid2.Facets.Count);
            for (int i = 0; i < solid1.Facets.Count; i++)
            {
                Assert.True(solid1.Facets[i].Equals(solid2.Facets[i]));
            }
        }
示例#19
0
        public void TestReader_ReadFacets()
        {
            IList<Facet> facets;
            using (var str = Utils.OpenDataStream("ASCII.stl"))
            using (var reader = new StlReader(str))
                facets = reader.ReadFacets().ToList();

            Assert.Equal(12, facets.Count);
            foreach (Facet facet in facets)
                Assert.Equal(3, facet.Vertices.Count);

            using (var str = Utils.OpenDataStream("Binary.stl"))
            using (var reader = new StlReader(str))
                facets = reader.ReadFacets().ToList();

            Assert.Equal(12, facets.Count);
            foreach (Facet facet in facets)
                Assert.Equal(3, facet.Vertices.Count);

            using (var str = new MemoryStream(new byte[4]))
            using (var reader = new StlReader(str))
                Assert.Throws<FormatException>(() => reader.ReadFacets().ToList());

        }
示例#20
0
 public void SetUp()
 {
     _objectUnderTest = new StlReader <Triangle, Vertex, Normal>(TestDataStructureHelpers.CreateTriangle, TestDataStructureHelpers.CreateVertex, TestDataStructureHelpers.CreateNormal);
 }
示例#21
0
        public void TestBinaryWriter()
        {
            Solid solid1 = new Solid("test", new Facet[]
            {
                new Facet(new Vertex( 0, 0, 1), new Vertex[]
                {
                    new Vertex( 0, 0, 0),
                    new Vertex(-10, -10, 0),
                    new Vertex(-10, 0, 0)
                }, 0)
            });

            byte[] data;

            using (MemoryStream stream = new MemoryStream())
            using (var writer = new StlBinaryWriter(stream))
            {
                writer.WriteSolid(solid1);
                data = stream.ToArray();
            }

            Solid solid2;

            using (MemoryStream stream = new MemoryStream(data))
            using (var reader = new StlReader(stream))
            {
                solid2 = reader.ReadSolid();
            }

            Assert.NotEqual(solid1.Name, solid2.Name);
            Assert.Null(solid2.Name);
            Assert.Equal(solid1.Facets.Count, solid2.Facets.Count);
            for (int i = 0; i < solid1.Facets.Count; i++)
                Assert.True(solid1.Facets[i].Equals(solid2.Facets[i]));

        }
示例#22
0
        public void TestArea()
        {

            Solid solid;
            using (var str = Utils.OpenDataStream("ASCII.stl"))
            using (var reader = new StlReader(str))
                solid = reader.ReadSolid();
            Assert.Equal(600f, Calculator.CalculateSurfaceArea(solid.Facets));

            using (var str = Utils.OpenDataStream("Binary.stl"))
            using (var reader = new StlReader(str))
                solid = reader.ReadSolid();
            Assert.Equal(600f, Calculator.CalculateSurfaceArea(solid.Facets));

            using (var str = Utils.OpenDataStream("block.stl"))
            using (var reader = new StlReader(str))
                solid = reader.ReadSolid();
            Assert.Equal(93.00019f, Calculator.CalculateSurfaceArea(solid.Facets));
            Assert.Equal(0f, Calculator.CalculateSurfaceArea(null));
            Assert.Equal(0f, Calculator.CalculateArea(null));
        }
示例#23
0
 public void Setup()
 {
     _reader = new StlReader();
 }
示例#24
0
        static int Main(string[] args)
        {
            progname = System.IO.Path.GetFileName(Environment.GetCommandLineArgs()[0]);
            //progname = Environment.GetCommandLineArgs()[0];

            // Parse and check the arguments
            try
            {
                ParseArgs(args);

                if (pArgs.HelpOption)
                {
                    PrintUsage();
                    return(0);
                }

                if (pArgs.VersionOption)
                {
                    var asm     = typeof(Program).Assembly;
                    var asmName = asm.GetName();
                    Console.WriteLine("stl-tools - version {0}", asmName.Version);
                    return(0);
                }

                if (String.IsNullOrWhiteSpace(pArgs.Filename))
                {
                    throw new InvalidOperationException("No input file name given.");
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Error.WriteLine("{0}: {1}", progname, ex.GetBaseException().Message);
                Console.ResetColor();
                PrintTryHelp();
                PressKeyToQuit();
                return(-1);
            }

            int result = 0;

            // Print header
            PrintHeader();

            try
            {
                // Load solid
                Console.WriteLine("Opening {0}.", pArgs.Filename);
                Solid     solid;
                Stopwatch sw = new Stopwatch();
                sw.Start();
                using (var file = File.OpenRead(pArgs.Filename))
                    using (var reader = new StlReader(file))
                        solid = reader.ReadSolid();
                sw.Stop();

                // Display file informations
                Console.WriteLine();
                Console.WriteLine("=== File informations");
                Console.WriteLine("File         : {0}", pArgs.Filename);
                Console.WriteLine("Name         : {0}", solid.Name);
                Console.WriteLine("Format       : {0}", solid.Format);
                Console.WriteLine("Time loading : {0} ms", sw.ElapsedMilliseconds);
                Console.WriteLine("Facets       : {0}", solid.Facets.Count);
                Console.WriteLine();

                // Display solid informations
                var solidSize = solid.GetSize();
                var volume    = solid.GetSignedVolume();

                Console.WriteLine();
                Console.WriteLine("=== Solid informations");
                Console.WriteLine("Facets : {0,9}", solid.Facets.Count);
                Console.WriteLine("Size X : {0,15:F5} ({1,10:F5} - {2,10:F5})", solidSize.Size.X, solidSize.Min.X, solidSize.Max.X);
                Console.WriteLine("Size Y : {0,15:F5} ({1,10:F5} - {2,10:F5})", solidSize.Size.Y, solidSize.Min.Y, solidSize.Max.Y);
                Console.WriteLine("Size Z : {0,15:F5} ({1,10:F5} - {2,10:F5})", solidSize.Size.Z, solidSize.Min.Z, solidSize.Max.Z);
                Console.WriteLine("Volume : {0,15:F5}", volume);
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Error.WriteLine("{0}: {1}", progname, ex.GetBaseException().Message);
                Console.ResetColor();
                result = -1;
            }
            PressKeyToQuit();
            return(result);
        }