OpenWalnut  1.4.0
WMarchingCubesAlgorithm.cpp
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 #include <vector>
26 
27 #include "WMarchingCubesAlgorithm.h"
28 
30  : m_matrix( 4, 4 )
31 {
32 }
33 
34 WPointXYZId WMarchingCubesAlgorithm::interpolate( double fX1, double fY1, double fZ1, double fX2, double fY2, double fZ2,
35  double tVal1, double tVal2 )
36 {
37  WPointXYZId interpolation;
38  double mu;
39 
40  mu = static_cast<double>( ( m_tIsoLevel - tVal1 ) ) / ( tVal2 - tVal1 );
41  interpolation.x = fX1 + mu * ( fX2 - fX1 );
42  interpolation.y = fY1 + mu * ( fY2 - fY1 );
43  interpolation.z = fZ1 + mu * ( fZ2 - fZ1 );
44  interpolation.newID = 0;
45 
46  return interpolation;
47 }
48 
49 int WMarchingCubesAlgorithm::getEdgeID( unsigned int nX, unsigned int nY, unsigned int nZ, unsigned int nEdgeNo )
50 {
51  switch( nEdgeNo )
52  {
53  case 0:
54  return 3 * getVertexID( nX, nY, nZ ) + 1;
55  case 1:
56  return 3 * getVertexID( nX, nY + 1, nZ );
57  case 2:
58  return 3 * getVertexID( nX + 1, nY, nZ ) + 1;
59  case 3:
60  return 3 * getVertexID( nX, nY, nZ );
61  case 4:
62  return 3 * getVertexID( nX, nY, nZ + 1 ) + 1;
63  case 5:
64  return 3 * getVertexID( nX, nY + 1, nZ + 1 );
65  case 6:
66  return 3 * getVertexID( nX + 1, nY, nZ + 1 ) + 1;
67  case 7:
68  return 3 * getVertexID( nX, nY, nZ + 1 );
69  case 8:
70  return 3 * getVertexID( nX, nY, nZ ) + 2;
71  case 9:
72  return 3 * getVertexID( nX, nY + 1, nZ ) + 2;
73  case 10:
74  return 3 * getVertexID( nX + 1, nY + 1, nZ ) + 2;
75  case 11:
76  return 3 * getVertexID( nX + 1, nY, nZ ) + 2;
77  default:
78  // Invalid edge no.
79  return -1;
80  }
81 }
82 
83 unsigned int WMarchingCubesAlgorithm::getVertexID( unsigned int nX, unsigned int nY, unsigned int nZ )
84 {
85  return nZ * ( m_nCellsY + 1 ) * ( m_nCellsX + 1) + nY * ( m_nCellsX + 1 ) + nX;
86 }
87 
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 m_nCellsY
No. of cells in y direction.
WMarchingCubesAlgorithm()
Constructor needed for matrix initalization.
double m_tIsoLevel
The isovalue.
int getEdgeID(unsigned int nX, unsigned int nY, unsigned int nZ, unsigned int nEdgeNo)
Returns the edge ID.
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.
unsigned int m_nCellsX
No. of cells in x direction.
double z
z coordinates of the point.
double y
y coordinates of the point.
A point consisting of its coordinates and ID.
unsigned int newID
ID of the point.
double x
x coordinates of the point.