GteOrientedBox.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Mathematics/GteVector.h>
11 
12 // A box has center C, axis directions U[i], and extents e[i]. The set
13 // {U[0],...,U[N-1]} is orthonormal, which means the vectors are
14 // unit-length and mutually perpendicular. The extents are nonnegative;
15 // zero is allowed, meaning the box is degenerate in the corresponding
16 // direction. A point X is represented in box coordinates by
17 // X = C + y[0]*U[0] + y[1]*U[1]. This point is inside or on the
18 // box whenever |y[i]| <= e[i] for all i.
19 
20 namespace gte
21 {
22 
23 template <int N, typename Real>
25 {
26 public:
27  // Construction and destruction. The default constructor sets the center
28  // to (0,...,0), axis d to Vector<N,Real>::Unit(d), and extent d to +1.
29  OrientedBox();
30  OrientedBox(Vector<N, Real> const& inCenter,
31  std::array<Vector<N, Real>, N> const& inAxis,
32  Vector<N, Real> const& inExtent);
33 
34  // Compute the vertices of the box. If index i has the bit pattern
35  // i = b[N-1]...b[0], then
36  // vertex[i] = center + sum_{d=0}^{N-1} sign[d] * extent[d] * axis[d]
37  // where sign[d] = 2*b[d] - 1.
38  void GetVertices(std::array<Vector<N, Real>, (1 << N)>& vertex) const;
39 
40  // Public member access. It is required that extent[i] >= 0.
42  std::array<Vector<N, Real>, N> axis;
44 
45 public:
46  // Comparisons to support sorted containers.
47  bool operator==(OrientedBox const& box) const;
48  bool operator!=(OrientedBox const& box) const;
49  bool operator< (OrientedBox const& box) const;
50  bool operator<=(OrientedBox const& box) const;
51  bool operator> (OrientedBox const& box) const;
52  bool operator>=(OrientedBox const& box) const;
53 };
54 
55 // Template aliases for convenience.
56 template <typename Real>
58 
59 template <typename Real>
61 
62 
63 template <int N, typename Real>
65 {
66  center.MakeZero();
67  for (int i = 0; i < N; ++i)
68  {
69  axis[i].MakeUnit(i);
70  extent[i] = (Real)1;
71  }
72 }
73 
74 template <int N, typename Real>
76  std::array<Vector<N, Real>, N> const& inAxis,
77  Vector<N, Real> const& inExtent)
78  :
79  center(inCenter),
80  axis(inAxis),
81  extent(inExtent)
82 {
83 }
84 
85 template <int N, typename Real>
87  std::array<Vector<N, Real>, (1 << N)>& vertex) const
88 {
89  unsigned int const dsup = static_cast<unsigned int>(N);
90  std::array<Vector<N, Real>, N> product;
91  for (unsigned int d = 0; d < dsup; ++d)
92  {
93  product[d] = extent[d] * axis[d];
94  }
95 
96  int const imax = (1 << N);
97  for (int i = 0; i < imax; ++i)
98  {
99  vertex[i] = center;
100  for (unsigned int d = 0, mask = 1; d < dsup; ++d, mask <<= 1)
101  {
102  Real sign = (i & mask ? (Real)1 : (Real)-1);
103  vertex[i] += sign * product[d];
104  }
105  }
106 }
107 
108 template <int N, typename Real>
110 {
111  return center == box.center && axis == box.axis && extent == box.extent;
112 }
113 
114 template <int N, typename Real>
116 {
117  return !operator==(box);
118 }
119 
120 template <int N, typename Real>
122 {
123  if (center < box.center)
124  {
125  return true;
126  }
127 
128  if (center > box.center)
129  {
130  return false;
131  }
132 
133  if (axis < box.axis)
134  {
135  return true;
136  }
137 
138  if (axis > box.axis)
139  {
140  return false;
141  }
142 
143  return extent < box.extent;
144 }
145 
146 template <int N, typename Real>
148 {
149  return operator<(box) || operator==(box);
150 }
151 
152 template <int N, typename Real>
154 {
155  return !operator<=(box);
156 }
157 
158 template <int N, typename Real>
160 {
161  return !operator<(box);
162 }
163 
164 
165 }
bool operator>(OrientedBox const &box) const
std::array< Vector< N, Real >, N > axis
bool operator==(OrientedBox const &box) const
bool operator<=(OrientedBox const &box) const
GLint GLuint mask
Definition: glcorearb.h:119
Vector< N, Real > extent
bool operator!=(OrientedBox const &box) const
GLenum array
Definition: glext.h:6669
bool operator>=(OrientedBox const &box) const
bool operator<(OrientedBox const &box) const
Vector< N, Real > center
void GetVertices(std::array< Vector< N, Real >,(1<< N)> &vertex) const


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01