aboutsummaryrefslogtreecommitdiff
path: root/Carpet
diff options
context:
space:
mode:
Diffstat (limited to 'Carpet')
-rw-r--r--Carpet/CarpetLib/src/bbox.cc80
-rw-r--r--Carpet/CarpetLib/src/bbox.hh36
-rw-r--r--Carpet/CarpetLib/src/bboxset.cc45
-rw-r--r--Carpet/CarpetLib/src/bboxset.hh91
4 files changed, 177 insertions, 75 deletions
diff --git a/Carpet/CarpetLib/src/bbox.cc b/Carpet/CarpetLib/src/bbox.cc
index 482404b05..e2315ce90 100644
--- a/Carpet/CarpetLib/src/bbox.cc
+++ b/Carpet/CarpetLib/src/bbox.cc
@@ -1,3 +1,4 @@
+
#include <cassert>
#include <iostream>
#include <limits>
@@ -15,13 +16,13 @@ using namespace std;
// Accessors
template<class T, int D>
-T bbox<T,D>::size () const {
+typename bbox<T,D>::size_type bbox<T,D>::size () const {
if (empty()) return 0;
const vect<T,D> sh(shape()/stride());
#ifdef NDEBUG
- return prod(sh);
+ return prod(vect<size_type,D>(sh));
#else
- T sz = 1, max = numeric_limits<T>::max();
+ size_type sz = 1, max = numeric_limits<size_type>::max();
for (int d=0; d<D; ++d) {
assert (sh[d] <= max);
sz *= sh[d];
@@ -32,24 +33,50 @@ T bbox<T,D>::size () const {
}
// Queries
+
+// Containment
template<class T, int D>
bool bbox<T,D>::contains (const vect<T,D>& x) const {
- return all(x>=lower() && x<=upper());
+ return all(x>=lower() and x<=upper());
+}
+
+template<class T, int D>
+bool bbox<T,D>::is_contained_in (const bbox& b) const {
+ if (empty()) return true;
+ // no alignment check
+ return all(lower()>=b.lower() and upper()<=b.upper());
+}
+
+// Intersection
+template<class T, int D>
+bool bbox<T,D>::intersects (const bbox& b) const {
+ if (empty()) return false;
+ if (b.empty()) return false;
+ // no alignment check
+ return all(upper()>=b.lower() and lower()<=b.upper());
+}
+
+// Alignment check
+template<class T, int D>
+bool bbox<T,D>::is_aligned_with (const bbox& b) const {
+ return all(stride()==b.stride() and (lower()-b.lower()) % stride() == T(0));
}
// Operators
template<class T, int D>
bool bbox<T,D>::operator== (const bbox& b) const {
- if (empty() && b.empty()) return true;
+ if (empty() and b.empty()) return true;
assert (all(stride()==b.stride()));
- return all(lower()==b.lower() && upper()==b.upper());
+ return all(lower()==b.lower() and upper()==b.upper());
}
template<class T, int D>
bool bbox<T,D>::operator!= (const bbox& b) const {
- return ! (*this == b);
+ return not (*this == b);
}
+#if 0
+// Introduce an ordering on bboxes
template<class T, int D>
bool bbox<T,D>::operator< (const bbox& b) const {
// An arbitraty order: empty boxes come first, then sorted by lower
@@ -70,15 +97,11 @@ bool bbox<T,D>::operator< (const bbox& b) const {
}
return false;
}
-
-template<class T, int D>
-bool bbox<T,D>::operator> (const bbox& b) const {
- return b < *this;
-}
+#endif
template<class T, int D>
bool bbox<T,D>::operator<= (const bbox& b) const {
- return ! (b > *this);
+ return is_contained_in (b);
}
template<class T, int D>
@@ -86,32 +109,21 @@ bool bbox<T,D>::operator>= (const bbox& b) const {
return b <= *this;
}
-// Containment
template<class T, int D>
-bool bbox<T,D>::is_contained_in (const bbox& b) const {
- if (empty()) return true;
- // no alignment check
- return all(lower()>=b.lower() && upper()<=b.upper());
-}
-
-// Intersection
-template<class T, int D>
-bool bbox<T,D>::intersects (const bbox& b) const {
- // no alignment check
- return all(upper()>=b.lower() && lower()<=b.upper());
+bool bbox<T,D>::operator< (const bbox& b) const {
+ return *this <= b and *this != b;
}
-// Alignment check
template<class T, int D>
-bool bbox<T,D>::is_aligned_with (const bbox& b) const {
- return all(stride()==b.stride() && (lower()-b.lower()) % stride() == T(0));
+bool bbox<T,D>::operator> (const bbox& b) const {
+ return b < *this;
}
// Expand the bbox a little by multiples of the stride
template<class T, int D>
bbox<T,D> bbox<T,D>::expand (const vect<T,D>& lo, const vect<T,D>& hi) const {
// Allow expansion only into directions where the extent is not negative
- assert (all(lower()<=upper() || (lo==T(0) && hi==T(0))));
+ assert (all(lower()<=upper() or (lo==T(0) and hi==T(0))));
const vect<T,D> str = stride();
const vect<T,D> lb = lower() - lo * str;
const vect<T,D> ub = upper() + hi * str;
@@ -204,19 +216,21 @@ void bbox<T,D>::input (istream& is) {
skipws (is);
if (is.peek() == '/') {
consume (is, '/');
- T lower_dummy;
+ vect<T,D> lower_dummy;
is >> lower_dummy;
skipws (is);
consume (is, ':');
- T upper_dummy;
+ vect<T,D> upper_dummy;
is >> upper_dummy;
skipws (is);
consume (is, '/');
- T shape_dummy;
+ vect<T,D> shape_dummy;
is >> shape_dummy;
+ skipws (is);
consume (is, '/');
- T size_dummy;
+ size_type size_dummy;
is >> size_dummy;
+ assert (is.good());
skipws (is);
}
consume (is, ')');
diff --git a/Carpet/CarpetLib/src/bbox.hh b/Carpet/CarpetLib/src/bbox.hh
index 92563651b..bc9d4555b 100644
--- a/Carpet/CarpetLib/src/bbox.hh
+++ b/Carpet/CarpetLib/src/bbox.hh
@@ -84,6 +84,10 @@ public:
/** Get upper bound. */
vect<T,D> upper () const { return _upper; }
+ /** Get bounds. */
+ vect<vect<T,D>,2> bounds () const
+ { return vect<vect<T,D>,2> (_lower, _upper); }
+
/** Get stride. */
vect<T,D> stride () const { return _stride; }
@@ -96,20 +100,33 @@ public:
}
/** Return the size, which is the number of contained points. */
- T size () const;
+ // T size () const;
+ typedef long long int size_type;
+ size_type size () const;
// Queries
/** Find out whether the bbox contains the point x. */
bool contains (const vect<T,D>& x) const;
+ /** Find out whether this bbox is contained in the bbox b. */
+ bool is_contained_in (const bbox& b) const;
+
+ /** Find out whether this bbox intersects the bbox b. */
+ bool intersects (const bbox& b) const;
+
+ /** Find out whether this bbox is aligned with the bbox b.
+ ("aligned" means that both bboxes have the same stride and that
+ their boundaries are commensurate.) */
+ bool is_aligned_with (const bbox& b) const;
+
// Operators
bool operator== (const bbox& b) const;
bool operator!= (const bbox& b) const;
- bool operator< (const bbox& b) const;
- bool operator> (const bbox& b) const;
bool operator<= (const bbox& b) const;
bool operator>= (const bbox& b) const;
+ bool operator< (const bbox& b) const;
+ bool operator> (const bbox& b) const;
/** Calculate the intersection (the set of common points) with the
bbox b. */
@@ -121,19 +138,10 @@ public:
return bbox(lo,up,stride());
}
- /** Find out whether this bbox is contained in the bbox b. */
- bool is_contained_in (const bbox& b) const;
-
- /** Find out whether this bbox intersects the bbox b. */
- bool intersects (const bbox& b) const;
-
- /** Find out whether this bbox is aligned with the bbox b.
- ("aligned" means that both bboxes have the same stride and that
- their boundaries are commesurate.) */
- bool is_aligned_with (const bbox& b) const;
-
/** Expand (enlarge) the bbox by multiples of the stride. */
bbox expand (const vect<T,D>& lo, const vect<T,D>& hi) const;
+ bbox expand (const vect<vect<T,D>,2>& lohi) const
+ { return expand (lohi[0], lohi[1]); }
/** Find the smallest b-compatible box around this bbox.
("compatible" means having the same stride.) */
diff --git a/Carpet/CarpetLib/src/bboxset.cc b/Carpet/CarpetLib/src/bboxset.cc
index 7383e6bc1..8e7bf1420 100644
--- a/Carpet/CarpetLib/src/bboxset.cc
+++ b/Carpet/CarpetLib/src/bboxset.cc
@@ -32,8 +32,23 @@ bboxset<T,D>::bboxset (const bboxset& s): bs(s.bs) {
}
template<class T, int D>
-bboxset<T,D>::bboxset (const bset& bs_): bs(bs_) {
- assert (invariant());
+bboxset<T,D>::bboxset (const list<box>& lb) {
+ for (typename list<box>::const_iterator
+ li = lb.begin(); li != lb.end(); ++ li)
+ {
+ *this |= *li;
+ }
+ normalize();
+}
+
+template<class T, int D>
+bboxset<T,D>::bboxset (const vector<list<box> >& vlb) {
+ for (typename vector<list<box> >::const_iterator
+ vli = vlb.begin(); vli != vlb.end(); ++ vli)
+ {
+ *this |= bboxset (*vli);
+ }
+ normalize();
}
@@ -64,7 +79,7 @@ void bboxset<T,D>::normalize ()
assert (invariant());
bboxset const oldbs = * this;
- int const oldsize = this->size();
+ size_type const oldsize = this->size();
// Split all bboxes into small pieces which have all their
// boundaries aligned.
@@ -94,10 +109,6 @@ void bboxset<T,D>::normalize ()
int const bstr = b.stride()[d];
int const blo = b.lower()[d];
int const bhi = b.upper()[d] + bstr;
-// typename buf::const_iterator const ilo
-// = find (sbnds.begin(), sbnds.end(), blo);
-// typename buf::const_iterator const ihi
-// = find (sbnds.begin(), sbnds.end(), bhi);
typename buf::const_iterator const ilo
= lower_bound (sbnds.begin(), sbnds.end(), blo);
typename buf::const_iterator const ihi
@@ -182,7 +193,7 @@ void bboxset<T,D>::normalize ()
assert (invariant());
}
- int const newsize = this->size();
+ size_type const newsize = this->size();
assert (*this == oldbs);
assert (newsize <= oldsize);
@@ -192,11 +203,11 @@ void bboxset<T,D>::normalize ()
// Accessors
template<class T, int D>
-T bboxset<T,D>::size () const {
- T s=0;
+typename bboxset<T,D>::size_type bboxset<T,D>::size () const {
+ size_type s=0;
for (const_iterator bi=begin(); bi!=end(); ++bi) {
- const T bsz = (*bi).size();
- assert (numeric_limits<T>::max() - bsz >= s);
+ const size_type bsz = (*bi).size();
+ assert (numeric_limits<size_type>::max() - bsz >= s);
s += bsz;
}
return s;
@@ -237,16 +248,6 @@ bboxset<T,D> bboxset<T,D>::operator+ (const bboxset& s) const {
return r;
}
-template<class T, int D>
-bboxset<T,D> bboxset<T,D>::plus (const bbox<T,D>& b1, const bbox<T,D>& b2) {
- return bboxset(b1) + b2;
-}
-
-template<class T, int D>
-bboxset<T,D> bboxset<T,D>::plus (const bbox<T,D>& b, const bboxset<T,D>& s) {
- return s + b;
-}
-
// Union
diff --git a/Carpet/CarpetLib/src/bboxset.hh b/Carpet/CarpetLib/src/bboxset.hh
index 5ad2dea94..602f8139c 100644
--- a/Carpet/CarpetLib/src/bboxset.hh
+++ b/Carpet/CarpetLib/src/bboxset.hh
@@ -5,6 +5,7 @@
#include <iostream>
#include <list>
#include <set>
+#include <vector>
#include "bbox.hh"
#include "defs.hh"
@@ -55,7 +56,9 @@ public:
bboxset ();
bboxset (const box& b);
bboxset (const bboxset& s);
- bboxset (const bset& bs);
+
+ bboxset (const list<box>& lb);
+ bboxset (const vector<list<box> >& vlb);
// Invariant
bool invariant () const;
@@ -65,7 +68,9 @@ public:
// Accessors
bool empty () const { return bs.empty(); }
- T size () const;
+ // T size () const;
+ typedef typename box::size_type size_type;
+ size_type size () const;
int setsize () const { return bs.size(); }
// Add (bboxes that don't overlap)
@@ -89,8 +94,6 @@ public:
bboxset& add_transfer (bboxset& s);
bboxset operator+ (const box& b) const;
bboxset operator+ (const bboxset& s) const;
- static bboxset plus (const box& b1, const box& b2);
- static bboxset plus (const box& b, const bboxset& s);
// Union
bboxset& operator|= (const box& b);
@@ -144,12 +147,12 @@ public:
template<class T,int D>
inline bboxset<T,D> operator+ (const bbox<T,D>& b1, const bbox<T,D>& b2) {
- return bboxset<T,D>::plus(b1,b2);
+ return bboxset<T,D>(b1) + bboxset<T,D>(b2);
}
template<class T,int D>
inline bboxset<T,D> operator+ (const bbox<T,D>& b, const bboxset<T,D>& s) {
- return bboxset<T,D>::plus(b,s);
+ return bboxset<T,D>(b) + s;
}
template<class T,int D>
@@ -164,6 +167,82 @@ inline bboxset<T,D> operator- (const bbox<T,D>& b, const bboxset<T,D>& s) {
+template<class T,int D>
+inline bboxset<T,D> operator| (const bbox<T,D>& b, const bboxset<T,D>& s) {
+ return s | b;
+}
+
+template<class T,int D>
+inline bboxset<T,D> operator& (const bbox<T,D>& b, const bboxset<T,D>& s) {
+ return s & b;
+}
+
+
+
+template<class T,int D>
+inline bool operator== (const bbox<T,D>& b, const bboxset<T,D>& s) {
+ return bboxset<T,D>(b) == s;
+}
+
+template<class T,int D>
+inline bool operator!= (const bbox<T,D>& b, const bboxset<T,D>& s) {
+ return bboxset<T,D>(b) != s;
+}
+
+template<class T,int D>
+inline bool operator< (const bbox<T,D>& b, const bboxset<T,D>& s) {
+ return bboxset<T,D>(b) < s;
+}
+
+template<class T,int D>
+inline bool operator<= (const bbox<T,D>& b, const bboxset<T,D>& s) {
+ return bboxset<T,D>(b) <= s;
+}
+
+template<class T,int D>
+inline bool operator> (const bbox<T,D>& b, const bboxset<T,D>& s) {
+ return bboxset<T,D>(b) > s;
+}
+
+template<class T,int D>
+inline bool operator>= (const bbox<T,D>& b, const bboxset<T,D>& s) {
+ return bboxset<T,D>(b) >= s;
+}
+
+
+
+template<class T,int D>
+inline bool operator== (const bboxset<T,D>& s, const bbox<T,D>& b) {
+ return s == bboxset<T,D>(b);
+}
+
+template<class T,int D>
+inline bool operator!= (const bboxset<T,D>& s, const bbox<T,D>& b) {
+ return s != bboxset<T,D>(b);
+}
+
+template<class T,int D>
+inline bool operator< (const bboxset<T,D>& s, const bbox<T,D>& b) {
+ return s < bboxset<T,D>(b);
+}
+
+template<class T,int D>
+inline bool operator<= (const bboxset<T,D>& s, const bbox<T,D>& b) {
+ return s <= bboxset<T,D>(b);
+}
+
+template<class T,int D>
+inline bool operator> (const bboxset<T,D>& s, const bbox<T,D>& b) {
+ return s > bboxset<T,D>(b);
+}
+
+template<class T,int D>
+inline bool operator>= (const bboxset<T,D>& s, const bbox<T,D>& b) {
+ return s >= bboxset<T,D>(b);
+}
+
+
+
// Output
template<class T,int D>
inline ostream& operator<< (ostream& os, const bboxset<T,D>& s) {