{"action":"created","issue":{"url":"https://api.github.com/repos/folded/carve/issues/54","labels_url":"https://api.github.com/repos/folded/carve/issues/54/labels{/name}","comments_url":"https://api.github.com/repos/folded/carve/issues/54/comments","events_url":"https://api.github.com/repos/folded/carve/issues/54/events","html_url":"https://github.com/folded/carve/issues/54","id":59768547,"number":54,"title":"Crash in reading OFF file","user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/folded/carve/labels/auto-migrated","name":"auto-migrated","color":"ededed"},{"url":"https://api.github.com/repos/folded/carve/labels/Priority-Medium","name":"Priority-Medium","color":"ededed"},{"url":"https://api.github.com/repos/folded/carve/labels/Type-Defect","name":"Type-Defect","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-04T09:03:35Z","updated_at":"2015-03-04T09:03:36Z","closed_at":null,"body":"```\nDear all,\n\nCould anyone help me to take a look at the following code to read OFF file? The \ncode crashed at this line:\n  carve::mesh::MeshSet<3> poly1(faces);\n\n\nIn addition, could anyone tell me how to write the code to write OFF file (the \nfunction 'write_off')?\n\n\nThanks,\nTang Laoya\n\n/// file: test_carve_polyhedrons_2.cpp\n// Begin License:\n// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).\n// All rights reserved.\n//\n// This file is part of the Carve CSG Library (http://carve-csg.com/)\n//\n// This file may be used under the terms of the GNU General Public\n// License version 2.0 as published by the Free Software Foundation\n// and appearing in the file LICENSE.GPL2 included in the packaging of\n// this file.\n//\n// This file is provided \"AS IS\" with NO WARRANTY OF ANY KIND,\n// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE.\n// End:\n\n#include <carve/csg.hpp>\n#include <carve/poly.hpp>\n#include <carve/geom.hpp>\n\n#include <vector>\n#include <iostream>\n\nvoid read_off(std::vector<carve::mesh::MeshSet<3>::vertex_t> *verts, \nstd::vector<carve::mesh::MeshSet<3>::face_t *> *faces,char* file)\n{\n\tFILE *fp=fopen(file,\"r\");\n\tchar off[10];\n\tint np, nf, nv, v;\n\tdouble x,y,z;\n  std::vector<carve::mesh::MeshSet<3>::vertex_t *> corners;\n\tfscanf(fp,\"%s\\n\",&off);\n\tfscanf(fp,\"%d %d\\n\",&np,&nf);\n\tfor (int i=0;i<np;i++)\n\t{\n\t\tfscanf(fp,\"%e %e %e\\n\",&x,&y,&z);\n\t\tverts->push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(x,y,z)));\n\t}\n\tfor (int i=0;i<nf;i++)\n\t{\n\t\tfscanf(fp,\"%d\",&nv);\n\t\tfor (int j=0;j<nv;j++)\n\t\t{\n\t\t\tfscanf(fp,\"%d\",&v);\n\t\t\tcorners.push_back(&(*verts)[v]);\n\t\t}\n\t\tfaces->push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\t\tcorners.clear();\n\t}\n\tfclose(fp);\n}\n\nvoid write_off(carve::mesh::MeshSet<3> poly,char *file)\n{\n\n}\n\nint main()\n{\n  //create a tetrahedron\n#define mytest\n#ifdef mytest\n  std::vector<carve::mesh::MeshSet<3>::vertex_t> verts;\n  std::vector<carve::mesh::MeshSet<3>::face_t *> faces;\n\tchar *file=\"E:\\\\Users\\\\tang\\\\tang\\\\mesh\\\\CSG\\\\carve-clone\\\\mytest\\\\a1.off\";\n\tread_off(&verts,&faces,file);\n  carve::mesh::MeshSet<3> poly1(faces);\n\tfile=\"E:\\\\Users\\\\tang\\\\tang\\\\mesh\\\\CSG\\\\carve-clone\\\\mytest\\\\a2.off\";\n\tread_off(&verts,&faces,file);\n  carve::mesh::MeshSet<3> poly2(faces);\n  carve::mesh::MeshSet<3> *is_poly = carve::csg::CSG().compute(&poly1,\n                                                               &poly2,\n                                                               carve::csg::CSG::A_MINUS_B);\n#else\n  std::vector<carve::mesh::MeshSet<3>::vertex_t> tet_verts;\n  std::vector<carve::mesh::MeshSet<3>::face_t *> tet_faces;\n  std::vector<carve::mesh::MeshSet<3>::vertex_t *> corners;\n\n  tet_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(0.0, 0.0, 0.0)));\n  tet_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(1.0, 0.0, 0.0)));\n  tet_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(0.0, 1.0, 0.0)));\n  tet_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(0.0, 0.0, 1.0)));\n \n  corners.push_back(&tet_verts[0]);\n  corners.push_back(&tet_verts[2]);\n  corners.push_back(&tet_verts[1]);\n  tet_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n  corners.clear();\n  corners.push_back(&tet_verts[0]);\n  corners.push_back(&tet_verts[1]);\n  corners.push_back(&tet_verts[3]);\n  tet_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n  corners.clear();\n  corners.push_back(&tet_verts[0]);\n  corners.push_back(&tet_verts[3]);\n  corners.push_back(&tet_verts[2]);\n  tet_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n  corners.clear();\n  corners.push_back(&tet_verts[1]);\n  corners.push_back(&tet_verts[2]);\n  corners.push_back(&tet_verts[3]);\n  tet_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n  carve::mesh::MeshSet<3> tetrahedron(tet_faces);\n\n  //create a triangle\n  std::vector<carve::mesh::MeshSet<3>::vertex_t> tri_verts;\n  std::vector<carve::mesh::MeshSet<3>::face_t *> tri_faces;\n\n  //Vertices\n  //crashes if last coordinate set to 1e-8, but ok for 1e-7\n  //tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(-0.3, 0.0, 1e-8)));\n  //tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(1.0, 0.0, 1.1e-8)));\n  //tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(-0.3, 1.0, 1.1e-8)));\n  tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(-0.1, -0.1, 0.5)));\n  tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(1.1, -0.1, 0.5)));\n  tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(-0.1, 1.1, 0.5)));\n\n  //Face\n  corners.clear();\n  corners.push_back(&tri_verts[0]);\n  corners.push_back(&tri_verts[2]);\n  corners.push_back(&tri_verts[1]);\n  tri_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n//  corners.clear();\n//  corners.push_back(&tri_verts[0]);\n//  corners.push_back(&tri_verts[1]);\n//  corners.push_back(&tri_verts[2]);\n//  tri_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners));\n\n  carve::mesh::MeshSet<3> triangle(tri_faces);\n\n  //cut triangle with tetrahedron.\n  carve::mesh::MeshSet<3> *is_poly = carve::csg::CSG().compute(&tetrahedron,\n                                                               &triangle,\n                                                               carve::csg::CSG::B_MINUS_A);\n#endif\n  // std::cout << \"Tetrahedron is ... \\n\" << tetrahedron;\n  // std::cout << \"Triangle is ... \\n\" << triangle;\n  // std::cout << \"Intersection is ... \\n\" << *is_poly;\n\n  return 0;\n}\n\n```\n\nOriginal issue reported on code.google.com by `tanglaoy...@gmail.com` on 16 Apr 2014 at 2:57"},"comment":{"url":"https://api.github.com/repos/folded/carve/issues/comments/77119892","html_url":"https://github.com/folded/carve/issues/54#issuecomment-77119892","issue_url":"https://api.github.com/repos/folded/carve/issues/54","id":77119892,"user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"created_at":"2015-03-04T09:03:36Z","updated_at":"2015-03-04T09:03:36Z","body":"```\nSorry again. \n\nNow the crash problem is solved. But the following error message displayed:\nuncontained hole loop does not share vertices with any face loop!\n\nCould anyone help me to take a look at it?\n\nIn addition, could anyone tell me how to write the 'write_off' function?\n\nThanks,\nTang Laoya\n\n\n\n// Begin License:\n// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).\n// All rights reserved.\n//\n// This file is part of the Carve CSG Library (http://carve-csg.com/)\n//\n// This file may be used under the terms of the GNU General Public\n// License version 2.0 as published by the Free Software Foundation\n// and appearing in the file LICENSE.GPL2 included in the packaging of\n// this file.\n//\n// This file is provided \"AS IS\" with NO WARRANTY OF ANY KIND,\n// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE.\n// End:\n\n#include <carve/csg.hpp>\n#include <carve/poly.hpp>\n#include <carve/geom.hpp>\n\n#include <vector>\n#include <iostream>\n\nvoid read_off(std::vector<carve::mesh::MeshSet<3>::vertex_t> *verts, \nstd::vector<carve::mesh::MeshSet<3>::face_t *> *faces,char* file)\n{\n\tFILE *fp=fopen(file,\"r\");\n\tchar off[10];\n\tint np, nf, tmp, nv, v;\n\tdouble x,y,z;\n  std::vector<carve::mesh::MeshSet<3>::vertex_t *> corners;\n\tfscanf(fp,\"%s\\n\",&off);\n\tfscanf(fp,\"%d %d %d\\n\",&np,&nf,&tmp);\n\tfor (int i=0;i<np;i++)\n\t{\n\t\tfscanf(fp,\"%le %le %le\\n\",&x,&y,&z);\n\t\tverts->push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(x,y,z)));\n\t}\n\tfor (int i=0;i<nf;i++)\n\t{\n\t\tfscanf(fp,\"%d\",&nv);\n\t\tfor (int j=0;j<nv;j++)\n\t\t{\n\t\t\tfscanf(fp,\"%d\",&v);\n\t\t\tcorners.push_back(&(*verts)[v]);\n\t\t}\n\t\tfaces->push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\t\tcorners.clear();\n\t}\n\tfclose(fp);\n}\n\nvoid write_off(carve::mesh::MeshSet<3> poly,char *file)\n{\n\n}\n\nint main()\n{\n  //create a tetrahedron\n#define mytest\n#ifdef mytest\n  std::vector<carve::mesh::MeshSet<3>::vertex_t> verts;\n  std::vector<carve::mesh::MeshSet<3>::face_t *> faces;\n\tchar *file=\"E:\\\\Users\\\\tang\\\\tang\\\\mesh\\\\CSG\\\\carve-clone\\\\mytest\\\\a1.off\";\n\tread_off(&verts,&faces,file);\n  carve::mesh::MeshSet<3> poly1(faces);\n\tverts.clear();\n\tfaces.clear();\n\tfile=\"E:\\\\Users\\\\tang\\\\tang\\\\mesh\\\\CSG\\\\carve-clone\\\\mytest\\\\a2.off\";\n\tread_off(&verts,&faces,file);\n  carve::mesh::MeshSet<3> poly2(faces);\n  carve::mesh::MeshSet<3> *is_poly = carve::csg::CSG().compute(&poly1,\n                                                               &poly2,\n                                                               carve::csg::CSG::A_MINUS_B);\n\tverts.clear();\n\tfaces.clear();\n#else\n  std::vector<carve::mesh::MeshSet<3>::vertex_t> tet_verts;\n  std::vector<carve::mesh::MeshSet<3>::face_t *> tet_faces;\n  std::vector<carve::mesh::MeshSet<3>::vertex_t *> corners;\n\n  tet_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(0.0, 0.0, 0.0)));\n  tet_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(1.0, 0.0, 0.0)));\n  tet_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(0.0, 1.0, 0.0)));\n  tet_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(0.0, 0.0, 1.0)));\n \n  corners.push_back(&tet_verts[0]);\n  corners.push_back(&tet_verts[2]);\n  corners.push_back(&tet_verts[1]);\n  tet_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n  corners.clear();\n  corners.push_back(&tet_verts[0]);\n  corners.push_back(&tet_verts[1]);\n  corners.push_back(&tet_verts[3]);\n  tet_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n  corners.clear();\n  corners.push_back(&tet_verts[0]);\n  corners.push_back(&tet_verts[3]);\n  corners.push_back(&tet_verts[2]);\n  tet_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n  corners.clear();\n  corners.push_back(&tet_verts[1]);\n  corners.push_back(&tet_verts[2]);\n  corners.push_back(&tet_verts[3]);\n  tet_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n  carve::mesh::MeshSet<3> tetrahedron(tet_faces);\n\n  //create a triangle\n  std::vector<carve::mesh::MeshSet<3>::vertex_t> tri_verts;\n  std::vector<carve::mesh::MeshSet<3>::face_t *> tri_faces;\n\n  //Vertices\n  //crashes if last coordinate set to 1e-8, but ok for 1e-7\n  //tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(-0.3, 0.0, 1e-8)));\n  //tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(1.0, 0.0, 1.1e-8)));\n  //tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(-0.3, 1.0, 1.1e-8)));\n  tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(-0.1, -0.1, 0.5)));\n  tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(1.1, -0.1, 0.5)));\n  tri_verts.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(-0.1, 1.1, 0.5)));\n\n  //Face\n  corners.clear();\n  corners.push_back(&tri_verts[0]);\n  corners.push_back(&tri_verts[2]);\n  corners.push_back(&tri_verts[1]);\n  tri_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners.begin(), corners.end()));\n\n//  corners.clear();\n//  corners.push_back(&tri_verts[0]);\n//  corners.push_back(&tri_verts[1]);\n//  corners.push_back(&tri_verts[2]);\n//  tri_faces.push_back(new carve::mesh::MeshSet<3>::face_t(corners));\n\n  carve::mesh::MeshSet<3> triangle(tri_faces);\n\n  //cut triangle with tetrahedron.\n  carve::mesh::MeshSet<3> *is_poly = carve::csg::CSG().compute(&tetrahedron,\n                                                               &triangle,\n                                                               carve::csg::CSG::B_MINUS_A);\n#endif\n  // std::cout << \"Tetrahedron is ... \\n\" << tetrahedron;\n  // std::cout << \"Triangle is ... \\n\" << triangle;\n  // std::cout << \"Intersection is ... \\n\" << *is_poly;\n\n  return 0;\n}\n\n```\n\nOriginal comment by `tanglaoy...@gmail.com` on 16 Apr 2014 at 3:42"}}