]>
git.sthu.org Git - libstick.git/blob - tests/image.h
1 #ifndef image_h_PooBeibuceushabo
2 #define image_h_PooBeibuceushabo
5 #include <cpptest-suite.h>
7 #include <libstick/image.h>
13 using namespace libstick
;
16 class image_TestSuite
: public Test::Suite
{
23 TEST_ADD(image_TestSuite::test_incidences
);
27 virtual void setup() {
30 virtual void tear_down() {
33 void test_incidences() {
34 const size_t height
=128, width
=64;
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;
42 // Create complex and add image
43 typedef simplicial_function
<2, uint32_t, float> sfunction
;
44 typedef sfunction::scomplex scomplex
;
47 add_image_to_simplicialfunction(f
, image
, width
, height
);
48 assert(f
.is_monotone());
50 typedef scomplex::simplex_order sorder
;
52 assert(so
.is_filtration());
54 typedef boolean_colrowmatrix
<uint32_t> bmatrix
;
55 bmatrix bm
= so
.get_boundary_matrix();
57 // Check for the right vertex incidences
58 for (unsigned i
=0; i
< height
; ++i
) {
59 for (unsigned j
=0; j
< width
; ++j
) {
60 // Get matrix row of this vertex. Its size is the number of edges
61 // incident to this vertex
62 const bmatrix::row_type
&row
= bm
.get_row(1 + i
*width
+ j
);
64 // Somewhere at the boundary of the image
65 if (i
== 0 || i
== height
-1 || j
== 0 || j
== width
-1) {
66 // top-left and bottom-right corner
67 if ((i
== 0 && j
== 0) || (i
== height
- 1 && j
== width
- 1)) {
68 TEST_ASSERT(row
.size() == 3);
69 } else if ((i
== 0 && j
== width
- 1) || (i
== height
- 1 && j
== 0)) {
70 TEST_ASSERT(row
.size() == 2);
72 TEST_ASSERT(row
.size() == 4);
75 TEST_ASSERT(row
.size() == 6);