Wildmeshing Toolkit
Loading...
Searching...
No Matches
EigenMatrixWriter.cpp
Go to the documentation of this file.
2
3namespace wmtk::utils {
4
5void EigenMatrixWriter::get_position_matrix(MatrixX<double>& matrix)
6{
7 get_double_matrix("vertices", PrimitiveType::Vertex, matrix);
8}
9
10void EigenMatrixWriter::get_position_matrix(MatrixX<Rational>& matrix)
11{
12 get_Rational_matrix("vertices", PrimitiveType::Vertex, matrix);
13}
14
15
16void EigenMatrixWriter::get_TV_matrix(MatrixX<int64_t>& matrix)
17{
19}
20
21void EigenMatrixWriter::get_FV_matrix(MatrixX<int64_t>& matrix)
22{
24}
25
26void EigenMatrixWriter::get_EV_matrix(MatrixX<int64_t>& matrix)
27{
29}
30
31void EigenMatrixWriter::get_double_matrix(
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
43void EigenMatrixWriter::get_int64_t_matrix(
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
55void EigenMatrixWriter::get_char_matrix(
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
67void EigenMatrixWriter::get_Rational_matrix(
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
79template <typename T>
80void EigenMatrixWriter::write_internal(
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
94void EigenMatrixWriter::write(
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
104void EigenMatrixWriter::write(
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
114void EigenMatrixWriter::write(
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
124void EigenMatrixWriter::write(
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?*/
136void EigenMatrixWriter::write_top_simplex_type(const PrimitiveType type)
137{
138 return;
139}
140void EigenMatrixWriter::write_absolute_id(const std::vector<int64_t>& id)
141{
142 ++m_mm_level;
143}
144void EigenMatrixWriter::write_capacities(const std::vector<int64_t>& capacities)
145{
146 return;
147}
148
149
150} // namespace wmtk::utils
std::map< std::pair< std::string, PrimitiveType >, MatrixX< double > > doubles
std::map< std::pair< std::string, PrimitiveType >, MatrixX< char > > chars
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 get_int64_t_matrix(const std::string &name, const PrimitiveType type, MatrixX< int64_t > &matrix)
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