OpenWalnut
1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WJOINCONTOURTREE_TEST_H 00026 #define WJOINCONTOURTREE_TEST_H 00027 00028 #include <set> 00029 #include <vector> 00030 00031 #include <cxxtest/TestSuite.h> 00032 00033 #include "../../../common/WLogger.h" 00034 00035 #include "../WJoinContourTree.h" 00036 00037 /** 00038 * Unit tests the Join Tree of the Contour Tree! 00039 */ 00040 class WJoinContourTreeTest : public CxxTest::TestSuite 00041 { 00042 public: 00043 00044 /** 00045 * The construction of a Join Tree is done via a special index array. 00046 */ 00047 void testbuildJoinTreeOnRegular2DGrid( void ) 00048 { 00049 // Expected JoinTree for this example: 00050 /** 00051 // 15 00052 // \ 14 00053 // 13 \ 00054 // \ \ 00055 // 12 \ 00056 // \ \ 00057 // 11 \ 00058 // \ \ 10 00059 // \ \ / 00060 // \ 9 00061 // \ / 00062 // \ 8 00063 // \ / 00064 // 5 00065 // | 00066 // 4 00067 // | 00068 // 3 00069 // | 00070 // 2 00071 // | 00072 // 1 00073 // | 00074 // 0 00075 // | 00076 // -1 00077 // | 00078 // -3 00079 */ 00080 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 00081 size_t data[] = { 4, 9, 3, 3, 5, 1, 7, 2, 12, 13, 11, 14, 6, 8, 9, 11 }; // NOLINT 00082 std::vector< size_t > expectedJT( data, data + 16 ); 00083 WJoinContourTree jt( m_dataset ); 00084 jt.buildJoinTree(); 00085 TS_ASSERT_EQUALS( jt.m_joinTree, expectedJT ); 00086 } 00087 00088 /** 00089 * All voxels enclosed by the biggest isosurface are contained in the biggest component 00090 * of the JoinTree above the given isovalue the in in the JoinTree. 00091 */ 00092 void testGetVolumeVoxelsEnclosedByIsoSurfaceWithOutMerge( void ) 00093 { 00094 size_t data[] = { 0, 4, 5, 1 }; // NOLINT 00095 std::set< size_t > expected( data, data + 4 ); 00096 00097 WJoinContourTree jt( m_dataset ); 00098 jt.buildJoinTree(); 00099 using string_utils::operator<<; 00100 TS_ASSERT_EQUALS( expected, *jt.getVolumeVoxelsEnclosedByIsoSurface( 8.3 ) ); 00101 } 00102 00103 /** 00104 * All voxels enclosed by the biggest isoSurface are contained in the biggest component 00105 * which may be created with some merges of the join tree. 00106 */ 00107 void testGetVolumeVoxelsEnclosedByIsoSurfaceWithMerges( void ) 00108 { 00109 size_t data[] = { 0, 4, 5, 1, 10, 11, 14, 15, 13, 9 }; // NOLINT 00110 std::set< size_t > expected( data, data + 10 ); 00111 00112 WJoinContourTree jt( m_dataset ); 00113 jt.buildJoinTree(); 00114 using string_utils::operator<<; 00115 TS_ASSERT_EQUALS( expected, *jt.getVolumeVoxelsEnclosedByIsoSurface( 4.0 ) ); 00116 } 00117 00118 protected: 00119 /** 00120 * Creates an example dataset so I hope its easy to test the join tree. 00121 */ 00122 void setUp() 00123 { 00124 WLogger::startup(); 00125 00126 // isovalues: Point id's: 00127 // 2--- 4--- 8---14 12---13---14---15 00128 // | | | | | | | | 00129 // | | | | | | | | 00130 // 3--- 5---10--- 9 8--- 9---10---11 00131 // | | | | | | | | 00132 // | | | | | | | | 00133 // 13---12--- 1--- 0 4--- 5--- 6--- 7 00134 // | | | | | | | | 00135 // |___ |___ |____| |___ |___ |____| 00136 // 15 11 -1 -3 0 1 2 3 00137 00138 boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( 4, 4, 1 ) ); 00139 double isoValuesData[] = { 15, 11, -1, -3, 13, 12, 1, 0, 3, 5, 10, 9, 2, 4, 8, 14 }; // NOLINT 00140 boost::shared_ptr< std::vector< double > > isoValues = 00141 boost::shared_ptr< std::vector< double > >( new std::vector< double >( isoValuesData, isoValuesData + 16 ) ); 00142 boost::shared_ptr< WValueSet< double > > valueset( new WValueSet< double >( 0, 1, isoValues, W_DT_DOUBLE ) ); 00143 m_dataset = boost::shared_ptr< WDataSetSingle >( new WDataSetSingle( valueset, grid ) ); 00144 } 00145 00146 /** 00147 * Tidy up things created during setUp 00148 */ 00149 void tearDown( void ) 00150 { 00151 m_dataset.reset(); 00152 } 00153 00154 boost::shared_ptr< WDataSetSingle > m_dataset; //!< Dataset which is used to create the join tree 00155 }; 00156 00157 #endif // WJOINCONTOURTREE_TEST_H