27 mu = math::max(mu,m_d);
29 while ( x>=m_t[mu+1]) mu++;
32 m_c.insert(m_c.begin()+mu,0);
36 for (
int i=mu; i>=mu-m_d+1; i--)
38 const T alpha = (x-m_t[i])/(m_t[i+m_d]-m_t[i]);
39 m_c[i] = (1.0-alpha) * m_c[i-1] + alpha * m_c[i];
43 m_t[m_n+m_d] = m_t[m_n+m_d-1];
46 m_t.insert(m_t.begin()+mu+1,x);
62 while( m_k<m_n && (m_c[m_k-1]*m_c[m_k] > 0) )
74 const T diff = m_t[m_k+m_d]-m_t[m_k];
83 const T cdiff = m_c[m_k-1]-m_c[m_k];
91 const T lambda = m_c[m_k-1] / cdiff ;
94 x = (std::accumulate(m_t.begin()+m_k, m_t.begin()+m_k+m_d, (T)(0.0) )
95 + lambda*diff ) / (T)(m_d);
99 const T e = math::max(x, m_t[m_k+m_d-1]) - math::min(x, m_t[m_k+1] );
116 gsWarn<<
"gsBSplineRoot: Maximum number of knots reached: "<< m_n <<
"\n";
139 template <
typename T>
140 Position relativePosition (
const T pos,
const T ref,
const T tol)
146 if ( pos <= ref+tol && pos >= ref-tol)
151 template <
typename T>
157 std::vector<Root<T> > &roots
162 "cannot intersect a curve in R^"<< curve.
coefDim()<<
" with a hyperplane in R^"<< normal.rows() );
165 gsWarn<<
"No intersection reportet between curve and invalid hyperplane."<<std::endl;
169 const int deg = curve.
degree();
170 const T tol = tolerance;
171 const T ref = reference;
177 Position curP = relativePosition(crv.
coef(0).dot(normal), ref, tol) ;
180 gsWarn<<__FUNCTION__<<
": first coefficient of curve is NAN, exit without results."<<std::endl;
183 Position newP = undef;
184 Position oldP = undef;
196 unsigned rootCount = 0;
200 newP = relativePosition(crv.
coef(curC).dot(normal), ref, tol);
203 gsWarn<<__FUNCTION__<<
": stopping the search for intersection because the curve contains nan coefficients"<<std::endl;
233 params(0,0) = crv.
knots()[lstC+deg];
234 params(0,1) = crv.
knots()[curC];
236 roots.push_back(Root<T>(is_odd, params(0,0),params(0,1),points.col(0),points.col(1)));
242 else if ( (curC-lstC) >= deg+1-(int)crv.
knots().multiplicityIndex(curC))
247 params(0,0) = crv.
knots()[curC];
249 roots.push_back(Root<T>(is_odd, params(0,0),points.col(0)));
263 intB=math::max(0,lstC-1);
267 GISMO_ASSERT(
false, __FUNCTION__<<
"The impossible happened! Check for B..S!!" );
269 const T grevB = crv.
knots().greville(intB);
270 const T grevE = crv.
knots().greville(curC);
271 const T coeffB = crv.
coef(curC).dot(normal)-ref;
272 const T coeffE = ref-crv.
coef(intB).dot(normal);
273 const T denom = (crv.
coef(curC)-crv.
coef(intB)).dot(normal);
274 newK = coeffB*(grevB/denom)+coeffE*(grevE/denom);
276 newK = math::max(newK, curve.
knots().first());
277 newK = math::min(newK, curve.
knots().last());
282 if (
math::abs(point.col(0).dot(normal)-ref)<tol)
284 roots.push_back(Root<T>(is_odd, newK,point.col(0)));
292 if (newK==oldK) { newK_rep+=1; }
296 if (newK_rep>=deg) newK=(grevB+grevE)/(T)(2);
303 gsWarn<< __FUNCTION__<<
": intersection does not satisfy required tolerance with knot insertion up to numerical precision\n";
304 roots.push_back(Root<T>(is_odd, newK,point.col(0)));
314 curC = math::max(math::max(curC-deg, lstC-1),0);
315 curP = relativePosition(crv.
coef(curC).dot(normal), ref, tol);
325 params(0,0) = crv.
knots()[lstC+deg];
326 params(0,1) = crv.
knots()[curC];
328 roots.push_back(Root<T>(
true, params(0,0),params(0,1),points.col(0),points.col(1)));
335 params(0,0) = crv.
knots()[curC];
337 roots.push_back(Root<T>(
true, params(0,0),points.col(0)));
gsMatrix< T >::RowXpr coef(index_t i)
Returns the i-th coefficient of the geometry as a row expression.
Definition: gsGeometry.h:346
short_t coefDim() const
Dimension n of the coefficients (control points)
Definition: gsGeometry.h:289
bool nextRoot()
Next root (requires that first root has been called before)
Definition: gsBSplineSolver.hpp:56
gsMatrix< T > eval(const gsMatrix< T > &u) const
Evaluate the function,.
Definition: gsFunctionSet.hpp:120
#define index_t
Definition: gsConfig.h:32
unsigned findHyperPlaneIntersections(const gsBSpline< T > &curve, const gsVector< T > &normal, T reference, T tolerance, std::vector< Root< T > > &roots)
find intersections of a BSpline curve with an hyperplane
Definition: gsBSplineSolver.hpp:152
index_t coefsSize() const
Return the number of coefficients (control points)
Definition: gsGeometry.h:371
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
A B-spline function of one argument, with arbitrary target dimension.
Definition: gsBSpline.h:50
void insertKnot(T knot, index_t i=1)
Definition: gsBSpline.hpp:249
#define gsWarn
Definition: gsDebug.h:50
bool isfinite(const gsEigen::MatrixBase< Derived > &x)
Check if all the entires if the matrix x are not INF (infinite)
Definition: gsLinearAlgebra.h:109
KnotVectorType & knots(const int i=0)
Returns a reference to the knot vector.
Definition: gsBSpline.h:170
Represents a B-spline curve/function with one parameter.
int insertKnot(int mu)
Definition: gsBSplineSolver.hpp:24
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition: gsExpressions.h:4486
short_t degree(short_t i=0) const
Returns the degree of the B-spline.
Definition: gsBSpline.h:186