API Documentation
Loading...
Searching...
No Matches
MatrixFunctions.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: MatrixFunctions
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include "Matrix.hpp"
35#include <NDEVR/Vertex.h>
36#include <NDEVR/LineSegment.h>
37#include <NDEVR/Bounds.h>
38#include <NDEVR/Triangle.h>
39#include <NDEVR/PolyLine.h>
40namespace NDEVR
41{
42 template<class t_type, class t_vector, uint01 t_dims, uint01 t_row_dims, uint01 t_col_dims>
44 {
45 return matrix * vertex;
46 }
47 template<class t_type, class t_vector, uint01 t_row_dims, uint01 t_col_dims>
49 {
51 trans = matrix * trans;
52 return Vertex<1, t_type, t_vector>(trans.template as<1, t_type>() / trans[1]);
53 }
54 template<class t_type, class t_vector, uint01 t_row_dims, uint01 t_col_dims>
56 {
57 t_type bottom = right[0] * matrix[0][3] + right[1] * matrix[1][3] + matrix[2][3] + matrix[3][3];
59 (right[0] * matrix[0][0] + right[1] * matrix[1][0] + matrix[2][0] + matrix[3][0]) / bottom
60 , (right[0] * matrix[0][1] + right[1] * matrix[1][1] + matrix[2][1] + matrix[3][1]) / bottom);
61 }
62 template<class t_type, class t_vector>
64 {
65 t_type bottom = right[0] * matrix[0][3] + right[1] * matrix[1][3] + right[2] * matrix[2][3] + matrix[3][3];
67 (right[0] * matrix[0][0] + right[1] * matrix[1][0] + right[2] * matrix[2][0] + matrix[3][0]) / bottom
68 , (right[0] * matrix[0][1] + right[1] * matrix[1][1] + right[2] * matrix[2][1] + matrix[3][1]) / bottom
69 , (right[0] * matrix[0][2] + right[1] * matrix[1][2] + right[2] * matrix[2][2] + matrix[3][2]) / bottom);
70 }
71 template<class t_type, class t_vector>
73 {
75 (right[0] * matrix[0][0] + right[1] * matrix[1][0] + right[2] * matrix[2][0])
76 , (right[0] * matrix[0][1] + right[1] * matrix[1][1] + right[2] * matrix[2][1])
77 , (right[0] * matrix[0][2] + right[1] * matrix[1][2] + right[2] * matrix[2][2]));
78 }
79 template<class t_type, class t_vector>
81 {
83 right[0] * matrix[0][0] + right[1] * matrix[1][0] + right[2] * matrix[2][0] + right[3] * matrix[3][0]
84 , right[0] * matrix[0][1] + right[1] * matrix[1][1] + right[2] * matrix[2][1] + right[3] * matrix[3][1]
85 , right[0] * matrix[0][2] + right[1] * matrix[1][2] + right[2] * matrix[2][2] + right[3] * matrix[3][2]
86 , right[0] * matrix[0][3] + right[1] * matrix[1][3] + right[2] * matrix[2][3] + right[3] * matrix[3][3]);
87 }
88
89 template<class t_type, class t_vector, uint01 t_dims, uint01 t_row_dims, uint01 t_col_dims>
91 {
92 return matrix * vertex;
93 }
94 template<class t_type, class t_vector, uint01 t_row_dims, uint01 t_col_dims>
96 {
97 return Ray<1, t_type, t_vector>(right[0] * matrix[0][0]);
98 }
99 template<class t_type, class t_vector, uint01 t_row_dims, uint01 t_col_dims>
101 {
103 (right[0] * matrix[0][0] + right[1] * matrix[1][0] + matrix[2][0])
104 , (right[0] * matrix[0][1] + right[1] * matrix[1][1] + matrix[2][1]));
105 }
106 template<class t_type, class t_vector>
108 {
110 (right[0] * matrix[0][0] + right[1] * matrix[1][0] + right[2] * matrix[2][0])
111 , (right[0] * matrix[0][1] + right[1] * matrix[1][1] + right[2] * matrix[2][1])
112 , (right[0] * matrix[0][2] + right[1] * matrix[1][2] + right[2] * matrix[2][2]));
113 }
114 template<class t_type, class t_vector>
116 {
118 (right[0] * matrix[0][0] + right[1] * matrix[1][0] + right[2] * matrix[2][0])
119 , (right[0] * matrix[0][1] + right[1] * matrix[1][1] + right[2] * matrix[2][1])
120 , (right[0] * matrix[0][2] + right[1] * matrix[1][2] + right[2] * matrix[2][2]));
121 }
122 template<class t_type, class t_vector>
124 {
126 right[0] * matrix[0][0] + right[1] * matrix[1][0] + right[2] * matrix[2][0] + right[3] * matrix[3][0]
127 , right[0] * matrix[0][1] + right[1] * matrix[1][1] + right[2] * matrix[2][1] + right[3] * matrix[3][1]
128 , right[0] * matrix[0][2] + right[1] * matrix[1][2] + right[2] * matrix[2][2] + right[3] * matrix[3][2]
129 , right[0] * matrix[0][3] + right[1] * matrix[1][3] + right[2] * matrix[2][3] + right[3] * matrix[3][3]);
130 }
131 template<class t_type, uint01 t_dims, class t_vertex, uint01 t_row_dims, uint01 t_col_dims>
136 template<class t_type, uint01 t_dims, class t_vertex, uint01 t_row_dims, uint01 t_col_dims>
141
142 template<class t_type, class t_vertex, uint01 t_dims, uint01 t_row_dims, uint01 t_col_dims>
144 {
146 for (uint04 i = 0; i < poly.vertexCount(); i++)
147 {
148 polyline.add(matrix * poly.vertex(i));
149 }
150 return polyline;
151 }
152 template<class t_type, class t_vertex, uint01 t_row_dims, uint01 t_col_dims>
154 {
156 t_vertex upper_1;
157 for (uint01 max_min = 0; max_min < 2; max_min++)
158 {
159 for (uint01 n = 0; n < 3; n++)
160 upper_1[n] = matrix[0][n] * bounds[max_min][X] + matrix[3][n];
161 t_type lower_1 = matrix[0][3] * bounds[max_min][X] + matrix[3][3];
162 bounds_2.addToBounds(upper_1 / lower_1);
163 }
164 return bounds_2;
165 }
166 template<class t_type, class t_vertex, uint01 t_row_dims, uint01 t_col_dims>
168 {
170 t_vertex upper_1;
171 for (uint01 i = MIN; i <= MAX; i++)
172 {
173 for (uint01 n = 0; n < 3; n++)
174 upper_1[n] = matrix[0][n] * bounds[i][X] + matrix[3][n];
175 t_type lower_1 = matrix[0][3] * bounds[i][X] + matrix[3][3];
176 t_vertex upper_2;
177 for (uint01 j = MIN; j <= MAX; j++)
178 {
179 for (uint01 n = 0; n < 3; n++)
180 upper_2[n] = upper_1[n] + matrix[1][n] * bounds[j][Y];
181 t_type lower_2 = lower_1 + matrix[1][3] * bounds[j][Y];
182 trans_bounds.addToBounds(upper_2 / lower_2);
183 }
184 }
185 return trans_bounds;
186 }
187 template<class t_type, class t_vertex, uint01 t_row_dims, uint01 t_col_dims>
189 {
190 if (IsInvalid(bounds))
191 return bounds;
192 else if (bounds == Constant<Bounds<3, t_type, t_vertex>>::Max)
193 return bounds;
194 else if (bounds == Constant<Bounds<3, t_type, t_vertex>>::Min)
195 return bounds;
197 t_vertex upper_1;
198 for (uint01 max_min = MIN; max_min <= MAX; max_min++)
199 {
200 for (uint01 n = 0; n < 3; n++)
201 upper_1[n] = matrix[0][n] * bounds[max_min][X] + matrix[3][n];
202 t_type lower_1 = matrix[0][3] * bounds[max_min][X] + matrix[3][3];
203 t_vertex upper_2;
204 for (uint01 max_min_2 = MIN; max_min_2 <= MAX; max_min_2++)
205 {
206 for (uint01 n = 0; n < 3; n++)
207 upper_2[n] = upper_1[n] + matrix[1][n] * bounds[max_min_2][Y];
208 t_type lower_2 = lower_1 + matrix[1][3] * bounds[max_min_2][Y];
209 t_vertex upper_3;
210 for (uint01 max_min_3 = MIN; max_min_3 <= MAX; max_min_3++)
211 {
212 for (uint01 n = 0; n < 3; n++)
213 upper_3[n] = upper_2[n] + matrix[2][n] * bounds[max_min_3][Z];
214 t_type lower_3 = lower_2 + matrix[2][3] * bounds[max_min_3][Z];
215 trans_bounds.addToBounds(upper_3 / lower_3);
216 }
217 }
218 }
219 /*trans_bounds.addToBounds(matrix * t_vertex(bounds[MIN][X], bounds[MIN][Y], bounds[MIN][Z]));
220 trans_bounds.addToBounds(matrix * t_vertex(bounds[MIN][X], bounds[MIN][Y], bounds[MAX][Z]));
221 trans_bounds.addToBounds(matrix * t_vertex(bounds[MIN][X], bounds[MAX][Y], bounds[MIN][Z]));
222 trans_bounds.addToBounds(matrix * t_vertex(bounds[MIN][X], bounds[MAX][Y], bounds[MAX][Z]));
223 trans_bounds.addToBounds(matrix * t_vertex(bounds[MAX][X], bounds[MIN][Y], bounds[MIN][Z]));
224 trans_bounds.addToBounds(matrix * t_vertex(bounds[MAX][X], bounds[MIN][Y], bounds[MAX][Z]));
225 trans_bounds.addToBounds(matrix * t_vertex(bounds[MAX][X], bounds[MAX][Y], bounds[MIN][Z]));
226 trans_bounds.addToBounds(matrix * t_vertex(bounds[MAX][X], bounds[MAX][Y], bounds[MAX][Z]));*/
227 return trans_bounds;
228 }
229
230 template<class t_type, uint01 t_row_dims, uint01 t_col_dims>
232 {
233 for (uint01 i = 0; i < t_row_dims; i++)
234 if (!equals(a[i], b[i], epsilon))
235 return false;
236 return true;
237 }
238
239 template<class t_type, uint01 t_row_dims, uint01 t_col_dims>
241 {
243 for (uint01 i = 0; i < t_row_dims; i++)
244 multiplied_matrix[i] = mult * matrix[i];
245 return multiplied_matrix;
246 }
248 {
249 public:
251 {
254 bool solve_offset_xy = true;;
255 bool solve_offset_z = true;
256 bool solve_heading = true;
257 bool solve_rotation = false;
258 bool solve_scale = false;
259 };
263 };
264
265}
266
#define NDEVR_BASE_API
Definition DLLInfo.h:57
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:52
constexpr void addToBounds(const t_vertex &vector)
Definition Bounds.hpp:390
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A line segment represented by two vertices, a start and end.
Definition Line.hpp:49
constexpr const t_vertex & vertex(uint01 index) const
Definition Line.hpp:152
Definition MatrixFunctions.h:248
static Matrix< fltp08 > SolveLeastSquaredAffine(const Buffer< Vertex< 3, fltp08 > > &a, const Buffer< Vertex< 3, fltp08 > > &b)
static Matrix< fltp08 > Solve2DAffine(const Buffer< Vertex< 2, fltp08 > > &a, const Buffer< Vertex< 2, fltp08 > > &b)
static Matrix< fltp08 > SolveBestFitTransform(const TransformSolveOptions &options)
Definition Matrix.hpp:176
A polyline which stores vertex information for many points along a given path.
Definition CoordinateProjectionManager.h:44
uint04 vertexCount() const
Definition PolyLine.hpp:191
void add(const t_vertex &vertex)
Definition PolyLine.hpp:241
const t_vertex & vertex(uint04 index) const
Definition PolyLine.hpp:143
Definition Vertex.hpp:317
A triangle is a polygon with three edges and three vertices. It is one of the basic shapes in geometr...
Definition Triangle.hpp:138
constexpr t_vertex & vertex(TriangleLocation triangle_node)
Vertices the given triangle node.
Definition Triangle.hpp:168
A vertex or point. A specific type of Vector used primarily for spacial location information.
Definition Vertex.hpp:48
Definition ACIColor.h:37
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
constexpr std::enable_if< IsVecType< t_vector_type, Angle< fltp08 > >::value, t_vector_type >::type operator*(const t_vector_type &angle, const t_type &mult)
Multiplication operator for a Vector of Angles.
Definition AngleFunctions.h:326
@ MIN
Definition BaseValues.hpp:196
@ MAX
Definition BaseValues.hpp:197
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
constexpr bool equals(const LineSegment< t_dims, t_type, t_vertex > &left, const LineSegment< t_dims, t_type, t_vertex > &right, const t_type &epsilon=cast< t_type >(0))
Definition Line.hpp:757
@ B
Definition BaseValues.hpp:170
@ A
Definition BaseValues.hpp:168
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
@ C
Definition BaseValues.hpp:172
@ Z
Definition BaseValues.hpp:171
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
Definition MatrixFunctions.h:251
Buffer< Vertex< 3, fltp08 > > a
Definition MatrixFunctions.h:252
Buffer< Vertex< 3, fltp08 > > b
Definition MatrixFunctions.h:253