src/tools/lvr2_asciiconverter/Main.cpp
Go to the documentation of this file.
1 
28 #include "Options.hpp"
29 
30 #include "lvr2/io/Timestamp.hpp"
31 #include "lvr2/io/AsciiIO.hpp"
32 #include "lvr2/io/DataStruct.hpp"
33 #include "lvr2/io/ModelFactory.hpp"
34 #include "lvr2/io/Progress.hpp"
35 
36 #include <iostream>
37 #include <fstream>
38 
39 using namespace lvr2;
40 
41 
45 int main(int argc, char** argv)
46 {
47  // Parse command line arguments
49 
50  // Exit if options had to generate a usage message
51  // (this means required parameters are missing)
52  if (options.printUsage()) return 0;
53 
54  std::cout << options << std::endl;
55 
56  // Get input and putput files
57  string inputFile = options.inputFile();
58  string outputFile = options.outputFile();
59 
60  // Count entries
61  int numEntries = AsciiIO::getEntriesInLine(inputFile);
62  int numLines = AsciiIO::countLines(inputFile);
63  int numPoints = numLines - 1;
64 
65  if(numPoints <= 0)
66  {
67  std::cout << timestamp << "File contains no points. Exiting." << std::endl;
68  }
69 
70  // Check color and intensity options
71  bool readColor = true;
72  if( (options.r() < 0) || (options.g() < 0) || (options.b() < 0) )
73  {
74  readColor = false;
75  }
76 
77  bool readIntensity = options.i() >= 0;
78  bool convert = options.convertRemission();
79 
80  // Print stats
81  std::cout << timestamp << "Read colors\t\t: " << readColor << std::endl;
82  std::cout << timestamp << "Read intensities\t\t: " << readIntensity << std::endl;
83  std::cout << timestamp << "Convert intensities\t: " << convert << std::endl;
84 
85  // Alloc buffers
86  floatArr points(new float[3 * numPoints]);
88  floatArr intensities;
89 
90  if(readColor || (readIntensity && convert))
91  {
92  colors = ucharArr(new unsigned char[3 * numPoints]);
93  }
94 
95  if(readIntensity)
96  {
97  intensities = floatArr(new float[numPoints]);
98  }
99 
100  // Open input file and skip first line
101 
102  string comment = timestamp.getElapsedTime() + "Reading file " + inputFile;
103  ProgressBar progress(numPoints, comment);
104 
105  std::ifstream in(inputFile.c_str());
106  char buffer[2048];
107  if(in.good())
108  {
109  // Data to store the input data
110  float* data = new float[numEntries];
111  in.getline(buffer, 2048);
112  int c = 0;
113  while(in.good() && c <= numPoints)
114  {
115  // Read a new line
116  for(int i = 0; i < numEntries; i++)
117  {
118  in >> data[i];
119  }
120 
121  // Fill data arrays
122  int posPtr = 3 * c;
123 
124  points[posPtr ] = data[options.x()];
125  points[posPtr + 1] = data[options.y()];
126  points[posPtr + 2] = data[options.z()];
127 
128  points[posPtr ] *= options.sx();
129  points[posPtr + 1] *= options.sy();
130  points[posPtr + 2] *= options.sz();
131 
132  if(convert)
133  {
134  colors[posPtr ] = (unsigned char)data[options.i()];
135  colors[posPtr + 1] = (unsigned char)data[options.i()];
136  colors[posPtr + 2] = (unsigned char)data[options.i()];
137  }
138  else if (readColor)
139  {
140  colors[posPtr ] = (unsigned char)data[options.r()];
141  colors[posPtr + 1] = (unsigned char)data[options.g()];
142  colors[posPtr + 2] = (unsigned char)data[options.b()];
143  }
144 
145  if(readIntensity)
146  {
147  intensities[c] = data[options.i()];
148  }
149  c++;
150  ++progress;
151  }
152  delete[] data;
153 
154  // Create model and save data
155  PointBufferPtr pointBuffer(new PointBuffer );
156  pointBuffer->setPointArray(points, numPoints);
157  pointBuffer->setColorArray(colors, numPoints);
158  pointBuffer->addFloatChannel(intensities, "intensities", numPoints, 1);
159 
160  ModelPtr model( new Model(pointBuffer));
161  ModelFactory::saveModel(model, outputFile);
162  }
163  else
164  {
165  std::cout << "Unable to open file for output: " << inputFile << std::endl;
166  }
167 
168  std::cout << std::endl;
169 
170  return 0;
171 }
172 
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
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
lvr2::ProgressBar
Definition: Progress.hpp:68
kaboom::Options::g
int g() const
Returns the position of the x coordinate in the data.
Definition: src/tools/lvr2_kaboom/Options.hpp:97
lvr2::BaseOption::x
int x() const
Returns the position of the x coordinate in the data.
Definition: BaseOption.hpp:77
AsciiIO.hpp
Read and write pointclouds from .pts and .3d files.
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
lvr2::AsciiIO::getEntriesInLine
static int getEntriesInLine(string filename)
Helper method. Returns the number of columns in the given file.
Definition: AsciiIO.cpp:404
Options.hpp
lvr2::PointBuffer
A class to handle point information with an arbitrarily large number of attribute channels....
Definition: PointBuffer.hpp:51
lvr2::Timestamp::getElapsedTime
string getElapsedTime() const
Returns a string representation of the current timer value.
Definition: Timestamp.cpp:136
lvr2::Model
Definition: Model.hpp:51
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::i
int i() const
Returns the position of the x coordinate in the data.
Definition: src/tools/lvr2_kaboom/Options.hpp:107
ascii_convert::Options
A class to parse the program options for the reconstruction executable.
Definition: src/tools/lvr2_asciiconverter/Options.hpp:59
lvr2::convert
void convert(COORD_SYSTEM from, COORD_SYSTEM to, float *point)
Definition: CoordinateTransform.cpp:46
lvr2::AsciiIO::countLines
static size_t countLines(string filename)
TODO: Coordinate mapping for ascii files.
Definition: AsciiIO.cpp:386
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
DataStruct.hpp
Datastructures for holding loaded data.
Progress.hpp
scripts.create_png.colors
colors
Definition: create_png.py:41
argc
int argc
Definition: tests_high_five_parallel.cpp:27
main
int main(int argc, char **argv)
Main entry point for the LSSR surface executable.
Definition: src/tools/lvr2_asciiconverter/Main.cpp:45
lvr2::ucharArr
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
lvr2::BaseOption::sx
float sx() const
Returns the scaling factor for the x coordinates.
Definition: BaseOption.hpp:62
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
kaboom::Options::r
int r() const
Returns the position of the x coordinate in the data.
Definition: src/tools/lvr2_kaboom/Options.hpp:92
lvr2::BaseOption::sy
float sy() const
Returns the scaling factor for the y coordinates.
Definition: BaseOption.hpp:67
Timestamp.hpp
ModelFactory.hpp
lvr2::BaseOption::sz
float sz() const
Returns the scaling factor for the z coordinates.
Definition: BaseOption.hpp:72
argv
char ** argv
Definition: tests_high_five_parallel.cpp:28
kaboom::Options::b
int b() const
Returns the position of the x coordinate in the data.
Definition: src/tools/lvr2_kaboom/Options.hpp:102


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