-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarchingCubes.h
139 lines (128 loc) · 6.33 KB
/
MarchingCubes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef MARCHINGCUBES_H
#define MARCHINGCUBES_H
//-----------------------------------------------------------------------------
/// @file GLData.h
/// @author Milto Miltiadou
/// @version 1.0
/// @date 04/05/15
/// @class MarchingCubes
/// @brief an implementation of the marching cubes algorithm which reconstructs
/// the surface of an implicit object
//-----------------------------------------------------------------------------
#include "Object.h"
#include "GLData.h"
#include "HashTable.h"
class MarchingCubes
{
public:
//--------------------------------------------------------------------------
/// @brief default constructor
/// @param[in] i_obj object to be polygonised
/// @param[in] i_x the number of cubes in the x-axis
//--------------------------------------------------------------------------
MarchingCubes(Object *i_obj, unsigned int i_x);
//--------------------------------------------------------------------------
/// @brief method that polygonises the object and returns its vertices,
/// indices, normals etc
/// @note memory is dynamic allocated and by calling the function you are
/// responsible for freeing the memory afterwards
//--------------------------------------------------------------------------
GLData *createPolygonisedObject();
//--------------------------------------------------------------------------
/// @param[in] default destructor
//--------------------------------------------------------------------------
~MarchingCubes();
protected:
//--------------------------------------------------------------------------
/// @brief method that polygonises the cube with min coordinates x,y,z
/// @param[in] i_x the min x coordinate of the cube to be polygonised
/// @param[in] i_y the min y coordinate of the cube to be polygonised
/// @param[in] i_z the min z coordinate of the cube to be polygonised
/// @param[in] i_isolevel the boundary of the object
//--------------------------------------------------------------------------
void polygoniseXYZ(
const unsigned int i_x,
const unsigned int i_y,
const unsigned int i_z,
const double i_isolevel,
GLData *i_glData
);
//--------------------------------------------------------------------------
/// @brief method that calculates the position where a surfaces cuts an edge
/// between two vertices using linear interpolation
/// @param[in] isolevel
/// @param[in] p1 the first point
/// @param[in] p2 the seconde point
/// @param[in] valp1 the value returned for point 1
/// @param[in] valp2 the value returned for point 2
//--------------------------------------------------------------------------
gmtl::Vec3f VertexInterp(
double isolevel,
const gmtl::Vec3f &p1,
const gmtl::Vec3f &p2,
const double valp1,
const double valp2
);
//--------------------------------------------------------------------------
/// @brief
//--------------------------------------------------------------------------
void Polygonise(
const std::vector<gmtl::Vec3f> &points,
double isolevel,
GLData *i_glData
);
//--------------------------------------------------------------------------
/// @brief method that returns the arithmetic position of a voxel in the
/// space given its indices
//--------------------------------------------------------------------------
gmtl::Vec3f getXYZ(unsigned int i_x, unsigned int i_y, unsigned int i_z);
//--------------------------------------------------------------------------
/// @brief method that polygonises the object and save its vertices into the
/// gl data
/// @param[in&out] i_glData the normals, vertices, indices,uvs of the object
//--------------------------------------------------------------------------
virtual void computeVertices(GLData *glData);
//--------------------------------------------------------------------------
/// @brief
//--------------------------------------------------------------------------
void computeNormals(GLData *i_glData);
//--------------------------------------------------------------------------
/// @brief
//--------------------------------------------------------------------------
void computeNormalsUsingGradientDecent(GLData *i_glData);
//--------------------------------------------------------------------------
/// @brief method that returns the index of a given vertex. If the index
/// does not exist in glData then it is first added and then the index is
/// returned.
/// @param[in] i_glData where vertices and indices are saved
/// @param[in] i_vertex the vertex of our interest
//--------------------------------------------------------------------------
unsigned int getIndex(GLData *i_glData, const gmtl::Vec3f &i_vertex);
//--------------------------------------------------------------------------
/// @brief object to be polygonised
//--------------------------------------------------------------------------
Object *m_obj;
//--------------------------------------------------------------------------
/// @brief number of cubes in x-axis
//--------------------------------------------------------------------------
unsigned int m_numOfCubsX;
//--------------------------------------------------------------------------
/// @brief number of cubes in y-axis
//--------------------------------------------------------------------------
unsigned int m_numOfCubsY;
//--------------------------------------------------------------------------
/// @brief number of cubes in z-axis
//--------------------------------------------------------------------------
unsigned int m_numOfCubsZ;
//--------------------------------------------------------------------------
/// @brief the min and max values define the bounding box of the object
/// @brief the max values of the object
//--------------------------------------------------------------------------
gmtl::Vec3f m_maxLimits;
//--------------------------------------------------------------------------
/// @brief the min values of the object
//--------------------------------------------------------------------------
gmtl::Vec3f m_minLimits;
HashTable m_hashTable;
};
#endif // MARCHINGCUBES_H