mirror of https://github.com/CGAL/cgal
Add CGAL::read_off() and CGAL::write_off() to OpenMesh
This commit is contained in:
parent
232106a39d
commit
5098e546c1
|
|
@ -36,13 +36,13 @@ int main(int argc, char** argv )
|
|||
V.push_back(add_vertex(mesh));
|
||||
add_face(V.begin(), V.end(), mesh);
|
||||
|
||||
// OpenMesh::IO::read_mesh(mesh, (argc>1)?argv[1]:"in.off");
|
||||
CGAL::read_off(std::ifstream((argc>1)?argv[1]:"in.off"), mesh);
|
||||
|
||||
BOOST_FOREACH(vertex_descriptor vd, vertices(mesh)){
|
||||
BOOST_FOREACH(halfedge_descriptor hd, CGAL::halfedges_around_target(vd,mesh)){
|
||||
if(! CGAL::is_border(edge(hd,mesh),mesh)){
|
||||
CGAL::Euler::flip_edge(hd,mesh);
|
||||
OpenMesh::IO::write_mesh(mesh, (argc>2)?argv[2]:"out.off");
|
||||
CGAL::write_off((argc>2)?argv[2]:"out.off", mesh);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include <CGAL/boost/graph/iterator.h>
|
||||
#include <CGAL/Iterator_range.h>
|
||||
#include <CGAL/boost/graph/helpers.h>
|
||||
#include <CGAL/boost/graph/io.h>
|
||||
#include <CGAL/assertions.h>
|
||||
|
||||
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
|
||||
|
|
@ -691,6 +692,20 @@ void clear(OpenMesh::PolyMesh_ArrayKernelT<K>& sm)
|
|||
CGAL_postcondition(num_faces(sm) == 0);
|
||||
}
|
||||
|
||||
|
||||
template<typename K>
|
||||
bool read_off(std::istream& is, OpenMesh::PolyMesh_ArrayKernelT<K>& sm)
|
||||
{
|
||||
return OpenMesh::IO::read_mesh(sm, is, ".OFF");
|
||||
}
|
||||
|
||||
|
||||
template<typename K>
|
||||
bool write_off(std::ostream& os, OpenMesh::PolyMesh_ArrayKernelT<K>& sm)
|
||||
{
|
||||
return OpenMesh::IO::write_mesh(sm, os, ".OFF");
|
||||
}
|
||||
|
||||
}
|
||||
#ifndef CGAL_NO_DEPRECATED_CODE
|
||||
#include <CGAL/boost/graph/backward_compatibility_functions.h>
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <CGAL/boost/graph/iterator.h>
|
||||
#include <CGAL/Iterator_range.h>
|
||||
#include <CGAL/boost/graph/helpers.h>
|
||||
#include <CGAL/boost/graph/io.h>
|
||||
#include <CGAL/assertions.h>
|
||||
|
||||
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
|
||||
|
|
@ -610,7 +611,40 @@ bool is_valid(OpenMesh::TriMesh_ArrayKernelT<K>& sm, bool /* verbose */ = false)
|
|||
|
||||
} // namespace OpenMesh
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
// Overload CGAL::clear function. TriMesh_ArrayKernel behaves
|
||||
// differently from other meshes. Calling clear does not affect the
|
||||
// number of vertices, edges, or faces in the mesh. To get actual
|
||||
// numbers it is necessary to first collect garbage. We add an
|
||||
// overlaod to get consistent behavior.
|
||||
template<typename K>
|
||||
void clear(OpenMesh::TriMesh_ArrayKernelT<K>& sm)
|
||||
{
|
||||
sm.clear();
|
||||
sm.garbage_collection(true, true, true);
|
||||
CGAL_postcondition(num_edges(sm) == 0);
|
||||
CGAL_postcondition(num_vertices(sm) == 0);
|
||||
CGAL_postcondition(num_faces(sm) == 0);
|
||||
}
|
||||
|
||||
|
||||
template<typename K>
|
||||
bool read_off(std::istream& is, OpenMesh::TriMesh_ArrayKernelT<K>& sm)
|
||||
{
|
||||
OpenMesh::IO::Options ropt;
|
||||
return OpenMesh::IO::read_mesh(sm, is, ".OFF", ropt, false);
|
||||
}
|
||||
|
||||
|
||||
template<typename K>
|
||||
bool write_off(std::ostream& os, OpenMesh::TriMesh_ArrayKernelT<K>& sm)
|
||||
{
|
||||
OpenMesh::IO::Options ropt;
|
||||
return OpenMesh::IO::write_mesh(sm, os, ".OFF", ropt);
|
||||
}
|
||||
|
||||
}
|
||||
#ifndef CGAL_NO_DEPRECATED_CODE
|
||||
#include <CGAL/boost/graph/backward_compatibility_functions.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ bool write_off(std::ostream& os,
|
|||
|
||||
*/
|
||||
template <typename FaceGraph>
|
||||
void write_off(const char* fname,
|
||||
bool write_off(const char* fname,
|
||||
const FaceGraph& g)
|
||||
{
|
||||
std::ofstream out(fname);
|
||||
|
|
|
|||
Loading…
Reference in New Issue