bool LoadOFF()

in GraphSampling/meshLoader.h [56:123]


    bool LoadOFF(const string & fileName,
                 vector< Vec3<float> > & points,
                 vector< Vec3<int> > & triangles)
    {
        FILE * fid = fopen(fileName.c_str(), "r");
        if (fid)
        {
            const string strOFF("OFF");
            char temp[1024];
            fscanf(fid, "%s", temp);
            if (string(temp) != strOFF)
            {
                printf( "Loading error: format not recognized \n");
                fclose(fid);
                return false;
            }
            else
            {
                int nv = 0;
                int nf = 0;
                int ne = 0;
                fscanf(fid, "%i", &nv);
                fscanf(fid, "%i", &nf);
                fscanf(fid, "%i", &ne);
                points.resize(nv);
                triangles.resize(nf);
                Vec3<float> coord;
                float x = 0;
                float y = 0;
                float z = 0;
                for (int p = 0; p < nv ; p++)
                {
                    fscanf(fid, "%f", &x);
                    fscanf(fid, "%f", &y);
                    fscanf(fid, "%f", &z);
                    points[p].X() = x;
                    points[p].Y() = y;
                    points[p].Z() = z;
                }
                int i = 0;
                int j = 0;
                int k = 0;
                int s = 0;
                for (int t = 0; t < nf ; ++t) {
                    fscanf(fid, "%i", &s);
                    if (s == 3)
                    {
                        fscanf(fid, "%i", &i);
                        fscanf(fid, "%i", &j);
                        fscanf(fid, "%i", &k);
                        triangles[t].X() = i;
                        triangles[t].Y() = j;
                        triangles[t].Z() = k;
                    }
                    else            // Fix me: support only triangular meshes
                    {
                        for(int h = 0; h < s; ++h) fscanf(fid, "%i", &s);
                    }
                }
                fclose(fid);
            }
        }
        else
        {
            printf( "Loading error: file not found \n");
            return false;
        }    return true;
    }