OpenWalnut
1.4.0
|
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 * The construction of a Join Tree is done via a special index array. 00045 */ 00046 void testbuildJoinTreeOnRegular2DGrid( void ) 00047 { 00048 // Expected JoinTree for this example: 00049 /** 00050 // 15 00051 // \ 14 00052 // 13 \ 00053 // \ \ 00054 // 12 \ 00055 // \ \ 00056 // 11 \ 00057 // \ \ 10 00058 // \ \ / 00059 // \ 9 00060 // \ / 00061 // \ 8 00062 // \ / 00063 // 5 00064 // | 00065 // 4 00066 // | 00067 // 3 00068 // | 00069 // 2 00070 // | 00071 // 1 00072 // | 00073 // 0 00074 // | 00075 // -1 00076 // | 00077 // -3 00078 */ 00079 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 00080 size_t data[] = { 4, 9, 3, 3, 5, 1, 7, 2, 12, 13, 11, 14, 6, 8, 9, 11 }; // NOLINT 00081 std::vector< size_t > expectedJT( data, data + 16 ); 00082 WJoinContourTree jt( m_dataset ); 00083 jt.buildJoinTree(); 00084 TS_ASSERT_EQUALS( jt.m_joinTree, expectedJT ); 00085 } 00086 00087 /** 00088 * All voxels enclosed by the biggest isosurface are contained in the biggest component 00089 * of the JoinTree above the given isovalue the in in the JoinTree. 00090 */ 00091 void testGetVolumeVoxelsEnclosedByIsoSurfaceWithOutMerge( void ) 00092 { 00093 size_t data[] = { 0, 4, 5, 1 }; // NOLINT 00094 std::set< size_t > expected( data, data + 4 ); 00095 00096 WJoinContourTree jt( m_dataset ); 00097 jt.buildJoinTree(); 00098 using string_utils::operator<<; 00099 TS_ASSERT_EQUALS( expected, *jt.getVolumeVoxelsEnclosedByIsoSurface( 8.3 ) ); 00100 } 00101 00102 /** 00103 * All voxels enclosed by the biggest isoSurface are contained in the biggest component 00104 * which may be created with some merges of the join tree. 00105 */ 00106 void testGetVolumeVoxelsEnclosedByIsoSurfaceWithMerges( void ) 00107 { 00108 size_t data[] = { 0, 4, 5, 1, 10, 11, 14, 15, 13, 9 }; // NOLINT 00109 std::set< size_t > expected( data, data + 10 ); 00110 00111 WJoinContourTree jt( m_dataset ); 00112 jt.buildJoinTree(); 00113 using string_utils::operator<<; 00114 TS_ASSERT_EQUALS( expected, *jt.getVolumeVoxelsEnclosedByIsoSurface( 4.0 ) ); 00115 } 00116 00117 protected: 00118 /** 00119 * Creates an example dataset so I hope its easy to test the join tree. 00120 */ 00121 void setUp() 00122 { 00123 WLogger::startup(); 00124 00125 // isovalues: Point id's: 00126 // 2--- 4--- 8---14 12---13---14---15 00127 // | | | | | | | | 00128 // | | | | | | | | 00129 // 3--- 5---10--- 9 8--- 9---10---11 00130 // | | | | | | | | 00131 // | | | | | | | | 00132 // 13---12--- 1--- 0 4--- 5--- 6--- 7 00133 // | | | | | | | | 00134 // |___ |___ |____| |___ |___ |____| 00135 // 15 11 -1 -3 0 1 2 3 00136 00137 boost::shared_ptr< WGridRegular3D > grid( new WGridRegular3D( 4, 4, 1 ) ); 00138 double isoValuesData[] = { 15, 11, -1, -3, 13, 12, 1, 0, 3, 5, 10, 9, 2, 4, 8, 14 }; // NOLINT 00139 boost::shared_ptr< std::vector< double > > isoValues = 00140 boost::shared_ptr< std::vector< double > >( new std::vector< double >( isoValuesData, isoValuesData + 16 ) ); 00141 boost::shared_ptr< WValueSet< double > > valueset( new WValueSet< double >( 0, 1, isoValues, W_DT_DOUBLE ) ); 00142 m_dataset = boost::shared_ptr< WDataSetSingle >( new WDataSetSingle( valueset, grid ) ); 00143 } 00144 00145 /** 00146 * Tidy up things created during setUp 00147 */ 00148 void tearDown( void ) 00149 { 00150 m_dataset.reset(); 00151 } 00152 00153 boost::shared_ptr< WDataSetSingle > m_dataset; //!< Dataset which is used to create the join tree 00154 }; 00155 00156 #endif // WJOINCONTOURTREE_TEST_H