30 template <
short_t d,
class T>
61 T refin,
const std::vector<unsigned> & extension,
63 :
gsFitting<T>(param_values, points, basis)
66 "Refinement percentage must be between 0 and 1." );
67 GISMO_ASSERT(extension.size() == d,
"Extension is not of the right dimension");
69 "Extension must be a positive number.");
97 void iterativeRefine(
int iterations, T tolerance, T err_threshold = -1);
111 const std::vector<boxSide>& fixedSides,
129 GISMO_ASSERT((refPercent >=0) && (refPercent <=1),
"Invalid percentage" );
137 "Extension must be a positive number.");
139 "Error in dimension");
144 std::vector<index_t>
getBoxes(
const std::vector<T>& errors,
150 virtual void appendBox(std::vector<index_t>& boxes,
151 std::vector<index_t>& cells,
159 const std::vector<index_t>& cells);
162 static void append(std::vector<index_t>& boxes,
165 for (
index_t col = 0; col != box.rows(); col++)
166 boxes.push_back(box[col]);
190 template<
short_t d,
class T>
194 std::vector<boxSide> dummy;
195 return nextIteration(tolerance, err_threshold, dummy, maxPcIter);
198 template<
short_t d,
class T>
200 const std::vector<boxSide>& fixedSides,
206 if ( m_pointErrors.size() != 0 )
209 if ( m_max_error > tolerance )
212 T threshold = (err_threshold >= 0) ? err_threshold : setRefineThreshold(m_pointErrors);
214 std::vector<index_t> boxes = getBoxes(m_pointErrors, threshold);
222 if(m_result != NULL && fixedSides.size() > 0)
224 m_result->refineElements(boxes);
227 gsDebug <<
"inserted " << boxes.size() / (2 * d + 1) <<
" boxes.\n";
231 gsDebug <<
"Tolerance reached.\n";
237 this->compute(m_lambda);
240 this->parameterCorrection(1e-7, maxPcIter, 1e-4);
242 this->computeErrors();
247 template<
short_t d,
class T>
254 if ( m_pointErrors.size() == 0 )
256 this->compute(m_lambda);
257 this->computeErrors();
261 for(
int i = 0; i < numIterations; i++ )
263 newIteration = nextIteration( tolerance, err_threshold );
264 if( m_max_error <= tolerance )
266 gsDebug <<
"Tolerance reached at iteration: " << i <<
"\n";
271 gsDebug <<
"No more Boxes to insert at iteration: " << i <<
"\n";
277 template <
short_t d,
class T>
282 std::vector<index_t> cells;
286 std::vector<index_t> boxes;
288 for (
size_t index = 0; index != errors.size(); index++)
290 if (threshold <= errors[index])
292 appendBox(boxes, cells, this->m_param_values.col(index));
299 template <
short_t d,
class T>
301 std::vector<index_t>& cells,
305 const int maxLvl = basis->
maxLevel();
311 for (
short_t dim = 0; dim != d; dim++)
317 if (!isCellAlreadyInserted(a_cell, cells))
319 append(cells, a_cell);
323 const int cell_lvl = basis->
tree().
query3(a_cell, a_cell_upp, maxLvl) + 1;
328 for (
short_t dim = 0; dim != d; dim++)
330 const unsigned numBreaks = basis->
numBreaks(cell_lvl, dim) - 1 ;
332 unsigned lowIndex = 0;
333 if (cell_lvl < maxLvl)
335 const unsigned shift = maxLvl - cell_lvl;
336 lowIndex = (a_cell(dim) >> shift);
340 const unsigned shift = cell_lvl - maxLvl;
341 lowIndex = (a_cell(dim) << shift);
345 index_t low = ( (lowIndex > m_ext[dim]) ? (lowIndex - m_ext[dim]) : 0 );
346 index_t upp = ( (lowIndex + m_ext[dim] + 1 < numBreaks) ?
347 (lowIndex + m_ext[dim] + 1) : numBreaks );
350 box[1 + d + dim] = upp;
358 template <
short_t d,
class T>
360 const std::vector<index_t>& cells)
363 for (
size_t i = 0; i != cells.size(); i += a_cell.rows())
366 for (
index_t col = 0; col != a_cell.rows(); col++)
368 if (cells[i + col] == a_cell[col])
374 if (commonEntries == a_cell.rows())
383 template<
short_t d,
class T>
386 std::vector<T> errorsCopy = errors;
387 const size_t i = cast<T,size_t>(errorsCopy.size() * (1.0 - m_ref));
388 typename std::vector<T>::iterator pos = errorsCopy.begin() + i;
389 std::nth_element(errorsCopy.begin(), pos, errorsCopy.end());
Provides definition of HTensorBasis abstract interface.
const std::vector< unsigned > & get_extension() const
Returns the chosen cell extension.
Definition: gsHFitting.h:121
T getRefPercentage() const
Return the refinement percentage.
Definition: gsHFitting.h:115
void setConstraints(const gsSparseMatrix< T > &lhs, const gsMatrix< T > &rhs)
Definition: gsFitting.h:133
gsHFitting(gsMatrix< T > const ¶m_values, gsMatrix< T > const &points, gsHTensorBasis< d, T > &basis, T refin, const std::vector< unsigned > &extension, T lambda=0)
Main constructor of the fitting class.
Definition: gsHFitting.h:58
static bool isCellAlreadyInserted(const gsVector< index_t, d > &a_cell, const std::vector< index_t > &cells)
Checks if a_cell is already inserted in container of cells.
Definition: gsHFitting.h:359
#define gsDebug
Definition: gsDebug.h:61
#define short_t
Definition: gsConfig.h:35
bool nextIteration(T tolerance, T err_threshold, index_t maxPcIter=0)
nextIteration One step of the refinement of iterative_refine(...);
Definition: gsHFitting.h:191
Provides declaration of data fitting algorithms by least squares approximation.
#define index_t
Definition: gsConfig.h:32
T m_ref
How many % to refine - 0-1 interval.
Definition: gsHFitting.h:172
const std::vector< tensorBasis * > & getBases() const
Returns the tensor B-spline space of all levels.
Definition: gsHTensorBasis.h:425
const gsHDomain< d > & tree() const
Returns a reference to m_tree.
Definition: gsHTensorBasis.h:601
T m_lambda
Smoothing parameter.
Definition: gsHFitting.h:175
A tensor product B-spline basis.
Definition: gsTensorBSplineBasis.h:36
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
uiterator uFind(const T u) const
Returns the uiterator pointing to the knot at the beginning of the knot interval containing u...
Definition: gsKnotVector.hpp:747
static void append(std::vector< index_t > &boxes, const gsVector< index_t > &box)
Appends a box to the end of boxes (This function also works for cells)
Definition: gsHFitting.h:162
Class for performing a least squares fit of a parametrized point cloud with a gsGeometry.
Definition: gsFitting.h:32
Class representing a (scalar) hierarchical tensor basis of functions .
Definition: gsHTensorBasis.h:74
gsHFitting()
Default constructor.
int query3(point const &k1, point const &k2, int level, node *_node) const
Definition: gsHDomain.hpp:448
virtual void refineElements(std::vector< index_t > const &boxes)
Insert the given boxes into the quadtree.
Definition: gsHTensorBasis.hpp:843
std::vector< index_t > getBoxes(const std::vector< T > &errors, const T threshold)
Returns boxes which define refinment area.
Definition: gsHFitting.h:278
void setExtension(std::vector< unsigned > const &extension)
Sets the cell extension.
Definition: gsHFitting.h:134
void setRefPercentage(double refPercent)
Sets the refinement percentage.
Definition: gsHFitting.h:127
gsFunctionSet< T > * m_basis
Pointer keeping the basis.
Definition: gsFitting.h:176
unsigned maxLevel() const
Returns the level in which the indices are stored internally.
Definition: gsHTensorBasis.h:811
void iterativeRefine(int iterations, T tolerance, T err_threshold=-1)
iterative_refine iteratively refine the basis
Definition: gsHFitting.h:248
gsMatrix< T > m_param_values
the parameter values of the point cloud
Definition: gsFitting.h:167
Class for representing a knot vector.
Definition: gsKnotVector.h:79
Creates a mapped object or data pointer to a const vector without copying data.
Definition: gsLinearAlgebra.h:130
virtual void appendBox(std::vector< index_t > &boxes, std::vector< index_t > &cells, const gsVector< T > ¶meter)
Definition: gsHFitting.h:300
std::vector< unsigned > m_ext
Size of the extension.
Definition: gsHFitting.h:178
T m_min_error
Minimum point-wise error.
Definition: gsFitting.h:193
Truncated hierarchical B-spline basis.
Definition: gsTHBSplineBasis.h:35
const Basis_t & component(short_t dir) const
For a tensor product basis, return the (const) 1-d basis for the i-th parameter component.
Definition: gsTensorBSplineBasis.h:202
T setRefineThreshold(const std::vector< T > &errors)
Identifies the threshold from where we should refine.
Definition: gsHFitting.h:384
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
This class applies hierarchical fitting of parametrized point clouds.
Definition: gsHFitting.h:31
T m_max_error
Maximum point-wise error.
Definition: gsFitting.h:190
int numBreaks(int lvl, int k) const
Definition: gsHTensorBasis.h:436