16 FILE *fp =
Fopen(name.c_str(),
"r");
18 Msg::Error(
"Unable to open file '%s'", name.c_str());
22 int numVertices, numFaces, numEdges;
23 if(fscanf(fp,
"OFF %d %d %d", &numVertices, &numFaces, &numEdges) != 3) {
28 if(!numVertices || !numFaces) {
36 std::vector<MVertex*>
vertices(numVertices);
37 for(
int i = 0; i < numVertices; i++) {
39 if(fscanf(fp,
"%lf %lf %lf", &x, &y, &
z) != 3) {
46 for(
int i = 0; i < numFaces; i++) {
48 if(fscanf(fp,
"%d", &n) != 1) {
51 int v[4] = {-1, -1, -1, -1};
53 if(fscanf(fp,
"%d %d %d", &v[0], &v[1], &v[2]) != 3) {
61 if(fscanf(fp,
"%d %d %d %d", &v[0], &v[1], &v[2], &v[3]) != 4) {
70 if(!fgets(buffer,
sizeof(buffer), fp))
85 FILE *fp =
Fopen(name.c_str(),
"w");
87 Msg::Error(
"Unable to open file '%s'", name.c_str());
94 for(
auto it =
faces.begin(); it !=
faces.end(); ++it) {
100 fprintf(fp,
"OFF %d %d 0\n", numVertices, numFaces);
102 std::vector<GEntity *> entities;
104 for(std::size_t i = 0; i < entities.size(); i++)
105 for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++)
106 entities[i]->mesh_vertices[j]->
writeOFF(fp, scalingFactor);
108 for(
auto it =
faces.begin(); it !=
faces.end(); ++it) {
111 for(std::size_t i = 0; i < gf->
triangles.size(); i++)
112 fprintf(fp,
"3 %d %d %d\n",
113 (
int)gf->
triangles[i]->getVertex(0)->getIndex() - 1,
114 (
int)gf->
triangles[i]->getVertex(1)->getIndex() - 1,
115 (
int)gf->
triangles[i]->getVertex(2)->getIndex() - 1);
116 for(std::size_t i = 0; i < gf->
quadrangles.size(); i++)
117 fprintf(fp,
"4 %d %d %d %d\n",
118 (
int)gf->
quadrangles[i]->getVertex(0)->getIndex() - 1,
119 (
int)gf->
quadrangles[i]->getVertex(1)->getIndex() - 1,
120 (
int)gf->
quadrangles[i]->getVertex(2)->getIndex() - 1,
121 (
int)gf->
quadrangles[i]->getVertex(3)->getIndex() - 1);