[MOAB-dev] commit/MOAB: tautges: Damn, forgot these. Sigh.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Sep 12 16:36:16 CDT 2013
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/39078a3df007/
Changeset: 39078a3df007
Branch: master
User: tautges
Date: 2013-09-12 23:36:08
Summary: Damn, forgot these. Sigh.
Affected #: 2 files
diff --git a/src/BoundBox.cpp b/src/BoundBox.cpp
new file mode 100644
index 0000000..cb34330
--- /dev/null
+++ b/src/BoundBox.cpp
@@ -0,0 +1,78 @@
+#include "moab/Interface.hpp"
+#include "moab/BoundBox.hpp"
+
+namespace moab
+{
+ ErrorCode BoundBox::update(Interface &iface, const Range& elems)
+ {
+ ErrorCode rval;
+ bMin = CartVect(HUGE_VAL);
+ bMax = CartVect(-HUGE_VAL);
+
+ CartVect coords;
+ EntityHandle const *conn, *conn2;
+ int len, len2;
+ Range::const_iterator i;
+
+ // vertices
+ const Range::const_iterator elem_begin = elems.lower_bound( MBEDGE );
+ for (i = elems.begin(); i != elem_begin; ++i) {
+ rval = iface.get_coords( &*i, 1, coords.array() );
+ if (MB_SUCCESS != rval)
+ return rval;
+ update_min(coords.array());
+ update_max(coords.array());
+ }
+
+ // elements with vertex-handle connectivity list
+ const Range::const_iterator poly_begin = elems.lower_bound( MBPOLYHEDRON, elem_begin );
+ std::vector<EntityHandle> dum_vector;
+ for (i = elem_begin; i != poly_begin; ++i) {
+ rval = iface.get_connectivity( *i, conn, len, true, &dum_vector);
+ if (MB_SUCCESS != rval)
+ return rval;
+
+ for (int j = 0; j < len; ++j) {
+ rval = iface.get_coords( conn+j, 1, coords.array() );
+ if (MB_SUCCESS != rval)
+ return rval;
+ update_min(coords.array());
+ update_max(coords.array());
+ }
+ }
+
+ // polyhedra
+ const Range::const_iterator set_begin = elems.lower_bound( MBENTITYSET, poly_begin );
+ for (i = poly_begin; i != set_begin; ++i) {
+ rval = iface.get_connectivity( *i, conn, len, true );
+ if (MB_SUCCESS != rval)
+ return rval;
+
+ for (int j = 0; j < len; ++j) {
+ rval = iface.get_connectivity( conn[j], conn2, len2 );
+ for (int k = 0; k < len2; ++k) {
+ rval = iface.get_coords( conn2+k, 1, coords.array() );
+ if (MB_SUCCESS != rval)
+ return rval;
+ update_min(coords.array());
+ update_max(coords.array());
+ }
+ }
+ }
+
+ // sets
+ BoundBox box;
+ for (i = set_begin; i != elems.end(); ++i) {
+ Range tmp_elems;
+ rval = iface.get_entities_by_handle(*i, tmp_elems);
+ if (MB_SUCCESS != rval) return rval;
+ rval = box.update(iface, tmp_elems);
+ if (MB_SUCCESS != rval) return rval;
+
+ update(box);
+ }
+
+ return MB_SUCCESS;
+ }
+
+}
diff --git a/src/moab/BoundBox.hpp b/src/moab/BoundBox.hpp
new file mode 100644
index 0000000..9400944
--- /dev/null
+++ b/src/moab/BoundBox.hpp
@@ -0,0 +1,177 @@
+#ifndef BOUND_BOX_HPP
+#define BOUND_BOX_HPP
+
+#include "moab/Interface.hpp"
+#include "moab/CartVect.hpp"
+
+#include <cfloat>
+
+namespace moab {
+
+ class BoundBox {
+ public:
+ BoundBox() : bMin(DBL_MAX), bMax(-DBL_MAX) {}
+ BoundBox(const CartVect &min, const CartVect &max) :
+ bMin(min), bMax(max) {}
+ BoundBox(const double *corners);
+ ~BoundBox() {}
+
+ bool contains_point(const double *point, const double tol = 0.0) const;
+ bool contains_box(const BoundBox &b, const double tol = 0.0) const;
+ void compute_center(CartVect ¢er);
+ void update(const BoundBox &other_box);
+ void update(const double *coords);
+ ErrorCode update(Interface &iface, const Range& elems);
+ ErrorCode update(Interface &iface, const EntityHandle ent);
+ void update_min(const BoundBox &other_box);
+ void update_min(const double *coords);
+ void update_max(const BoundBox &other_box);
+ void update_max(const double *coords);
+
+ /** \brief Return the diagonal length of this box
+ */
+ double diagonal_length() const;
+
+ /** \brief Return the square of the diagonal length of this box
+ */
+ double diagonal_squared() const;
+
+ /** \brief Return square of distance from box, or zero if inside
+ * \param from_point Point from which you want distance_sq
+ */
+ double distance_squared(const double *from_point) const;
+
+ /** \brief Return distance from box, or zero if inside
+ * \param from_point Point from which you want distance
+ */
+ double distance(const double *from_point) const;
+
+ BoundBox &operator=(const BoundBox &from) {
+ bMin = from.bMin;
+ bMax = from.bMax;
+ return *this;
+ }
+ inline bool operator==(const BoundBox &box) const {
+ return (bMin == box.bMin && bMax == box.bMax);
+ }
+
+ CartVect bMin, bMax;
+ };
+
+ inline BoundBox::BoundBox(const double *corners)
+ {
+ // relies on CartVect being Plain Old Data, no virtual table
+ double *arr = bMin.array();
+ for (int i = 0; i < 6; i++)
+ arr[i] = corners[i];
+ }
+
+ inline bool BoundBox::contains_point(const double *point, const double tol) const {
+ if (point[0] < bMin[0]-tol || point[0] > bMax[0]+tol ||
+ point[1] < bMin[1]-tol || point[1] > bMax[1]+tol ||
+ point[2] < bMin[2]-tol || point[2] > bMax[2]+tol)
+ return false;
+ else return true;
+ }
+
+ inline bool BoundBox::contains_box(const BoundBox &b, const double tol) const {
+ if (b.bMin[0] < bMin[0]-tol || b.bMax[0] > bMax[0]+tol ||
+ b.bMin[1] < bMin[1]-tol || b.bMax[1] > bMax[1]+tol ||
+ b.bMin[2] < bMin[2]-tol || b.bMax[2] > bMax[2]+tol)
+ return false;
+
+ else return true;
+ }
+
+ inline void BoundBox::update(const BoundBox &other_box)
+ {
+ update_min(other_box);
+ update_max(other_box);
+ }
+
+ inline void BoundBox::update(const double *coords)
+ {
+ update_min(coords);
+ update_max(coords+3);
+ }
+
+ inline void BoundBox::update_min(const BoundBox &other_box)
+ {
+ bMin[0] = std::min(bMin[0], other_box.bMin[0]);
+ bMin[1] = std::min(bMin[1], other_box.bMin[1]);
+ bMin[2] = std::min(bMin[2], other_box.bMin[2]);
+ }
+
+ inline void BoundBox::update_min(const double *coords)
+ {
+ bMin[0] = std::min(bMin[0], coords[0]);
+ bMin[1] = std::min(bMin[1], coords[1]);
+ bMin[2] = std::min(bMin[2], coords[2]);
+ }
+
+ inline void BoundBox::update_max(const BoundBox &other_box)
+ {
+ bMax[0] = std::max(bMax[0], other_box.bMax[0]);
+ bMax[1] = std::max(bMax[1], other_box.bMax[1]);
+ bMax[2] = std::max(bMax[2], other_box.bMax[2]);
+ }
+
+ inline void BoundBox::update_max(const double *coords)
+ {
+ bMax[0] = std::max(bMax[0], coords[0]);
+ bMax[1] = std::max(bMax[1], coords[1]);
+ bMax[2] = std::max(bMax[2], coords[2]);
+ }
+
+ inline void BoundBox::compute_center(CartVect ¢er){
+ center = 0.5 * (bMin + bMax);
+ }
+
+ inline std::ostream &operator<<(std::ostream& out, const BoundBox &box) {
+ out << "Min: ";
+ out << box.bMin;
+ out << ", Max: ";
+ out << box.bMax;
+ return out;
+ }
+
+ inline ErrorCode BoundBox::update(Interface &iface, const EntityHandle ent)
+ {
+ Range tmp_range(ent, ent);
+ return update(iface, tmp_range);
+ }
+
+ inline double BoundBox::distance_squared(const double *from_point) const
+ {
+ double dist_sq = 0.0;
+ for (int i = 0; i < 3; ++i) {
+ if (from_point[i] < bMin[i])
+ dist_sq += (bMin[i] - from_point[i]) * (bMin[i] - from_point[i]);
+ else if (from_point[i] > bMax[i])
+ dist_sq += (bMax[i] - from_point[i]) * (bMax[i] - from_point[i]);
+ }
+ return dist_sq;
+ }
+
+ inline double BoundBox::distance(const double *from_point) const
+ {
+ double dist_sq = distance_squared(from_point);
+ return sqrt(dist_sq);
+ }
+
+ inline double BoundBox::diagonal_length() const
+ {
+ if (DBL_MAX == bMax[0] || DBL_MAX == bMax[1] || DBL_MAX == bMax[2] ||
+ DBL_MAX == bMin[0] || DBL_MAX == bMin[1] || DBL_MAX == bMin[2]) return DBL_MAX;
+ return (bMax - bMin).length();
+ }
+
+ inline double BoundBox::diagonal_squared() const
+ {
+ if (DBL_MAX == bMax[0] || DBL_MAX == bMax[1] || DBL_MAX == bMax[2] ||
+ DBL_MAX == bMin[0] || DBL_MAX == bMin[1] || DBL_MAX == bMin[2]) return DBL_MAX;
+ return (bMax - bMin).length_squared();
+ }
+}
+
+#endif
Repository URL: https://bitbucket.org/fathomteam/moab/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the moab-dev
mailing list