Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Torenvliet
eos
Commits
ca8aa7d7
Commit
ca8aa7d7
authored
8 years ago
by
Patrik Huber
Browse files
Options
Downloads
Patches
Plain Diff
Added conversion for 3x4 matrices
Careful about GLM's notation! A 3x4 matrix is a mat4x3!
parent
fbcfa576
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/pybind11_glm.hpp
+57
-0
57 additions, 0 deletions
utils/pybind11_glm.hpp
with
57 additions
and
0 deletions
utils/pybind11_glm.hpp
+
57
−
0
View file @
ca8aa7d7
...
...
@@ -29,6 +29,9 @@ NAMESPACE_BEGIN(detail)
*
* All converters for matrices assume col-major storage of glm, the default.
* Things will likely break if non-default storage order is used.
*
* Note: GLM follows the GLSL matrix definition, so e.g. a glm::tmat4x3 has 4 cols
* and 3 rows, and is thus (in the standard mathematical notation) a 3x4 matrix.
*/
template
<
typename
T
,
glm
::
precision
P
>
...
...
@@ -175,6 +178,60 @@ protected:
static
PYBIND11_DESCR
elements
()
{
return
_
(
std
::
to_string
(
num_elements
).
c_str
());
}
};
template
<
typename
T
,
glm
::
precision
P
>
struct
type_caster
<
glm
::
tmat4x3
<
T
,
P
>>
{
using
matrix_type
=
glm
::
tmat4x3
<
T
,
P
>
;
typedef
typename
T
Scalar
;
static
constexpr
std
::
size_t
num_rows
=
3
;
static
constexpr
std
::
size_t
num_cols
=
4
;
bool
load
(
handle
src
,
bool
)
{
array_t
<
Scalar
>
buf
(
src
,
true
);
if
(
!
buf
.
check
())
return
false
;
if
(
buf
.
ndim
()
==
2
)
// a 2-dimensional matrix
{
if
(
buf
.
shape
(
0
)
!=
num_rows
||
buf
.
shape
(
1
)
!=
num_cols
)
{
return
false
;
// not a 3x4 matrix
}
if
(
buf
.
strides
(
0
)
/
sizeof
(
Scalar
)
!=
num_cols
||
buf
.
strides
(
1
)
!=
sizeof
(
Scalar
))
{
std
::
cout
<<
"An array with non-standard strides is given. Please pass a contiguous array."
<<
std
::
endl
;
return
false
;
}
// What we get from Python is laid out in row-major memory order, while GLM's
// storage is col-major, thus, we create a mat3x4 and then transpose.
value
=
glm
::
transpose
(
glm
::
make_mat3x4
(
buf
.
mutable_data
()));
// make_mat*() copies the data (unnecessarily)
}
else
{
// buf.ndim() != 2
return
false
;
}
return
true
;
}
static
handle
cast
(
const
matrix_type
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
return
array
(
{
num_rows
,
num_cols
},
// shape
{
sizeof
(
Scalar
),
sizeof
(
Scalar
)
*
num_rows
},
// strides - flip the row/col layout!
glm
::
value_ptr
(
src
)
// data
).
release
();
}
// Specifies the doc-string for the type in Python:
PYBIND11_TYPE_CASTER
(
matrix_type
,
_
(
"numpy.ndarray["
)
+
npy_format_descriptor
<
Scalar
>::
name
()
+
_
(
"["
)
+
rows
()
+
_
(
", "
)
+
cols
()
+
_
(
"]]"
));
protected
:
template
<
typename
T
=
matrix_type
>
static
PYBIND11_DESCR
rows
()
{
return
_
(
std
::
to_string
(
num_rows
).
c_str
());
}
template
<
typename
T
=
matrix_type
>
static
PYBIND11_DESCR
cols
()
{
return
_
(
std
::
to_string
(
num_cols
).
c_str
());
}
};
template
<
typename
T
,
glm
::
precision
P
>
struct
type_caster
<
glm
::
tmat4x4
<
T
,
P
>>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment