LasIO.cpp
Go to the documentation of this file.
1 
35 #include <iostream>
36 using std::cout;
37 using std::endl;
38 
39 #include "lvr2/io/LasIO.hpp"
40 #include "lvr2/io/Timestamp.hpp"
41 
42 #include <lasreader.hpp>
43 #include <laswriter.hpp>
44 
45 namespace lvr2
46 {
47 
49 {
50 
51  // Create Lasreader object
52  LASreadOpener lasreadopener;
53  lasreadopener.set_file_name(filename.c_str());
54 
55  if(lasreadopener.active())
56  {
57  LASreader* lasreader = lasreadopener.open();
58 
59  // Get number of points in file
60  size_t num_points = lasreader->npoints;
61 
62  // Alloc coordinate array
63  floatArr points ( new float[3 * num_points]);
64  floatArr intensities ( new float[num_points]);
65  ucharArr colors (new unsigned char[3 * num_points]);
66 
67  // Read point data
68  for(size_t i = 0; i < num_points; i++)
69  {
70  size_t buf_pos = 3 * i;
71  lasreader->read_point();
72  points[buf_pos] = lasreader->point.x;
73  points[buf_pos + 1] = lasreader->point.y;
74  points[buf_pos + 2] = lasreader->point.z;
75 
76  // Create fake colors from intensities
78  colors[buf_pos] = lasreader->point.intensity;
79  colors[buf_pos + 1] = lasreader->point.intensity;
80  colors[buf_pos + 2] = lasreader->point.intensity;
81 
82  intensities[i] = lasreader->point.intensity;
83 
84  }
85 
86  // Create point buffer and model
87  PointBufferPtr p_buffer( new PointBuffer);
88  p_buffer->setPointArray(points, num_points);
89  p_buffer->addFloatChannel(intensities, "intensities", num_points, 1);
90  p_buffer->setColorArray(colors, num_points);
91 
92  ModelPtr m_ptr( new Model(p_buffer));
93  m_model = m_ptr;
94 
95  delete lasreader;
96 
97  return m_ptr;
98  }
99  else
100  {
101  cout << timestamp << "LasIO::read(): Unable to open file " << filename << endl;
102  return ModelPtr();
103  }
104 }
105 
106 
107 void LasIO::save( string filename )
108 {
110  std::cerr << "LASIO: Saving not yet implemented." << endl;
111 }
112 
113 } /* namespace lvr2 */
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
LASreader::point
LASpoint point
Definition: lasreader.hpp:53
lasreader.hpp
LASreadOpener::active
BOOL active() const
Definition: lasreader.cpp:1195
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
LASreadOpener::open
LASreader * open()
Definition: lasreader.cpp:312
LASreader::npoints
I64 npoints
Definition: lasreader.hpp:55
lvr2::PointBuffer
A class to handle point information with an arbitrarily large number of attribute channels....
Definition: PointBuffer.hpp:51
lvr2::LasIO::save
virtual void save(string filename)
Save the loaded elements to the given file.
Definition: LasIO.cpp:107
lvr2::Model
Definition: Model.hpp:51
laswriter.hpp
LASpoint::y
I32 y
Definition: lasdefinitions.hpp:479
LasIO.hpp
lvr2::LasIO::read
virtual ModelPtr read(string filename)
Parse the given file and load supported elements.
Definition: LasIO.cpp:48
LASreader
Definition: lasreader.hpp:49
LASreadOpener::set_file_name
void set_file_name(const char *file_name, BOOL unique=FALSE)
Definition: lasreader.cpp:997
scripts.normalize_multiple.filename
filename
Definition: normalize_multiple.py:60
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
LASreadOpener
Definition: lasreader.hpp:133
scripts.create_png.colors
colors
Definition: create_png.py:41
LASpoint::z
I32 z
Definition: lasdefinitions.hpp:480
lvr2::BaseIO::m_model
ModelPtr m_model
Definition: BaseIO.hpp:104
lvr2::ucharArr
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
Timestamp.hpp
LASpoint::x
I32 x
Definition: lasdefinitions.hpp:478
LASreader::read_point
BOOL read_point()
Definition: lasreader.hpp:74
LASpoint::intensity
U16 intensity
Definition: lasdefinitions.hpp:481


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23