1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
// Copyright (c) 2018 GeometryFactory Sarl (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/Classification/include/CGAL/Classification/property_maps.h $
// $Id: include/CGAL/Classification/property_maps.h 08b27d3db14 $
// 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
|