VolViz
A volume visualization tool
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Types.h
Go to the documentation of this file.
1 #ifndef VolViz_Types_h
2 #define VolViz_Types_h
3 
4 #include <Eigen/Core>
5 #include <Eigen/Geometry>
6 #include <gsl/gsl>
7 #include <phys/units/quantity.hpp>
8 
9 #include <array>
10 
11 namespace VolViz {
12 
13 using namespace gsl;
14 
16 
17 using Matrix3 = Eigen::Matrix3f;
18 using Matrix4 = Eigen::Matrix4f;
19 
23 using PositionH = Eigen::Vector4f;
24 
26 using Position2 = Eigen::Vector2f;
27 
28 using Size2 = Eigen::Matrix<std::size_t, 2, 1>;
29 using Size3 = Eigen::Matrix<std::size_t, 3, 1>;
30 
32 
34 template <class T> struct Range {
35  T min, max;
36  constexpr auto length() const noexcept { return max - min; }
37 };
38 
41 
42 namespace Colors {
43 inline auto Black() noexcept { return Color::Zero(); }
44 inline auto White() noexcept { return Color::Ones(); }
45 inline auto Red() noexcept { return Color::UnitX(); }
46 inline auto Green() noexcept { return Color::UnitY(); }
47 inline auto Blue() noexcept { return Color::UnitZ(); }
48 inline auto Yellow() noexcept { return Red() + Green(); }
49 inline auto Magenta() noexcept { return Red() + Blue(); }
50 inline auto Cyan() noexcept { return Blue() + Green(); }
51 }
52 
54 using Orientation = Eigen::Quaternionf;
55 
56 struct DepthRange {
57  float near{1.f}, far{-1.f};
58 };
59 
60 enum class Axis { X, Y, Z };
61 
62 using Scale = float;
63 
64 using Length = phys::units::quantity<phys::units::length_d>;
65 using Angle = double;
66 using PhysicalPosition = Eigen::Matrix<Length, 3, 1>;
67 
68 using phys::units::meter;
69 using phys::units::rad;
70 using phys::units::degree_angle;
71 
72 using phys::units::centi;
73 using phys::units::milli;
74 using phys::units::micro;
75 using phys::units::nano;
76 
77 using phys::units::abs;
78 
79 namespace literals = phys::units::literals;
80 
81 using VoxelSize = std::array<Length, 3>;
82 
85 template <class T>
86 inline constexpr auto as_span(T *ptr,
87  typename span<T>::index_type size) noexcept {
88  return span<T>(ptr, size);
89 }
90 
91 template <
92  class Container,
93  class = std::enable_if_t<
96  std::is_convertible<typename Container::pointer,
97  decltype(std::declval<Container>().data())>::value>>
98 inline constexpr auto as_span(Container &c) {
100 }
101 
102 template <
103  class Container,
104  class = std::enable_if_t<
107  std::is_convertible<typename Container::pointer,
108  decltype(std::declval<Container>().data())>::value>>
109 inline constexpr auto as_span(Container const &c) {
111 }
113 
114 } // namespace VolViz
115 
116 #if __cplusplus < 201703L
117 
118 namespace std {
119 
120 template<class T>
121 constexpr const T& clamp( const T& v, const T& lo, const T& hi ) {
122  return clamp( v, lo, hi, std::less<>() );
123 }
124 
125 template<class T, class Compare>
126 constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp ) {
127  return assert( !comp(hi, lo) ),
128  comp(v, lo) ? lo : comp(hi, v) ? hi : v;
129  }
130 
131 }
132 
133 #endif
134 
135 #endif // VolViz_Types_h
Eigen::Matrix< Length, 3, 1 > PhysicalPosition
Definition: Types.h:66
GLboolean * data
Definition: glad.h:2184
Eigen::Quaternionf Orientation
6-DOF orientation, represented as a quaternion
Definition: Types.h:54
const GLdouble * v
Definition: glad.h:2583
GLsizei const GLfloat * value
Definition: glad.h:2544
Eigen::Matrix3f Matrix3
Definition: Types.h:17
Definition: Types.h:56
constexpr auto as_span(T *ptr, typename span< T >::index_type size) noexcept
Conveniance wrapper for span<>
Definition: Types.h:86
auto White() noexcept
Definition: Types.h:44
auto Black() noexcept
Definition: Types.h:43
T min
Definition: Types.h:35
Eigen::Vector3f Position
Position in 3D euclidean space.
Definition: Types.h:21
Eigen::Vector3f Size3f
Definition: Types.h:31
An 1D range.
Definition: Types.h:34
const GLubyte * c
Definition: glad.h:14924
auto Red() noexcept
Definition: Types.h:45
double Angle
Definition: Types.h:65
Eigen::Vector3f Color
Normalized RGB color.
Definition: Types.h:40
GLenum clamp
Definition: glad.h:2753
float Scale
Definition: Types.h:62
auto Cyan() noexcept
Definition: Types.h:50
auto Magenta() noexcept
Definition: Types.h:49
Eigen::Matrix< std::size_t, 2, 1 > Size2
Definition: Types.h:28
Eigen::Matrix4f Matrix4
Definition: Types.h:18
auto Green() noexcept
Definition: Types.h:46
auto Blue() noexcept
Definition: Types.h:47
auto Yellow() noexcept
Definition: Types.h:48
std::array< Length, 3 > VoxelSize
Definition: Types.h:81
GLsizeiptr size
Definition: glad.h:2387
constexpr auto length() const noexcept
Definition: Types.h:36
phys::units::quantity< phys::units::length_d > Length
Definition: Types.h:64
Eigen::Vector3f Vector3f
Definition: Types.h:15
Eigen::Vector2f Position2
Position in 2D space.
Definition: Types.h:26
Eigen::Matrix< std::size_t, 3, 1 > Size3
Definition: Types.h:29
Axis
Definition: Types.h:60
GLenum void ** pointer
Definition: glad.h:2502
GLenum GLenum GLsizei void GLsizei void void * span
Definition: glad.h:4220
Eigen::Vector4f PositionH
Position in homogenous coordinates.
Definition: Types.h:23
GLdouble far
Definition: glad.h:2220