cgv
Loading...
Searching...
No Matches
cgv::media::mesh::obj_reader_base Class Referenceabstract

base class for obj reader with implementation that is independent of coordinate type. More...

#include <obj_reader.h>

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

Public Types

typedef illum::obj_material::color_type color_type
 type used for rgba colors
 

Protected Attributes

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
 

helpers for reading

int minus
 
unsigned nr_normals
 
unsigned nr_texcoords
 
bool have_default_material
 
std::set< std::string > mtl_lib_files
 
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)
 
virtual void parse_and_process_vertex (const std::vector< cgv::utils::token > &tokens)=0
 
virtual void parse_and_process_normal (const std::vector< cgv::utils::token > &tokens)=0
 
virtual void parse_and_process_texcoord (const std::vector< cgv::utils::token > &tokens)=0
 

status info during reading

std::string path_name
 store the path name
 
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 interface

virtual void process_comment (const std::string &comment)
 overide this function to process a comment
 
virtual 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 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
 
virtual void process_line (unsigned vcount, int *vertices, int *texcoords=0, int *normals=0)
 overide this function to process a line strip, the indices start with 0
 
virtual void process_face (unsigned vcount, int *vertices, int *texcoords=0, int *normals=0)
 overide this function to process a face, the indices start with 0
 
virtual void process_group (const std::string &name, const std::string &parameters)
 overide this function to process a group given by name and parameter string
 
virtual void process_material (const cgv::media::illum::obj_material &mtl, unsigned idx)
 process a material definition. If a material with a certain name is overwritten, it will receive the same index
 
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_obj (const std::string &file_name)
 read an obj file
 
virtual bool read_mtl (const std::string &file_name)
 read a material file
 
virtual void clear ()
 clear the reader such that a new file can be read
 

Detailed Description

base class for obj reader with implementation that is independent of coordinate type.

Definition at line 18 of file obj_reader.h.

Member Typedef Documentation

◆ color_type

type used for rgba colors

Definition at line 22 of file obj_reader.h.

Constructor & Destructor Documentation

◆ obj_reader_base()

cgv::media::mesh::obj_reader_base::obj_reader_base ( )

Definition at line 87 of file obj_reader.cxx.

Member Function Documentation

◆ clear()

void cgv::media::mesh::obj_reader_base::clear ( )
virtual

clear the reader such that a new file can be read

Reimplemented in cgv::media::mesh::obj_loader_generic< T >.

Definition at line 92 of file obj_reader.cxx.

References material_index, material_index_lut, nr_groups, and nr_materials.

Referenced by cgv::media::mesh::obj_loader_generic< T >::clear().

◆ convert_to_positive()

void cgv::media::mesh::obj_reader_base::convert_to_positive ( unsigned  vcount,
int *  vertices,
int *  texcoords,
int *  normals,
unsigned  v,
unsigned  n,
unsigned  t 
)
protected

convert negative indices to positive ones by adding the number of elements

Definition at line 138 of file obj_reader.cxx.

Referenced by cgv::media::mesh::simple_mesh_obj_reader< T >::process_face().

◆ get_current_group()

unsigned cgv::media::mesh::obj_reader_base::get_current_group ( ) const
protected

return the index of the currently selected group or -1 if no group is defined

Definition at line 76 of file obj_reader.cxx.

References group_index.

Referenced by cgv::media::mesh::simple_mesh_obj_reader< T >::process_face().

◆ get_current_material()

unsigned cgv::media::mesh::obj_reader_base::get_current_material ( ) const
protected

return the index of the currently selected material or -1 if no material is defined

Definition at line 82 of file obj_reader.cxx.

References material_index.

Referenced by cgv::media::mesh::simple_mesh_obj_reader< T >::process_face().

◆ parse_color()

obj_reader_base::color_type cgv::media::mesh::obj_reader_base::parse_color ( const std::vector< cgv::utils::token > &  t,
unsigned  off = 0 
) const
protected

parse a color, if alpha not given it defaults to 1

Definition at line 63 of file obj_reader.cxx.

Referenced by parse_obj(), and read_mtl().

◆ parse_face()

void cgv::media::mesh::obj_reader_base::parse_face ( const std::vector< cgv::utils::token > &  tokens,
bool  is_line = false 
)
protected

Definition at line 419 of file obj_reader.cxx.

◆ parse_material()

void cgv::media::mesh::obj_reader_base::parse_material ( const std::vector< cgv::utils::token > &  tokens)
protected

Definition at line 407 of file obj_reader.cxx.

◆ parse_obj()

bool cgv::media::mesh::obj_reader_base::parse_obj ( const std::string &  content,
const std::string  path_name = "" 
)
virtual

◆ process_color()

void cgv::media::mesh::obj_reader_base::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)

overide this function to process a normal

Reimplemented in cgv::media::mesh::obj_loader_generic< T >, and cgv::media::mesh::simple_mesh_obj_reader< T >.

Definition at line 133 of file obj_reader.cxx.

Referenced by parse_obj().

◆ process_comment()

void cgv::media::mesh::obj_reader_base::process_comment ( const std::string &  comment)
protectedvirtual

overide this function to process a comment

Definition at line 110 of file obj_reader.cxx.

◆ process_face()

void cgv::media::mesh::obj_reader_base::process_face ( unsigned  vcount,
int *  vertices,
int *  texcoords = 0,
int *  normals = 0 
)
protectedvirtual

overide this function to process a face, the indices start with 0

overide this function to process a face

Reimplemented in cgv::media::mesh::simple_mesh_obj_reader< T >, and cgv::media::mesh::obj_loader_generic< T >.

Definition at line 162 of file obj_reader.cxx.

◆ process_group()

void cgv::media::mesh::obj_reader_base::process_group ( const std::string &  name,
const std::string &  parameters 
)
protectedvirtual

overide this function to process a group given by name and parameter string

Reimplemented in cgv::media::mesh::obj_loader_generic< T >, and cgv::media::mesh::simple_mesh_obj_reader< T >.

Definition at line 167 of file obj_reader.cxx.

Referenced by parse_obj().

◆ process_line()

void cgv::media::mesh::obj_reader_base::process_line ( unsigned  vcount,
int *  vertices,
int *  texcoords = 0,
int *  normals = 0 
)
protectedvirtual

overide this function to process a line strip, the indices start with 0

overide this function to process a line given by two indices that start with 0

Reimplemented in cgv::media::mesh::obj_loader_generic< T >.

Definition at line 157 of file obj_reader.cxx.

◆ process_material()

void cgv::media::mesh::obj_reader_base::process_material ( const cgv::media::illum::obj_material mtl,
unsigned  idx 
)
protectedvirtual

process a material definition. If a material with a certain name is overwritten, it will receive the same index

process a material definition

Reimplemented in cgv::media::mesh::obj_loader_generic< T >, and cgv::media::mesh::simple_mesh_obj_reader< T >.

Definition at line 172 of file obj_reader.cxx.

Referenced by parse_obj(), and read_mtl().

◆ read_mtl()

◆ read_obj()

bool cgv::media::mesh::obj_reader_base::read_obj ( const std::string &  file_name)
virtual

read an obj file

Reimplemented in cgv::media::mesh::obj_loader_generic< T >.

Definition at line 195 of file obj_reader.cxx.

References parse_obj(), path_name, and cgv::base::read_data_file().

Referenced by cgv::media::mesh::simple_mesh< T >::read().

Member Data Documentation

◆ group_index

unsigned cgv::media::mesh::obj_reader_base::group_index
protected

keep track of the current group

Definition at line 25 of file obj_reader.h.

Referenced by get_current_group(), and parse_obj().

◆ have_default_material

bool cgv::media::mesh::obj_reader_base::have_default_material
protected

Definition at line 40 of file obj_reader.h.

◆ material_index

unsigned cgv::media::mesh::obj_reader_base::material_index
protected

keep track of current material index

Definition at line 29 of file obj_reader.h.

Referenced by clear(), get_current_material(), and parse_obj().

◆ material_index_lut

std::map<std::string, unsigned> cgv::media::mesh::obj_reader_base::material_index_lut
protected

mapping from material names to material indices

Definition at line 33 of file obj_reader.h.

Referenced by clear(), parse_obj(), and read_mtl().

◆ minus

int cgv::media::mesh::obj_reader_base::minus
protected

Definition at line 38 of file obj_reader.h.

◆ mtl_lib_files

std::set<std::string> cgv::media::mesh::obj_reader_base::mtl_lib_files
protected

Definition at line 41 of file obj_reader.h.

◆ nr_groups

unsigned cgv::media::mesh::obj_reader_base::nr_groups
protected

number of groups

Definition at line 27 of file obj_reader.h.

Referenced by clear(), and parse_obj().

◆ nr_materials

unsigned cgv::media::mesh::obj_reader_base::nr_materials
protected

number of materials

Definition at line 31 of file obj_reader.h.

Referenced by clear(), parse_obj(), and read_mtl().

◆ nr_normals

unsigned cgv::media::mesh::obj_reader_base::nr_normals
protected

Definition at line 39 of file obj_reader.h.

◆ nr_texcoords

unsigned cgv::media::mesh::obj_reader_base::nr_texcoords
protected

Definition at line 39 of file obj_reader.h.

◆ path_name

std::string cgv::media::mesh::obj_reader_base::path_name
protected

store the path name

Definition at line 52 of file obj_reader.h.

Referenced by read_mtl(), and read_obj().


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