OpenWalnut  1.5.0dev
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  * Test interpolate on edge
41  */
43  {
45  mc.m_tIsoLevel = 1.7; // mu = 0.5454...
46 
47  WPointXYZId expected;
48  expected.newID = 0;
49  expected.x = 1.3545454545454545;
50  expected.y = 2.4545454545454545;
51  expected.z = 5.4090909090909091;
52 
53  WPointXYZId result = mc.interpolate( 1.3, 2.4, 3.5,
54  1.4, 2.5, 7.0,
55  1.1, 2.2 );
56 
57  double delta = 1e-9;
58  TS_ASSERT_DELTA( expected.x, result.x, delta );
59  TS_ASSERT_DELTA( expected.y, result.y, delta );
60  TS_ASSERT_DELTA( expected.z, result.z, delta );
61  TS_ASSERT_EQUALS( expected.newID, result.newID );
62  }
63 
64  /**
65  * Test computation of veretexID
66  */
68  {
70  mc.m_nCellsX = 10;
71  mc.m_nCellsY = 11;
72  mc.m_nCellsZ = 12;
73 
74  unsigned int x = 4;
75  unsigned int y = 5;
76  unsigned int z = 6;
77 
78  unsigned int nbVertsInXDir = ( mc.m_nCellsX + 1 );
79  unsigned int nbVertsInSlice = nbVertsInXDir * ( mc.m_nCellsY + 1 );
80  unsigned int expected = z * nbVertsInSlice + y * nbVertsInXDir + x;
81 
82  TS_ASSERT_EQUALS( expected, mc.getVertexID( x, y, z ) );
83  }
84 
85  /**
86  * Test computation of egeId
87  */
89  {
91  mc.m_nCellsX = 10;
92  mc.m_nCellsY = 11;
93  mc.m_nCellsZ = 12;
94 
95  unsigned int nbVertsInXDir = ( mc.m_nCellsX + 1 );
96  unsigned int nbVertsInSlice = nbVertsInXDir * ( mc.m_nCellsY + 1 );
97 
98  // test edge numbers for(0,0,0) case
99  TS_ASSERT_EQUALS( 1 , mc.getEdgeID( 0, 0, 0, 0 ) );
100  TS_ASSERT_EQUALS( 3 * nbVertsInXDir , mc.getEdgeID( 0, 0, 0, 1 ) );
101  TS_ASSERT_EQUALS( 3 * 1 + 1 , mc.getEdgeID( 0, 0, 0, 2 ) );
102  TS_ASSERT_EQUALS( 0 , mc.getEdgeID( 0, 0, 0, 3 ) );
103  TS_ASSERT_EQUALS( 3 * nbVertsInSlice + 1 , mc.getEdgeID( 0, 0, 0, 4 ) );
104  TS_ASSERT_EQUALS( 3 * ( nbVertsInSlice + nbVertsInXDir ), mc.getEdgeID( 0, 0, 0, 5 ) );
105  TS_ASSERT_EQUALS( 3 * ( 1 + nbVertsInSlice ) + 1, mc.getEdgeID( 0, 0, 0, 6 ) );
106  TS_ASSERT_EQUALS( 3 * nbVertsInSlice, mc.getEdgeID( 0, 0, 0, 7 ) );
107  TS_ASSERT_EQUALS( 2 , mc.getEdgeID( 0, 0, 0, 8 ) );
108  TS_ASSERT_EQUALS( 3 * nbVertsInXDir + 2, mc.getEdgeID( 0, 0, 0, 9 ) );
109  TS_ASSERT_EQUALS( 3 * ( 1 + nbVertsInXDir ) + 2, mc.getEdgeID( 0, 0, 0, 10 ) );
110  TS_ASSERT_EQUALS( 3 * 1 + 2, mc.getEdgeID( 0, 0, 0, 11 ) );
111 
112  // wrong edge numbers should return -1
113  TS_ASSERT_EQUALS( -1 , mc.getEdgeID( 0, 0, 0, -1 ) );
114  TS_ASSERT_EQUALS( -1 , mc.getEdgeID( 0, 0, 0, 12 ) );
115  TS_ASSERT_DIFFERS( -1 , mc.getEdgeID( 0, 0, 0, 1 ) );
116  }
117 
118  /**
119  * Test calculateIntersection with unsigned char
120  */
122  {
124  mc.m_tIsoLevel = 1.7;
125  mc.m_nCellsX = 1;
126  mc.m_nCellsY = 1;
127  mc.m_nCellsZ = 1;
128 
129  std::vector< unsigned char > data;
130  data.push_back( 0 );
131  data.push_back( 1 );
132  data.push_back( 2 );
133  data.push_back( 3 );
134  data.push_back( 4 );
135  data.push_back( 5 );
136  data.push_back( 6 );
137  data.push_back( 7 );
138 
139  WPointXYZId expected;
140  expected.newID = 0;
141  expected.x = 1;
142  expected.y = 0.35;
143  expected.z = 0;
144 
145  // This is the edge between grid pos 3 and 1 which are cell verts 2 and 3
146  WPointXYZId result = mc.calculateIntersection( &data, 0, 0, 0, 2 );
147 
148  double delta = 1e-9;
149  TS_ASSERT_DELTA( expected.x, result.x, delta );
150  TS_ASSERT_DELTA( expected.y, result.y, delta );
151  TS_ASSERT_DELTA( expected.z, result.z, delta );
152  TS_ASSERT_EQUALS( expected.newID, result.newID );
153  }
154 
155 
156  /**
157  * Test calculateIntersection with float
158  */
160  {
162  mc.m_tIsoLevel = 1.7;
163  mc.m_nCellsX = 1;
164  mc.m_nCellsY = 1;
165  mc.m_nCellsZ = 1;
166 
167  std::vector< float > data;
168  data.push_back( 0 );
169  data.push_back( 1 );
170  data.push_back( 2 );
171  data.push_back( 3 );
172  data.push_back( 4 );
173  data.push_back( 5 );
174  data.push_back( 6 );
175  data.push_back( 7 );
176 
177  WPointXYZId expected;
178  expected.newID = 0;
179  expected.x = 1;
180  expected.y = 0.35;
181  expected.z = 0;
182 
183  // This is the edge between grid pos 3 and 1 which are cell verts 2 and 3
184  WPointXYZId result = mc.calculateIntersection( &data, 0, 0, 0, 2 );
185 
186  double delta = 1e-9;
187  TS_ASSERT_DELTA( expected.x, result.x, delta );
188  TS_ASSERT_DELTA( expected.y, result.y, delta );
189  TS_ASSERT_DELTA( expected.z, result.z, delta );
190  TS_ASSERT_EQUALS( expected.newID, result.newID );
191  }
192 };
193 
194 #endif // WMARCHINGCUBESALGORITHM_TEST_H
Tests for the class computing the actual marching cubes.
void testCalculateIntersectionFloat()
Test calculateIntersection with float.
void testInterpolate()
Test interpolate on edge.
void testGetEdgeID()
Test computation of egeId.
void testGetVertexID()
Test computation of veretexID.
void testCalculateIntersectionUnsignedChar()
Test calculateIntersection with unsigned char.
This class does the actual computation of marching cubes.
unsigned int m_nCellsZ
No. of cells in z direction.
WPointXYZId interpolate(double fX1, double fY1, double fZ1, double fX2, double fY2, double fZ2, double tVal1, double tVal2)
Interpolates between two grid points to produce the point at which the isosurface intersects an edge.
unsigned int getVertexID(unsigned int nX, unsigned int nY, unsigned int nZ)
Returns the ID of the vertex given by by the IDs along the axis.
int getEdgeID(unsigned int nX, unsigned int nY, unsigned int nZ, unsigned int nEdgeNo)
Returns the edge ID.
unsigned int m_nCellsY
No. of cells in y direction.
WPointXYZId calculateIntersection(const std::vector< T > *vals, unsigned int nX, unsigned int nY, unsigned int nZ, unsigned int nEdgeNo)
Calculates the intersection point id of the isosurface with an edge.
unsigned int m_nCellsX
No. of cells in x direction.
A point consisting of its coordinates and ID.
double z
z coordinates of the point.
double x
x coordinates of the point.
double y
y coordinates of the point.
unsigned int newID
ID of the point.