Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 39 lines (34 sloc) 1.238 kb
eac5e31 @moritz visualize matrices with imlib2
authored
1 #ifndef __VISUALIZE_H
2 #define __VISUALIZE_H
3
d60d10d @moritz generalize visualize.h
authored
4 #include <Eigen/Core>
5 #include <Eigen/Sparse>
eac5e31 @moritz visualize matrices with imlib2
authored
6 #include <Imlib2.h>
7
d60d10d @moritz generalize visualize.h
authored
8 template <typename T, int _Flags>
d8f460c rip out useless, non-working MUMPS stuff
Moritz Lenz authored
9 void visualize(const Eigen::SparseMatrix<T, _Flags> &matrix, const char* filename) {
10 using namespace std;
eac5e31 @moritz visualize matrices with imlib2
authored
11 int my = matrix.rows();
12 int mx = matrix.cols();
3b745f4 don't visualize large images
Moritz Lenz authored
13 if (mx * my > 1000000) {
14 std::cerr <<
15 "visualize(): warning: matrix too large, not writing "
16 "image `" << filename << "'\n";
17 return;
18 }
eac5e31 @moritz visualize matrices with imlib2
authored
19 unsigned char *pixmap = (unsigned char*)malloc(4 * mx * my);
20 memset(pixmap, 255, 4 * mx * my);
21 for (int k = 0; k < matrix.outerSize(); ++k) {
d60d10d @moritz generalize visualize.h
authored
22 for (typename Eigen::SparseMatrix<T>::InnerIterator it(matrix,k); it; ++it) {
eac5e31 @moritz visualize matrices with imlib2
authored
23 int i = it.col() * mx + it.row();
d8f460c rip out useless, non-working MUMPS stuff
Moritz Lenz authored
24 // cout << mx << " " << my << " " << it.col() << " " << it.row() << endl;
25 assert(4 * i + 1 < 4 * mx * my);
eac5e31 @moritz visualize matrices with imlib2
authored
26 pixmap[4 * i ] = 0;
27 pixmap[4 * i + 1] = 0;
28 pixmap[4 * i + 2] = 0;
29 }
30 }
31 Imlib_Image img = imlib_create_image_using_data(mx, my, (DATA32 *) pixmap);
32 imlib_context_set_image(img);
33 imlib_save_image(filename);
34 }
35
36
3b745f4 don't visualize large images
Moritz Lenz authored
37 // vim: ts=4 sw=4 expandtab
eac5e31 @moritz visualize matrices with imlib2
authored
38 #endif /* __VISUALIZE_H */
Something went wrong with that request. Please try again.