mirror of https://github.com/CGAL/cgal
Add generic property map for Polyhedron_3
This commit is contained in:
parent
4ff981de70
commit
5e5a3d9e97
|
|
@ -67,6 +67,7 @@ create_single_source_cgal_program( "transform_iterator.cpp" )
|
|||
|
||||
create_single_source_cgal_program( "copy_polyhedron.cpp" )
|
||||
|
||||
create_single_source_cgal_program( "polyhedron_generic_properties.cpp" )
|
||||
|
||||
if(OpenMesh_FOUND)
|
||||
target_link_libraries( copy_polyhedron ${OPENMESH_LIBRARIES} )
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/boost/graph/Euler_operations.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> K;
|
||||
typedef K::Point_3 Point_3;
|
||||
typedef CGAL::Polyhedron_3<K> Mesh;
|
||||
|
||||
int main()
|
||||
{
|
||||
Mesh m;
|
||||
CGAL::make_triangle(Point_3(0,0,0),Point_3(1,0,0),Point_3(1,1,0),m);
|
||||
|
||||
typedef boost::property_map<Mesh, boost::vertex_property_t<int> >::type VIM;
|
||||
VIM vim = add(boost::vertex_property_t<int>("index"), m);
|
||||
put(vim, *(vertices(m).first), 7812);
|
||||
std::cout << get(vim, *(vertices(m).first)) << std::endl;
|
||||
remove(vim,m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -30,6 +30,7 @@
|
|||
#include <CGAL/number_utils.h>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <CGAL/boost/graph/internal/Has_member_id.h>
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#define CGAL_HDS_PARAM_ template < class Traits, class Items, class Alloc> class HDS
|
||||
|
||||
|
|
@ -37,6 +38,55 @@ namespace CGAL {
|
|||
|
||||
namespace internal {
|
||||
|
||||
template <typename Poly, typename K, typename V>
|
||||
struct Dynamic_polyhedron_property_map {
|
||||
|
||||
typedef K key_type;
|
||||
typedef V value_type;
|
||||
typedef value_type& reference;
|
||||
typedef boost::read_write_property_map_tag category;
|
||||
|
||||
|
||||
|
||||
Dynamic_polyhedron_property_map(const V& default_value)
|
||||
: map_(new Map()), default_value(default_value)
|
||||
{}
|
||||
|
||||
void clear()
|
||||
{
|
||||
map_ = boost::shared_ptr<Map>(0);
|
||||
}
|
||||
|
||||
|
||||
friend value_type get(const Dynamic_polyhedron_property_map& m, const key_type& k)
|
||||
{
|
||||
typename Map::const_iterator it = m.map_->find(k);
|
||||
if(it == m.map_->end()){
|
||||
return m.default();
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
friend void put(Dynamic_polyhedron_property_map& m, const key_type& k, const value_type& v)
|
||||
{
|
||||
if(v != m.default()){
|
||||
(*(m.map_))[k] = v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const V& default() const
|
||||
{
|
||||
return default_value;
|
||||
}
|
||||
|
||||
|
||||
V default_value;
|
||||
typedef boost::unordered_map<K,V> Map;
|
||||
boost::shared_ptr<Map> map_;
|
||||
};
|
||||
|
||||
template<class Handle>
|
||||
class Polyhedron_index_map_external
|
||||
: public boost::put_get_helper<std::size_t&, Polyhedron_index_map_external<Handle> >
|
||||
|
|
@ -484,8 +534,37 @@ struct graph_has_property<CGAL::Polyhedron_3<Gt, I, HDS, A>, vertex_index_t>
|
|||
>
|
||||
{};
|
||||
|
||||
|
||||
template <class Gt, class I, CGAL_HDS_PARAM_, class A, typename T>
|
||||
struct property_map<CGAL::Polyhedron_3<Gt, I, HDS, A>, boost::vertex_property_t<T> >
|
||||
{
|
||||
typedef CGAL::Polyhedron_3<Gt, I, HDS, A> SM;
|
||||
typedef typename boost::graph_traits<SM>::vertex_descriptor vertex_descriptor;
|
||||
typedef CGAL::internal::Dynamic_polyhedron_property_map<SM,vertex_descriptor,T> type;
|
||||
typedef type const_type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template<class Gt, class I, CGAL_HDS_PARAM_, class A, class V>
|
||||
typename boost::property_map<Polyhedron_3<Gt, I, HDS, A>, boost::vertex_property_t<V> >::const_type
|
||||
add(boost::vertex_property_t<V> vprop, Polyhedron_3<Gt, I, HDS, A>& poly)
|
||||
{
|
||||
typedef CGAL::Polyhedron_3<Gt, I, HDS, A> SM;
|
||||
typedef typename boost::graph_traits<SM>::vertex_descriptor vertex_descriptor;
|
||||
return internal::Dynamic_polyhedron_property_map<SM,vertex_descriptor,V>(V());
|
||||
}
|
||||
|
||||
template <typename Pmap, class Gt, class I, CGAL_HDS_PARAM_, class A>
|
||||
void remove(Pmap pm, Polyhedron_3<Gt, I, HDS, A>&)
|
||||
{
|
||||
pm.clear();
|
||||
}
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#undef CGAL_HDS_PARAM_
|
||||
|
||||
|
|
|
|||
|
|
@ -87,19 +87,30 @@ public:
|
|||
|
||||
// overloads and specializations in the boost namespace
|
||||
namespace boost {
|
||||
#if 1
|
||||
|
||||
template <typename Point, typename T>
|
||||
struct property_map<CGAL::Surface_mesh<Point>, boost::vertex_property_t<T> >
|
||||
{
|
||||
typedef CGAL::Surface_mesh<Point> SM;
|
||||
typedef typename SM:: template Property_map<typename SM::vertex_index,T> type;
|
||||
typedef typename SM:: template Property_map<typename SM::Vertex_index,T> type;
|
||||
typedef type const_type;
|
||||
};
|
||||
|
||||
template <typename Point, typename T>
|
||||
struct property_map<CGAL::Surface_mesh<Point>, boost::face_property_t<T> >
|
||||
{
|
||||
typedef CGAL::Surface_mesh<Point> SM;
|
||||
typedef typename SM:: template Property_map<typename SM::Face_index,T> type;
|
||||
typedef type const_type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
template <typename Point, typename T>
|
||||
struct property_map<CGAL::Surface_mesh<Point>, boost::edge_property_t<T> >
|
||||
{
|
||||
typedef CGAL::Surface_mesh<Point> SM;
|
||||
typedef typename SM:: template Property_map<typename SM::Edge_index,T> type;
|
||||
typedef type const_type;
|
||||
};
|
||||
//
|
||||
// edge_weight
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in New Issue