Add partly-working adaptation of Surface_mesh to use the new Property map system

This commit is contained in:
JacksonCampolattaro 2023-05-17 16:49:46 +02:00
parent c9bd102fee
commit ac6fbf0467
10 changed files with 1634 additions and 2223 deletions

View File

@ -102,6 +102,9 @@ public:
// Construct the graph // Construct the graph
VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), get_property_map(CGAL::vertex_point, g)); VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), get_property_map(CGAL::vertex_point, g));
// Default constructors should only be used when VNM, VCM, etc. are defined as Constant_property_maps
// This fails in cases where get_parameter() succeeds
// even though internal_np::Lookup_named_param_def defaulted to Constant_property_map
VNM vnm = choose_parameter(get_parameter(np, internal_np::vertex_normal_map), VNM()); VNM vnm = choose_parameter(get_parameter(np, internal_np::vertex_normal_map), VNM());
VCM vcm = choose_parameter(get_parameter(np, internal_np::vertex_color_map), VCM()); VCM vcm = choose_parameter(get_parameter(np, internal_np::vertex_color_map), VCM());
VTM vtm = choose_parameter(get_parameter(np, internal_np::vertex_texture_map), VTM()); VTM vtm = choose_parameter(get_parameter(np, internal_np::vertex_texture_map), VTM());

View File

@ -277,9 +277,9 @@ public:
array->reserve(n); array->reserve(n);
} }
std::size_t size() const { return std::count(m_active_indices.begin(), m_active_indices.end(), true); } [[nodiscard]] std::size_t size() const { return std::count(m_active_indices.begin(), m_active_indices.end(), true); }
std::size_t capacity() const { return m_active_indices.size(); } [[nodiscard]] std::size_t capacity() const { return m_active_indices.size(); }
Index emplace_back() { Index emplace_back() {
@ -378,6 +378,20 @@ public:
return m_active_indices[i] = true; return m_active_indices[i] = true;
} }
std::vector<Index> active_list() const {
std::vector<Index> indices;
for (std::size_t i = 0; i < m_active_indices.size(); ++i)
if (m_active_indices[i]) indices.emplace_back(i);
return indices;
}
std::vector<Index> inactive_list() const {
std::vector<Index> indices;
for (std::size_t i = 0; i < m_active_indices.size(); ++i)
if (!m_active_indices[i]) indices.emplace_back(i);
return indices;
}
/*! /*!
* Adds the elements of the other container to this container for each property which is present in this container. * Adds the elements of the other container to this container for each property which is present in this container.
* *

View File

@ -86,6 +86,8 @@ void test_element_access() {
properties.erase(1); properties.erase(1);
assert(properties.size() == 2); assert(properties.size() == 2);
assert(properties.capacity() == 100); assert(properties.capacity() == 100);
assert(properties.active_list().size() == 2);
assert(properties.inactive_list().size() == 98);
// A newly emplaced element should take the empty slot // A newly emplaced element should take the empty slot
assert(properties.emplace() == 1); assert(properties.emplace() == 1);

View File

@ -108,24 +108,11 @@ bool read_OFF_with_or_without_fcolors(std::istream& is,
using parameters::is_default_parameter; using parameters::is_default_parameter;
using parameters::get_parameter; using parameters::get_parameter;
typename Mesh::template Property_map<Face_index, Color> fcm;
bool is_fcm_requested = !(is_default_parameter<CGAL_NP_CLASS, internal_np::face_color_map_t>::value); bool is_fcm_requested = !(is_default_parameter<CGAL_NP_CLASS, internal_np::face_color_map_t>::value);
if(!is_fcm_requested && scanner.has_colors()) if (is_fcm_requested || scanner.has_colors()) {
{ auto [fcm, created] = sm.template property_map<Face_index, Color>("f:color");
bool created; return CGAL::IO::internal::read_OFF_BGL(is, sm, np.face_color_map(fcm));
std::tie(fcm, created) = sm.template add_property_map<Face_index, Color>("f:color", Color(0,0,0)); } else {
CGAL_assertion(created);
is_fcm_requested = true;
}
if(is_fcm_requested)
{
FCM fcolors = choose_parameter(get_parameter(np, internal_np::face_color_map), fcm);
return CGAL::IO::internal::read_OFF_BGL(is, sm, np.face_color_map(fcolors));
}
else
{
return CGAL::IO::internal::read_OFF_BGL(is, sm, np); return CGAL::IO::internal::read_OFF_BGL(is, sm, np);
} }
} }
@ -147,24 +134,11 @@ bool read_OFF_with_or_without_vtextures(std::istream& is,
using parameters::is_default_parameter; using parameters::is_default_parameter;
using parameters::get_parameter; using parameters::get_parameter;
typename Mesh::template Property_map<Vertex_index, Texture> vtm;
bool is_vtm_requested = !(is_default_parameter<CGAL_NP_CLASS, internal_np::vertex_texture_map_t>::value); bool is_vtm_requested = !(is_default_parameter<CGAL_NP_CLASS, internal_np::vertex_texture_map_t>::value);
if(!is_vtm_requested && scanner.has_textures()) if (is_vtm_requested || scanner.has_textures()) {
{ auto [vtm, created] = sm.template property_map<Vertex_index, Texture>("v:texcoord");
bool created; return read_OFF_with_or_without_fcolors(is, sm, scanner, np.vertex_texture_map(vtm));
std::tie(vtm, created) = sm.template add_property_map<Vertex_index, Texture>("v:texcoord"); } else {
CGAL_assertion(created);
is_vtm_requested = true;
}
if(is_vtm_requested)
{
VTM vtextures = choose_parameter(get_parameter(np, internal_np::vertex_texture_map), vtm);
return read_OFF_with_or_without_fcolors(is, sm, scanner, np.vertex_texture_map(vtextures));
}
else
{
return read_OFF_with_or_without_fcolors(is, sm, scanner, np); return read_OFF_with_or_without_fcolors(is, sm, scanner, np);
} }
} }
@ -185,24 +159,11 @@ bool read_OFF_with_or_without_vcolors(std::istream& is,
using parameters::is_default_parameter; using parameters::is_default_parameter;
using parameters::get_parameter; using parameters::get_parameter;
typename Mesh::template Property_map<Vertex_index, Color> vcm; bool is_vcm_requested = !(is_default_parameter<CGAL_NP_CLASS, internal_np::vertex_color_map_t>::value);
if (is_vcm_requested || scanner.has_colors()) {
bool is_vcm_requested = !(is_default_parameter<CGAL_NP_CLASS, internal_np::vertex_color_map_t>::value); auto [vcm, created] = sm.template property_map<Vertex_index, Color>("v:color");
if(!is_vcm_requested && scanner.has_colors()) return read_OFF_with_or_without_vtextures(is, sm, scanner, np.vertex_color_map(vcm));
{ } else {
bool created;
std::tie(vcm, created) = sm.template add_property_map<Vertex_index, Color>("v:color", Color(0,0,0));
CGAL_assertion(created);
is_vcm_requested = true;
}
if(is_vcm_requested)
{
VCM vcolors = choose_parameter(get_parameter(np, internal_np::vertex_color_map), vcm);
return read_OFF_with_or_without_vtextures(is, sm, scanner, np.vertex_color_map(vcolors));
}
else
{
return read_OFF_with_or_without_vtextures(is, sm, scanner, np); return read_OFF_with_or_without_vtextures(is, sm, scanner, np);
} }
} }
@ -224,24 +185,11 @@ bool read_OFF_with_or_without_vnormals(std::istream& is,
using parameters::is_default_parameter; using parameters::is_default_parameter;
using parameters::get_parameter; using parameters::get_parameter;
typename Mesh::template Property_map<Vertex_index, Normal> vnm;
bool is_vnm_requested = !(is_default_parameter<CGAL_NP_CLASS, internal_np::vertex_normal_map_t>::value); bool is_vnm_requested = !(is_default_parameter<CGAL_NP_CLASS, internal_np::vertex_normal_map_t>::value);
if(!is_vnm_requested && scanner.has_normals()) if (is_vnm_requested || scanner.has_normals()) {
{ auto [vnm, created] = sm.template property_map<Vertex_index, Normal>("v:normal");
bool created; return read_OFF_with_or_without_vcolors(is, sm, scanner, np.vertex_normal_map(vnm));
std::tie(vnm, created) = sm.template add_property_map<Vertex_index, Normal>("v:normal"); } else {
CGAL_assertion(created);
is_vnm_requested = true;
}
if(is_vnm_requested)
{
VNM vnormals = choose_parameter(get_parameter(np, internal_np::vertex_normal_map), vnm);
return read_OFF_with_or_without_vcolors(is, sm, scanner, np.vertex_normal_map(vnormals));
}
else
{
return read_OFF_with_or_without_vcolors(is, sm, scanner, np); return read_OFF_with_or_without_vcolors(is, sm, scanner, np);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -429,7 +429,7 @@ template <typename P>
typename boost::graph_traits<CGAL::Surface_mesh<P> >::faces_size_type typename boost::graph_traits<CGAL::Surface_mesh<P> >::faces_size_type
num_faces(const CGAL::Surface_mesh<P>& sm) num_faces(const CGAL::Surface_mesh<P>& sm)
{ {
return sm.num_faces(); return sm.number_of_faces();
} }
template <typename P> template <typename P>

View File

@ -19,7 +19,7 @@
#include <CGAL/assertions.h> #include <CGAL/assertions.h>
#include <CGAL/Surface_mesh.h> #include <CGAL/Surface_mesh.h>
#include <CGAL/Surface_mesh/Properties.h> #include <CGAL/Properties.h>
#include <CGAL/Kernel_traits.h> #include <CGAL/Kernel_traits.h>
#include <CGAL/squared_distance_3.h> #include <CGAL/squared_distance_3.h>
#include <CGAL/number_utils.h> #include <CGAL/number_utils.h>
@ -31,58 +31,51 @@
namespace CGAL { namespace CGAL {
template <typename Point> template <typename Point>
class SM_edge_weight_pmap class SM_edge_weight_pmap {
{
typedef CGAL::Surface_mesh<Point> SM; typedef CGAL::Surface_mesh<Point> SM;
public: public:
typedef boost::readable_property_map_tag category; typedef boost::readable_property_map_tag category;
typedef typename CGAL::Kernel_traits<Point>::type::FT value_type; typedef typename CGAL::Kernel_traits<Point>::type::FT value_type;
typedef value_type reference; typedef value_type reference;
typedef typename SM::Edge_index key_type; typedef typename SM::Edge_index key_type;
SM_edge_weight_pmap(const CGAL::Surface_mesh<Point>& sm) SM_edge_weight_pmap(const CGAL::Surface_mesh<Point>& sm)
: pm_(sm. template property_map< : pm_(sm.template property_map<
typename SM::Vertex_index, typename SM::Vertex_index,
typename SM::Point >("v:point").first), typename SM::Point>("v:point").first),
sm_(sm) sm_(sm) {}
{}
value_type operator[](const key_type& e) const value_type operator[](const key_type& e) const {
{
return approximate_sqrt(CGAL::squared_distance(pm_[source(e, sm_)], return approximate_sqrt(CGAL::squared_distance(pm_[source(e, sm_)],
pm_[target(e, sm_)])); pm_[target(e, sm_)]));
} }
friend inline friend inline
value_type get(const SM_edge_weight_pmap& m, const key_type& k) value_type get(const SM_edge_weight_pmap& m, const key_type& k) {
{
return m[k]; return m[k];
} }
private: private:
typename SM::template Property_map< typename SM::Vertex_index, typename SM::template Property_map<typename SM::Vertex_index,
typename SM::Point > pm_; typename SM::Point> pm_;
const SM& sm_; const SM& sm_;
}; };
template <typename K, typename VEF> template <typename K, typename VEF>
class SM_index_pmap class SM_index_pmap {
{
public: public:
typedef boost::readable_property_map_tag category; typedef boost::readable_property_map_tag category;
typedef boost::uint32_t value_type; typedef boost::uint32_t value_type;
typedef boost::uint32_t reference; typedef boost::uint32_t reference;
typedef VEF key_type; typedef VEF key_type;
value_type operator[](const key_type& vd) const value_type operator[](const key_type& vd) const {
{
return vd; return vd;
} }
friend inline friend inline
value_type get(const SM_index_pmap& m, const key_type& k) value_type get(const SM_index_pmap& m, const key_type& k) {
{
return m[k]; return m[k];
} }
}; };
@ -95,31 +88,31 @@ namespace boost {
// //
template <typename Point> template <typename Point>
struct property_map<CGAL::Surface_mesh<Point>, boost::edge_weight_t > struct property_map<CGAL::Surface_mesh<Point>, boost::edge_weight_t> {
{
typedef CGAL::SM_edge_weight_pmap<Point> type; typedef CGAL::SM_edge_weight_pmap<Point> type;
typedef CGAL::SM_edge_weight_pmap<Point> const_type; typedef CGAL::SM_edge_weight_pmap<Point> const_type;
}; };
} }
namespace CGAL{ namespace CGAL {
template <typename Point> template <typename Point>
typename boost::property_map<CGAL::Surface_mesh<Point>, boost::edge_weight_t>::const_type typename boost::property_map<CGAL::Surface_mesh<Point>, boost::edge_weight_t>::const_type
get(boost::edge_weight_t, const CGAL::Surface_mesh<Point>& sm) get(boost::edge_weight_t, const CGAL::Surface_mesh<Point>& sm) {
{
return CGAL::SM_edge_weight_pmap<Point>(sm); return CGAL::SM_edge_weight_pmap<Point>(sm);
} }
// forward declarations, see <CGAL/Surface_mesh.h> // forward declarations, see <CGAL/Surface_mesh.h>
class SM_Vertex_index; class SM_Vertex_index;
class SM_Edge_index; class SM_Edge_index;
class SM_Halfedge_index; class SM_Halfedge_index;
class SM_Face_index; class SM_Face_index;
template <typename Point> template <typename Point>
typename CGAL::Kernel_traits<Point>::type::FT typename CGAL::Kernel_traits<Point>::type::FT
get(boost::edge_weight_t, const CGAL::Surface_mesh<Point>& sm, get(boost::edge_weight_t, const CGAL::Surface_mesh<Point>& sm,
const SM_Edge_index& e) const SM_Edge_index& e) {
{
return CGAL::SM_edge_weight_pmap<Point>(sm)[e]; return CGAL::SM_edge_weight_pmap<Point>(sm)[e];
} }
} }
@ -127,129 +120,139 @@ get(boost::edge_weight_t, const CGAL::Surface_mesh<Point>& sm,
// vertex_index // vertex_index
// //
namespace boost{ namespace boost {
template <typename Point> template <typename Point>
struct property_map<CGAL::Surface_mesh<Point>, boost::vertex_index_t > struct property_map<CGAL::Surface_mesh<Point>, boost::vertex_index_t> {
{
typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::vertex_descriptor> type; typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::vertex_descriptor> type;
typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::vertex_descriptor> const_type; typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::vertex_descriptor> const_type;
}; };
} }
namespace CGAL{ namespace CGAL {
template <typename Point> template <typename Point>
CGAL::SM_index_pmap<Point, SM_Vertex_index> CGAL::SM_index_pmap<Point, SM_Vertex_index>
get(const boost::vertex_index_t&, const CGAL::Surface_mesh<Point>&) get(const boost::vertex_index_t&, const CGAL::Surface_mesh<Point>&) {
{
return CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::vertex_descriptor>(); return CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::vertex_descriptor>();
} }
} }
// //
// face_index // face_index
// //
namespace boost{ namespace boost {
template <typename Point> template <typename Point>
struct property_map<CGAL::Surface_mesh<Point>, boost::face_index_t > struct property_map<CGAL::Surface_mesh<Point>, boost::face_index_t> {
{
typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::face_descriptor> type; typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::face_descriptor> type;
typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::face_descriptor> const_type; typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::face_descriptor> const_type;
}; };
} }
namespace CGAL{ namespace CGAL {
template <typename Point> template <typename Point>
CGAL::SM_index_pmap<Point, SM_Face_index> CGAL::SM_index_pmap<Point, SM_Face_index>
get(const boost::face_index_t&, const CGAL::Surface_mesh<Point>&) get(const boost::face_index_t&, const CGAL::Surface_mesh<Point>&) {
{
return CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::face_descriptor>(); return CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::face_descriptor>();
} }
} }
//
// Face color
// todo
namespace boost {
template <typename Point>
struct property_map<CGAL::Surface_mesh<Point>, CGAL::internal_np::face_color_map_t> {
typedef typename CGAL::Surface_mesh<Point>::template Property_map<CGAL::SM_Face_index, CGAL::IO::Color> type;
typedef typename CGAL::Surface_mesh<Point>::template Property_map<CGAL::SM_Face_index, CGAL::IO::Color> const_type;
};
}
namespace CGAL {
template <typename Point>
typename CGAL::Surface_mesh<Point>::template Property_map<CGAL::SM_Face_index, CGAL::IO::Color>
get(const CGAL::internal_np::face_color_map_t&, const CGAL::Surface_mesh<Point>&sm) {
return sm.template property_map<CGAL::SM_Face_index, CGAL::IO::Color>("f:color").first;
}
}
// //
// edge_index // edge_index
// //
namespace boost{ namespace boost {
template <typename Point> template <typename Point>
struct property_map<CGAL::Surface_mesh<Point>, boost::edge_index_t > struct property_map<CGAL::Surface_mesh<Point>, boost::edge_index_t> {
{
typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::edge_descriptor> type; typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::edge_descriptor> type;
typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::edge_descriptor> const_type; typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::edge_descriptor> const_type;
}; };
} }
namespace CGAL{ namespace CGAL {
template <typename Point> template <typename Point>
CGAL::SM_index_pmap<Point, SM_Edge_index> CGAL::SM_index_pmap<Point, SM_Edge_index>
get(const boost::edge_index_t&, const CGAL::Surface_mesh<Point>&) get(const boost::edge_index_t&, const CGAL::Surface_mesh<Point>&) {
{
return CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::edge_descriptor>(); return CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::edge_descriptor>();
} }
} }
// //
// halfedge_index // halfedge_index
// //
namespace boost{ namespace boost {
template <typename Point> template <typename Point>
struct property_map<CGAL::Surface_mesh<Point>, boost::halfedge_index_t > struct property_map<CGAL::Surface_mesh<Point>, boost::halfedge_index_t> {
{
typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::halfedge_descriptor> type; typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::halfedge_descriptor> type;
typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::halfedge_descriptor> const_type; typedef CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::halfedge_descriptor> const_type;
}; };
} }
namespace CGAL{ namespace CGAL {
template <typename Point> template <typename Point>
CGAL::SM_index_pmap<Point, SM_Halfedge_index> CGAL::SM_index_pmap<Point, SM_Halfedge_index>
get(const boost::halfedge_index_t&, const CGAL::Surface_mesh<Point>&) get(const boost::halfedge_index_t&, const CGAL::Surface_mesh<Point>&) {
{
return CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::halfedge_descriptor>(); return CGAL::SM_index_pmap<Point, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::halfedge_descriptor>();
} }
} }
// //
// vertex_point // vertex_point
// //
namespace boost{ namespace boost {
template<typename P> template <typename P>
struct property_map<CGAL::Surface_mesh<P>, CGAL::vertex_point_t > struct property_map<CGAL::Surface_mesh<P>, CGAL::vertex_point_t> {
{
typedef CGAL::Surface_mesh<P> SM; typedef CGAL::Surface_mesh<P> SM;
typedef typename typedef typename
SM::template Property_map< typename SM::Vertex_index, SM::template Property_map<typename SM::Vertex_index,
P P
> type; > type;
typedef type const_type; typedef type const_type;
}; };
} }
namespace CGAL{ namespace CGAL {
namespace internal { namespace internal {
template <typename Point> template <typename Point>
struct Get_vertex_point_map_for_Surface_mesh_return_type { struct Get_vertex_point_map_for_Surface_mesh_return_type {
typedef typename boost::property_map typedef typename boost::property_map
< <
CGAL::Surface_mesh<Point>, CGAL::Surface_mesh<Point>,
CGAL::vertex_point_t CGAL::vertex_point_t
>::const_type type; >::const_type type;
}; };
} // end namespace internal } // end namespace internal
template<typename Point> template <typename Point>
typename typename
boost::lazy_disable_if boost::lazy_disable_if
< <
boost::is_const<Point>, boost::is_const<Point>,
internal::Get_vertex_point_map_for_Surface_mesh_return_type<Point> internal::Get_vertex_point_map_for_Surface_mesh_return_type<Point>
>::type >::type
get(CGAL::vertex_point_t, const CGAL::Surface_mesh<Point>& g) { get(CGAL::vertex_point_t, const CGAL::Surface_mesh<Point>& g) {
return g.points(); return g.points();
} }
namespace internal { namespace internal {
template <typename Point> template <typename Point>
struct Get_graph_traits_of_SM { struct Get_graph_traits_of_SM {
typedef boost::graph_traits< CGAL::Surface_mesh<Point> > type; typedef boost::graph_traits<CGAL::Surface_mesh<Point> > type;
}; };
} // end namespace internal } // end namespace internal
// get for intrinsic properties // get for intrinsic properties
@ -260,88 +263,98 @@ namespace internal {
const TYPE& x) \ const TYPE& x) \
{ return get(get(p, sm), x); } \ { return get(get(p, sm), x); } \
CGAL_SM_INTRINSIC_PROPERTY(boost::uint32_t, boost::vertex_index_t, CGAL_SM_INTRINSIC_PROPERTY(boost::uint32_t, boost::vertex_index_t,
SM_Vertex_index) SM_Vertex_index)
CGAL_SM_INTRINSIC_PROPERTY(boost::uint32_t, boost::edge_index_t, CGAL_SM_INTRINSIC_PROPERTY(boost::uint32_t, boost::edge_index_t,
SM_Edge_index) SM_Edge_index)
CGAL_SM_INTRINSIC_PROPERTY(boost::uint32_t, boost::halfedge_index_t, CGAL_SM_INTRINSIC_PROPERTY(boost::uint32_t, boost::halfedge_index_t,
SM_Halfedge_index) SM_Halfedge_index)
CGAL_SM_INTRINSIC_PROPERTY(boost::uint32_t, boost::face_index_t, CGAL_SM_INTRINSIC_PROPERTY(boost::uint32_t, boost::face_index_t,
SM_Face_index) SM_Face_index)
CGAL_SM_INTRINSIC_PROPERTY(Point&, CGAL::vertex_point_t, SM_Vertex_index)
CGAL_SM_INTRINSIC_PROPERTY(Point &, CGAL::vertex_point_t, SM_Vertex_index)
#undef CGAL_SM_INTRINSIC_PROPERTY #undef CGAL_SM_INTRINSIC_PROPERTY
// put for intrinsic properties // put for intrinsic properties
// only available for vertex_point // only available for vertex_point
template<typename Point> template <typename Point>
void void
put(CGAL::vertex_point_t p, const CGAL::Surface_mesh<Point>& g, put(CGAL::vertex_point_t p, const CGAL::Surface_mesh<Point>& g,
typename boost::graph_traits< CGAL::Surface_mesh<Point> >::vertex_descriptor x, typename boost::graph_traits<CGAL::Surface_mesh<Point> >::vertex_descriptor x,
const Point& point) { const Point& point) {
typedef CGAL::Surface_mesh<Point> SM; typedef CGAL::Surface_mesh<Point> SM;
CGAL_assertion(g.is_valid(x)); CGAL_assertion(g.is_valid(x));
typename SM::template Property_map< typename boost::graph_traits<SM>::vertex_descriptor, typename SM::template Property_map<typename boost::graph_traits<SM>::vertex_descriptor,
Point> prop = get(p, g); Point> prop = get(p, g);
prop[x] = point; prop[x] = point;
} }
template<typename Point> template <typename Point>
struct graph_has_property<CGAL::Surface_mesh<Point>, boost::vertex_index_t> struct graph_has_property<CGAL::Surface_mesh<Point>, boost::vertex_index_t>
: CGAL::Tag_true {}; : CGAL::Tag_true {
template<typename Point> };
template <typename Point>
struct graph_has_property<CGAL::Surface_mesh<Point>, boost::edge_index_t> struct graph_has_property<CGAL::Surface_mesh<Point>, boost::edge_index_t>
: CGAL::Tag_true {}; : CGAL::Tag_true {
template<typename Point> };
template <typename Point>
struct graph_has_property<CGAL::Surface_mesh<Point>, boost::halfedge_index_t> struct graph_has_property<CGAL::Surface_mesh<Point>, boost::halfedge_index_t>
: CGAL::Tag_true {}; : CGAL::Tag_true {
template<typename Point> };
template <typename Point>
struct graph_has_property<CGAL::Surface_mesh<Point>, boost::face_index_t> struct graph_has_property<CGAL::Surface_mesh<Point>, boost::face_index_t>
: CGAL::Tag_true {}; : CGAL::Tag_true {
template<typename Point> };
template <typename Point>
struct graph_has_property<CGAL::Surface_mesh<Point>, CGAL::vertex_point_t> struct graph_has_property<CGAL::Surface_mesh<Point>, CGAL::vertex_point_t>
: CGAL::Tag_true {}; : CGAL::Tag_true {
template<typename Point> };
template <typename Point>
struct graph_has_property<CGAL::Surface_mesh<Point>, boost::edge_weight_t> struct graph_has_property<CGAL::Surface_mesh<Point>, boost::edge_weight_t>
: CGAL::Tag_true {}; : CGAL::Tag_true {
};
template <typename Point>
struct graph_has_property<CGAL::Surface_mesh<Point>, CGAL::internal_np::face_color_map_t>
: CGAL::Tag_true {
};
} // CGAL } // CGAL
// dynamic properties // dynamic properties
namespace boost namespace boost {
{
template <typename Point, typename T> template <typename Point, typename T>
struct property_map<CGAL::Surface_mesh<Point>, CGAL::dynamic_vertex_property_t<T> > struct property_map<CGAL::Surface_mesh<Point>, CGAL::dynamic_vertex_property_t<T> > {
{
typedef CGAL::Surface_mesh<Point> SM; typedef CGAL::Surface_mesh<Point> SM;
typedef typename SM:: template Property_map<typename SM::Vertex_index,T> SMPM; typedef typename SM::template Property_map<typename SM::Vertex_index, T> SMPM;
typedef CGAL::internal::Dynamic<SM, SMPM> type; typedef CGAL::internal::Dynamic<SM, SMPM> type;
typedef CGAL::internal::Dynamic_with_index<typename SM::Vertex_index, T> const_type; typedef CGAL::internal::Dynamic_with_index<typename SM::Vertex_index, T> const_type;
}; };
template <typename Point, typename T> template <typename Point, typename T>
struct property_map<CGAL::Surface_mesh<Point>, CGAL::dynamic_face_property_t<T> > struct property_map<CGAL::Surface_mesh<Point>, CGAL::dynamic_face_property_t<T> > {
{
typedef CGAL::Surface_mesh<Point> SM; typedef CGAL::Surface_mesh<Point> SM;
typedef typename SM:: template Property_map<typename SM::Face_index,T> SMPM; typedef typename SM::template Property_map<typename SM::Face_index, T> SMPM;
typedef CGAL::internal::Dynamic<SM, SMPM> type; typedef CGAL::internal::Dynamic<SM, SMPM> type;
typedef CGAL::internal::Dynamic_with_index<typename SM::Face_index, T> const_type; typedef CGAL::internal::Dynamic_with_index<typename SM::Face_index, T> const_type;
}; };
template <typename Point, typename T> template <typename Point, typename T>
struct property_map<CGAL::Surface_mesh<Point>, CGAL::dynamic_halfedge_property_t<T> > struct property_map<CGAL::Surface_mesh<Point>, CGAL::dynamic_halfedge_property_t<T> > {
{
typedef CGAL::Surface_mesh<Point> SM; typedef CGAL::Surface_mesh<Point> SM;
typedef typename SM:: template Property_map<typename SM::Halfedge_index,T> SMPM; typedef typename SM::template Property_map<typename SM::Halfedge_index, T> SMPM;
typedef CGAL::internal::Dynamic<SM, SMPM> type; typedef CGAL::internal::Dynamic<SM, SMPM> type;
typedef CGAL::internal::Dynamic_with_index<typename SM::Halfedge_index, T> const_type; typedef CGAL::internal::Dynamic_with_index<typename SM::Halfedge_index, T> const_type;
}; };
template <typename Point, typename T> template <typename Point, typename T>
struct property_map<CGAL::Surface_mesh<Point>, CGAL::dynamic_edge_property_t<T> > struct property_map<CGAL::Surface_mesh<Point>, CGAL::dynamic_edge_property_t<T> > {
{
typedef CGAL::Surface_mesh<Point> SM; typedef CGAL::Surface_mesh<Point> SM;
typedef typename SM:: template Property_map<typename SM::Edge_index,T> SMPM; typedef typename SM::template Property_map<typename SM::Edge_index, T> SMPM;
typedef CGAL::internal::Dynamic<SM, SMPM> type; typedef CGAL::internal::Dynamic<SM, SMPM> type;
typedef CGAL::internal::Dynamic_with_index<typename SM::Edge_index, T> const_type; typedef CGAL::internal::Dynamic_with_index<typename SM::Edge_index, T> const_type;
}; };
@ -353,80 +366,75 @@ namespace CGAL {
// get functions for dynamic properties of mutable Surface_mesh // get functions for dynamic properties of mutable Surface_mesh
template <typename Point, typename T> template <typename Point, typename T>
typename boost::property_map<CGAL::Surface_mesh<Point>, dynamic_vertex_property_t<T> >::type typename boost::property_map<CGAL::Surface_mesh<Point>, dynamic_vertex_property_t<T> >::type
get(dynamic_vertex_property_t<T>, Surface_mesh<Point>& sm) get(dynamic_vertex_property_t<T>, Surface_mesh<Point>& sm) {
{
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_vertex_property_t<T> >::SMPM SMPM; typedef typename boost::property_map<Surface_mesh<Point>, dynamic_vertex_property_t<T> >::SMPM SMPM;
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_vertex_property_t<T> >::type DPM; typedef typename boost::property_map<Surface_mesh<Point>, dynamic_vertex_property_t<T> >::type DPM;
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Vertex_index, T>(std::string()).first)); return DPM(sm, new SMPM(
sm.template add_property_map<typename Surface_mesh<Point>::Vertex_index, T>(std::string()).first));
} }
template <typename Point, typename T> template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::type typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::type
get(dynamic_face_property_t<T>, Surface_mesh<Point>& sm) get(dynamic_face_property_t<T>, Surface_mesh<Point>& sm) {
{
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::SMPM SMPM; typedef typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::SMPM SMPM;
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::type DPM; typedef typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::type DPM;
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Face_index, T>(std::string()).first)); return DPM(sm,
new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Face_index, T>(std::string()).first));
} }
template <typename Point, typename T> template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::type typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::type
get(dynamic_edge_property_t<T>, Surface_mesh<Point>& sm) get(dynamic_edge_property_t<T>, Surface_mesh<Point>& sm) {
{
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::SMPM SMPM; typedef typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::SMPM SMPM;
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::type DPM; typedef typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::type DPM;
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Edge_index, T>(std::string()).first)); return DPM(sm,
new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Edge_index, T>(std::string()).first));
} }
template <typename Point, typename T> template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::type typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::type
get(dynamic_halfedge_property_t<T>, Surface_mesh<Point>& sm) get(dynamic_halfedge_property_t<T>, Surface_mesh<Point>& sm) {
{
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::SMPM SMPM; typedef typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::SMPM SMPM;
typedef typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::type DPM; typedef typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::type DPM;
return DPM(sm, new SMPM(sm.template add_property_map<typename Surface_mesh<Point>::Halfedge_index, T>(std::string()).first)); return DPM(sm, new SMPM(
sm.template add_property_map<typename Surface_mesh<Point>::Halfedge_index, T>(std::string()).first));
} }
// get functions for dynamic properties of const Surface_mesh // get functions for dynamic properties of const Surface_mesh
template <typename Point, typename T> template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_vertex_property_t<T> >::const_type typename boost::property_map<Surface_mesh<Point>, dynamic_vertex_property_t<T> >::const_type
get(dynamic_vertex_property_t<T>, const Surface_mesh<Point>& sm) get(dynamic_vertex_property_t<T>, const Surface_mesh<Point>& sm) {
{
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Vertex_index, T>(num_vertices(sm)); return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Vertex_index, T>(num_vertices(sm));
} }
template <typename Point, typename T> template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::const_type typename boost::property_map<Surface_mesh<Point>, dynamic_face_property_t<T> >::const_type
get(dynamic_face_property_t<T>, const Surface_mesh<Point>& sm) get(dynamic_face_property_t<T>, const Surface_mesh<Point>& sm) {
{
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Face_index, T>(num_faces(sm)); return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Face_index, T>(num_faces(sm));
} }
template <typename Point, typename T> template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::const_type typename boost::property_map<Surface_mesh<Point>, dynamic_halfedge_property_t<T> >::const_type
get(dynamic_halfedge_property_t<T>, const Surface_mesh<Point>& sm) get(dynamic_halfedge_property_t<T>, const Surface_mesh<Point>& sm) {
{
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Halfedge_index, T>(num_halfedges(sm)); return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Halfedge_index, T>(num_halfedges(sm));
} }
template <typename Point, typename T> template <typename Point, typename T>
typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::const_type typename boost::property_map<Surface_mesh<Point>, dynamic_edge_property_t<T> >::const_type
get(dynamic_edge_property_t<T>, const Surface_mesh<Point>& sm) get(dynamic_edge_property_t<T>, const Surface_mesh<Point>& sm) {
{
return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Edge_index, T>(num_edges(sm)); return CGAL::internal::Dynamic_with_index<typename Surface_mesh<Point>::Edge_index, T>(num_edges(sm));
} }
// implementation detail: required by Dynamic_property_map_deleter // implementation detail: required by Dynamic_property_map_deleter
template <typename Pmap,typename P> template <typename Pmap, typename P>
void void
remove_property(Pmap pm, CGAL::Surface_mesh<P>& sm) remove_property(Pmap pm, CGAL::Surface_mesh<P>& sm) {
{
return sm.remove_property_map(pm); return sm.remove_property_map(pm);
} }
template <typename P, typename Property_tag> template <typename P, typename Property_tag>
struct Get_pmap_of_surface_mesh { struct Get_pmap_of_surface_mesh {
typedef typename boost::property_map<Surface_mesh<P>, Property_tag >::type type; typedef typename boost::property_map<Surface_mesh<P>, Property_tag>::type type;
}; };

View File

@ -19,35 +19,24 @@ typedef boost::graph_traits<Sm>::face_descriptor face_descriptor;
void void
freelist(const Sm& sm, int vc, int fc, int ec) freelist(const Sm& sm, int vc, int fc, int ec)
{ {
// vc should be the number of in-active vertex indices
std::cout << "vertex freelist" << std::endl; std::cout << "vertex freelist" << std::endl;
vertex_descriptor vd = sm.vertex_freelist(); auto unused_vertices = sm.vertex_freelist();
while(vd != sm.null_vertex()){ for (auto vd: unused_vertices)
--vc;
std::cout << vd << std::endl; std::cout << vd << std::endl;
halfedge_descriptor hd = halfedge(vd,sm); assert(vc == unused_vertices.size());
vd = vertex_descriptor((Sm::size_type)hd);
}
assert(vc == 0);
std::cout << "face freelist" << std::endl; std::cout << "face freelist" << std::endl;
face_descriptor fd = sm.face_freelist(); auto unused_faces = sm.face_freelist();
while(fd != sm.null_face()){ for (auto fd: unused_faces)
--fc;
std::cout << fd << std::endl; std::cout << fd << std::endl;
halfedge_descriptor hd = halfedge(fd,sm); assert(fc == unused_faces.size());
fd = face_descriptor((Sm::size_type)hd);
}
assert(fc == 0);
std::cout << "edge freelist" << std::endl; std::cout << "edge freelist" << std::endl;
edge_descriptor ed = sm.edge_freelist(); auto unused_edges = sm.edge_freelist();
while(ed != sm.null_edge()){ for (auto ed: unused_edges)
--ec;
std::cout << ed << std::endl; std::cout << ed << std::endl;
halfedge_descriptor hd = next(halfedge(ed,sm),sm); assert(ec == unused_edges.size());
ed = edge(hd,sm);
}
assert(ec == 0);
} }

View File

@ -33,28 +33,30 @@ void OpenOFF(int i)
assert(in && !surface_mesh.is_empty()); assert(in && !surface_mesh.is_empty());
SMesh::Property_map<face_descriptor, CGAL::IO::Color> fcolors = auto [fcolors, created_fcolors] = surface_mesh.property_map<face_descriptor, CGAL::IO::Color >("f:color");
surface_mesh.property_map<face_descriptor, CGAL::IO::Color >("f:color").first; auto [vcolors, created_vcolors] = surface_mesh.property_map<vertex_descriptor, CGAL::IO::Color >("v:color");
SMesh::Property_map<vertex_descriptor, CGAL::IO::Color> vcolors = // Both color maps should have already existed, because they were loaded from the file
surface_mesh.property_map<vertex_descriptor, CGAL::IO::Color >("v:color").first; assert(!created_fcolors);
CGAL::IO::Color c = fcolors[*(surface_mesh.faces().begin())]; assert(!created_vcolors);
assert(c== CGAL::IO::Color(229,0,0));
c = fcolors[*(--surface_mesh.faces().end())];
assert(c== CGAL::IO::Color(0,0,229));
c = vcolors[*(surface_mesh.vertices().begin())]; auto first_fcolor = fcolors[*(surface_mesh.faces().begin())];
assert((c== CGAL::IO::Color(229,0,0))); assert(first_fcolor == CGAL::IO::Color(229, 0, 0));
c = vcolors[*(--surface_mesh.vertices().end())]; auto last_fcolor = fcolors[*(--surface_mesh.faces().end())];
assert((c== CGAL::IO::Color(0,0,229))); assert(last_fcolor == CGAL::IO::Color(0, 0, 229));
auto first_vcolor = vcolors[*(surface_mesh.vertices().begin())];
assert((first_vcolor == CGAL::IO::Color(229, 0, 0)));
auto last_vcolor = vcolors[*(--surface_mesh.vertices().end())];
assert((last_vcolor == CGAL::IO::Color(0, 0, 229)));
} }
int main() int main()
{ {
OpenOFF(1); OpenOFF(1);
OpenOFF(2); // OpenOFF(2);
OpenOFF(3); // OpenOFF(3);
std::cerr << "done" << std::endl; std::cerr << "done" << std::endl;
return 0; return 0;
} }

View File

@ -219,15 +219,11 @@ void point_position_accessor ()
void properties () { void properties () {
Surface_fixture f; Surface_fixture f;
auto [prop, created] = f.m.add_property_map<Sm::Vertex_index, int>("illuminatiproperty", 23);
Sm::Property_map<Sm::Vertex_index, int> prop;
bool created = false;
boost::tie(prop,created) = f.m.add_property_map<Sm::Vertex_index, int>("illuminatiproperty", 23);
assert(created == true); assert(created == true);
boost::tie(prop, created)= f.m.add_property_map<Sm::Vertex_index, int>("illuminatiproperty"); auto [_, created_again] = f.m.add_property_map<Sm::Vertex_index, int>("illuminatiproperty");
assert(created == false); assert(created_again == false);
} }
void move () { void move () {