PICCANTE  0.4
The hottest HDR imaging library!
simple_ply.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_COMPUTER_VISION_SIMPLE_PLY_HPP
19 #define PIC_COMPUTER_VISION_SIMPLE_PLY_HPP
20 
21 #include <vector>
22 #include <random>
23 #include <stdlib.h>
24 
25 #include "../base.hpp"
26 
27 #include "../util/math.hpp"
28 
29 #include "../util/eigen_util.hpp"
30 
31 #ifndef PIC_DISABLE_EIGEN
32 
33 #ifndef PIC_EIGEN_NOT_BUNDLED
34  #include "../externals/Eigen/Dense"
35  #include "../externals/Eigen/SVD"
36  #include "../externals/Eigen/Geometry"
37 #else
38  #include <Eigen/Dense>
39  #include <Eigen/SVD>
40  #include <Eigen/Geometry>
41 #endif
42 
43 #endif
44 
45 namespace pic {
46 
47 #ifndef PIC_DISABLE_EIGEN
48 
49 PIC_INLINE bool writeSimplePLY(std::string name,
50  std::vector< Eigen::Vector3d > &points_3d,
51  std::vector< unsigned char > &colors)
52 {
53  //write a PLY file
54  FILE *file = fopen(name.c_str(), "w");
55 
56  if (file == NULL) {
57  return false;
58  }
59 
60  bool bColor = colors.size() == (points_3d.size() * 3);
61 
62  fprintf(file,"ply\n");
63  fprintf(file,"format ascii 1.0\n");
64  fprintf(file,"element vertex %d\n", int(points_3d.size()));
65 
66  fprintf(file,"property float x\n");
67  fprintf(file,"property float y\n");
68  fprintf(file,"property float z\n");
69 
70  if(bColor) {
71  fprintf(file,"property uchar red\n");
72  fprintf(file,"property uchar green\n");
73  fprintf(file,"property uchar blue\n");
74  fprintf(file,"property uchar alpha\n");
75  }
76  fprintf(file,"end_header\n");
77 
78  for(unsigned int i = 0; i < points_3d.size(); i++) {
79  //write position information
80  fprintf(file, "%3.4f %3.4f %3.4f ", points_3d[i][0], points_3d[i][1], points_3d[i][2]);
81 
82  //write color information
83  if(bColor) {
84  auto k = i * 3;
85  fprintf(file, " %d %d %d 255\n", colors[k], colors[k + 1], colors[k + 2]);
86  }
87  }
88 
89  fclose(file);
90  return true;
91 }
92 
93 #endif // PIC_DISABLE_EIGEN
94 
95 } // end namespace pic
96 
97 #endif // PIC_COMPUTER_VISION_SIMPLE_PLY_HPP
#define PIC_INLINE
Definition: base.hpp:33
Definition: bilateral_separation.hpp:25
PIC_INLINE bool writeSimplePLY(std::string name, std::vector< Eigen::Vector3d > &points_3d, std::vector< unsigned char > &colors)
Definition: simple_ply.hpp:49