OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WJoinContourTree_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WJOINCONTOURTREE_TEST_H
26 #define WJOINCONTOURTREE_TEST_H
27 
28 #include <set>
29 #include <vector>
30 
31 #include <cxxtest/TestSuite.h>
32 
33 #include "../../../common/WLogger.h"
34 
35 #include "../WJoinContourTree.h"
36 
37 /**
38  * Unit tests the Join Tree of the Contour Tree!
39  */
40 class WJoinContourTreeTest : public CxxTest::TestSuite
41 {
42 public:
43 
44  /**
45  * The construction of a Join Tree is done via a special index array.
46  */
48  {
49  // Expected JoinTree for this example:
50  /**
51  // 15
52  // \ 14
53  // 13 \
54  // \ \
55  // 12 \
56  // \ \
57  // 11 \
58  // \ \ 10
59  // \ \ /
60  // \ 9
61  // \ /
62  // \ 8
63  // \ /
64  // 5
65  // |
66  // 4
67  // |
68  // 3
69  // |
70  // 2
71  // |
72  // 1
73  // |
74  // 0
75  // |
76  // -1
77  // |
78  // -3
79  */
80  // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
81  size_t data[] = { 4, 9, 3, 3, 5, 1, 7, 2, 12, 13, 11, 14, 6, 8, 9, 11 }; // NOLINT
82  std::vector< size_t > expectedJT( data, data + 16 );
84  jt.buildJoinTree();
85  TS_ASSERT_EQUALS( jt.m_joinTree, expectedJT );
86  }
87 
88  /**
89  * All voxels enclosed by the biggest isosurface are contained in the biggest component
90  * of the JoinTree above the given isovalue the in in the JoinTree.
91  */
93  {
94  size_t data[] = { 0, 4, 5, 1 }; // NOLINT
95  std::set< size_t > expected( data, data + 4 );
96 
98  jt.buildJoinTree();
99  using string_utils::operator<<;
100  TS_ASSERT_EQUALS( expected, *jt.getVolumeVoxelsEnclosedByIsoSurface( 8.3 ) );
101  }
102 
103  /**
104  * All voxels enclosed by the biggest isoSurface are contained in the biggest component
105  * which may be created with some merges of the join tree.
106  */
108  {
109  size_t data[] = { 0, 4, 5, 1, 10, 11, 14, 15, 13, 9 }; // NOLINT
110  std::set< size_t > expected( data, data + 10 );
111 
113  jt.buildJoinTree();
114  using string_utils::operator<<;
115  TS_ASSERT_EQUALS( expected, *jt.getVolumeVoxelsEnclosedByIsoSurface( 4.0 ) );
116  }
117 
118 protected:
119  /**
120  * Creates an example dataset so I hope its easy to test the join tree.
121  */
122  void setUp()
123  {
125 
126  // isovalues: Point id's:
127  // 2--- 4--- 8---14 12---13---14---15
128  // | | | | | | | |
129  // | | | | | | | |
130  // 3--- 5---10--- 9 8--- 9---10---11
131  // | | | | | | | |
132  // | | | | | | | |
133  // 13---12--- 1--- 0 4--- 5--- 6--- 7
134  // | | | | | | | |
135  // |___ |___ |____| |___ |___ |____|
136  // 15 11 -1 -3 0 1 2 3
137 
138  boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( 4, 4, 1 ) );
139  double isoValuesData[] = { 15, 11, -1, -3, 13, 12, 1, 0, 3, 5, 10, 9, 2, 4, 8, 14 }; // NOLINT
140  boost::shared_ptr< std::vector< double > > isoValues =
141  boost::shared_ptr< std::vector< double > >( new std::vector< double >( isoValuesData, isoValuesData + 16 ) );
142  boost::shared_ptr< WValueSet< double > > valueset( new WValueSet< double >( 0, 1, isoValues, W_DT_DOUBLE ) );
143  m_dataset = boost::shared_ptr< WDataSetSingle >( new WDataSetSingle( valueset, grid ) );
144  }
145 
146  /**
147  * Tidy up things created during setUp
148  */
149  void tearDown( void )
150  {
151  m_dataset.reset();
152  }
153 
154  boost::shared_ptr< WDataSetSingle > m_dataset; //!< Dataset which is used to create the join tree
155 };
156 
157 #endif // WJOINCONTOURTREE_TEST_H