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
61  transform::Options options(argc, argv);
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 
202  ModelFactory::saveModel(model, options.getOutputFile());
203  } catch(...) {
204  cout << "something went wrong..." << endl;
205  }
206 }
string getInputFile() const
Returns the output file name.
const kaboom::Options * options
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
A 4x4 matrix class implementation for use with the provided vertex types.
Definition: Matrix4.hpp:64
bool anyTransformFile() const
Returns true if transform file is given.
A class to parse the program options for the reconstruction executable.
bool anyTranslationX() const
Returns true if there is any x translation value.
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
float getTranslationY() const
Returns the y axis translation.
static ModelPtr readModel(std::string filename)
bool anyTranslation() const
Returns true if there is any translation value.
bool anyScaleX() const
Returns true if there is any x-scale value.
string getTransformFile() const
Returns the transform file name.
std::shared_ptr< PointBuffer > PointBufferPtr
void set(int i, ValueType value)
Sets the given index of the Matrix&#39;s data field to the provided value.
Definition: Matrix4.hpp:401
float getTranslationZ() const
Returns the z axis translation.
bool anyRotationX() const
Returns true if there is any x-rotation value.
float getRotationZ() const
Returns the z axis rotation.
BaseVector< float > Vec
string getOutputFile() const
Returns the output file name.
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
int main(int argc, char **argv)
bool anyTranslationZ() const
Returns true if there is any z translation value.
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
bool anyRotationY() const
Returns true if there is any y-rotation value.
float getTranslationX() const
Returns the x axis translation.
bool anyTranslationY() const
Returns true if there is any y translation value.
bool anyRotationZ() const
Returns true if there is any z-rotation value.
float getScaleX() const
Returns the x axis scale.
bool anyRotation() const
Returns true if there is any rotation value.
float getRotationX() const
Returns the x axis rotation.
float getRotationY() const
Returns the y axis rotation.
bool printUsage() const
Prints a usage message to stdout.
static void saveModel(ModelPtr m, std::string file)
char ** argv


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