18 template <
typename Real>
50 bool Extract(std::array<Real, 8>
const& F,
Mesh& mesh)
const;
87 template <
typename Real>
92 template <
typename Real>
99 template <
typename Real>
102 std::array<Real, 3> zero = { (Real)0, (Real)0, (Real)0 };
103 std::fill(vertices.begin(), vertices.end(), zero);
106 template <
typename Real>
110 for (
int i = 0,
mask = 1; i < 8; ++i,
mask <<= 1)
116 else if (F[i] == (Real)0)
124 for (
int i = 0; i < mesh.
topology.numVertices; ++i)
130 corner0[0] =
static_cast<Real
>(j0 & 1);
131 corner0[1] =
static_cast<Real
>((j0 & 2) >> 1);
132 corner0[2] =
static_cast<Real
>((j0 & 4) >> 2);
135 corner1[0] =
static_cast<Real
>(j1 & 1);
136 corner1[1] =
static_cast<Real
>((j1 & 2) >> 1);
137 corner1[2] =
static_cast<Real
>((j1 & 4) >> 2);
139 Real invDenom = ((Real)1) / (F[j0] - F[j1]);
140 for (
int k = 0; k < 3; ++k)
142 Real numer = F[j0] * corner1[k] - F[j1] * corner0[k];
143 mesh.
vertices[i][k] = numer*invDenom;
149 template <
typename Real>
161 std::array<size_t, 8> corners;
164 std::array<Real, 8> F;
165 for (
int k = 0; k < 8; ++k)
174 int vbase =
static_cast<int>(vertices.size());
175 for (
int i = 0; i < mesh.
topology.numVertices; ++i)
178 position[0] +=
static_cast<Real
>(
x);
179 position[1] +=
static_cast<Real
>(
y);
180 position[2] +=
static_cast<Real
>(
z);
181 vertices.push_back(position);
184 for (
int i = 0; i < mesh.
topology.numTriangles; ++i)
186 for (
int j = 0; j < 3; ++j)
188 indices.push_back(vbase + mesh.
topology.itriple[i][j]);
205 template <
typename Real>
208 std::vector<Vector3<Real>> outVertices;
209 std::vector<int> outIndices;
211 vertices = std::move(outVertices);
212 indices = std::move(outIndices);
215 template <
typename Real>
219 int const numTriangles =
static_cast<int>(indices.size() / 3);
220 int* triangle = indices.data();
221 for (
int t = 0;
t < numTriangles; ++
t, triangle += 3)
239 Vector3<Real> gradientAvr = (gradient0 + gradient1 + gradient2) / (Real)3;
242 Real dot =
Dot(gradientAvr, normal);
250 std::swap(triangle[1], triangle[2]);
258 std::swap(triangle[1], triangle[2]);
264 template <
typename Real>
269 int const numVertices =
static_cast<int>(vertices.size());
270 normals.resize(numVertices);
272 std::fill(normals.begin(), normals.end(), zero);
274 int const numTriangles =
static_cast<int>(indices.size() / 3);
275 int const* current = indices.data();
276 for (
int i = 0; i < numTriangles; ++i)
291 normals[i0] += normal;
292 normals[i1] += normal;
293 normals[i2] += normal;
298 for (
auto& normal : normals)
304 template <
typename Real>
307 int x =
static_cast<int>(floor(position[0]));
313 int y =
static_cast<int>(floor(position[1]));
319 int z =
static_cast<int>(floor(position[2]));
325 position[0] -=
static_cast<Real
>(
x);
326 position[1] -=
static_cast<Real
>(
y);
327 position[2] -=
static_cast<Real
>(
z);
328 Real oneMX = (Real)1 - position[0];
329 Real oneMY = (Real)1 - position[1];
330 Real oneMZ = (Real)1 - position[2];
333 std::array<size_t, 8> corners;
335 Real f000 =
mImage[corners[0]];
336 Real f100 =
mImage[corners[1]];
337 Real f010 =
mImage[corners[2]];
338 Real f110 =
mImage[corners[3]];
339 Real f001 =
mImage[corners[4]];
340 Real f101 =
mImage[corners[5]];
341 Real f011 =
mImage[corners[6]];
342 Real f111 =
mImage[corners[7]];
346 Real tmp0 = oneMY * (f100 - f000) + position[1] * (f110 - f010);
347 Real tmp1 = oneMY * (f101 - f001) + position[1] * (f111 - f011);
348 gradient[0] = oneMZ * tmp0 + position[2] * tmp1;
350 tmp0 = oneMX * (f010 - f000) + position[0] * (f110 - f100);
351 tmp1 = oneMX * (f011 - f001) + position[0] * (f111 - f101);
352 gradient[1] = oneMZ * tmp0 + position[2] * tmp1;
354 tmp0 = oneMX * (f001 - f000) + position[0] * (f101 - f100);
355 tmp1 = oneMX * (f011 - f010) + position[0] * (f111 - f110);
356 gradient[2] = oneMY * tmp0 + position[1] * tmp1;
int const * GetTable() const
int GetDimension(int d) const
GLenum GLenum GLsizei void * image
void GetCorners(std::array< int, 8 > &nbr) const
GLsizei GLenum const void * indices
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Real Normalize(GVector< Real > &v, bool robust=false)
DualQuaternion< Real > Cross(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLdouble GLdouble GLdouble z
GLfloat GLfloat GLfloat v2