]>
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-0.1/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_complex
<2, uint32_t, float> scomplex
;
45 add_image_to_complex(s
, image
, width
, height
);
46 assert(s
.is_monotone());
48 typedef scomplex::simplex_order sorder
;
50 assert(so
.is_filtration());
52 typedef sorder::boundary_matrix bmatrix
;
53 bmatrix bm
= so
.get_boundary_matrix();
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
);
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);
70 TEST_ASSERT(row
.size() == 4);
73 TEST_ASSERT(row
.size() == 6);