30 template<
class T>
bool read(T& val)
32 int bytes =
sizeof(T);
33 if (m_currentOffset+bytes<=m_size)
35 char* dest = (
char*)&val;
36 memcpy(dest,&m_data[m_currentOffset],bytes);
37 m_currentOffset+=bytes;
54 m_domain.m_min[0] = buf[0];
55 m_domain.m_min[1] = buf[1];
56 m_domain.m_min[2] = buf[2];
57 m_domain.m_min[3] = 0;
58 m_domain.m_max[0] = buf[3];
59 m_domain.m_max[1] = buf[4];
60 m_domain.m_max[2] = buf[5];
61 m_domain.m_max[3] = 0;
66 m_resolution[0] = buf2[0];
67 m_resolution[1] = buf2[1];
68 m_resolution[2] = buf2[2];
73 m_cell_size[0] = buf[0];
74 m_cell_size[1] = buf[1];
75 m_cell_size[2] = buf[2];
80 m_inv_cell_size[0] = buf[0];
81 m_inv_cell_size[1] = buf[1];
82 m_inv_cell_size[2] = buf[2];
85 unsigned long long int cells;
90 unsigned long long int fields;
96 unsigned long long int nodes0;
100 if (n_nodes0 > 1024 * 1024 * 1024)
104 m_nodes.resize(n_nodes0);
105 for (
unsigned int i=0;i<n_nodes0;i++)
107 unsigned long long int n_nodes1;
111 for (
int j=0;j<nodes.
size();j++)
113 double& node = nodes[j];
118 unsigned long long int n_cells0;
120 m_cells.resize(n_cells0);
121 for (
int i=0;i<n_cells0;i++)
123 unsigned long long int n_cells1;
127 for (
int j=0;j<n_cells1;j++)
135 unsigned long long int n_cell_maps0;
136 ds.
read(n_cell_maps0);
138 m_cell_map.resize(n_cell_maps0);
139 for (
int i=0;i<n_cell_maps0;i++)
141 unsigned long long int n_cell_maps1;
143 ds.
read(n_cell_maps1);
144 cell_maps.
resize(n_cell_maps1);
145 for (
int j=0;j<n_cell_maps1;j++)
147 unsigned int& cell_map = cell_maps[j];
160 return m_resolution[1] * m_resolution[0] * ijk.
ijk[2] + m_resolution[0] * ijk.
ijk[1] + ijk.
ijk[0];
168 tmp.
m_floats[0] = m_cell_size[0]*(double)ijk.
ijk[0];
169 tmp.
m_floats[1] = m_cell_size[1]*(
double)ijk.
ijk[1];
170 tmp.
m_floats[2] = m_cell_size[2]*(double)ijk.
ijk[2];
183 unsigned int n01 = m_resolution[0] * m_resolution[1];
184 unsigned int k = l / n01;
185 unsigned int temp = l % n01;
186 unsigned int j = temp / m_resolution[0];
187 unsigned int i = temp % m_resolution[0];
199 return subdomain(singleToMultiIndex(l));
254 btScalar fac = 1.0 / 64.0 * (9.0 * (x2 + y2 + z2) - 19.0);
255 res[0] = fac * _1mxt1my * _1mz;
256 res[1] = fac * _1pxt1my * _1mz;
257 res[2] = fac * _1mxt1py * _1mz;
258 res[3] = fac * _1pxt1py * _1mz;
259 res[4] = fac * _1mxt1my * _1pz;
260 res[5] = fac * _1pxt1my * _1pz;
261 res[6] = fac * _1mxt1py * _1pz;
262 res[7] = fac * _1pxt1py * _1pz;
266 fac = 9.0 / 64.0 * _1mx2;
269 res[ 8] = fact1m3x * _1myt1mz;
270 res[ 9] = fact1p3x * _1myt1mz;
271 res[10] = fact1m3x * _1myt1pz;
272 res[11] = fact1p3x * _1myt1pz;
273 res[12] = fact1m3x * _1pyt1mz;
274 res[13] = fact1p3x * _1pyt1mz;
275 res[14] = fact1m3x * _1pyt1pz;
276 res[15] = fact1p3x * _1pyt1pz;
278 fac = 9.0 / 64.0 * _1my2;
281 res[16] = fact1m3y * _1mxt1mz;
282 res[17] = fact1p3y * _1mxt1mz;
283 res[18] = fact1m3y * _1pxt1mz;
284 res[19] = fact1p3y * _1pxt1mz;
285 res[20] = fact1m3y * _1mxt1pz;
286 res[21] = fact1p3y * _1mxt1pz;
287 res[22] = fact1m3y * _1pxt1pz;
288 res[23] = fact1p3y * _1pxt1pz;
290 fac = 9.0 / 64.0 * _1mz2;
293 res[24] = fact1m3z * _1mxt1my;
294 res[25] = fact1p3z * _1mxt1my;
295 res[26] = fact1m3z * _1mxt1py;
296 res[27] = fact1p3z * _1mxt1py;
297 res[28] = fact1m3z * _1pxt1my;
298 res[29] = fact1p3z * _1pxt1my;
299 res[30] = fact1m3z * _1pxt1py;
300 res[31] = fact1p3z * _1pxt1py;
306 btScalar _9t3x2py2pz2m19 = 9.0 * (3.0 * x2 + y2 + z2) - 19.0;
307 btScalar _9tx2p3y2pz2m19 = 9.0 * (x2 + 3.0 * y2 + z2) - 19.0;
308 btScalar _9tx2py2p3z2m19 = 9.0 * (x2 + y2 + 3.0 * z2) - 19.0;
321 btScalar _18xm9t3x2py2pz2m19 = _18x - _9t3x2py2pz2m19;
322 btScalar _18xp9t3x2py2pz2m19 = _18x + _9t3x2py2pz2m19;
323 btScalar _18ym9tx2p3y2pz2m19 = _18y - _9tx2p3y2pz2m19;
324 btScalar _18yp9tx2p3y2pz2m19 = _18y + _9tx2p3y2pz2m19;
325 btScalar _18zm9tx2py2p3z2m19 = _18z - _9tx2py2p3z2m19;
326 btScalar _18zp9tx2py2p3z2m19 = _18z + _9tx2py2p3z2m19;
328 dN(0,0) =_18xm9t3x2py2pz2m19 * _1myt1mz;
329 dN(0,1) =_1mxt1mz * _18ym9tx2p3y2pz2m19;
330 dN(0,2) =_1mxt1my * _18zm9tx2py2p3z2m19;
331 dN(1,0) =_18xp9t3x2py2pz2m19 * _1myt1mz;
332 dN(1,1) =_1pxt1mz * _18ym9tx2p3y2pz2m19;
333 dN(1,2) =_1pxt1my * _18zm9tx2py2p3z2m19;
334 dN(2,0) =_18xm9t3x2py2pz2m19 * _1pyt1mz;
335 dN(2,1) =_1mxt1mz * _18yp9tx2p3y2pz2m19;
336 dN(2,2) =_1mxt1py * _18zm9tx2py2p3z2m19;
337 dN(3,0) =_18xp9t3x2py2pz2m19 * _1pyt1mz;
338 dN(3,1) =_1pxt1mz * _18yp9tx2p3y2pz2m19;
339 dN(3,2) =_1pxt1py * _18zm9tx2py2p3z2m19;
340 dN(4,0) =_18xm9t3x2py2pz2m19 * _1myt1pz;
341 dN(4,1) =_1mxt1pz * _18ym9tx2p3y2pz2m19;
342 dN(4,2) =_1mxt1my * _18zp9tx2py2p3z2m19;
343 dN(5,0) =_18xp9t3x2py2pz2m19 * _1myt1pz;
344 dN(5,1) =_1pxt1pz * _18ym9tx2p3y2pz2m19;
345 dN(5,2) =_1pxt1my * _18zp9tx2py2p3z2m19;
346 dN(6,0) =_18xm9t3x2py2pz2m19 * _1pyt1pz;
347 dN(6,1) =_1mxt1pz * _18yp9tx2p3y2pz2m19;
348 dN(6,2) =_1mxt1py * _18zp9tx2py2p3z2m19;
349 dN(7,0) =_18xp9t3x2py2pz2m19 * _1pyt1pz;
350 dN(7,1) =_1pxt1pz * _18yp9tx2p3y2pz2m19;
351 dN(7,2) =_1pxt1py * _18zp9tx2py2p3z2m19;
355 btScalar _m3m9x2m2x = -_3m9x2 - _2x;
357 btScalar _1mx2t1m3x = _1mx2 * _1m3x;
358 btScalar _1mx2t1p3x = _1mx2 * _1p3x;
359 dN( 8,0) = _m3m9x2m2x * _1myt1mz,
360 dN( 8,1) = -_1mx2t1m3x * _1mz,
361 dN( 8,2) = -_1mx2t1m3x * _1my;
362 dN( 9,0) = _p3m9x2m2x * _1myt1mz,
363 dN( 9,1) = -_1mx2t1p3x * _1mz,
364 dN( 9,2) = -_1mx2t1p3x * _1my;
365 dN(10,0) = _m3m9x2m2x * _1myt1pz,
366 dN(10,1) = -_1mx2t1m3x * _1pz,
367 dN(10,2) = _1mx2t1m3x * _1my;
368 dN(11,0) = _p3m9x2m2x * _1myt1pz,
369 dN(11,1) = -_1mx2t1p3x * _1pz,
370 dN(11,2) = _1mx2t1p3x * _1my;
371 dN(12,0) = _m3m9x2m2x * _1pyt1mz,
372 dN(12,1) = _1mx2t1m3x * _1mz,
373 dN(12,2) = -_1mx2t1m3x * _1py;
374 dN(13,0) = _p3m9x2m2x * _1pyt1mz,
375 dN(13,1) = _1mx2t1p3x * _1mz,
376 dN(13,2) = -_1mx2t1p3x * _1py;
377 dN(14,0) = _m3m9x2m2x * _1pyt1pz,
378 dN(14,1) = _1mx2t1m3x * _1pz,
379 dN(14,2) = _1mx2t1m3x * _1py;
380 dN(15,0) = _p3m9x2m2x * _1pyt1pz,
381 dN(15,1) = _1mx2t1p3x * _1pz,
382 dN(15,2) = _1mx2t1p3x * _1py;
384 btScalar _m3m9y2m2y = -_3m9y2 - _2y;
386 btScalar _1my2t1m3y = _1my2 * _1m3y;
387 btScalar _1my2t1p3y = _1my2 * _1p3y;
388 dN(16,0) = -_1my2t1m3y * _1mz,
389 dN(16,1) = _m3m9y2m2y * _1mxt1mz,
390 dN(16,2) = -_1my2t1m3y * _1mx;
391 dN(17,0) = -_1my2t1p3y * _1mz,
392 dN(17,1) = _p3m9y2m2y * _1mxt1mz,
393 dN(17,2) = -_1my2t1p3y * _1mx;
394 dN(18,0) = _1my2t1m3y * _1mz,
395 dN(18,1) = _m3m9y2m2y * _1pxt1mz,
396 dN(18,2) = -_1my2t1m3y * _1px;
397 dN(19,0) = _1my2t1p3y * _1mz,
398 dN(19,1) = _p3m9y2m2y * _1pxt1mz,
399 dN(19,2) = -_1my2t1p3y * _1px;
400 dN(20,0) = -_1my2t1m3y * _1pz,
401 dN(20,1) = _m3m9y2m2y * _1mxt1pz,
402 dN(20,2) = _1my2t1m3y * _1mx;
403 dN(21,0) = -_1my2t1p3y * _1pz,
404 dN(21,1) = _p3m9y2m2y * _1mxt1pz,
405 dN(21,2) = _1my2t1p3y * _1mx;
406 dN(22,0) = _1my2t1m3y * _1pz,
407 dN(22,1) = _m3m9y2m2y * _1pxt1pz,
408 dN(22,2) = _1my2t1m3y * _1px;
409 dN(23,0) = _1my2t1p3y * _1pz,
410 dN(23,1) = _p3m9y2m2y * _1pxt1pz,
411 dN(23,2) = _1my2t1p3y * _1px;
414 btScalar _m3m9z2m2z = -_3m9z2 - _2z;
416 btScalar _1mz2t1m3z = _1mz2 * _1m3z;
417 btScalar _1mz2t1p3z = _1mz2 * _1p3z;
418 dN(24,0) = -_1mz2t1m3z * _1my,
419 dN(24,1) = -_1mz2t1m3z * _1mx,
420 dN(24,2) = _m3m9z2m2z * _1mxt1my;
421 dN(25,0) = -_1mz2t1p3z * _1my,
422 dN(25,1) = -_1mz2t1p3z * _1mx,
423 dN(25,2) = _p3m9z2m2z * _1mxt1my;
424 dN(26,0) = -_1mz2t1m3z * _1py,
425 dN(26,1) = _1mz2t1m3z * _1mx,
426 dN(26,2) = _m3m9z2m2z * _1mxt1py;
427 dN(27,0) = -_1mz2t1p3z * _1py,
428 dN(27,1) = _1mz2t1p3z * _1mx,
429 dN(27,2) = _p3m9z2m2z * _1mxt1py;
430 dN(28,0) = _1mz2t1m3z * _1my,
431 dN(28,1) = -_1mz2t1m3z * _1px,
432 dN(28,2) = _m3m9z2m2z * _1pxt1my;
433 dN(29,0) = _1mz2t1p3z * _1my,
434 dN(29,1) = -_1mz2t1p3z * _1px,
435 dN(29,2) = _p3m9z2m2z * _1pxt1my;
436 dN(30,0) = _1mz2t1m3z * _1py,
437 dN(30,1) = _1mz2t1m3z * _1px,
438 dN(30,2) = _m3m9z2m2z * _1pxt1py;
439 dN(31,0) = _1mz2t1p3z * _1py,
440 dN(31,1) = _1mz2t1p3z * _1px,
441 dN(31,2) = _p3m9z2m2z * _1pxt1py;
459 if (!m_domain.contains(x))
462 btVector3 tmpmi = ((x - m_domain.min())*(m_inv_cell_size));
463 unsigned int mi[3] = {(
unsigned int )tmpmi[0],(
unsigned int )tmpmi[1],(
unsigned int )tmpmi[2]};
464 if (mi[0] >= m_resolution[0])
465 mi[0] = m_resolution[0]-1;
466 if (mi[1] >= m_resolution[1])
467 mi[1] = m_resolution[1]-1;
468 if (mi[2] >= m_resolution[2])
469 mi[2] = m_resolution[2]-1;
474 int i = multiToSingleIndex(mui);
475 unsigned int i_ = m_cell_map[field_id][i];
488 btCell32 const& cell = m_cells[field_id][i];
494 for (
unsigned int j = 0u; j < 32u; ++j)
496 unsigned int v = cell.
m_cells[j];
497 double c = m_nodes[field_id][v];
514 for (
unsigned int j = 0u; j < 32u; ++j)
516 unsigned int v = cell.
m_cells[j];
517 double c = m_nodes[field_id][v];
524 (*gradient)[0] += c * dN(j, 0);
525 (*gradient)[1] += c * dN(j, 1);
526 (*gradient)[2] += c * dN(j, 2);
void bottomRowsMul(int row, double val)
btAlignedBox3d subdomain(btMultiIndex const &ijk) const
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
btSdfDataStream(const char *data, int size)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
const btVector3 & min() const
bool interpolate(unsigned int field_id, double &dist, btVector3 const &x, btVector3 *gradient) const
bool load(const char *data, int size)
unsigned int multiToSingleIndex(btMultiIndex const &ijk) const
btShapeMatrix shape_function_(btVector3 const &xi, btShapeGradients *gradient=0) const
int size() const
return the number of elements in the array
const btVector3 & max() const
btMultiIndex singleToMultiIndex(unsigned int l) const
btVector3 can be used to represent 3D points and vectors.
void topRowsDivide(int row, double denom)
void resize(int newsize, const T &fillData=T())
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...