/// <summary>
        /// Parses ASCII file.
        /// </summary>
        public static IEnumerable <Chunk> Chunks(string filename, Token[] lineDefinition, ParseConfig config)
        {
            Chunk?lineParser(byte[] buffer, int count, double filterDist)
            => LineParsers.Custom(buffer, count, filterDist, lineDefinition);

            return(Parsing.AsciiLines(lineParser, filename, config));
        }
        /// <summary>
        /// Parses ASCII stream.
        /// </summary>
        public static IEnumerable <Chunk> Chunks(this Stream stream, long streamLengthInBytes, Token[] lineDefinition, ParseConfig config)
        {
            Chunk?lineParser(byte[] buffer, int count, double filterDist)
            => LineParsers.Custom(buffer, count, filterDist, lineDefinition);

            return(Parsing.AsciiLines(lineParser, stream, streamLengthInBytes, config));
        }
Beispiel #3
0
        private static void ParseAscii_Int_Test(string txt, int result)
        {
            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.Intensity };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);
            Assert.IsTrue(data.Value.Intensities[0] == result);
        }
Beispiel #4
0
        private static void ParseAscii_Float64_Test(string txt, double result)
        {
            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.PositionX };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);
            Assert.IsTrue(data.Value.Positions[0].X.ApproximateEquals(result, 10e-15));
        }
Beispiel #5
0
        public void ParseAscii_XYZIRGB_PartialXYZR()
        {
            var txt = @"
                1.2 3.4 5.6 8765 8
                ";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var data   = LineParsers.XYZIRGB(buffer, buffer.Length, 0.0);

            Assert.IsTrue(!data.HasValue);
        }
Beispiel #6
0
        public void ParseAscii_Custom_Intensity()
        {
            var txt = @"31415";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.Intensity };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);
            Assert.IsTrue(data.Value.Intensities[0] == 31415);
        }
Beispiel #7
0
        public void ParseAscii_Custom_Normal()
        {
            var txt = @"0.0 0.1 0.8";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.NormalX, Token.NormalY, Token.NormalZ };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);
            Assert.IsTrue(data.Value.Normals[0] == new V3f(0.0, 0.1, 0.8));
        }
Beispiel #8
0
        public void ParseAscii_Custom_ColorFloat()
        {
            var txt = @"0.0 0.5 1.0 0.8";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.ColorRf, Token.ColorGf, Token.ColorBf, Token.ColorAf };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);
            Assert.IsTrue(data.Value.Colors[0] == new C4b(0, 127, 255, 204));
        }
Beispiel #9
0
        public void ParseAscii_Custom_Color()
        {
            var txt = @"7 42 255 127";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.ColorR, Token.ColorG, Token.ColorB, Token.ColorA };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);
            Assert.IsTrue(data.Value.Colors[0] == new C4b(7, 42, 255, 127));
        }
Beispiel #10
0
        public void ParseAscii_Custom_Position()
        {
            var txt = @"1.2 3.4 5.6";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.PositionX, Token.PositionY, Token.PositionZ };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);
            Assert.IsTrue(data.Value.Positions[0] == new V3d(1.2, 3.4, 5.6));
        }
Beispiel #11
0
        public void ParseAscii_SingleLine_WithSkip()
        {
            var txt = @"1.2 3.4 5.6 8 254 97 6543 0.1 0.2 0.3";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.PositionX, Token.PositionY, Token.PositionZ, Token.ColorR, Token.ColorG, Token.ColorB, Token.Skip, Token.NormalX, Token.NormalY, Token.NormalZ };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);
            Assert.IsTrue(data.Value.Positions[0] == new V3d(1.2, 3.4, 5.6));
            Assert.IsTrue(data.Value.Colors[0] == new C4b(8, 254, 97));
            Assert.IsTrue(data.Value.Normals[0] == new V3f(0.1, 0.2, 0.3));
        }
Beispiel #12
0
        public void ParseAscii_XYZRGB_0()
        {
            var txt = @"
                1.2 3.4 5.6 8 254 97
                ";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var data   = LineParsers.XYZRGB(buffer, buffer.Length, 0.0);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);

            Assert.IsTrue(data.Value.Positions[0] == new V3d(1.2, 3.4, 5.6));
            Assert.IsTrue(data.Value.Colors[0] == new C4b(8, 254, 97));
        }
Beispiel #13
0
        public void ParseAscii_XYZRGB_PartialLinesAreSkipped()
        {
            var txt = @"
                8.2 3.4 5.6
                1.2 3.4 5.6 10 20 30
                9.2 3.4 5.6
                ";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var data   = LineParsers.XYZRGB(buffer, buffer.Length, 0.0);

            Assert.IsTrue(data.HasValue && data.Value.Count == 1);

            Assert.IsTrue(data.Value.Positions[0] == new V3d(1.2, 3.4, 5.6));
            Assert.IsTrue(data.Value.Colors[0] == new C4b(10, 20, 30));
        }
Beispiel #14
0
        private static void ParseAscii_FloatColor_Test(string txt, int result, bool isInvalid)
        {
            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.ColorRf };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            if (isInvalid)
            {
                Assert.IsTrue(!data.HasValue);
            }
            else
            {
                Assert.IsTrue(data.HasValue && data.Value.Count == 1);
                Assert.IsTrue(data.Value.Colors[0].R == result);
            }
        }
Beispiel #15
0
        public void ParseAscii_EmptyLinesIntermediate()
        {
            var txt = @"

1.2 3.4 5.6

5.5 6.6 7.7

";

            var buffer = Encoding.ASCII.GetBytes(txt);
            var layout = new[] { Token.PositionX, Token.PositionY, Token.PositionZ };
            var data   = LineParsers.Custom(buffer, buffer.Length, 0.0, layout);

            Assert.IsTrue(data.HasValue && data.Value.Count == 2);
            Assert.IsTrue(data.Value.Positions[0] == new V3d(1.2, 3.4, 5.6));
            Assert.IsTrue(data.Value.Positions[1] == new V3d(5.5, 6.6, 7.7));
        }