Chemical Data Processing Library C++ API - Version 1.4.0
RegularSpatialGrid.hpp
Go to the documentation of this file.
1 /*
2  * RegularSpatialGrid.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_REGULARSPATIALGRID_HPP
28 #define CDPL_MATH_REGULARSPATIALGRID_HPP
29 
30 #include <type_traits>
31 #include <utility>
32 #include <memory>
33 
35 #include "CDPL/Math/Grid.hpp"
36 #include "CDPL/Math/Matrix.hpp"
37 #include "CDPL/Math/Vector.hpp"
38 #include "CDPL/Math/TypeTraits.hpp"
39 #include "CDPL/Base/Exceptions.hpp"
40 
41 namespace CDPL
42 {
43 
44  namespace Math
45  {
46 
51  template <typename MatrixType>
53  {
54 
59  static void init(MatrixType& mtx)
60  {
62  }
63 
71  template <typename M>
72  static bool invert(const MatrixType& mtx, M& inv_mtx)
73  {
74  return Math::invert(mtx, inv_mtx);
75  }
76 
85  template <typename V, typename R>
86  static void transform(const MatrixType& mtx, const V& v, R& r)
87  {
88  prod(mtx, v, r);
89  }
90  };
91 
96  template <typename T>
98 
103  template <typename T>
105  {};
106 
111  template <typename T>
112  struct GridCoordinatesTransformTraits<BoundedMatrix<T, 4, 4> > : public GridCoordinatesMatrixTransformTraits<BoundedMatrix<T, 4, 4> >
113  {};
114 
115 
125  template <typename T, typename C = typename TypeTraits<T>::RealType, typename GD = Grid<T>, typename XF = CMatrix<C, 4, 4> >
126  class RegularSpatialGrid : public GridExpression<RegularSpatialGrid<T, C, GD, XF> >
127  {
128 
130 
131  public:
133  typedef T ValueType;
137  typedef GD GridDataType;
141  typedef typename CoordinatesTransformType::MatrixTemporaryType InvCoordinatesTransformType;
143  typedef typename std::conditional<std::is_const<GD>::value,
144  typename GD::ConstReference,
145  typename GD::Reference>::type Reference;
147  typedef typename GD::ConstReference ConstReference;
149  typedef typename GD::SizeType SizeType;
151  typedef std::ptrdiff_t SSizeType;
153  typedef typename GD::DifferenceType DifferenceType;
157  typedef const SelfType ConstClosureType;
159  typedef std::shared_ptr<SelfType> SharedPointer;
160 
168  xStep(xs), yStep(ys), zStep(zs)
169  {
170 
173  }
174 
183  data(data), xStep(xs), yStep(ys), zStep(zs)
184  {
185 
188  }
189 
195  xStep(s), yStep(s), zStep(s)
196  {
197 
200  }
201 
208  data(data), xStep(s), yStep(s), zStep(s)
209  {
210 
213  }
214 
220  data(usg.data), xStep(usg.xStep), yStep(usg.yStep), zStep(usg.zStep),
221  xform(usg.xform), invXform(usg.invXform) {}
222 
228  data(std::move(usg.data)), xStep(usg.xStep), yStep(usg.yStep), zStep(usg.zStep),
229  xform(usg.xform), invXform(usg.invXform) {}
230 
234  virtual ~RegularSpatialGrid() {}
235 
242  {
243  return data(i);
244  }
245 
252  {
253  return data(i);
254  }
255 
264  {
265  return data(i, j, k);
266  }
267 
276  {
277  return data(i, j, k);
278  }
279 
285  {
286  return data.getSize();
287  }
288 
294  {
295  return data.getSize1();
296  }
297 
303  {
304  return data.getSize2();
305  }
306 
312  {
313  return data.getSize3();
314  }
315 
321  {
322  return data.getMaxSize();
323  }
324 
330  {
331  return data.getMaxSize1();
332  }
333 
339  {
340  return data.getMaxSize2();
341  }
342 
348  {
349  return data.getMaxSize3();
350  }
351 
357  {
358  return xStep;
359  }
360 
366  {
367  return yStep;
368  }
369 
375  {
376  return zStep;
377  }
378 
384  {
385  xStep = xs;
386  }
387 
393  {
394  yStep = ys;
395  }
396 
402  {
403  zStep = zs;
404  }
405 
411  {
412  return ((data.getSize1() <= 1 ? SizeType(0) : (data.getSize1() - 1)) * xStep);
413  }
414 
420  {
421  return ((data.getSize2() <= 1 ? SizeType(0) : (data.getSize2() - 1)) * yStep);
422  }
423 
429  {
430  return ((data.getSize3() <= 1 ? SizeType(0) : (data.getSize3() - 1)) * zStep);
431  }
432 
439  template <typename V>
440  void getCoordinates(SizeType i, V& coords) const
441  {
442  SizeType z = i / (getSize1() * getSize2());
443  SizeType xy = i % (getSize1() * getSize2());
444  SizeType y = xy / getSize1();
445  SizeType x = xy % getSize1();
446 
447  getCoordinates(x, y, z, coords);
448  }
449 
458  template <typename V>
459  void getCoordinates(SSizeType i, SSizeType j, SSizeType k, V& coords) const
460  {
462 
463  getLocalCoordinates(i, j, k, local_coords);
464  local_coords(3) = CoordinatesValueType(1);
465 
468 
469  coords[0] = world_coords(0);
470  coords[1] = world_coords(1);
471  coords[2] = world_coords(2);
472  }
473 
486  template <typename V>
487  void getLocalCoordinates(SSizeType i, SSizeType j, SSizeType k, V& coords) const
488  {
489  coords[0] = i * xStep - getXExtent() * CoordinatesValueType(0.5);
490  coords[1] = j * yStep - getYExtent() * CoordinatesValueType(0.5);
491  coords[2] = k * zStep - getZExtent() * CoordinatesValueType(0.5);
492  }
493 
501  template <typename V1, typename V2>
502  void getLocalCoordinates(const V1& world_coords, V2& local_coords) const
503  {
504  CVector<CoordinatesValueType, 4> tmp_local_coords;
505 
506  transformToLocalCoordinates(world_coords, tmp_local_coords);
507 
508  local_coords[0] = tmp_local_coords[0];
509  local_coords[1] = tmp_local_coords[1];
510  local_coords[2] = tmp_local_coords[2];
511  }
512 
519  template <typename V>
520  bool containsPoint(const V& pos) const
521  {
523 
524  transformToLocalCoordinates(pos, local_coords);
525 
526  return containsLocalPoint(local_coords);
527  }
528 
535  template <typename V>
536  bool containsLocalPoint(const V& pos) const
537  {
538  if (CoordinatesValueType(pos[0]) >= (getXExtent() * CoordinatesValueType(0.5)))
539  return false;
540 
541  if (CoordinatesValueType(pos[1]) >= (getYExtent() * CoordinatesValueType(0.5)))
542  return false;
543 
544  if (CoordinatesValueType(pos[2]) >= (getZExtent() * CoordinatesValueType(0.5)))
545  return false;
546 
547  if (CoordinatesValueType(pos[0]) < (-getXExtent() * CoordinatesValueType(0.5)))
548  return false;
549 
550  if (CoordinatesValueType(pos[1]) < (-getYExtent() * CoordinatesValueType(0.5)))
551  return false;
552 
553  if (CoordinatesValueType(pos[2]) < (-getZExtent() * CoordinatesValueType(0.5)))
554  return false;
555 
556  return true;
557  }
558 
566  template <typename V1, typename V2>
567  void getContainingCell(const V1& pos, V2& indices) const
568  {
570 
571  transformToLocalCoordinates(pos, local_coords);
572 
573  getLocalContainingCell(local_coords, indices);
574  }
575 
583  template <typename V1, typename V2>
584  void getLocalContainingCell(const V1& pos, V2& indices) const
585  {
589 
590  indices[0] = SSizeType(std::floor(x / xStep));
591  indices[1] = SSizeType(std::floor(y / yStep));
592  indices[2] = SSizeType(std::floor(z / zStep));
593  }
594 
599  bool isEmpty() const
600  {
601  return data.isEmpty();
602  }
603 
608  const GridDataType& getData() const
609  {
610  return data;
611  }
612 
618  {
619  return data;
620  }
621 
627  {
628  return xform;
629  }
630 
637  template <typename T1>
638  void setCoordinatesTransform(const T1& xform)
639  {
640  this->xform = xform;
641 #ifdef CDPL_MATH_CHECKS_DISABLE
643 #else
645  "Inversion of transformation failed", Base::CalculationFailed);
646 #endif // CDPL_MATH_CHECKS_DISABLE
647  }
648 
655  {
656  data = usg.data;
657  xform = usg.xform;
658  invXform = usg.invXform;
659  xStep = usg.xStep;
660  yStep = usg.yStep;
661  zStep = usg.zStep;
662  return *this;
663  }
664 
671  {
672  data = std::move(usg.data);
673  xform = usg.xform;
674  invXform = usg.invXform;
675  xStep = usg.xStep;
676  yStep = usg.yStep;
677  zStep = usg.zStep;
678  return *this;
679  }
680 
687  template <typename E>
689  {
690  data.operator=(e);
691  return *this;
692  }
693 
700  template <typename E>
702  {
703  data.operator+=(e);
704  return *this;
705  }
706 
713  template <typename E>
715  {
716  data.operator-=(e);
717  return *this;
718  }
719 
726  template <typename T1>
727  typename std::enable_if<IsScalar<T>::value, RegularSpatialGrid>::type& operator*=(const T1& t)
728  {
729  data.operator*=(t);
730  return *this;
731  }
732 
739  template <typename T1>
740  typename std::enable_if<IsScalar<T>::value, RegularSpatialGrid>::type& operator/=(const T1& t)
741  {
742  data.operator/=(t);
743  return *this;
744  }
745 
752  template <typename E>
754  {
755  data.assign(e);
756  return *this;
757  }
758 
765  template <typename E>
767  {
768  data.plusAssign(e);
769  return *this;
770  }
771 
778  template <typename E>
780  {
781  data.minusAssign(e);
782  return *this;
783  }
784 
790  {
791  data.swap(usg.data);
792  xform.swap(usg.xform);
793  invXform.swap(usg.invXform);
794  std::swap(xStep, usg.xStep);
795  std::swap(yStep, usg.yStep);
796  std::swap(zStep, usg.zStep);
797  }
798 
804  friend void swap(RegularSpatialGrid& usg1, RegularSpatialGrid& usg2)
805  {
806  usg1.swap(usg2);
807  }
808 
813  void clear(const ValueType& v = ValueType())
814  {
815  data.clear(v);
816  }
817 
826  void resize(SizeType m, SizeType n, SizeType o, bool preserve = true, const ValueType& v = ValueType())
827  {
828  data.resize(m, n, o, preserve, v);
829  }
830 
831  private:
832  template <typename V1, typename V2>
833  void transformToLocalCoordinates(const V1& coords, V2& local_coords) const
834  {
836 
837  world_coords(0) = coords[0];
838  world_coords(1) = coords[1];
839  world_coords(2) = coords[2];
840  world_coords(3) = CoordinatesValueType(1);
841 
843  }
844 
845  GridDataType data;
846  CoordinatesValueType xStep;
847  CoordinatesValueType yStep;
848  CoordinatesValueType zStep;
851  };
852 
866  template <typename T, typename C, typename GD, typename XF, typename V>
867  T interpolateTrilinear(const RegularSpatialGrid<T, C, GD, XF>& grid, const V& pos, bool local_pos)
868  {
869  typedef RegularSpatialGrid<T, C, GD, XF> GridType;
870 
871  typedef typename GridType::CoordinatesValueType CoordinatesValueType;
872  typedef typename GridType::SSizeType SSizeType;
873  typedef typename GridType::ValueType ValueType;
874 
875  if (grid.isEmpty())
876  return CoordinatesValueType();
877 
878  CoordinatesValueType loc_pos[3];
879 
880  if (local_pos) {
881  loc_pos[0] = pos[0];
882  loc_pos[1] = pos[1];
883  loc_pos[2] = pos[2];
884 
885  } else
886  grid.getLocalCoordinates(pos, loc_pos);
887 
888  SSizeType inds[3];
889 
890  grid.getLocalContainingCell(loc_pos, inds);
891 
892  CoordinatesValueType xyz0[3];
893 
894  grid.getLocalCoordinates(inds[0], inds[1], inds[2], xyz0);
895 
896  SSizeType inds_p1[3];
897 
898  inds_p1[0] = inds[0] + 1;
899  inds_p1[1] = inds[1] + 1;
900  inds_p1[2] = inds[2] + 1;
901 
902  inds[0] = std::max(SSizeType(0), inds[0]);
903  inds[1] = std::max(SSizeType(0), inds[1]);
904  inds[2] = std::max(SSizeType(0), inds[2]);
905 
906  inds[0] = std::min(SSizeType(grid.getSize1() - 1), inds[0]);
907  inds[1] = std::min(SSizeType(grid.getSize2() - 1), inds[1]);
908  inds[2] = std::min(SSizeType(grid.getSize3() - 1), inds[2]);
909 
910  inds_p1[0] = std::max(SSizeType(0), inds_p1[0]);
911  inds_p1[1] = std::max(SSizeType(0), inds_p1[1]);
912  inds_p1[2] = std::max(SSizeType(0), inds_p1[2]);
913 
914  inds_p1[0] = std::min(SSizeType(grid.getSize1() - 1), inds_p1[0]);
915  inds_p1[1] = std::min(SSizeType(grid.getSize2() - 1), inds_p1[1]);
916  inds_p1[2] = std::min(SSizeType(grid.getSize3() - 1), inds_p1[2]);
917 
918  CoordinatesValueType xd = (loc_pos[0] - xyz0[0]) / grid.getXStepSize();
919  CoordinatesValueType yd = (loc_pos[1] - xyz0[1]) / grid.getYStepSize();
920  CoordinatesValueType zd = (loc_pos[2] - xyz0[2]) / grid.getZStepSize();
921 
922  ValueType c00 = grid(inds[0], inds[1], inds[2]) * (1 - xd) + grid(inds_p1[0], inds[1], inds[2]) * xd;
923  ValueType c01 = grid(inds[0], inds[1], inds_p1[2]) * (1 - xd) + grid(inds_p1[0], inds[1], inds_p1[2]) * xd;
924  ValueType c10 = grid(inds[0], inds_p1[1], inds[2]) * (1 - xd) + grid(inds_p1[0], inds_p1[1], inds[2]) * xd;
925  ValueType c11 = grid(inds[0], inds_p1[1], inds_p1[2]) * (1 - xd) + grid(inds_p1[0], inds_p1[1], inds_p1[2]) * xd;
926 
927  ValueType c0 = c00 * (1 - yd) + c10 * yd;
928  ValueType c1 = c01 * (1 - yd) + c11 * yd;
929 
930  ValueType c = c0 * (1 - zd) + c1 * zd;
931 
932  return c;
933  }
934 
939 
944  } // namespace Math
945 } // namespace CDPL
946 
947 #endif // CDPL_MATH_REGULARSPATIALGRID_HPP
Definition of exception classes.
#define CDPL_MATH_CHECK(expr, msg, e)
Throws the exception e with message msg when the boolean expression expr evaluates to false.
Definition: Check.hpp:47
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
Variable-size matrix with fixed upper capacities M N stored in a stack-allocated array.
Definition: Matrix.hpp:1461
Fixed-size dense matrix of dimensions M N backed by a 2D C-array (no dynamic allocation).
Definition: Matrix.hpp:1987
Fixed-size vector of dimension N backed by a C-array (no dynamic allocation).
Definition: Vector.hpp:1876
CRTP base class for all grid expression types.
Definition: Expression.hpp:180
Dynamically-sized dense 3D grid ( ) with configurable underlying storage.
Definition: Math/Grid.hpp:378
Constant identity-matrix expression ( on the diagonal, elsewhere).
Definition: Matrix.hpp:2784
3D grid data structure combining a Math::Grid data store with a coordinate-system transformation that...
Definition: RegularSpatialGrid.hpp:127
GD::ConstReference ConstReference
Constant reference type to a grid cell.
Definition: RegularSpatialGrid.hpp:147
SizeType getMaxSize3() const
Returns the maximum size of the grid along the third dimension.
Definition: RegularSpatialGrid.hpp:347
bool containsPoint(const V &pos) const
Tells whether the world-space point pos lies within the grid bounds.
Definition: RegularSpatialGrid.hpp:520
CoordinatesValueType getZStepSize() const
Returns the per-cell step size along the Z axis.
Definition: RegularSpatialGrid.hpp:374
XF CoordinatesTransformType
The coordinate transformation type mapping cell indices to world coordinates.
Definition: RegularSpatialGrid.hpp:139
RegularSpatialGrid & operator=(const RegularSpatialGrid &usg)
Copy-assigns from usg.
Definition: RegularSpatialGrid.hpp:654
SizeType getMaxSize2() const
Returns the maximum size of the grid along the second dimension.
Definition: RegularSpatialGrid.hpp:338
void setCoordinatesTransform(const T1 &xform)
Sets the cell-index to world-coordinate transformation to xform and caches its inverse.
Definition: RegularSpatialGrid.hpp:638
void setYStepSize(const CoordinatesValueType &ys)
Sets the per-cell step size along the Y axis to ys.
Definition: RegularSpatialGrid.hpp:392
bool isEmpty() const
Tells whether the grid is empty (zero cells along any dimension).
Definition: RegularSpatialGrid.hpp:599
RegularSpatialGrid(const RegularSpatialGrid &usg)
Constructs a copy of the RegularSpatialGrid instance usg.
Definition: RegularSpatialGrid.hpp:219
void setZStepSize(const CoordinatesValueType &zs)
Sets the per-cell step size along the Z axis to zs.
Definition: RegularSpatialGrid.hpp:401
RegularSpatialGrid & operator=(RegularSpatialGrid &&usg)
Move-assigns from usg.
Definition: RegularSpatialGrid.hpp:670
std::enable_if< IsScalar< T >::value, RegularSpatialGrid >::type & operator*=(const T1 &t)
Multiplies every cell by the scalar t.
Definition: RegularSpatialGrid.hpp:727
RegularSpatialGrid(const GridDataType &data, const CoordinatesValueType &xs, const CoordinatesValueType &ys, const CoordinatesValueType &zs)
Constructs the grid with anisotropic per-axis step sizes initialized to the supplied grid data.
Definition: RegularSpatialGrid.hpp:182
T ValueType
The grid cell value type.
Definition: RegularSpatialGrid.hpp:133
std::conditional< std::is_const< GD >::value, typename GD::ConstReference, typename GD::Reference >::type Reference
Mutable reference type to a grid cell (degrades to ConstReference when the data container is const).
Definition: RegularSpatialGrid.hpp:145
RegularSpatialGrid(const CoordinatesValueType &xs, const CoordinatesValueType &ys, const CoordinatesValueType &zs)
Constructs an empty grid with anisotropic per-axis step sizes.
Definition: RegularSpatialGrid.hpp:167
const SelfType ConstClosureType
Constant closure type used when this grid appears inside another expression.
Definition: RegularSpatialGrid.hpp:157
CoordinatesTransformType::MatrixTemporaryType InvCoordinatesTransformType
The inverse coordinate transformation type.
Definition: RegularSpatialGrid.hpp:141
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the cell at the (i, j, k) position.
Definition: RegularSpatialGrid.hpp:275
RegularSpatialGrid & minusAssign(const GridExpression< E > &e)
Subtracts the grid expression e from the underlying grid data without intermediate temporary.
Definition: RegularSpatialGrid.hpp:779
std::shared_ptr< SelfType > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated RegularSpatialGrid instances.
Definition: RegularSpatialGrid.hpp:159
std::enable_if< IsScalar< T >::value, RegularSpatialGrid >::type & operator/=(const T1 &t)
Divides every cell by the scalar t.
Definition: RegularSpatialGrid.hpp:740
CoordinatesValueType getYExtent() const
Returns the spatial extent of the grid along the Y axis.
Definition: RegularSpatialGrid.hpp:419
GD::DifferenceType DifferenceType
The signed difference type used by the grid data container.
Definition: RegularSpatialGrid.hpp:153
void clear(const ValueType &v=ValueType())
Sets every cell of the grid to the value v.
Definition: RegularSpatialGrid.hpp:813
SizeType getSize() const
Returns the total number of cells of the grid.
Definition: RegularSpatialGrid.hpp:284
std::ptrdiff_t SSizeType
A signed size type used for offset arithmetic.
Definition: RegularSpatialGrid.hpp:151
SizeType getMaxSize1() const
Returns the maximum size of the grid along the first dimension.
Definition: RegularSpatialGrid.hpp:329
void setXStepSize(const CoordinatesValueType &xs)
Sets the per-cell step size along the X axis to xs.
Definition: RegularSpatialGrid.hpp:383
RegularSpatialGrid(const CoordinatesValueType &s)
Constructs an empty grid with isotropic step size s on all three axes.
Definition: RegularSpatialGrid.hpp:194
RegularSpatialGrid & operator+=(const GridExpression< E > &e)
Adds the grid expression e cell-wise to the underlying grid data.
Definition: RegularSpatialGrid.hpp:701
friend void swap(RegularSpatialGrid &usg1, RegularSpatialGrid &usg2)
ADL-enabled free-function form of swap().
Definition: RegularSpatialGrid.hpp:804
GD::SizeType SizeType
The unsigned size type used by the grid data container.
Definition: RegularSpatialGrid.hpp:149
SizeType getSize3() const
Returns the size of the grid along the third dimension.
Definition: RegularSpatialGrid.hpp:311
SizeType getSize1() const
Returns the size of the grid along the first dimension.
Definition: RegularSpatialGrid.hpp:293
Reference operator()(SizeType i, SizeType j, SizeType k)
Returns a mutable reference to the cell at the (i, j, k) position.
Definition: RegularSpatialGrid.hpp:263
CoordinatesValueType getXStepSize() const
Returns the per-cell step size along the X axis.
Definition: RegularSpatialGrid.hpp:356
RegularSpatialGrid & operator-=(const GridExpression< E > &e)
Subtracts the grid expression e cell-wise from the underlying grid data.
Definition: RegularSpatialGrid.hpp:714
RegularSpatialGrid(RegularSpatialGrid &&usg)
Move-constructs the grid by moving usg.
Definition: RegularSpatialGrid.hpp:227
const CoordinatesTransformType & getCoordinatesTransform() const
Returns the coordinate transformation mapping cell-index coordinates to world coordinates.
Definition: RegularSpatialGrid.hpp:626
SizeType getSize2() const
Returns the size of the grid along the second dimension.
Definition: RegularSpatialGrid.hpp:302
CoordinatesValueType getYStepSize() const
Returns the per-cell step size along the Y axis.
Definition: RegularSpatialGrid.hpp:365
CoordinatesValueType getXExtent() const
Returns the spatial extent of the grid along the X axis ( for non-empty grids).
Definition: RegularSpatialGrid.hpp:410
void getLocalCoordinates(SSizeType i, SSizeType j, SSizeType k, V &coords) const
Writes the local-space 3D position of the cell at (i, j, k) into coords.
Definition: RegularSpatialGrid.hpp:487
void getContainingCell(const V1 &pos, V2 &indices) const
Writes the (i, j, k) cell indices of the cell containing the world-space point pos into indices.
Definition: RegularSpatialGrid.hpp:567
SelfType ClosureType
Closure type used when this grid appears inside another expression.
Definition: RegularSpatialGrid.hpp:155
RegularSpatialGrid & assign(const GridExpression< E > &e)
Assigns the grid expression e to the underlying grid data without intermediate temporary.
Definition: RegularSpatialGrid.hpp:753
GD GridDataType
The underlying grid data container type.
Definition: RegularSpatialGrid.hpp:137
ConstReference operator()(SizeType i) const
Returns a const reference to the cell at the linear index i.
Definition: RegularSpatialGrid.hpp:251
RegularSpatialGrid & operator=(const GridExpression< E > &e)
Assigns the grid expression e to the underlying grid data (the spatial parameters are left unchanged)...
Definition: RegularSpatialGrid.hpp:688
RegularSpatialGrid & plusAssign(const GridExpression< E > &e)
Adds the grid expression e to the underlying grid data without intermediate temporary.
Definition: RegularSpatialGrid.hpp:766
const GridDataType & getData() const
Returns a const reference to the underlying grid data container.
Definition: RegularSpatialGrid.hpp:608
RegularSpatialGrid(const GridDataType &data, const CoordinatesValueType &s)
Constructs the grid with isotropic step size s and the supplied grid data.
Definition: RegularSpatialGrid.hpp:207
void resize(SizeType m, SizeType n, SizeType o, bool preserve=true, const ValueType &v=ValueType())
Resizes the grid to cells.
Definition: RegularSpatialGrid.hpp:826
bool containsLocalPoint(const V &pos) const
Tells whether the local-space point pos lies within the grid bounds.
Definition: RegularSpatialGrid.hpp:536
C CoordinatesValueType
The coordinate (real) value type used in the world frame.
Definition: RegularSpatialGrid.hpp:135
CoordinatesValueType getZExtent() const
Returns the spatial extent of the grid along the Z axis.
Definition: RegularSpatialGrid.hpp:428
void getCoordinates(SizeType i, V &coords) const
Writes the world-space 3D position of the cell with linear index i into coords.
Definition: RegularSpatialGrid.hpp:440
GridDataType & getData()
Returns a mutable reference to the underlying grid data container.
Definition: RegularSpatialGrid.hpp:617
void getLocalContainingCell(const V1 &pos, V2 &indices) const
Writes the (i, j, k) cell indices of the cell containing the local-space point pos into indices.
Definition: RegularSpatialGrid.hpp:584
void getCoordinates(SSizeType i, SSizeType j, SSizeType k, V &coords) const
Writes the world-space 3D position of the cell at (i, j, k) into coords.
Definition: RegularSpatialGrid.hpp:459
Reference operator()(SizeType i)
Returns a mutable reference to the cell at the linear index i.
Definition: RegularSpatialGrid.hpp:241
SizeType getMaxSize() const
Returns the maximum total number of cells the grid can hold.
Definition: RegularSpatialGrid.hpp:320
virtual ~RegularSpatialGrid()
Virtual destructor.
Definition: RegularSpatialGrid.hpp:234
void getLocalCoordinates(const V1 &world_coords, V2 &local_coords) const
Transforms the world-space point world_coords into the grid's local coordinate frame and stores the r...
Definition: RegularSpatialGrid.hpp:502
void swap(RegularSpatialGrid &usg)
Swaps the contents of this grid with those of usg.
Definition: RegularSpatialGrid.hpp:789
constexpr unsigned int V2
Specifies the PDB format version V2.
Definition: PDBFormatVersion.hpp:54
constexpr unsigned int R
Specifies that the atom has R configuration.
Definition: AtomConfiguration.hpp:58
constexpr unsigned int M
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
Unbounded dense regular grid storing floating point values of type double.
Definition: RegularSpatialGrid.hpp:943
Matrix1VectorBinaryTraits< E1, E2, MatrixVectorProduct< E1, E2 > >::ResultType prod(const MatrixExpression< E1 > &e1, const VectorExpression< E2 > &e2)
Returns the matrix-vector product as a vector expression (named-function form of operator*).
Definition: MatrixExpression.hpp:1480
RegularSpatialGrid< float > FRegularSpatialGrid
Unbounded dense regular grid storing floating point values of type float.
Definition: RegularSpatialGrid.hpp:938
bool invert(const MatrixExpression< E > &e, MatrixContainer< C > &c)
Computes the inverse of the matrix expression e and stores it in c.
Definition: Matrix.hpp:3046
T interpolateTrilinear(const RegularSpatialGrid< T, C, GD, XF > &grid, const V &pos, bool local_pos)
Returns the trilinearly-interpolated value of grid at pos.
Definition: RegularSpatialGrid.hpp:867
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:54
The namespace of the Chemical Data Processing Library.
Reusable transformation traits used by Math::RegularSpatialGrid when the coordinate transform is a 4x...
Definition: RegularSpatialGrid.hpp:53
static bool invert(const MatrixType &mtx, M &inv_mtx)
Computes inv_mtx as the inverse of mtx.
Definition: RegularSpatialGrid.hpp:72
static void init(MatrixType &mtx)
Initializes mtx to the 4x4 identity matrix.
Definition: RegularSpatialGrid.hpp:59
static void transform(const MatrixType &mtx, const V &v, R &r)
Computes r as mtx * v.
Definition: RegularSpatialGrid.hpp:86
Primary traits template for grid-coordinate transformations of type T (left unspecialized; specialize...
Definition: RegularSpatialGrid.hpp:97