|
7 | 7 |
|
8 | 8 | namespace CurvatureMetric { |
9 | 9 |
|
| 10 | + |
| 11 | +class FlipMapMatrixGenerator { |
| 12 | +public: |
| 13 | +FlipMapMatrixGenerator(int size) |
| 14 | +: m_size(size) { |
| 15 | + reset(); |
| 16 | + |
| 17 | +} |
| 18 | + |
| 19 | +void reset() { |
| 20 | + m_list_of_lists = |
| 21 | + std::vector<std::map<int, Scalar>>(m_size, std::map<int, Scalar>()); |
| 22 | + for (int i = 0; i < m_size; ++i) { |
| 23 | + m_list_of_lists[i][i] = 1.0; |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +void multiply_by_matrix( |
| 28 | + const std::vector<int>& matrix_indices, |
| 29 | + const std::vector<Scalar>& matrix_scalars, |
| 30 | + int ed |
| 31 | +) { |
| 32 | + // Compute the new row of J_del corresponding to edge ed, which is the only |
| 33 | + // edge that changes |
| 34 | + std::map<int, Scalar> J_del_d_new; |
| 35 | + for (int i = 0; i < 5; ++i) { |
| 36 | + int ei = matrix_indices[i]; |
| 37 | + Scalar Di = matrix_scalars[i]; |
| 38 | + for (auto it : m_list_of_lists[ei]) { |
| 39 | + J_del_d_new[it.first] += Di * it.second; |
| 40 | + } |
| 41 | + } |
| 42 | + m_list_of_lists[ed] = J_del_d_new; |
| 43 | +} |
| 44 | + |
| 45 | +MatrixX build_matrix() const { |
| 46 | + // Build triplets from list of lists |
| 47 | + typedef Eigen::Triplet<Scalar> T; |
| 48 | + std::vector<T> tripletList; |
| 49 | + tripletList.reserve(5 * m_size); |
| 50 | + for (int i = 0; i < m_size; ++i) { |
| 51 | + for (auto it : m_list_of_lists[i]) { |
| 52 | + tripletList.push_back(T(i, it.first, it.second)); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + // Create the matrix from the triplets |
| 57 | + MatrixX matrix; |
| 58 | + matrix.resize(m_size, m_size); |
| 59 | + matrix.reserve(tripletList.size()); |
| 60 | + matrix.setFromTriplets(tripletList.begin(), tripletList.end()); |
| 61 | + |
| 62 | + return matrix; |
| 63 | +} |
| 64 | + |
| 65 | +private: |
| 66 | + int m_size; |
| 67 | + std::vector<std::map<int, Scalar>> m_list_of_lists; |
| 68 | +}; |
| 69 | + |
10 | 70 | class FlipMatrixGenerator |
11 | 71 | { |
12 | 72 | public: |
|
0 commit comments