src/tools/lvr2_cl_sor/Main.cpp
Go to the documentation of this file.
1 
28 #include <boost/filesystem.hpp>
29 
31 #include "lvr2/io/ModelFactory.hpp"
32 #include "lvr2/io/DataStruct.hpp"
33 #include "lvr2/io/Timestamp.hpp"
34 #include "lvr2/io/IOUtils.hpp"
35 //#include "Options.hpp"
36 
37 
38 using namespace lvr2;
39 
40 void filter(lvr2::PointBufferPtr& cloud, lvr2::indexArray& inlier, size_t j)
41 {
42  lvr2::PointBufferPtr cloud_filtered(new lvr2::PointBuffer());
43  int type;
44  std::map<std::string, lvr2::Channel<float> > floatChannels;
45  type = cloud->getAllChannelsOfType<float>(floatChannels);
46 
47  std::vector<lvr2::FloatChannelPtr> channels;
48  for(auto channelPair: floatChannels)
49  {
50  std::string name = channelPair.first;
51  auto channel2 = channelPair.second;
52  lvr2::FloatChannelPtr filtered(new lvr2::FloatChannel(j, channel2.width()));
53  channels.push_back(filtered);
54  for(size_t i = 0; i < j; ++i)
55  {
56  size_t index = inlier[i];
57  for(size_t k = 0; k < channel2.width(); ++k)
58  {
59  (*filtered)[i][k] = channel2[index][k];
60  }
61  }
62 // cloud->removeFloatChannel(name);
63  cloud_filtered->addFloatChannel(filtered, name);
64 
65  }
66 
67  std::vector<lvr2::UCharChannelPtr> channels_uchar;
68  std::map<std::string, lvr2::Channel<unsigned char> > uCharChannels;
69  int ucharType = cloud->getAllChannelsOfType<unsigned char>(uCharChannels);
70  for(auto channelPair: uCharChannels)
71  {
72  std::string name = channelPair.first;
73  auto channel2 = channelPair.second;
74  lvr2::UCharChannelPtr filtered(new lvr2::UCharChannel(j, channel2.width()));
75  channels_uchar.push_back(filtered);
76  for(size_t i = 0; i < j; ++i)
77  {
78  size_t index = inlier[i];
79  for(size_t k = 0; k < channel2.width(); ++k)
80  {
81  (*filtered)[i][k] = channel2[index][k];
82  }
83  }
84 // cloud->removeUCharChannel(name);
85  cloud_filtered->addUCharChannel(filtered, name);
86  }
87 
88  cloud = cloud_filtered;
89 }
90 
91 int main(int argc, char** argv){
92  ModelPtr model = ModelFactory::readModel(argv[1]);
93  size_t num_points;
94 
95 
96  UCharChannelOptional colorsOpt = model->m_pointCloud->getUCharChannel("colors");
97 
98  // filter based on grayscale from rgb
99  //
100 // if(colorsOpt)
101 // {
102 // lvr2::uintArr inlier2 = lvr2::uintArr(new unsigned int[model->m_pointCloud->numPoints()]);
103 // std::cout << timestamp << "filter based on grayscale" << std::endl;
104 // size_t k = 0;
105 // for(size_t i = 0; i < colorsOpt->numElements(); ++i)
106 // {
107 // int scalar = (*colorsOpt)[i][0] +
108 // (*colorsOpt)[i][1] +
109 // (*colorsOpt)[i][2];
110 // scalar /= 3;
111 // if(scalar < 255)
112 // {
113 // inlier2[k++] = i;
114 // }
115 // }
116 //
117 // std::cout << timestamp << "outliers " << model->m_pointCloud->numPoints() - k << std::endl;
118 // std::cout << timestamp << "inliers " << k << std::endl;
119 // filter(model->m_pointCloud, inlier2, k);
120 // }
121 
122  floatArr points;
123  if (model && model->m_pointCloud )
124  {
125  num_points = model->m_pointCloud->numPoints();
126  points = model->m_pointCloud->getPointArray();
127  cout << timestamp << "Read " << num_points << " points from " << argv[1] << endl;
128  }
129  else
130  {
131  cout << timestamp << "Warning: No point cloud data found in " << argv[1] << endl;
132  return 0;
133  }
134 
135  lvr2::uintArr inlier = lvr2::uintArr(new unsigned int[num_points]);
136 
137  cout << timestamp << "Constructing kd-tree..." << endl;
138  ClSOR sor(points, num_points, 20);
139  cout << timestamp << "Finished kd-tree construction." << endl;
140 
141 
142  sor.calcDistances();
143  cout << timestamp << "Got Nearest Neighbors" << std::endl;
144  sor.calcStatistics();
145  cout << timestamp << "Got Statistics" << std::endl;
146  sor.setMult(1.5);
147 
148  int j = sor.getInliers(inlier);
149 
150  std::cout << timestamp << "outliers " << num_points - j << std::endl;
151  std::cout << timestamp << "inliers " << j << std::endl;
152 
153  filter(model->m_pointCloud, inlier, j);
154 
155 // lvr2::PointBufferPtr cloud = model->m_pointCloud;
156 // lvr2::PointBufferPtr cloud_filtered(new lvr2::PointBuffer());
157 // int type;
158 // std::map<std::string, lvr2::Channel<float> > floatChannels;
159 // type = cloud->getAllChannelsOfType<float>(floatChannels);
160 //
161 // std::vector<lvr2::FloatChannelPtr> channels;
162 // for(auto channelPair: floatChannels)
163 // {
164 // std::string name = channelPair.first;
165 // auto channel2 = channelPair.second;
166 // lvr2::FloatChannelPtr filtered(new lvr2::FloatChannel(j, channel2.width()));
167 // channels.push_back(filtered);
168 // for(size_t i = 0; i < j; ++i)
169 // {
170 // size_t index = inlier[i];
171 // for(size_t k = 0; k < channel2.width(); ++k)
172 // {
173 // (*filtered)[i][k] = channel2[index][k];
174 // }
175 // }
177 // cloud_filtered->addFloatChannel(filtered, name);
178 //
179 // }
180 //
181 // std::vector<lvr2::UCharChannelPtr> channels_uchar;
182 // std::map<std::string, lvr2::Channel<unsigned char> > uCharChannels;
183 // int ucharType = cloud->getAllChannelsOfType<unsigned char>(uCharChannels);
184 // for(auto channelPair: uCharChannels)
185 // {
186 // std::string name = channelPair.first;
187 // auto channel2 = channelPair.second;
188 // lvr2::UCharChannelPtr filtered(new lvr2::UCharChannel(j, channel2.width()));
189 // channels_uchar.push_back(filtered);
190 // for(size_t i = 0; i < j; ++i)
191 // {
192 // size_t index = inlier[i];
193 // for(size_t k = 0; k < channel2.width(); ++k)
194 // {
195 // (*filtered)[i][k] = channel2[index][k];
196 // }
197 // }
199 // cloud_filtered->addUCharChannel(filtered, name);
200 // }
201 // lvr2::ModelPtr model_filtered(new lvr2::Model(cloud_filtered, lvr2::MeshBufferPtr()));
202  lvr2::ModelFactory::saveModel(model, argv[2]);
203 
204  return 0;
205 
206 }
A class to handle point information with an arbitrarily large number of attribute channels...
Definition: PointBuffer.hpp:51
Datastructures for holding loaded data.
boost::shared_array< unsigned int > uintArr
Definition: DataStruct.hpp:130
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
static ModelPtr readModel(std::string filename)
void setMult(float std_dev_mult)
UCharChannel::Optional UCharChannelOptional
Definition: Channel.hpp:96
std::shared_ptr< PointBuffer > PointBufferPtr
int main(int argc, char **argv)
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
int getInliers(lvr2::indexArray &inliers)
void filter(lvr2::PointBufferPtr &cloud, lvr2::indexArray &inlier, size_t j)
UCharChannel::Ptr UCharChannelPtr
Definition: Channel.hpp:97
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
FloatChannel::Ptr FloatChannelPtr
Definition: Channel.hpp:89
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