Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "pcl/point_types.h"
00037 #include "pcl/point_cloud.h"
00038 #include "rangetocoords.h"
00039 #include "../structures/PlanePatch.h"
00040 #include <string>
00041 #include <arpa/inet.h>
00042
00043 #ifndef RANGEIMAGEIO_H_
00044 #define RANGEIMAGEIO_H_
00045 #define RAS_MAGIC 0x59a66a95
00046
00047 typedef pcl::PointXYZRGB PointT;
00048 typedef pcl::PointCloud<PointT> PointCloud;
00049
00050 int getInt(FILE* file);
00051
00052 template<typename DataType>
00053 void readPGM(FILE* fp, DataType* buffer, unsigned int& col, unsigned int& row) {
00054 unsigned int i, j, k = 0;
00055 int z;
00056
00057 char filetype[3];
00058 int result = fscanf(fp, "%s", filetype);
00059 if ((result == EOF) || (result == 0))
00060 {
00061
00062 throw std::runtime_error("File not in PGM format.");
00063 }
00064 if (strcmp(filetype, "P5") && strcmp(filetype, "P2"))
00065 {
00066 col = 0;
00067 row = 0;
00068
00069 throw std::runtime_error("File not in PGM format.");
00070 }
00071
00072 col = getInt(fp);
00073 row = getInt(fp);
00074
00075
00076 while (255 != (i = getInt(fp)))
00077 ;
00078
00079 if (0 == strcmp(filetype, "P5")) {
00080
00081
00082
00083
00084 if (fread(buffer,sizeof(DataType),row * col,fp) != row * col){
00085
00086 exit(1);
00087 }
00088 } else {
00089
00090 for (i = 1; i <= row; i++)
00091 for (j = 1; j <= col; j++) {
00092 if (fscanf(fp, "%d", &z) != 1)
00093 {
00094
00095 throw std::runtime_error("Could not read value. File not in PGM format.");
00096 }
00097 buffer[k++] = (DataType)z;
00098 }
00099 }
00100 }
00101
00102 void writePGM(const std::string& filename, const unsigned int& width, const unsigned int& height, const std::vector<unsigned char>& data);
00103
00104
00105
00106 template<typename DataType>
00107 void readRasterfile(FILE* fp, DataType * buffer, unsigned int& cols, unsigned int& rows){
00108 unsigned int rasterHeader[8];
00109 if (fread(rasterHeader, sizeof(unsigned int), 8, fp) != 8){
00110
00111 exit(1);
00112 }
00113 if (rasterHeader[0] != RAS_MAGIC) {
00114 if (ntohl(rasterHeader[0]) != RAS_MAGIC){
00115
00116 exit(1);
00117 }
00118 for (unsigned int i=0; i < 8; ++i){
00119 rasterHeader[i] = ntohl(rasterHeader[i]);
00120 }
00121 }
00122 cols = rasterHeader[1];
00123 rows = rasterHeader[2];
00124 if (fread(buffer,sizeof(DataType),rows * cols,fp) != rows * cols){
00125
00126 exit(1);
00127 }
00128 }
00129
00130 void writeRasterfile(const std::string& filename, const unsigned int& width, const unsigned int& height, const std::vector<unsigned char>& data);
00131
00132 void writeMSNormals(const std::string& filename, const PlanePatch::PlanePatches& planes);
00133
00134 void writeTimeToFile(const std::string& filename, const double timeInSec);
00135
00136 void readPointCloudFromABWFile(PointCloud& pointCloud, const std::string& filename, unsigned int& width, unsigned int& height, std::vector<unsigned int>& undefPoints, bool pgm = false);
00137 void readPointCloudFromPERCEPTRONFile(PointCloud& pointCloud, const std::string& filename, unsigned int& width, unsigned int& height, std::vector<unsigned int>& undefPoints);
00138
00139 #endif