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)
LoadMask(filename, oi);
const int inputMask = oi.mask;
Mask::ClampMask<OpenMeshType>(m,oi.mask);
if (oi.numVertices == 0)
@ -395,7 +396,7 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
std::string texcoord;
std::string normal;
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 )
{
@ -453,7 +454,7 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
std::string normal;
for(int i=0;i<3;++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(QuadFlag) { ff.v[i]+=1; }
}
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
// -------------------------------------------
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
@ -522,7 +524,7 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
int vt4_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(!GoodObjIndex(v4_index, numVertices))
return E_BAD_VERT_INDEX;
@ -678,14 +680,14 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
} // end of Open
/*!
* Read the next valid line and parses it into "tokens", allowing
* the tokens to be read one at a time.
* \param stream The object providing the input stream
* \param tokens The "tokens" in the next line
*/
inline static const void TokenizeNextLine(std::ifstream &stream, std::vector< std::string > &tokens)
{
/*!
* Read the next valid line and parses it into "tokens", allowing
* the tokens to be read one at a time.
* \param stream The object providing the input stream
* \param tokens The "tokens" in the next line
*/
inline static const void TokenizeNextLine(std::ifstream &stream, std::vector< std::string > &tokens)
{
if(stream.eof()) return;
std::string line;
do
@ -713,30 +715,31 @@ static int Open( OpenMeshType &m, const char * filename, Info &oi)
}
}
while (from<length);
} // end TokenizeNextLine
} // end TokenizeNextLine
inline static const void SplitToken(std::string token, int &vId, int &nId, int &tId, int mask)
{
std::string vertex;
std::string texcoord;
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) ) 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) ) SplitVToken(token, vertex);
vId = atoi(vertex.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;
vId = atoi(vertex.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;
}
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();
texcoord.clear();
@ -762,10 +765,10 @@ inline static const void SplitVToken(std::string token, std::string &vertex)
++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();
normal.clear();
@ -792,10 +795,10 @@ inline static const void SplitVToken(std::string token, std::string &vertex)
++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();
texcoord.clear();
normal.clear();
@ -828,7 +831,7 @@ inline static const void SplitVToken(std::string token, std::string &vertex)
++to;
}
}
} // end of SplitVVTVNToken
} // end of SplitVVTVNToken
/*!
* Retrieves infos about kind of data stored into the file and fills a mask appropriately