Ponca  4a9354998d048bf882a3ee9bac8105216fa08d13
Point Cloud Analysis library
Loading...
Searching...
No Matches
project.h
1/*
2 This Source Code Form is subject to the terms of the Mozilla Public
3 License, v. 2.0. If a copy of the MPL was not distributed with this
4 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5*/
6#pragma once
7#include "../concepts.h"
8
9#include <algorithm> // std::min
10
11namespace Ponca
12{
17 {
18 public:
27 template <ProvidesProjectionOperator ComputeObject>
28 PONCA_MULTIARCH typename ComputeObject::VectorType project(const ComputeObject& _f,
29 const typename ComputeObject::VectorType& _pos) const
30 {
31 return _f.project(_pos);
32 }
33
37 template <typename ComputeObject>
38 PONCA_MULTIARCH typename ComputeObject::VectorType operator()(
39 const ComputeObject& _f, const typename ComputeObject::VectorType& _pos) const
40 {
41 return project(_f, _pos);
42 }
43 };
44
54 {
55 public:
56 GradientDescentProjectionOperator(unsigned int _nbIter = 16) : nbIter(_nbIter) {}
57
66 template <ProvidesImplicitPrimitive ComputeObject>
67 PONCA_MULTIARCH typename ComputeObject::VectorType project(const ComputeObject& _f,
68 const typename ComputeObject::VectorType& _pos) const
69 {
70 PONCA_MULTIARCH_STD_MATH(min)
71 using VectorType = typename ComputeObject::VectorType;
72 using Scalar = typename ComputeObject::Scalar;
73
74 VectorType grad;
75 VectorType dir = _f.primitiveGradient(_pos);
76 Scalar ilg = Scalar(1.) / dir.norm();
77 dir = dir * ilg;
78 Scalar ad = _f.potential(_pos);
79 Scalar delta = -ad * min(ilg, Scalar(1.));
80 VectorType proj = _pos + dir * delta;
81
82 for (unsigned int i = 0; i < nbIter; ++i)
83 {
84 grad = _f.primitiveGradient(proj);
85 ilg = Scalar(1.) / grad.norm();
86 delta = -_f.potential(proj) * min(ilg, Scalar(1.));
87 proj += dir * delta;
88 }
89 return proj;
90 }
91
95 template <typename ComputeObject>
96 PONCA_MULTIARCH typename ComputeObject::VectorType operator()(
97 const ComputeObject& f, const typename ComputeObject::VectorType& pos) const
98 {
99 return project(f, pos);
100 }
101
102 public:
103 unsigned int nbIter;
104 };
105}; // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:294
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
ComputeObject is a virtual object that represents an algorithm which can be used with the compute fun...
Definition compute.h:24
Project a point using the primitive projection operator.
Definition project.h:17
ComputeObject::VectorType operator()(const ComputeObject &_f, const typename ComputeObject::VectorType &_pos) const
Project a point using the primitive projection operator.
Definition project.h:38
ComputeObject::VectorType project(const ComputeObject &_f, const typename ComputeObject::VectorType &_pos) const
Project a point using the primitive projection operator.
Definition project.h:28
Project a point using the gradinet of the sdf.
Definition project.h:54
ComputeObject::VectorType project(const ComputeObject &_f, const typename ComputeObject::VectorType &_pos) const
Project a point using the gradinet of the sdf.
Definition project.h:67
ComputeObject::VectorType operator()(const ComputeObject &f, const typename ComputeObject::VectorType &pos) const
Project a point using the gradinet of the sdf.
Definition project.h:96