in GraphSampling/meshLoader.h [221:330]
bool LoadOBJ_withcolor(const string & fileName,
vector< Vec3<float> > & points, vector< Vec3<float> > & colors,
vector< Vec3<int> > & triangles)
{
const char ObjDelimiters[]=" /";
const unsigned int BufferSize = 1024;
FILE * fid = fopen(fileName.c_str(), "r");
if (fid)
{
char buffer[BufferSize];
Vec3<int> ip;
Vec3<int> in;
Vec3<int> it;
char * pch;
char * str;
size_t nn = 0;
size_t nt = 0;
Vec3<float> x;
Vec3<float> c;
while (!feof(fid))
{
if (!fgets(buffer, BufferSize, fid))
{
break;
}
else if (buffer[0] == 'v')
{
if (buffer[1] == ' ')
{
str = buffer+2;
for(int k = 0; k < 6; ++k)
{
pch = strtok (str, " ");
if (pch)
{
if(k<3)
{
x[k] = static_cast<float>(atof(pch));
}
else
{
c[k-3] = static_cast<float>(atof(pch));
}
}
else
{
return false;
}
str = NULL;
}
points.push_back(x);
colors.push_back(c);
}
else if (buffer[1] == 'n')
{
++nn;
}
else if (buffer[1] == 't')
{
++nt;
}
}
else if (buffer[0] == 'f')
{
str = buffer+2;
for(int k = 0; k < 3; ++k)
{
pch = strtok (str, ObjDelimiters);
if (pch) ip[k] = atoi(pch) - 1;
else
{
return false;
}
str = NULL;
if (nt > 0)
{
pch = strtok (NULL, ObjDelimiters);
if (pch) it[k] = atoi(pch) - 1;
else
{
return false;
}
}
if (nn > 0)
{
pch = strtok (NULL, ObjDelimiters);
if (pch) in[k] = atoi(pch) - 1;
else
{
return false;
}
}
}
triangles.push_back(ip);
}
}
fclose(fid);
}
else
{
cout << "File not found" << endl;
return false;
}
return true;
}