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 WMARCHINGCUBESALGORITHM_TEST_H 00026 #define WMARCHINGCUBESALGORITHM_TEST_H 00027 00028 #include <vector> 00029 #include <cxxtest/TestSuite.h> 00030 00031 #include "../WMarchingCubesAlgorithm.h" 00032 00033 /** 00034 * Tests for the class computing the actual marching cubes. 00035 */ 00036 class WMarchingCubesAlgorithmTest : public CxxTest::TestSuite 00037 { 00038 public: 00039 /** 00040 * Test interpolate on edge 00041 */ 00042 void testInterpolate() 00043 { 00044 WMarchingCubesAlgorithm mc; 00045 mc.m_tIsoLevel = 1.7; // mu = 0.5454... 00046 00047 WPointXYZId expected; 00048 expected.newID = 0; 00049 expected.x = 1.3545454545454545; 00050 expected.y = 2.4545454545454545; 00051 expected.z = 5.4090909090909091; 00052 00053 WPointXYZId result = mc.interpolate( 1.3, 2.4, 3.5, 00054 1.4, 2.5, 7.0, 00055 1.1, 2.2 ); 00056 00057 double delta = 1e-9; 00058 TS_ASSERT_DELTA( expected.x, result.x, delta ); 00059 TS_ASSERT_DELTA( expected.y, result.y, delta ); 00060 TS_ASSERT_DELTA( expected.z, result.z, delta ); 00061 TS_ASSERT_EQUALS( expected.newID, result.newID ); 00062 } 00063 00064 /** 00065 * Test computation of veretexID 00066 */ 00067 void testGetVertexID() 00068 { 00069 WMarchingCubesAlgorithm mc; 00070 mc.m_nCellsX = 10; 00071 mc.m_nCellsY = 11; 00072 mc.m_nCellsZ = 12; 00073 00074 unsigned int x = 4; 00075 unsigned int y = 5; 00076 unsigned int z = 6; 00077 00078 unsigned int nbVertsInXDir = ( mc.m_nCellsX + 1 ); 00079 unsigned int nbVertsInSlice = nbVertsInXDir * ( mc.m_nCellsY + 1 ); 00080 unsigned int expected = z * nbVertsInSlice + y * nbVertsInXDir + x; 00081 00082 TS_ASSERT_EQUALS( expected, mc.getVertexID( x, y, z ) ); 00083 } 00084 00085 /** 00086 * Test computation of egeId 00087 */ 00088 void testGetEdgeID() 00089 { 00090 WMarchingCubesAlgorithm mc; 00091 mc.m_nCellsX = 10; 00092 mc.m_nCellsY = 11; 00093 mc.m_nCellsZ = 12; 00094 00095 unsigned int nbVertsInXDir = ( mc.m_nCellsX + 1 ); 00096 unsigned int nbVertsInSlice = nbVertsInXDir * ( mc.m_nCellsY + 1 ); 00097 00098 // test edge numbers for(0,0,0) case 00099 TS_ASSERT_EQUALS( 1 , mc.getEdgeID( 0, 0, 0, 0 ) ); 00100 TS_ASSERT_EQUALS( 3 * nbVertsInXDir , mc.getEdgeID( 0, 0, 0, 1 ) ); 00101 TS_ASSERT_EQUALS( 3 * 1 + 1 , mc.getEdgeID( 0, 0, 0, 2 ) ); 00102 TS_ASSERT_EQUALS( 0 , mc.getEdgeID( 0, 0, 0, 3 ) ); 00103 TS_ASSERT_EQUALS( 3 * nbVertsInSlice + 1 , mc.getEdgeID( 0, 0, 0, 4 ) ); 00104 TS_ASSERT_EQUALS( 3 * ( nbVertsInSlice + nbVertsInXDir ), mc.getEdgeID( 0, 0, 0, 5 ) ); 00105 TS_ASSERT_EQUALS( 3 * ( 1 + nbVertsInSlice ) + 1, mc.getEdgeID( 0, 0, 0, 6 ) ); 00106 TS_ASSERT_EQUALS( 3 * nbVertsInSlice, mc.getEdgeID( 0, 0, 0, 7 ) ); 00107 TS_ASSERT_EQUALS( 2 , mc.getEdgeID( 0, 0, 0, 8 ) ); 00108 TS_ASSERT_EQUALS( 3 * nbVertsInXDir + 2, mc.getEdgeID( 0, 0, 0, 9 ) ); 00109 TS_ASSERT_EQUALS( 3 * ( 1 + nbVertsInXDir ) + 2, mc.getEdgeID( 0, 0, 0, 10 ) ); 00110 TS_ASSERT_EQUALS( 3 * 1 + 2, mc.getEdgeID( 0, 0, 0, 11 ) ); 00111 00112 // wrong edge numbers should return -1 00113 TS_ASSERT_EQUALS( -1 , mc.getEdgeID( 0, 0, 0, -1 ) ); 00114 TS_ASSERT_EQUALS( -1 , mc.getEdgeID( 0, 0, 0, 12 ) ); 00115 TS_ASSERT_DIFFERS( -1 , mc.getEdgeID( 0, 0, 0, 1 ) ); 00116 } 00117 00118 /** 00119 * Test calculateIntersection with unsigned char 00120 */ 00121 void testCalculateIntersectionUnsignedChar() 00122 { 00123 WMarchingCubesAlgorithm mc; 00124 mc.m_tIsoLevel = 1.7; 00125 mc.m_nCellsX = 1; 00126 mc.m_nCellsY = 1; 00127 mc.m_nCellsZ = 1; 00128 00129 std::vector< unsigned char > data; 00130 data.push_back( 0 ); 00131 data.push_back( 1 ); 00132 data.push_back( 2 ); 00133 data.push_back( 3 ); 00134 data.push_back( 4 ); 00135 data.push_back( 5 ); 00136 data.push_back( 6 ); 00137 data.push_back( 7 ); 00138 00139 WPointXYZId expected; 00140 expected.newID = 0; 00141 expected.x = 1; 00142 expected.y = 0.35; 00143 expected.z = 0; 00144 00145 // This is the edge between grid pos 3 and 1 which are cell verts 2 and 3 00146 WPointXYZId result = mc.calculateIntersection( &data, 0, 0, 0, 2 ); 00147 00148 double delta = 1e-9; 00149 TS_ASSERT_DELTA( expected.x, result.x, delta ); 00150 TS_ASSERT_DELTA( expected.y, result.y, delta ); 00151 TS_ASSERT_DELTA( expected.z, result.z, delta ); 00152 TS_ASSERT_EQUALS( expected.newID, result.newID ); 00153 } 00154 00155 00156 /** 00157 * Test calculateIntersection with float 00158 */ 00159 void testCalculateIntersectionFloat() 00160 { 00161 WMarchingCubesAlgorithm mc; 00162 mc.m_tIsoLevel = 1.7; 00163 mc.m_nCellsX = 1; 00164 mc.m_nCellsY = 1; 00165 mc.m_nCellsZ = 1; 00166 00167 std::vector< float > data; 00168 data.push_back( 0 ); 00169 data.push_back( 1 ); 00170 data.push_back( 2 ); 00171 data.push_back( 3 ); 00172 data.push_back( 4 ); 00173 data.push_back( 5 ); 00174 data.push_back( 6 ); 00175 data.push_back( 7 ); 00176 00177 WPointXYZId expected; 00178 expected.newID = 0; 00179 expected.x = 1; 00180 expected.y = 0.35; 00181 expected.z = 0; 00182 00183 // This is the edge between grid pos 3 and 1 which are cell verts 2 and 3 00184 WPointXYZId result = mc.calculateIntersection( &data, 0, 0, 0, 2 ); 00185 00186 double delta = 1e-9; 00187 TS_ASSERT_DELTA( expected.x, result.x, delta ); 00188 TS_ASSERT_DELTA( expected.y, result.y, delta ); 00189 TS_ASSERT_DELTA( expected.z, result.z, delta ); 00190 TS_ASSERT_EQUALS( expected.newID, result.newID ); 00191 } 00192 }; 00193 00194 #endif // WMARCHINGCUBESALGORITHM_TEST_H