Kiretu
|
00001 /* This file is part of the Kiretu, a Kinect reconstruction tutor. 00002 * 00003 * http://pille.iwr.uni-heidelberg.de/~kinect01/ 00004 * 00005 * The code ist licensed to you under the terms of the GNU General Public 00006 * License, version 2.0. See the GPL2 file for the text of the license or the 00007 * following URL: 00008 * 00009 * http://www.gnu.org/licenses/gpl-2.0.txt 00010 * 00011 * If you redistribute this file in source form, modified or unmodified, you 00012 * have to leave this header intact and distribute it under the same terms with 00013 * the GPL2 file. 00014 * 00015 * Binary distributions must follow the binary distribution requirements of 00016 * the License. 00017 * 00018 */ 00019 00020 /** \file CloudWriter.h 00021 * 00022 * Header file of the CloudWriter-class. 00023 * 00024 * \author Daniel Wunderlich (d.wunderlich@stud.uni-heidelberg.de) 00025 * \version 0.8 00026 * \date 2011-01-26 00027 */ 00028 00029 #include <vector> 00030 #include <string> 00031 #include <cstring> 00032 #include <fstream> 00033 #include <iostream> 00034 #include <ctime> 00035 00036 00037 /** \class CloudWriter 00038 * \brief C++-class which saves a point-cloud of Microsoft's Kinect to a 00039 * ply-file. It supports per-vertex-color and the ability of mirroring 00040 * the cloud along x-, y- and z-axis. It is also possible to export 00041 * the points which don't have an corresponding color at the RGB-image 00042 * in a custom color. 00043 * 00044 * \author Daniel Wunderlich (d.wunderlich@stud.uni-heidelberg.de) 00045 * \version 0.8 00046 * \date 2011-01-26 00047 */ 00048 class CloudWriter { 00049 00050 public: 00051 00052 /** \brief Constructor of the CloudWriter-class. 00053 * 00054 * \param filenamePrefix Prefix of filename. 00055 */ 00056 CloudWriter(const std::string filenamePrefix); 00057 00058 /** \brief Destructor of the CloudWriter-class. 00059 */ 00060 ~CloudWriter(); 00061 00062 00063 /** \brief Mirror-possibilities of CloudWriter. 00064 */ 00065 enum CloudMirror 00066 { 00067 MIRROR_X, /**< Mirror along x-axis */ 00068 MIRROR_Y, /**< Mirror along y-axis */ 00069 MIRROR_Z /**< Mirror along z-axis */ 00070 }; 00071 00072 00073 /** \brief Adds a point-cloud to the CloudWriter. This cloud should be computed 00074 * by KinectCloud before. 00075 * 00076 * \param cloud Vector of \f$640 \times 480\f$ 3-dimensional points. 00077 * 00078 */ 00079 void addCloud(std::vector< std::vector<float> > cloud); 00080 00081 00082 /** \brief Adds a vector of RGB-colors to the CloudWriter.This vector should 00083 * be computed by KinectCloud before. 00084 * 00085 * \param cloudRgb Vector of \f$640 \times 480\f$ colors. Each color is 00086 * specified in \f$R\f$-, \f$G\f$- and \f$B\f$-values with 00087 * \f$R, G, B \in [1, 255]\f$. 00088 */ 00089 void addCloudRgb(std::vector< std::vector<int> > cloudRgb); 00090 00091 00092 /** \brief Adds a vector of depth-RGB-mapping values to the CloudWriter. These 00093 * values should be computed by 00094 * KinectCloud::computeRgbMapping(std::vector< std::vector<float> > rgbCam) 00095 * before. 00096 * 00097 * \param cloudRgbMapping Vector of \f$640 \times 480\f$ 2-dimensional 00098 * mapping-values. 00099 */ 00100 void addCloudRgbMapping(std::vector< std::vector<int> > cloudRgbMapping); 00101 00102 //~ void addNormals(std::vector< std::vector<float> > normals); 00103 00104 00105 /** \brief Adds a vector of valid-points-flags to the CloudWriter. Get 00106 * these points with KinectCloud::getValidValues(). 00107 * 00108 * \param validValues Vector of \f$640 \times 480\f$ booleans which indicate, 00109 * if the corresponding vector is valid 00110 * (\f$depth < 2047\f$). 00111 */ 00112 void addValidValues(std::vector<bool> validValues); 00113 00114 00115 /** \brief Adds a vector of reconstruction-steps-flags to the CloudWriter. 00116 * Get these points with KinectCloud::getReconstructionSteps(). 00117 * 00118 * \param reconstructionSteps Vector of 5 booleans which indicate, if the 00119 * equivalent reconstruction-step was done. 00120 * 00121 * \see KinectCloud::getReconstructionSteps() 00122 */ 00123 void addReconstructionSteps(std::vector<bool> reconstructionSteps); 00124 00125 00126 /** \brief Sets if points of the point-cloud, which don't have an equivalent 00127 * color at the RGB-image should be added to the final point-cloud. 00128 * They will be added with a custom color, specified with 00129 * setUndefinedColor(int color[3]). 00130 * 00131 * \param printUndefined True, if points with undefined color should 00132 * be added to the exported file. False, if not. 00133 */ 00134 void setUndefined(bool printUndefined); 00135 00136 00137 /** \brief Sets the color of points with undefined color. 00138 * 00139 * \param color RGB-color with \f$R, G, B \in [1, 255]\f$. 00140 */ 00141 void setUndefinedColor(int color[3]); 00142 00143 00144 /** \brief Mirrors the point-cloud along the given axis. Multiple calls 00145 * possible. 00146 * 00147 * \param mirror The mirror-axis. 00148 */ 00149 void setMirror(CloudMirror mirror); 00150 00151 00152 /** \brief Writes the cloud to the ply-file. 00153 */ 00154 void writeCloud(); 00155 00156 private: 00157 std::string filenamePrefix; /**< Filename prefix */ 00158 std::string filename; /**< Resulting filename (Filename prefix + datetime + reconstruction-steps) */ 00159 std::vector< std::vector<float> > cloud; /**< Point-cloud */ 00160 std::vector< std::vector<int> > cloudRgb; /**< RGB-values */ 00161 std::vector< std::vector<int> > cloudRgbMapping; /**< Coordinates of a point's corresponding color at the RGB-image */ 00162 //~ std::vector< std::vector<float> > normals; 00163 std::vector<bool> validValues; /**< Valid flags for each point */ 00164 std::vector<bool> reconstructionSteps; /**< Reconstruction flags */ 00165 std::vector< std::vector<float> > cloudOutput; /**< Final ply-output */ 00166 00167 bool printUndefined; /**< Flag for printing points without a corresponding color */ 00168 bool reconstructionStepsAdded; /**< Indicates, if the reconstruction-steps were added */ 00169 int undefinedColor[3]; /**< Color for points with undefined colors at the RGB-image */ 00170 int mirrorX; /**< Help-variable for mirroring along x-axis */ 00171 int mirrorY; /**< Help-variable for mirroring along y-axis */ 00172 int mirrorZ; /**< Help-variable for mirroring along z-axis */ 00173 00174 void createOutput(); /**< Generates the ply-output */ 00175 void createFilename(); /**< Generates the filename */ 00176 };