Dem Bones  1.2.0
Skinning Decomposition Library
Indexing.h
Go to the documentation of this file.
1 // Dem Bones - Skinning Decomposition Library //
3 // Copyright (c) 2019, Electronic Arts. All rights reserved. //
5 
6 
7 
8 #ifndef DEM_BONES_INDEXING
9 #define DEM_BONES_INDEXING
10 
11 #ifdef _MSC_VER
12 #pragma warning(disable:4172)
13 #endif
14 
15 #include <Eigen/Dense>
16 
17 namespace Dem
18 {
19 
23 template<class ArgType, class RowIndexType, class ColIndexType>
25  const ArgType &m_arg;
26  const RowIndexType &m_rowIndices;
27  const ColIndexType &m_colIndices;
28 public:
29  typedef Eigen::Matrix<typename ArgType::Scalar,
30  RowIndexType::SizeAtCompileTime,
31  ColIndexType::SizeAtCompileTime,
32  ArgType::Flags& Eigen::RowMajorBit?Eigen::RowMajor:Eigen::ColMajor,
33  RowIndexType::MaxSizeAtCompileTime,
34  ColIndexType::MaxSizeAtCompileTime> MatrixType;
35  indexing_functor_row_col(const ArgType& arg, const RowIndexType& row_indices, const ColIndexType& col_indices)
36  : m_arg(arg), m_rowIndices(row_indices), m_colIndices(col_indices) {}
37  const typename ArgType::Scalar& operator() (Eigen::Index row, Eigen::Index col) const {
38  return m_arg(m_rowIndices[row], m_colIndices[col]);
39  }
40 };
41 
45 template <class ArgType, class RowIndexType, class ColIndexType>
46 Eigen::CwiseNullaryOp<indexing_functor_row_col<ArgType, RowIndexType, ColIndexType>, typename indexing_functor_row_col<ArgType, RowIndexType, ColIndexType>::MatrixType>
47 indexing_row_col(const Eigen::MatrixBase<ArgType>& arg, const RowIndexType& row_indices, const ColIndexType& col_indices) {
49  typedef typename Func::MatrixType MatrixType;
50  return MatrixType::NullaryExpr(row_indices.size(), col_indices.size(), Func(arg.derived(), row_indices, col_indices));
51 }
52 
53 
54 
58 template<class ArgType, class RowIndexType>
60  const ArgType &m_arg;
61  const RowIndexType &m_rowIndices;
62 public:
63  typedef Eigen::Matrix<typename ArgType::Scalar,
64  RowIndexType::SizeAtCompileTime,
65  ArgType::ColsAtCompileTime,
66  ArgType::Flags& Eigen::RowMajorBit?Eigen::RowMajor:Eigen::ColMajor,
67  RowIndexType::MaxSizeAtCompileTime,
68  ArgType::MaxColsAtCompileTime> MatrixType;
69  indexing_functor_row(const ArgType& arg, const RowIndexType& row_indices)
70  : m_arg(arg), m_rowIndices(row_indices) {}
71  const typename ArgType::Scalar& operator() (Eigen::Index row, Eigen::Index col) const {
72  return m_arg(m_rowIndices[row], col);
73  }
74 };
75 
79 template <class ArgType, class RowIndexType>
80 Eigen::CwiseNullaryOp<indexing_functor_row<ArgType, RowIndexType>, typename indexing_functor_row<ArgType, RowIndexType>::MatrixType>
81 indexing_row(const Eigen::MatrixBase<ArgType>& arg, const RowIndexType& row_indices) {
83  typedef typename Func::MatrixType MatrixType;
84  return MatrixType::NullaryExpr(row_indices.size(), arg.cols(), Func(arg.derived(), row_indices));
85 }
86 
87 
88 
92 template<class ArgType, class IndexType>
94  const ArgType &m_arg;
95  const IndexType &m_indices;
96 public:
97  typedef Eigen::Matrix<typename ArgType::Scalar,
98  IndexType::SizeAtCompileTime,
99  1,
100  Eigen::ColMajor,
101  IndexType::MaxSizeAtCompileTime,
103  indexing_functor_vector(const ArgType& arg, const IndexType& indices)
104  : m_arg(arg), m_indices(indices) {}
105  const typename ArgType::Scalar& operator() (Eigen::Index idx) const {
106  return m_arg(m_indices[idx]);
107  }
108 };
109 
113 template <class ArgType, class IndexType>
114 Eigen::CwiseNullaryOp<indexing_functor_vector<ArgType, IndexType>, typename indexing_functor_vector<ArgType, IndexType>::VectorType>
115 indexing_vector(const Eigen::MatrixBase<ArgType>& arg, const IndexType& indices) {
117  typedef typename Func::VectorType VectorType;
118  return VectorType::NullaryExpr(indices.size(), Func(arg.derived(), indices));
119 }
120 
121 }
122 
123 #endif
Dem::indexing_functor_row_col::MatrixType
Eigen::Matrix< typename ArgType::Scalar, RowIndexType::SizeAtCompileTime, ColIndexType::SizeAtCompileTime, ArgType::Flags &Eigen::RowMajorBit?Eigen::RowMajor:Eigen::ColMajor, RowIndexType::MaxSizeAtCompileTime, ColIndexType::MaxSizeAtCompileTime > MatrixType
Definition: Indexing.h:34
Dem::indexing_row
Eigen::CwiseNullaryOp< indexing_functor_row< ArgType, RowIndexType >, typename indexing_functor_row< ArgType, RowIndexType >::MatrixType > indexing_row(const Eigen::MatrixBase< ArgType > &arg, const RowIndexType &row_indices)
Definition: Indexing.h:81
Dem::indexing_functor_row::indexing_functor_row
indexing_functor_row(const ArgType &arg, const RowIndexType &row_indices)
Definition: Indexing.h:69
Dem
Definition: ConvexLS.h:15
Dem::indexing_functor_vector::VectorType
Eigen::Matrix< typename ArgType::Scalar, IndexType::SizeAtCompileTime, 1, Eigen::ColMajor, IndexType::MaxSizeAtCompileTime, 1 > VectorType
Definition: Indexing.h:102
Dem::indexing_functor_vector::operator()
const ArgType::Scalar & operator()(Eigen::Index idx) const
Definition: Indexing.h:105
Dem::indexing_functor_row_col
Definition: Indexing.h:24
Dem::indexing_vector
Eigen::CwiseNullaryOp< indexing_functor_vector< ArgType, IndexType >, typename indexing_functor_vector< ArgType, IndexType >::VectorType > indexing_vector(const Eigen::MatrixBase< ArgType > &arg, const IndexType &indices)
Definition: Indexing.h:115
Dem::indexing_functor_row
Definition: Indexing.h:59
Dem::indexing_functor_row_col::indexing_functor_row_col
indexing_functor_row_col(const ArgType &arg, const RowIndexType &row_indices, const ColIndexType &col_indices)
Definition: Indexing.h:35
Dem::indexing_functor_vector::indexing_functor_vector
indexing_functor_vector(const ArgType &arg, const IndexType &indices)
Definition: Indexing.h:103
Dem::indexing_functor_row_col::operator()
const ArgType::Scalar & operator()(Eigen::Index row, Eigen::Index col) const
Definition: Indexing.h:37
Dem::indexing_functor_row::MatrixType
Eigen::Matrix< typename ArgType::Scalar, RowIndexType::SizeAtCompileTime, ArgType::ColsAtCompileTime, ArgType::Flags &Eigen::RowMajorBit?Eigen::RowMajor:Eigen::ColMajor, RowIndexType::MaxSizeAtCompileTime, ArgType::MaxColsAtCompileTime > MatrixType
Definition: Indexing.h:68
Dem::indexing_functor_vector
Definition: Indexing.h:93
Dem::indexing_functor_row::operator()
const ArgType::Scalar & operator()(Eigen::Index row, Eigen::Index col) const
Definition: Indexing.h:71
Dem::indexing_row_col
Eigen::CwiseNullaryOp< indexing_functor_row_col< ArgType, RowIndexType, ColIndexType >, typename indexing_functor_row_col< ArgType, RowIndexType, ColIndexType >::MatrixType > indexing_row_col(const Eigen::MatrixBase< ArgType > &arg, const RowIndexType &row_indices, const ColIndexType &col_indices)
Definition: Indexing.h:47