61 void compute_periodic();
103 int m_degree=m_knots.degree();
105 int num_points=m_points.rows();
107 int m_dimension=m_points.cols();
112 int num_basis=curveBasis->
size();
120 curveBasis->
eval_into(m_param_values.transpose(),values);
122 curveBasis->
active_into(m_param_values.transpose(),actives);
125 int num_rows=num_basis;
127 num_rows=num_rows-m_degree;
139 for(
index_t k=0;k<num_points;k++){
140 for(
index_t i=0;i<actives.rows();i++){
141 m_B.row(actives(i,k)%num_rows) += values(i,k)*m_points.row(k);
142 for(
index_t j=0;j<actives.rows();j++){
143 m_A(actives(i,k)%num_rows,actives(j,k)%num_rows) += values(i,k)*values(j,k);
150 x=m_A.fullPivHouseholderQr().solve( m_B);
155 coefs.conservativeResize(num_rows+m_degree,m_dimension);
156 for(
index_t i=0;i<m_degree;i++){
157 for(
index_t j=0;j<m_dimension;j++){
158 coefs(num_rows+i,j)=coefs(i,j);
172 int m_degree=m_knots.degree();
174 int num_points=m_points.rows();
176 int m_dimension=m_points.cols();
181 int num_basis=curveBasis.size();
189 curveBasis.eval_into(m_param_values.transpose(),values);
191 curveBasis.active_into(m_param_values.transpose(),actives);
194 int num_rows=num_basis;
210 for(
index_t k=0;k<num_points;k++){
211 for(
index_t i=0;i<actives.rows();i++){
212 m_B.row(actives(i,k)) += values(i,k)*m_points.row(k);
213 for(
index_t j=0;j<actives.rows();j++){
214 m_A(actives(i,k),actives(j,k)) += values(i,k)*values(j,k);
220 gsMatrix<T> x (m_B.rows(), m_B.cols());
221 x=m_A.fullPivHouseholderQr().solve( m_B);
226 coefs.conservativeResize(num_rows+m_degree,m_dimension);
227 for(
index_t i=0;i<m_degree;i++){
228 for(
index_t j=0;j<m_dimension;j++){
229 coefs(num_rows+i,j)=coefs(i,j);
234 curveBasis.setPeriodic(
false);
237 m_curve= gsBSpline<T>(curveBasis,
give(coefs));
238 m_curve.setPeriodic(m_closed);
246 m_curve.eval_into(m_param_values.transpose(),results);
247 results.transposeInPlace();
250 error = (m_points - results).squaredNorm();
255 std::ostream & operator <<( std::ostream &os, gsCurveFitting<T>
const & cf)
257 os <<
"with "<< (cf.returnPoints()).rows() <<
" points of dimension " << (cf.returnPoints()).cols() <<
258 ". The desired B-spline curve should have degree "<< (cf.returnKnotVector()).degree() <<
" with the following knot vector: " << cf.returnKnotVector() <<
"\n";
index_t size() const
size
Definition: gsBSplineBasis.h:165
bool m_closed
closed or not closed curve
Definition: gsCurveFitting.h:94
~gsCurveFitting()
Destructor.
Definition: gsCurveFitting.h:52
void setClosedCurve(bool closed)
set m_closed to true/or false since we want to have a closed/open curve
Definition: gsCurveFitting.h:67
gsMatrix< T > m_points
the points of the point cloud
Definition: gsCurveFitting.h:90
S give(S &x)
Definition: gsMemory.h:266
Provides declaration of Geometry abstract interface.
#define index_t
Definition: gsConfig.h:32
gsKnotVector< T > m_knots
the knot vector of the desired B-spline curve
Definition: gsCurveFitting.h:92
void computeApproxError(T &error)
computes the approximation error of the fitted curve to the original point cloud
Definition: gsCurveFitting.h:242
A B-spline function of one argument, with arbitrary target dimension.
Definition: gsBSpline.h:50
A univariate B-spline basis.
Definition: gsBSplineBasis.h:694
gsBSpline< T > m_curve
pointer to a B-spline curve
Definition: gsCurveFitting.h:86
gsCurveFitting()
default constructor
Definition: gsCurveFitting.h:36
gsMatrix< T > m_param_values
the parameter values of the point cloud
Definition: gsCurveFitting.h:88
gsCurveFitting(gsMatrix< T > const ¶m_values, gsMatrix< T > const &points, gsKnotVector< T > const &knots, const bool &closed=false)
constructor
Definition: gsCurveFitting.h:42
Class for performing a least squares fit to get a open/closed B-Spline curve for some given data...
Definition: gsCurveFitting.h:32
void compute()
computes the least squares fit for a (closed) B-spline curve
Definition: gsCurveFitting.h:100
gsMatrix< T > returnPoints() const
returns the points
Definition: gsCurveFitting.h:81
Represents a B-spline curve/function with one parameter.
virtual void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates nonzero basis functions at point u into result.
Definition: gsBSplineBasis.hpp:260
void active_into(const gsMatrix< T > &u, gsMatrix< index_t > &result) const
Returns the indices of active basis functions at points u, as a list of indices, in result...
Definition: gsBSplineBasis.hpp:127
Class for representing a knot vector.
Definition: gsKnotVector.h:79
This is the main header file that collects wrappers of Eigen for linear algebra.
gsMatrix< T > returnParamValues() const
returns the parameter values
Definition: gsCurveFitting.h:78
gsKnotVector< T > returnKnotVector() const
returns the knot vector
Definition: gsCurveFitting.h:75
const gsBSpline< T > & curve() const
gives back the computed B-spline curve
Definition: gsCurveFitting.h:72