1) fixed token parsing : SplitToken() should take the original IO mask and not the clamped (with mesh attributes) one.

2) some indentation work.
This commit is contained in:
Marco Di Benedetto 2009-11-22 19:09:53 +00:00
parent 302a7725fa
commit 8e9062b12b
1 changed files with 296 additions and 293 deletions

View File

@ -282,6 +282,7 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
if (oi.mask == -1) if (oi.mask == -1)
LoadMask(filename, oi); LoadMask(filename, oi);
const int inputMask = oi.mask;
Mask::ClampMask<OpenMeshType>(m,oi.mask); Mask::ClampMask<OpenMeshType>(m,oi.mask);
if (oi.numVertices == 0) if (oi.numVertices == 0)
@ -395,7 +396,7 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
std::string texcoord; std::string texcoord;
std::string normal; std::string normal;
for(int i=0;i<vertexesPerFace;++i) // remember index starts from 1 instead of 0 for(int i=0;i<vertexesPerFace;++i) // remember index starts from 1 instead of 0
SplitToken(tokens[i+1], ff.v[i], ff.n[i], ff.t[i], oi.mask); SplitToken(tokens[i+1], ff.v[i], ff.n[i], ff.t[i], inputMask);
if ( oi.mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) if ( oi.mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD )
{ {
@ -453,7 +454,7 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
std::string normal; std::string normal;
for(int i=0;i<3;++i) for(int i=0;i<3;++i)
{ // remember index starts from 1 instead of 0 { // remember index starts from 1 instead of 0
SplitToken(tokens[i+1], ff.v[i], ff.n[i], ff.t[i], oi.mask); SplitToken(tokens[i+1], ff.v[i], ff.n[i], ff.t[i], inputMask);
if(QuadFlag) { ff.v[i]+=1; } if(QuadFlag) { ff.v[i]+=1; }
} }
if ( oi.mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) if ( oi.mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD )
@ -481,7 +482,8 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
// verifying validity of vertex normal indices // verifying validity of vertex normal indices
// ------------------------------------------- // -------------------------------------------
for(int i=0;i<3;i++) for(int i=0;i<3;i++)
if(!GoodObjIndex(ff.n[i],numVNormals)) return E_BAD_VERT_NORMAL_INDEX; if(!GoodObjIndex(ff.n[i],numVNormals))
return E_BAD_VERT_NORMAL_INDEX;
} }
// assigning face color // assigning face color
@ -522,7 +524,7 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
int vt4_index; int vt4_index;
int vn4_index; int vn4_index;
SplitToken(tokens[++iVertex], v4_index, vn4_index, vt4_index, oi.mask); SplitToken(tokens[++iVertex], v4_index, vn4_index, vt4_index, inputMask);
if(QuadFlag) { v4_index+=1; } if(QuadFlag) { v4_index+=1; }
if(!GoodObjIndex(v4_index, numVertices)) if(!GoodObjIndex(v4_index, numVertices))
return E_BAD_VERT_INDEX; return E_BAD_VERT_INDEX;
@ -678,14 +680,14 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
} // end of Open } // end of Open
/*! /*!
* Read the next valid line and parses it into "tokens", allowing * Read the next valid line and parses it into "tokens", allowing
* the tokens to be read one at a time. * the tokens to be read one at a time.
* \param stream The object providing the input stream * \param stream The object providing the input stream
* \param tokens The "tokens" in the next line * \param tokens The "tokens" in the next line
*/ */
inline static const void TokenizeNextLine(std::ifstream &stream, std::vector< std::string > &tokens) inline static const void TokenizeNextLine(std::ifstream &stream, std::vector< std::string > &tokens)
{ {
if(stream.eof()) return; if(stream.eof()) return;
std::string line; std::string line;
do do
@ -713,30 +715,31 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
} }
} }
while (from<length); while (from<length);
} // end TokenizeNextLine } // end TokenizeNextLine
inline static const void SplitToken(std::string token, int &vId, int &nId, int &tId, int mask) inline static const void SplitToken(std::string token, int &vId, int &nId, int &tId, int mask)
{ {
std::string vertex; std::string vertex;
std::string texcoord; std::string texcoord;
std::string normal; std::string normal;
if( ( mask & Mask::IOM_WEDGTEXCOORD ) && (mask & Mask::IOM_WEDGNORMAL) ) SplitVVTVNToken(token, vertex, texcoord, normal); if( ( mask & Mask::IOM_WEDGTEXCOORD ) && (mask & Mask::IOM_WEDGNORMAL) ) SplitVVTVNToken(token, vertex, texcoord, normal);
if(!( mask & Mask::IOM_WEDGTEXCOORD ) && (mask & Mask::IOM_WEDGNORMAL) ) SplitVVNToken(token, vertex, normal); if(!( mask & Mask::IOM_WEDGTEXCOORD ) && (mask & Mask::IOM_WEDGNORMAL) ) SplitVVNToken(token, vertex, normal);
if( ( mask & Mask::IOM_WEDGTEXCOORD ) &&!(mask & Mask::IOM_WEDGNORMAL) ) SplitVVTToken(token, vertex, texcoord); if( ( mask & Mask::IOM_WEDGTEXCOORD ) &&!(mask & Mask::IOM_WEDGNORMAL) ) SplitVVTToken(token, vertex, texcoord);
if(!( mask & Mask::IOM_WEDGTEXCOORD ) &&!(mask & Mask::IOM_WEDGNORMAL) ) SplitVToken(token, vertex); if(!( mask & Mask::IOM_WEDGTEXCOORD ) &&!(mask & Mask::IOM_WEDGNORMAL) ) SplitVToken(token, vertex);
vId = atoi(vertex.c_str())-1; vId = atoi(vertex.c_str()) - 1;
if(mask & Mask::IOM_WEDGTEXCOORD) tId = atoi(texcoord.c_str())-1; if(mask & Mask::IOM_WEDGTEXCOORD) tId = atoi(texcoord.c_str()) - 1;
if(mask & Mask::IOM_WEDGNORMAL) nId= atoi(normal.c_str())-1; if(mask & Mask::IOM_WEDGNORMAL) nId = atoi(normal.c_str()) - 1;
} }
inline static const void SplitVToken(std::string token, std::string &vertex) inline static const void SplitVToken(std::string token, std::string &vertex)
{ {
vertex=token; vertex = token;
} }
inline static const void SplitVVTToken(std::string token, std::string &vertex, std::string &texcoord) inline static const void SplitVVTToken(std::string token, std::string &vertex, std::string &texcoord)
{ {
vertex.clear(); vertex.clear();
texcoord.clear(); texcoord.clear();
@ -762,10 +765,10 @@ inline static const void SplitVToken(std::string token, std::string &vertex)
++to; ++to;
} }
} }
} // end of SplitVVTToken } // end of SplitVVTToken
inline static const void SplitVVNToken(std::string token, std::string &vertex, std::string &normal) inline static const void SplitVVNToken(std::string token, std::string &vertex, std::string &normal)
{ {
vertex.clear(); vertex.clear();
normal.clear(); normal.clear();
@ -792,10 +795,10 @@ inline static const void SplitVToken(std::string token, std::string &vertex)
++to; ++to;
} }
} }
} // end of SplitVVNToken } // end of SplitVVNToken
inline static const void SplitVVTVNToken(std::string token, std::string &vertex, std::string &texcoord, std::string &normal) inline static const void SplitVVTVNToken(std::string token, std::string &vertex, std::string &texcoord, std::string &normal)
{ {
vertex.clear(); vertex.clear();
texcoord.clear(); texcoord.clear();
normal.clear(); normal.clear();
@ -828,7 +831,7 @@ inline static const void SplitVToken(std::string token, std::string &vertex)
++to; ++to;
} }
} }
} // end of SplitVVTVNToken } // end of SplitVVTVNToken
/*! /*!
* Retrieves infos about kind of data stored into the file and fills a mask appropriately * Retrieves infos about kind of data stored into the file and fills a mask appropriately