Class: NMatrix::IO::PointCloud::MetaReader
- Defined in:
- lib/nmatrix/io/point_cloud.rb
Overview
:nodoc:
Constant Summary collapse
- ENTRIES =
[:version, :fields, :size, :type, :count, :width, :height, :viewpoint, :points, :data]
- ASSIGNS =
[:version=, :fields=, :size=, :type=, :count=, :width=, :height=, :viewpoint=, :points=, :data=]
- CONVERT =
[:to_s, :downcase_to_sym, :to_i, :downcase_to_sym, :to_i, :to_i, :to_i, :to_f, :to_i, :downcase_to_sym]
- DTYPE_CONVERT =
{:byte => :to_i, :int8 => :to_i, :int16 => :to_i, :int32 => :to_i, :float32 => :to_f, :float64 => :to_f}
- INT_DTYPE_BY_SIZE =
For UINT, just add 1 to the index.
{1 => :int8, 2 => :int16, 4 => :int32, 8 => :int64, 16 => :int64}
- FLOAT_DTYPE_BY_SIZE =
{1 => :float32, 2 => :float32, 4 => :float32, 8 => :float64,16 => :float64}
Instance Attribute Summary collapse
-
#matrix ⇒ Object
readonly
Returns the value of attribute matrix.
Class Method Summary collapse
-
.dtype_by_type_and_size(t, s) ⇒ Object
Given a type and a number of bytes, figure out an appropriate dtype.
Instance Method Summary collapse
-
#initialize(filename) ⇒ MetaReader
constructor
call-seq: PointCloudReader::MetaReader.new(filename) -> MetaReader.
Constructor Details
#initialize(filename) ⇒ MetaReader
call-seq:
PointCloudReader::MetaReader.new(filename) -> MetaReader
-
Arguments :
-
filename
-> String giving the name of the file to be loaded.
-
-
Raises :
-
NotImplementedError
-> only ASCII supported currently -
IOError
-> premature end of file
-
Open a file and read the metadata at the top; then read the PCD into an NMatrix.
In addition to the fields in the PCD file, there will be at least one additional attribute, :matrix, storing the data.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/nmatrix/io/point_cloud.rb', line 103 def initialize filename f = File.new(filename, "r") ENTRIES.each.with_index do |entry,i| read_entry(f, entry, ASSIGNS[i], CONVERT[i]) end raise(NotImplementedError, "only ASCII supported currently") \ unless self.data.first == :ascii @matrix = NMatrix.new(self.shape, dtype: self.dtype) # Do we want to use to_i or to_f? convert = DTYPE_CONVERT[self.dtype] i = 0 while line = f.gets @matrix[i,:*] = line.chomp.split.map { |f| f.send(convert) } i += 1 end raise(IOError, "premature end of file") if i < self.points[0] end |
Instance Attribute Details
#matrix ⇒ Object (readonly)
Returns the value of attribute matrix.
129 130 131 |
# File 'lib/nmatrix/io/point_cloud.rb', line 129 def matrix @matrix end |
Class Method Details
.dtype_by_type_and_size(t, s) ⇒ Object
Given a type and a number of bytes, figure out an appropriate dtype
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/nmatrix/io/point_cloud.rb', line 77 def dtype_by_type_and_size t, s if t == :f FLOAT_DTYPE_BY_SIZE[s] elsif t == :u return :byte if s == 1 INT_DTYPE_BY_SIZE[s*2] else INT_DTYPE_BY_SIZE[s] end end |