74 {
75 assert(values.
cols() == 1);
76 assert(points.
cols() == 3);
77
78 if(x_res <2 || y_res<2 ||z_res<2)
79 return;
81 int num_faces = 0;
82
84 int num_vertices = 0;
85
86
87 unsigned n_cubes = (x_res-1) * (y_res-1) * (z_res-1);
88 assert(
unsigned(points.
rows()) == x_res * y_res * z_res);
89
90 unsigned int offsets_[8];
91 offsets_[0] = 0;
92 offsets_[1] = 1;
93 offsets_[2] = 1 + x_res;
94 offsets_[3] = x_res;
95 offsets_[4] = x_res*y_res;
96 offsets_[5] = 1 + x_res*y_res;
97 offsets_[6] = 1 + x_res + x_res*y_res;
98 offsets_[7] = x_res + x_res*y_res;
99
100 for (unsigned cube_it =0 ; cube_it < n_cubes; ++cube_it)
101 {
102
103 unsigned corner[8];
104 typename DerivedF::Scalar samples[12];
105 unsigned char cubetype(0);
106 unsigned int i;
107
108
109
110 for (i=0; i<8; ++i)
111 {
112
113 unsigned int _idx = cube_it;
114 unsigned int X(x_res-1),
Y(y_res-1);
115 unsigned int x = _idx %
X; _idx /=
X;
116 unsigned int y = _idx %
Y; _idx /=
Y;
117 unsigned int z = _idx;
118
119
120 _idx =
x +
y*x_res + z*x_res*y_res;
121
122
123 corner[i] = _idx + offsets_[i];
124 }
125
126
127
128 for (i=0; i<8; ++i)
129 if (values(corner[i]) > 0.0)
130 cubetype |= (1<<i);
131
132
133
134 if (cubetype == 0 || cubetype == 255)
135 continue;
136
137
138
163
164
165
166
167 for (i=0;
triTable[cubetype][0][i] != -1; i+=3 )
168 {
169 num_faces++;
170 if (num_faces > faces.
rows())
172
173 faces.row(num_faces-1) <<
175 samples[
triTable[cubetype][0][i+1]],
176 samples[
triTable[cubetype][0][i+2]];
177
178 }
179
180 }
181
184
185 };
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
Definition PlainObjectBase.h:153
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void conservativeResize(Index rows, Index cols)
Definition PlainObjectBase.h:390
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition PlainObjectBase.h:279
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
Definition PlainObjectBase.h:151
static DerivedF::Scalar add_vertex(const Eigen::PlainObjectBase< Derivedvalues > &values, const Eigen::PlainObjectBase< Derivedpoints > &points, unsigned int i0, unsigned int i1, Eigen::PlainObjectBase< Derivedvertices > &vertices, int &num_vertices, MyMap &edge2vertex)
Definition marching_cubes.cpp:187
MyMap edge2vertex
Definition marching_cubes.cpp:223
const int edgeTable[256]
Definition marching_cubes_tables.h:36
const int triTable[256][2][17]
Definition marching_cubes_tables.h:76
const Scalar & y
Definition MathFunctions.h:552
@ NoChange
Definition Constants.h:350
@ Y
Definition libslic3r.h:99
@ X
Definition libslic3r.h:98
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297