Medusa  1.1
Coordinate Free Mehless Method implementation
VectorField_fwd.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_TYPES_VECTORFIELD_FWD_HPP_
2 #define MEDUSA_BITS_TYPES_VECTORFIELD_FWD_HPP_
3 
11 #include <medusa/Config.hpp>
13 #include "Vec_fwd.hpp"
14 #include "traits.hpp"
15 #include <Eigen/Core>
16 
17 namespace mm {
18 
37 template <typename Scalar, int dimension>
38 class VectorField : public Eigen::Matrix<Scalar, Eigen::Dynamic, dimension> {
39  public:
40  typedef Scalar scalar_t;
41  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, dimension> Base;
42  using Base::operator=; // inherit assignment operators
43 
45  VectorField(void) : Base() {}
47  VectorField(const VectorField&) = default;
49  VectorField& operator=(const VectorField&) = default;
51  VectorField(VectorField&&) noexcept = default;
53  VectorField& operator=(VectorField&&) noexcept = default;
54 
56  template <typename OtherDerived>
57  VectorField(const Eigen::MatrixBase<OtherDerived>& other);
58 
60  template <typename OtherDerived>
61  VectorField& operator=(const Eigen::MatrixBase<OtherDerived>& other);
62 
67  template <typename SizeType>
68  explicit VectorField(SizeType N) : Base(N, dimension) {}
69 
72 
74  template <typename OtherDerived>
75  static VectorField fromLinear(const Eigen::PlainObjectBase<OtherDerived>& other);
76 
77  private:
81  const indexes_t& indexes;
82  friend class VectorField;
85  public:
87  void operator=(const Vec<scalar_t, dimension>& other) {
88  sf(indexes, Eigen::all) = other.transpose().replicate(indexes.size(), 1);
89  }
90  };
91 
92  public:
94  Eigen::Transpose<typename Base::RowXpr> operator[](typename Eigen::Index i) {
95  return Base::row(i).transpose();
96  }
98  SINL Eigen::Transpose<typename Base::ConstRowXpr> operator[](typename Eigen::Index i) const {
99  return Base::row(i).transpose();
100  }
101 
102  using Base::operator();
104  SINL Eigen::Transpose<typename Base::RowXpr> operator()(typename Eigen::Index i) {
105  return Base::row(i).transpose();
106  }
108  SINL Eigen::Transpose<typename Base::ConstRowXpr> operator()(typename Eigen::Index i) const {
109  return Base::row(i).transpose();
110  }
111 
116  SINL typename Base::ColXpr c(typename Eigen::Index i) { return Base::col(i); }
118  SINL typename Base::ConstColXpr c(typename Eigen::Index i) const { return Base::col(i); }
119 
121  Eigen::IndexedView<Base, indexes_t, Eigen::internal::AllRange<dimension>>
122  SINL operator()(const indexes_t& rowIndices) {
123  return Base::operator()(rowIndices, Eigen::all);
124  }
125 
128  return VectorFieldView(*this, indexes);
129  }
130 
132  Scalar* begin() { return this->data(); }
134  const Scalar* begin() const { return this->data(); }
135 
137  Scalar* end() { return this->data() + this->size(); }
139  const Scalar* end() const { return this->data() + this->size(); }
140 
142  const Scalar* cbegin() const { return this->data(); }
144  const Scalar* cend() const { return this->data() + this->size(); }
145 };
147 template <typename Scalar, int dim> struct vector_type<VectorField<Scalar, dim>> {
149 };
150 
154 
155 } // namespace mm
156 
157 #endif // MEDUSA_BITS_TYPES_VECTORFIELD_FWD_HPP_
mm::VectorField::VectorFieldView::indexes
const indexes_t & indexes
Indexes of this view.
Definition: VectorField_fwd.hpp:81
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::VectorField::Base
Eigen::Matrix< Scalar, Eigen::Dynamic, dimension > Base
Base class.
Definition: VectorField_fwd.hpp:41
mm::VectorField::operator()
SINL Eigen::Transpose< typename Base::RowXpr > operator()(typename Eigen::Index i)
Return a single row as a vector, non-const version.
Definition: VectorField_fwd.hpp:104
mm::Vec
Eigen::Matrix< scalar_t, dim, 1, Eigen::ColMajor|Eigen::AutoAlign, dim, 1 > Vec
Fixed size vector type, representing a mathematical 1d/2d/3d vector.
Definition: Vec_fwd.hpp:31
mm::VectorField::operator()
Eigen::IndexedView< Base, indexes_t, Eigen::internal::AllRange< dimension > > SINL operator()(const indexes_t &rowIndices)
Return an indexed view to a subset of vectors.
Definition: VectorField_fwd.hpp:122
mm::VectorField::end
const Scalar * end() const
Const pointer to the last coefficient.
Definition: VectorField_fwd.hpp:139
mm::VectorField::c
SINL Base::ColXpr c(typename Eigen::Index i)
Return the i-th component of this vector field.
Definition: VectorField_fwd.hpp:116
mm::VectorField::fromLinear
static VectorField fromLinear(const Eigen::PlainObjectBase< OtherDerived > &other)
Construct VectorField from its linear representation, obtained from asLinear().
mm::VectorField::begin
const Scalar * begin() const
Pointer to the first coefficient.
Definition: VectorField_fwd.hpp:134
mm::vector_type< VectorField< Scalar, dim > >::type
Vec< Scalar, dim > type
Underlying vector type.
Definition: VectorField_fwd.hpp:148
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
mm::VectorField::VectorField
VectorField(void)
Construct a vector field of size 0.
Definition: VectorField_fwd.hpp:45
mm::VectorField3d
VectorField< double, 3 > VectorField3d
Three dimensional vector field of doubles.
Definition: VectorField_fwd.hpp:153
mm::VectorField::end
Scalar * end()
Pointer to the last coefficient.
Definition: VectorField_fwd.hpp:137
mm::VectorField::operator[]
Eigen::Transpose< typename Base::RowXpr > operator[](typename Eigen::Index i)
Return a single row as a vector, non-const version.
Definition: VectorField_fwd.hpp:94
mm::VectorField::c
SINL Base::ConstColXpr c(typename Eigen::Index i) const
Const version of VectorField::c().
Definition: VectorField_fwd.hpp:118
mm::VectorField1d
VectorField< double, 1 > VectorField1d
One dimensional vector field of doubles.
Definition: VectorField_fwd.hpp:151
mm::sh::all
static const shape_flags all
Indicates to prepare all shapes, default.
Definition: shape_flags.hpp:29
Config.hpp
mm::VectorField::cend
const Scalar * cend() const
Const version of end.
Definition: VectorField_fwd.hpp:144
mm::indexes_t
std::vector< int > indexes_t
Class representing a collection of indices.
Definition: Config.hpp:36
Vec_fwd.hpp
mm::VectorField::operator[]
SINL Eigen::Transpose< typename Base::ConstRowXpr > operator[](typename Eigen::Index i) const
Return a single row as a vector, const version.
Definition: VectorField_fwd.hpp:98
mm::VectorField::scalar_t
Scalar scalar_t
Scalar data type.
Definition: VectorField_fwd.hpp:40
mm::VectorField::VectorFieldView::VectorFieldView
VectorFieldView(VectorField &sf, const indexes_t &indexes)
Construct a non contiguous view to a scalar field.
Definition: VectorField_fwd.hpp:84
mm::VectorField::cbegin
const Scalar * cbegin() const
Const version of begin.
Definition: VectorField_fwd.hpp:142
mm::vector_type
Type trait for vector fields to obtain their underlying vector type.
Definition: traits.hpp:28
assert.hpp
mm::VectorField
Represents a discretization of a vector field, a finite collection of vectors.
Definition: VectorField_fwd.hpp:38
mm::VectorField2d
VectorField< double, 2 > VectorField2d
Two dimensional vector field of doubles.
Definition: VectorField_fwd.hpp:152
mm::VectorField::operator()
SINL Eigen::Transpose< typename Base::ConstRowXpr > operator()(typename Eigen::Index i) const
Return a single row as a vector, const version.
Definition: VectorField_fwd.hpp:108
mm::VectorField::VectorFieldView::sf
VectorField & sf
Reference to the viewed field.
Definition: VectorField_fwd.hpp:80
mm::VectorField::begin
Scalar * begin()
Pointer to the first coefficient.
Definition: VectorField_fwd.hpp:132
SINL
#define SINL
Strong inline macro.
Definition: Config.hpp:24
mm::VectorField::operator=
VectorField & operator=(const VectorField &)=default
Default copy assignment.
mm::VectorField::operator[]
SINL VectorFieldView operator[](const indexes_t &indexes)
Returns an indexed view to a subset of vectors, that can be assigned.
Definition: VectorField_fwd.hpp:127
Matrix
Matrix(const Scalar &s)
Construct matrix from scalar. Enabled only for fixed size matrices.
Definition: MatrixAddons.hpp:21
mm::VectorField::VectorFieldView::operator=
void operator=(const Vec< scalar_t, dimension > &other)
Assign a vector to this view.
Definition: VectorField_fwd.hpp:87
traits.hpp
mm::VectorField::VectorFieldView
Represents a non contiguous view to a vector field.
Definition: VectorField_fwd.hpp:79