X-Git-Url: https://git.sthu.org/?p=libstick.git;a=blobdiff_plain;f=include%2Flibstick%2Fimage.h;h=b33801c6f46e120c7d91a7c8f858cfe458b223a6;hp=abb1df02c42c9e77039e901a4bd68f92ab04e4a8;hb=7186ae9cc97393496d7f0e0cb281524276f1e47c;hpb=d6673c66ae1cb2b421b6e0c4b6a2f6ea6f0fad98 diff --git a/include/libstick/image.h b/include/libstick/image.h index abb1df0..b33801c 100644 --- a/include/libstick/image.h +++ b/include/libstick/image.h @@ -1,7 +1,7 @@ #ifndef image_h_uiHiKahYooroomai #define image_h_uiHiKahYooroomai -#include "simplicialcomplex.h" +#include "simplicialfunction.h" namespace libstick { @@ -14,14 +14,19 @@ 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 -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 +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 // | /| @@ -38,30 +43,30 @@ void add_image_to_complex(simplicial_complex<2, IT, VT> &s, const VT *values, si 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 @@ -70,12 +75,12 @@ void add_image_to_complex(simplicial_complex<2, IT, VT> &s, const VT *values, si 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); } }