PointSave.cpp
Go to the documentation of this file.
1 #include <kfusion/PointSave.hpp>
2 
3 using namespace lvr;
4 
5 bool PointSave::savePoints(const char* filename,std::vector<std::vector<ColorVertex<float, unsigned char> > > rcb,int size){
6  if(rcb.size() > 0) {
7  ofstream point_file;
8  point_file.open(filename);
9 
10  point_file << "ply" << endl;
11  point_file << "format ascii 1.0" << endl;
12  point_file << "element vertex "<< std::to_string(size)<< endl;
13  point_file << "property float x\nproperty float y\nproperty float z" << endl;
14  point_file << "property uchar red\nproperty uchar green\nproperty uchar blue" << endl;
15 
16  point_file << "end_header" << endl;
17 
18  for(int i=0;i<rcb.size();i++){
19  for(int j=0;j<rcb[i].size();j++){
20  for(int k=0;k<3;k++){
21  point_file << rcb[i][j][k] << " ";
22  }
23  point_file << i*255/rcb.size() << " " << i*255/rcb.size() << " " << i*255/rcb.size() << endl;
24 
25  }
26  }
27 
28  point_file.close();
29  }
30 }
31 
32 bool PointSave::savePointsWithCameras(const char* filename,std::vector<std::vector<ColorVertex<float, unsigned char> > > rcb, int size, std::vector<kfusion::ImgPose> image_pose_buffer){
33  if(rcb.size() > 0) {
34  ofstream point_file;
35  point_file.open(filename);
36 
37  point_file << "ply" << std::endl;
38  point_file << "format ascii 1.0" << std::endl;
39  point_file << "element vertex "<< std::to_string(size +image_pose_buffer.size()) << std::endl;
40  point_file << "property float x\nproperty float y\nproperty float z" << std::endl;
41  point_file << "property uchar red\nproperty uchar green\nproperty uchar blue" << std::endl;
42 
43 
44  point_file << "end_header" << std::endl;
45 
46  for(int i=0;i<rcb.size();i++){
47  for(int j=0;j<rcb[i].size();j++){
48  for(int k=0;k<3;k++){
49  point_file << rcb[i][j][k] << " ";
50  }
51  point_file << i*255/rcb.size() << " " << i*255/rcb.size() << " " << i*255/rcb.size() << std::endl;
52  }
53  }
54 
55  //cameras einzeichnen in rot
56  cv::Vec3f dst;
57 
58  for(int i=0;i<image_pose_buffer.size();i++){
59  cv::Vec3f z_dir(image_pose_buffer[i].pose.rotation() * (cv::Vec3f(0,0,1)));
60  z_dir = z_dir * 1/4;
61  dst = image_pose_buffer[i].pose.translation();
62  point_file << dst[0] << " " << dst[1] << " " << dst[2] << " 255 0 0"<< endl;
63  cv::Vec3f direction = dst + z_dir;
64  point_file << dst[0] << " " << dst[1] << " " << dst[2] << " 0 255 0"<< endl;
65  }
66 
67  point_file.close();
68  }
69 }
70 
71 bool PointSave::saveBoundingRectangles(const char* filename, std::vector< std::vector<cv::Point3f> > b_rects, int size){
72  if(b_rects.size() > 0) {
73  ofstream point_file;
74  point_file.open(filename);
75 
76  point_file << "ply" << std::endl;
77  point_file << "format ascii 1.0" << std::endl;
78  point_file << "element vertex "<<to_string(size)<< std::endl;
79  point_file << "property float x\nproperty float y\nproperty float z" << std::endl;
80  point_file << "property uchar red\nproperty uchar green\nproperty uchar blue" << std::endl;
81  //optional
82  point_file << "element face " << to_string(size/4) << std::endl;
83  point_file << "property list uchar int vertex_index" << std::endl;
84 
85  point_file << "end_header" << std::endl;
86 
87  for(int i=0;i<b_rects.size();i++){
88  for(int j=0;j<b_rects[i].size();j++){
89 
90  point_file << b_rects[i][j].x << " " << b_rects[i][j].y << " " << b_rects[i][j].z << " " ;
91 
92  point_file << i*255/b_rects.size() << " " << i*255/b_rects.size() << " " << i*255/b_rects.size() << std::endl;
93  }
94  }
95 
96  for(int i=0;i<size;i+=4){
97  point_file << "4 " << i << " " << i+1 << " " << i+2 << " " << i+3 << std::endl;
98  }
99 
100  std::cout << "saved BoundingBoxes to " << filename << std::endl;
101 
102  point_file.close();
103  }else{
104  std::cout << "Couldn't save. Bounding Rects = 0" << std::endl;
105  }
106 }
PointSave::savePoints
bool savePoints(const char *filename, std::vector< std::vector< lvr::ColorVertex< float, unsigned char > > > rcb, int size)
Definition: PointSave.cpp:5
PointSave::saveBoundingRectangles
bool saveBoundingRectangles(const char *filename, std::vector< std::vector< cv::Point3f > > b_rects, int size)
Definition: PointSave.cpp:71
PointSave.hpp
kfusion::device::Vec3f
float3 Vec3f
Definition: internal.hpp:26
PointSave::savePointsWithCameras
bool savePointsWithCameras(const char *filename, std::vector< std::vector< lvr::ColorVertex< float, unsigned char > > > rcb, int size, std::vector< kfusion::ImgPose > image_pose_buffer)
Definition: PointSave.cpp:32
scripts.normalize_multiple.filename
filename
Definition: normalize_multiple.py:60


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