OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WMarchingCubesAlgorithm_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 WMARCHINGCUBESALGORITHM_TEST_H
26 #define WMARCHINGCUBESALGORITHM_TEST_H
27 
28 #include <vector>
29 #include <cxxtest/TestSuite.h>
30 
31 #include "../WMarchingCubesAlgorithm.h"
32 
33 /**
34  * Tests for the class computing the actual marching cubes.
35  */
36 class WMarchingCubesAlgorithmTest : public CxxTest::TestSuite
37 {
38 public:
39 
40  /**
41  * Test interpolate on edge
42  */
44  {
46  mc.m_tIsoLevel = 1.7; // mu = 0.5454...
47 
48  WPointXYZId expected;
49  expected.newID = 0;
50  expected.x = 1.3545454545454545;
51  expected.y = 2.4545454545454545;
52  expected.z = 5.4090909090909091;
53 
54  WPointXYZId result = mc.interpolate( 1.3, 2.4, 3.5,
55  1.4, 2.5, 7.0,
56  1.1, 2.2 );
57 
58  double delta = 1e-9;
59  TS_ASSERT_DELTA( expected.x, result.x, delta );
60  TS_ASSERT_DELTA( expected.y, result.y, delta );
61  TS_ASSERT_DELTA( expected.z, result.z, delta );
62  TS_ASSERT_EQUALS( expected.newID, result.newID );
63  }
64 
65  /**
66  * Test computation of veretexID
67  */
69  {
71  mc.m_nCellsX = 10;
72  mc.m_nCellsY = 11;
73  mc.m_nCellsZ = 12;
74 
75  unsigned int x = 4;
76  unsigned int y = 5;
77  unsigned int z = 6;
78 
79  unsigned int nbVertsInXDir = ( mc.m_nCellsX + 1 );
80  unsigned int nbVertsInSlice = nbVertsInXDir * ( mc.m_nCellsY + 1 );
81  unsigned int expected = z * nbVertsInSlice + y * nbVertsInXDir + x;
82 
83  TS_ASSERT_EQUALS( expected, mc.getVertexID( x, y, z ) );
84  }
85 
86  /**
87  * Test computation of egeId
88  */
90  {
92  mc.m_nCellsX = 10;
93  mc.m_nCellsY = 11;
94  mc.m_nCellsZ = 12;
95 
96  unsigned int nbVertsInXDir = ( mc.m_nCellsX + 1 );
97  unsigned int nbVertsInSlice = nbVertsInXDir * ( mc.m_nCellsY + 1 );
98 
99  // test edge numbers for(0,0,0) case
100  TS_ASSERT_EQUALS( 1 , mc.getEdgeID( 0, 0, 0, 0 ) );
101  TS_ASSERT_EQUALS( 3 * nbVertsInXDir , mc.getEdgeID( 0, 0, 0, 1 ) );
102  TS_ASSERT_EQUALS( 3 * 1 + 1 , mc.getEdgeID( 0, 0, 0, 2 ) );
103  TS_ASSERT_EQUALS( 0 , mc.getEdgeID( 0, 0, 0, 3 ) );
104  TS_ASSERT_EQUALS( 3 * nbVertsInSlice + 1 , mc.getEdgeID( 0, 0, 0, 4 ) );
105  TS_ASSERT_EQUALS( 3 * ( nbVertsInSlice + nbVertsInXDir ), mc.getEdgeID( 0, 0, 0, 5 ) );
106  TS_ASSERT_EQUALS( 3 * ( 1 + nbVertsInSlice ) + 1, mc.getEdgeID( 0, 0, 0, 6 ) );
107  TS_ASSERT_EQUALS( 3 * nbVertsInSlice, mc.getEdgeID( 0, 0, 0, 7 ) );
108  TS_ASSERT_EQUALS( 2 , mc.getEdgeID( 0, 0, 0, 8 ) );
109  TS_ASSERT_EQUALS( 3 * nbVertsInXDir + 2, mc.getEdgeID( 0, 0, 0, 9 ) );
110  TS_ASSERT_EQUALS( 3 * ( 1 + nbVertsInXDir ) + 2, mc.getEdgeID( 0, 0, 0, 10 ) );
111  TS_ASSERT_EQUALS( 3 * 1 + 2, mc.getEdgeID( 0, 0, 0, 11 ) );
112 
113  // wrong edge numbers should return -1
114  TS_ASSERT_EQUALS( -1 , mc.getEdgeID( 0, 0, 0, -1 ) );
115  TS_ASSERT_EQUALS( -1 , mc.getEdgeID( 0, 0, 0, 12 ) );
116  TS_ASSERT_DIFFERS( -1 , mc.getEdgeID( 0, 0, 0, 1 ) );
117  }
118 
119  /**
120  * Test calculateIntersection with unsigned char
121  */
123  {
125  mc.m_tIsoLevel = 1.7;
126  mc.m_nCellsX = 1;
127  mc.m_nCellsY = 1;
128  mc.m_nCellsZ = 1;
129 
130  std::vector< unsigned char > data;
131  data.push_back( 0 );
132  data.push_back( 1 );
133  data.push_back( 2 );
134  data.push_back( 3 );
135  data.push_back( 4 );
136  data.push_back( 5 );
137  data.push_back( 6 );
138  data.push_back( 7 );
139 
140  WPointXYZId expected;
141  expected.newID = 0;
142  expected.x = 1;
143  expected.y = 0.35;
144  expected.z = 0;
145 
146  // This is the edge between grid pos 3 and 1 which are cell verts 2 and 3
147  WPointXYZId result = mc.calculateIntersection( &data, 0, 0, 0, 2 );
148 
149  double delta = 1e-9;
150  TS_ASSERT_DELTA( expected.x, result.x, delta );
151  TS_ASSERT_DELTA( expected.y, result.y, delta );
152  TS_ASSERT_DELTA( expected.z, result.z, delta );
153  TS_ASSERT_EQUALS( expected.newID, result.newID );
154  }
155 
156 
157  /**
158  * Test calculateIntersection with float
159  */
161  {
163  mc.m_tIsoLevel = 1.7;
164  mc.m_nCellsX = 1;
165  mc.m_nCellsY = 1;
166  mc.m_nCellsZ = 1;
167 
168  std::vector< float > data;
169  data.push_back( 0 );
170  data.push_back( 1 );
171  data.push_back( 2 );
172  data.push_back( 3 );
173  data.push_back( 4 );
174  data.push_back( 5 );
175  data.push_back( 6 );
176  data.push_back( 7 );
177 
178  WPointXYZId expected;
179  expected.newID = 0;
180  expected.x = 1;
181  expected.y = 0.35;
182  expected.z = 0;
183 
184  // This is the edge between grid pos 3 and 1 which are cell verts 2 and 3
185  WPointXYZId result = mc.calculateIntersection( &data, 0, 0, 0, 2 );
186 
187  double delta = 1e-9;
188  TS_ASSERT_DELTA( expected.x, result.x, delta );
189  TS_ASSERT_DELTA( expected.y, result.y, delta );
190  TS_ASSERT_DELTA( expected.z, result.z, delta );
191  TS_ASSERT_EQUALS( expected.newID, result.newID );
192  }
193 };
194 
195 #endif // WMARCHINGCUBESALGORITHM_TEST_H