21 template <
short_t d,
class T>
22 typename gsHBox<d, T>::SortedContainer gsHBoxUtils<d,T>::Sort(
const Container & container)
24 SortedContainer scontainer(container.begin(), container.end());
27 std::sort(scontainer.begin(),scontainer.end(),gsHBoxCompare<d,T>());
32 template <
short_t d,
class T>
33 typename gsHBox<d, T>::Container gsHBoxUtils<d,T>::Unique(
const Container & container)
35 SortedContainer scontainer = gsHBoxUtils<d,T>::Sort(container);
38 typename SortedContainer::iterator it = std::unique(scontainer.begin(),scontainer.end(),gsHBoxEqual<d,T>());
40 Container result(scontainer.begin(),scontainer.end());
44 template <
short_t d,
class T>
45 typename gsHBox<d, T>::HContainer gsHBoxUtils<d,T>::Unique(
const HContainer & container)
47 HContainer result(container.size());
48 for (
size_t k=0; k!=container.size(); k++)
49 result[k] = gsHBoxUtils<d,T>::Unique(container[k]);
53 template <
short_t d,
class T>
54 gsHBoxContainer<d, T> gsHBoxUtils<d,T>::Unique(
const gsHBoxContainer<d,T> & container)
56 HContainer result = gsHBoxUtils<d,T>::Unique(container.boxes());
57 return gsHBoxContainer<d,T>(result);
60 template <
short_t d,
class T>
61 typename gsHBox<d, T>::Container gsHBoxUtils<d,T>::Union(
const Container & container1,
const Container & container2)
63 SortedContainer sortedResult;
65 SortedContainer scontainer1 = gsHBoxUtils<d,T>::Sort(container1);
66 SortedContainer scontainer2 = gsHBoxUtils<d,T>::Sort(container2);
68 sortedResult.reserve(scontainer1.size() + scontainer2.size());
69 if (scontainer1.size()!=0 && scontainer2.size()!=0)
71 std::set_union( scontainer1.begin(),scontainer1.end(),
72 scontainer2.begin(),scontainer2.end(),
73 std::inserter(sortedResult,sortedResult.begin()),
74 gsHBoxCompare<d,T>());
76 else if (scontainer1.size()!=0 && container2.size()==0)
77 sortedResult.insert(sortedResult.end(),scontainer1.begin(),scontainer1.end());
78 else if (scontainer1.size()==0 && container2.size()!=0)
79 sortedResult.insert(sortedResult.end(),scontainer2.begin(),scontainer2.end());
82 Container result(sortedResult.begin(),sortedResult.end());
87 template <
short_t d,
class T>
88 typename gsHBox<d, T>::HContainer gsHBoxUtils<d,T>::Union(
const HContainer & container1,
const HContainer & container2)
90 HContainer result, region1, region2;
95 index_t lmax = std::max(region1.size(),region2.size());
100 for (
index_t l = 0; l!=lmax; l++)
101 result[l] = gsHBoxUtils<d,T>::Union(region1[l],region2[l]);
106 template <
short_t d,
class T>
107 gsHBoxContainer<d, T> gsHBoxUtils<d,T>::Union(
const gsHBoxContainer<d,T> & container1,
const gsHBoxContainer<d,T> & container2)
110 HContainer region1(container1.boxes());
111 HContainer region2(container2.boxes());
113 index_t lmax = std::max(region1.size(),region2.size());
114 region1.resize(lmax);
115 region2.resize(lmax);
118 for (
index_t l = 0; l!=lmax; l++)
119 result[l] = gsHBoxUtils<d,T>::Union(region1[l],region2[l]);
121 return gsHBoxContainer<d,T>(result);
125 template <
short_t d,
class T>
126 typename gsHBox<d, T>::Container gsHBoxUtils<d,T>::Difference(
const Container & container1,
const Container & container2)
128 SortedContainer sortedResult;
130 SortedContainer scontainer1 = gsHBoxUtils<d,T>::Sort(container1);
131 SortedContainer scontainer2 = gsHBoxUtils<d,T>::Sort(container2);
133 sortedResult.reserve(scontainer1.size());
136 std::set_difference(scontainer1.begin(),scontainer1.end(),
137 scontainer2.begin(),scontainer2.end(),
138 std::inserter(sortedResult,sortedResult.begin()),
139 gsHBoxCompare<d,T>());
147 Container result(sortedResult.begin(),sortedResult.end());
165 template <
short_t d,
class T>
166 typename gsHBox<d, T>::HContainer gsHBoxUtils<d,T>::Difference(
const HContainer & container1,
const HContainer & container2)
168 HContainer result, region1, region2;
170 region1 = container1;
171 region2 = container2;
173 index_t lmax = std::max(region1.size(),region2.size());
174 region1.resize(lmax);
175 region2.resize(lmax);
178 for (
index_t l = 0; l!=lmax; l++)
179 result[l] = gsHBoxUtils<d,T>::Difference(region1[l],region2[l]);
184 template <
short_t d,
class T>
185 gsHBoxContainer<d, T> gsHBoxUtils<d,T>::Difference(
const gsHBoxContainer<d,T> & container1,
const gsHBoxContainer<d,T> & container2)
188 HContainer region1(container1.boxes());
189 HContainer region2(container2.boxes());
191 index_t lmax = std::max(region1.size(),region2.size());
192 region1.resize(lmax);
193 region2.resize(lmax);
196 for (
index_t l = 0; l!=lmax; l++)
197 result[l] = gsHBoxUtils<d,T>::Difference(region1[l],region2[l]);
199 return gsHBoxContainer<d,T>(result);
213 template <
short_t d,
class T>
219 for (cIterator it1=container1.begin(); it1!=container1.end(); it1++)
220 for (cIterator it2=container2.begin(); it2!=container2.end(); it2++)
222 b1in2 = it1->contains(*it2);
223 b2in1 = it2->contains(*it1);
226 result.push_back(*it1);
227 else if (b1in2 && !b2in1)
228 result.push_back(*it2);
229 else if (!b1in2 && b2in1)
230 result.push_back(*it1);
240 template <
short_t d,
class T>
246 for (cIterator it1=container1.begin(); it1!=container1.end(); it1++)
247 for (cIterator it2=container2.begin(); it2!=container2.end(); it2++)
249 b1in2 = it1->contains(*it2);
252 result.push_back(*it2);
272 template <
short_t d,
class T>
275 SortedContainer sortedResult;
280 sortedResult.reserve(scontainer1.size());
283 std::set_intersection( scontainer1.begin(),scontainer1.end(),
284 scontainer2.begin(),scontainer2.end(),
285 std::inserter(sortedResult,sortedResult.begin()),
286 gsHBoxCompare<d,T>());
294 Container result(sortedResult.begin(),sortedResult.end());
326 template <
short_t d,
class T>
330 for (cHIterator hit = container.begin(); hit!=container.end(); hit++)
331 for (cIterator it=hit->begin(); it!=hit->end(); it++)
332 result.push_back(*it);
337 template <
short_t d,
class T>
338 typename gsHBox<d,T>::HContainer gsHBoxUtils<d,T>::Container2HContainer(
const Container & container )
340 HContainer result(1);
341 for (cIterator it=container.begin(); it!=container.end(); it++)
343 if (result.size() <
static_cast<unsigned>(it->level() + 1))
344 result.resize(it->level()+1);
346 result[it->level()].push_back(*it);
351 template <
short_t d,
class T>
356 for (cHIterator hit = container.begin(); hit!=container.end(); hit++)
357 for (cIterator it = hit->begin(); it!=hit->end(); it++)
359 result.push_back(*it);
365 template <
short_t d,
class T>
371 for (cHIterator hit = container.begin(); hit!=container.end(); hit++)
372 for (cIterator it = hit->begin(); it!=hit->end(); it++)
374 boxes = it->toUnitBoxes();
375 for (cIterator boxIt = boxes.begin(); boxIt != boxes.end(); boxIt++)
376 result.push_back(*boxIt);
382 template <
short_t d,
class T>
385 HContainer result(container.size());
386 HIterator resIt = result.begin();
389 for (cHIterator hit = container.begin(); hit!=container.end(); hit++, resIt++)
390 for (cIterator it = hit->begin(); it!=hit->end(); it++)
392 boxes = it->toUnitBoxes();
393 for (cIterator boxIt = boxes.begin(); boxIt != boxes.end(); boxIt++)
394 resIt->push_back(*boxIt);
400 template <
short_t d,
class T>
406 template <
short_t d,
class T>
413 template <
short_t d,
class T>
419 template <
short_t d,
class T>
426 template <
short_t d,
class T>
427 template<gsHNeighborhood _mode>
428 typename std::enable_if<_mode==gsHNeighborhood::T || _mode==gsHNeighborhood::H, typename gsHBoxUtils<d, T>::HContainer>::type
431 HContainer marked_copy = marked;
432 Container marked_l = marked[lvl];
436 for (Iterator it = marked_l.begin(); it!=marked_l.end(); it++)
438 neighbors.
add(it->template getNeighborhood<_mode>(m));
442 if (neighbors.
boxes().size()!=0)
444 marked_k = marked_copy[k];
445 gsHBoxContainer<d,T> boxUnion = gsHBoxUtils<d,T>::Union(neighbors,gsHBoxContainer<d,T>(marked_k));
446 marked_copy[k] = boxUnion.getActivesOnLevel(k);
447 marked_copy = gsHBoxUtils<d,T>::_markRecursive<_mode>(marked_copy,k,m);
452 template <
short_t d,
class T>
453 template<gsHNeighborhood _mode>
454 typename std::enable_if<_mode!=gsHNeighborhood::T && _mode!=gsHNeighborhood::H, typename gsHBoxUtils<d, T>::HContainer>::type
460 template <
short_t d,
class T>
461 template<gsHNeighborhood _mode>
465 for (
size_t l = 0; l!=unitBoxes.size(); l++)
466 unitBoxes = gsHBoxUtils<d,T>::_markRecursive<_mode>(unitBoxes,l,m);
468 unitBoxes = gsHBoxUtils<d,T>::Unique(unitBoxes);
472 template <
short_t d,
class T>
473 template<gsHNeighborhood _mode>
476 HContainer unitBoxes = gsHBoxUtils<d,T>::Container2HContainer(marked.toUnitBoxes());
477 return gsHBoxUtils<d,T>::markAdmissible<_mode>(unitBoxes,m);
493 template <
short_t d,
class T>
498 for (cHIterator hit = marked.begin(); hit!=marked.end(); hit++)
502 NHtype = gsHBoxUtils<d,T>::neighborhoodType(hit->front());
508 if (NHtype==gsHNeighborhood::T)
509 result = gsHBoxUtils<d,T>::markAdmissible<gsHNeighborhood::T>(marked,m);
510 else if (NHtype==gsHNeighborhood::H)
511 result = gsHBoxUtils<d,T>::markAdmissible<gsHNeighborhood::H>(marked,m);
513 GISMO_ERROR(
"Basis type should be gsTHBSplineBasis or gsHBSplineBasis");
517 template <
short_t d,
class T>
521 if (
dynamic_cast<const gsTHBSplineBasis<d,T>*
>(&marked.basis()))
522 result = gsHBoxUtils<d,T>::markAdmissible<gsHNeighborhood::T>(marked,m);
523 else if (
dynamic_cast<const gsHBSplineBasis<d,T>*
>(&marked.basis()))
524 result = gsHBoxUtils<d,T>::markAdmissible<gsHNeighborhood::H>(marked,m);
526 GISMO_ERROR(
"Basis type should be gsTHBSplineBasis or gsHBSplineBasis");
530 template <
short_t d,
class T>
531 bool gsHBoxUtils<d, T>::allActive(
const Container & elements)
534 for (cIterator it=elements.begin(); it!=elements.end() && check; it++)
536 check &= it->isActive();
541 template <
short_t d,
class T>
542 bool gsHBoxUtils<d, T>::allActive(
const HContainer & elements)
545 for (cHIterator hit = elements.begin(); hit!=elements.end() && check; hit++)
546 check &= allActive(*hit);
550 template <
short_t d,
class T>
551 gsHNeighborhood gsHBoxUtils<d, T>::neighborhoodType(
const gsHBox<d,T> & box )
553 if (
dynamic_cast<const gsTHBSplineBasis<d,T>*
>(&box.basis()))
554 return gsHNeighborhood::T;
555 else if (
dynamic_cast<const gsHBSplineBasis<d,T>*
>(&box.basis()))
556 return gsHNeighborhood::H;
558 GISMO_ERROR(
"Neighborhood type cannot be inferred. Is the basis related to the HBox a gsHTensorBasis?");
561 template <
short_t d,
class T>
562 bool gsHBoxCompare<d,T>::operator()(
const gsHBox<d,T> & a,
const gsHBox<d,T> & b)
const
565 (a.patch() < b.patch())
567 ((a.patch() == b.patch()) &&
568 (a.level() < b.level()) )
570 ((a.patch() == b.patch()) &&
571 (a.level() == b.level()) &&
572 std::lexicographical_compare( a.lowerIndex().begin(), a.lowerIndex().end(),
573 b.lowerIndex().begin(), b.lowerIndex().end()) )
575 ((a.patch() == b.patch()) &&
576 (a.level() == b.level()) &&
577 (a.lowerIndex() == b.lowerIndex()) &&
578 std::lexicographical_compare( a.upperIndex().begin(), a.upperIndex().end(),
579 b.upperIndex().begin(), b.upperIndex().end()) );
582 template <
short_t d,
class T>
583 bool gsHBoxEqual<d,T>::operator()(
const gsHBox<d,T> & a,
const gsHBox<d,T> & b)
const
614 template <
short_t d,
class T>
615 bool gsHBoxContains<d,T>::operator()(
const gsHBox<d,T> & a,
const gsHBox<d,T> & b)
const
618 res &= a.level() <= b.level();
622 for (
index_t i=0; i!=d && res; i++)
624 res &= a.lowerIndex().at(i) >= b.getAncestor(a.level()).lowerIndex().at(i);
625 res &= a.upperIndex().at(i) <= b.getAncestor(a.level()).upperIndex().at(i);
647 template <
short_t d,
class T>
648 bool gsHBoxIsContained<d,T>::operator()(
const gsHBox<d,T> & a,
const gsHBox<d,T> & b)
const
651 res &= a.level() >= b.level();
655 for (
index_t i=0; i!=d && res; i++)
657 res &= a.getAncestor(b.level()).lowerIndex().at(i) >= b.lowerIndex().at(i);
658 res &= a.getAncestor(b.level()).upperIndex().at(i) <= b.upperIndex().at(i);
T distance(gsMatrix< T > const &A, gsMatrix< T > const &B, index_t i=0, index_t j=0, bool cols=false)
compute a distance between the point number in the set and the point number <j> in the set ; by def...
static std::enable_if< _mode==gsHNeighborhood::T||_mode==gsHNeighborhood::H, HContainer >::type _markRecursive(const HContainer &marked, index_t lvl, index_t m)
Marks Recursively.
static Container toUnitBoxes(const HContainer &container)
Transforms the boxes in container as unit boxes.
Definition: gsHBoxUtils.hpp:366
static Container toContainer(const HContainer &container)
Returns a container representation of the object.
Definition: gsHBoxUtils.hpp:352
This class provides a Hierarchical Box (gsHBox)
Definition: gsHBox.h:54
#define index_t
Definition: gsConfig.h:32
static HContainer markTadmissible(const HContainer &marked, index_t m)
Performs T-admissible refinement.
Definition: gsHBoxUtils.hpp:401
HContainer & boxes()
Returns a heirarchical container with the boxes stored in the container.
Definition: gsHBoxContainer.h:123
The Hierarchical Box Container provides a container for gsHBox objects.
Definition: gsHBoxContainer.h:39
Provides declaration of THBSplineBasis class.
static gsHBox< d, T >::Container Intersection(const Container &container1, const Container &container2)
Performs an intersection. Keeps the smallest boxes in overlapping regions, can also intersect partial...
Definition: gsHBoxUtils.hpp:214
void add(const gsHBox< d, T > &box)
Adds a single box.
Definition: gsHBoxContainer.hpp:121
static HContainer markAdmissible(const gsHBox< d, T > &marked, index_t m)
Performs H-admissible refinement.
static HContainer markHadmissible(const HContainer &marked, index_t m)
Performs H-admissible refinement.
Definition: gsHBoxUtils.hpp:414
static gsHBox< d, T >::Container ExactIntersection(const Container &container1, const Container &container2)
Performs an intersection; only keeps the boxes that are EXACTLY the same (also level is the same) ...
Definition: gsHBoxUtils.hpp:273
gsHNeighborhood
The gsHNeighborhood is a struct that classifies the type of admissible refinement.
Definition: gsHBoxUtils.h:25
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
static HContainer toUnitHBoxes(const HContainer &container)
Transforms the boxes in container as unit boxes.
Definition: gsHBoxUtils.hpp:383
The gsHBoxUtils provide basic utilities to modify HBoxes.
Definition: gsHBoxUtils.h:45
Provides declaration of HBSplineBasis class.
Provides gsHBox: smart boxes for HTensorBases.