cgv
Loading...
Searching...
No Matches
cgv::media::mesh::obj_loader_generic< T > Class Template Reference

implements the virtual interface of the obj_reader and stores all read information. More...

#include <obj_loader.h>

Inheritance diagram for cgv::media::mesh::obj_loader_generic< T >:
cgv::media::mesh::obj_reader_generic< T > cgv::media::mesh::obj_reader_base

Public Types

typedef obj_reader_generic< T >::vec3_type vec3_type
typedef obj_reader_generic< T >::vec2_type vec2_type
typedef obj_reader_base::color_type color_type
Public Types inherited from cgv::media::mesh::obj_reader_generic< T >
typedef T coord_type
 type of coordinates
typedef cgv::math::fvec< T, 2 > vec2_type
 type used to store texture coordinates
typedef cgv::math::fvec< T, 3 > vec3_type
 type used to store positions and normal vectors
Public Types inherited from cgv::media::mesh::obj_reader_base
typedef illum::obj_material::color_type color_type
 type used for rgba colors

Public Attributes

std::vector< vec3_type > vertices
std::vector< vec3_type > normals
std::vector< vec2_type > texcoords
std::vector< color_type > colors
std::vector< unsigned > vertex_indices
std::vector< unsigned > normal_indices
std::vector< unsigned > texcoord_indices
std::vector< line_info > lines
std::vector< face_info > faces
std::vector< group_info > groups
std::vector< cgv::media::illum::obj_material > materials

virtual interface

void process_vertex (const vec3_type &p)
 overide this function to process a vertex
void process_texcoord (const vec2_type &t)
 overide this function to process a texcoord
void process_normal (const vec3_type &n)
 overide this function to process a normal
void process_color (const color_type &c)
 overide this function to process a color (this called for vc prefixes which is is not in the standard but for example used in pobj-files)
void process_line (unsigned vcount, int *vertices, int *texcoords=0, int *normals=0)
 overide this function to process a line
void process_face (unsigned vcount, int *vertices, int *texcoords=0, int *normals=0)
 overide this function to process a face
void process_group (const std::string &name, const std::string &parameters)
 overide this function to process a group given by name
void process_material (const cgv::media::illum::obj_material &mtl, unsigned idx)
 process a material definition
bool read_obj (const std::string &file_name)
 overloads reading to support binary file format
bool read_obj_bin (const std::string &file_name)
 read a binary version of an obj file
bool write_obj_bin (const std::string &file_name) const
 write the information from the last read obj file in binary format
void show_stats () const
 use this after reading to show status information about the number of read entities
void clear ()
 prepare for reading another file

Additional Inherited Members

 obj_reader_generic ()
 default constructor
virtual bool parse_obj (const std::string &content, const std::string path_name="")
 parse the content of an obj file already read to memory, where path_name is used to find material files
virtual bool read_mtl (const std::string &file_name)
 read a material file
Static Public Member Functions inherited from cgv::media::mesh::obj_reader_generic< T >
static bool is_double (const char *begin, const char *end, coord_type &value)
Protected Member Functions inherited from cgv::media::mesh::obj_reader_generic< T >
vec2_type parse_vec2 (const std::vector< cgv::utils::token > &t) const
 parse 2d vector
vec3_type parse_vec3 (const std::vector< cgv::utils::token > &t) const
 parse 3d vector
void parse_and_process_vertex (const std::vector< cgv::utils::token > &tokens)
void parse_and_process_normal (const std::vector< cgv::utils::token > &tokens)
void parse_and_process_texcoord (const std::vector< cgv::utils::token > &tokens)
color_type parse_color (const std::vector< cgv::utils::token > &t, unsigned off=0) const
 parse a color, if alpha not given it defaults to 1
void parse_face (const std::vector< cgv::utils::token > &tokens, bool is_line=false)
void parse_material (const std::vector< cgv::utils::token > &tokens)
unsigned get_current_group () const
 return the index of the currently selected group or -1 if no group is defined
unsigned get_current_material () const
 return the index of the currently selected material or -1 if no material is defined
virtual void process_comment (const std::string &comment)
 overide this function to process a comment
void convert_to_positive (unsigned vcount, int *vertices, int *texcoords, int *normals, unsigned v, unsigned n, unsigned t)
 convert negative indices to positive ones by adding the number of elements
Protected Attributes inherited from cgv::media::mesh::obj_reader_base
unsigned group_index
 keep track of the current group
unsigned nr_groups
 number of groups
unsigned material_index
 keep track of current material index
unsigned nr_materials
 number of materials
std::map< std::string, unsigned > material_index_lut
 mapping from material names to material indices
int minus
unsigned nr_normals
unsigned nr_texcoords
bool have_default_material
std::set< std::string > mtl_lib_files
std::string path_name
 store the path name

Detailed Description

template<typename T>
class cgv::media::mesh::obj_loader_generic< T >

implements the virtual interface of the obj_reader and stores all read information.

The read information is automatically stored in binary form to accelerate the second loading of the same obj file.

Definition at line 64 of file obj_loader.h.

Member Typedef Documentation

◆ color_type

template<typename T>
typedef obj_reader_base::color_type cgv::media::mesh::obj_loader_generic< T >::color_type

Definition at line 70 of file obj_loader.h.

◆ vec2_type

template<typename T>
typedef obj_reader_generic<T>::vec2_type cgv::media::mesh::obj_loader_generic< T >::vec2_type

Definition at line 69 of file obj_loader.h.

◆ vec3_type

template<typename T>
typedef obj_reader_generic<T>::vec3_type cgv::media::mesh::obj_loader_generic< T >::vec3_type

Definition at line 68 of file obj_loader.h.

Member Function Documentation

◆ clear()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::clear ( )
virtual

prepare for reading another file

Reimplemented from cgv::media::mesh::obj_reader_base.

Definition at line 299 of file obj_loader.cxx.

References cgv::media::mesh::obj_reader_base::clear().

◆ process_color()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::process_color ( const color_type & c)
protectedvirtual

overide this function to process a color (this called for vc prefixes which is is not in the standard but for example used in pobj-files)

Reimplemented from cgv::media::mesh::obj_reader_base.

Definition at line 57 of file obj_loader.cxx.

◆ process_face()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::process_face ( unsigned vcount,
int * vertices,
int * texcoords = 0,
int * normals = 0 )
protectedvirtual

overide this function to process a face

Reimplemented from cgv::media::mesh::obj_reader_base.

Definition at line 86 of file obj_loader.cxx.

References cgv::media::mesh::obj_reader_base::convert_to_positive().

◆ process_group()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::process_group ( const std::string & name,
const std::string & parameters )
protectedvirtual

overide this function to process a group given by name

Reimplemented from cgv::media::mesh::obj_reader_base.

Definition at line 109 of file obj_loader.cxx.

References cgv::media::mesh::group_info::name, and cgv::media::mesh::group_info::parameters.

◆ process_line()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::process_line ( unsigned vcount,
int * vertices,
int * texcoords = 0,
int * normals = 0 )
protectedvirtual

overide this function to process a line

Reimplemented from cgv::media::mesh::obj_reader_base.

Definition at line 64 of file obj_loader.cxx.

References cgv::media::mesh::obj_reader_base::convert_to_positive().

◆ process_material()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::process_material ( const cgv::media::illum::obj_material & mtl,
unsigned idx )
protectedvirtual

process a material definition

Reimplemented from cgv::media::mesh::obj_reader_base.

Definition at line 119 of file obj_loader.cxx.

◆ process_normal()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::process_normal ( const vec3_type & n)
protectedvirtual

overide this function to process a normal

Reimplemented from cgv::media::mesh::obj_reader_generic< T >.

Definition at line 51 of file obj_loader.cxx.

◆ process_texcoord()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::process_texcoord ( const vec2_type & t)
protectedvirtual

overide this function to process a texcoord

Reimplemented from cgv::media::mesh::obj_reader_generic< T >.

Definition at line 45 of file obj_loader.cxx.

◆ process_vertex()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::process_vertex ( const vec3_type & p)
protectedvirtual

overide this function to process a vertex

Reimplemented from cgv::media::mesh::obj_reader_generic< T >.

Definition at line 38 of file obj_loader.cxx.

◆ read_obj()

template<typename T>
bool cgv::media::mesh::obj_loader_generic< T >::read_obj ( const std::string & file_name)
virtual

overloads reading to support binary file format

Reimplemented from cgv::media::mesh::obj_reader_base.

Definition at line 141 of file obj_loader.cxx.

References cgv::media::mesh::obj_reader_base::path_name, cgv::media::mesh::obj_reader_base::read_obj(), read_obj_bin(), and write_obj_bin().

◆ read_obj_bin()

template<typename T>
bool cgv::media::mesh::obj_loader_generic< T >::read_obj_bin ( const std::string & file_name)

read a binary version of an obj file

Definition at line 182 of file obj_loader.cxx.

References cgv::media::mesh::obj_reader_base::read_mtl().

Referenced by read_obj().

◆ show_stats()

template<typename T>
void cgv::media::mesh::obj_loader_generic< T >::show_stats ( ) const

use this after reading to show status information about the number of read entities

Definition at line 428 of file obj_loader.cxx.

◆ write_obj_bin()

template<typename T>
bool cgv::media::mesh::obj_loader_generic< T >::write_obj_bin ( const std::string & file_name) const

write the information from the last read obj file in binary format

Definition at line 317 of file obj_loader.cxx.

Referenced by read_obj().

Member Data Documentation

◆ colors

template<typename T>
std::vector<color_type> cgv::media::mesh::obj_loader_generic< T >::colors

Definition at line 75 of file obj_loader.h.

◆ faces

template<typename T>
std::vector<face_info> cgv::media::mesh::obj_loader_generic< T >::faces

Definition at line 82 of file obj_loader.h.

◆ groups

template<typename T>
std::vector<group_info> cgv::media::mesh::obj_loader_generic< T >::groups

Definition at line 83 of file obj_loader.h.

◆ lines

template<typename T>
std::vector<line_info> cgv::media::mesh::obj_loader_generic< T >::lines

Definition at line 81 of file obj_loader.h.

◆ materials

template<typename T>
std::vector<cgv::media::illum::obj_material> cgv::media::mesh::obj_loader_generic< T >::materials

Definition at line 84 of file obj_loader.h.

◆ normal_indices

template<typename T>
std::vector<unsigned> cgv::media::mesh::obj_loader_generic< T >::normal_indices

Definition at line 78 of file obj_loader.h.

◆ normals

template<typename T>
std::vector<vec3_type> cgv::media::mesh::obj_loader_generic< T >::normals

Definition at line 73 of file obj_loader.h.

◆ texcoord_indices

template<typename T>
std::vector<unsigned> cgv::media::mesh::obj_loader_generic< T >::texcoord_indices

Definition at line 79 of file obj_loader.h.

◆ texcoords

template<typename T>
std::vector<vec2_type> cgv::media::mesh::obj_loader_generic< T >::texcoords

Definition at line 74 of file obj_loader.h.

◆ vertex_indices

template<typename T>
std::vector<unsigned> cgv::media::mesh::obj_loader_generic< T >::vertex_indices

Definition at line 77 of file obj_loader.h.

◆ vertices

template<typename T>
std::vector<vec3_type> cgv::media::mesh::obj_loader_generic< T >::vertices

Definition at line 72 of file obj_loader.h.


The documentation for this class was generated from the following files: