~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/Eigen3/Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of Eigen, a lightweight C++ template library
 
2
// for linear algebra. Eigen itself is part of the KDE project.
 
3
//
 
4
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
 
5
// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
 
6
//
 
7
// Eigen is free software; you can redistribute it and/or
 
8
// modify it under the terms of the GNU Lesser General Public
 
9
// License as published by the Free Software Foundation; either
 
10
// version 3 of the License, or (at your option) any later version.
 
11
//
 
12
// Alternatively, you can redistribute it and/or
 
13
// modify it under the terms of the GNU General Public License as
 
14
// published by the Free Software Foundation; either version 2 of
 
15
// the License, or (at your option) any later version.
 
16
//
 
17
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
 
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
19
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
 
20
// GNU General Public License for more details.
 
21
//
 
22
// You should have received a copy of the GNU Lesser General Public
 
23
// License and a copy of the GNU General Public License along with
 
24
// Eigen. If not, see <http://www.gnu.org/licenses/>.
 
25
 
 
26
// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
 
27
 
 
28
 
 
29
/** \geometry_module \ingroup Geometry_Module
 
30
  *
 
31
  * \class ParametrizedLine
 
32
  *
 
33
  * \brief A parametrized line
 
34
  *
 
35
  * A parametrized line is defined by an origin point \f$ \mathbf{o} \f$ and a unit
 
36
  * direction vector \f$ \mathbf{d} \f$ such that the line corresponds to
 
37
  * the set \f$ l(t) = \mathbf{o} + t \mathbf{d} \f$, \f$ l \in \mathbf{R} \f$.
 
38
  *
 
39
  * \param _Scalar the scalar type, i.e., the type of the coefficients
 
40
  * \param _AmbientDim the dimension of the ambient space, can be a compile time value or Dynamic.
 
41
  */
 
42
template <typename _Scalar, int _AmbientDim>
 
43
class ParametrizedLine
 
44
{
 
45
public:
 
46
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
 
47
  enum { AmbientDimAtCompileTime = _AmbientDim };
 
48
  typedef _Scalar Scalar;
 
49
  typedef typename NumTraits<Scalar>::Real RealScalar;
 
50
  typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType;
 
51
 
 
52
  /** Default constructor without initialization */
 
53
  inline explicit ParametrizedLine() {}
 
54
 
 
55
  /** Constructs a dynamic-size line with \a _dim the dimension
 
56
    * of the ambient space */
 
57
  inline explicit ParametrizedLine(int _dim) : m_origin(_dim), m_direction(_dim) {}
 
58
 
 
59
  /** Initializes a parametrized line of direction \a direction and origin \a origin.
 
60
    * \warning the vector direction is assumed to be normalized.
 
61
    */
 
62
  ParametrizedLine(const VectorType& origin, const VectorType& direction)
 
63
    : m_origin(origin), m_direction(direction) {}
 
64
 
 
65
  explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane);
 
66
 
 
67
  /** Constructs a parametrized line going from \a p0 to \a p1. */
 
68
  static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1)
 
69
  { return ParametrizedLine(p0, (p1-p0).normalized()); }
 
70
 
 
71
  ~ParametrizedLine() {}
 
72
 
 
73
  /** \returns the dimension in which the line holds */
 
74
  inline int dim() const { return m_direction.size(); }
 
75
 
 
76
  const VectorType& origin() const { return m_origin; }
 
77
  VectorType& origin() { return m_origin; }
 
78
 
 
79
  const VectorType& direction() const { return m_direction; }
 
80
  VectorType& direction() { return m_direction; }
 
81
 
 
82
  /** \returns the squared distance of a point \a p to its projection onto the line \c *this.
 
83
    * \sa distance()
 
84
    */
 
85
  RealScalar squaredDistance(const VectorType& p) const
 
86
  {
 
87
    VectorType diff = p-origin();
 
88
    return (diff - diff.eigen2_dot(direction())* direction()).squaredNorm();
 
89
  }
 
90
  /** \returns the distance of a point \a p to its projection onto the line \c *this.
 
91
    * \sa squaredDistance()
 
92
    */
 
93
  RealScalar distance(const VectorType& p) const { return ei_sqrt(squaredDistance(p)); }
 
94
 
 
95
  /** \returns the projection of a point \a p onto the line \c *this. */
 
96
  VectorType projection(const VectorType& p) const
 
97
  { return origin() + (p-origin()).eigen2_dot(direction()) * direction(); }
 
98
 
 
99
  Scalar intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane);
 
100
 
 
101
  /** \returns \c *this with scalar type casted to \a NewScalarType
 
102
    *
 
103
    * Note that if \a NewScalarType is equal to the current scalar type of \c *this
 
104
    * then this function smartly returns a const reference to \c *this.
 
105
    */
 
106
  template<typename NewScalarType>
 
107
  inline typename internal::cast_return_type<ParametrizedLine,
 
108
           ParametrizedLine<NewScalarType,AmbientDimAtCompileTime> >::type cast() const
 
109
  {
 
110
    return typename internal::cast_return_type<ParametrizedLine,
 
111
                    ParametrizedLine<NewScalarType,AmbientDimAtCompileTime> >::type(*this);
 
112
  }
 
113
 
 
114
  /** Copy constructor with scalar type conversion */
 
115
  template<typename OtherScalarType>
 
116
  inline explicit ParametrizedLine(const ParametrizedLine<OtherScalarType,AmbientDimAtCompileTime>& other)
 
117
  {
 
118
    m_origin = other.origin().template cast<Scalar>();
 
119
    m_direction = other.direction().template cast<Scalar>();
 
120
  }
 
121
 
 
122
  /** \returns \c true if \c *this is approximately equal to \a other, within the precision
 
123
    * determined by \a prec.
 
124
    *
 
125
    * \sa MatrixBase::isApprox() */
 
126
  bool isApprox(const ParametrizedLine& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
 
127
  { return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec); }
 
128
 
 
129
protected:
 
130
 
 
131
  VectorType m_origin, m_direction;
 
132
};
 
133
 
 
134
/** Constructs a parametrized line from a 2D hyperplane
 
135
  *
 
136
  * \warning the ambient space must have dimension 2 such that the hyperplane actually describes a line
 
137
  */
 
138
template <typename _Scalar, int _AmbientDim>
 
139
inline ParametrizedLine<_Scalar, _AmbientDim>::ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane)
 
140
{
 
141
  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
 
142
  direction() = hyperplane.normal().unitOrthogonal();
 
143
  origin() = -hyperplane.normal()*hyperplane.offset();
 
144
}
 
145
 
 
146
/** \returns the parameter value of the intersection between \c *this and the given hyperplane
 
147
  */
 
148
template <typename _Scalar, int _AmbientDim>
 
149
inline _Scalar ParametrizedLine<_Scalar, _AmbientDim>::intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane)
 
150
{
 
151
  return -(hyperplane.offset()+origin().eigen2_dot(hyperplane.normal()))
 
152
          /(direction().eigen2_dot(hyperplane.normal()));
 
153
}