sparsetv.h
Go to the documentation of this file.
1 // kate: replace-tabs off; indent-width 4; indent-mode normal
2 // vim: ts=4:sw=4:noexpandtab
3 /*
4 
5 Copyright (c) 2010--2018
6 
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11  * Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13  * Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in the
15  documentation and/or other materials provided with the distribution.
16  * Neither the name of the <organization> nor the
17  names of its contributors may be used to endorse or promote products
18  derived from this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
24 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 */
32 #pragma once
33 
35 
36 #include <Eigen/Core>
37 #include <Eigen/Eigenvalues>
38 
39 #include <nabo/nabo.h>
40 
50 //Sparse Tensor Voting
51 template <typename T>
52 struct TensorVoting
53 {
54 //--types
56  using DP = typename PM::DataPoints;
57 
58  using InvalidField = typename DP::InvalidField;
59 
60  using SparseTensor = Eigen::Matrix<T, 4, 1>; // (saliency, ex,ey,ez)
61  using Tensor = Eigen::Matrix<T, 3, 3>;
62 
63  using Field = Eigen::Matrix< Tensor, Eigen::Dynamic, 1>;
64  using Tensors = Eigen::Matrix< Tensor, Eigen::Dynamic, 1>;
65  using SparseTensors = Eigen::Matrix< SparseTensor, Eigen::Dynamic, 1>;
66 
67  using Vector3 = Eigen::Matrix<T, 3, 1>;
68  using Matrix33 = Eigen::Matrix<T, 3, 3>;
69 
70  using Matrix = typename PM::Matrix;
71  using Vector = typename PM::Vector;
72 
74  using Index = typename NNS::Index;
75  using IndexMatrix = typename NNS::IndexMatrix;
76 
78 
79 public:
80 //--attributes
81  const T sigma; //control the scale of the voting field
82  std::size_t k; //number of neighbors
83 
85 
89 
90 public:
91 //--resulting descriptors
92  Matrix surfaceness; //surface saliency map (stick)
93  Matrix curveness; //curve saliency map (plate)
94  Matrix pointness; //junction saliency map (ball)
95 
96  Matrix normals; //normals (stick orientation)
97  Matrix tangents; //tangents (plate orientation)
98 
99  Matrix sticks; //(s,n)
100  Matrix plates; //(s,n1,n2)
101  Matrix balls; // (s)
102 private:
103 //knn
106 
107 public:
108 //--ctor
109  TensorVoting(T sigma_ = T(0.2), std::size_t k_ = 50);
110 //--dtor
111  ~TensorVoting();
112 
113 //--methods
114 
116  void vote(const DP& pts);
117  void refine(const DP& pts);
118 
119  void encode(const DP& pts, Encoding encoding = Encoding::UBALL);
120 
121  void disableBallComponent();
122 
123  void ballVote(const DP& pts, bool doKnn = true);
124  void stickVote(const DP& pts, bool doKnn = true);
125  void plateVote(const DP& pts, bool doKnn = true);
126 
127  void cfvote(const DP& pts, bool doKnn = true);
128 
129  void decompose();
130 
131  void toDescriptors();
132 
135  {
136  static inline T sradial(const T z)
137  {
138  if(z < 3.)
139  return std::pow(z, 2) * std::pow(z - 3, 4) / 16.;
140  else
141  return 0.;
142  }
143 
144  static inline T radial(const T z)
145  {
146  return std::exp(-std::pow(z, 2));
147  }
148 
149  static inline T angular(const T theta)
150  {
151  return std::pow(std::cos(theta), 8);
152  }
153 
154  /***************************************************************************
155  * See Eq (1) in :
156  * G. Guy and G. Medioni, “Inference of surfaces, 3D curves, and junctions
157  * from sparse, noisy, 3D Data,” 1997.
158  **************************************************************************/
159  static inline T diabolo(const T s, const T c, const T k, const T sigma)
160  {
161  return std::exp(-1. * std::pow(s, 2) / std::pow(sigma, 2) - c * std::pow(k, 2) );
162  }
163 
164  /***************************************************************************
165  * See Eq (1) and Eq (2) in :
166  * T.-P. Wu, S.-K. Yeung, J. Jia, C.-K. Tang, and G. Medioni,
167  * “A Closed-Form Solution to Tensor Voting: Theory and Applications,” 2016.
168  ***************************************************************************/
169  static inline T eta(const T vv, const T sigma, const T vvn)
170  {
171  return cij(vv, sigma) * (1. - vvn * vvn);
172  }
173 
174  static inline T cij(const T vv, const T sigma)
175  {
176  return std::exp(- std::pow(vv, 2) / sigma);
177  }
178  };
179 private:
180  void computeKnn(const DP& pts);
181 };
182 
183 #include "sparsetv.hpp"
Tensors tensors
Definition: sparsetv.h:84
static T radial(const T z)
Definition: sparsetv.h:144
void toDescriptors()
Definition: sparsetv.hpp:474
public interface
IndexMatrix indices
Definition: sparsetv.h:104
constexpr T pow(const T base, const std::size_t exponent)
Definition: utils.h:47
Matrix surfaceness
Definition: sparsetv.h:92
static const char encoding[]
Definition: binary.cpp:6
void stickVote(const DP &pts, bool doKnn=true)
Definition: sparsetv.hpp:252
typename NNS::IndexMatrix IndexMatrix
Definition: sparsetv.h:75
Matrix pointness
Definition: sparsetv.h:94
void encode(const DP &pts, Encoding encoding=Encoding::UBALL)
Definition: sparsetv.hpp:55
TensorVoting(T sigma_=T(0.2), std::size_t k_=50)
Definition: sparsetv.hpp:38
Eigen::Matrix< T, 3, 3 > Matrix33
Definition: sparsetv.h:68
PM::DataPoints DataPoints
Eigen::Matrix< SparseTensor, Eigen::Dynamic, 1 > SparseTensors
Definition: sparsetv.h:65
void decompose()
Definition: sparsetv.hpp:427
void plateVote(const DP &pts, bool doKnn=true)
Definition: sparsetv.hpp:312
Eigen::Matrix< Tensor, Eigen::Dynamic, 1 > Field
Definition: sparsetv.h:63
typename PM::Vector Vector
Definition: sparsetv.h:71
static T angular(const T theta)
Definition: sparsetv.h:149
SparseTensors sparsePlate
Definition: sparsetv.h:87
const T sigma
Definition: sparsetv.h:81
typename PM::Matrix Matrix
Definition: sparsetv.h:70
static T eta(const T vv, const T sigma, const T vvn)
Definition: sparsetv.h:169
std::size_t k
Definition: sparsetv.h:82
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dense matrix over ScalarType.
Definition: PointMatcher.h:169
void refine(const DP &pts)
Definition: sparsetv.hpp:187
void disableBallComponent()
Definition: sparsetv.hpp:173
typename DP::InvalidField InvalidField
Definition: sparsetv.h:58
SparseTensors sparseStick
Definition: sparsetv.h:86
Eigen::Matrix< T, 3, 3 > Tensor
Definition: sparsetv.h:61
Functions and classes that are dependant on scalar type are defined in this templatized class...
Definition: PointMatcher.h:130
Kernel methods.
Definition: sparsetv.h:134
Eigen::Matrix< Index, Eigen::Dynamic, Eigen::Dynamic > IndexMatrix
Eigen::Matrix< Tensor, Eigen::Dynamic, 1 > Tensors
Definition: sparsetv.h:64
Eigen::Matrix< T, 4, 1 > SparseTensor
Definition: sparsetv.h:60
Matrix curveness
Definition: sparsetv.h:93
static T sradial(const T z)
Definition: sparsetv.h:136
static T cij(const T vv, const T sigma)
Definition: sparsetv.h:174
Matrix normals
Definition: sparsetv.h:96
Matrix tangents
Definition: sparsetv.h:97
Matrix plates
Definition: sparsetv.h:100
SparseTensors sparseBall
Definition: sparsetv.h:88
Eigen::Matrix< T, 3, 1 > Vector3
Definition: sparsetv.h:67
void cfvote(const DP &pts, bool doKnn=true)
Definition: sparsetv.hpp:381
An exception thrown when one tries to access features or descriptors unexisting or of wrong dimension...
Definition: PointMatcher.h:250
typename PM::DataPoints DP
Definition: sparsetv.h:56
Matrix dist
Definition: sparsetv.h:105
Matrix sticks
Definition: sparsetv.h:99
static T diabolo(const T s, const T c, const T k, const T sigma)
Definition: sparsetv.h:159
Matrix balls
Definition: sparsetv.h:101
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector over ScalarType.
Definition: PointMatcher.h:161
typename NNS::Index Index
Definition: sparsetv.h:74
void computeKnn(const DP &pts)
Definition: sparsetv.hpp:510
void vote(const DP &pts)
Voting methods.
Definition: sparsetv.hpp:49
void ballVote(const DP &pts, bool doKnn=true)
Definition: sparsetv.hpp:215


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:38:03