Files
cgal/Classification/include/CGAL/Classification/property_maps.h
T
Mael Rouxel-Labbé 590ddf8015 Various fixes for pmaps:
- Use `value_type` when the returned type is not a reference
- Enforce `reference = value_type` if the returned type is not
  a reference (to avoid `typename PM::reference r = get(m, k)`,
  which will take a ref to a temporary if the `reference`
  typedef is an actualy reference)
- Do not use `put_get_helper` if the property map is not a `lvalue`
  **mutable** property map: the `put()` is `map[k] = v`, which
  is broken if `operator[]` does not return a reference
- The concept `boost::lvalue_property_map_tag` requires `operator[](key)`,
  not a reference in `get(map, key)`. You can have a readable property map
  returning a reference through its `get(map, key)`, but if there is
  no `operator[]`, it's just a `boost::readable_property_map_tag`
- Some const correctness to avoid copying maps with state
  or heavy keys in `get(map, key)` / `put(map, key, value)`
- Base the category of a wrapping pmap on what it offers instead
  of just forwarding the base property map's category
- Tried to do something like mutable lvalue pmap:
  * `value_type& operator[](key&)`
  * `ref get(map, const key&)`
  * `put(map, const key&, const value_type&)`
  and non-mutable lvalue pmap:
  * `const value_type& operator[](const key&)`
  * `ref get(map, const key&)`
  but not everything fits properly...
2021-10-08 15:38:47 +02:00

160 lines
4.5 KiB
C++

// Copyright (c) 2018 GeometryFactory Sarl (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL$
// $Id$
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : Simon Giraudot
#ifndef CGAL_CLASSIFICATION_PROPERTY_MAPS_H
#define CGAL_CLASSIFICATION_PROPERTY_MAPS_H
#include <CGAL/license/Classification.h>
#include <CGAL/centroid.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/property_map.h>
#include <CGAL/boost/graph/properties.h>
namespace CGAL
{
namespace Classification
{
/*!
\ingroup PkgClassificationMesh
\brief Property map that constructs the center of mass of the face
of a mesh on-the-fly.
\cgalModels `ReadablePropertyMap`
\tparam FaceGraph model of `FaceGraph`.
\tparam VertexPointMap model of `ReadablePropertyMap` with with
`boost::graph_traits<FaceGraph>::%vertex_descriptor` as key type
and `CGAL::Point_3` as value type.
*/
template <typename FaceGraph,
typename VertexPointMap = typename boost::property_map<FaceGraph,vertex_point_t>::type >
class Face_descriptor_to_center_of_mass_map
{
public:
typedef typename boost::property_traits<VertexPointMap>::value_type Point_3;
typedef typename boost::graph_traits<FaceGraph>::face_descriptor key_type;
typedef Point_3 value_type;
typedef Point_3 reference;
typedef boost::readable_property_map_tag category;
private:
typedef typename boost::graph_traits<FaceGraph>::vertex_descriptor vertex_descriptor;
const FaceGraph* m_mesh;
VertexPointMap m_vpm;
public:
Face_descriptor_to_center_of_mass_map ()
: m_mesh (nullptr) { }
Face_descriptor_to_center_of_mass_map (const FaceGraph* mesh)
: m_mesh (mesh), m_vpm (get (vertex_point, *m_mesh)) { }
Face_descriptor_to_center_of_mass_map (const FaceGraph* mesh, VertexPointMap vpm)
: m_mesh (mesh), m_vpm (vpm) { }
/// \cond SKIP_IN_MANUAL
inline friend value_type get (const Face_descriptor_to_center_of_mass_map& map, key_type f)
{
std::vector<Point_3> points;
for(vertex_descriptor v : vertices_around_face(halfedge(f, *(map.m_mesh)), *(map.m_mesh)))
points.push_back (get (map.m_vpm, v));
return CGAL::centroid (points.begin(), points.end());
}
/// \endcond
};
/*!
\ingroup PkgClassificationMesh
\brief Property map that constructs a face descriptor with a
`bbox()` method from a face descriptor.
\cgalModels `ReadablePropertyMap`
\tparam FaceGraph model of `FaceGraph`.
\tparam VertexPointMap model of `ReadablePropertyMap` with with
`boost::graph_traits<FaceGraph>::%vertex_descriptor` as key type
and `CGAL::Point_3` as value type.
*/
template <typename FaceGraph,
typename VertexPointMap = typename boost::property_map<FaceGraph,vertex_point_t>::type >
class Face_descriptor_to_face_descriptor_with_bbox_map
{
public:
typedef typename boost::graph_traits<FaceGraph>::face_descriptor face_descriptor;
/*!
\brief Face descriptor with a precomputed bounding box.
*/
class face_descriptor_with_bbox
{
face_descriptor m_descriptor;
CGAL::Bbox_3 m_bbox;
public:
face_descriptor_with_bbox (const face_descriptor& descriptor,
const CGAL::Bbox_3& bbox)
: m_descriptor (descriptor), m_bbox (bbox)
{ }
const CGAL::Bbox_3 bbox() const { return m_bbox; }
operator face_descriptor() const { return m_descriptor; }
};
typedef face_descriptor key_type;
typedef face_descriptor_with_bbox value_type;
typedef face_descriptor_with_bbox reference;
typedef boost::readable_property_map_tag category;
private:
typedef typename boost::graph_traits<FaceGraph>::vertex_descriptor vertex_descriptor;
const FaceGraph* m_mesh;
VertexPointMap m_vpm;
public:
Face_descriptor_to_face_descriptor_with_bbox_map ()
: m_mesh (nullptr) { }
Face_descriptor_to_face_descriptor_with_bbox_map (const FaceGraph* mesh)
: m_mesh (mesh), m_vpm (get (vertex_point, *m_mesh)) { }
Face_descriptor_to_face_descriptor_with_bbox_map (const FaceGraph* mesh, VertexPointMap vpm)
: m_mesh (mesh), m_vpm (vpm) { }
/// \cond SKIP_IN_MANUAL
inline friend value_type get (const Face_descriptor_to_face_descriptor_with_bbox_map& map, key_type f)
{
CGAL::Bbox_3 bbox;
for(vertex_descriptor v : vertices_around_face(halfedge(f, *(map.m_mesh)), *(map.m_mesh)))
bbox = bbox + get(map.m_vpm, v).bbox();
return value_type (f, bbox);
}
/// \endcond
};
} // namespace Classification
} // namespace CGAL
#endif // CGAL_CLASSIFICATION_PROPERTY_MAPS_H