#ifndef image_h_uiHiKahYooroomai
#define image_h_uiHiKahYooroomai
-#include "simplicialcomplex.h"
+#include "simplicialfunction.h"
namespace libstick {
* 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) {
+ * bottom-left.
+ *
+ * Requires that f.is_complete() gives true.
+ * */
+template<class IT, class VT>
+void add_image_to_simplicialfunction(simplicial_function<2, IT, VT> &f, const VT *values, size_t width, size_t height) {
+ assert(f.is_complete());
+
// Add the vertices
- const IT v1st = s.size();
+ const IT v1st = f.size();
for (unsigned i=0; i < height; ++i)
for (unsigned j=0; j < width; ++j)
- s.add_simplex(0, NULL, values[i*width + j]);
+ f.add_simplex(0, NULL, values[i*width + j]);
// row i+1 o-------o
// | /|
IT faces[3];
// Adding horizontal edges
- const IT he1st = s.size();
+ const IT he1st = f.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);
+ f.add_simplex(1, faces);
}
// Adding vertical edges
- const IT ve1st = s.size();
+ const IT ve1st = f.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);
+ f.add_simplex(1, faces);
}
// Adding diagonal edges
- const IT de1st = s.size();
+ const IT de1st = f.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);
+ f.add_simplex(1, faces);
}
// Add triangles
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);
+ f.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);
+ f.add_simplex(2, faces);
}
}