mirror of https://github.com/CGAL/cgal
fix OFF surface_mesh reading
This commit is contained in:
parent
9199534373
commit
63c554fb7d
|
|
@ -146,11 +146,6 @@ bool read_OBJ(const char* fname,
|
||||||
bool verbose = true)
|
bool verbose = true)
|
||||||
{
|
{
|
||||||
std::ifstream in(fname);
|
std::ifstream in(fname);
|
||||||
if(!in)
|
|
||||||
{
|
|
||||||
std::cerr<<"File doesn't exist"<<std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return read_OBJ(in, g, np, verbose);
|
return read_OBJ(in, g, np, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,10 +157,6 @@ bool read_OFF(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np,
|
||||||
bool verbose = true)
|
bool verbose = true)
|
||||||
{
|
{
|
||||||
std::ifstream is(fname);
|
std::ifstream is(fname);
|
||||||
if(!is){
|
|
||||||
std::cerr<<"File doesn't exist."<<std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return read_OFF(is, g, np, verbose);
|
return read_OFF(is, g, np, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,11 +133,6 @@ bool read_STL(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np,
|
||||||
bool verbose = true)
|
bool verbose = true)
|
||||||
{
|
{
|
||||||
std::ifstream is(fname);
|
std::ifstream is(fname);
|
||||||
if(!is)
|
|
||||||
{
|
|
||||||
std::cerr<<"File doesn't exist."<<std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return read_STL(is, g, np, verbose);
|
return read_STL(is, g, np, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -754,32 +754,14 @@ template<>
|
||||||
void test_bgl_VTP<Polyhedron>(const char* filename,
|
void test_bgl_VTP<Polyhedron>(const char* filename,
|
||||||
const bool binary)
|
const bool binary)
|
||||||
{
|
{
|
||||||
Polyhedron fg;
|
//todo same tests as the others.
|
||||||
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
|
|
||||||
Point(2, 0, 1), Point(3, 0, 0), fg);
|
|
||||||
|
|
||||||
typedef boost::property_map<Polyhedron, CGAL::dynamic_vertex_property_t<std::size_t> >::type VertexIdMap;
|
|
||||||
VertexIdMap vid = get(CGAL::dynamic_vertex_property_t<std::size_t>(), fg);
|
|
||||||
std::size_t id = 0;
|
|
||||||
for(auto v : vertices(fg))
|
|
||||||
put(vid, v, id++);
|
|
||||||
|
|
||||||
std::ofstream os("tetrahedron.vtp");
|
|
||||||
bool ok = CGAL::write_VTP(os, fg, CGAL::parameters::vertex_index_map(vid).use_binary_mode(binary));
|
|
||||||
assert(ok);
|
|
||||||
|
|
||||||
Polyhedron fg2;
|
|
||||||
ok = CGAL::read_polygon_mesh("tetrahedron.vtp", fg2);
|
|
||||||
assert(ok);
|
|
||||||
|
|
||||||
assert(are_equal_meshes(fg, fg2));
|
|
||||||
}
|
}
|
||||||
#endif // CGAL_USE_VTK
|
#endif // CGAL_USE_VTK
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
// OFF
|
// OFF
|
||||||
/*
|
|
||||||
const char* off_file = (argc > 1) ? argv[1] : "data/prim.off";
|
const char* off_file = (argc > 1) ? argv[1] : "data/prim.off";
|
||||||
test_bgl_OFF<Polyhedron>(off_file);
|
test_bgl_OFF<Polyhedron>(off_file);
|
||||||
test_bgl_OFF<SM>(off_file);
|
test_bgl_OFF<SM>(off_file);
|
||||||
|
|
@ -787,7 +769,7 @@ int main(int argc, char** argv)
|
||||||
#ifdef CGAL_USE_OPENMESH
|
#ifdef CGAL_USE_OPENMESH
|
||||||
test_bgl_OFF<OMesh>(off_file);
|
test_bgl_OFF<OMesh>(off_file);
|
||||||
#endif
|
#endif
|
||||||
|
return 0; //tmp
|
||||||
// OBJ
|
// OBJ
|
||||||
const char* obj_file = (argc > 2) ? argv[2] : "data/sphere.obj";
|
const char* obj_file = (argc > 2) ? argv[2] : "data/sphere.obj";
|
||||||
test_bgl_OBJ<Polyhedron>(obj_file);
|
test_bgl_OBJ<Polyhedron>(obj_file);
|
||||||
|
|
@ -814,7 +796,7 @@ int main(int argc, char** argv)
|
||||||
#ifdef CGAL_USE_OPENMESH
|
#ifdef CGAL_USE_OPENMESH
|
||||||
test_bgl_STL<OMesh>(stl_file);
|
test_bgl_STL<OMesh>(stl_file);
|
||||||
#endif
|
#endif
|
||||||
*/
|
|
||||||
// GOCAD
|
// GOCAD
|
||||||
const char* gocad_file = (argc > 5) ? argv[5] : "data/2016206_MHT_surface.ts";
|
const char* gocad_file = (argc > 5) ? argv[5] : "data/2016206_MHT_surface.ts";
|
||||||
test_bgl_GOCAD<Polyhedron>(gocad_file);
|
test_bgl_GOCAD<Polyhedron>(gocad_file);
|
||||||
|
|
@ -825,6 +807,7 @@ int main(int argc, char** argv)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// VTP
|
// VTP
|
||||||
|
/*
|
||||||
#ifdef CGAL_USE_VTK
|
#ifdef CGAL_USE_VTK
|
||||||
const char* vtp_file = (argc > 6) ? argv[6] : "data/prim.off"; // @fixme put a VTP file
|
const char* vtp_file = (argc > 6) ? argv[6] : "data/prim.off"; // @fixme put a VTP file
|
||||||
|
|
||||||
|
|
@ -836,6 +819,6 @@ int main(int argc, char** argv)
|
||||||
test_bgl_VTP<SM>(vtp_file, true);
|
test_bgl_VTP<SM>(vtp_file, true);
|
||||||
test_bgl_VTP<LCC>(vtp_file, true);
|
test_bgl_VTP<LCC>(vtp_file, true);
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,11 @@ bool read_OBJ(std::istream& is,
|
||||||
VertexNormalOutputIterator vn_out,
|
VertexNormalOutputIterator vn_out,
|
||||||
bool verbose = true)
|
bool verbose = true)
|
||||||
{
|
{
|
||||||
|
if(!is.good())
|
||||||
|
{
|
||||||
|
std::cerr<<"File doesn't exist"<<std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
typedef typename boost::range_value<PointRange>::type Point;
|
typedef typename boost::range_value<PointRange>::type Point;
|
||||||
typedef typename CGAL::Kernel_traits<Point>::Kernel Kernel;
|
typedef typename CGAL::Kernel_traits<Point>::Kernel Kernel;
|
||||||
typedef typename Kernel::Vector_3 Normal;
|
typedef typename Kernel::Vector_3 Normal;
|
||||||
|
|
@ -167,11 +172,6 @@ bool read_OBJ(const char* fname, PointRange& points, PolygonRange& polygons,
|
||||||
const CGAL_BGL_NP_CLASS& np, bool verbose = true)
|
const CGAL_BGL_NP_CLASS& np, bool verbose = true)
|
||||||
{
|
{
|
||||||
std::ifstream in(fname);
|
std::ifstream in(fname);
|
||||||
if(!in)
|
|
||||||
{
|
|
||||||
std::cerr<<"File doesn't exist."<<std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return read_OBJ(in, points, polygons, np, verbose);
|
return read_OBJ(in, points, polygons, np, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,10 @@ bool read_OFF(std::istream& is,
|
||||||
|
|
||||||
CGAL_USE(verbose);
|
CGAL_USE(verbose);
|
||||||
|
|
||||||
if(!is.good())
|
if(!is.good()){
|
||||||
|
std::cerr<<"File doesn't exist."<<std::endl;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CGAL::File_scanner_OFF scanner(is);
|
CGAL::File_scanner_OFF scanner(is);
|
||||||
if(is.fail())
|
if(is.fail())
|
||||||
|
|
@ -185,11 +187,6 @@ bool read_OFF(const char* fname,
|
||||||
bool verbose = true)
|
bool verbose = true)
|
||||||
{
|
{
|
||||||
std::ifstream in(fname);
|
std::ifstream in(fname);
|
||||||
if(!in)
|
|
||||||
{
|
|
||||||
std::cerr<<"File doesn't exist."<<std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return read_OFF(in, points, polygons, np, verbose);
|
return read_OFF(in, points, polygons, np, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,13 @@ bool read_STL(std::istream& is,
|
||||||
const CGAL_BGL_NP_CLASS& /*np*/, // might become useful one day for face normals
|
const CGAL_BGL_NP_CLASS& /*np*/, // might become useful one day for face normals
|
||||||
bool verbose = false)
|
bool verbose = false)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
if(!is.good())
|
||||||
|
{
|
||||||
|
std::cerr<<"File doesn't exist"<<std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = 0;
|
||||||
// Ignore all initial whitespace
|
// Ignore all initial whitespace
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -243,10 +243,14 @@ bool write_OFF_with_or_without_fcolors(std::ostream& os,
|
||||||
typedef CGAL::Color Color;
|
typedef CGAL::Color Color;
|
||||||
|
|
||||||
typename Mesh::template Property_map<Face_index, Color> fcolors;
|
typename Mesh::template Property_map<Face_index, Color> fcolors;
|
||||||
bool has_fcolors;
|
using parameters::choose_parameter;
|
||||||
std::tie(fcolors, has_fcolors) = sm.template property_map<Face_index, CGAL::Color>("f:color");
|
using parameters::is_default_parameter;
|
||||||
|
using parameters::get_parameter;
|
||||||
|
const bool has_fcolors = !(is_default_parameter(get_parameter(np, internal_np::face_color_map)));
|
||||||
|
bool has_internal_fcolors;
|
||||||
|
std::tie(fcolors, has_internal_fcolors) = sm.template property_map<Face_index, CGAL::Color>("f:color");
|
||||||
|
|
||||||
if(has_fcolors && !std::distance(fcolors.begin(), fcolors.end()) > 0)
|
if(!has_fcolors && has_internal_fcolors && !std::distance(fcolors.begin(), fcolors.end()) > 0)
|
||||||
return write_OFF_BGL(os, sm, np.face_color_map(fcolors));
|
return write_OFF_BGL(os, sm, np.face_color_map(fcolors));
|
||||||
else
|
else
|
||||||
return write_OFF_BGL(os, sm, np);
|
return write_OFF_BGL(os, sm, np);
|
||||||
|
|
@ -264,10 +268,14 @@ bool write_OFF_with_or_without_vtextures(std::ostream& os,
|
||||||
typedef typename K::Point_2 Texture;
|
typedef typename K::Point_2 Texture;
|
||||||
|
|
||||||
typename Mesh::template Property_map<Vertex_index, Texture> vtextures;
|
typename Mesh::template Property_map<Vertex_index, Texture> vtextures;
|
||||||
bool has_vtextures;
|
using parameters::choose_parameter;
|
||||||
std::tie(vtextures, has_vtextures) = sm.template property_map<Vertex_index, Texture>("v:texcoord");
|
using parameters::is_default_parameter;
|
||||||
|
using parameters::get_parameter;
|
||||||
|
const bool has_vtextures = !(is_default_parameter(get_parameter(np, internal_np::vertex_texture_map)));
|
||||||
|
bool has_internal_vtextures;
|
||||||
|
std::tie(vtextures, has_internal_vtextures) = sm.template property_map<Vertex_index, Texture>("v:texcoord");
|
||||||
|
|
||||||
if(has_vtextures && !std::distance(vtextures.begin(), vtextures.end()) > 0)
|
if(!has_vtextures && has_internal_vtextures && !std::distance(vtextures.begin(), vtextures.end()) > 0)
|
||||||
return write_OFF_with_or_without_fcolors(os, sm, np.vertex_texture_map(vtextures));
|
return write_OFF_with_or_without_fcolors(os, sm, np.vertex_texture_map(vtextures));
|
||||||
else
|
else
|
||||||
return write_OFF_with_or_without_fcolors(os, sm, np);
|
return write_OFF_with_or_without_fcolors(os, sm, np);
|
||||||
|
|
@ -283,10 +291,16 @@ bool write_OFF_with_or_without_vcolors(std::ostream& os,
|
||||||
typedef CGAL::Color Color;
|
typedef CGAL::Color Color;
|
||||||
|
|
||||||
typename Mesh::template Property_map<Vertex_index, Color> vcolors;
|
typename Mesh::template Property_map<Vertex_index, Color> vcolors;
|
||||||
bool has_vcolors;
|
using parameters::choose_parameter;
|
||||||
std::tie(vcolors, has_vcolors) = sm.template property_map<Vertex_index, CGAL::Color>("v:color");
|
using parameters::is_default_parameter;
|
||||||
|
using parameters::get_parameter;
|
||||||
|
const bool has_vcolors = !(is_default_parameter(get_parameter(np, internal_np::vertex_color_map)));
|
||||||
|
bool has_internal_vcolors;
|
||||||
|
|
||||||
if(has_vcolors && !std::distance(vcolors.begin(), vcolors.end()) > 0)
|
|
||||||
|
std::tie(vcolors, has_internal_vcolors) = sm.template property_map<Vertex_index, CGAL::Color>("v:color");
|
||||||
|
|
||||||
|
if(!has_vcolors && has_internal_vcolors && !std::distance(vcolors.begin(), vcolors.end()) > 0)
|
||||||
return write_OFF_with_or_without_vtextures(os, sm, np.vertex_color_map(vcolors));
|
return write_OFF_with_or_without_vtextures(os, sm, np.vertex_color_map(vcolors));
|
||||||
else
|
else
|
||||||
return write_OFF_with_or_without_vtextures(os, sm, np);
|
return write_OFF_with_or_without_vtextures(os, sm, np);
|
||||||
|
|
@ -304,10 +318,14 @@ bool write_OFF_with_or_without_vnormals(std::ostream& os,
|
||||||
typedef typename K::Vector_3 Normal;
|
typedef typename K::Vector_3 Normal;
|
||||||
|
|
||||||
typename Mesh::template Property_map<Vertex_index, Normal> vnormals;
|
typename Mesh::template Property_map<Vertex_index, Normal> vnormals;
|
||||||
bool has_vnormals;
|
using parameters::choose_parameter;
|
||||||
std::tie(vnormals, has_vnormals) = sm.template property_map<Vertex_index, Normal>("v:normal");
|
using parameters::is_default_parameter;
|
||||||
|
using parameters::get_parameter;
|
||||||
|
const bool has_vnormals = !(is_default_parameter(get_parameter(np, internal_np::vertex_normal_map)));
|
||||||
|
bool has_internal_vnormals;
|
||||||
|
std::tie(vnormals, has_internal_vnormals) = sm.template property_map<Vertex_index, Normal>("v:normal");
|
||||||
|
|
||||||
if(has_vnormals && !std::distance(vnormals.begin(), vnormals.end()) > 0)
|
if(!has_vnormals && has_internal_vnormals && !std::distance(vnormals.begin(), vnormals.end()) > 0)
|
||||||
return write_OFF_with_or_without_vcolors(os, sm, np.vertex_normal_map(vnormals));
|
return write_OFF_with_or_without_vcolors(os, sm, np.vertex_normal_map(vnormals));
|
||||||
else
|
else
|
||||||
return write_OFF_with_or_without_vcolors(os, sm, np);
|
return write_OFF_with_or_without_vcolors(os, sm, np);
|
||||||
|
|
@ -329,12 +347,14 @@ bool write_OFF(std::ostream& os,
|
||||||
const Surface_mesh<Point>& sm,
|
const Surface_mesh<Point>& sm,
|
||||||
const CGAL_BGL_NP_CLASS& np)
|
const CGAL_BGL_NP_CLASS& np)
|
||||||
{
|
{
|
||||||
// Just to discard any excess named parameters
|
using parameters::choose_parameter;
|
||||||
typename CGAL::GetVertexPointMap<Surface_mesh<Point>, CGAL_BGL_NP_CLASS>::const_type
|
using parameters::is_default_parameter;
|
||||||
vpm = parameters::choose_parameter(parameters::get_parameter(np, internal_np::vertex_point),
|
using parameters::get_parameter;
|
||||||
get_const_property_map(CGAL::vertex_point, sm));
|
|
||||||
|
|
||||||
return IO::internal::write_OFF_with_or_without_vnormals(os, sm, np.vertex_point_map(vpm));
|
const bool has_vpoints= !(is_default_parameter(get_parameter(np, internal_np::vertex_point)));
|
||||||
|
if(has_vpoints)
|
||||||
|
return IO::internal::write_OFF_with_or_without_vnormals(os, sm, np);
|
||||||
|
return IO::internal::write_OFF_with_or_without_vnormals(os, sm, np.vertex_point_map(get_const_property_map(CGAL::vertex_point, sm)));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CGAL
|
} // namespace CGAL
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue