+#ifndef image_h_uiHiKahYooroomai
+#define image_h_uiHiKahYooroomai
+
+#include "simplicialcomplex.h"
+
+
+namespace libstick {
+
+/** We consider an image, i.e. a rectangular arrangement of pixels, of given
+ * height and width. Every pixel has a specific value (e.g., grey value) given
+ * by the 'values' array as concatenation of all rows. We add every pixel as
+ * vertex with its value as simplex value. We further triangulate the resulting
+ * rectangular latice as a grid graph together with south-west to north-east
+ * edges for each of the small squares of the grid graph. Finally the resulting
+ * triangles are added. For all non-vertex simplices the maximum of its
+ * vertex-values is used as its value. The first pixel is considered to be at
+ * bottom-left. */
+template<class VT, class IT>
+void add_image_to_complex(simplicial_complex<2, IT, VT> &s, const VT *values, size_t width, size_t height) {
+ // Add the vertices
+ const IT v1st = s.size();
+ for (unsigned i=0; i < height; ++i)
+ for (unsigned j=0; j < width; ++j)
+ s.add_simplex(0, NULL, values[i*width + j]);
+
+ // row i+1 o-------o
+ // | /|
+ // | / |
+ // | 2/ |
+ // 0 | / |
+ // | / |
+ // | / |
+ // |/ 1 |
+ // row i o-------o
+ // ^
+ // column j
+
+ IT faces[3];
+
+ // Adding horizontal edges
+ const IT he1st = s.size();
+ for (unsigned i=0; i < height; ++i)
+ for (unsigned j=0; j < width-1; ++j) {
+ faces[0] = v1st + i*width + j;
+ faces[1] = faces[0] + 1;
+ s.add_simplex(1, faces);
+ }
+
+ // Adding vertical edges
+ const IT ve1st = s.size();
+ for (unsigned i=0; i < height-1; ++i)
+ for (unsigned j=0; j < width; ++j) {
+ faces[0] = v1st + i*width + j;
+ faces[1] = faces[0] + width;
+ s.add_simplex(1, faces);
+ }
+
+ // Adding diagonal edges
+ const IT de1st = s.size();
+ for (unsigned i=0; i < height-1; ++i)
+ for (unsigned j=0; j < width-1; ++j) {
+ faces[0] = v1st + i*width + j;
+ faces[1] = faces[0] + width + 1;
+ s.add_simplex(1, faces);
+ }
+
+ // Add triangles
+ for (unsigned i=0; i < height-1; ++i)
+ for (unsigned j=0; j < width-1; ++j) {
+ faces[0] = he1st + i*(width-1) + j;
+ faces[1] = ve1st + i*width + j + 1;
+ faces[2] = de1st + i*(width-1) + j;
+ s.add_simplex(2, faces);
+
+ faces[0] = he1st + (i+1)*(width-1) + j;
+ faces[1] = ve1st + i*width + j;
+ faces[2] = de1st + i*(width-1) + j;
+ s.add_simplex(2, faces);
+ }
+}
+
+
+}
+
+#endif
+