OpenWalnut  1.5.0dev
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 <memory>
29 #include <set>
30 #include <vector>
31 
32 #include <cxxtest/TestSuite.h>
33 
34 #include "../../../common/WLogger.h"
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  * The construction of a Join Tree is done via a special index array.
45  */
47  {
48  // Expected JoinTree for this example:
49  /**
50  // 15
51  // \ 14
52  // 13 \
53  // \ \
54  // 12 \
55  // \ \
56  // 11 \
57  // \ \ 10
58  // \ \ /
59  // \ 9
60  // \ /
61  // \ 8
62  // \ /
63  // 5
64  // |
65  // 4
66  // |
67  // 3
68  // |
69  // 2
70  // |
71  // 1
72  // |
73  // 0
74  // |
75  // -1
76  // |
77  // -3
78  */
79  // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
80  size_t data[] = { 4, 9, 3, 3, 5, 1, 7, 2, 12, 13, 11, 14, 6, 8, 9, 11 }; // NOLINT
81  std::vector< size_t > expectedJT( data, data + 16 );
83  jt.buildJoinTree();
84  TS_ASSERT_EQUALS( jt.m_joinTree, expectedJT );
85  }
86 
87  /**
88  * All voxels enclosed by the biggest isosurface are contained in the biggest component
89  * of the JoinTree above the given isovalue the in in the JoinTree.
90  */
92  {
93  size_t data[] = { 0, 4, 5, 1 }; // NOLINT
94  std::set< size_t > expected( data, data + 4 );
95 
97  jt.buildJoinTree();
98  using string_utils::operator<<;
99  TS_ASSERT_EQUALS( expected, *jt.getVolumeVoxelsEnclosedByIsoSurface( 8.3 ) );
100  }
101 
102  /**
103  * All voxels enclosed by the biggest isoSurface are contained in the biggest component
104  * which may be created with some merges of the join tree.
105  */
107  {
108  size_t data[] = { 0, 4, 5, 1, 10, 11, 14, 15, 13, 9 }; // NOLINT
109  std::set< size_t > expected( data, data + 10 );
110 
112  jt.buildJoinTree();
113  using string_utils::operator<<;
114  TS_ASSERT_EQUALS( expected, *jt.getVolumeVoxelsEnclosedByIsoSurface( 4.0 ) );
115  }
116 
117 protected:
118  /**
119  * Creates an example dataset so I hope its easy to test the join tree.
120  */
121  void setUp()
122  {
124 
125  // isovalues: Point id's:
126  // 2--- 4--- 8---14 12---13---14---15
127  // | | | | | | | |
128  // | | | | | | | |
129  // 3--- 5---10--- 9 8--- 9---10---11
130  // | | | | | | | |
131  // | | | | | | | |
132  // 13---12--- 1--- 0 4--- 5--- 6--- 7
133  // | | | | | | | |
134  // |___ |___ |____| |___ |___ |____|
135  // 15 11 -1 -3 0 1 2 3
136 
137  std::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( 4, 4, 1 ) );
138  double isoValuesData[] = { 15, 11, -1, -3, 13, 12, 1, 0, 3, 5, 10, 9, 2, 4, 8, 14 }; // NOLINT
139  std::shared_ptr< std::vector< double > > isoValues =
140  std::shared_ptr< std::vector< double > >( new std::vector< double >( isoValuesData, isoValuesData + 16 ) );
141  std::shared_ptr< WValueSet< double > > valueset( new WValueSet< double >( 0, 1, isoValues, W_DT_DOUBLE ) );
142  m_dataset = std::shared_ptr< WDataSetSingle >( new WDataSetSingle( valueset, grid ) );
143  }
144 
145  /**
146  * Tidy up things created during setUp
147  */
148  void tearDown( void )
149  {
150  m_dataset.reset();
151  }
152 
153  std::shared_ptr< WDataSetSingle > m_dataset; //!< Dataset which is used to create the join tree
154 };
155 
156 #endif // WJOINCONTOURTREE_TEST_H
A data set consisting of a set of values based on a grid.
A grid that has parallelepiped cells which all have the same proportion.
Unit tests the Join Tree of the Contour Tree!
void testGetVolumeVoxelsEnclosedByIsoSurfaceWithMerges(void)
All voxels enclosed by the biggest isoSurface are contained in the biggest component which may be cre...
void setUp()
Creates an example dataset so I hope its easy to test the join tree.
void testbuildJoinTreeOnRegular2DGrid(void)
The construction of a Join Tree is done via a special index array.
void tearDown(void)
Tidy up things created during setUp.
void testGetVolumeVoxelsEnclosedByIsoSurfaceWithOutMerge(void)
All voxels enclosed by the biggest isosurface are contained in the biggest component of the JoinTree ...
std::shared_ptr< WDataSetSingle > m_dataset
Dataset which is used to create the join tree.
Processes a dataset for join tree computation.
std::vector< size_t > m_joinTree
For each index stores which node it is connected to.
void buildJoinTree()
Build the join tree.
std::shared_ptr< std::set< size_t > > getVolumeVoxelsEnclosedByIsoSurface(const double isoValue) const
For a given isovalue all the voxel which are enclosed by the biggest isosurface are computed.
static void startup(std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
Create the first and only instance of the logger as it is a singleton.
Definition: WLogger.cpp:41
Base Class for all value set types.
Definition: WValueSet.h:47