Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __PLY_IO_H__
00011 #define __PLY_IO_H__
00012
00013 #include "PLYProperty.hpp"
00014 #include "PLYElement.hpp"
00015
00016 #include <iostream>
00017 #include <fstream>
00018 #include <vector>
00019
00020 #include <cassert>
00021
00022 using std::ofstream;
00023 using std::ifstream;
00024 using std::vector;
00025 using std::cout;
00026 using std::endl;
00027
00028 #define BUFFER_SIZE 1024
00029 #define OUT_BUFFER_SIZE 20000
00030
00031 namespace lssr
00032 {
00033
00037 class PLYIO {
00038
00039 public:
00040
00044 PLYIO();
00045
00051 void addElement(PLYElement* e);
00052
00062 void setVertexArray(float* array, size_t n);
00063
00073 void setNormalArray(float* array, size_t n);
00074
00081 void setColorArray(float* array, size_t n);
00082
00092 void setIndexArray(unsigned int* array, size_t n);
00093
00101 void save(string filename, bool binary = true);
00102
00107 void read(string filename);
00108
00112 virtual ~PLYIO();
00113
00120 float* getVertexArray(size_t &n);
00121
00128 float* getNormalArray(size_t &n);
00129
00136 float* getColorArray(size_t &);
00137
00149 float** getIndexedVertexArray(size_t &n);
00150
00151
00163 float** getIndexedNormalArray(size_t &n);
00164
00173 void setIndexedVertexArray(float** arr, size_t size);
00174
00183 void setIndexedNormalArray(float** arr, size_t size);
00184
00190 unsigned int* getIndexArray(size_t &n);
00191
00197 bool containsElement(PLYElement& e);
00198
00203 bool containsElement(string elementName);
00204
00208 bool hasProperty(PLYElement& e, Property& p);
00209
00213 void printElementsInHeader();
00214
00215 private:
00216
00217 float** interlacedBufferToIndexedBuffer(float* src, size_t n);
00218 float* indexedBufferToInterlacedBuffer(float** src, size_t n);
00219
00220 void writeHeader(ofstream& str);
00221 void writeElements(ofstream &str);
00222 void writeFacesBinary(ofstream &str, PLYElement* e);
00223 void writeFacesASCII(ofstream &str, PLYElement* e);
00224 void writeVerticesBinary(ofstream &str, PLYElement* e);
00225 void writeVerticesASCII(ofstream &str, PLYElement* e);
00226 void writeNormalsBinary(ofstream &out, PLYElement* e);
00227 void writeNormalsASCII(ofstream &out, PLYElement* e);
00228
00229 void readVerticesBinary(ifstream &in, PLYElement* descr);
00230 void readFacesBinary(ifstream &in, PLYElement* descr);
00231 void readNormalsBinary(ifstream &in, PLYElement* descr);
00232
00233 void readVerticesASCII(ifstream &in, PLYElement* descr);
00234 void readFacesASCII(ifstream &in, PLYElement* descr);
00235 void readNormalsASCII(ifstream &in, PLYElement* descr);
00236
00237 void readHeader(ifstream& str);
00238
00239 char* putElementInBuffer(char* buffer, string s, float value);
00240
00241 bool isSupported(string element_name);
00242 bool parseHeaderLine(const char* line);
00243
00244 void loadElements(ifstream& in);
00245
00246 void deleteBuffers();
00247 void allocVertexBuffers(PLYElement* dscr);
00248
00249 void copyElementToVertexBuffer(ifstream &str, Property*, float* buffer, size_t position);
00250
00251 template<typename T>
00252 void copyElementToVertexBuffer(char* src, float* buffer, size_t positon);
00253
00254 float* m_vertices;
00255 float* m_normals;
00256 float* m_colors;
00257 unsigned int* m_indices;
00258
00259 size_t m_numberOfNormals;
00260 size_t m_numberOfVertices;
00261 size_t m_numberOfFaces;
00262
00263 bool m_binary;
00264
00265 vector<PLYElement*> m_elements;
00266
00267 };
00268
00269
00270
00271 }
00272
00273 #endif