G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsFitting.h
Go to the documentation of this file.
1 
15 #pragma once
16 
18 #include <vector>
21 
22 namespace gismo
23 {
24 
31 template<class T>
32 class gsFitting
33 {
34 public:
37  {
38  m_basis = NULL;
39  m_result= NULL ;
40  }
41 
43  gsFitting(gsMatrix<T> const & param_values,
44  gsMatrix<T> const & points,
45  gsBasis<T> & basis);
46 
48  gsFitting(gsMatrix<T> const & param_values,
49  gsMatrix<T> const & points,
50  gsVector<index_t> offset,
51  gsMappedBasis<2,T> & mbasis) ;
52 
54  virtual ~gsFitting();
55 
56 public:
57 
59  void compute(T lambda = 0);
60 
61  void parameterCorrection(T accuracy = 1e-8,
62  index_t maxIter = 10,
63  T tolOrth = 1e-6);
64 
66  void computeErrors();
67 
69  void computeMaxNormErrors();
70 
72  void computeApproxError(T & error, int type = 0) const;
73 
75  void get_Error(std::vector<T>& errors, int type = 0) const;
76 
78  T minPointError() const { return m_min_error; }
79 
81  T maxPointError() const { return m_max_error; }
82 
84  const std::vector<T> & pointWiseErrors() const
85  {
86  return m_pointErrors;
87  }
88 
90  size_t numPointsBelow(T threshold) const
91  {
92  const size_t result=
93  std::count_if(m_pointErrors.begin(), m_pointErrors.end(),
94  GS_BIND2ND(std::less<T>(), threshold));
95  return result;
96  }
97 
99  void iterativeCompute( T const & tolerance, unsigned const & num_iters = 10);
100 
103  void applySmoothing(T lambda, gsSparseMatrix<T> & A_mat);
104  gsSparseMatrix<T> smoothingMatrix(T lambda) const;
107 
108 
109 public:
110 
112  gsGeometry<T> * result() const { return m_result; }
113 
115  const gsMappedSpline<2,T> & mresult() const { return m_mresult; }
116 
118  const gsBasis<T> & getBasis() const {return *static_cast<const gsBasis<T>*>(m_basis);}
119 
120  void setBasis(gsBasis<T> & basis) {m_basis=&basis;}
121 
124  gsMatrix<T> & returnParamValues() {return m_param_values;}
125 
128 
133  void setConstraints(const gsSparseMatrix<T>& lhs, const gsMatrix<T>& rhs)
134  {
135  m_constraintsLHS = lhs;
136  m_constraintsRHS = rhs;
137  }
138 
142  void setConstraints(const std::vector<index_t>& indices,
143  const std::vector<gsMatrix<T> >& coefs);
144 
147  void setConstraints(const std::vector<boxSide>& fixedSides);
148 
152  void setConstraints(const std::vector<boxSide>& fixedSides,
153  const std::vector<gsBSpline<T> >& fixedCurves);
154  void setConstraints(const std::vector<boxSide>& fixedSides,
155  const std::vector<gsGeometry<T> * >& fixedCurves);
156 
157 
158 private:
160  void extendSystem(gsSparseMatrix<T>& A_mat, gsMatrix<T>& m_B);
161 
162 protected:
163 
164  //gsOptionList
165 
168 
171 
172  // Patch offsets
173  gsVector<index_t> m_offset;
174 
177 
180 
182  gsMappedSpline<2,T> m_mresult;
183 
184  // All point-wise errors
185  std::vector<T> m_pointErrors;
186 
187  mutable T m_last_lambda;
188 
191 
194 
200 
206 
207 private:
208  //void applySmoothing(T lambda, gsMatrix<T> & A_mat);
209 
210 }; // class gsFitting
211 
212 
213 #ifdef GISMO_WITH_PYBIND11
214 
218  void pybind11_init_gsFitting(pybind11::module &m);
219 
220 #endif // GISMO_WITH_PYBIND11
221 
222 
223 }// namespace gismo
224 
225 
226 #ifndef GISMO_BUILD_LIB
227 #include GISMO_HPP_HEADER(gsFitting.hpp)
228 #endif
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
void computeApproxError(T &error, int type=0) const
Computes the approximation error of the fitted curve to the original point cloud. ...
Definition: gsFitting.hpp:434
void setConstraints(const gsSparseMatrix< T > &lhs, const gsMatrix< T > &rhs)
Definition: gsFitting.h:133
virtual ~gsFitting()
Destructor.
Definition: gsFitting.hpp:28
size_t numPointsBelow(T threshold) const
Computes the number of points below the error threshold (or zero if not fitted)
Definition: gsFitting.h:90
void applySmoothing(T lambda, gsSparseMatrix< T > &A_mat)
Definition: gsFitting.hpp:299
gsMatrix< T > m_points
the points of the point cloud
Definition: gsFitting.h:170
void computeMaxNormErrors()
Computes the maximum norm error for each point.
Definition: gsFitting.hpp:413
const gsBasis< T > & getBasis() const
Returns the basis of the approximation.
Definition: gsFitting.h:118
void computeErrors()
Computes the euclidean error for each point.
Definition: gsFitting.hpp:388
T minPointError() const
Returns the minimum point-wise error from the pount cloud (or zero if not fitted) ...
Definition: gsFitting.h:78
#define index_t
Definition: gsConfig.h:32
A B-spline function of one argument, with arbitrary target dimension.
Definition: gsBSpline.h:50
gsSparseMatrix< T > m_constraintsLHS
Definition: gsFitting.h:199
void get_Error(std::vector< T > &errors, int type=0) const
return the errors for each point
Definition: gsFitting.hpp:475
void iterativeCompute(T const &tolerance, unsigned const &num_iters=10)
Computes the least squares fit for a gsBasis.
void assembleSystem(gsSparseMatrix< T > &A_mat, gsMatrix< T > &B)
Assembles system for the least square fit.
Definition: gsFitting.hpp:220
Class for performing a least squares fit of a parametrized point cloud with a gsGeometry.
Definition: gsFitting.h:32
gsMatrix< T > m_constraintsRHS
Definition: gsFitting.h:205
gsMatrix< T > & getreturnParamValues()
returns the parameter values
Definition: gsFitting.h:123
Provides declaration of Basis abstract interface.
gsFitting()
default constructor
Definition: gsFitting.h:36
const std::vector< T > & pointWiseErrors() const
Return the errors for each point.
Definition: gsFitting.h:84
T maxPointError() const
Returns the maximum point-wise error from the pount cloud (or zero if not fitted) ...
Definition: gsFitting.h:81
gsGeometry< T > * result() const
gives back the computed approximation
Definition: gsFitting.h:112
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
Provides forward declarations of types and structs.
Provides declaration of Basis abstract interface.
gsFunctionSet< T > * m_basis
Pointer keeping the basis.
Definition: gsFitting.h:176
gsMatrix< T > returnPoints() const
returns the points
Definition: gsFitting.h:127
gsMatrix< T > m_param_values
the parameter values of the point cloud
Definition: gsFitting.h:167
void extendSystem(gsSparseMatrix< T > &A_mat, gsMatrix< T > &m_B)
Extends the system of equations by taking constraints into account.
Definition: gsFitting.hpp:260
T m_min_error
Minimum point-wise error.
Definition: gsFitting.h:193
const gsMappedSpline< 2, T > & mresult() const
gives back the computed approximation for multipatch geometry
Definition: gsFitting.h:115
gsMappedSpline< 2, T > m_mresult
Pointer keeping the resulting multipatch geometry.
Definition: gsFitting.h:182
gsGeometry< T > * m_result
Pointer keeping the resulting geometry.
Definition: gsFitting.h:179
T m_max_error
Maximum point-wise error.
Definition: gsFitting.h:190
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
void compute(T lambda=0)
Computes the least squares fit for a gsBasis.
Definition: gsFitting.hpp:68