1 // Copyright (c) 2017 GeometryFactory Sarl (France).
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org).
5 //
6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Classification/include/CGAL/Classification/Feature/Simple_feature.h $
7 // $Id: Simple_feature.h 0e934b1 2020-08-04T13:16:13+02:00 Simon Giraudot
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 // Author(s)     : Simon Giraudot
11 
12 #ifndef CGAL_CLASSIFICATION_SIMPLE_FEATURE_H
13 #define CGAL_CLASSIFICATION_SIMPLE_FEATURE_H
14 
15 #include <CGAL/license/Classification.h>
16 
17 #include <vector>
18 #include <CGAL/Classification/Feature_base.h>
19 
20 namespace CGAL {
21 
22 namespace Classification {
23 
24 namespace Feature {
25 
26   /*!
27     \ingroup PkgClassificationFeatures
28 
29     %Feature based on a user-defined scalar field.
30 
31     \tparam InputRange model of `ConstRange`. Its iterator type
32     is `RandomAccessIterator`.
33     \tparam PropertyMap model of `ReadablePropertyMap` whose key
34     type is the value type of the iterator of `PointRange` and value type
35     is statically castable to `float`.
36   */
37 template <typename InputRange, typename PropertyMap>
38 class Simple_feature : public Feature_base
39 {
40   const InputRange& m_input;
41   PropertyMap m_pmap;
42 
43 public:
44   /*!
45     \brief constructs the feature using an input range and a property map.
46 
47     \param input point range.
48     \param property_map property map to access scalar field.
49     \param name name of the property (no default name is given).
50   */
Simple_feature(const InputRange & input,PropertyMap property_map,const std::string & name)51   Simple_feature (const InputRange& input,
52                   PropertyMap property_map,
53                   const std::string& name)
54     : m_input (input), m_pmap (property_map)
55   {
56     this->set_name (name);
57   }
58   /// \cond SKIP_IN_MANUAL
value(std::size_t pt_index)59   virtual float value (std::size_t pt_index)
60   {
61     return static_cast<float> (get (m_pmap, *(m_input.begin()+pt_index)));
62   }
63   /// \endcond
64 };
65 
66 } // namespace Feature
67 
68 } // namespace Classification
69 
70 } // namespace CGAL
71 
72 #endif // CGAL_CLASSIFICATION_SIMPLE_FEATURE_H
73