27 #ifndef CDPL_MATH_REGULARSPATIALGRID_HPP
28 #define CDPL_MATH_REGULARSPATIALGRID_HPP
30 #include <type_traits>
47 template <
typename MatrixType>
51 static void init(MatrixType& mtx)
57 static bool invert(
const MatrixType& mtx,
M& inv_mtx)
62 template <
typename V,
typename R>
81 template <typename T, typename C = typename TypeTraits<T>::RealType,
typename GD =
Grid<T>,
typename XF =
CMatrix<C, 4, 4> >
100 typedef typename std::conditional<std::is_const<GD>::value,
101 typename GD::ConstReference,
112 dataMode(
POINT), xStep(xs), yStep(ys), zStep(zs)
120 dataMode(
POINT), data(data), xStep(xs), yStep(ys), zStep(zs)
128 dataMode(
POINT), xStep(
s), yStep(
s), zStep(
s)
136 dataMode(
POINT), data(data), xStep(
s), yStep(
s), zStep(
s)
144 dataMode(usg.dataMode), data(usg.data), xStep(usg.xStep), yStep(usg.yStep), zStep(usg.zStep),
145 xform(usg.xform), invXform(usg.invXform) {}
148 dataMode(usg.dataMode), data(std::move(usg.data)), xStep(usg.xStep), yStep(usg.yStep), zStep(usg.zStep),
149 xform(usg.xform), invXform(usg.invXform) {}
175 return data(i, j, k);
180 return data(i, j, k);
185 return data.getSize();
190 return data.getSize1();
195 return data.getSize2();
200 return data.getSize3();
205 return data.getMaxSize();
210 return data.getMaxSize1();
215 return data.getMaxSize2();
220 return data.getMaxSize3();
255 if (dataMode ==
POINT)
256 return (data.getSize1() * xStep);
258 return ((data.getSize1() <= 1 ?
SizeType(0) : (data.getSize1() - 1)) * xStep);
263 if (dataMode ==
POINT)
264 return (data.getSize2() * yStep);
266 return ((data.getSize2() <= 1 ?
SizeType(0) : (data.getSize2() - 1)) * yStep);
271 if (dataMode ==
POINT)
272 return (data.getSize3() * zStep);
274 return ((data.getSize3() <= 1 ?
SizeType(0) : (data.getSize3() - 1)) * zStep);
277 template <
typename V>
288 template <
typename V>
299 coords[0] = world_coords(0);
300 coords[1] = world_coords(1);
301 coords[2] = world_coords(2);
304 template <
typename V>
307 if (dataMode ==
POINT) {
319 template <
typename V1,
typename V2>
324 transformToLocalCoordinates(world_coords, tmp_local_coords);
326 local_coords[0] = tmp_local_coords[0];
327 local_coords[1] = tmp_local_coords[1];
328 local_coords[2] = tmp_local_coords[2];
331 template <
typename V>
336 transformToLocalCoordinates(pos, local_coords);
341 template <
typename V>
365 template <
typename V1,
typename V2>
370 transformToLocalCoordinates(pos, local_coords);
375 template <
typename V1,
typename V2>
382 indices[0] =
SSizeType(std::floor(x / xStep));
383 indices[1] =
SSizeType(std::floor(y / yStep));
384 indices[2] =
SSizeType(std::floor(z / zStep));
389 return data.isEmpty();
407 template <
typename T1>
411 #ifdef CDPL_MATH_CHECKS_DISABLE
420 dataMode = usg.dataMode;
423 invXform = usg.invXform;
432 dataMode = usg.dataMode;
433 data = std::move(usg.data);
435 invXform = usg.invXform;
442 template <
typename E>
449 template <
typename E>
456 template <
typename E>
463 template <
typename T1>
470 template <
typename T1>
477 template <
typename E>
484 template <
typename E>
491 template <
typename E>
501 xform.swap(usg.xform);
502 invXform.swap(usg.invXform);
503 std::swap(xStep, usg.xStep);
504 std::swap(yStep, usg.yStep);
505 std::swap(zStep, usg.zStep);
506 std::swap(dataMode, dataMode);
521 data.resize(
m, n, o, preserve, v);
525 template <
typename V1,
typename V2>
526 void transformToLocalCoordinates(
const V1& coords,
V2& local_coords)
const
530 world_coords(0) = coords[0];
531 world_coords(1) = coords[1];
532 world_coords(2) = coords[2];
547 template <
typename T,
typename C,
typename GD,
typename XF,
typename V>
552 typedef typename GridType::CoordinatesValueType CoordinatesValueType;
553 typedef typename GridType::SSizeType SSizeType;
554 typedef typename GridType::ValueType ValueType;
557 return CoordinatesValueType();
559 CoordinatesValueType loc_pos[3];
573 CoordinatesValueType xyz0[3];
577 SSizeType inds_p1[3];
580 bool recalc_xyz0 =
false;
582 if (loc_pos[0] < xyz0[0]) {
583 inds_p1[0] = inds[0];
588 inds_p1[0] = inds[0] + 1;
590 if (loc_pos[1] < xyz0[1]) {
591 inds_p1[1] = inds[1];
596 inds_p1[1] = inds[1] + 1;
598 if (loc_pos[2] < xyz0[2]) {
599 inds_p1[2] = inds[2];
604 inds_p1[2] = inds[2] + 1;
610 inds_p1[0] = inds[0] + 1;
611 inds_p1[1] = inds[1] + 1;
612 inds_p1[2] = inds[2] + 1;
615 inds[0] = std::max(SSizeType(0), inds[0]);
616 inds[1] = std::max(SSizeType(0), inds[1]);
617 inds[2] = std::max(SSizeType(0), inds[2]);
619 inds[0] = std::min(SSizeType(grid.
getSize1() - 1), inds[0]);
620 inds[1] = std::min(SSizeType(grid.
getSize2() - 1), inds[1]);
621 inds[2] = std::min(SSizeType(grid.
getSize3() - 1), inds[2]);
623 inds_p1[0] = std::max(SSizeType(0), inds_p1[0]);
624 inds_p1[1] = std::max(SSizeType(0), inds_p1[1]);
625 inds_p1[2] = std::max(SSizeType(0), inds_p1[2]);
627 inds_p1[0] = std::min(SSizeType(grid.
getSize1() - 1), inds_p1[0]);
628 inds_p1[1] = std::min(SSizeType(grid.
getSize2() - 1), inds_p1[1]);
629 inds_p1[2] = std::min(SSizeType(grid.
getSize3() - 1), inds_p1[2]);
631 CoordinatesValueType xd = (loc_pos[0] - xyz0[0]) / grid.
getXStepSize();
632 CoordinatesValueType yd = (loc_pos[1] - xyz0[1]) / grid.
getYStepSize();
633 CoordinatesValueType zd = (loc_pos[2] - xyz0[2]) / grid.
getZStepSize();
635 ValueType c00 = grid(inds[0], inds[1], inds[2]) * (1 - xd) + grid(inds_p1[0], inds[1], inds[2]) * xd;
636 ValueType c01 = grid(inds[0], inds[1], inds_p1[2]) * (1 - xd) + grid(inds_p1[0], inds[1], inds_p1[2]) * xd;
637 ValueType c10 = grid(inds[0], inds_p1[1], inds[2]) * (1 - xd) + grid(inds_p1[0], inds_p1[1], inds[2]) * xd;
638 ValueType c11 = grid(inds[0], inds_p1[1], inds_p1[2]) * (1 - xd) + grid(inds_p1[0], inds_p1[1], inds_p1[2]) * xd;
640 ValueType c0 = c00 * (1 - yd) + c10 * yd;
641 ValueType c1 = c01 * (1 - yd) + c11 * yd;
643 ValueType c = c0 * (1 - zd) + c1 * zd;
Definition of exception classes.
#define CDPL_MATH_CHECK(expr, msg, e)
Definition: Check.hpp:36
Definition of various grid expression types and operations.
Definition of grid data types.
Definition of matrix data types.
Definition of type traits.
Definition of vector data types.
Thrown to indicate that some requested calculation has failed.
Definition: Base/Exceptions.hpp:230
Definition: Matrix.hpp:854
Definition: Matrix.hpp:1152
Definition: Vector.hpp:1053
Definition: Expression.hpp:120
Definition: Math/Grid.hpp:226
Definition: Matrix.hpp:1607
Definition: RegularSpatialGrid.hpp:83
GD::ConstReference ConstReference
Definition: RegularSpatialGrid.hpp:103
SizeType getMaxSize3() const
Definition: RegularSpatialGrid.hpp:218
bool containsPoint(const V &pos) const
Definition: RegularSpatialGrid.hpp:332
CoordinatesValueType getZStepSize() const
Definition: RegularSpatialGrid.hpp:233
XF CoordinatesTransformType
Definition: RegularSpatialGrid.hpp:98
RegularSpatialGrid & operator=(const RegularSpatialGrid &usg)
Definition: RegularSpatialGrid.hpp:418
SizeType getMaxSize2() const
Definition: RegularSpatialGrid.hpp:213
DataMode
Definition: RegularSpatialGrid.hpp:89
@ POINT
Definition: RegularSpatialGrid.hpp:92
@ CELL
Definition: RegularSpatialGrid.hpp:91
void setCoordinatesTransform(const T1 &xform)
Definition: RegularSpatialGrid.hpp:408
void setYStepSize(const CoordinatesValueType &ys)
Definition: RegularSpatialGrid.hpp:243
bool isEmpty() const
Definition: RegularSpatialGrid.hpp:387
RegularSpatialGrid(const RegularSpatialGrid &usg)
Definition: RegularSpatialGrid.hpp:143
DataMode getDataMode() const
Definition: RegularSpatialGrid.hpp:158
void setZStepSize(const CoordinatesValueType &zs)
Definition: RegularSpatialGrid.hpp:248
RegularSpatialGrid & operator=(RegularSpatialGrid &&usg)
Definition: RegularSpatialGrid.hpp:430
std::enable_if< IsScalar< T >::value, RegularSpatialGrid >::type & operator*=(const T1 &t)
Definition: RegularSpatialGrid.hpp:464
RegularSpatialGrid(const GridDataType &data, const CoordinatesValueType &xs, const CoordinatesValueType &ys, const CoordinatesValueType &zs)
Definition: RegularSpatialGrid.hpp:119
T ValueType
Definition: RegularSpatialGrid.hpp:95
std::conditional< std::is_const< GD >::value, typename GD::ConstReference, typename GD::Reference >::type Reference
Definition: RegularSpatialGrid.hpp:102
RegularSpatialGrid(const CoordinatesValueType &xs, const CoordinatesValueType &ys, const CoordinatesValueType &zs)
Definition: RegularSpatialGrid.hpp:111
const SelfType ConstClosureType
Definition: RegularSpatialGrid.hpp:108
CoordinatesTransformType::MatrixTemporaryType InvCoordinatesTransformType
Definition: RegularSpatialGrid.hpp:99
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Definition: RegularSpatialGrid.hpp:178
RegularSpatialGrid & minusAssign(const GridExpression< E > &e)
Definition: RegularSpatialGrid.hpp:492
std::shared_ptr< SelfType > SharedPointer
Definition: RegularSpatialGrid.hpp:109
std::enable_if< IsScalar< T >::value, RegularSpatialGrid >::type & operator/=(const T1 &t)
Definition: RegularSpatialGrid.hpp:471
CoordinatesValueType getYExtent() const
Definition: RegularSpatialGrid.hpp:261
GD::DifferenceType DifferenceType
Definition: RegularSpatialGrid.hpp:106
void clear(const ValueType &v=ValueType())
Definition: RegularSpatialGrid.hpp:514
SizeType getSize() const
Definition: RegularSpatialGrid.hpp:183
std::ptrdiff_t SSizeType
Definition: RegularSpatialGrid.hpp:105
SizeType getMaxSize1() const
Definition: RegularSpatialGrid.hpp:208
void setXStepSize(const CoordinatesValueType &xs)
Definition: RegularSpatialGrid.hpp:238
RegularSpatialGrid(const CoordinatesValueType &s)
Definition: RegularSpatialGrid.hpp:127
RegularSpatialGrid & operator+=(const GridExpression< E > &e)
Definition: RegularSpatialGrid.hpp:450
friend void swap(RegularSpatialGrid &usg1, RegularSpatialGrid &usg2)
Definition: RegularSpatialGrid.hpp:509
GD::SizeType SizeType
Definition: RegularSpatialGrid.hpp:104
SizeType getSize3() const
Definition: RegularSpatialGrid.hpp:198
SizeType getSize1() const
Definition: RegularSpatialGrid.hpp:188
Reference operator()(SizeType i, SizeType j, SizeType k)
Definition: RegularSpatialGrid.hpp:173
CoordinatesValueType getXStepSize() const
Definition: RegularSpatialGrid.hpp:223
RegularSpatialGrid & operator-=(const GridExpression< E > &e)
Definition: RegularSpatialGrid.hpp:457
RegularSpatialGrid(RegularSpatialGrid &&usg)
Definition: RegularSpatialGrid.hpp:147
const CoordinatesTransformType & getCoordinatesTransform() const
Definition: RegularSpatialGrid.hpp:402
void setDataMode(DataMode mode)
Definition: RegularSpatialGrid.hpp:153
SizeType getSize2() const
Definition: RegularSpatialGrid.hpp:193
CoordinatesValueType getYStepSize() const
Definition: RegularSpatialGrid.hpp:228
CoordinatesValueType getXExtent() const
Definition: RegularSpatialGrid.hpp:253
void getLocalCoordinates(SSizeType i, SSizeType j, SSizeType k, V &coords) const
Definition: RegularSpatialGrid.hpp:305
void getContainingCell(const V1 &pos, V2 &indices) const
Definition: RegularSpatialGrid.hpp:366
SelfType ClosureType
Definition: RegularSpatialGrid.hpp:107
RegularSpatialGrid & assign(const GridExpression< E > &e)
Definition: RegularSpatialGrid.hpp:478
GD GridDataType
Definition: RegularSpatialGrid.hpp:97
ConstReference operator()(SizeType i) const
Definition: RegularSpatialGrid.hpp:168
RegularSpatialGrid & operator=(const GridExpression< E > &e)
Definition: RegularSpatialGrid.hpp:443
RegularSpatialGrid & plusAssign(const GridExpression< E > &e)
Definition: RegularSpatialGrid.hpp:485
const GridDataType & getData() const
Definition: RegularSpatialGrid.hpp:392
RegularSpatialGrid(const GridDataType &data, const CoordinatesValueType &s)
Definition: RegularSpatialGrid.hpp:135
void resize(SizeType m, SizeType n, SizeType o, bool preserve=true, const ValueType &v=ValueType())
Definition: RegularSpatialGrid.hpp:519
bool containsLocalPoint(const V &pos) const
Definition: RegularSpatialGrid.hpp:342
C CoordinatesValueType
Definition: RegularSpatialGrid.hpp:96
CoordinatesValueType getZExtent() const
Definition: RegularSpatialGrid.hpp:269
void getCoordinates(SizeType i, V &coords) const
Definition: RegularSpatialGrid.hpp:278
GridDataType & getData()
Definition: RegularSpatialGrid.hpp:397
void getLocalContainingCell(const V1 &pos, V2 &indices) const
Definition: RegularSpatialGrid.hpp:376
void getCoordinates(SSizeType i, SSizeType j, SSizeType k, V &coords) const
Definition: RegularSpatialGrid.hpp:289
Reference operator()(SizeType i)
Definition: RegularSpatialGrid.hpp:163
SizeType getMaxSize() const
Definition: RegularSpatialGrid.hpp:203
virtual ~RegularSpatialGrid()
Definition: RegularSpatialGrid.hpp:151
void getLocalCoordinates(const V1 &world_coords, V2 &local_coords) const
Definition: RegularSpatialGrid.hpp:320
void swap(RegularSpatialGrid &usg)
Definition: RegularSpatialGrid.hpp:498
constexpr unsigned int R
Specifies that the atom has R configuration.
Definition: AtomConfiguration.hpp:58
constexpr unsigned int M
A generic type that covers any element that is a metal.
Definition: AtomType.hpp:657
constexpr unsigned int V
Specifies Vanadium.
Definition: AtomType.hpp:177
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int C
Specifies Carbon.
Definition: AtomType.hpp:92
constexpr unsigned int r
Specifies that the stereocenter has r configuration.
Definition: CIPDescriptor.hpp:76
constexpr unsigned int s
Specifies that the stereocenter has s configuration.
Definition: CIPDescriptor.hpp:81
constexpr unsigned int m
Specifies that the stereocenter has m configuration.
Definition: CIPDescriptor.hpp:116
RegularSpatialGrid< double > DRegularSpatialGrid
An unbounded dense regular grid in 3D space holding floating point values of type double.
Definition: RegularSpatialGrid.hpp:656
Matrix1VectorBinaryTraits< E1, E2, MatrixVectorProduct< E1, E2 > >::ResultType prod(const MatrixExpression< E1 > &e1, const VectorExpression< E2 > &e2)
Definition: MatrixExpression.hpp:833
RegularSpatialGrid< float > FRegularSpatialGrid
An unbounded dense regular grid in 3D space holding floating point values of type float.
Definition: RegularSpatialGrid.hpp:651
bool invert(const MatrixExpression< E > &e, MatrixContainer< C > &c)
Definition: Matrix.hpp:1766
T interpolateTrilinear(const RegularSpatialGrid< T, C, GD, XF > &grid, const V &pos, bool local_pos)
Definition: RegularSpatialGrid.hpp:548
void transform(VectorArray< CVector< T, Dim > > &va, const CMatrix< T1, Dim, Dim > &xform)
Transforms each -dimensional vector in the array with the -dimensional square matrix xform.
Definition: VectorArrayFunctions.hpp:51
The namespace of the Chemical Data Processing Library.