Use more efficient colmatrix-based reduction
[libstick.git] / tests / image.h
1 #ifndef image_h_PooBeibuceushabo
2 #define image_h_PooBeibuceushabo
3
4 #include <cpptest.h>
5 #include <cpptest-suite.h>
6
7 #include <libstick-0.1/image.h>
8
9 #include <cassert>
10 #include <math.h>
11
12
13 using namespace libstick;
14
15
16 class image_TestSuite: public Test::Suite {
17
18 private:
19
20 public:
21 image_TestSuite()
22 {
23 TEST_ADD(image_TestSuite::test_incidences);
24 }
25
26 protected:
27 virtual void setup() {
28 }
29
30 virtual void tear_down() {
31 }
32
33 void test_incidences() {
34 const size_t height=128, width=64;
35
36 //Create "some" image
37 float image[height*width];
38 for (unsigned i=0; i < height; ++i)
39 for (unsigned j=0; j < width; ++j)
40 image[i*width + j] = (sin(j/10.0) + 0.5*sin(j/4.0))*cos(i/7.0) + i*j*0.5*1e-3;
41
42 // Create complex and add image
43 typedef simplicial_complex<2, uint32_t, float> scomplex;
44 scomplex s;
45 add_image_to_complex(s, image, width, height);
46 assert(s.is_monotone());
47
48 typedef scomplex::simplex_order sorder;
49 sorder so(s);
50 assert(so.is_filtration());
51
52 typedef boolean_colrowmatrix<uint32_t> bmatrix;
53 bmatrix bm = so.get_boundary_matrix();
54
55 // Check for the right vertex incidences
56 for (unsigned i=0; i < height; ++i) {
57 for (unsigned j=0; j < width; ++j) {
58 // Get matrix row of this vertex. Its size is the number of edges
59 // incident to this vertex
60 const bmatrix::row_type &row = bm.get_row(1 + i*width + j);
61
62 // Somewhere at the boundary of the image
63 if (i == 0 || i == height-1 || j == 0 || j == width-1) {
64 // top-left and bottom-right corner
65 if ((i == 0 && j == 0) || (i == height - 1 && j == width - 1)) {
66 TEST_ASSERT(row.size() == 3);
67 } else if ((i == 0 && j == width - 1) || (i == height - 1 && j == 0)) {
68 TEST_ASSERT(row.size() == 2);
69 } else {
70 TEST_ASSERT(row.size() == 4);
71 }
72 } else {
73 TEST_ASSERT(row.size() == 6);
74 }
75 }
76 }
77 }
78 };
79
80 #endif