Beispiel #1
0
        public override CaveGraph ReadCave(string csvFilePath)
        {
            var lines = File.ReadAllLines(csvFilePath);
            var tree = new CaveGraph();

            for (int i = 1; i < lines.Length; i++)
            {
                var parts = lines[i].Split(',');

                CavePoint p1 = tree.GetPoint(parts[0], tree);
                p1.Distances = parts.Where((p, ind) => ind > 4 && ind <= 8).Select(p =>
                {
                    double d;
                    return double.TryParse(p, out d) ? d : -1;
                }).ToArray();

                double x, y, z;
                if (double.TryParse(parts[9], out x) && double.TryParse(parts[10], out y) && double.TryParse(parts[11], out z))
                {
                    p1.Point = new Point3D(x, y, z);
                }

                CavePoint p2 = tree.GetPoint(parts[1], tree);

                double len, azimuth, vangel;
                if (ParseSpatialData(parts[3], parts[2], parts[4], out azimuth, out vangel, out len))
                {
                    tree.AddEdge(p1, new CaveEdge(p1, p2, len, azimuth, vangel));
                }
                else
                {
                    LogManager.GetCurrentClassLogger().ErrorFormat("Cannot parse input data");
                    throw new ArgumentException("Cannot parse input data");
                }
            }

            LogManager.GetCurrentClassLogger().InfoFormat("Input cave {0} parsed successfully", csvFilePath);
            return tree;
        }
Beispiel #2
0
        public override CaveGraph ReadCave(string file)
        {
            var cave = new CaveGraph();
            var lines = File.ReadAllLines(file);

            int i;

            for (i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                var templ = line.Replace(" ", "").ToLowerInvariant();

                if (string.IsNullOrEmpty(templ))
                    continue;

                if (templ == "datanormalfromtobackcompassclinolength")
                {
                    continue;
                }
                if (templ == "datadimensionsstationleftrightupdown")
                {
                    break;
                }

                var parts = line.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries);

                CavePoint p1 = cave.GetPoint(parts[0], cave);
                CavePoint p2 = cave.GetPoint(parts[1], cave);

                double len, azimuth, vangel;
                if (ParseSpatialData(parts[2], parts[3], parts[4], out azimuth, out vangel, out len))
                {
                    cave.AddEdge(p1, new CaveEdge(p1, p2, len, azimuth, 90 - vangel));
                }
                else
                {
                    LogManager.GetCurrentClassLogger().ErrorFormat("Cannot parse input data. Azimuth={0}, Vangle={1}, Lenght={2}", parts[2], parts[3], parts[4]);
                    throw new ArgumentException("Cannot parse input data");
                }
            }

            for (; i < lines.Length; i++)
            {
                var line = lines[i];
                var templ = line.Replace(" ", "").ToLowerInvariant();

                if (string.IsNullOrEmpty(templ))
                    continue;

                var parts = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                CavePoint p1 = cave.GetPoint(parts[0], cave);

                p1.Distances = parts.Where((p, ind) => ind > 1 && ind <= 4).Select(p =>
                {
                    double d;
                    return double.TryParse(p, out d) ? d : -1;
                }).ToArray();
            }

            var firstPoint = cave.PointsDict.FirstOrDefault().Value;
            firstPoint.Point = new Point3D(0,0,0);

            return cave;
        }