Vis 2 Demo  1.0
Technical illustration type real-time rendering of geometry
 All Classes Namespaces Files Functions Variables Typedefs Macros
LoaderOBJ.h
Go to the documentation of this file.
1 #ifndef __LOADER_OBJ_H__
2 #define __LOADER_OBJ_H__
3 
4 #include <cstdio>
5 #include <vector>
6 #include <iostream>
7 #include <fstream>
8 #include <string>
9 #include <glew.h>
10 #include <glm/glm.hpp>
11 
12 #define VIS2_FILE_TYPE_OBJ 0
13 #define VIS2_FILE_TYPE_DAT 1
14 
15 namespace vis2
16 {
17  typedef std::vector<GLfloat> vertAttribContainer;
18  typedef std::vector<GLuint> indexContainer;
19  typedef std::vector<indexContainer> multIndexContainer;
20 
22 
26  class LoaderOBJ
27  {
28  public:
30 
31  LoaderOBJ(const std::string &);
33  ~LoaderOBJ();
34 
36  int obj2Container();
37 
38  GLfloat* vert_positions;
39  GLfloat* vert_normals;
40  GLfloat* vert_uvs;
41  GLuint* face_ind;
42 
44  inline const unsigned int getNrFaceInd() const {return nr_face_ind;}
46  inline const unsigned int getNrVertices() const {return single_ind;}
47 
48  private:
50  LoaderOBJ(const LoaderOBJ&);
51 
53 
57  int readDataFromOBJ();
58 
60 
64  int readDataFromDAT();
65 
67 
71  int writeDataToDAT();
72 
74  void checkForErrors(std::ios & _ofs);
75 
77 
80  void parseOBJ(std::FILE* _f);
81 
83 
86  vertAttribContainer string2VertAttr(std::string & _line);
87 
89 
93  indexContainer string2Index(std::string & _line);
94 
96 
101  bool iCareEqual(const indexContainer & _ic1, const indexContainer & _ic2);
102 
104  void mult2singleIndex();
105 
106 
107  std::string file_path;
108  unsigned int file_type;
109 
111 
112  // data parsed form the file
117 
118  unsigned int nr_face_ind;
119  unsigned int single_ind;
120  };
121 }
122 
123 
124 
125 #endif