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 
124  template <typename T, typename C = typename TypeTraits<T>::RealType, typename GD = Grid<T>, typename XF = CMatrix<C, 4, 4> >
125  class RegularSpatialGrid : public GridExpression<RegularSpatialGrid<T, C, GD, XF> >
126  {
127 
129 
130  public:
134  typedef T ValueType;
135 
140 
144  typedef GD GridDataType;
145 
150 
154  typedef typename CoordinatesTransformType::MatrixTemporaryType InvCoordinatesTransformType;
155 
159  typedef typename std::conditional<std::is_const<GD>::value,
160  typename GD::ConstReference,
161  typename GD::Reference>::type Reference;
162 
166  typedef typename GD::ConstReference ConstReference;
167 
171  typedef typename GD::SizeType SizeType;
172 
176  typedef std::ptrdiff_t SSizeType;
177 
181  typedef typename GD::DifferenceType DifferenceType;
182 
187 
191  typedef const SelfType ConstClosureType;
192 
196  typedef std::shared_ptr<SelfType> SharedPointer;
197 
205  xStep(xs), yStep(ys), zStep(zs)
206  {
207 
210  }
211 
220  data(data), xStep(xs), yStep(ys), zStep(zs)
221  {
222 
225  }
226 
232  xStep(s), yStep(s), zStep(s)
233  {
234 
237  }
238 
245  data(data), xStep(s), yStep(s), zStep(s)
246  {
247 
250  }
251 
257  data(usg.data), xStep(usg.xStep), yStep(usg.yStep), zStep(usg.zStep),
258  xform(usg.xform), invXform(usg.invXform) {}
259 
265  data(std::move(usg.data)), xStep(usg.xStep), yStep(usg.yStep), zStep(usg.zStep),
266  xform(usg.xform), invXform(usg.invXform) {}
267 
271  virtual ~RegularSpatialGrid() {}
272 
279  {
280  return data(i);
281  }
282 
289  {
290  return data(i);
291  }
292 
301  {
302  return data(i, j, k);
303  }
304 
313  {
314  return data(i, j, k);
315  }
316 
322  {
323  return data.getSize();
324  }
325 
331  {
332  return data.getSize1();
333  }
334 
340  {
341  return data.getSize2();
342  }
343 
349  {
350  return data.getSize3();
351  }
352 
358  {
359  return data.getMaxSize();
360  }
361 
367  {
368  return data.getMaxSize1();
369  }
370 
376  {
377  return data.getMaxSize2();
378  }
379 
385  {
386  return data.getMaxSize3();
387  }
388 
394  {
395  return xStep;
396  }
397 
403  {
404  return yStep;
405  }
406 
412  {
413  return zStep;
414  }
415 
421  {
422  xStep = xs;
423  }
424 
430  {
431  yStep = ys;
432  }
433 
439  {
440  zStep = zs;
441  }
442 
448  {
449  return ((data.getSize1() <= 1 ? SizeType(0) : (data.getSize1() - 1)) * xStep);
450  }
451 
457  {
458  return ((data.getSize2() <= 1 ? SizeType(0) : (data.getSize2() - 1)) * yStep);
459  }
460 
466  {
467  return ((data.getSize3() <= 1 ? SizeType(0) : (data.getSize3() - 1)) * zStep);
468  }
469 
476  template <typename V>
477  void getCoordinates(SizeType i, V& coords) const
478  {
479  SizeType z = i / (getSize1() * getSize2());
480  SizeType xy = i % (getSize1() * getSize2());
481  SizeType y = xy / getSize1();
482  SizeType x = xy % getSize1();
483 
484  getCoordinates(x, y, z, coords);
485  }
486 
495  template <typename V>
496  void getCoordinates(SSizeType i, SSizeType j, SSizeType k, V& coords) const
497  {
499 
500  getLocalCoordinates(i, j, k, local_coords);
501  local_coords(3) = CoordinatesValueType(1);
502 
505 
506  coords[0] = world_coords(0);
507  coords[1] = world_coords(1);
508  coords[2] = world_coords(2);
509  }
510 
519  template <typename V>
520  void getLocalCoordinates(SSizeType i, SSizeType j, SSizeType k, V& coords) const
521  {
522  coords[0] = i * xStep - getXExtent() * CoordinatesValueType(0.5);
523  coords[1] = j * yStep - getYExtent() * CoordinatesValueType(0.5);
524  coords[2] = k * zStep - getZExtent() * CoordinatesValueType(0.5);
525  }
526 
535  template <typename V1, typename V2>
536  void getLocalCoordinates(const V1& world_coords, V2& local_coords) const
537  {
538  CVector<CoordinatesValueType, 4> tmp_local_coords;
539 
540  transformToLocalCoordinates(world_coords, tmp_local_coords);
541 
542  local_coords[0] = tmp_local_coords[0];
543  local_coords[1] = tmp_local_coords[1];
544  local_coords[2] = tmp_local_coords[2];
545  }
546 
553  template <typename V>
554  bool containsPoint(const V& pos) const
555  {
557 
558  transformToLocalCoordinates(pos, local_coords);
559 
560  return containsLocalPoint(local_coords);
561  }
562 
569  template <typename V>
570  bool containsLocalPoint(const V& pos) const
571  {
572  if (CoordinatesValueType(pos[0]) >= (getXExtent() * CoordinatesValueType(0.5)))
573  return false;
574 
575  if (CoordinatesValueType(pos[1]) >= (getYExtent() * CoordinatesValueType(0.5)))
576  return false;
577 
578  if (CoordinatesValueType(pos[2]) >= (getZExtent() * CoordinatesValueType(0.5)))
579  return false;
580 
581  if (CoordinatesValueType(pos[0]) < (-getXExtent() * CoordinatesValueType(0.5)))
582  return false;
583 
584  if (CoordinatesValueType(pos[1]) < (-getYExtent() * CoordinatesValueType(0.5)))
585  return false;
586 
587  if (CoordinatesValueType(pos[2]) < (-getZExtent() * CoordinatesValueType(0.5)))
588  return false;
589 
590  return true;
591  }
592 
600  template <typename V1, typename V2>
601  void getContainingCell(const V1& pos, V2& indices) const
602  {
604 
605  transformToLocalCoordinates(pos, local_coords);
606 
607  getLocalContainingCell(local_coords, indices);
608  }
609 
617  template <typename V1, typename V2>
618  void getLocalContainingCell(const V1& pos, V2& indices) const
619  {
623 
624  indices[0] = SSizeType(std::floor(x / xStep));
625  indices[1] = SSizeType(std::floor(y / yStep));
626  indices[2] = SSizeType(std::floor(z / zStep));
627  }
628 
633  bool isEmpty() const
634  {
635  return data.isEmpty();
636  }
637 
642  const GridDataType& getData() const
643  {
644  return data;
645  }
646 
652  {
653  return data;
654  }
655 
661  {
662  return xform;
663  }
664 
671  template <typename T1>
672  void setCoordinatesTransform(const T1& xform)
673  {
674  this->xform = xform;
675 #ifdef CDPL_MATH_CHECKS_DISABLE
677 #else
679  "Inversion of transformation failed", Base::CalculationFailed);
680 #endif // CDPL_MATH_CHECKS_DISABLE
681  }
682 
689  {
690  data = usg.data;
691  xform = usg.xform;
692  invXform = usg.invXform;
693  xStep = usg.xStep;
694  yStep = usg.yStep;
695  zStep = usg.zStep;
696  return *this;
697  }
698 
705  {
706  data = std::move(usg.data);
707  xform = usg.xform;
708  invXform = usg.invXform;
709  xStep = usg.xStep;
710  yStep = usg.yStep;
711  zStep = usg.zStep;
712  return *this;
713  }
714 
721  template <typename E>
723  {
724  data.operator=(e);
725  return *this;
726  }
727 
734  template <typename E>
736  {
737  data.operator+=(e);
738  return *this;
739  }
740 
747  template <typename E>
749  {
750  data.operator-=(e);
751  return *this;
752  }
753 
760  template <typename T1>
761  typename std::enable_if<IsScalar<T>::value, RegularSpatialGrid>::type& operator*=(const T1& t)
762  {
763  data.operator*=(t);
764  return *this;
765  }
766 
773  template <typename T1>
774  typename std::enable_if<IsScalar<T>::value, RegularSpatialGrid>::type& operator/=(const T1& t)
775  {
776  data.operator/=(t);
777  return *this;
778  }
779 
786  template <typename E>
788  {
789  data.assign(e);
790  return *this;
791  }
792 
799  template <typename E>
801  {
802  data.plusAssign(e);
803  return *this;
804  }
805 
812  template <typename E>
814  {
815  data.minusAssign(e);
816  return *this;
817  }
818 
824  {
825  data.swap(usg.data);
826  xform.swap(usg.xform);
827  invXform.swap(usg.invXform);
828  std::swap(xStep, usg.xStep);
829  std::swap(yStep, usg.yStep);
830  std::swap(zStep, usg.zStep);
831  }
832 
838  friend void swap(RegularSpatialGrid& usg1, RegularSpatialGrid& usg2)
839  {
840  usg1.swap(usg2);
841  }
842 
847  void clear(const ValueType& v = ValueType())
848  {
849  data.clear(v);
850  }
851 
860  void resize(SizeType m, SizeType n, SizeType o, bool preserve = true, const ValueType& v = ValueType())
861  {
862  data.resize(m, n, o, preserve, v);
863  }
864 
865  private:
866  template <typename V1, typename V2>
867  void transformToLocalCoordinates(const V1& coords, V2& local_coords) const
868  {
870 
871  world_coords(0) = coords[0];
872  world_coords(1) = coords[1];
873  world_coords(2) = coords[2];
874  world_coords(3) = CoordinatesValueType(1);
875 
877  }
878 
879  GridDataType data;
880  CoordinatesValueType xStep;
881  CoordinatesValueType yStep;
882  CoordinatesValueType zStep;
885  };
886 
899  template <typename T, typename C, typename GD, typename XF, typename V>
900  T interpolateTrilinear(const RegularSpatialGrid<T, C, GD, XF>& grid, const V& pos, bool local_pos)
901  {
902  typedef RegularSpatialGrid<T, C, GD, XF> GridType;
903 
904  typedef typename GridType::CoordinatesValueType CoordinatesValueType;
905  typedef typename GridType::SSizeType SSizeType;
906  typedef typename GridType::ValueType ValueType;
907 
908  if (grid.isEmpty())
909  return CoordinatesValueType();
910 
911  CoordinatesValueType loc_pos[3];
912 
913  if (local_pos) {
914  loc_pos[0] = pos[0];
915  loc_pos[1] = pos[1];
916  loc_pos[2] = pos[2];
917 
918  } else
919  grid.getLocalCoordinates(pos, loc_pos);
920 
921  SSizeType inds[3];
922 
923  grid.getLocalContainingCell(loc_pos, inds);
924 
925  CoordinatesValueType xyz0[3];
926 
927  grid.getLocalCoordinates(inds[0], inds[1], inds[2], xyz0);
928 
929  SSizeType inds_p1[3];
930 
931  inds_p1[0] = inds[0] + 1;
932  inds_p1[1] = inds[1] + 1;
933  inds_p1[2] = inds[2] + 1;
934 
935  inds[0] = std::max(SSizeType(0), inds[0]);
936  inds[1] = std::max(SSizeType(0), inds[1]);
937  inds[2] = std::max(SSizeType(0), inds[2]);
938 
939  inds[0] = std::min(SSizeType(grid.getSize1() - 1), inds[0]);
940  inds[1] = std::min(SSizeType(grid.getSize2() - 1), inds[1]);
941  inds[2] = std::min(SSizeType(grid.getSize3() - 1), inds[2]);
942 
943  inds_p1[0] = std::max(SSizeType(0), inds_p1[0]);
944  inds_p1[1] = std::max(SSizeType(0), inds_p1[1]);
945  inds_p1[2] = std::max(SSizeType(0), inds_p1[2]);
946 
947  inds_p1[0] = std::min(SSizeType(grid.getSize1() - 1), inds_p1[0]);
948  inds_p1[1] = std::min(SSizeType(grid.getSize2() - 1), inds_p1[1]);
949  inds_p1[2] = std::min(SSizeType(grid.getSize3() - 1), inds_p1[2]);
950 
951  CoordinatesValueType xd = (loc_pos[0] - xyz0[0]) / grid.getXStepSize();
952  CoordinatesValueType yd = (loc_pos[1] - xyz0[1]) / grid.getYStepSize();
953  CoordinatesValueType zd = (loc_pos[2] - xyz0[2]) / grid.getZStepSize();
954 
955  ValueType c00 = grid(inds[0], inds[1], inds[2]) * (1 - xd) + grid(inds_p1[0], inds[1], inds[2]) * xd;
956  ValueType c01 = grid(inds[0], inds[1], inds_p1[2]) * (1 - xd) + grid(inds_p1[0], inds[1], inds_p1[2]) * xd;
957  ValueType c10 = grid(inds[0], inds_p1[1], inds[2]) * (1 - xd) + grid(inds_p1[0], inds_p1[1], inds[2]) * xd;
958  ValueType c11 = grid(inds[0], inds_p1[1], inds_p1[2]) * (1 - xd) + grid(inds_p1[0], inds_p1[1], inds_p1[2]) * xd;
959 
960  ValueType c0 = c00 * (1 - yd) + c10 * yd;
961  ValueType c1 = c01 * (1 - yd) + c11 * yd;
962 
963  ValueType c = c0 * (1 - zd) + c1 * zd;
964 
965  return c;
966  }
967 
972 
977  } // namespace Math
978 } // namespace CDPL
979 
980 #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 dimension M×N backed by a stack-allocated array.
Definition: Matrix.hpp:1601
Fixed-size dense matrix of dimension M×N backed by a stack-allocated array.
Definition: Matrix.hpp:2180
Fixed-size vector of dimension N backed by a C-array (no dynamic allocation).
Definition: Vector.hpp:2047
CRTP base class of all grid expression types.
Definition: Expression.hpp:188
Dynamically-sized dense 3D grid with configurable underlying storage.
Definition: Math/Grid.hpp:401
Constant identity-matrix expression (1 on the diagonal, 0 elsewhere).
Definition: Matrix.hpp:3082
3D grid data structure combining a grid data store with a coordinate-system transformation that maps ...
Definition: RegularSpatialGrid.hpp:126
GD::ConstReference ConstReference
Constant grid cell reference type.
Definition: RegularSpatialGrid.hpp:166
SizeType getMaxSize3() const
Returns the maximum number of cells along the z-axis.
Definition: RegularSpatialGrid.hpp:384
bool containsPoint(const V &pos) const
Tells whether the world space point pos lies within the grid bounds.
Definition: RegularSpatialGrid.hpp:554
CoordinatesValueType getZStepSize() const
Returns the per-cell step size along the z-axis.
Definition: RegularSpatialGrid.hpp:411
XF CoordinatesTransformType
The coordinate transformation type mapping grid space coordinates to world coordinates.
Definition: RegularSpatialGrid.hpp:149
RegularSpatialGrid & operator=(const RegularSpatialGrid &usg)
Copy-assigns the state of usg to this grid.
Definition: RegularSpatialGrid.hpp:688
SizeType getMaxSize2() const
Returns the maximum number of cells along the y-axis.
Definition: RegularSpatialGrid.hpp:375
void setCoordinatesTransform(const T1 &xform)
Sets the grid space to world coordinates transformation to xform and caches its calculated inverse.
Definition: RegularSpatialGrid.hpp:672
void setYStepSize(const CoordinatesValueType &ys)
Sets the per-cell step size along the y-axis to ys.
Definition: RegularSpatialGrid.hpp:429
bool isEmpty() const
Tells whether the grid is empty (zero cells along any dimension).
Definition: RegularSpatialGrid.hpp:633
RegularSpatialGrid(const RegularSpatialGrid &usg)
Constructs a copy of the RegularSpatialGrid instance usg.
Definition: RegularSpatialGrid.hpp:256
void setZStepSize(const CoordinatesValueType &zs)
Sets the per-cell step size along the z-axis to zs.
Definition: RegularSpatialGrid.hpp:438
RegularSpatialGrid & operator=(RegularSpatialGrid &&usg)
Move-assigns the state of usg to this grid.
Definition: RegularSpatialGrid.hpp:704
std::enable_if< IsScalar< T >::value, RegularSpatialGrid >::type & operator*=(const T1 &t)
Multiplies every cell value by the scalar t.
Definition: RegularSpatialGrid.hpp:761
RegularSpatialGrid(const GridDataType &data, const CoordinatesValueType &xs, const CoordinatesValueType &ys, const CoordinatesValueType &zs)
Constructs the grid with the specified anisotropic per-axis step sizes initialized to the supplied gr...
Definition: RegularSpatialGrid.hpp:219
T ValueType
The grid cell value type.
Definition: RegularSpatialGrid.hpp:134
std::conditional< std::is_const< GD >::value, typename GD::ConstReference, typename GD::Reference >::type Reference
Mutable grid cell reference type (degrades to ConstReference when the data container is const).
Definition: RegularSpatialGrid.hpp:161
RegularSpatialGrid(const CoordinatesValueType &xs, const CoordinatesValueType &ys, const CoordinatesValueType &zs)
Constructs an empty grid with the specified anisotropic per-axis step sizes.
Definition: RegularSpatialGrid.hpp:204
const SelfType ConstClosureType
Constant closure type used when this grid appears inside another expression.
Definition: RegularSpatialGrid.hpp:191
CoordinatesTransformType::MatrixTemporaryType InvCoordinatesTransformType
The inverse coordinate transformation type mapping world coordinates to grid space coordinates.
Definition: RegularSpatialGrid.hpp:154
ConstReference operator()(SizeType i, SizeType j, SizeType k) const
Returns a const reference to the value of cell at (i, j, k).
Definition: RegularSpatialGrid.hpp:312
RegularSpatialGrid & minusAssign(const GridExpression< E > &e)
Subtracts the grid expression e from the underlying grid data without intermediate temporary.
Definition: RegularSpatialGrid.hpp:813
std::shared_ptr< SelfType > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated RegularSpatialGrid instances.
Definition: RegularSpatialGrid.hpp:196
std::enable_if< IsScalar< T >::value, RegularSpatialGrid >::type & operator/=(const T1 &t)
Divides every cell value by the scalar t.
Definition: RegularSpatialGrid.hpp:774
CoordinatesValueType getYExtent() const
Returns the spatial extent of the grid along the y-axis.
Definition: RegularSpatialGrid.hpp:456
GD::DifferenceType DifferenceType
The signed difference type used by the grid data container.
Definition: RegularSpatialGrid.hpp:181
void clear(const ValueType &v=ValueType())
Sets every cell of the grid to the value v.
Definition: RegularSpatialGrid.hpp:847
SizeType getSize() const
Returns the total number of cells of the grid.
Definition: RegularSpatialGrid.hpp:321
std::ptrdiff_t SSizeType
A signed size type used for offset arithmetic.
Definition: RegularSpatialGrid.hpp:176
SizeType getMaxSize1() const
Returns the maximum number of cells along the x-axis.
Definition: RegularSpatialGrid.hpp:366
void setXStepSize(const CoordinatesValueType &xs)
Sets the per-cell step size along the x-axis to xs.
Definition: RegularSpatialGrid.hpp:420
RegularSpatialGrid(const CoordinatesValueType &s)
Constructs an empty grid with the specified isotropic step size s on all three axes.
Definition: RegularSpatialGrid.hpp:231
RegularSpatialGrid & operator+=(const GridExpression< E > &e)
Adds the grid expression e cell-wise to the underlying grid data.
Definition: RegularSpatialGrid.hpp:735
friend void swap(RegularSpatialGrid &usg1, RegularSpatialGrid &usg2)
ADL-enabled free-function form of swap().
Definition: RegularSpatialGrid.hpp:838
GD::SizeType SizeType
The unsigned size type used by the grid data container.
Definition: RegularSpatialGrid.hpp:171
SizeType getSize3() const
Returns the number of cells along the z-axis.
Definition: RegularSpatialGrid.hpp:348
SizeType getSize1() const
Returns the number of cells along the x-axis.
Definition: RegularSpatialGrid.hpp:330
Reference operator()(SizeType i, SizeType j, SizeType k)
Returns a mutable reference to the value of cell at (i, j, k).
Definition: RegularSpatialGrid.hpp:300
CoordinatesValueType getXStepSize() const
Returns the per-cell step size along the x-axis.
Definition: RegularSpatialGrid.hpp:393
RegularSpatialGrid & operator-=(const GridExpression< E > &e)
Subtracts the grid expression e cell-wise from the underlying grid data.
Definition: RegularSpatialGrid.hpp:748
RegularSpatialGrid(RegularSpatialGrid &&usg)
Move-constructs the grid by moving usg.
Definition: RegularSpatialGrid.hpp:264
const CoordinatesTransformType & getCoordinatesTransform() const
Returns the coordinate transformation mapping grid space to world coordinates.
Definition: RegularSpatialGrid.hpp:660
SizeType getSize2() const
Returns the number of cells along the y-axis.
Definition: RegularSpatialGrid.hpp:339
CoordinatesValueType getYStepSize() const
Returns the per-cell step size along the y-axis.
Definition: RegularSpatialGrid.hpp:402
CoordinatesValueType getXExtent() const
Returns the spatial extent of the grid along the x-axis.
Definition: RegularSpatialGrid.hpp:447
void getLocalCoordinates(SSizeType i, SSizeType j, SSizeType k, V &coords) const
Writes the grid space 3D position of the cell at (i, j, k) into coords.
Definition: RegularSpatialGrid.hpp:520
void getContainingCell(const V1 &pos, V2 &indices) const
Writes the (i, j, k) indices of the cell containing the world space point pos into indices.
Definition: RegularSpatialGrid.hpp:601
SelfType ClosureType
Closure type used when this grid appears inside another expression.
Definition: RegularSpatialGrid.hpp:186
RegularSpatialGrid & assign(const GridExpression< E > &e)
Assigns the grid expression e to the underlying grid data without intermediate temporary.
Definition: RegularSpatialGrid.hpp:787
GD GridDataType
The underlying grid data container type.
Definition: RegularSpatialGrid.hpp:144
ConstReference operator()(SizeType i) const
Returns a const reference to the value of the cell at the linear index i.
Definition: RegularSpatialGrid.hpp:288
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:722
RegularSpatialGrid & plusAssign(const GridExpression< E > &e)
Adds the grid expression e to the underlying grid data without intermediate temporary.
Definition: RegularSpatialGrid.hpp:800
const GridDataType & getData() const
Returns a const reference to the underlying grid data container.
Definition: RegularSpatialGrid.hpp:642
RegularSpatialGrid(const GridDataType &data, const CoordinatesValueType &s)
Constructs the grid with the isotropic step size s and the supplied grid data.
Definition: RegularSpatialGrid.hpp:244
void resize(SizeType m, SizeType n, SizeType o, bool preserve=true, const ValueType &v=ValueType())
Resizes the grid to m×n×o cells.
Definition: RegularSpatialGrid.hpp:860
bool containsLocalPoint(const V &pos) const
Tells whether the grid space point pos lies within the grid bounds.
Definition: RegularSpatialGrid.hpp:570
C CoordinatesValueType
The xyz-coordinates value type.
Definition: RegularSpatialGrid.hpp:139
CoordinatesValueType getZExtent() const
Returns the spatial extent of the grid along the z-axis.
Definition: RegularSpatialGrid.hpp:465
void getCoordinates(SizeType i, V &coords) const
Outputs the world space 3D position of the cell with linear index i into coords.
Definition: RegularSpatialGrid.hpp:477
GridDataType & getData()
Returns a mutable reference to the underlying grid data container.
Definition: RegularSpatialGrid.hpp:651
void getLocalContainingCell(const V1 &pos, V2 &indices) const
Writes the (i, j, k) indices of the cell containing the grid space point pos into indices.
Definition: RegularSpatialGrid.hpp:618
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:496
Reference operator()(SizeType i)
Returns a mutable reference to the cell at the linear index i.
Definition: RegularSpatialGrid.hpp:278
SizeType getMaxSize() const
Returns the maximum total number of cells the grid can hold.
Definition: RegularSpatialGrid.hpp:357
virtual ~RegularSpatialGrid()
Virtual destructor.
Definition: RegularSpatialGrid.hpp:271
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:536
void swap(RegularSpatialGrid &usg)
Swaps the data of this grid with those of usg.
Definition: RegularSpatialGrid.hpp:823
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 spatial grid storing floating-point values of type double.
Definition: RegularSpatialGrid.hpp:976
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:1731
RegularSpatialGrid< float > FRegularSpatialGrid
Unbounded dense regular spatial grid storing floating-point values of type float.
Definition: RegularSpatialGrid.hpp:971
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:3370
T interpolateTrilinear(const RegularSpatialGrid< T, C, GD, XF > &grid, const V &pos, bool local_pos)
Returns the trilinearly interpolated cell value of the regular spatial grid grid at the position pos.
Definition: RegularSpatialGrid.hpp:900
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 grid-coordinate transform is...
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 4×4 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).
Definition: RegularSpatialGrid.hpp:97