GteMarchingCubes.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <GTEngineDEF.h>
11 #include <array>
12 #include <string>
13 
14 namespace gte
15 {
16 
17 // Create the lookup table for the Marching Cubes algorithm that is used to
18 // extract a triangular mesh that represents a level surface of a 3D image
19 // sampled on a regular lattice. The assumption is that no data sample is
20 // zero, which allows us to have a table with 256 entries: 2 signs per
21 // sample, 8 samples per volume element (voxel). Each entry corresponds to
22 // the pattern of 8 signs at the corners of a voxel. The signs are stored as
23 // bits (b7,b6,b5,b4,b3,b2,b1,b0). The bit assignments to voxel corners is
24 // b0 = (x,y,z), b1 = (x+1,y,z), b2 = (x,y+1,z), b3 = (x+1,y+1,z)
25 // b4 = (x,y,z+1), b5 = (x+1,y,z+1), b6 = (x,y+1,z+1), b7 = (x+1,y+1,z+1)
26 // If a bit is zero, then the voxel value at the corresponding corner is
27 // positive; otherwise, the bit is one and the value is negative. The
28 // triangles are counterclockwise ordered according to an observer viewing
29 // the triangle from the negative side of the level surface.
30 
32 {
33 public:
34  // Construction and destruction.
35  virtual ~MarchingCubes();
36  MarchingCubes();
37 
39  {
40  MAX_VERTICES = 12,
41  MAX_TRIANGLES = 5,
42  };
43 
45  {
46  // All members are set to zeros.
47  Topology();
48 
51  std::array<std::array<int, 2>, MAX_VERTICES> vpair;
52  std::array<std::array<int, 3>, MAX_TRIANGLES> itriple;
53  };
54 
55  // The entry must be in {0..255}.
56  inline Topology const& GetTable(int entry) const;
57 
58  // The table has 256 entries, each 41 integers, stored as table[256][41].
59  // The return value is a pointer to the table via &table[0][0].
60  inline int const* GetTable() const;
61 
62  // Get the configuration type for the voxel, which is one of the string
63  // names of the 'void Bits* (int[8])' functions.
64  static std::string GetConfigurationType(int entry);
65 
66 protected:
67  // Support for lookup construction and access.
68  // mTable[i][0] = numVertices
69  // mTable[i][1] = numTriangles
70  // mTable[i][2..25] = pairs of corner indices (maximum of 12 pairs)
71  // mTable[i][26..40] = triples of indices (maximum of 5 triples)
72  Topology mTable[256];
73 
74  // The constructor iterates mEntry from 0 to 255 and calls configuration
75  // functions, each calling SetTable(...). The mEntry value is the table
76  // index to be used.
77  int mEntry;
78 
79  void SetTable(int numV, int const* vpair, int numT, int const* itriple);
80 
81  // The precomputed information about the 256 configurations for voxels.
82  void Bits0(int index[8]);
83  void Bits1(int index[8]);
84  void Bits7(int index[8]);
85  void Bits2Edge(int index[8]);
86  void Bits6Edge(int index[8]);
87  void Bits2FaceDiag(int index[8]);
88  void Bits6FaceDiag(int index[8]);
89  void Bits2BoxDiag(int index[8]);
90  void Bits6BoxDiag(int index[8]);
91  void Bits3SameFace(int index[8]);
92  void Bits5SameFace(int index[8]);
93  void Bits3EdgeFaceDiag(int index[8]);
94  void Bits5EdgeFaceDiag(int index[8]);
95  void Bits3FaceDiagFaceDiag(int index[8]);
96  void Bits5FaceDiagFaceDiag(int index[8]);
97  void Bits4SameFace(int index[8]);
98  void Bits4FaceEdge(int index[8]);
99  void Bits4FaceFaceDiagL(int index[8]);
100  void Bits4FaceFaceDiagR(int index[8]);
101  void Bits4FaceBoxDiag(int index[8]);
102  void Bits4EdgeEdgePara(int index[8]);
103  void Bits4EdgeEdgePerp(int index[8]);
104 
105  enum GTE_IMPEXP ConfigurationType
106  {
108  CT_Bits1,
109  CT_Bits7,
110  CT_Bits2Edge,
111  CT_Bits6Edge,
129  CT_NUM_TYPES
130  };
131 
132  typedef void (MarchingCubes::*Function)(int[8]);
133 
135  {
136  ConfigurationType type;
138  int index[8];
139  };
140 
141  static Configuration msConfiguration[256];
142  static std::string msConfigurationString[CT_NUM_TYPES];
143 };
144 
145 inline MarchingCubes::Topology const& MarchingCubes::GetTable(int entry) const
146 {
147  return mTable[entry];
148 }
149 
150 int const* MarchingCubes::GetTable() const
151 {
152  return reinterpret_cast<int const*>(mTable);
153 }
154 
155 }
CT_Bits4FaceBoxDiag
CT_Bits2FaceDiag
CT_Bits3FaceDiagFaceDiag
CT_Bits5EdgeFaceDiag
CT_Bits3EdgeFaceDiag
int const * GetTable() const
CT_Bits4EdgeEdgePara
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
CT_Bits2Edge
CT_Bits1
CT_Bits6FaceDiag
CT_Bits5FaceDiagFaceDiag
CT_Bits4EdgeEdgePerp
CT_Bits6Edge
CT_Bits4FaceEdge
CT_Bits4FaceFaceDiagR
CT_Bits2BoxDiag
CT_Bits4FaceFaceDiagL
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
CT_Bits4SameFace
CT_Bits0
CT_Bits5SameFace
CT_Bits7
std::array< std::array< int, 3 >, MAX_TRIANGLES > itriple
GLuint index
Definition: glcorearb.h:781
CT_Bits3SameFace
std::array< std::array< int, 2 >, MAX_VERTICES > vpair
CT_Bits6BoxDiag


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01