G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsBSplineSolver.h
Go to the documentation of this file.
1
17#pragma once
18
21
22namespace gismo {
23
24
25enum RootType
26{
27 odd,
28 even,
29 odd_interval,
30 even_interval,
31 invalid
32};
33
34
35
36
37template <typename T=real_t>
38struct Root
39{
40 // requires cleanup
41 RootType type;
42 T parameter;
43 T begParameter;
44 T endParameter;
45 gsVector<T> point;
46 gsVector<T> begPoint;
47 gsVector<T> endPoint;
48
49 Root(bool is_odd, T par, const gsVector<T> &mpoint)
50 : type(is_odd?odd:even), begParameter(0), endParameter(0)
51 {
52 parameter=par;
53 point=mpoint;
54 }
55 Root(bool is_odd, T parB, T parE, const gsVector<T> &pointB, const gsVector<T> &pointE)
56 : type(is_odd?odd_interval:even_interval), parameter(0)
57 {
58 begParameter=parB;
59 endParameter=parE;
60 begPoint=pointB;
61 endPoint=pointE;
62 }
63 Root() : type(invalid){}
64};
65
66
98template <typename T>
100 const gsBSpline<T> &curve,
101 const gsVector<T> &normal,
102 T reference,
103 T tolerance,
104 std::vector<Root<T> > &roots
105 );
106
107
108
112template<class T>
114{
115 typedef gsKnotVector<T> knotVectorType;
116
117public:
119 gsBSplineSolver() : m_n(1),m_k(1), m_d(1), eps(1e-7) { }
120
123
124public:
126 bool firstRoot(gsBSpline<T> const & bsp, int const & coord = 0,
127 T const & tr = 0, T const & tol = 1e-7, unsigned const & N=100)
128 {
129 initSolver(bsp,coord,tr,tol,N);
130 return nextRoot();
131 }
132
134 bool nextRoot ();
135
137 inline T value () { return x;}
138
139 // Return a vector with all the roots
140 void allRoots (gsBSpline<T> const & bsp, std::vector<T> & result,
141 int const & coord = 0,
142 T const & tr = 0, T const & tol = 1e-7, unsigned const & N=100)
143 {
144 result.clear();
145 initSolver(bsp,coord,tr,tol,N);
146
147 while ( nextRoot() )
148 {
149 result.push_back( value() ) ;
150 }
151 //gsLog<< "gsBSplineSolver: found "<< result.size() <<" roots.\n ";
152 }
153
154private:
156 void initSolver(gsBSpline<T> const & bsp , int const & coord,
157 T const & tr, T const & tol, unsigned const &N)
158 {
159 m_n = bsp.coefsSize();
160 m_d = bsp.degree();
161 m_k = 1;
162 eps = tol;
163 x = 0.0;
164 maxn = N + m_n;
165
166 const knotVectorType & kv = bsp.knots();
167
168 m_t.resize(m_n+N+m_d+1);
169 m_c.resize(m_n+N);
170
171 for ( unsigned i = 0; i < m_n; ++i )
172 {
173 m_c[i]= bsp.coef(i, coord) - tr;
174 m_t[i]= kv[i];
175 }
176
177 for ( unsigned i = m_n; i < m_n + m_d +1 ; ++i )
178 m_t[i]= kv[i];
179 }
180
184 int insertKnot (int mu) ;
185
186// Data members
187private:
188
189 // m_t: knot vector, m_c: coefficients
190 std::vector<T> m_c, m_t;
191 //gsVector<T> m_c, m_t;
192
193 // m_n: coefficient size, maxn: maximum coeff. size // m_k span of root
194 unsigned m_n, maxn, m_k ;
195
196 int m_d; // m_d: degree
197
198 T eps; // tolerance
199
200 T x; // root value
201
202}; // class gsClass
203
204} //namespace gismo
205
206#ifndef GISMO_BUILD_LIB
207#include GISMO_HPP_HEADER(gsBSplineSolver.hpp)
208#endif
209
Definition gsBSplineSolver.h:114
bool nextRoot()
Next root (requires that first root has been called before)
Definition gsBSplineSolver.hpp:56
T value()
The value of the current root.
Definition gsBSplineSolver.h:137
int insertKnot(int mu)
Definition gsBSplineSolver.hpp:24
~gsBSplineSolver()
Destructor.
Definition gsBSplineSolver.h:122
gsBSplineSolver()
Default empty constructor.
Definition gsBSplineSolver.h:119
bool firstRoot(gsBSpline< T > const &bsp, int const &coord=0, T const &tr=0, T const &tol=1e-7, unsigned const &N=100)
Return true if the first root exist, the value of the root is in this->value()
Definition gsBSplineSolver.h:126
void initSolver(gsBSpline< T > const &bsp, int const &coord, T const &tr, T const &tol, unsigned const &N)
Initialize the solver with B-spline data.
Definition gsBSplineSolver.h:156
A B-spline function of one argument, with arbitrary target dimension.
Definition gsBSpline.h:51
KnotVectorType & knots(const int i=0)
Returns a reference to the knot vector.
Definition gsBSpline.h:170
short_t degree(short_t i=0) const
Returns the degree of the B-spline.
Definition gsBSpline.h:186
gsMatrix< T >::RowXpr coef(index_t i)
Returns the i-th coefficient of the geometry as a row expression.
Definition gsGeometry.h:346
index_t coefsSize() const
Return the number of coefficients (control points)
Definition gsGeometry.h:371
Class for representing a knot vector.
Definition gsKnotVector.h:80
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
Provides forward declarations of types and structs.
This is the main header file that collects wrappers of Eigen for linear algebra.
The G+Smo namespace, containing all definitions for the library.
GISMO_DEPRECATED bool parameter(int s)
Returns the parameter value (false=0=start, true=1=end) that corresponds to side s.
Definition gsBoundary.h:1069