10 #ifndef EIGEN_ALIGNEDBOX_H 11 #define EIGEN_ALIGNEDBOX_H 29 template <
typename _Scalar,
int _AmbientDim>
33 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
34 enum { AmbientDimAtCompileTime = _AmbientDim };
35 typedef _Scalar Scalar;
36 typedef NumTraits<Scalar> ScalarTraits;
38 typedef typename ScalarTraits::Real RealScalar;
39 typedef typename ScalarTraits::NonInteger NonInteger;
69 EIGEN_DEVICE_FUNC
inline explicit AlignedBox(Index _dim) : m_min(_dim), m_max(_dim)
74 template<
typename OtherVectorType1,
typename OtherVectorType2>
75 EIGEN_DEVICE_FUNC
inline AlignedBox(
const OtherVectorType1& _min,
const OtherVectorType2& _max) : m_min(_min), m_max(_max) {}
78 template<
typename Derived>
85 EIGEN_DEVICE_FUNC
inline Index
dim()
const {
return AmbientDimAtCompileTime==
Dynamic ? m_min.size() :
Index(AmbientDimAtCompileTime); }
95 EIGEN_DEVICE_FUNC
inline bool isEmpty()
const {
return (m_min.array() > m_max.array()).any(); }
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; }
117 {
return (m_min+m_max)/RealScalar(2); }
124 {
return m_max - m_min; }
127 EIGEN_DEVICE_FUNC
inline Scalar
volume()
const 128 {
return sizes().prod(); }
134 EIGEN_DEVICE_FUNC
inline CwiseBinaryOp< internal::scalar_difference_op<Scalar,Scalar>,
const VectorType,
const VectorType>
diagonal()
const 148 EIGEN_STATIC_ASSERT(_AmbientDim <= 3, THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE);
153 for(Index d=0; d<
dim(); ++d)
155 if( mult & corner ) res[d] = m_max[d];
156 else res[d] = m_min[d];
164 EIGEN_DEVICE_FUNC
inline VectorType
sample()
const 167 for(Index d=0; d<
dim(); ++d)
169 if(!ScalarTraits::IsInteger)
171 r[d] = m_min[d] + (m_max[d]-m_min[d])
172 * internal::random<Scalar>(Scalar(0), Scalar(1));
175 r[d] = internal::random(m_min[d], m_max[d]);
181 template<
typename Derived>
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();
190 {
return (m_min.array()<=(b.min)().array()).all() && ((b.max)().array()<=m_max.array()).all(); }
195 {
return (m_min.array()<=(b.max)().array()).all() && ((b.min)().array()<=m_max.array()).all(); }
199 template<
typename Derived>
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);
212 m_min = m_min.cwiseMin(b.m_min);
213 m_max = m_max.cwiseMax(b.m_max);
222 m_min = m_min.cwiseMax(b.m_min);
223 m_max = m_max.cwiseMin(b.m_max);
231 {
return AlignedBox(m_min.cwiseMax(b.m_min), m_max.cwiseMin(b.m_max)); }
237 {
return AlignedBox(m_min.cwiseMin(b.m_min), m_max.cwiseMax(b.m_max)); }
240 template<
typename Derived>
243 const typename internal::nested_eval<Derived,2>::type t(a_t.
derived());
253 template<
typename Derived>
266 template<
typename Derived>
282 template<
typename NewScalarType>
283 EIGEN_DEVICE_FUNC
inline typename internal::cast_return_type<
AlignedBox,
286 return typename internal::cast_return_type<
AlignedBox,
291 template<
typename OtherScalarType>
294 m_min = (other.min)().template cast<Scalar>();
295 m_max = (other.max)().template cast<Scalar>();
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); }
307 VectorType m_min, m_max;
312 template<
typename Scalar,
int AmbientDim>
313 template<
typename Derived>
316 typename internal::nested_eval<Derived,2*AmbientDim>::type p(a_p.
derived());
319 for (Index k=0; k<
dim(); ++k)
321 if( m_min[k] > p[k] )
323 aux = m_min[k] - p[k];
326 else if( p[k] > m_max[k] )
328 aux = p[k] - m_max[k];
335 template<
typename Scalar,
int AmbientDim>
340 for (Index k=0; k<
dim(); ++k)
342 if( m_min[k] > b.m_max[k] )
344 aux = m_min[k] - b.m_max[k];
347 else if( b.m_min[k] > m_max[k] )
349 aux = b.m_min[k] - m_max[k];
372 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ 374 typedef AlignedBox<Type, Size> AlignedBox##SizeSuffix##TypeSuffix; 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) 383 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
int, i)
384 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
float, f)
385 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(
double, d)
387 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES 388 #undef EIGEN_MAKE_TYPEDEFS 392 #endif // EIGEN_ALIGNEDBOX_H const CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > sizes() const
Definition: AlignedBox.h:123
const VectorType &() max() const
Definition: AlignedBox.h:110
AlignedBox & clamp(const AlignedBox &b)
Definition: AlignedBox.h:220
VectorType corner(CornerType corner) const
Definition: AlignedBox.h:146
NonInteger exteriorDistance(const AlignedBox &b) const
Definition: AlignedBox.h:274
Definition: AlignedBox.h:56
VectorType sample() const
Definition: AlignedBox.h:164
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
AlignedBox(Index _dim)
Definition: AlignedBox.h:69
Namespace containing all symbols from the Eigen library.
Definition: Core:287
const VectorType &() min() const
Definition: AlignedBox.h:106
Derived & derived()
Definition: EigenBase.h:45
Definition: AlignedBox.h:47
Scalar squaredExteriorDistance(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:314
bool isApprox(const AlignedBox &other, const RealScalar &prec=ScalarTraits::dummy_precision()) const
Definition: AlignedBox.h:302
void setEmpty()
Definition: AlignedBox.h:99
An axis aligned box.
Definition: ForwardDeclarations.h:272
AlignedBox()
Definition: AlignedBox.h:65
Definition: AlignedBox.h:51
NonInteger exteriorDistance(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:267
Definition: AlignedBox.h:57
Definition: AlignedBox.h:59
AlignedBox & extend(const AlignedBox &b)
Definition: AlignedBox.h:210
AlignedBox intersection(const AlignedBox &b) const
Definition: AlignedBox.h:230
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
CornerType
Definition: AlignedBox.h:44
bool intersects(const AlignedBox &b) const
Definition: AlignedBox.h:194
Definition: AlignedBox.h:52
Definition: AlignedBox.h:59
void setNull()
Definition: AlignedBox.h:91
Definition: AlignedBox.h:51
Scalar volume() const
Definition: AlignedBox.h:127
AlignedBox merged(const AlignedBox &b) const
Definition: AlignedBox.h:236
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
bool isNull() const
Definition: AlignedBox.h:88
Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:341
Definition: AlignedBox.h:52
bool contains(const AlignedBox &b) const
Definition: AlignedBox.h:189
VectorType &() max()
Definition: AlignedBox.h:112
AlignedBox & translate(const MatrixBase< Derived > &a_t)
Definition: AlignedBox.h:241
bool isEmpty() const
Definition: AlignedBox.h:95
const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(VectorTypeSum, RealScalar, quotient) center() const
Definition: AlignedBox.h:115
internal::cast_return_type< AlignedBox, AlignedBox< NewScalarType, AmbientDimAtCompileTime > >::type cast() const
Definition: AlignedBox.h:284
VectorType &() min()
Definition: AlignedBox.h:108
AlignedBox(const MatrixBase< Derived > &p)
Definition: AlignedBox.h:79
Definition: AlignedBox.h:58
AlignedBox(const OtherVectorType1 &_min, const OtherVectorType2 &_max)
Definition: AlignedBox.h:75
const int Dynamic
Definition: Constants.h:21
Index dim() const
Definition: AlignedBox.h:85
AlignedBox & extend(const MatrixBase< Derived > &p)
Definition: AlignedBox.h:200
Definition: AlignedBox.h:58
Definition: AlignedBox.h:57
Definition: AlignedBox.h:56
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
bool contains(const MatrixBase< Derived > &p) const
Definition: AlignedBox.h:182
Definition: AlignedBox.h:47
CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > diagonal() const
Definition: AlignedBox.h:134
AlignedBox(const AlignedBox< OtherScalarType, AmbientDimAtCompileTime > &other)
Definition: AlignedBox.h:292