33template <
short_t d,
class T>
57 T refin,
const std::vector<unsigned> & extension,
59 :
gsFitting<T>(param_values, points, basis)
62 "Refinement percentage must be between 0 and 1." );
63 GISMO_ASSERT(extension.size() == d,
"Extension is not of the right dimension");
65 "Extension must be a positive number.");
89 void iterativeRefine(
int iterations, T tolerance, T err_threshold = -1);
103 const std::vector<boxSide>& fixedSides,
113 bool nextRefinement(T tolerance, T err_threshold,
index_t maxPcIter = 0,
bool admissibleRef =
false);
120 const std::vector<boxSide>& fixedSides,
122 bool admissibleRef =
false);
131 bool nextIteration_tdm(T tolerance, T err_threshold,
index_t maxPcIter, T mu, T sigma,
const std::vector<index_t> & interpIdx, tdm_method method,
bool admissibleRef =
false);
138 const std::vector<boxSide>& fixedSides,
141 const std::vector<index_t>& interpIdx,
152 bool nextIteration_pdm(T tolerance, T err_threshold,
index_t maxPcIter,
const std::vector<index_t> & interpIdx,
bool admissibleRef =
false);
159 const std::vector<boxSide>& fixedSides,
161 const std::vector<index_t>& interpIdx,
179 GISMO_ASSERT((refPercent >=0) && (refPercent <=1),
"Invalid percentage" );
187 "Extension must be a positive number.");
188 GISMO_ASSERT(extension.size()==
static_cast<size_t>(this->m_basis.dim()),
189 "Error in dimension");
194 std::vector<index_t>
getBoxes(
const std::vector<T>& errors,
199 virtual void appendBox(std::vector<index_t>& boxes,
200 std::vector<index_t>& cells,
208 const std::vector<index_t>& cells);
211 static void append(std::vector<index_t>& boxes,
214 for (
index_t col = 0; col != box.rows(); col++)
215 boxes.push_back(box[col]);
226 const std::vector<T>& errors,
253template<
short_t d,
class T>
257 std::vector<boxSide> dummy;
258 return nextIteration(tolerance, err_threshold, dummy, maxPcIter);
263template<
short_t d,
class T>
265 index_t maxPcIter, T mu, T sigma,
266 const std::vector<index_t>& interpIdx,
270 std::vector<boxSide> dummy;
271 return nextIteration_tdm(tolerance, err_threshold, dummy, maxPcIter, mu, sigma, interpIdx, method, admissibleRef);
275template<
short_t d,
class T>
278 const std::vector<index_t>& interpIdx,
281 std::vector<boxSide> dummy;
282 return nextIteration_pdm(tolerance, err_threshold, dummy, maxPcIter, interpIdx, admissibleRef);
286template<
short_t d,
class T>
289 std::vector<boxSide> dummy;
290 return nextRefinement(tolerance, err_threshold, dummy, maxPcIter, admissibleRef);
294template<
short_t d,
class T>
296 const std::vector<boxSide>& fixedSides,
301 if ( m_pointErrors.size() != 0 )
304 if ( m_max_error > tolerance )
307 T threshold = (err_threshold >= 0) ? err_threshold : setRefineThreshold(m_pointErrors);
308 std::vector<index_t> boxes = getBoxes(m_pointErrors, threshold);
313 basis->refineElements(boxes);
316 if(m_result != NULL && fixedSides.size() > 0)
318 m_result->refineElements(boxes);
329 this->compute(m_lambda);
332 this->parameterCorrection(1e-7, maxPcIter, 1e-4);
335 this->computeErrors();
341template<
short_t d,
class T>
343 const std::vector<boxSide>& fixedSides,
345 const std::vector<index_t>& interpIdx,
349 if ( m_pointErrors.size() != 0 )
351 if ( m_max_error > tolerance )
354 std::vector<index_t> boxes;
357 T threshold = (err_threshold >= 0) ? err_threshold : setRefineThreshold(m_pointErrors);
363 markedRef = getMarkedHBoxesFromBasis_max(*basis, m_pointErrors, m_param_values, threshold, 2.);
368 boxes = getBoxes(m_pointErrors, threshold);
374 basis->refineElements(boxes);
375 m_result->refineElements(boxes);
378 if(m_result != NULL && fixedSides.size() > 0)
380 m_result->refineElements(boxes);
391 this->compute(m_lambda);
394 this->parameterCorrectionSepBoundary_pdm(1e-6, maxPcIter,interpIdx);
397 this->computeErrors();
405template<
short_t d,
class T>
407 const std::vector<boxSide>& fixedSides,
408 index_t maxPcIter, T mu, T sigma,
409 const std::vector<index_t>& interpIdx,
413 if ( m_pointErrors.size() != 0 )
417 std::vector<index_t> boxes;
419 if ( m_max_error > tolerance )
422 T threshold = (err_threshold >= 0) ? err_threshold : setRefineThreshold(m_pointErrors);
430 markedRef = getMarkedHBoxesFromBasis_max(*basis, m_pointErrors, m_param_values, threshold, 2.);
435 boxes = getBoxes(m_pointErrors, threshold);
441 basis->refineElements(boxes);
442 m_result->refineElements(boxes);
445 if(m_result != NULL && fixedSides.size() > 0)
447 m_result->refineElements(boxes);
458 this->compute_tdm(m_lambda, mu, sigma, interpIdx, method);
462 gsInfo <<
"Parameter correction: parameterCorrectionSepBoundary_tdm\n";
463 this->parameterCorrectionSepBoundary_tdm(1e-6, maxPcIter, mu, sigma, interpIdx, method);
466 this->computeErrors();
472template<
short_t d,
class T>
474 const std::vector<boxSide>& fixedSides,
480 if ( m_pointErrors.size() != 0 )
483 if ( m_max_error > tolerance )
485 std::vector<index_t> boxes;
488 T threshold = (err_threshold >= 0) ? err_threshold : setRefineThreshold(m_pointErrors);
495 markedRef = getMarkedHBoxesFromBasis_max(*basis, m_pointErrors, m_param_values, threshold, 2.);
500 boxes = getBoxes(m_pointErrors, threshold);
506 basis->refineElements(boxes);
507 m_result->refineElements(boxes);
509 if(m_result != NULL && fixedSides.size() > 0)
511 m_result->refineElements(boxes);
525 this->compute(m_lambda);
528 this->parameterCorrection(1e-7, maxPcIter, 1e-4);
529 this->computeErrors();
536template<
short_t d,
class T>
543 if ( m_pointErrors.size() == 0 )
545 this->compute(m_lambda);
546 this->computeErrors();
550 for(
int i = 0; i < numIterations; i++ )
552 newIteration = nextIteration( tolerance, err_threshold );
553 if( m_max_error <= tolerance )
565template <
short_t d,
class T>
570 std::vector<index_t> cells;
574 std::vector<index_t> boxes;
576 for (
size_t index = 0; index != errors.size(); index++)
578 if (threshold <= errors[index])
580 appendBox(boxes, cells, this->m_param_values.col(index));
588template <
short_t d,
class T>
590 std::vector<index_t>& cells,
594 const int maxLvl = basis->maxLevel();
595 const tensorBasis & tBasis = *(basis->getBases()[maxLvl]);
600 for (
short_t dim = 0; dim != d; dim++)
606 if (!isCellAlreadyInserted(a_cell, cells))
608 append(cells, a_cell);
612 const int cell_lvl = basis->tree().query3(a_cell, a_cell_upp, maxLvl) + 1;
617 for (
short_t dim = 0; dim != d; dim++)
619 const unsigned numBreaks = basis->numBreaks(cell_lvl, dim) - 1 ;
621 unsigned lowIndex = 0;
622 if (cell_lvl < maxLvl)
624 const unsigned shift = maxLvl - cell_lvl;
625 lowIndex = (a_cell(dim) >> shift);
629 const unsigned shift = cell_lvl - maxLvl;
630 lowIndex = (a_cell(dim) << shift);
634 index_t low = ( (lowIndex > m_ext[dim]) ? (lowIndex - m_ext[dim]) : 0 );
635 index_t upp = ( (lowIndex + m_ext[dim] + 1 < numBreaks) ?
636 (lowIndex + m_ext[dim] + 1) : numBreaks );
639 box[1 + d + dim] = upp;
647template <
short_t d,
class T>
649 const std::vector<index_t>& cells)
652 for (
size_t i = 0; i != cells.size(); i += a_cell.rows())
655 for (
index_t col = 0; col != a_cell.rows(); col++)
657 if (cells[i + col] == a_cell[col])
663 if (commonEntries == a_cell.rows())
673template<
short_t d,
class T>
676 std::vector<T> errorsCopy = errors;
677 const size_t i = cast<T,size_t>(errorsCopy.size() * (1.0 - m_ref));
678 typename std::vector<T>::iterator pos = errorsCopy.begin() + i;
679 std::nth_element(errorsCopy.begin(), pos, errorsCopy.end());
692 return element(0, 0) <= x && x < element(0, 1) &&
693 element(1, 0) <= y && y < element(1, 1);
698bool is_point_inside_cell(
const T x,
700 const gsMatrix<T>& element)
702 bool condition = (element(0, 0) <= x && x <= element(0, 1) && element(1, 0) <= y && y <= element(1, 1));
709T getCellMaxError(
const gsMatrix<T>& a_cell,
710 const std::vector<T>& errors,
711 const gsMatrix<T>& parameters){
713 std::vector<T> a_cellErrs;
715 for(
index_t it=0; it < parameters.cols(); it++){
716 const T xx = parameters.col(it)(0);
717 const T yy = parameters.col(it)(1);
718 if (is_point_inside_cell(xx, yy, a_cell))
720 a_cellErrs.push_back(errors[it]);
724 for(
typename std::vector<T>::iterator errIt = a_cellErrs.begin(); errIt != a_cellErrs.end(); ++errIt){
725 if (*errIt > cell_max_err){
726 cell_max_err = *errIt;
733template <
short_t d,
class T>
735 const std::vector<T>& errors,
741 typename gsHTensorBasis<d, T>::domainIter domIt = basis.makeDomainIterator();
742 for (; domIt->good(); domIt->next() )
745 elMatrix.col(0)<< domIt->lowerCorner();
746 elMatrix.col(1)<< domIt->upperCorner();
747 T cellMaxError = getCellMaxError(elMatrix, errors, parameters);
748 if (cellMaxError >= threshold)
754 markedHBoxes.
add(tmp);
Creates a mapped object or data pointer to a const vector without copying data.
Definition gsAsMatrix.h:285
Class for performing a fit of a parametrized point cloud with a gsGeometry.
Definition gsFitting.h:32
gsMatrix< T > m_param_values
the parameter values of the point cloud
Definition gsFitting.h:345
tdm_method
choose the method for computing the coefficients: TDM, PDM, HDM with different blending weights
Definition gsFitting.h:81
gsGeometry< T > * m_result
Pointer keeping the resulting geometry.
Definition gsFitting.h:357
T m_max_error
Maximum point-wise error.
Definition gsFitting.h:371
gsFunctionSet< T > * m_basis
Pointer keeping the basis.
Definition gsFitting.h:354
void setConstraints(const gsSparseMatrix< T > &lhs, const gsMatrix< T > &rhs)
Definition gsFitting.h:272
T m_min_error
Minimum point-wise error.
Definition gsFitting.h:374
T lambda() const
Returns the smoothing weight used in the last fitting.
Definition gsFitting.h:310
gsMatrix< T > m_points
the points of the point cloud
Definition gsFitting.h:348
The Hierarchical Box Container provides a container for gsHBox objects.
Definition gsHBoxContainer.h:40
void add(const gsHBox< d, T > &box)
Adds a single box.
Definition gsHBoxContainer.hpp:121
RefBox toRefBoxes(const index_t patchID=-1) const
Returns refinement box representation of the object.
Definition gsHBoxContainer.hpp:374
This class provides a Hierarchical Box (gsHBox)
Definition gsHBox.h:55
Re-implements gsDomainIterator for iteration over all boundary elements of a hierarchical parameter d...
Definition gsHDomainIterator.h:39
This class applies hierarchical fitting of parametrized point clouds.
Definition gsHFitting.h:35
void setExtension(std::vector< unsigned > const &extension)
Sets the cell extension.
Definition gsHFitting.h:184
T m_ref
How many % to refine - 0-1 interval.
Definition gsHFitting.h:234
bool nextIteration_tdm(T tolerance, T err_threshold, index_t maxPcIter, T mu, T sigma, const std::vector< index_t > &interpIdx, tdm_method method, bool admissibleRef=false)
nextIteration_tdm: perform one iterazion of adaptive refinement with HDM fitting and with boundary co...
Definition gsHFitting.h:264
T setRefineThreshold(const std::vector< T > &errors)
Automatic set the refinement threshold.
Definition gsHFitting.h:674
std::vector< unsigned > m_ext
Size of the extension.
Definition gsHFitting.h:240
bool nextRefinement(T tolerance, T err_threshold, index_t maxPcIter=0, bool admissibleRef=false)
nextRefinement: One step of the refinement of iterativeRefine;
Definition gsHFitting.h:287
gsHFitting()
Default constructor.
void iterativeRefine(int iterations, T tolerance, T err_threshold=-1)
iterativeRefine: iteratively refine the basis
Definition gsHFitting.h:537
gsHBoxContainer< d > getMarkedHBoxesFromBasis_max(const gsHTensorBasis< d, T > &basis, const std::vector< T > &errors, const gsMatrix< T > ¶meters, T threshold, T extension)
getMarkedHBoxesFromBasis_max: returns the markd cells to refine admissibiliy.
Definition gsHFitting.h:734
gsHFitting(gsMatrix< T > const ¶m_values, gsMatrix< T > const &points, gsHTensorBasis< d, T > &basis, T refin, const std::vector< unsigned > &extension, T lambda=0)
gsHFitting: Main constructor of the h-fitting class
Definition gsHFitting.h:54
void setRefPercentage(double refPercent)
Sets the refinement percentage.
Definition gsHFitting.h:177
std::vector< index_t > getBoxes(const std::vector< T > &errors, const T threshold)
Returns boxes which define refinment area.
Definition gsHFitting.h:566
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 cells.
Definition gsHFitting.h:648
T m_lambda
Smoothing parameter.
Definition gsHFitting.h:237
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:211
const std::vector< unsigned > & get_extension() const
Returns the chosen cell extension.
Definition gsHFitting.h:171
bool nextIteration_pdm(T tolerance, T err_threshold, index_t maxPcIter, const std::vector< index_t > &interpIdx, bool admissibleRef=false)
nextIteration_pdm: perform one iterazion of adaptive refinement with PDM fitting and with boundary co...
Definition gsHFitting.h:276
bool nextIteration(T tolerance, T err_threshold, index_t maxPcIter=0)
nextIteration: perform one iterazion of adaptive refinement with PDM fitting without boundary constra...
Definition gsHFitting.h:254
T getRefPercentage() const
Return the refinement percentage.
Definition gsHFitting.h:165
virtual void appendBox(std::vector< index_t > &boxes, std::vector< index_t > &cells, const gsVector< T > ¶meter)
Appends a box around parameter to the boxes only if the box is not already in boxes.
Definition gsHFitting.h:589
Class representing a (scalar) hierarchical tensor basis of functions .
Definition gsHTensorBasis.h:75
Class for representing a knot vector.
Definition gsKnotVector.h:80
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
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Truncated hierarchical B-spline basis.
Definition gsTHBSplineBasis.h:36
A tensor product B-spline basis.
Definition gsTensorBSplineBasis.h:37
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
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define gsInfo
Definition gsDebug.h:43
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides declaration of data fitting algorithms by least squares approximation.
Provides a container for gsHBox.
Provides utility functions for gsHBox and gsHBoxContainer.
Provides gsHBox: smart boxes for HTensorBases.
Provides definition of HTensorBasis abstract interface.
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
The gsHBoxUtils provide basic utilities to modify HBoxes.
Definition gsHBoxUtils.h:46