Itasca C++ Interface
dim.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "base/src/base.h"
4 namespace itasca {
5  class Accumulator3;
6  class Accumulator2;
7  class Accumulator;
8 }
9 
25 #ifndef DIM
26 # error DIM must be defined as 2 or 3 to compile this module.
27 #endif
28 
29 #if DIM==2
31  template <class T>
32  class Vector : public Vector2<T> {
33  public:
35  Vector() { }
37  Vector(const Vector<T> &v) : Vector2<T>(v) { }
39  Vector(const Vector2<T> &v) : Vector2<T>(v) { }
41  explicit Vector(const T &t) : Vector2<T>(t) { }
42  };
44  template <class T>
45  class AVector : public AVector2<T> {
46  public:
48  AVector() { }
50  AVector(const AVector &av) : AVector2<T>(av) { }
52  AVector(const AVector2<T> &av) : AVector2<T>(av) { }
53  };
55  template <class T>
56  class Extent : public Extent2<T> {
57  public:
59  Extent() { }
61  Extent(const Vector<T> &v11,const Vector<T> &v22) : Extent2<T>(v11,v22) { }
63  Extent(const Extent &r) : Extent2<T>(r) { }
64  Extent(const Extent2<T> &r) : Extent2<T>(r) { }
65  };
67  using DVect = DVect2;
68  using FVect = FVect2;
69  using IVect = IVect2;
70  using I64Vect = I64Vect2;
71  using UVect = UVect2;
72  using U64Vect = U64Vect2;
73  using DExtent = DExtent2;
74  using IExtent = IExtent2;
75  using DAVect = DAVect2;
76  using FAVect = FAVect2;
77  using Axes = Axes2D;
78  using CAxes = CAxes2D;
79  using Orientation = Orientation2;
80  using Quat = Quat2;
81  using VAccum = itasca::Accumulator2;
82  using AVAccum = itasca::Accumulator;
83  inline DMatrix<2,2> toMatrixDIM(const SymTensor &s) { return toMatrix2(s); }
84 
85 # ifndef TWOD
86 # define TWOD
87 # endif
88 # define DIMSTR "2d"
89 # define CDIMSTR "2D"
90  static constexpr const char *dimstr = "2d";
91  static constexpr const char *cdimstr = "2D";
92 # undef itascaxd
93 # define itascaxd itasca2d
94 # define DIMRET(x,y) x
95  template <class T> inline const Vector2<T> & toVect(const Vector2<T> &in) { return toVect2(in); }
96  template <class T> inline Vector<T> toVect(const Vector3<T> &in) { return toVect2(in); }
97  template <class T> inline Vector<T> toVect(const AVector2<T> &) { return Vector2<T>(0); }
98  template <class T> inline AVector<T> toAVect(const AVector2<T> &in) { return in; }
99  template <class T> inline AVector<T> toAVect(const AVector3<T> &in) { return AVector2<T>(in.z()); }
100  template <class T> inline AVector<T> toAVect(const Vector2<T> &) { return AVector2<T>(0.0); }
101  template <class T> inline AVector<T> toAVect(const Vector3<T> &in) { return AVector2<T>(in.z()); }
102  template <class T> inline const Extent<T> & toExtent(const Extent2<T> &t) { return t; }
103  template <class T> inline Extent<T> toExtent(const Extent3<T> &t) { return Extent2<T>(t.x1(),t.x2(),t.y1(),t.y2()); }
104  template <class T> inline IVect toIVect(const Vector2<T> &in) { IVect iv(to<int32>(in.x()),to<int32>(in.y())); return iv; }
105  template <class T> inline FVect toFVect(const Vector2<T> &in) { FVect fv(to<float>(in.x()),to<float>(in.y())); return fv; }
106  template <class T> inline DVect toDVect(const Vector2<T> &in) { DVect dv(to<double>(in.x()),to<double>(in.y())); return dv; }
107  template <class T> inline DVect toDVect(const Vector3<T> &in) { DVect dv(to<double>(in.x()),to<double>(in.y())); return dv; }
108  template <class T,class U> inline constexpr const T &dimval(const T &val2,const U &) { return val2; }
109  static const unsigned int totdof = 3;
110 #else // DIM==3
112  template <class T>
113  class Vector : public Vector3<T> {
114  public:
116  Vector() { }
118  Vector(const Vector<T> &v) : Vector3<T>(v) { }
120  Vector(const Vector3<T> &v) : Vector3<T>(v) { }
122  Vector(const T &x,const T &y,const T &z) : Vector3<T>(x,y,z) { }
124  explicit Vector(const T &t) : Vector3<T>(t) { }
125  };
127  template <class T>
128  class AVector : public AVector3<T> {
129  public:
131  AVector() { }
133  AVector(const AVector &av) : AVector3<T>(av) { }
135  AVector(const AVector3<T> &av) : AVector3<T>(av) { }
136  };
138  template <class T>
139  class Extent : public Extent3<T> {
140  public:
142  Extent() { }
144  Extent(const Vector<T> &v11,const Vector<T> &v22) : Extent3<T>(v11,v22) { }
146  Extent(const Extent &r) : Extent3<T>(r) { }
148  Extent(const Extent3<T> &r) : Extent3<T>(r) { }
149  };
150  using DVect = DVect3;
151  using FVect = FVect3;
152  using IVect = IVect3;
153  using I64Vect = I64Vect3;
154  using UVect = UVect3;
155  using U64Vect = U64Vect3;
156  using DExtent = DExtent3;
157  using IExtent = IExtent3;
158  using DAVect = DAVect3;
159  using FAVect = FAVect3;
160  using Axes = Axes3D;
161  using CAxes = CAxes3D;
163  using Quat = Quat3;
164  using VAccum = itasca::Accumulator3;
165  using AVAccum = itasca::Accumulator3;
166  inline DMatrix<3,3> toMatrixDIM(const SymTensor &s) { return toMatrix(s); }
167 # ifndef THREED
168 # define THREED
169 # endif
170 # define DIMSTR "3d"
171 # define CDIMSTR "3D"
172  static constexpr const char *dimstr = "3d";
173  static constexpr const char *cdimstr = "3D";
174 # undef itascaxd
175 # define itascaxd itasca3d
176 # define DIMRET(x,y) y
177  template <class T> inline Vector3<T> toVect(const Vector2<T> &in) { return toVect3(in); }
178  template <class T> inline const Vector3<T> & toVect(const Vector3<T> &in) { return in; }
179  template <class T> inline Vector3<T> toVect(const AVector2<T> &in) { return Vector3<T>(0,0,in.z()); }
180  template <class T> inline AVector3<T> toAVect(const AVector2<T> &in) { return AVector3<T>(in); }
181  template <class T> inline const AVector3<T> &toAVect(const AVector3<T> &in) { return in; }
182  template <class T> inline AVector3<T> toAVect(const Vector2<T> &in) { return AVector3<T>(in.x(),in.y(),0.0); }
183  template <class T> inline AVector3<T> toAVect(const Vector3<T> &in) { return AVector3<T>(in.x(),in.y(),in.z()); }
184  template <class T> inline Extent<T> toExtent(const Extent2<T> &t) { return Extent3<T>(t.x1(),t.x2(),t.y1(),t.y2(),0,1); }
185  template <class T> inline Extent<T> toExtent(const Extent3<T> &t) { return t; }
186  template <class T> inline IVect toIVect(const Vector3<T> &in) { IVect iv(to<int32>(in.x()),to<int32>(in.y()),to<int32>(in.z())); return iv; }
187  template <class T> inline FVect toFVect(const Vector3<T> &in) { FVect fv(to<float>(in.x()),to<float>(in.y()),to<float>(in.z())); return fv; }
188  template <class T> inline DVect toDVect(const Vector3<T> &in) { DVect dv(to<double>(in.x()),to<double>(in.y()),to<double>(in.z())); return dv; }
189  template <class T,class U>
190  inline constexpr const U &dimval(const T &,const U &val3) { return val3; }
191  static const unsigned int totdof = 6;
192 #endif
193 
194 static constexpr uint32 dim = DIM;
195 static constexpr bool is2D = dimval(true,false);
196 static constexpr bool is3D = dimval(false,true);
197 static constexpr uint32 adof = dimval(1,3); // Number of angular DOF
198 static constexpr uint32 tdof = dimval(2,3); // Number of translational DOF
199 
201 // EoF
One stop include for all objects defined as part of base interface.
2D Angular vector class.
Definition: avect.h:43
const T & z() const
Member access - returns the z component of the 2D angular vector.
Definition: avect.h:70
3D Angular vector class.
Definition: avect.h:176
An AVector2 in 2D, an AVector3 in 3D.
Definition: dim.h:128
AVector()
Default constructor, no data initialization.
Definition: dim.h:131
AVector(const AVector3< T > &av)
Copy constructor.
Definition: dim.h:135
AVector(const AVector &av)
Copy constructor.
Definition: dim.h:133
Class for specifying a particular 2D cartesian axes system, and converting to and from it.
Definition: axes.h:21
Class for specifying a particular 3D cartesian axes system, and converting to and from it.
Definition: axes.h:121
Class for specifying a particular 2D cartesian axes system, and converting to and from it.
Definition: caxes.h:25
Class for specifying a particular 3D cartesian axes system, and converting to and from it.
Definition: caxes.h:103
DMatrix is a Matrix that defaults to type double...
Definition: matrix.h:741
2D cartesian region in space.
Definition: extent2.h:12
const T & y1() const
Returns the lower y-bound.
Definition: extent2.h:37
const T & x1() const
Returns the lower x-bound.
Definition: extent2.h:33
const T & y2() const
Returns the upper y-bound.
Definition: extent2.h:39
const T & x2() const
Returns the upper x-bound.
Definition: extent2.h:35
A Class representing a cartesian extent in 3D.
Definition: extent3.h:16
const T & x1() const
Returns the lower bound of the extent in the x-direction.
Definition: extent3.h:42
const T & y2() const
Returns the upper bound of the extent in the y-direction.
Definition: extent3.h:48
const T & x2() const
Returns the upper bound of the extent in the x-direction.
Definition: extent3.h:44
const T & y1() const
Returns the lower bound of the extent in the y-direction.
Definition: extent3.h:46
A Extent2<T> in 2D, and a Extent3<T> in 2D.
Definition: dim.h:139
Extent(const Vector< T > &v11, const Vector< T > &v22)
Explicit constructor, given the lower and upper bound as two Vector.
Definition: dim.h:144
Extent(const Extent3< T > &r)
Copy constructor.
Definition: dim.h:148
Extent(const Extent &r)
Copy constructor.
Definition: dim.h:146
Extent()
Default constructor, not data initialization.
Definition: dim.h:142
Class for storing an "orientation", or a direction in 2D or 3D space.
Definition: orientation.h:50
Class for storing an "orientation", or a direction in 2D or 3D space.
Definition: orientation.h:99
2D quaternion-like utility class. In this case only the angle (in radians) is stored as opposed to th...
Definition: quat.h:20
3D quaternion utility class.
Definition: quat.h:109
A Vector2 in 2D, a Vector3 in 3D.
Definition: dim.h:113
Vector()
Default constructor, no data initialization.
Definition: dim.h:116
Vector(const Vector3< T > &v)
Copy constructor.
Definition: dim.h:120
Vector(const T &t)
Single component constructor.
Definition: dim.h:124
Vector(const T &x, const T &y, const T &z)
From three.
Definition: dim.h:122
Vector(const Vector< T > &v)
Copy constructor.
Definition: dim.h:118
BASE_EXPORT DMatrix< 2, 2 > toMatrix2(const SymTensor &s)
Definition: matrix.cpp:16
constexpr VMatrix< T, 2 > toMatrix(const Vector2< T > &v)
Definition: matrix.h:938
Vector2< T > toVect2(const AVector2< T > &)
Definition: avect.h:247
Vector3< T > toVect3(const AVector2< T > &v)
Definition: avect.h:250
DVect toDVect(const Vector3< T > &in)
Converts a Vector3<T> to a DVect.
Definition: dim.h:188
constexpr const U & dimval(const T &, const U &val3)
Returns the first argument in a 2D compile, and the second in a 3D compile.
Definition: dim.h:190
IVect toIVect(const Vector3< T > &in)
Converts a Vector3<T> to an IVect.
Definition: dim.h:186
FAVect3 FAVect
Angular vector of floats, either 2D or 3D.
Definition: dim.h:159
DExtent3 DExtent
A DExtent2 in 2D, a DExtent3 in 3D.
Definition: dim.h:156
FVect toFVect(const Vector3< T > &in)
Converts a Vector3<T> to a FVect.
Definition: dim.h:187
FVect3 FVect
Vector of floats, either 2D or 3D.
Definition: dim.h:151
AVector3< T > toAVect(const AVector2< T > &in)
Converts an AVector2 to an AVector.
Definition: dim.h:180
IExtent3 IExtent
An IExtent2 in 2D, an IExtent3 in 3D.
Definition: dim.h:157
DVect3 DVect
Vector of doubles, either 2D or 3D.
Definition: dim.h:150
Vector3< T > toVect(const Vector2< T > &in)
Converts a Vector2 to a Vector.
Definition: dim.h:177
UVect3 UVect
Vector of uints, either 2D or 3D.
Definition: dim.h:154
itasca::Accumulator3 AVAccum
3D angular accumulator
Definition: dim.h:165
DAVect3 DAVect
Angular vector of doubles, either 2D or 3D.
Definition: dim.h:158
itasca::Accumulator3 VAccum
3D vector accumulator
Definition: dim.h:164
Extent< T > toExtent(const Extent2< T > &t)
Converts Extent2 to an Extent.
Definition: dim.h:184
IVect3 IVect
Vector of ints, either 2D or 3D.
Definition: dim.h:152
namespace Itasca
Definition: basememory.cpp:10