RxpIO.cpp
Go to the documentation of this file.
1 
28 #include <iostream>
29 #include <assert.h>
30 
31 #include <riegl/scanifc.h>
32 
33 
34 
35 #include "lvr2/io/PointBuffer.hpp"
36 #include "lvr2/io/Model.hpp"
37 #include "lvr2/io/RxpIO.hpp"
39 
40 namespace lvr2
41 {
42 
43 
45 {
46  return read(filename, 1, Transformd::Identity());
47 }
48 
49 ModelPtr RxpIO::read(std::string filename, int reduction_factor, const Transformd& tf)
50 {
51  if (reduction_factor < 1)
52  {
53  reduction_factor = 1;
54  }
55 
56  // open file
57  point3dstream_handle stream;
58  if (check_error(scanifc_point3dstream_open(("file:" + filename).c_str(), 0, &stream)))
59  {
60  return ModelPtr();
61  }
62 
63  std::vector<BaseVector<float> > data;
64  BaseVector<float> cur_point;
65 
66  const unsigned int point_buf_size = 32768;
67  scanifc_xyz32_t point_buf[point_buf_size];
68  int end_of_frame = 0;
69  unsigned int got = 0;
70  int count = 0;
71 
72 
73  // read data
74  do
75  {
76 
77  if (check_error(scanifc_point3dstream_read(stream, point_buf_size, point_buf, 0, 0, &got, &end_of_frame)))
78  {
79  return ModelPtr();
80  }
81 
82  // use points here
83  for (int i = 0; i < got; i++)
84  {
85  if (count++ % reduction_factor == 0)
86  {
87  cur_point.x = point_buf[i].x;
88  cur_point.y = point_buf[i].y;
89  cur_point.z = point_buf[i].z;
90 
91  data.push_back(tf * cur_point);
92  }
93  }
94 
95  } while(end_of_frame || got);
96 
97 
98  // TODO check this for null?
99  float *data2 = new float[data.size() * 3];
100  assert(data2 != nullptr);
101 
102  // TODO Since we don't know the size in advance there is no better way?
103  for (int i = 0; i < data.size(); i++)
104  {
105  data2[i*3 + 0] = data[i].x;
106  data2[i*3 + 1] = data[i].y;
107  data2[i*3 + 2] = data[i].z;
108  }
109 
110  PointBufferPtr pbp(new PointBuffer());
111  pbp->setPointArray(floatArr(data2), data.size());
112 
113  // close file
114  if (check_error(scanifc_point3dstream_close(stream)))
115  {
116  // if we get an error while closing the file we shouldn't do anything
117  }
118 
119  return ModelPtr(new Model(MeshBufferPtr(), pbp));
120 }
121 
122 void RxpIO::save(std::string filename)
123 {
124  std::cout << "[RxpIO] Error: Saving files to .rxp format is not supported" << std::endl;
125 }
126 
127 bool RxpIO::check_error(int error_code)
128 {
129  if (error_code)
130  {
131  // TODO check if string is zero delimited IF msg_size > (>=) msg_buf_size!
132  unsigned int msg_buf_size = 2048;
133  char msg_buf[msg_buf_size];
134  unsigned int msg_size = 0;
135 
136  scanifc_get_last_error(msg_buf, msg_buf_size, &msg_size);
137 
138  std::cout << "[RxpIO] Error: " << msg_buf << std::endl;
139 
140  return true;
141  }
142  else
143  {
144  return false;
145  }
146 }
147 
148 } // namespace lvr2
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
BaseVector.hpp
lvr2::BaseVector< float >
lvr2::Transformd
Transform< double > Transformd
4x4 double precision transformation matrix
Definition: MatrixTypes.hpp:71
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
RxpIO.hpp
lvr2::PointBuffer
A class to handle point information with an arbitrarily large number of attribute channels....
Definition: PointBuffer.hpp:51
lvr2::BaseVector::x
CoordT x
Definition: BaseVector.hpp:65
lvr2::Model
Definition: Model.hpp:51
lvr2::RxpIO::read
ModelPtr read(std::string filename)
Reads .rxp files.
Definition: RxpIO.cpp:44
lvr2::BaseVector::y
CoordT y
Definition: BaseVector.hpp:66
PointBuffer.hpp
scripts.normalize_multiple.filename
filename
Definition: normalize_multiple.py:60
Model.hpp
lvr2::BaseVector::z
CoordT z
Definition: BaseVector.hpp:67
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
lvr2::MeshBufferPtr
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
lvr2::RxpIO::save
void save(std::string filename)
This function is not supported and will do nothing.
Definition: RxpIO.cpp:122


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:24