add reserve to MutableFaceGraph

This commit is contained in:
Sébastien Loriot 2017-01-18 18:19:25 +01:00
parent a03a4e2d1a
commit 6926578b15
12 changed files with 55 additions and 160 deletions

View File

@ -27,6 +27,6 @@ Expression | returns | Description
`remove_face(f, g)` | `void` | Removes `f` from the graph.
`set_face(h, f, g)` | `void` | Sets the corresponding face of `h` to `f`.
`set_halfedge(f, h, g)` | `void` | Sets the corresponding halfedge of `f` to `h`.
`reserve(g, nv, ne, nf)`| `void` | Called to indicate the expected size of vertices (`nv`), edges (`ed`) and faces (`nf`)
*/
class MutableFaceGraph{};

View File

@ -398,6 +398,15 @@ remove_vertex(typename boost::graph_traits< Graph_with_descriptor_with_graph<Gra
remove_vertex(v.descriptor, *w.graph);
}
template<typename Graph>
void
reserve(Graph_with_descriptor_with_graph<Graph>& w,
typename boost::graph_traits< Graph_with_descriptor_with_graph<Graph> >::vertices_size_type nv,
typename boost::graph_traits< Graph_with_descriptor_with_graph<Graph> >::edges_size_type ne,
typename boost::graph_traits< Graph_with_descriptor_with_graph<Graph> >::faces_size_type nf)
{
reserve(*w.graph, nv, ne, nf);
}
template <class Graph>
typename boost::graph_traits< Graph_with_descriptor_with_graph<Graph> >::edge_descriptor

View File

@ -162,6 +162,8 @@ BOOST_concept(MutableFaceGraph,(G))
remove_face(f, g);
set_face(h, f, g);
set_halfedge(f, h, g);
int i;
reserve(g, i, i, i);
}
G g;
typename boost::graph_traits<G>::face_descriptor f;

View File

@ -504,7 +504,16 @@ set_halfedge(typename boost::graph_traits<OpenMesh::PolyMesh_ArrayKernelT<K> >::
sm.set_halfedge_handle(f, h);
}
template<typename K>
void
reserve(OpenMesh::PolyMesh_ArrayKernelT<K>& tm,
typename boost::graph_traits< OpenMesh::PolyMesh_ArrayKernelT<K> >::vertices_size_type nv,
typename boost::graph_traits< OpenMesh::PolyMesh_ArrayKernelT<K> >::edges_size_type ne,
typename boost::graph_traits< OpenMesh::PolyMesh_ArrayKernelT<K> >::faces_size_type nf)
{
tm.reserve(nv, ne, nf);
}
//
// FaceListGraph
//

View File

@ -388,6 +388,15 @@ add_edge(OpenMesh::TriMesh_ArrayKernelT<K>& sm)
boost::graph_traits<OpenMesh::TriMesh_ArrayKernelT<K> >::null_vertex() ), sm);
}
template<typename K>
void
reserve(OpenMesh::TriMesh_ArrayKernelT<K>& tm,
typename boost::graph_traits< OpenMesh::TriMesh_ArrayKernelT<K> >::vertices_size_type nv,
typename boost::graph_traits< OpenMesh::TriMesh_ArrayKernelT<K> >::edges_size_type ne,
typename boost::graph_traits< OpenMesh::TriMesh_ArrayKernelT<K> >::faces_size_type nf)
{
tm.reserve(nv, ne, nf);
}
//
// FaceGraph

View File

@ -25,7 +25,6 @@
#include <CGAL/boost/graph/iterator.h>
#include <CGAL/boost/graph/properties.h>
#include <CGAL/boost/graph/internal/Has_member_clear.h>
#include <CGAL/boost/graph/internal/Has_member_reserve.h>
namespace CGAL {
@ -726,22 +725,6 @@ clear_impl(FaceGraph& g)
}
}
template<typename FaceGraph, typename T1, typename T2, typename T3>
inline
typename boost::enable_if<Has_member_reserve<FaceGraph,T1, T2, T3>, void>::type
reserve_impl(FaceGraph& g, T1 nv, T2 ne, T3 nf)
{
g.reserve(nv, ne, nf);
}
template<typename FaceGraph, typename T1, typename T2, typename T3>
inline
typename boost::disable_if<Has_member_reserve<FaceGraph,T1,T2,T3>, void>::type
reserve_impl(FaceGraph&, T1, T2, T3)
{
}
}
/**
@ -768,31 +751,6 @@ void clear(FaceGraph& g)
CGAL_postcondition(num_faces(g) == 0);
}
/**
* \ingroup PkgBGLHelperFct
*
* If `FaceGraph` has a member function `reserve(nv,ne,nf)`, it will be called.
* Otherwise, nothing will be done.
*
* @tparam FaceGraph model of `MutableHalfedgeGraph` and `MutableFaceGraph`
*
* @param g the graph
* @param nv number of vertices
* @param ne number of edges
* @param nf number of faces
*
**/
template<typename FaceGraph>
void reserve(FaceGraph& g,
typename boost::graph_traits<FaceGraph>::vertices_size_type nv,
typename boost::graph_traits<FaceGraph>::edges_size_type ne,
typename boost::graph_traits<FaceGraph>::faces_size_type nf)
{
internal::reserve_impl(g,nv, ne, nf);
}
} // namespace CGAL
// Include "Euler_operations.h" at the end, because its implementation

View File

@ -1,45 +0,0 @@
// Copyright (c) 2016 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) : Sebastien Loriot
#ifndef CGAL_HAS_MEMBER_RESERVE_H
#define CGAL_HAS_MEMBER_RESERVE_H
namespace CGAL {
namespace internal {
template<class T, class I1, class I2, class I3>
class Has_member_reserve
{
private:
template<class U, U>
class check {};
template<class C>
static char f(check<void(C::*)(I1, I2, I3), &C::reserve>*);
template<class C>
static int f(...);
public:
static const bool value = (sizeof(f<T>(0)) == sizeof(char));
};
} // internal
} // CGAL
#endif /* CGAL_HAS_MEMBER_RESERVE_H */

View File

@ -77,8 +77,6 @@ create_single_source_cgal_program( "graph_concept_Gwdwg_Surface_mesh.cpp" )
create_single_source_cgal_program( "test_clear.cpp" )
create_single_source_cgal_program( "test_reserve.cpp" )
create_single_source_cgal_program( "test_helpers.cpp" )
create_single_source_cgal_program( "test_Has_member_clear.cpp" )

View File

@ -1,51 +0,0 @@
#include "test_Prefix.h"
#include <CGAL/boost/graph/helpers.h>
template<typename Mesh>
void test() {
Mesh m;
CGAL::reserve(m, 6, 12, 7);
}
struct MyGraph{};
struct MyGraphWithReserve{
bool OK;
MyGraphWithReserve()
: OK(false)
{}
void reserve(int,int,int)
{
OK=true;
}
};
namespace boost
{
template<>
struct graph_traits<MyGraph>
{
typedef int vertices_size_type;
typedef int edges_size_type;
typedef int faces_size_type;
};
template<>
struct graph_traits<MyGraphWithReserve>
: graph_traits<MyGraph>
{};
}
int main()
{
test<SM>();
test<Polyhedron>();
#if defined(CGAL_USE_OPENMESH)
test<OMesh>();
#endif
test<MyGraph>();
MyGraphWithReserve g;
assert(!g.OK);
CGAL::reserve(g,1,2,3);
assert(g.OK);
return 0;
}

View File

@ -173,6 +173,13 @@ and <code>src/</code> directories).
</li>
</ul>
<h3>CGAL and the Boost Graph Library (BGL)</h3>
<ul>
<li>
<b>Breaking change</b>: Addition of a free function <code>reserve()</code> in the concept <code>MutableFaceGraph</code>.
Models provided by CGAL have been updated.
</li>
</ul>
<!-- Arithmetic and Algebra -->
<!-- Combinatorial Algorithms -->
<!-- Geometry Kernels -->
@ -315,9 +322,6 @@ and <code>src/</code> directories).
Add class <code>CGAL::Graph_with_descriptor_with_graph</code> that wraps an existing
graph and provides a reference to the said graph to all of its descriptors.
</li>
<li>Add the helper function `CGAL::reserve(G,nv,ne,nf)` that enables to reserve
vertices, edges, and faces of a `MutableFaceGraph`.
</li>
</ul>
<h3>Cone Based Spanners</h3>
<ul>

View File

@ -444,7 +444,15 @@ num_faces(const CGAL::Polyhedron_3<Gt,I,HDS,A>& p)
return p.size_of_facets();
}
template<class Gt, class I, CGAL_HDS_PARAM_, class A>
void
reserve(CGAL::Polyhedron_3<Gt,I,HDS,A>& p,
typename boost::graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> >::vertices_size_type nv,
typename boost::graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> >::edges_size_type ne,
typename boost::graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> >::faces_size_type nf)
{
p.reserve(nv, 2*ne, nf);
}
template<class Gt, class I, CGAL_HDS_PARAM_, class A>
bool is_valid(const CGAL::Polyhedron_3<Gt,I,HDS,A>& p, bool verbose = false)

View File

@ -414,7 +414,7 @@ num_faces(const CGAL::Surface_mesh<P>& sm)
{
return sm.num_faces();
}
template <typename P>
Iterator_range<typename boost::graph_traits<CGAL::Surface_mesh<P> >::face_iterator>
faces(const CGAL::Surface_mesh<P>& sm)
@ -435,23 +435,17 @@ add_vertex(const typename boost::graph_traits<CGAL::Surface_mesh<P> >::vertex_pr
return sm.add_vertex(p);
}
/*
// MutableGraph
// add a vertex with a default constructed property
template <typename P>
typename boost::graph_traits<CGAL::Surface_mesh<P> >::vertex_descriptor
add_vertex(CGAL::Surface_mesh<P>& sm) {
return sm.add_vertex(typename boost::graph_traits<CGAL::Surface_mesh<P> >::vertex_property_type());
}
template <typename P>
template<typename P>
void
clear_vertex(typename boost::graph_traits<CGAL::Surface_mesh<P> >::vertex_descriptor,
CGAL::Surface_mesh<P>&) {
CGAL_assertion(false);
reserve(CGAL::Surface_mesh<P>& sm,
typename boost::graph_traits< CGAL::Surface_mesh<P> >::vertices_size_type nv,
typename boost::graph_traits< CGAL::Surface_mesh<P> >::edges_size_type ne,
typename boost::graph_traits< CGAL::Surface_mesh<P> >::faces_size_type nf)
{
sm.reserve(nv, ne, nf);
}
*/
template <typename P>
void