8#ifndef IMPALGEBRA_BOUNDING_BOX_D_H
9#define IMPALGEBRA_BOUNDING_BOX_D_H
11#include <IMP/algebra/algebra_config.h>
14#include "internal/utility.h"
16#include <cereal/access.hpp>
18IMPALGEBRA_BEGIN_NAMESPACE
30 for (
int i = 0; i < D; ++i) {
31 b_[0][i] = std::numeric_limits<double>::max();
32 b_[1][i] = -std::numeric_limits<double>::max();
49#if defined(IMP_SWIG_WRAPPER)
55 <<
"with a variable dimension bounding box.");
63 <<
"with a variable dimension bounding box.");
65 for (
unsigned int i = 0; i < d; ++i) {
66 lb[i] = std::numeric_limits<double>::max();
67 ub[i] = -std::numeric_limits<double>::max();
77 for (
unsigned int i = 0; i < lb.get_dimension(); ++i) {
91 for (
unsigned int j = 0; j < points.size(); j++) {
96 unsigned int get_dimension()
const {
97 return get_corner_0().get_dimension();
102 for (
unsigned int i = 0; i < get_dimension(); ++i) {
103 b_[0][i] = std::min(o.get_corner_0()[i],
get_corner_0()[i]);
104 b_[1][i] = std::max(o.get_corner_1()[i],
get_corner_1()[i]);
111 for (
unsigned int i = 0; i < get_dimension(); ++i) {
112 b_[0][i] = std::min(o[i], b_[0][i]);
113 b_[1][i] = std::max(o[i], b_[1][i]);
120 for (
unsigned int i = 0; i < get_dimension(); ++i) {
121 b_[0][i] = b_[0][i] - o;
122 b_[1][i] = b_[1][i] + o;
163 for (
unsigned int i = 0; i < get_dimension(); ++i) {
180 friend class cereal::access;
182 template<
class Archive>
void serialize(Archive &ar) {
190 for (
unsigned int i = 0; i < bb.get_dimension(); ++i) {
191 v *= bb.get_corner_1()[i] - bb.get_corner_0()[i];
198 return (g.get_corner_1()[0] - g.get_corner_0()[0]) *
199 (g.get_corner_1()[1] - g.get_corner_0()[1]) *
200 (g.get_corner_1()[2] - g.get_corner_0()[2]),
205template <
unsigned int D>
218template <
unsigned int D>
237 "Dimensions of bounding boxes don't match.");
238 for (
unsigned int i = 0; i < a.get_dimension(); ++i) {
239 if (a.get_corner_0()[i] > b.get_corner_1()[i]) {
242 if (b.get_corner_0()[i] > a.get_corner_1()[i]) {
258 for (
unsigned int i = 0; i < a.get_dimension(); ++i) {
259 if (a.get_corner_0()[i] > b.get_corner_0()[i]) {
260 ic0[i] = a.get_corner_0()[i];
262 ic0[i] = b.get_corner_0()[i];
266 for (
unsigned int i = 0; i < a.get_dimension(); ++i) {
267 if (a.get_corner_1()[i] < b.get_corner_1()[i]) {
268 ic1[i] = a.get_corner_1()[i];
270 ic1[i] = b.get_corner_1()[i];
290 double e = a.get_corner_1()[0] - a.get_corner_0()[0];
291 for (
unsigned int i = 1; i < a.get_dimension(); ++i) {
292 double ce = a.get_corner_1()[0] - a.get_corner_0()[0];
304 ret[0] = bb.get_corner_0();
305 ret[1] = bb.get_corner_1();
309 unsigned int dim = bb.get_dimension();
313 for (
unsigned int m = 0; m < (1U << dim); ++m) {
315 for (
unsigned int j = 0; j < dim; ++j) {
316 if (m & (1U << (dim - 1 - j))) {
317 cur[j] = bb.get_corner_1()[j];
325 for (
int i = 0; i < D - 1; ++i) {
326 c0[i] = bb.get_corner_0()[i];
327 c1[i] = bb.get_corner_1()[i];
332 for (
unsigned int i = 0; i < recurse.size(); ++i) {
334 for (
int j = 0; j < D - 1; ++j) {
335 cur[j] = recurse[i][j];
337 cur[D - 1] = bb.get_corner_0()[D - 1];
339 cur[D - 1] = bb.get_corner_1()[D - 1];
348 static const IntPair edges[12] = {
349 IntPair(0, 1), IntPair(0, 2), IntPair(0, 4), IntPair(1, 3),
350 IntPair(1, 5), IntPair(2, 3), IntPair(2, 6), IntPair(3, 7),
351 IntPair(4, 5), IntPair(4, 6), IntPair(5, 7), IntPair(6, 7)};
352 static IntPairs ret(edges, edges + 12);
356IMPALGEBRA_END_NAMESPACE
#define IMP_NOT_IMPLEMENTED
Use this to mark that the method is not implemented yet.
#define IMP_IF_CHECK(level)
Execute the code block if a certain level checks are on.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
A Cartesian vector in D-dimensions.
A more IMP-like version of the std::vector.
An axis-aligned bounding box.
BoundingBoxD(unsigned int d)
Create an empty bounding box.
const VectorD< D > & get_corner_0() const
BoundingBoxD(const Vector< VectorD< D > > &points)
Creating a bounding box from a set of points.
bool get_contains(const BoundingBoxD &bb) const
True if the input bounding box is completely contained within this one.
BoundingBoxD(const VectorD< D > &lb, const VectorD< D > &ub)
Make from the lower and upper corners.
BoundingBoxD()
Create an empty bounding box.
const BoundingBoxD< D > operator+(const O &o) const
Return a bounding box grown by o on all sides.
const BoundingBoxD< D > operator+(const BoundingBoxD< D > &o) const
Returning a bounding box containing both.
const BoundingBoxD< D > & operator+=(const BoundingBoxD< D > &o)
const BoundingBoxD< D > & operator+=(double o)
Grow the bounding box by o on all sizes.
const VectorD< D > & get_corner(unsigned int i) const
For 0 return lower corner and for 1, the upper corner.
const BoundingBoxD< D > & operator+=(const VectorD< D > &o)
Extend the current bounding box to include the point.
bool get_contains(const VectorD< D > &o) const
True if the point o is contained within this bounding box.
BoundingBoxD(const VectorD< D > &v)
Creating a bounding box containing one point.
const VectorD< D > & get_corner_1() const
Exception definitions and assertions.
Various important macros for implementing geometry.
#define IMP_VOLUME_GEOMETRY_METHODS_D(Name, name, area, volume, bounding_box)
Implement the needed namespace methods for a geometry type.
double get_maximum_length(const BoundingBoxD< D > &a)
Return the maximum axis aligned extent.
IntPairs get_edges(const BoundingBoxD< 3 > &)
Return the edges of the box as indices into the vertices list.
VectorD< D > get_ones_vector_d(double v=1)
Return a vector of ones (or another constant).
VectorD< D > get_ones_vector_kd(unsigned int Di, double v=1)
Return a vector of ones (or another constant).
BoundingBoxD<-1 > get_unit_bounding_box_kd(unsigned int d)
Box with radius one.
BoundingBoxD< D > get_unit_bounding_box_d()
Box with radius one.
double get_volume(const BoundingBoxD< D > &bb)
See BoundingBoxD.
BoundingBoxD< D > get_intersection(const BoundingBoxD< D > &a, const BoundingBoxD< D > &b)
Return the intersecting bounding box.
BoundingBoxD< D > get_cube_d(double radius)
Cube with radius of length radius.
BoundingBoxD< D > get_union(BoundingBoxD< D > a, const BoundingBoxD< D > &b)
Return the union bounding box.
bool get_interiors_intersect(const BoundingBoxD< D > &a, const BoundingBoxD< D > &b)
Return true if they intersect.
Vector< VectorD< D > > get_vertices(const BoundingBoxD< D > &bb)
Return a list of the 2^D bounding points for the bounding box.
BoundingBoxD<-1 > get_cube_kd(unsigned int d, double radius)
Cube with radius of length side.
IMP::Vector< IntPair > IntPairs
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
#define IMP_UNUSED(variable)