Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
eos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Richard Torenvliet
eos
Commits
942644fd
Commit
942644fd
authored
Nov 08, 2016
by
Patrik Huber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added transparent binding for tmat3x3
parent
240d166a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
utils/pybind11_glm.hpp
utils/pybind11_glm.hpp
+54
-0
No files found.
utils/pybind11_glm.hpp
View file @
942644fd
...
@@ -178,6 +178,60 @@ protected:
...
@@ -178,6 +178,60 @@ protected:
static
PYBIND11_DESCR
elements
()
{
return
_
(
std
::
to_string
(
num_elements
).
c_str
());
}
static
PYBIND11_DESCR
elements
()
{
return
_
(
std
::
to_string
(
num_elements
).
c_str
());
}
};
};
template
<
typename
T
,
glm
::
precision
P
>
struct
type_caster
<
glm
::
tmat3x3
<
T
,
P
>>
{
using
matrix_type
=
glm
::
tmat3x3
<
T
,
P
>
;
typedef
typename
T
Scalar
;
static
constexpr
std
::
size_t
num_rows
=
3
;
static
constexpr
std
::
size_t
num_cols
=
3
;
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 3x3 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 transpose.
value
=
glm
::
transpose
(
glm
::
make_mat3x3
(
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
>
template
<
typename
T
,
glm
::
precision
P
>
struct
type_caster
<
glm
::
tmat4x3
<
T
,
P
>>
struct
type_caster
<
glm
::
tmat4x3
<
T
,
P
>>
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment