6 #define STB_IMAGE_IMPLEMENTATION
13 int width, height, channels;
14 unsigned char* img = stbi_load(file.string().c_str(), &width, &height, &channels, 0);
16 throw std::runtime_error(
"Error in loading the image");
18 const size_t img_size = width * height * channels;
20 Eigen::Matrix<int64_t, -1, -1> pixel_matrix;
21 pixel_matrix.resize(height, width);
23 for (
size_t i = 0; i < height; ++i) {
24 for (
size_t j = 0; j < width; ++j) {
25 const int pixel = *(img + ((width * i) + j) * channels);
26 pixel_matrix(i, j) = pixel;
36 const std::filesystem::path& file,
37 const std::string& tag_name)
39 std::shared_ptr<wmtk::TriMesh> m = std::make_shared<wmtk::TriMesh>();
43 std::cout <<
"img:\n" << img << std::endl;
45 auto lex_index_v = [&img](
size_t i,
size_t j) {
return i * (img.cols() + 1) + j; };
46 auto lex_index_f = [&img](
size_t i,
size_t j) {
return i * img.cols() + j; };
50 V.resize((img.rows() + 1) * (img.cols() + 1), 2);
51 for (
size_t i = 0; i < img.rows() + 1; ++i) {
52 for (
size_t j = 0; j < img.cols() + 1; ++j) {
53 V.row(lex_index_v(i, j)) = Eigen::Matrix<double, 2, 1>(j, img.rows() - i);
59 F.resize(img.rows() * img.cols() * 2, 3);
61 tags.resize(F.rows(), 1);
62 for (
size_t i = 0; i < img.rows(); ++i) {
63 for (
size_t j = 0; j < img.cols(); ++j) {
64 const int v0 = lex_index_v(i, j);
65 const int v1 = lex_index_v(i, j + 1);
66 const int v2 = lex_index_v(i + 1, j);
67 const int v3 = lex_index_v(i + 1, j + 1);
68 F.row(2 * lex_index_f(i, j) + 0) = Eigen::Matrix<int64_t, 3, 1>(v0, v2, v1);
69 F.row(2 * lex_index_f(i, j) + 1) = Eigen::Matrix<int64_t, 3, 1>(v2, v3, v1);
70 tags(2 * lex_index_f(i, j) + 0) = img(i, j);
71 tags(2 * lex_index_f(i, j) + 1) = img(i, j);
attribute::MeshAttributeHandle set_matrix_attribute(const Mat &data, const std::string &name, const PrimitiveType &type, Mesh &mesh)
RowVectors< int64_t, 3 > RowVectors3l
Eigen::Matrix< T, Eigen::Dynamic, C > RowVectors