AlignedBox.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_ALIGNEDBOX_H
11 #define EIGEN_ALIGNEDBOX_H
12 
13 namespace Eigen {
14 
29 template <typename _Scalar, int _AmbientDim>
30 class AlignedBox
31 {
32 public:
34  enum { AmbientDimAtCompileTime = _AmbientDim };
35  typedef _Scalar Scalar;
37  typedef Eigen::Index Index;
38  typedef typename ScalarTraits::Real RealScalar;
39  typedef typename ScalarTraits::NonInteger NonInteger;
42 
45  {
47  Min=0, Max=1,
61  };
62 
63 
65  EIGEN_DEVICE_FUNC inline AlignedBox()
67 
69  EIGEN_DEVICE_FUNC inline explicit AlignedBox(Index _dim) : m_min(_dim), m_max(_dim)
70  { setEmpty(); }
71 
74  template<typename OtherVectorType1, typename OtherVectorType2>
75  EIGEN_DEVICE_FUNC inline AlignedBox(const OtherVectorType1& _min, const OtherVectorType2& _max) : m_min(_min), m_max(_max) {}
76 
78  template<typename Derived>
79  EIGEN_DEVICE_FUNC inline explicit AlignedBox(const MatrixBase<Derived>& p) : m_min(p), m_max(m_min)
80  { }
81 
82  EIGEN_DEVICE_FUNC ~AlignedBox() {}
83 
85  EIGEN_DEVICE_FUNC inline Index dim() const { return AmbientDimAtCompileTime==Dynamic ? m_min.size() : Index(AmbientDimAtCompileTime); }
86 
88  EIGEN_DEVICE_FUNC inline bool isNull() const { return isEmpty(); }
89 
91  EIGEN_DEVICE_FUNC inline void setNull() { setEmpty(); }
92 
95  EIGEN_DEVICE_FUNC inline bool isEmpty() const { return (m_min.array() > m_max.array()).any(); }
96 
99  EIGEN_DEVICE_FUNC inline void setEmpty()
100  {
101  m_min.setConstant( ScalarTraits::highest() );
102  m_max.setConstant( ScalarTraits::lowest() );
103  }
104 
106  EIGEN_DEVICE_FUNC inline const VectorType& (min)() const { return m_min; }
108  EIGEN_DEVICE_FUNC inline VectorType& (min)() { return m_min; }
110  EIGEN_DEVICE_FUNC inline const VectorType& (max)() const { return m_max; }
112  EIGEN_DEVICE_FUNC inline VectorType& (max)() { return m_max; }
113 
115  EIGEN_DEVICE_FUNC inline const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(VectorTypeSum, RealScalar, quotient)
116  center() const
117  { return (m_min+m_max)/RealScalar(2); }
118 
123  EIGEN_DEVICE_FUNC inline const CwiseBinaryOp< internal::scalar_difference_op<Scalar,Scalar>, const VectorType, const VectorType> sizes() const
124  { return m_max - m_min; }
125 
127  EIGEN_DEVICE_FUNC inline Scalar volume() const
128  { return sizes().prod(); }
129 
134  EIGEN_DEVICE_FUNC inline CwiseBinaryOp< internal::scalar_difference_op<Scalar,Scalar>, const VectorType, const VectorType> diagonal() const
135  { return sizes(); }
136 
146  EIGEN_DEVICE_FUNC inline VectorType corner(CornerType corner) const
147  {
148  EIGEN_STATIC_ASSERT(_AmbientDim <= 3, THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE);
149 
150  VectorType res;
151 
152  Index mult = 1;
153  for(Index d=0; d<dim(); ++d)
154  {
155  if( mult & corner ) res[d] = m_max[d];
156  else res[d] = m_min[d];
157  mult *= 2;
158  }
159  return res;
160  }
161 
164  EIGEN_DEVICE_FUNC inline VectorType sample() const
165  {
166  VectorType r(dim());
167  for(Index d=0; d<dim(); ++d)
168  {
170  {
171  r[d] = m_min[d] + (m_max[d]-m_min[d])
172  * internal::random<Scalar>(Scalar(0), Scalar(1));
173  }
174  else
175  r[d] = internal::random(m_min[d], m_max[d]);
176  }
177  return r;
178  }
179 
181  template<typename Derived>
182  EIGEN_DEVICE_FUNC inline bool contains(const MatrixBase<Derived>& p) const
183  {
184  typename internal::nested_eval<Derived,2>::type p_n(p.derived());
185  return (m_min.array()<=p_n.array()).all() && (p_n.array()<=m_max.array()).all();
186  }
187 
189  EIGEN_DEVICE_FUNC inline bool contains(const AlignedBox& b) const
190  { return (m_min.array()<=(b.min)().array()).all() && ((b.max)().array()<=m_max.array()).all(); }
191 
194  EIGEN_DEVICE_FUNC inline bool intersects(const AlignedBox& b) const
195  { return (m_min.array()<=(b.max)().array()).all() && ((b.min)().array()<=m_max.array()).all(); }
196 
199  template<typename Derived>
200  EIGEN_DEVICE_FUNC inline AlignedBox& extend(const MatrixBase<Derived>& p)
201  {
202  typename internal::nested_eval<Derived,2>::type p_n(p.derived());
203  m_min = m_min.cwiseMin(p_n);
204  m_max = m_max.cwiseMax(p_n);
205  return *this;
206  }
207 
210  EIGEN_DEVICE_FUNC inline AlignedBox& extend(const AlignedBox& b)
211  {
212  m_min = m_min.cwiseMin(b.m_min);
213  m_max = m_max.cwiseMax(b.m_max);
214  return *this;
215  }
216 
220  EIGEN_DEVICE_FUNC inline AlignedBox& clamp(const AlignedBox& b)
221  {
222  m_min = m_min.cwiseMax(b.m_min);
223  m_max = m_max.cwiseMin(b.m_max);
224  return *this;
225  }
226 
230  EIGEN_DEVICE_FUNC inline AlignedBox intersection(const AlignedBox& b) const
231  {return AlignedBox(m_min.cwiseMax(b.m_min), m_max.cwiseMin(b.m_max)); }
232 
236  EIGEN_DEVICE_FUNC inline AlignedBox merged(const AlignedBox& b) const
237  { return AlignedBox(m_min.cwiseMin(b.m_min), m_max.cwiseMax(b.m_max)); }
238 
240  template<typename Derived>
241  EIGEN_DEVICE_FUNC inline AlignedBox& translate(const MatrixBase<Derived>& a_t)
242  {
243  const typename internal::nested_eval<Derived,2>::type t(a_t.derived());
244  m_min += t;
245  m_max += t;
246  return *this;
247  }
248 
253  template<typename Derived>
254  EIGEN_DEVICE_FUNC inline Scalar squaredExteriorDistance(const MatrixBase<Derived>& p) const;
255 
260  EIGEN_DEVICE_FUNC inline Scalar squaredExteriorDistance(const AlignedBox& b) const;
261 
266  template<typename Derived>
267  EIGEN_DEVICE_FUNC inline NonInteger exteriorDistance(const MatrixBase<Derived>& p) const
268  { EIGEN_USING_STD_MATH(sqrt) return sqrt(NonInteger(squaredExteriorDistance(p))); }
269 
274  EIGEN_DEVICE_FUNC inline NonInteger exteriorDistance(const AlignedBox& b) const
275  { EIGEN_USING_STD_MATH(sqrt) return sqrt(NonInteger(squaredExteriorDistance(b))); }
276 
282  template<typename NewScalarType>
283  EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<AlignedBox,
285  {
286  return typename internal::cast_return_type<AlignedBox,
288  }
289 
291  template<typename OtherScalarType>
292  EIGEN_DEVICE_FUNC inline explicit AlignedBox(const AlignedBox<OtherScalarType,AmbientDimAtCompileTime>& other)
293  {
294  m_min = (other.min)().template cast<Scalar>();
295  m_max = (other.max)().template cast<Scalar>();
296  }
297 
302  EIGEN_DEVICE_FUNC bool isApprox(const AlignedBox& other, const RealScalar& prec = ScalarTraits::dummy_precision()) const
303  { return m_min.isApprox(other.m_min, prec) && m_max.isApprox(other.m_max, prec); }
304 
305 protected:
306 
307  VectorType m_min, m_max;
308 };
309 
310 
311 
312 template<typename Scalar,int AmbientDim>
313 template<typename Derived>
314 EIGEN_DEVICE_FUNC inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const MatrixBase<Derived>& a_p) const
315 {
316  typename internal::nested_eval<Derived,2*AmbientDim>::type p(a_p.derived());
317  Scalar dist2(0);
318  Scalar aux;
319  for (Index k=0; k<dim(); ++k)
320  {
321  if( m_min[k] > p[k] )
322  {
323  aux = m_min[k] - p[k];
324  dist2 += aux*aux;
325  }
326  else if( p[k] > m_max[k] )
327  {
328  aux = p[k] - m_max[k];
329  dist2 += aux*aux;
330  }
331  }
332  return dist2;
333 }
334 
335 template<typename Scalar,int AmbientDim>
336 EIGEN_DEVICE_FUNC inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const AlignedBox& b) const
337 {
338  Scalar dist2(0);
339  Scalar aux;
340  for (Index k=0; k<dim(); ++k)
341  {
342  if( m_min[k] > b.m_max[k] )
343  {
344  aux = m_min[k] - b.m_max[k];
345  dist2 += aux*aux;
346  }
347  else if( b.m_min[k] > m_max[k] )
348  {
349  aux = b.m_min[k] - m_max[k];
350  dist2 += aux*aux;
351  }
352  }
353  return dist2;
354 }
355 
372 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
373  \
374 typedef AlignedBox<Type, Size> AlignedBox##SizeSuffix##TypeSuffix;
375 
376 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
377 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 1, 1) \
378 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
379 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
380 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
381 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X)
382 
386 
387 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
388 #undef EIGEN_MAKE_TYPEDEFS
389 
390 } // end namespace Eigen
391 
392 #endif // EIGEN_ALIGNEDBOX_H
d
EIGEN_DEVICE_FUNC bool isApprox(const AlignedBox &other, const RealScalar &prec=ScalarTraits::dummy_precision()) const
Definition: AlignedBox.h:302
EIGEN_DEVICE_FUNC bool contains(const AlignedBox &b) const
Definition: AlignedBox.h:189
ScalarTraits::NonInteger NonInteger
Definition: AlignedBox.h:39
VectorType m_min
Definition: AlignedBox.h:307
EIGEN_DEVICE_FUNC AlignedBox & translate(const MatrixBase< Derived > &a_t)
Definition: AlignedBox.h:241
EIGEN_DEVICE_FUNC const VectorType &() max() const
Definition: AlignedBox.h:110
ScalarTraits::Real RealScalar
Definition: AlignedBox.h:38
EIGEN_DEVICE_FUNC AlignedBox & extend(const AlignedBox &b)
Definition: AlignedBox.h:210
VectorType m_max
Definition: AlignedBox.h:307
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
EIGEN_DEVICE_FUNC bool isNull() const
Definition: AlignedBox.h:88
EIGEN_DEVICE_FUNC ~AlignedBox()
Definition: AlignedBox.h:82
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition: LDLT.h:16
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:122
EIGEN_DEVICE_FUNC NonInteger exteriorDistance(const AlignedBox &b) const
Definition: AlignedBox.h:274
EIGEN_DEVICE_FUNC AlignedBox(const OtherVectorType1 &_min, const OtherVectorType2 &_max)
Definition: AlignedBox.h:75
EIGEN_DEVICE_FUNC Scalar volume() const
Definition: AlignedBox.h:127
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
Definition: Memory.h:691
An axis aligned box.
EIGEN_DEVICE_FUNC const CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > sizes() const
Definition: AlignedBox.h:123
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
EIGEN_DEVICE_FUNC AlignedBox & clamp(const AlignedBox &b)
Definition: AlignedBox.h:220
EIGEN_DEVICE_FUNC AlignedBox()
Definition: AlignedBox.h:65
EIGEN_DEVICE_FUNC AlignedBox(const AlignedBox< OtherScalarType, AmbientDimAtCompileTime > &other)
Definition: AlignedBox.h:292
EIGEN_DEVICE_FUNC const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(VectorTypeSum, RealScalar, quotient) center() const
Definition: AlignedBox.h:115
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Eigen::Index Index
Definition: AlignedBox.h:37
EIGEN_DEVICE_FUNC internal::cast_return_type< AlignedBox, AlignedBox< NewScalarType, AmbientDimAtCompileTime > >::type cast() const
Definition: AlignedBox.h:284
EIGEN_DEVICE_FUNC Derived & setConstant(Index size, const Scalar &val)
EIGEN_DEVICE_FUNC void setEmpty()
Definition: AlignedBox.h:99
EIGEN_DEVICE_FUNC AlignedBox(const MatrixBase< Derived > &p)
Definition: AlignedBox.h:79
EIGEN_DEVICE_FUNC bool isEmpty() const
Definition: AlignedBox.h:95
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > diagonal() const
Definition: AlignedBox.h:134
EIGEN_DEVICE_FUNC VectorType corner(CornerType corner) const
Definition: AlignedBox.h:146
EIGEN_DEVICE_FUNC const VectorType &() min() const
Definition: AlignedBox.h:106
CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const VectorType, const VectorType > VectorTypeSum
Definition: AlignedBox.h:41
EIGEN_DEVICE_FUNC void setNull()
Definition: AlignedBox.h:91
EIGEN_DEVICE_FUNC NonInteger exteriorDistance(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:267
EIGEN_DEVICE_FUNC Index dim() const
Definition: AlignedBox.h:85
EIGEN_DEVICE_FUNC AlignedBox merged(const AlignedBox &b) const
Definition: AlignedBox.h:236
EIGEN_DEVICE_FUNC VectorType sample() const
Definition: AlignedBox.h:164
NumTraits< Scalar > ScalarTraits
Definition: AlignedBox.h:36
EIGEN_DEVICE_FUNC bool intersects(const AlignedBox &b) const
Definition: AlignedBox.h:194
EIGEN_DEVICE_FUNC AlignedBox & extend(const MatrixBase< Derived > &p)
Definition: AlignedBox.h:200
const mpreal random(unsigned int seed=0)
Definition: mpreal.h:2614
EIGEN_DEVICE_FUNC AlignedBox(Index _dim)
Definition: AlignedBox.h:69
EIGEN_DEVICE_FUNC Scalar squaredExteriorDistance(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:314
EIGEN_DEVICE_FUNC VectorType &() max()
Definition: AlignedBox.h:112
const int Dynamic
Definition: Constants.h:21
EIGEN_DEVICE_FUNC VectorType &() min()
Definition: AlignedBox.h:108
EIGEN_DEVICE_FUNC bool contains(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:182
#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix)
Definition: AlignedBox.h:376
EIGEN_DEVICE_FUNC const Scalar & b
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
EIGEN_DEVICE_FUNC AlignedBox intersection(const AlignedBox &b) const
Definition: AlignedBox.h:230
Matrix< Scalar, AmbientDimAtCompileTime, 1 > VectorType
Definition: AlignedBox.h:40


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:07:59