File: Verticality.h

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (114 lines) | stat: -rw-r--r-- 3,480 bytes parent folder | download
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
// Copyright (c) 2017 GeometryFactory Sarl (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1/Classification/include/CGAL/Classification/Feature/Verticality.h $
// $Id: include/CGAL/Classification/Feature/Verticality.h b26b07a1242 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s)     : Simon Giraudot

#ifndef CGAL_CLASSIFICATION_FEATURE_VERTICALITY_H
#define CGAL_CLASSIFICATION_FEATURE_VERTICALITY_H

#include <CGAL/license/Classification.h>

#include <vector>
#include <CGAL/Classification/Feature_base.h>
#include <CGAL/Classification/Local_eigen_analysis.h>

namespace CGAL {

namespace Classification {

namespace Feature {

  /*!
    \ingroup PkgClassificationFeatures

    %Feature based on local verticality. The orientation of the
    local tangent plane of the considered point can be useful to
    discriminate facades from the ground. This feature can use
    normal vectors if available or eigen analysis that estimates
    tangent planes from local neighborhoods.

    Its default name is "verticality".

    \tparam GeomTraits model of \cgal Kernel.
  */
template <typename GeomTraits>
class Verticality : public Feature_base
{
  const typename GeomTraits::Vector_3 vertical;
  std::vector<compressed_float> verticality_feature;
  const Local_eigen_analysis* eigen;

public:
  /*!
    \brief constructs the feature using local eigen analysis.

    \tparam InputRange model of `ConstRange`. Its iterator type
    is `RandomAccessIterator`.
    \param input input range.
    \param eigen class with precomputed eigenvectors and eigenvalues.
  */
  template <typename InputRange>
  Verticality (const InputRange& input,
               const Local_eigen_analysis& eigen)
    : vertical (0., 0., 1.), eigen (&eigen)
  {
    CGAL_USE(input);
    this->set_name ("verticality");
  }


  /*!
    \brief constructs the feature using provided normals of points.

    \tparam PointRange model of `ConstRange`. Its iterator type
    is `RandomAccessIterator` and its value type is the key type of
    `VectorMap`.
    \tparam VectorMap model of `ReadablePropertyMap` whose key
    type is the value type of the iterator of `PointRange` and value type
    is `GeomTraits::Vector_3`.
    \param input point range.
    \param normal_map property map to access the normal vectors of the input points.
  */
  template <typename PointRange, typename VectorMap>
  Verticality (const PointRange& input,
               VectorMap normal_map)
    : vertical (0., 0., 1.), eigen(nullptr)
  {
    this->set_name ("verticality");
    for (std::size_t i = 0; i < input.size(); i++)
    {
      typename GeomTraits::Vector_3 normal = get(normal_map, *(input.begin()+i));
      normal = normal / CGAL::sqrt (normal * normal);
      verticality_feature.push_back (compress_float(1.f - float(CGAL::abs(normal * vertical))));
    }
  }


  /// \cond SKIP_IN_MANUAL
  virtual float value (std::size_t pt_index)
  {
    if (eigen != nullptr)
    {
      typename GeomTraits::Vector_3 normal = eigen->normal_vector<GeomTraits>(pt_index);
      normal = normal / CGAL::sqrt (normal * normal);
      return (1.f - float(CGAL::abs(normal * vertical)));
    }
    else
      return decompress_float(verticality_feature[pt_index]);
  }
  /// \endcond
};

} // namespace Feature

} // namespace Classification

} // namespace CGAL

#endif // CGAL_CLASSIFICATION_FEATURE_VERTICALITY_H