Wildmeshing Toolkit
EigenMatrixWriter.cpp
Go to the documentation of this file.
1 #include "EigenMatrixWriter.hpp"
2 
3 namespace wmtk::utils {
4 
6 {
7  get_double_matrix("vertices", PrimitiveType::Vertex, matrix);
8 }
9 
11 {
12  get_Rational_matrix("vertices", PrimitiveType::Vertex, matrix);
13 }
14 
15 
17 {
19 }
20 
22 {
24 }
25 
27 {
28  get_int64_t_matrix("m_ev", PrimitiveType::Edge, matrix);
29 }
30 
32  const std::string& name,
33  const PrimitiveType type,
34  MatrixX<double>& matrix)
35 {
36  if (doubles.find(std::make_pair(name, type)) != doubles.end()) {
37  matrix = doubles[std::make_pair(name, type)];
38  } else {
39  throw std::runtime_error("No attribute named " + name);
40  }
41 }
42 
44  const std::string& name,
45  const PrimitiveType type,
46  MatrixX<int64_t>& matrix)
47 {
48  if (int64_ts.find(std::make_pair(name, type)) != int64_ts.end()) {
49  matrix = int64_ts[std::make_pair(name, type)];
50  } else {
51  throw std::runtime_error("No attribute named " + name);
52  }
53 }
54 
56  const std::string& name,
57  const PrimitiveType type,
58  MatrixX<char>& matrix)
59 {
60  if (chars.find(std::make_pair(name, type)) != chars.end()) {
61  matrix = chars[std::make_pair(name, type)];
62  } else {
63  throw std::runtime_error("No attribute named " + name);
64  }
65 }
66 
68  const std::string& name,
69  const PrimitiveType type,
70  MatrixX<Rational>& matrix)
71 {
72  if (Rationals.find(std::make_pair(name, type)) != Rationals.end()) {
73  matrix = Rationals[std::make_pair(name, type)];
74  } else {
75  throw std::runtime_error("No attribute named " + name);
76  }
77 }
78 
79 template <typename T>
81  std::map<std::pair<std::string, PrimitiveType>, MatrixX<T>>& Ts,
82  const std::string& name,
83  const int64_t type,
84  const int64_t stride,
85  const std::vector<T>& val,
86  const T& default_val)
87 {
88  if (m_mm_level != 1) return;
89  using MapType = typename MatrixX<T>::ConstMapType;
90  Ts[std::make_pair(name, PrimitiveType(type))] =
91  MapType(val.data(), stride, val.size() / stride).transpose();
92 }
93 
95  const std::string& name,
96  const int64_t type,
97  const int64_t stride,
98  const std::vector<char>& val,
99  const char default_val)
100 {
101  write_internal(chars, name, type, stride, val, default_val);
102 }
103 
105  const std::string& name,
106  const int64_t type,
107  const int64_t stride,
108  const std::vector<int64_t>& val,
109  const int64_t default_val)
110 {
111  write_internal(int64_ts, name, type, stride, val, default_val);
112 }
113 
115  const std::string& name,
116  const int64_t type,
117  const int64_t stride,
118  const std::vector<double>& val,
119  const double default_val)
120 {
121  write_internal(doubles, name, type, stride, val, default_val);
122 }
123 
125  const std::string& name,
126  const int64_t type,
127  const int64_t stride,
128  const std::vector<Rational>& val,
129  const Rational& default_val)
130 {
131  write_internal(Rationals, name, type, stride, val, default_val);
132 }
133 
134 
135 /* use less functions below, TODO: should throw?*/
137 {
138  return;
139 }
140 void EigenMatrixWriter::write_absolute_id(const std::vector<int64_t>& id)
141 {
142  ++m_mm_level;
143 }
144 void EigenMatrixWriter::write_capacities(const std::vector<int64_t>& capacities)
145 {
146  return;
147 }
148 
149 
150 } // namespace wmtk::utils
int64_t m_mm_level
Definition: MeshWriter.hpp:51
std::map< std::pair< std::string, PrimitiveType >, MatrixX< double > > doubles
std::map< std::pair< std::string, PrimitiveType >, MatrixX< char > > chars
void get_position_matrix(MatrixX< double > &matrix)
std::map< std::pair< std::string, PrimitiveType >, MatrixX< int64_t > > int64_ts
void write_internal(std::map< std::pair< std::string, PrimitiveType >, MatrixX< T >> &Ts, const std::string &name, const int64_t type, const int64_t stride, const std::vector< T > &val, const T &default_val)
void get_Rational_matrix(const std::string &name, const PrimitiveType type, MatrixX< Rational > &matrix)
void write_top_simplex_type(const PrimitiveType type) override
void get_EV_matrix(MatrixX< int64_t > &matrix)
void get_TV_matrix(MatrixX< int64_t > &matrix)
bool write(const int dim) override
void get_char_matrix(const std::string &name, const PrimitiveType type, MatrixX< char > &matrix)
void write_absolute_id(const std::vector< int64_t > &id) override
void get_int64_t_matrix(const std::string &name, const PrimitiveType type, MatrixX< int64_t > &matrix)
void get_FV_matrix(MatrixX< int64_t > &matrix)
void write_capacities(const std::vector< int64_t > &capacities) override
std::map< std::pair< std::string, PrimitiveType >, MatrixX< Rational > > Rationals
void get_double_matrix(const std::string &name, const PrimitiveType type, MatrixX< double > &matrix)
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Definition: Types.hpp:14