Example #1
0
 public virtual void read(byte[] buffer, int pos, ref PCD_PointBuilder pbb)
 {
     if (id > -1)
     {
         pbb.data[id] = null;
     }
 }
Example #2
0
 public virtual void readASCII(string str, ref PCD_PointBuilder pbb)
 {
     if (id > -1)
     {
         pbb.data[id] = null;
     }
 }
Example #3
0
 public override void readASCII(string str, ref PCD_PointBuilder pbb)
 {
     if (id > -1)
     {
         pbb.data[id] = System.Convert.ToInt32(str, CultureInfo.InvariantCulture);
     }
 }
Example #4
0
 public override void read(byte[] buffer, int pos, ref PCD_PointBuilder pbb)
 {
     if (id > -1)
     {
         pbb.data[id] = (int)buffer[pos];
     }
 }
Example #5
0
 public override void read(byte[] buffer, int pos, ref PCD_PointBuilder pbb)
 {
     if (id > -1)
     {
         pbb.data[id] = (int)System.BitConverter.ToUInt32(buffer, pos);
     }
 }
Example #6
0
 public override void read(byte[] buffer, int pos, ref PCD_PointBuilder pbb)
 {
 }
Example #7
0
        public bool Import(string path, out PointCloud pc, bool intensity = false)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();

            pc = new PointCloud();

            string header;

            if (!OpenFile(path, out header))
            {
                return(false);
            }
            if (!ParseHeader(header))
            {
                if (this.br != null)
                {
                    this.br.Close();
                }
                return(false);
            }

            log += string.Format("time {0}\n", watch.ElapsedMilliseconds);

            pc.UserDictionary.Set("width", this.width);
            pc.UserDictionary.Set("height", this.height);

            if (this.binary)
            {
                //byte[] buffer;

                int log_step = this.num_points / 5;
                //PCD_PointBuilder pbb;

                byte[]     total_buffer = br.ReadBytes(psize * num_points);
                Point3d[]  points       = new Point3d[num_points];
                Vector3d[] normals      = new Vector3d[num_points];
                Color[]    colors       = new Color[num_points];

                Parallel.For(0, num_points, i => {
                    int total_pos        = i * psize;
                    int pos              = total_pos;
                    PCD_PointBuilder pbb = new PCD_PointBuilder();
                    for (int k = 0; k < m_fields.Count; ++k)
                    {
                        m_fields[k].read(total_buffer, pos, ref pbb);
                        pos       += m_fields[k].size;
                        points[i]  = pbb.Point() * scale;
                        normals[i] = pbb.Normal();
                        if (intensity)
                        {
                            colors[i] = Color.FromArgb(pbb.Intensity());
                        }
                        else
                        {
                            colors[i] = Color.FromArgb(pbb.Color());
                        }
                    }
                });

                pc.AddRange(points, normals, colors);

                /*
                 * for (int i = 0, j = 0; i < this.num_points; ++i, j+=psize)
                 * {
                 *  int pos = j;
                 *  pbb = new PCD_PointBuilder();
                 *
                 *  for (int k = 0; k < this.fields.Count; ++k)
                 *  {
                 *      this.fields[k].read(total_buffer, pos, ref pbb);
                 *      pos += this.fields[k].size;
                 *  }
                 *  if (intensity)
                 *      pc.Add(pbb.Point() * scale, pbb.Normal(), System.Drawing.Color.FromArgb(pbb.Intensity()));
                 *  else
                 *      pc.Add(pbb.Point() * scale, pbb.Normal(), System.Drawing.Color.FromArgb(pbb.Color()));
                 * }
                 */
                log += string.Format("time {0}\n", watch.ElapsedMilliseconds);

                this.br.Close();
                if (use_transform)
                {
                    pc.Transform(this.scan_transform);
                }
                return(true);
            }
            else
            {
                // read all data into buffer
                byte[] buffer = br.ReadBytes((int)br.BaseStream.Length - (int)br.BaseStream.Position);

                // parse buffer as ASCII text
                string bufferStr = System.Text.Encoding.Default.GetString(buffer);

                // split string buffer into list of strings
                List <string> lines = new List <string>(bufferStr.Split('\n'));

                if (lines.Count != this.num_points)
                {
                    log += "Header data doesn't match up with number of data lines!\n";
                }

                // parse points from line data
                for (int i = 0; i < lines.Count; ++i)
                {
                    PCD_PointBuilder pbb    = new PCD_PointBuilder();
                    string[]         tokens = lines[i].Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                    //log += lines[i];
                    //log += " " + tokens.Length.ToString() + "\n";
                    if (tokens.Length != this.m_fields.Count)
                    {
                        continue;
                    }

                    for (int j = 0; j < this.m_fields.Count; ++j)
                    {
                        this.m_fields[j].readASCII(tokens[j], ref pbb);
                    }
                    if (intensity)
                    {
                        pc.Add(pbb.Point() * this.scale, pbb.Normal(), System.Drawing.Color.FromArgb(pbb.Intensity()));
                    }
                    else
                    {
                        pc.Add(pbb.Point() * this.scale, pbb.Normal(), System.Drawing.Color.FromArgb(pbb.Color()));
                    }
                }
                this.br.Close();

                log += string.Format("time {0}\n", watch.ElapsedMilliseconds);

                if (use_transform)
                {
                    pc.Transform(this.scan_transform);
                }
                log += string.Format("time {0}\n", watch.ElapsedMilliseconds);

                return(true);
            }
        }