Itasca C++ Interface
Loading...
Searching...
No Matches
dim.h
Go to the documentation of this file.
1#pragma once
2
3#include "base/src/base.h"
4namespace 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
31template <class T>
32class Vector : public Vector2<T> {
33public:
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};
44template <class T>
45class AVector : public AVector2<T> {
46public:
48 AVector() { }
50 AVector(const AVector &av) : AVector2<T>(av) { }
52 AVector(const AVector2<T> &av) : AVector2<T>(av) { }
53};
55template <class T>
56class Extent : public Extent2<T> {
57public:
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};
67using DVect = DVect2;
68using FVect = FVect2;
69using IVect = IVect2;
70using I64Vect = I64Vect2;
71using UVect = UVect2;
72using U64Vect = U64Vect2;
73using DExtent = DExtent2;
74using IExtent = IExtent2;
75using DAVect = DAVect2;
76using FAVect = FAVect2;
77using Axes = Axes2D;
78using CAxes = CAxes2D;
80using Quat = Quat2;
81using VAccum = itasca::Accumulator2;
82using AVAccum = itasca::Accumulator;
83inline 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"
90static constexpr const char *dimstr = "2d";
91static constexpr const char *cdimstr = "2D";
92# undef itascaxd
93# define itascaxd itasca2d
94# define DIMRET(x,y) x
95template <class T> inline const Vector2<T> & toVect(const Vector2<T> &in) { return toVect2(in); }
96template <class T> inline Vector<T> toVect(const Vector3<T> &in) { return toVect2(in); }
97template <class T> inline Vector<T> toVect(const AVector2<T> &) { return Vector2<T>(0); }
98template <class T> inline AVector<T> toAVect(const AVector2<T> &in) { return in; }
99template <class T> inline AVector<T> toAVect(const AVector3<T> &in) { return AVector2<T>(in.z()); }
100template <class T> inline AVector<T> toAVect(const Vector2<T> &) { return AVector2<T>(0.0); }
101template <class T> inline AVector<T> toAVect(const Vector3<T> &in) { return AVector2<T>(in.z()); }
102template <class T> inline const Extent<T> & toExtent(const Extent2<T> &t) { return t; }
103template <class T> inline Extent<T> toExtent(const Extent3<T> &t) { return Extent2<T>(t.x1(),t.x2(),t.y1(),t.y2()); }
104template <class T> inline IVect toIVect(const Vector2<T> &in) { IVect iv(to<int32>(in.x()),to<int32>(in.y())); return iv; }
105template <class T> inline FVect toFVect(const Vector2<T> &in) { FVect fv(to<float>(in.x()),to<float>(in.y())); return fv; }
106template <class T> inline DVect toDVect(const Vector2<T> &in) { DVect dv(to<double>(in.x()),to<double>(in.y())); return dv; }
107template <class T> inline DVect toDVect(const Vector3<T> &in) { DVect dv(to<double>(in.x()),to<double>(in.y())); return dv; }
108template <class T,unsigned SX>
109Vector2<T> toVector(const VMatrix<T,SX> &m,unsigned start) { Vector2<T> ret(m(start),m(start+1)); return ret; }
110inline constexpr DMatrix<2,2> toMatrix(const SymTensor &s) { return toMatrix2(s); }
111inline DSymMatrix<2> toSymMatrix(const SymTensor &s) { return toSymMatrix2(s); }
112template <class T,class U> inline constexpr const T &dimval(const T &val2,const U &) { return val2; }
113static const unsigned int totdof = 3;
114#else // DIM==3
116template <class T>
117class Vector : public Vector3<T> {
118public:
120 Vector() { }
122 Vector(const Vector<T> &v) : Vector3<T>(v) { }
124 Vector(const Vector3<T> &v) : Vector3<T>(v) { }
126 Vector(const T &x,const T &y,const T &z) : Vector3<T>(x,y,z) { }
128 explicit Vector(const T &t) : Vector3<T>(t) { }
129};
131template <class T>
132class AVector : public AVector3<T> {
133public:
137 AVector(const AVector &av) : AVector3<T>(av) { }
139 AVector(const AVector3<T> &av) : AVector3<T>(av) { }
140};
142template <class T>
143class Extent : public Extent3<T> {
144public:
146 Extent() { }
148 Extent(const Vector<T> &v11,const Vector<T> &v22) : Extent3<T>(v11,v22) { }
150 Extent(const Extent &r) : Extent3<T>(r) { }
152 Extent(const Extent3<T> &r) : Extent3<T>(r) { }
153};
154using DVect = DVect3;
155using FVect = FVect3;
156using IVect = IVect3;
157using I64Vect = I64Vect3;
158using UVect = UVect3;
159using U64Vect = U64Vect3;
160using DExtent = DExtent3;
161using IExtent = IExtent3;
162using DAVect = DAVect3;
163using FAVect = FAVect3;
164using Axes = Axes3D;
165using CAxes = CAxes3D;
167using Quat = Quat3;
168using VAccum = itasca::Accumulator3;
169using AVAccum = itasca::Accumulator3;
170inline DMatrix<3,3> toMatrixDIM(const SymTensor &s) { return toMatrix3(s); }
171# ifndef THREED
172# define THREED
173# endif
174# define DIMSTR "3d"
175# define CDIMSTR "3D"
176static constexpr const char *dimstr = "3d";
177static constexpr const char *cdimstr = "3D";
178# undef itascaxd
179# define itascaxd itasca3d
180# define DIMRET(x,y) y
181template <class T> inline Vector3<T> toVect(const Vector2<T> &in) { return toVect3(in); }
182template <class T> inline const Vector3<T> & toVect(const Vector3<T> &in) { return in; }
183template <class T> inline Vector3<T> toVect(const AVector2<T> &in) { return Vector3<T>(0,0,in.z()); }
184template <class T> inline AVector3<T> toAVect(const AVector2<T> &in) { return AVector3<T>(in); }
185template <class T> inline const AVector3<T> &toAVect(const AVector3<T> &in) { return in; }
186template <class T> inline AVector3<T> toAVect(const Vector2<T> &in) { return AVector3<T>(in.x(),in.y(),0.0); }
187template <class T> inline AVector3<T> toAVect(const Vector3<T> &in) { return AVector3<T>(in.x(),in.y(),in.z()); }
188template <class T> inline Extent<T> toExtent(const Extent2<T> &t) { return Extent3<T>(t.x1(),t.x2(),t.y1(),t.y2(),0,1); }
189template <class T> inline Extent<T> toExtent(const Extent3<T> &t) { return t; }
190template <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; }
191template <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; }
192template <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; }
194template <class T,unsigned SX>
195Vector3<T> toVector(const VMatrix<T,SX> &m,unsigned start) { Vector3<T> ret(m(start),m(start+1),m(start+2)); return ret; }
196inline constexpr DMatrix<3,3> toMatrix(const SymTensor &s) { return toMatrix3(s); }
197inline DSymMatrix<3> toSymMatrix(const SymTensor &s) { return toSymMatrix3(s); }
198template <class T,class U>
199inline constexpr const U &dimval(const T &,const U &val3) { return val3; }
200static const unsigned int totdof = 6;
201#endif
202
203static constexpr uint32 dim = DIM;
204static constexpr bool is2D = dimval(true,false);
205static constexpr bool is3D = dimval(false,true);
206static constexpr uint32 adof = dimval(1,3); // Number of angular DOF
207static constexpr uint32 tdof = dimval(2,3); // Number of translational DOF
208
210// 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:132
AVector()
Default constructor, no data initialization.
Definition dim.h:135
AVector(const AVector3< T > &av)
Copy constructor.
Definition dim.h:139
AVector(const AVector &av)
Copy constructor.
Definition dim.h:137
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:758
DSymMatrix is a SymMatrix that defaults to type double...
Definition matrix.h:780
2D cartesian region in space.
Definition extent2.h:12
const T & y1() const
Returns the lower y-bound.
Definition extent2.h:37
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
const T & x1() const
Returns the lower x-bound.
Definition extent2.h:33
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 & y1() const
Returns the lower bound of the extent in the y-direction.
Definition extent3.h:46
const T & x2() const
Returns the upper bound of the extent in the x-direction.
Definition extent3.h:44
A Extent2<T> in 2D, and a Extent3<T> in 2D.
Definition dim.h:143
Extent(const Vector< T > &v11, const Vector< T > &v22)
Explicit constructor, given the lower and upper bound as two Vector.
Definition dim.h:148
Extent(const Extent3< T > &r)
Copy constructor.
Definition dim.h:152
Extent(const Extent &r)
Copy constructor.
Definition dim.h:150
Extent()
Default constructor, not data initialization.
Definition dim.h:146
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:108
A symmetric 2nd order tensor.
Definition symtensor.h:22
A 1-Dimensional version of Matrix, to represent a vector.
Definition matrix.h:716
2D vector utility class.
Definition vect.h:34
constexpr const T & x() const
X component access.
Definition vect.h:58
constexpr const T & y() const
Y component access.
Definition vect.h:60
3D vector utility class.
Definition vect.h:163
constexpr const T & y() const
The y-component of the vector.
Definition vect.h:186
constexpr const T & x() const
The x-component of the vector.
Definition vect.h:184
constexpr const T & z() const
The z-component of the vector.
Definition vect.h:188
A Vector2 in 2D, a Vector3 in 3D.
Definition dim.h:117
Vector()
Default constructor, no data initialization.
Definition dim.h:120
Vector(const Vector3< T > &v)
Copy constructor.
Definition dim.h:124
Vector(const T &t)
Single component constructor.
Definition dim.h:128
Vector(const T &x, const T &y, const T &z)
From three.
Definition dim.h:126
Vector(const Vector< T > &v)
Copy constructor.
Definition dim.h:122
constexpr Vector3< T > toVect3(const Vector2< T > &v, const T &t=0)
Conversion between vectors of different dimension.
Definition vect.h:341
constexpr const Vector2< T > & toVect2(const Vector2< T > &v)
Conversion between vectors of different dimension.
Definition vect.h:339
Vector3< T > toVect(const Vector2< T > &in)
Converts a Vector2 to a Vector.
Definition dim.h:181
DVect toDVect(const Vector3< T > &in)
Definition dim.h:192
Extent< T > toExtent(const Extent2< T > &t)
Converts Extent2 to an Extent.
Definition dim.h:188
AVector3< T > toAVect(const AVector2< T > &in)
Converts an AVector2 to an AVector.
Definition dim.h:184
IVect toIVect(const Vector3< T > &in)
Converts a Vector3<T> to an IVect.
Definition dim.h:190
FAVect3 FAVect
Angular vector of floats, either 2D or 3D.
Definition dim.h:163
DExtent3 DExtent
A DExtent2 in 2D, a DExtent3 in 3D.
Definition dim.h:160
FVect toFVect(const Vector3< T > &in)
Converts a Vector3<T> to a FVect.
Definition dim.h:191
FVect3 FVect
Vector of floats, either 2D or 3D.
Definition dim.h:155
Vector3< T > toVector(const VMatrix< T, SX > &m, unsigned start)
Converts a VMatrix to a Vector3, using three elements starting at index start.
Definition dim.h:195
IExtent3 IExtent
An IExtent2 in 2D, an IExtent3 in 3D.
Definition dim.h:161
DVect3 DVect
Vector of doubles, either 2D or 3D.
Definition dim.h:154
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:199
UVect3 UVect
Vector of uints, either 2D or 3D.
Definition dim.h:158
itasca::Accumulator3 AVAccum
3D angular accumulator
Definition dim.h:169
DAVect3 DAVect
Angular vector of doubles, either 2D or 3D.
Definition dim.h:162
itasca::Accumulator3 VAccum
3D vector accumulator
Definition dim.h:168
IVect3 IVect
Vector of ints, either 2D or 3D.
Definition dim.h:156
namespace Itasca
Definition basememory.cpp:10