Example #1
0
        public void Create(PointIndexer indexer, double step = 1000)
        {
            _step    = step;
            _indexer = indexer;
            var pts = indexer.Points;

            ds = new Dictionary <string, List <int> >();

            for (int i = 0; i < pts.Length; i++)
            {
                if (!indexer.Contains(i))
                {
                    continue;
                }
                var p   = pts[i] * step;
                var key = (int)(p.X) + ";" + (int)p.Y + ";" + (int)p.Z;
                if (!ds.ContainsKey(key))
                {
                    ds.Add(key, new List <int>());
                }
                ds[key].Add(i);
            }
            _clusters = ds.Select(z => new ClusterInfo()
            {
                Key = z.Key, Indicies = z.Value.ToArray()
            }).ToArray();
        }
Example #2
0
        public static PointIndexer FromPoints(Vector3d[] points)
        {
            PointIndexer ret = new PointIndexer();

            ret.Points   = points;
            ret.Indicies = points.Select((z, i) => i).ToArray();
            return(ret);
        }
Example #3
0
        public PointIndexer GetSubIndexer(int[] inds)
        {
            var r = new PointIndexer()
            {
                Points = Points, Indicies = inds
            };

            r.Init();
            return(r);
        }
Example #4
0
 internal void Recreate(PointIndexer pin)
 {
     Create(pin, _step);
 }
Example #5
0
        public static PointIndexer LoadPly(string path)
        {
            var points = new List <Vector3d>();

            var  rf          = File.ReadAllLines(path);
            bool binary      = false;
            int? verticies   = null;
            bool isBigEndian = false;

            if (rf.Take(5).Any(z => z.Contains("binary")))
            {
                binary = true;

                var             bts    = File.ReadAllBytes(path);
                List <byte>     accum1 = new List <byte>();
                int             pos    = 0;
                List <PropInfo> props  = new List <PropInfo>();

                bool faceSection = false;
                for (int i = 0; i < bts.Length; i++)
                {
                    accum1.Add(bts[i]);
                    if (bts[i] == 0x0a)
                    {
                        var str = Encoding.UTF8.GetString(accum1.ToArray());
                        if (str.ToLower().Contains("binary_big_endian"))
                        {
                            isBigEndian = true;
                            accum1.Clear();
                            continue;
                        }
                        if (str.ToLower().Contains("element vertex"))
                        {
                            var ar = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

                            accum1.Clear();
                            verticies = int.Parse(ar[2]);
                            continue;
                        }
                        if (str.ToLower().Contains("element face"))
                        {
                            accum1.Clear();
                            faceSection = true;
                            continue;
                        }
                        if (str.Contains("property") && !faceSection)
                        {
                            var aa1 = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                            props.Add(new PropInfo()
                            {
                                Name = aa1[2], Type = aa1[1]
                            });
                        }
                        if (str.Contains("end_header"))
                        {
                            pos = i;
                            break;
                        }
                        accum1.Clear();
                    }
                }
                var             data = bts.Skip(pos + 1).ToArray();
                List <double[]> dd   = new List <double[]>();
                var             word = props.Sum(z => z.TypeLen);
                for (int i = 0; i < data.Length; i += word)
                {
                    int           shift = 0;
                    List <double> dd2   = new List <double>();

                    foreach (var prop in props)
                    {
                        if (prop.Type == "double")
                        {
                            byte[] temp = new byte[4];
                            Array.Copy(data, i + shift, temp, 0, 4);
                            if (isBigEndian && BitConverter.IsLittleEndian)
                            {
                                Array.Reverse(temp);
                            }
                            dd2.Add(BitConverter.ToDouble(temp, 0));

                            shift += 8;
                        }
                        if (prop.Type == "float")
                        {
                            byte[] temp = new byte[4];
                            Array.Copy(data, i + shift, temp, 0, 4);
                            if (isBigEndian && BitConverter.IsLittleEndian)
                            {
                                Array.Reverse(temp);
                            }
                            dd2.Add(BitConverter.ToSingle(temp, 0));
                            shift += 4;
                        }
                    }
                    dd.Add(dd2.ToArray());

                    if (verticies != null)
                    {
                        if (verticies.Value == dd.Count)
                        {
                            break;
                        }
                    }
                }

                for (int i = 0; i < dd.Count; i++)
                {
                    Vector3d v = new Vector3d(dd[i][0], dd[i][1], dd[i][2]);
                    points.Add(v);
                }
                return(PointIndexer.FromPoints(points.ToArray()));
            }
            bool end = false;


            foreach (var item in rf)
            {
                var ar = item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

                if (item.ToLower().Contains("element vertex"))
                {
                    verticies = int.Parse(ar[2]);
                    continue;
                }

                if (item.ToLower().Contains("end") && item.Contains("header"))
                {
                    end = true;
                    continue;
                }
                if (end)
                {
                    var d1 = ar.Select(z => double.Parse(z.Replace(",", "."), CultureInfo.InvariantCulture)).ToArray();
                    var v1 = new Vector3d(d1[0], d1[1], d1[2]);
                    points.Add(v1);
                    if (verticies != null)
                    {
                        if (verticies.Value == points.Count)
                        {
                            break;
                        }
                    }
                }
            }


            return(PointIndexer.FromPoints(points.ToArray()));
        }
Example #6
0
 internal void Merge(PointIndexer pin)
 {
     Points   = Points.Union(pin.Points).ToArray();
     Indicies = Indicies.Concat(pin.Indicies.Select(u => u + Indicies.Length)).ToArray();
     Init();
 }