Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filename">File to read from</param>
        /// <param name="offset">Offset to start reading from</param>
        /// <returns>Pointcloud of type T</returns>
        public PointCloud <T> Read(String filename, int offset)
        {
            PCDHeader header = ReadHeader(filename);
            List <T>  pointList;

            // Start reading data
            using (StreamReader sr = new StreamReader(filename))
            {
                String line = sr.ReadLine();

                while (!line.Contains("DATA"))
                {
                    line = sr.ReadLine();
                }

                if (line.Contains("ascii"))
                {
                    pointList = readData(sr);
                }
                else
                {
                    throw new PCDReaderException("Data in file in unrecognized format.");
                }
            }

            PointCloud <T> cloud = new PointCloud <T>(pointList);

            cloud.Height = header.Height;
            cloud.Width  = header.Width;

            return(cloud);
        }
Exemple #2
0
        /// <summary>
        /// Reads the header of PCD file;
        /// </summary>
        /// <param name="filename">PCD File</param>
        /// <returns>PCDHeader object</returns>
        public PCDHeader ReadHeader(string filename)
        {
            PCDHeader header = new PCDHeader();

            using (StreamReader sr = new StreamReader(filename))
            {
                String line = sr.ReadLine();

                // TODO: Code needs some refactoring. Lots of repeated code but it works.
                // Keep reading until Datasection is found
                while (line != null && !line.Contains("DATA"))
                {
                    if (line.Contains("VERSION"))
                    {
                        header.Version = getVersion(line);
                    }
                    if (line.Contains("FIELDS"))
                    {
                        // Read fieldsnames from the line expects no spaces in field name
                        string[] fields = line.Substring(7).Split(' ');

                        for (int i = 0; i < fields.Length; i++)
                        {
                            header.Fields.Add(i, new FieldDescription {
                                Name = fields[i]
                            });
                        }
                    }
                    if (line.Contains("SIZE"))
                    {
                        if (header.Fields.Count == 0)
                        {
                            throw new PointCloudException("No fields found in pcb file.");
                        }

                        string[] fields = line.Substring(7).Split(' ');

                        for (int i = 0; i < fields.Length; i++)
                        {
                            FieldDescription desc = header.Fields[i];
                            desc.Size        = Convert.ToInt32(fields[i]);
                            header.Fields[i] = desc;
                        }
                    }
                    if (line.Contains("TYPE"))
                    {
                        if (header.Fields.Count == 0)
                        {
                            throw new PointCloudException("No fields found in pcb file.");
                        }

                        string[] fields = line.Substring(5).Split(' ');

                        for (int i = 0; i < fields.Length; i++)
                        {
                            FieldDescription desc = header.Fields[i];
                            desc.Type        = fields[i].ToCharArray()[0];
                            header.Fields[i] = desc;
                        }
                    }

                    if (line.Contains("COUNT"))
                    {
                        if (header.Fields.Count == 0)
                        {
                            throw new PointCloudException("No fields found in pcb file.");
                        }

                        string[] fields = line.Substring(6).Split(' ');

                        for (int i = 0; i < fields.Length; i++)
                        {
                            FieldDescription desc = header.Fields[i];
                            desc.Count       = Convert.ToInt32(fields[i]);
                            header.Fields[i] = desc;
                        }
                    }
                    if (line.Contains("WIDTH"))
                    {
                        header.Width = Convert.ToInt32(line.Substring(6));
                    }
                    if (line.Contains("HEIGHT"))
                    {
                        header.Height = Convert.ToInt32(line.Substring(7));
                    }

                    line = sr.ReadLine();
                }
            }

            return(header);
        }