mirror of https://github.com/CGAL/cgal
Merge pull request #728 from bo0ts/BGL-document_copy_face_graph-pmoeller
Add BGL helper copy_face_graph()
This commit is contained in:
commit
ea1462d6da
|
|
@ -7,6 +7,7 @@ INPUT += ${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/Euler_operations.h \
|
|||
${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/helpers.h \
|
||||
${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/selection.h \
|
||||
${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/split_graph_into_polylines.h \
|
||||
${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/copy_face_graph.h \
|
||||
${CGAL_PACKAGE_INCLUDE_DIR}/CGAL/boost/graph/Dual.h
|
||||
EXAMPLE_PATH = ${CGAL_Surface_mesh_skeletonization_EXAMPLE_DIR} \
|
||||
${CGAL_BGL_EXAMPLE_DIR}
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ user might encounter.
|
|||
- `CGAL::make_hexahedron()`
|
||||
|
||||
- `CGAL::clear()`
|
||||
- `CGAL::copy_face_graph()`
|
||||
|
||||
## Iterators ##
|
||||
- `CGAL::Halfedge_around_source_iterator`
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ endif()
|
|||
find_package( OpenMesh QUIET )
|
||||
|
||||
if ( OpenMesh_FOUND )
|
||||
include( UseOpenMesh )
|
||||
include( UseOpenMesh )
|
||||
add_definitions( -DCGAL_USE_OPENMESH )
|
||||
else()
|
||||
message(STATUS "Examples that use OpenMesh will not be compiled.")
|
||||
endif()
|
||||
|
|
@ -64,10 +65,9 @@ create_single_source_cgal_program( "range.cpp" )
|
|||
|
||||
create_single_source_cgal_program( "transform_iterator.cpp" )
|
||||
|
||||
|
||||
create_single_source_cgal_program( "copy_polyhedron.cpp" )
|
||||
|
||||
if(OpenMesh_FOUND)
|
||||
create_single_source_cgal_program( "polyhedron_2_OpenMesh.cpp" )
|
||||
target_link_libraries( polyhedron_2_OpenMesh ${OPENMESH_LIBRARIES} )
|
||||
target_link_libraries( copy_polyhedron ${OPENMESH_LIBRARIES} )
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
||||
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
|
||||
|
||||
#if defined(CGAL_USE_OPENMESH)
|
||||
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
|
||||
#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
|
||||
|
||||
namespace OpenMesh { // auxiliary functions so OpenMesh Handles can be hashed
|
||||
inline std::size_t hash_value(const VertexHandle& i) { return i.idx(); }
|
||||
inline std::size_t hash_value(const HalfedgeHandle& i) { return i.idx(); }
|
||||
inline std::size_t hash_value(const FaceHandle& i) { return i.idx(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include <CGAL/boost/graph/copy_face_graph.h>
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
|
||||
typedef CGAL::Polyhedron_3<Kernel> Source;
|
||||
typedef boost::graph_traits<Source>::vertex_descriptor sm_vertex_descriptor;
|
||||
typedef boost::graph_traits<Source>::halfedge_descriptor sm_halfedge_descriptor;
|
||||
typedef boost::graph_traits<Source>::face_descriptor sm_face_descriptor;
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Other_kernel;
|
||||
typedef Other_kernel::Point_3 Point;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Source S;
|
||||
|
||||
std::ifstream in((argc>1)?argv[1]:"cube.off");
|
||||
in >> S;
|
||||
|
||||
// Note that the vertex_point property of the Source and Target1
|
||||
// come from different kernels.
|
||||
typedef CGAL::Surface_mesh<Point> Target1;
|
||||
Target1 T1;
|
||||
{
|
||||
CGAL::copy_face_graph(S, T1);
|
||||
std::ofstream out("sm.off");
|
||||
out << T1;
|
||||
}
|
||||
|
||||
#if defined(CGAL_USE_OPENMESH)
|
||||
typedef OpenMesh::PolyMesh_ArrayKernelT</* MyTraits*/> Target2;
|
||||
Target2 T2;
|
||||
{
|
||||
typedef boost::graph_traits<Target2>::vertex_descriptor tm_vertex_descriptor;
|
||||
typedef boost::graph_traits<Target2>::halfedge_descriptor tm_halfedge_descriptor;
|
||||
typedef boost::graph_traits<Target2>::face_descriptor tm_face_descriptor;
|
||||
|
||||
// Use an unordered_map to keep track of elements.
|
||||
boost::unordered_map<sm_vertex_descriptor, tm_vertex_descriptor> v2v;
|
||||
boost::unordered_map<sm_halfedge_descriptor, tm_halfedge_descriptor> h2h;
|
||||
boost::unordered_map<sm_face_descriptor, tm_face_descriptor> f2f;
|
||||
|
||||
CGAL::copy_face_graph(S, T2, std::inserter(v2v, v2v.end()),
|
||||
std::inserter(h2h, h2h.end()),
|
||||
std::inserter(f2f, f2f.end()));
|
||||
OpenMesh::IO::write_mesh(T2, "om.off");
|
||||
}
|
||||
#endif
|
||||
S.clear();
|
||||
{
|
||||
typedef boost::graph_traits<Target1>::vertex_descriptor source_vertex_descriptor;
|
||||
typedef boost::graph_traits<Target1>::halfedge_descriptor source_halfedge_descriptor;
|
||||
|
||||
typedef boost::graph_traits<Source>::vertex_descriptor tm_vertex_descriptor;
|
||||
typedef boost::graph_traits<Source>::halfedge_descriptor tm_halfedge_descriptor;
|
||||
|
||||
boost::unordered_map<source_vertex_descriptor, tm_vertex_descriptor> v2v;
|
||||
boost::unordered_map<source_halfedge_descriptor, tm_halfedge_descriptor> h2h;
|
||||
|
||||
CGAL::copy_face_graph(T1, S, std::inserter(v2v, v2v.end()), std::inserter(h2h, h2h.end()));
|
||||
std::ofstream out("reverse.off");
|
||||
out << T1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
||||
|
||||
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||
|
||||
#if 1
|
||||
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
|
||||
#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
|
||||
#else
|
||||
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
|
||||
#include <CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h>
|
||||
#endif
|
||||
|
||||
#include <CGAL/boost/graph/convert_surface_mesh.h>
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef CGAL::Polyhedron_3<Kernel> Source;
|
||||
|
||||
#if 1
|
||||
typedef OpenMesh::PolyMesh_ArrayKernelT</* MyTraits*/> Target;
|
||||
#else
|
||||
typedef OpenMesh::TriMesh_ArrayKernelT</* MyTraits*/> Target;
|
||||
#endif
|
||||
typedef boost::graph_traits<Source>::vertex_descriptor sm_vertex_descriptor;
|
||||
typedef boost::graph_traits<Target>::vertex_descriptor tm_vertex_descriptor;
|
||||
|
||||
typedef boost::graph_traits<Source>::halfedge_descriptor sm_halfedge_descriptor;
|
||||
typedef boost::graph_traits<Target>::halfedge_descriptor tm_halfedge_descriptor;
|
||||
|
||||
namespace OpenMesh {
|
||||
|
||||
inline std::size_t hash_value(const VertexHandle& i)
|
||||
{
|
||||
return i.idx();
|
||||
}
|
||||
|
||||
inline std::size_t hash_value(const HalfedgeHandle& i)
|
||||
{
|
||||
return i.idx();
|
||||
}
|
||||
|
||||
inline std::size_t hash_value(const FaceHandle& i)
|
||||
{
|
||||
return i.idx();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Source S;
|
||||
Target T;
|
||||
std::ifstream in((argc>1)?argv[1]:"cube.off");
|
||||
in >> S;
|
||||
|
||||
{
|
||||
boost::unordered_map<sm_vertex_descriptor, tm_vertex_descriptor> v2v;
|
||||
boost::unordered_map<sm_halfedge_descriptor, tm_halfedge_descriptor> h2h;
|
||||
|
||||
convert_surface_mesh(S,T,v2v,h2h);
|
||||
OpenMesh::IO::write_mesh(T, "om.off");
|
||||
}
|
||||
S.clear();
|
||||
{
|
||||
boost::unordered_map<tm_vertex_descriptor, sm_vertex_descriptor> v2v;
|
||||
boost::unordered_map<tm_halfedge_descriptor, sm_halfedge_descriptor> h2h;
|
||||
|
||||
convert_surface_mesh(T,S,v2v,h2h);
|
||||
std::ofstream out("reverse.off");
|
||||
out << S << std::endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
// Copyright (c) 2015 GeometryFactory (France). All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of the License,
|
||||
// or (at your option) any later version.
|
||||
//
|
||||
// Licensees holding a valid commercial license may use this file in
|
||||
// accordance with the commercial license agreement provided with the software.
|
||||
//
|
||||
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
// Author(s) : Andreas Fabri
|
||||
|
||||
#ifndef CGAL_BOOST_GRAPH_CONVERT_SURFACE_MESH_H
|
||||
#define CGAL_BOOST_GRAPH_CONVERT_SURFACE_MESH_H
|
||||
|
||||
#include <CGAL/boost/graph/Euler_operations.h>
|
||||
#include <CGAL/boost/graph/iterator.h>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <CGAL/boost/graph/helpers.h>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template <typename SourceMesh, typename TargetMesh, typename V2V, typename H2H>
|
||||
void convert_surface_mesh(const SourceMesh& sm, TargetMesh& tm, V2V& v2v, H2H& h2h)
|
||||
{
|
||||
typedef typename boost::graph_traits<SourceMesh>::vertex_descriptor sm_vertex_descriptor;
|
||||
typedef typename boost::graph_traits<TargetMesh>::vertex_descriptor tm_vertex_descriptor;
|
||||
|
||||
typedef typename boost::graph_traits<SourceMesh>::face_descriptor sm_face_descriptor;
|
||||
typedef typename boost::graph_traits<TargetMesh>::face_descriptor tm_face_descriptor;
|
||||
|
||||
typedef typename boost::graph_traits<SourceMesh>::halfedge_descriptor sm_halfedge_descriptor;
|
||||
typedef typename boost::graph_traits<TargetMesh>::halfedge_descriptor tm_halfedge_descriptor;
|
||||
|
||||
typedef typename boost::property_map<SourceMesh, vertex_point_t>::const_type sm_PMap;
|
||||
typedef typename boost::property_map<TargetMesh, vertex_point_t>::type tm_PMap;
|
||||
|
||||
sm_PMap sm_pmap = get(vertex_point, sm);
|
||||
tm_PMap tm_pmap = get(vertex_point, tm);
|
||||
|
||||
|
||||
BOOST_FOREACH(sm_vertex_descriptor svd, vertices(sm)){
|
||||
tm_vertex_descriptor tvd = add_vertex(tm);
|
||||
v2v.insert(std::make_pair(svd, tvd));
|
||||
put(tm_pmap, tvd, get(sm_pmap, svd));
|
||||
}
|
||||
|
||||
boost::unordered_map<sm_face_descriptor, tm_face_descriptor> f2f;
|
||||
BOOST_FOREACH(sm_face_descriptor sfd, faces(sm)){
|
||||
std::vector<tm_vertex_descriptor> tv;
|
||||
BOOST_FOREACH(sm_vertex_descriptor svd, vertices_around_face(halfedge(sfd,sm),sm)){
|
||||
tv.push_back(v2v.at(svd));
|
||||
}
|
||||
f2f[sfd] = Euler::add_face(tv,tm);
|
||||
}
|
||||
|
||||
BOOST_FOREACH(sm_face_descriptor sfd, faces(sm)){
|
||||
sm_halfedge_descriptor shd = halfedge(sfd,sm), done(shd);
|
||||
tm_halfedge_descriptor thd = halfedge(f2f[sfd],tm);
|
||||
tm_vertex_descriptor tvd = v2v.at(target(shd,sm));
|
||||
while(target(thd,tm) != tvd){
|
||||
thd = next(thd,tm);
|
||||
}
|
||||
do {
|
||||
h2h.insert(std::make_pair(shd, thd));
|
||||
|
||||
if (face(opposite(shd, sm), sm) == boost::graph_traits<SourceMesh>::null_face())
|
||||
h2h.insert(std::make_pair(opposite(shd, sm), opposite(thd, tm)));
|
||||
|
||||
shd = next(shd,sm);
|
||||
thd = next(thd,tm);
|
||||
}while(shd != done);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_BOOST_GRAPH_CONVERT_SURFACE_MESH_H
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
// Copyright (c) 2015 GeometryFactory (France). All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of the License,
|
||||
// or (at your option) any later version.
|
||||
//
|
||||
// Licensees holding a valid commercial license may use this file in
|
||||
// accordance with the commercial license agreement provided with the software.
|
||||
//
|
||||
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
// Author(s) : Andreas Fabri
|
||||
|
||||
#ifndef CGAL_BOOST_GRAPH_COPY_FACE_GRAPH_H
|
||||
#define CGAL_BOOST_GRAPH_COPY_FACE_GRAPH_H
|
||||
|
||||
#include <CGAL/config.h>
|
||||
#include <CGAL/iterator.h>
|
||||
#include <CGAL/Kernel_traits.h>
|
||||
#include <CGAL/Cartesian_converter.h>
|
||||
|
||||
#include <CGAL/boost/graph/Euler_operations.h>
|
||||
#include <CGAL/boost/graph/iterator.h>
|
||||
#include <CGAL/boost/graph/helpers.h>
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
/*!
|
||||
\ingroup PkgBGLHelperFct
|
||||
|
||||
copies a source model of `FaceListGraph` into a target model of a
|
||||
`FaceListGraph`. `OutputIterators` can be provided to produce a
|
||||
mapping between source and target elements. The target graph is not
|
||||
cleared.
|
||||
|
||||
\tparam SourceMesh a model of `FaceListGraph`
|
||||
\tparam TargetMesh a model of `FaceListGraph`
|
||||
\tparam V2V a model of `OutputIterator` accepting `std::pair<sm_vertex_descriptor, tm_vertex_descriptor>`
|
||||
\tparam H2H a model of `OutputIterator` accepting `std::pair<sm_halfedge_descriptor, tm_halfedge_descriptor>`
|
||||
\tparam F2F a model of `OutputIterator` accepting `std::pair<sm_face_descriptor, tm_face_descriptor>`
|
||||
|
||||
where the prefix `sm_` and `tm_` mean belonging to the source and
|
||||
target mesh respectively.
|
||||
|
||||
\param sm the source mesh
|
||||
\param tm the target mesh
|
||||
\param v2v pairs of `vertex_descriptors` from `sm` and corresponding `vertex_descriptors` in `tm` are added to `v2v`
|
||||
\param h2h pairs of `halfedge_descriptors` from `sm` and corresponding `halfedge_descriptors` in `tm` are added to `h2h`
|
||||
\param f2f pairs of `face_descriptors` from `sm` and corresponding `face_descriptors` in `tm` are added to `f2f`
|
||||
|
||||
This function assumes that both graphs have an internal property
|
||||
`vertex_point`. Values of that property are converted using
|
||||
`CGAL::Cartesian_converter<SourceKernel,
|
||||
TargetKernel>`. `SourceKernel` and `TargetKernel` are deduced using
|
||||
`CGAL::Kernel_traits`.
|
||||
|
||||
Other properties are not copied.
|
||||
*/
|
||||
#if defined(CGAL_CXX11) || defined(DOXYGEN_RUNNING) // Use template default arguments
|
||||
template <typename SourceMesh, typename TargetMesh,
|
||||
typename V2V = Emptyset_iterator,
|
||||
typename H2H = Emptyset_iterator,
|
||||
typename F2F = Emptyset_iterator>
|
||||
void copy_face_graph(const SourceMesh& sm, TargetMesh& tm,
|
||||
V2V v2v = V2V(), H2H h2h = H2H(), F2F f2f = F2F())
|
||||
#else // use the overloads
|
||||
template <typename SourceMesh, typename TargetMesh,
|
||||
typename V2V, typename H2H, typename F2F>
|
||||
void copy_face_graph(const SourceMesh& sm, TargetMesh& tm,
|
||||
V2V v2v, H2H h2h, F2F f2f)
|
||||
#endif
|
||||
{
|
||||
typedef typename boost::graph_traits<SourceMesh>::vertex_descriptor sm_vertex_descriptor;
|
||||
typedef typename boost::graph_traits<TargetMesh>::vertex_descriptor tm_vertex_descriptor;
|
||||
|
||||
typedef typename boost::graph_traits<SourceMesh>::face_descriptor sm_face_descriptor;
|
||||
typedef typename boost::graph_traits<TargetMesh>::face_descriptor tm_face_descriptor;
|
||||
|
||||
typedef typename boost::graph_traits<SourceMesh>::halfedge_descriptor sm_halfedge_descriptor;
|
||||
typedef typename boost::graph_traits<TargetMesh>::halfedge_descriptor tm_halfedge_descriptor;
|
||||
|
||||
typedef typename boost::property_map<SourceMesh, vertex_point_t>::const_type sm_PMap;
|
||||
typedef typename boost::property_map<TargetMesh, vertex_point_t>::type tm_PMap;
|
||||
|
||||
Cartesian_converter<typename Kernel_traits<typename boost::property_traits<sm_PMap>::value_type>::type,
|
||||
typename Kernel_traits<typename boost::property_traits<tm_PMap>::value_type>::type >
|
||||
conv;
|
||||
|
||||
sm_PMap sm_pmap = get(vertex_point, sm);
|
||||
tm_PMap tm_pmap = get(vertex_point, tm);
|
||||
|
||||
// internal f2f and v2v
|
||||
boost::unordered_map<sm_vertex_descriptor, tm_vertex_descriptor> v2v_;
|
||||
boost::unordered_map<sm_face_descriptor, tm_face_descriptor> f2f_;
|
||||
|
||||
BOOST_FOREACH(sm_vertex_descriptor svd, vertices(sm)){
|
||||
tm_vertex_descriptor tvd = add_vertex(tm);
|
||||
v2v_[svd] = tvd;
|
||||
*v2v++ = std::make_pair(svd, tvd);
|
||||
put(tm_pmap, tvd, conv(get(sm_pmap, svd)));
|
||||
}
|
||||
|
||||
BOOST_FOREACH(sm_face_descriptor sfd, faces(sm)){
|
||||
std::vector<tm_vertex_descriptor> tv;
|
||||
BOOST_FOREACH(sm_vertex_descriptor svd, vertices_around_face(halfedge(sfd,sm),sm)){
|
||||
tv.push_back(v2v_.at(svd));
|
||||
}
|
||||
tm_face_descriptor new_face = Euler::add_face(tv,tm);
|
||||
f2f_[sfd] = new_face;
|
||||
*f2f++ = std::make_pair(sfd, new_face);
|
||||
}
|
||||
|
||||
BOOST_FOREACH(sm_face_descriptor sfd, faces(sm)){
|
||||
sm_halfedge_descriptor shd = halfedge(sfd,sm), done(shd);
|
||||
tm_halfedge_descriptor thd = halfedge(f2f_[sfd],tm);
|
||||
tm_vertex_descriptor tvd = v2v_.at(target(shd,sm));
|
||||
while(target(thd,tm) != tvd){
|
||||
thd = next(thd,tm);
|
||||
}
|
||||
do {
|
||||
*h2h++ = std::make_pair(shd, thd);
|
||||
if (face(opposite(shd, sm), sm) == boost::graph_traits<SourceMesh>::null_face()){
|
||||
*h2h++ = std::make_pair(opposite(shd, sm), opposite(thd, tm));
|
||||
}
|
||||
shd = next(shd,sm);
|
||||
thd = next(thd,tm);
|
||||
}while(shd != done);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if !defined(CGAL_CXX11)
|
||||
template <typename SourceMesh, typename TargetMesh>
|
||||
void copy_face_graph(const SourceMesh& sm, TargetMesh& tm)
|
||||
{ copy_face_graph(sm, tm, Emptyset_iterator(), Emptyset_iterator(), Emptyset_iterator()); }
|
||||
|
||||
template <typename SourceMesh, typename TargetMesh, typename V2V>
|
||||
void copy_face_graph(const SourceMesh& sm, TargetMesh& tm, V2V v2v)
|
||||
{ copy_face_graph(sm, tm, v2v, Emptyset_iterator(), Emptyset_iterator()); }
|
||||
|
||||
template <typename SourceMesh, typename TargetMesh, typename V2V, typename H2H>
|
||||
void copy_face_graph(const SourceMesh& sm, TargetMesh& tm, V2V v2v, H2H h2h)
|
||||
{ copy_face_graph(sm, tm, v2v, h2h, Emptyset_iterator()); }
|
||||
#endif
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_BOOST_GRAPH_COPY_FACE_GRAPH_H
|
||||
|
|
@ -151,6 +151,15 @@ and <code>src/</code> directories).
|
|||
<!-- Interpolation -->
|
||||
<!-- Kinetic Data Structures -->
|
||||
<!-- Support Library -->
|
||||
<h3>CGAL and the Boost Graph Library (BGL)</h3>
|
||||
<ul>
|
||||
<li>
|
||||
Add a helper function <code>CGAL::copy_face_graph()</code> to
|
||||
copy a source FaceListGraph into another FaceListGraph of
|
||||
different type.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Visualization -->
|
||||
|
||||
<!-- end of the div for 4.9 -->
|
||||
|
|
|
|||
|
|
@ -1,92 +0,0 @@
|
|||
// Copyright (c) 2014 GeometryFactory (France). All rights reserved.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org).
|
||||
// You can redistribute it and/or modify it under the terms of the GNU
|
||||
// General Public License as published by the Free Software Foundation,
|
||||
// either version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// Licensees holding a valid commercial license may use this file in
|
||||
// accordance with the commercial license agreement provided with the software.
|
||||
//
|
||||
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
//
|
||||
// Author(s) : Sebastien Loriot
|
||||
//
|
||||
|
||||
|
||||
#ifndef CGAL_FACEGRAPH_POLYHEDRON_3_H
|
||||
#define CGAL_FACEGRAPH_POLYHEDRON_3_H 1
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
#include <CGAL/Modifier_base.h>
|
||||
#include <CGAL/Polyhedron_incremental_builder_3.h>
|
||||
#include <CGAL/Cartesian_converter.h>
|
||||
#include <CGAL/Kernel_traits.h>
|
||||
|
||||
#include <boost/graph/graph_traits.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template < class FaceGraph, class PointPMap, class HDS, bool clear_target_before = true >
|
||||
class FaceGraph_to_Polyhedron_3 : public Modifier_base<HDS> {
|
||||
FaceGraph& fg;
|
||||
PointPMap ppmap;
|
||||
public:
|
||||
typedef HDS Halfedge_data_structure;
|
||||
FaceGraph_to_Polyhedron_3(const FaceGraph& src, PointPMap map)
|
||||
: fg(const_cast<FaceGraph&>(src))
|
||||
, ppmap(map)
|
||||
{}
|
||||
void operator()( HDS& target);
|
||||
};
|
||||
|
||||
template < class FaceGraph, class PointPMap, class HDS, bool clear_target_before>
|
||||
void
|
||||
FaceGraph_to_Polyhedron_3<FaceGraph, PointPMap, HDS, clear_target_before>::
|
||||
operator()(HDS& tgt)
|
||||
{
|
||||
typedef typename boost::graph_traits<FaceGraph>::vertex_descriptor vertex_descriptor;
|
||||
typedef typename boost::graph_traits<FaceGraph>::face_descriptor face_descriptor;
|
||||
typedef typename boost::graph_traits<FaceGraph>::halfedge_descriptor halfedge_descriptor;
|
||||
|
||||
Cartesian_converter<
|
||||
typename Kernel_traits<typename boost::property_traits<PointPMap>::value_type>::Kernel,
|
||||
typename Kernel_traits<typename HDS::Vertex::Point>::Kernel
|
||||
> convert;
|
||||
|
||||
if ( clear_target_before )
|
||||
tgt.clear();
|
||||
|
||||
Polyhedron_incremental_builder_3<HDS> B(tgt);
|
||||
B.begin_surface( num_vertices(fg),
|
||||
num_faces(fg),
|
||||
num_halfedges(fg));
|
||||
std::map<vertex_descriptor, std::size_t> indices;
|
||||
std::size_t i=0;
|
||||
BOOST_FOREACH(vertex_descriptor vd, vertices(fg) )
|
||||
{
|
||||
B.add_vertex( convert( get(ppmap, vd) ) );
|
||||
indices[vd]=i++;
|
||||
}
|
||||
|
||||
BOOST_FOREACH(face_descriptor fd, faces(fg))
|
||||
{
|
||||
B.begin_facet();
|
||||
halfedge_descriptor hd=halfedge(fd, fg), first=hd;
|
||||
do {
|
||||
B.add_vertex_to_facet( indices[target(edge(hd,fg), fg)] );
|
||||
hd=next(hd,fg);;
|
||||
} while( hd != first);
|
||||
B.end_facet();
|
||||
}
|
||||
B.end_surface();
|
||||
}
|
||||
|
||||
} //namespace CGAL
|
||||
#endif // CGAL_FACEGRAPH_POLYHEDRON_3_H //
|
||||
// EOF //
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Polyhedron_items_with_id_3.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
||||
#include <CGAL/FaceGraph_to_Polyhedron_3.h>
|
||||
#include <CGAL/boost/graph/copy_face_graph.h>
|
||||
|
||||
#include <boost/graph/graph_traits.hpp>
|
||||
#include <boost/graph/adjacency_list.hpp>
|
||||
|
|
@ -385,7 +385,7 @@ public:
|
|||
const Traits& traits = Traits())
|
||||
: m_traits(traits), m_weight_calculator(m_tmesh)
|
||||
{
|
||||
init(tmesh, get(vertex_point, tmesh));
|
||||
init(tmesh);
|
||||
}
|
||||
#endif
|
||||
/// @} Constructor
|
||||
|
|
@ -827,18 +827,11 @@ private:
|
|||
}
|
||||
|
||||
/// Initialize some global data structures such as vertex id.
|
||||
void init(const TriangleMesh& tmesh,
|
||||
VertexPointMap vpm)
|
||||
void init(const TriangleMesh& tmesh)
|
||||
{
|
||||
// copy the input FaceGraph into a mTriangleMesh
|
||||
CGAL::FaceGraph_to_Polyhedron_3<TriangleMesh,
|
||||
VertexPointMap,
|
||||
typename mTriangleMesh::HalfedgeDS,
|
||||
false> modifier(tmesh, vpm);
|
||||
copy_face_graph(tmesh, m_tmesh);
|
||||
|
||||
m_tmesh.delegate(modifier);
|
||||
|
||||
// copy input vertices to keep correspondance
|
||||
// copy input vertices to keep correspondence
|
||||
typename boost::graph_traits<mTriangleMesh>::vertex_iterator vit=vertices(m_tmesh).first;
|
||||
BOOST_FOREACH(Input_vertex_descriptor vd, vertices(tmesh) )
|
||||
(*vit++)->vertices.push_back(vd);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Polyhedron_items_with_id_3.h>
|
||||
#include <CGAL/FaceGraph_to_Polyhedron_3.h>
|
||||
#ifdef CGAL_EIGEN3_ENABLED
|
||||
#include <CGAL/Eigen_solver_traits.h> // for sparse linear system solver
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue