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 */
A class to handle point information with an arbitrarily large number of attribute channels...
Definition: PointBuffer.hpp:51
BOOL read_point()
Definition: lasreader.hpp:74
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
LASpoint point
Definition: lasreader.hpp:53
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
I64 npoints
Definition: lasreader.hpp:55
std::shared_ptr< PointBuffer > PointBufferPtr
ModelPtr m_model
Definition: BaseIO.hpp:104
void set_file_name(const char *file_name, BOOL unique=FALSE)
Definition: lasreader.cpp:997
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
virtual void save(string filename)
Save the loaded elements to the given file.
Definition: LasIO.cpp:107
LASreader * open()
Definition: lasreader.cpp:312
BOOL active() const
Definition: lasreader.cpp:1195
virtual ModelPtr read(string filename)
Parse the given file and load supported elements.
Definition: LasIO.cpp:48


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 Mon Feb 28 2022 22:46:07