cgv
obj_loader.h
1 #pragma once
2 
3 #include "obj_reader.h"
4 #include <map>
5 #include <set>
6 #include <cgv/math/fvec.h>
7 
8 #include <cgv/media/lib_begin.h>
9 
10 namespace cgv {
11  namespace media {
12  namespace mesh {
13 
15 struct CGV_API face_info
16 {
18  unsigned degree;
30  face_info(unsigned _nr = 0, unsigned _vi0 = 0, int _ti0 = -1, int _ni0 = -1, unsigned gi=-1, unsigned mi=-1);
31 };
32 
34 struct group_info
35 {
37  std::string name;
39  std::string parameters;
40 };
41 
45 template <typename T>
46 class CGV_API obj_loader_generic : public obj_reader_generic<T>
47 {
48 public:
49  // We need to repeat the typenames here, because gcc will not inherit them in templates
52  typedef obj_reader_base::color_type color_type;
53 
54  std::vector<v3d_type> vertices;
55  std::vector<v3d_type> normals;
56  std::vector<v2d_type> texcoords;
57  std::vector<color_type> colors;
58 
59  std::vector<unsigned> vertex_indices;
60  std::vector<unsigned> normal_indices;
61  std::vector<unsigned> texcoord_indices;
62 
63  std::vector<face_info> faces;
64  std::vector<group_info> groups;
65  std::vector<cgv::media::illum::obj_material> materials;
66 protected:
69  void process_vertex(const v3d_type& p);
72  void process_texcoord(const v2d_type& t);
74  void process_normal(const v3d_type& n);
76  void process_color(const color_type& c);
78  void process_face(unsigned vcount, int *vertices,
79  int *texcoords = 0, int *normals=0);
81  void process_group(const std::string& name, const std::string& parameters);
83  void process_material(const cgv::media::illum::obj_material& mtl, unsigned idx);
85 public:
87  bool read_obj(const std::string& file_name);
89  bool read_obj_bin(const std::string& file_name);
91  bool write_obj_bin(const std::string& file_name) const;
93  void show_stats() const;
95  void clear();
96 };
97 
98 
102 
103  }
104  }
105 }
106 
107 #include <cgv/config/lib_end.h>
cgv::media::mesh::face_info::degree
unsigned degree
degree of face
Definition: obj_loader.h:18
cgv::media::mesh::obj_reader_generic
Definition: obj_reader.h:93
cgv::media::mesh::obj_loader_generic
Definition: obj_loader.h:47
cgv::media::mesh::group_info
Definition: obj_loader.h:35
cgv::media::mesh::face_info::group_index
int group_index
index of group to which the face belongs
Definition: obj_loader.h:26
cgv::media::mesh::face_info::first_texcoord_index
int first_texcoord_index
index into texcoord index array or -1 if not specified
Definition: obj_loader.h:22
cgv::math::fvec
Definition: fvec.h:18
cgv::media::mesh::face_info::first_vertex_index
unsigned first_vertex_index
index into vertex index array
Definition: obj_loader.h:20
cgv::media::mesh::group_info::parameters
std::string parameters
parameters string
Definition: obj_loader.h:39
cgv::media::illum::obj_material
>extension of a phong material with support for texture mapped color channels
Definition: obj_material.hh:12
cgv::media::mesh::face_info
Definition: obj_loader.h:16
cgv::media::mesh::face_info::material_index
int material_index
material index to which the face belongs
Definition: obj_loader.h:28
cgv::media::mesh::obj_reader_base::color_type
illum::obj_material::color_type color_type
type used for rgba colors
Definition: obj_reader.h:22
cgv::media::mesh::group_info::name
std::string name
name of the group
Definition: obj_loader.h:37
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::media::mesh::face_info::first_normal_index
int first_normal_index
index into normal index array or -1 if not specified
Definition: obj_loader.h:24