Vis 2 Demo  1.0
Technical illustration type real-time rendering of geometry
 All Classes Namespaces Files Functions Variables Typedefs Macros
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
vis2::LoaderOBJ Class Reference

This class is for reading and parsing geometry from a Wavefront Object (OBJ) or a binary (DAT) file. More...

Public Member Functions

 LoaderOBJ (const std::string &)
 Constructor. More...
 
 ~LoaderOBJ ()
 Destructor. More...
 
int obj2Container ()
 This function starts the loading / parsing process. More...
 
const unsigned int getNrFaceInd () const
 A getter for the number of face indices. More...
 
const unsigned int getNrVertices () const
 A getter for the number of vertices. More...
 

Public Attributes

GLfloat * vert_positions
 holds the vertex positions as a 1-dimensional array
(every 3 consecutive values are 1 vertex position) More...
 
GLfloat * vert_normals
 holds the vertex normals as a 1-dimensional array
(every 3 consecutive values are 1 vertex normal) More...
 
GLfloat * vert_uvs
 holds the vertex texture coordinates as a 1-dimensional array
(every 2 consecutive values are 1 texture coordinate) More...
 
GLuint * face_ind
 holds the face indices as a 1-dimensional array
(every 3 consecutive values describe one triangle) More...
 

Private Member Functions

 LoaderOBJ (const LoaderOBJ &)
 Hidden copy-contructor. More...
 
int readDataFromOBJ ()
 This function reads and parses the OBJ file. More...
 
int readDataFromDAT ()
 This function reads and parses the DAT file. More...
 
int writeDataToDAT ()
 This function is called by readDataFromOBJ() to write the DAT file. More...
 
void checkForErrors (std::ios &_ofs)
 This is the error-handling function. More...
 
void parseOBJ (std::FILE *_f)
 This function contains the main parsing functionality. More...
 
vertAttribContainer string2VertAttr (std::string &_line)
 This function converts a string to a std::vector of 3 floats. More...
 
indexContainer string2Index (std::string &_line)
 This function converts a string to a std::vector of 9 uints. More...
 
bool iCareEqual (const indexContainer &_ic1, const indexContainer &_ic2)
 This is function a for comparing two index containers. More...
 
void mult2singleIndex ()
 This function converts the multiple-index geometry in the OBJ file into single-index geometry for use in OpenGL. More...
 

Private Attributes

std::string file_path
 holds the full path to the OBJ or DAT file More...
 
unsigned int file_type
 is VIS2_FILE_TYPE_OBJ if the read file is OBJ, VIS2_FILE_TYPE_DAT therwise More...
 
multIndexContainer new_mult_indices
 contains all old index triples that caused new elements to be added to the vertex attribute arrays More...
 
vertAttribContainer vert_positions_OBJ
 holds the old vertex positions as a 1-dimensional array
(every 3 consecutive values are 1 vertex position) More...
 
vertAttribContainer vert_normals_OBJ
 holds the old vertex normals as a 1-dimensional array
(every 3 consecutive values are 1 vertex normal) More...
 
vertAttribContainer vert_uvs_OBJ
 holds the old vertex texture coordinates as a 1-dimensional array
(every 2 consecutive values are 1 texture coordinate) More...
 
indexContainer face_ind_OBJ
 holds the old face multi-indices as a 1-dimensional array
(every 9 consecutive values describe one triangle) More...
 
unsigned int nr_face_ind
 is the number of new face indices in total More...
 
unsigned int single_ind
 is the number of single-indices (unique) needed for drawing More...
 

Detailed Description

This class is for reading and parsing geometry from a Wavefront Object (OBJ) or a binary (DAT) file.

The class parses an OBJ file and writes a binary file with extension DAT it in the same
directory as the original. If the input file is an already parsed DAT file, the class loads it directy.

Definition at line 26 of file LoaderOBJ.h.

Constructor & Destructor Documentation

LoaderOBJ::LoaderOBJ ( const std::string &  _file_path)

Constructor.

Only checks if the file has a valid extension. No parsing takes place yet.

Definition at line 8 of file LoaderOBJ.cpp.

LoaderOBJ::~LoaderOBJ ( )

Destructor.

Definition at line 26 of file LoaderOBJ.cpp.

vis2::LoaderOBJ::LoaderOBJ ( const LoaderOBJ )
private

Hidden copy-contructor.

Member Function Documentation

void LoaderOBJ::checkForErrors ( std::ios &  _ofs)
private

This is the error-handling function.

Definition at line 152 of file LoaderOBJ.cpp.

const unsigned int vis2::LoaderOBJ::getNrFaceInd ( ) const
inline

A getter for the number of face indices.

Definition at line 44 of file LoaderOBJ.h.

const unsigned int vis2::LoaderOBJ::getNrVertices ( ) const
inline

A getter for the number of vertices.

Definition at line 46 of file LoaderOBJ.h.

bool LoaderOBJ::iCareEqual ( const indexContainer _ic1,
const indexContainer _ic2 
)
private

This is function a for comparing two index containers.

Parameters
[in]_ic1is the one,
[in]_ic2is the other index container.
The comparison is based on the first 3 entries only.

Definition at line 295 of file LoaderOBJ.cpp.

void LoaderOBJ::mult2singleIndex ( )
private

This function converts the multiple-index geometry in the OBJ file into single-index geometry for use in OpenGL.

Definition at line 310 of file LoaderOBJ.cpp.

int LoaderOBJ::obj2Container ( )

This function starts the loading / parsing process.

Definition at line 38 of file LoaderOBJ.cpp.

void LoaderOBJ::parseOBJ ( std::FILE *  _f)
private

This function contains the main parsing functionality.

Parameters
[in]_fis the openend file handle.

Definition at line 181 of file LoaderOBJ.cpp.

int LoaderOBJ::readDataFromDAT ( )
private

This function reads and parses the DAT file.

Returns
0 if the parsing was successful.
If the file handling caused an error, the application exits.

Definition at line 82 of file LoaderOBJ.cpp.

int LoaderOBJ::readDataFromOBJ ( )
private

This function reads and parses the OBJ file.

Returns
0 if the parsing was successful.
If the file handling caused an error, the application exits.

Definition at line 59 of file LoaderOBJ.cpp.

indexContainer LoaderOBJ::string2Index ( std::string &  _line)
private

This function converts a string to a std::vector of 9 uints.

As the OBJ file contains multi-indexed face indices, each index of a triangle
constists of 3 indices into the vertex, normals and texture coordinate arrays.

Parameters
[in]_lineis the string read from the OBJ file.

Definition at line 265 of file LoaderOBJ.cpp.

vertAttribContainer LoaderOBJ::string2VertAttr ( std::string &  _line)
private

This function converts a string to a std::vector of 3 floats.

Parameters
[in]_lineis the string read from the OBJ file.

Definition at line 242 of file LoaderOBJ.cpp.

int LoaderOBJ::writeDataToDAT ( )
private

This function is called by readDataFromOBJ() to write the DAT file.

Returns
0 if the writing of the DAT file was successful.
If the file handling caused an error, the application exits.

Definition at line 117 of file LoaderOBJ.cpp.

Member Data Documentation

GLuint* vis2::LoaderOBJ::face_ind

holds the face indices as a 1-dimensional array
(every 3 consecutive values describe one triangle)

Definition at line 41 of file LoaderOBJ.h.

indexContainer vis2::LoaderOBJ::face_ind_OBJ
private

holds the old face multi-indices as a 1-dimensional array
(every 9 consecutive values describe one triangle)

Definition at line 116 of file LoaderOBJ.h.

std::string vis2::LoaderOBJ::file_path
private

holds the full path to the OBJ or DAT file

Definition at line 107 of file LoaderOBJ.h.

unsigned int vis2::LoaderOBJ::file_type
private

is VIS2_FILE_TYPE_OBJ if the read file is OBJ, VIS2_FILE_TYPE_DAT therwise

Definition at line 108 of file LoaderOBJ.h.

multIndexContainer vis2::LoaderOBJ::new_mult_indices
private

contains all old index triples that caused new elements to be added to the vertex attribute arrays

Definition at line 110 of file LoaderOBJ.h.

unsigned int vis2::LoaderOBJ::nr_face_ind
private

is the number of new face indices in total

Definition at line 118 of file LoaderOBJ.h.

unsigned int vis2::LoaderOBJ::single_ind
private

is the number of single-indices (unique) needed for drawing

Definition at line 119 of file LoaderOBJ.h.

GLfloat* vis2::LoaderOBJ::vert_normals

holds the vertex normals as a 1-dimensional array
(every 3 consecutive values are 1 vertex normal)

Definition at line 39 of file LoaderOBJ.h.

vertAttribContainer vis2::LoaderOBJ::vert_normals_OBJ
private

holds the old vertex normals as a 1-dimensional array
(every 3 consecutive values are 1 vertex normal)

Definition at line 114 of file LoaderOBJ.h.

GLfloat* vis2::LoaderOBJ::vert_positions

holds the vertex positions as a 1-dimensional array
(every 3 consecutive values are 1 vertex position)

Definition at line 38 of file LoaderOBJ.h.

vertAttribContainer vis2::LoaderOBJ::vert_positions_OBJ
private

holds the old vertex positions as a 1-dimensional array
(every 3 consecutive values are 1 vertex position)

Definition at line 113 of file LoaderOBJ.h.

GLfloat* vis2::LoaderOBJ::vert_uvs

holds the vertex texture coordinates as a 1-dimensional array
(every 2 consecutive values are 1 texture coordinate)

Definition at line 40 of file LoaderOBJ.h.

vertAttribContainer vis2::LoaderOBJ::vert_uvs_OBJ
private

holds the old vertex texture coordinates as a 1-dimensional array
(every 2 consecutive values are 1 texture coordinate)

Definition at line 115 of file LoaderOBJ.h.


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