criptic v1
Cosmic Ray Interstellar Propagation Tool using Itô Calculus
Loading...
Searching...
No Matches
RealBox.H
Go to the documentation of this file.
1
11#ifndef _REALBOX_H_
12#define _REALBOX_H_
13
14#include <array>
15#include "RealTensor2.H"
16#include "Vec3.H"
17#include "Types.H"
18
19namespace criptic {
20
30 class RealBox {
31
32 public:
33
39 RealBox(const RealVec& lo_ = zeroVec,
40 const RealVec& hi_ = zeroVec) : lo(lo_), hi(hi_) { }
41
47 RealBox(const RealVec* pts, const IdxType npts) {
48 lo = pts[0];
49 hi = pts[0];
50 for (IdxType n=1; n<npts; n++) {
51 lo = min(lo, pts[n]);
52 hi = max(hi, pts[n]);
53 }
54 }
55
61 RealBox(const RealBox& rb1, const RealBox& rb2) {
62 lo = min(rb1.lo, rb2.lo);
63 hi = max(rb1.hi, rb2.hi);
64 }
65
71 bool contains(const RealVec& x) const {
72 return lo[0] <= x[0] && x[0] <= hi[0] &&
73 lo[1] <= x[1] && x[1] <= hi[1] &&
74 lo[2] <= x[2] && x[2] <= hi[2];
75 }
76
81 std::array<RealVec,8> corners() const {
82 std::array<RealVec,8> c;
83 int ptr = 0;
84 for (int i=0; i<2; i++) {
85 for (int j=0; j<2; j++) {
86 for (int k=0; k<2; k++) {
87 c[ptr][0] = (i == 0) ? lo[0] : hi[0];
88 c[ptr][1] = (j == 0) ? lo[1] : hi[1];
89 c[ptr][2] = (k == 0) ? lo[2] : hi[2];
90 ptr++;
91 }
92 }
93 }
94 return c;
95 }
96
101 RealVec size() const { return hi - lo; }
102
111 RealBox rotate(const RealTensor2& rot) const {
112 std::array<RealVec,8> c = corners();
113 for (int i=0; i<8; i++) c[i] = rot * c[i];
114 return RealBox(c.data(), 8);
115 }
116
129 void gaussExtrema(const RealTensor2& eta,
130 Real& gMin,
131 Real& gMax) const;
132
134 // Operations with vectors
136
143 RealBox operator+(const RealVec& v) const {
144 RealBox rb;
145 rb.lo = lo + v;
146 rb.hi = hi + v;
147 return rb;
148 }
149
156 RealBox operator-(const RealVec& v) const {
157 RealBox rb;
158 rb.lo = lo - v;
159 rb.hi = hi - v;
160 return rb;
161 }
162
163
164 // Data
168 };
169
170}
171
172// Overload the >> and << operators for convenience
180std::istream& operator>>(std::istream& is,
182
190std::ostream& operator<<(std::ostream& os,
191 const criptic::RealBox& b);
192
193
194#endif
195// _REALBOX_H_
std::ostream & operator<<(std::ostream &os, const criptic::RealBox &b)
ASCII-formatted output of RealBox to stream.
Definition RealBox.cpp:15
std::istream & operator>>(std::istream &is, criptic::RealBox &b)
ASCII-formatted read of RealBox from stream.
Definition RealBox.cpp:6
Class that represents a rank 2 tensor.
Basic integer and real types.
Class that represents a mathematical vector in 3-space.
Class that represents a 3D rectangular prism.
Definition RealBox.H:30
RealBox operator+(const RealVec &v) const
Displace the position of a RealBox by a vector v.
Definition RealBox.H:143
bool contains(const RealVec &x) const
Is a point in the box?
Definition RealBox.H:71
RealVec hi
Definition RealBox.H:166
RealBox(const RealBox &rb1, const RealBox &rb2)
Construct a RealBox that contains two other RealBox's.
Definition RealBox.H:61
std::array< RealVec, 8 > corners() const
Return all corners of the box.
Definition RealBox.H:81
RealBox operator-(const RealVec &v) const
Displace the position of a RealBox by a vector -v.
Definition RealBox.H:156
void gaussExtrema(const RealTensor2 &eta, Real &gMin, Real &gMax) const
Find extrema of a Gaussian function on a box.
Definition RealBox.cpp:22
RealBox(const RealVec *pts, const IdxType npts)
Construct a RealBox that bounds an array of points.
Definition RealBox.H:47
RealBox(const RealVec &lo_=zeroVec, const RealVec &hi_=zeroVec)
Construct a RealBox from two vectors.
Definition RealBox.H:39
RealBox rotate(const RealTensor2 &rot) const
Rotate box and return a box containing it.
Definition RealBox.H:111
RealVec size() const
Return size of box.
Definition RealBox.H:101
RealVec lo
Definition RealBox.H:165
Class that represents a rank 2 tensor.
Definition RealTensor2.H:34
The primary namespace for criptic objects.
Definition AdvancePacket.H:25
std::vector< Real >::size_type IdxType
Definition Types.H:45
criptic::FieldQty max(const criptic::FieldQty &q1, const criptic::FieldQty &q2)
Take elementwise maximum of two FieldQty objects.
Definition FieldQty.H:277
double Real
Definition Types.H:38
static const RealVec zeroVec(0, 0, 0)
criptic::FieldQty min(const criptic::FieldQty &q1, const criptic::FieldQty &q2)
Take elementwise minimum of two FieldQty objects.
Definition FieldQty.H:263