src/tools/lvr2_transform/Main.cpp
Go to the documentation of this file.
1 
28 /*
29  * main.cpp
30  *
31  * @date 2012-08-23
32  * @author Christian Wansart <cwansart@uos.de>
33  * @author Thomas Wiemann
34  */
35 
36 #include "Options.hpp"
39 #include "lvr2/io/Model.hpp"
40 #include "lvr2/io/ModelFactory.hpp"
41 #include "lvr2/io/Timestamp.hpp"
42 #include <iostream>
43 #include <cmath>
44 
45 using namespace lvr2;
46 using std::cout;
47 using std::endl;
48 
50 
51 
52 int main(int argc, char **argv)
53 {
54  try {
55  bool did_anything = false;
56  float x, y, z, r1, r2, r3;
57  Matrix4<Vec> mat;
58  size_t num;
59 
60  // get options
62 
63  // quit if usage was printed
64  if(options.printUsage())
65  return 0;
66 
67  // load model via ModelFactory
69 
70  if(!model)
71  {
72  cout << timestamp << "IO Error: Unable to parse " << options.getInputFile() << endl;
73  exit(-1);
74  }
75 
76  if(options.anyTransformFile())
77  {
78  // Check if transformFile was given, check if it's a pose or frames file and
79  // read in accordingly.
80  ifstream in(options.getTransformFile().c_str());
81  if(!in.good()){
82  cout << timestamp << "Warning: Load transform file: File not found or corrupted." << endl;
83  return -1;
84  }
85 
86  if(options.getTransformFile().substr(options.getTransformFile().length()-5) == ".pose")
87  {
88  cout << timestamp << "Reading from .pose file" << endl;
89  in >> x >> y >> z >> r1 >> r2 >> r3;
90 
91  r1 = r1 * 0.0174532925f;
92  r2 = r2 * 0.0174532925f;
93  r3 = r3 * 0.0174532925f;
94 
95  mat = Matrix4<Vec>(Vec(x, y, z), Vec(r1, r2, r3));
96  }
97  else //expect frames file instead
98  {
99  cout << timestamp << "Reading from .frames file" << endl;
100  float t[17];
101  ifstream in(options.getTransformFile().c_str());
102  while(in.good())
103  {
104  in >> t[0] >> t[1] >> t[2] >> t[3]
105  >> t[4] >> t[5] >> t[6] >> t[7]
106  >> t[8] >> t[9] >> t[10] >> t[11]
107  >> t[12] >> t[13] >> t[14] >> t[15]
108  >> t[16]; // we don't need this value but we need to skip it
109  }
110 
111  for(int i = 0; i < 16; ++i)
112  mat.set(i, t[i]);
113  }
114  }
115  else // read from s, r or t
116  {
117  x = y = z = r1 = r2 = r3 = 0.0f;
118 
119  if(options.anyRotation())
120  {
121  if(options.anyRotationX())
122  r1 = options.getRotationX();
123 
124  if(options.anyRotationY())
125  r2 = options.getRotationY();
126 
127  if(options.anyRotationZ())
128  r3 = options.getRotationZ();
129  }
130 
131  if(options.anyTranslation())
132  {
133  if(options.anyTranslationX())
134  x = options.getTranslationX();
135 
136  if(options.anyTranslationY())
137  y = options.getTranslationY();
138 
139  if(options.anyTranslationZ())
140  z = options.getTranslationZ();
141  }
142 
143  // To radians
144  r1 = r1 * 0.0174532925f;
145  r2 = r2 * 0.0174532925f;
146  r3 = r3 * 0.0174532925f;
147 
148  mat = Matrix4<Vec>(Vec(x, y, z), Vec(r1, r2, r3));
149  }
150 
151  // Get point buffer
152  if(model->m_pointCloud)
153  {
154  PointBufferPtr p_buffer = model->m_pointCloud;
155 
156  cout << timestamp << "Using points" << endl;
157  did_anything = true;
158  FloatChannelOptional points = p_buffer->getFloatChannel("points");
159 
160  cout << mat;
161  for(size_t i = 0; i < points->numElements(); i++)
162  {
163  Vec v((*points)[i][0], (*points)[i][1], (*points)[i][2]);
164  v = mat * v;
165  v.x = options.anyScaleX() ? v[0] * options.getScaleX() : v[0];
166  v.y = options.anyScaleX() ? v[1] * options.getScaleX() : v[1];
167  v.z = options.anyScaleX() ? v[2] * options.getScaleX() : v[2];
168  (*points)[i] = v;
169  }
170  }
171 
172  // Get mesh buffer
173  if(model->m_mesh)
174  {
175  MeshBufferPtr m_buffer = model->m_mesh;
176 
177  cout << timestamp << "Using meshes" << endl;
178  did_anything = true;
179  FloatChannelOptional points = m_buffer->getFloatChannel("vertices");
180 
181  for(size_t i = 0; i < points->numElements(); i++)
182  {
183  Vec v((*points)[i][0], (*points)[i][1], (*points)[i][2]);
184  v = mat * v;
185  v.x = options.anyScaleX() ? v[0] * options.getScaleX() : v[0];
186  v.y = options.anyScaleX() ? v[1] * options.getScaleX() : v[1];
187  v.z = options.anyScaleX() ? v[2] * options.getScaleX() : v[2];
188  (*points)[i] = v;
189  }
190  }
191 
192  if(!did_anything)
193  {
194  std::cerr << timestamp << "I had nothing to do. Terminating now..." << std::endl;
195  return 0;
196  }
197  else
198  {
199  cout << timestamp << "Finished. Program end." << endl;
200  }
201 
203  } catch(...) {
204  cout << "something went wrong..." << endl;
205  }
206 }
lvr2::BaseOption::z
int z() const
Returns the position of the x coordinate in the data.
Definition: BaseOption.hpp:87
lvr2::ModelFactory::saveModel
static void saveModel(ModelPtr m, std::string file)
Definition: ModelFactory.cpp:225
BaseVector.hpp
lvr2::Matrix4
A 4x4 matrix class implementation for use with the provided vertex types.
Definition: Matrix4.hpp:64
lvr2::BaseVector< float >
lvr2::Vec
BaseVector< float > Vec
Definition: TexturedMesh.hpp:44
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
lvr2::BaseVector::x
CoordT x
Definition: BaseVector.hpp:65
lvr2::FloatChannelOptional
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
Options.hpp
kaboom::Options::getInputFile
string getInputFile() const
Definition: src/tools/lvr2_kaboom/Options.cpp:93
transform::Options
A class to parse the program options for the reconstruction executable.
Definition: src/tools/lvr2_transform/Options.hpp:60
lvr2::BaseOption::y
int y() const
Returns the position of the x coordinate in the data.
Definition: BaseOption.hpp:82
options
const kaboom::Options * options
Definition: src/tools/lvr2_kaboom/Main.cpp:45
kaboom::Options::getOutputFile
string getOutputFile() const
Definition: src/tools/lvr2_kaboom/Options.cpp:88
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
Model.hpp
argc
int argc
Definition: tests_high_five_parallel.cpp:27
Matrix4.hpp
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
Timestamp.hpp
main
int main(int argc, char **argv)
Definition: src/tools/lvr2_transform/Main.cpp:52
lvr2::ModelFactory::readModel
static ModelPtr readModel(std::string filename)
Definition: ModelFactory.cpp:65
ModelFactory.hpp
lvr2::Matrix4::set
void set(int i, ValueType value)
Sets the given index of the Matrix's data field to the provided value.
Definition: Matrix4.hpp:401
argv
char ** argv
Definition: tests_high_five_parallel.cpp:28


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