X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=tests%2Fimage.h;fp=tests%2Fimage.h;h=ff7817af6193cc4f2744b1c542c82e5f55b41f27;hb=4b8265e5bcfd2332a3333c4129352e10c2d59c2f;hp=0000000000000000000000000000000000000000;hpb=b7f36c820bf1c247ff02c5647e9cca597a9a1ba9;p=libstick.git diff --git a/tests/image.h b/tests/image.h new file mode 100644 index 0000000..ff7817a --- /dev/null +++ b/tests/image.h @@ -0,0 +1,80 @@ +#ifndef image_h_PooBeibuceushabo +#define image_h_PooBeibuceushabo + +#include +#include + +#include + +#include +#include + + +using namespace libstick; + + +class image_TestSuite: public Test::Suite { + + private: + + public: + image_TestSuite() + { + TEST_ADD(image_TestSuite::test_incidences); + } + + protected: + virtual void setup() { + } + + virtual void tear_down() { + } + + void test_incidences() { + const size_t height=128, width=64; + + //Create "some" image + float image[height*width]; + for (unsigned i=0; i < height; ++i) + for (unsigned j=0; j < width; ++j) + image[i*width + j] = (sin(j/10.0) + 0.5*sin(j/4.0))*cos(i/7.0) + i*j*0.5*1e-3; + + // Create complex and add image + typedef simplicial_complex<2, uint32_t, float> scomplex; + scomplex s; + add_image_to_complex(s, image, width, height); + assert(s.is_monotone()); + + typedef scomplex::simplex_order sorder; + sorder so(s); + assert(so.is_filtration()); + + typedef sorder::boundary_matrix bmatrix; + bmatrix bm = so.get_boundary_matrix(); + + // Check for the right vertex incidences + for (unsigned i=0; i < height; ++i) { + for (unsigned j=0; j < width; ++j) { + // Get matrix row of this vertex. Its size is the number of edges + // incident to this vertex + const bmatrix::row_type &row = bm.get_row(1 + i*width + j); + + // Somewhere at the boundary of the image + if (i == 0 || i == height-1 || j == 0 || j == width-1) { + // top-left and bottom-right corner + if ((i == 0 && j == 0) || (i == height - 1 && j == width - 1)) { + TEST_ASSERT(row.size() == 3); + } else if ((i == 0 && j == width - 1) || (i == height - 1 && j == 0)) { + TEST_ASSERT(row.size() == 2); + } else { + TEST_ASSERT(row.size() == 4); + } + } else { + TEST_ASSERT(row.size() == 6); + } + } + } + } +}; + +#endif