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