Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
navipy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
cbaca8ae
Commit
cbaca8ae
authored
7 years ago
by
Luise Odenthal
Browse files
Options
Downloads
Patches
Plain Diff
updates blenttest for conventions and renderer
parent
8e4d7a01
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
navipy/sensors/blendtest1.py
+74
-105
74 additions, 105 deletions
navipy/sensors/blendtest1.py
navipy/sensors/renderer.py
+19
-10
19 additions, 10 deletions
navipy/sensors/renderer.py
with
93 additions
and
115 deletions
navipy/sensors/blendtest1.py
+
74
−
105
View file @
cbaca8ae
from
navipy.sensors.renderer
import
BlenderRender
from
navipy.sensors.renderer
import
BlenderRender
import
tempfile
from
navipy.maths.euler
import
matrix
,
from_matrix
from
navipy.maths.euler
import
matrix
,
from_matrix
from
navipy.maths.quaternion
import
from_matrix
as
quat_matrix
from
navipy.maths.quaternion
import
from_matrix
as
quat_matrix
import
pandas
as
pd
import
pandas
as
pd
...
@@ -10,149 +11,117 @@ import unittest
...
@@ -10,149 +11,117 @@ import unittest
class
TestCase
(
unittest
.
TestCase
):
class
TestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
i
=
[
np
.
array
([
'
location
'
,
'
location
'
,
'
location
'
,
self
.
tuples
=
[(
'
location
'
,
'
x
'
),
(
'
location
'
,
'
y
'
),
'
sxyz
'
,
'
sxyz
'
,
'
sxyz
'
]),
(
'
location
'
,
'
z
'
),
(
'
rxyz
'
,
'
alpha_0
'
),
np
.
array
([
'
x
'
,
'
y
'
,
'
z
'
,
(
'
rxyz
'
,
'
alpha_1
'
),
(
'
rxyz
'
,
'
alpha_2
'
)]
'
alpha_0
'
,
'
alpha_1
'
,
'
alpha_2
'
])]
self
.
tuples2
=
[(
'
location
'
,
'
x
'
),
(
'
location
'
,
'
y
'
),
self
.
i2
=
[
np
.
array
([
'
location
'
,
'
location
'
,
'
location
'
,
(
'
location
'
,
'
z
'
),
(
'
ryzx
'
,
'
alpha_0
'
),
'
syzx
'
,
'
syzx
'
,
'
syzx
'
]),
(
'
ryzx
'
,
'
alpha_1
'
),
(
'
ryzx
'
,
'
alpha_2
'
)]
np
.
array
([
'
x
'
,
'
y
'
,
'
z
'
,
'
alpha_0
'
,
'
alpha_1
'
,
'
alpha_2
'
])]
self
.
image2
=
np
.
zeros
((
4
,
180
,
360
,
4
,
1
))
self
.
image2
=
np
.
zeros
((
4
,
180
,
360
,
4
,
1
))
self
.
posorient2
=
pd
.
Series
(
index
=
self
.
i2
)
index
=
pd
.
MultiIndex
.
from_tuples
(
self
.
tuples2
,
names
=
[
'
position
'
,
'
orientation
'
])
self
.
posorient2
=
pd
.
Series
(
index
=
index
)
self
.
posorient2
.
loc
[
'
location
'
][
'
x
'
]
=
0
self
.
posorient2
.
loc
[
'
location
'
][
'
x
'
]
=
0
self
.
posorient2
.
loc
[
'
location
'
][
'
y
'
]
=
0
self
.
posorient2
.
loc
[
'
location
'
][
'
y
'
]
=
0
self
.
posorient2
.
loc
[
'
location
'
][
'
z
'
]
=
0
self
.
posorient2
.
loc
[
'
location
'
][
'
z
'
]
=
0
self
.
posorient2
.
loc
[
'
s
yzx
'
][
'
alpha_0
'
]
=
0
self
.
posorient2
.
loc
[
'
r
yzx
'
][
'
alpha_0
'
]
=
0
self
.
posorient2
.
loc
[
'
s
yzx
'
][
'
alpha_1
'
]
=
0
self
.
posorient2
.
loc
[
'
r
yzx
'
][
'
alpha_1
'
]
=
0
self
.
posorient2
.
loc
[
'
s
yzx
'
][
'
alpha_2
'
]
=
0
self
.
posorient2
.
loc
[
'
r
yzx
'
][
'
alpha_2
'
]
=
0
self
.
a
=
1
self
.
a
=
1
self
.
b
=
0.75
self
.
b
=
0.75
self
.
c
=
0.5
self
.
c
=
0.5
self
.
posorient
=
pd
.
Series
(
index
=
self
.
i
)
index
=
pd
.
MultiIndex
.
from_tuples
(
self
.
tuples
,
names
=
[
'
position
'
,
'
orientation
'
])
self
.
posorient
=
pd
.
Series
(
index
=
index
)
self
.
posorient
.
loc
[
'
location
'
][
'
x
'
]
=
0
self
.
posorient
.
loc
[
'
location
'
][
'
x
'
]
=
0
self
.
posorient
.
loc
[
'
location
'
][
'
y
'
]
=
0
self
.
posorient
.
loc
[
'
location
'
][
'
y
'
]
=
0
self
.
posorient
.
loc
[
'
location
'
][
'
z
'
]
=
0
self
.
posorient
.
loc
[
'
location
'
][
'
z
'
]
=
0
self
.
posorient
.
loc
[
'
sxyz
'
][
'
alpha_0
'
]
=
self
.
a
self
.
posorient
.
loc
[
'
rxyz
'
][
'
alpha_0
'
]
=
self
.
a
self
.
posorient
.
loc
[
'
sxyz
'
][
'
alpha_1
'
]
=
self
.
b
self
.
posorient
.
loc
[
'
rxyz
'
][
'
alpha_1
'
]
=
self
.
b
self
.
posorient
.
loc
[
'
sxyz
'
][
'
alpha_2
'
]
=
self
.
c
self
.
posorient
.
loc
[
'
rxyz
'
][
'
alpha_2
'
]
=
self
.
c
self
.
renderer
=
BlenderRender
()
def
test_diff_euler_xyz2yzx
(
self
):
def
test_diff_euler_xyz2yzx
(
self
):
# print("euler test")
mat1
=
matrix
(
self
.
a
,
self
.
b
,
self
.
c
,
axes
=
'
rxyz
'
)
logfile
=
'
blender_render.log
'
at
,
bt
,
ct
=
from_matrix
(
mat1
,
axes
=
'
ryzx
'
)
open
(
logfile
,
'
a
'
).
close
()
default_tmp_dir
=
tempfile
.
_get_default_tempdir
()
fp
=
default_tmp_dir
+
"
/
"
+
next
(
tempfile
.
_get_candidate_names
())
open
(
fp
,
'
a
'
).
close
()
old
=
os
.
dup
(
1
)
old
=
os
.
dup
(
1
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
os
.
close
(
1
)
os
.
close
(
1
)
os
.
open
(
logfile
,
os
.
O_WRONLY
)
os
.
open
(
fp
,
os
.
O_WRONLY
)
renderer
=
BlenderRender
()
renderer2
=
BlenderRender
()
mat1
=
matrix
(
self
.
a
,
self
.
b
,
self
.
c
,
axes
=
'
sxyz
'
)
a1
,
a2
,
a3
=
from_matrix
(
mat1
,
axes
=
'
sxyz
'
)
at
,
bt
,
ct
=
from_matrix
(
mat1
,
axes
=
'
syzx
'
)
self
.
posorient2
.
loc
[
'
syzx
'
][
'
alpha_0
'
]
=
at
self
.
posorient2
.
loc
[
'
ryzx
'
][
'
alpha_0
'
]
=
bt
self
.
posorient2
.
loc
[
'
syzx
'
][
'
alpha_1
'
]
=
bt
self
.
posorient2
.
loc
[
'
ryzx
'
][
'
alpha_1
'
]
=
ct
self
.
posorient2
.
loc
[
'
syzx
'
][
'
alpha_2
'
]
=
ct
self
.
posorient2
.
loc
[
'
ryzx
'
][
'
alpha_2
'
]
=
at
# renderer.camera_rotation_mode = 'YZX'
self
.
image2
[
0
]
=
self
.
renderer
.
scene
(
self
.
posorient
)
# print("poorient ### ",self.posorient2.loc[['syzx'],
self
.
image2
[
1
]
=
self
.
renderer
.
scene
(
self
.
posorient2
)
# ['alpha_0', 'alpha_1', 'alpha_2']].values)
self
.
image2
[
0
]
=
renderer2
.
scene
(
self
.
posorient2
)
# conv = renderer2.camera_rotation_mode
# self.posorient.loc['sxyz']['alpha_0'] = a
# self.posorient.loc['sxyz']['alpha_1'] = b
# self.posorient.loc['sxyz']['alpha_2'] = c
# print("poorient ### ",posorient.loc[['sxyz'],
# ['alpha_0', 'alpha_1', 'alpha_2']].values)
# renderer.camera_rotation_mode = 'XYZ'
self
.
image2
[
1
]
=
renderer
.
scene
(
self
.
posorient
)
# disable output redirection
# disable output redirection
os
.
close
(
1
)
os
.
close
(
1
)
os
.
dup
(
old
)
os
.
dup
(
old
)
os
.
close
(
old
)
os
.
close
(
old
)
# print("first image")
#
print(self.image[0,:,0,0] - self.image[1,:,0,0])
#
indices = np.where(np.abs(self.image2[0] -
#
print("second
image
"
)
#
self.
image
2[1]
)
#
print
(self.image[
1,:,0,
0]
)
#
==np.max(np.abs
(self.image
2
[0]
#
conv2= renderer.camera_rotation_mode
#
- self.image2[1])))
# print("
angels xyz",a1,a2,a3,"angles yzx",at,bt,ct)
# print("
first image", self.image2[0,indices[0],indices[1],indices[2]],
#
print("sh be yzx",conv,"sh be xyz",conv2
)
#
"second image",self.image2[1,indices[0],indices[1],indices[2]]
)
# print(np.sum(np.abs(image2[0,:,:,0]-image2[1,:,:,0])))
# print(np.sum(np.abs(
self.
image2[0,:,:,0]-
self.
image2[1,:,:,0])))
# print("max diff ",np.max(np.abs(self.image2[0
]-self.image2[1])))
# print("max diff ",np.max(np.abs(self.image2[0
,:,:,0]
#
assert np.testing,assert_allclose(self.image[0],
#
-self.image2[1,:,:,0])))
#
self.image
[1
], atol
= 0.007
)
assert
np
.
all
(
np
.
isclose
(
self
.
image2
[
2
],
self
.
image
2
[
3
],
atol
=
1.2
)
)
def
test_euler_xyz_2_quaternion
(
self
):
def
test_euler_xyz_2_quaternion
(
self
):
# print("quaternion test")
# print("quaternion test")
logfile
=
'
blender_render.log
'
i2
=
[(
'
location
'
,
'
x
'
),
(
'
location
'
,
'
y
'
),
open
(
logfile
,
'
a
'
).
close
()
(
'
location
'
,
'
z
'
),
(
'
quaternion
'
,
'
q_0
'
),
(
'
quaternion
'
,
'
q_1
'
),
(
'
quaternion
'
,
'
q_2
'
),
(
'
quaternion
'
,
'
q_3
'
)]
mat1
=
matrix
(
self
.
a
,
self
.
b
,
self
.
c
,
axes
=
'
rxyz
'
)
at
,
bt
,
ct
,
dt
=
quat_matrix
(
mat1
)
default_tmp_dir
=
tempfile
.
_get_default_tempdir
()
fp
=
default_tmp_dir
+
"
/
"
+
next
(
tempfile
.
_get_candidate_names
())
open
(
fp
,
'
a
'
).
close
()
old
=
os
.
dup
(
1
)
old
=
os
.
dup
(
1
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
os
.
close
(
1
)
os
.
close
(
1
)
os
.
open
(
logfile
,
os
.
O_WRONLY
)
os
.
open
(
fp
,
os
.
O_WRONLY
)
i2
=
[
np
.
array
([
'
location
'
,
'
location
'
,
'
location
'
,
'
quaternion
'
,
'
quaternion
'
,
'
quaternion
'
,
'
quaternion
'
]),
np
.
array
([
'
x
'
,
'
y
'
,
'
z
'
,
'
q_0
'
,
'
q_1
'
,
'
q_2
'
,
'
q_3
'
])]
renderer
=
BlenderRender
()
renderer2
=
BlenderRender
()
mat1
=
matrix
(
self
.
a
,
self
.
b
,
self
.
c
,
axes
=
'
sxyz
'
)
at
,
bt
,
ct
,
dt
=
quat_matrix
(
mat1
)
posorient2
=
pd
.
Series
(
index
=
i2
)
index
=
pd
.
MultiIndex
.
from_tuples
(
i2
,
names
=
[
'
position
'
,
'
orientation
'
])
posorient2
=
pd
.
Series
(
index
=
index
)
posorient2
.
loc
[
'
location
'
][
'
x
'
]
=
0
posorient2
.
loc
[
'
location
'
][
'
x
'
]
=
0
posorient2
.
loc
[
'
location
'
][
'
y
'
]
=
0
posorient2
.
loc
[
'
location
'
][
'
y
'
]
=
0
posorient2
.
loc
[
'
location
'
][
'
z
'
]
=
0
posorient2
.
loc
[
'
location
'
][
'
z
'
]
=
0
posorient2
.
loc
[
'
quaternion
'
][
'
q_0
'
]
=
at
posorient2
.
loc
[
'
quaternion
'
][
'
q_0
'
]
=
bt
posorient2
.
loc
[
'
quaternion
'
][
'
q_1
'
]
=
bt
posorient2
.
loc
[
'
quaternion
'
][
'
q_1
'
]
=
ct
posorient2
.
loc
[
'
quaternion
'
][
'
q_2
'
]
=
ct
posorient2
.
loc
[
'
quaternion
'
][
'
q_2
'
]
=
dt
posorient2
.
loc
[
'
quaternion
'
][
'
q_3
'
]
=
dt
posorient2
.
loc
[
'
quaternion
'
][
'
q_3
'
]
=
at
# renderer.camera_rotation_mode = 'YZX'
self
.
image2
[
3
]
=
self
.
renderer
.
scene
(
posorient2
)
# print("poorient ### ",posorient2.loc[['quternion'],
self
.
image2
[
2
]
=
self
.
renderer
.
scene
(
self
.
posorient
)
# ['q_0', 'q_1',
# 'q_2', 'q_3']].values)
self
.
image2
[
2
]
=
renderer2
.
scene
(
posorient2
)
# conv = renderer2.camera_rotation_mode
# self.posorient = pd.Series(index=self.i)
# self.posorient.loc['sxyz']['alpha_0'] = a
# self.posorient.loc['sxyz']['alpha_1'] = b
# self.posorient.loc['sxyz']['alpha_2'] = c
# print("poorient ### ",self.posorient.loc[['sxyz'],
# ['alpha_0', 'alpha_1', 'alpha_2']].values)
# renderer.camera_rotation_mode = 'XYZ'
self
.
image2
[
3
]
=
renderer
.
scene
(
self
.
posorient
)
# disable output redirection
# disable output redirection
os
.
close
(
1
)
os
.
close
(
1
)
os
.
dup
(
old
)
os
.
dup
(
old
)
os
.
close
(
old
)
os
.
close
(
old
)
# print(self.image2[2,:,0,0] - self.image2[3,:,0,0])
# print("max diff ",np.max(np.abs(self.image2[2]-self.image2[3])))
# print("max diff ",np.max(np.abs(self.image2[2]-self.image2[3])))
# print("alternative");
# print("alternative");
# indices = np.where(np.abs(self.image2[0,:,:,0] -
# indices = np.where(np.abs(self.image2[2] -
# self.image2[1,:,:,0])
# self.image2[3])
# ==np.max(np.abs(self.image2[0,:,:,0]
# ==np.max(np.abs(self.image2[2]
# - self.image2[1,:,:,0])))
# - self.image2[3])))
# print("indices", indices)
# print("first image", self.image2[2,indices[0],indices[1],indices[2]],
# print("first image")
# "second image",self.image2[3,indices[0],indices[1],indices[2]])
# print(self.image[0,0,:,0])
# print(np.sum(np.abs(self.image2[2,:,:,0]-self.image2[3,:,:,0])))
# print("second image")
# print("max diff ",np.max(np.abs(self.image2[2]-self.image2[3])))
# print(self.image[1,0,:,0])
# assert np.all(np.isclose(self.image2[2],self.image2[3], atol = 1.2))
# conv2= renderer.camera_rotation_mode
# print("angels xyz",a,b,c,"angles yzx",at,bt,ct)
# print("sh be yzx",conv,"sh be xyz",conv2)
# print(np.sum(np.abs(self.image[0,:,:,0]-self.image[1,:,:,0])))
# print(np.all(np.isclose(self.image[0], self.image[1])))
# assert np.testing.assert_allclose(self.image[0],
# self.image[1], atol = 0.007)
This diff is collapsed.
Click to expand it.
navipy/sensors/renderer.py
+
19
−
10
View file @
cbaca8ae
...
@@ -293,7 +293,7 @@ class BlenderRender():
...
@@ -293,7 +293,7 @@ class BlenderRender():
[convention][alpha_1]
[convention][alpha_1]
[convention][alpha_2]
[convention][alpha_2]
**where convention can be:
**where convention can be:
s
xyz,
s
xzy,
s
yxz,
s
yzx,
s
zyx,
s
zxy
r
xyz,
r
xzy,
r
yxz,
r
yzx,
r
zyx,
r
zxy
*in case of quaternions the index should be
*in case of quaternions the index should be
[
'
location
'
][
'
x
'
]
[
'
location
'
][
'
x
'
]
[
'
location
'
][
'
y
'
]
[
'
location
'
][
'
y
'
]
...
@@ -310,31 +310,40 @@ class BlenderRender():
...
@@ -310,31 +310,40 @@ class BlenderRender():
"""
"""
if
isinstance
(
posorient
,
pd
.
Series
):
if
isinstance
(
posorient
,
pd
.
Series
):
# set roation mode
# set roation mode
found_convention
=
False
index
=
posorient
.
index
index
=
posorient
.
index
convention
=
index
.
get_level_values
(
0
)[
-
1
]
convention
=
index
.
get_level_values
(
0
)[
-
1
]
if
convention
==
'
s
xyz
'
:
if
convention
==
'
r
xyz
'
:
self
.
camera_rotation_mode
=
'
XYZ
'
self
.
camera_rotation_mode
=
'
XYZ
'
elif
convention
==
'
syzx
'
:
found_convention
=
True
elif
convention
==
'
ryzx
'
:
self
.
camera_rotation_mode
=
'
YZX
'
self
.
camera_rotation_mode
=
'
YZX
'
elif
convention
==
'
sxzy
'
:
found_convention
=
True
elif
convention
==
'
rxzy
'
:
self
.
camera_rotation_mode
=
'
XZY
'
self
.
camera_rotation_mode
=
'
XZY
'
elif
convention
==
'
syxz
'
:
found_convention
=
True
elif
convention
==
'
ryxz
'
:
self
.
camera_rotation_mode
=
'
YXZ
'
self
.
camera_rotation_mode
=
'
YXZ
'
elif
convention
==
'
szxy
'
:
found_convention
=
True
elif
convention
==
'
rzxy
'
:
self
.
camera_rotation_mode
=
'
ZXY
'
self
.
camera_rotation_mode
=
'
ZXY
'
elif
convention
==
'
szyx
'
:
found_convention
=
True
self
.
camera_rotation_mode
=
'
ZYX
'
elif
convention
==
'
rzyx
'
:
self
.
camera_rotation_mode
=
'
ZYX
'
found_convention
=
True
self
.
camera
.
location
=
\
self
.
camera
.
location
=
\
posorient
.
loc
[[
'
location
'
],
[
'
x
'
,
'
y
'
,
'
z
'
]].
values
posorient
.
loc
[[
'
location
'
],
[
'
x
'
,
'
y
'
,
'
z
'
]].
values
if
convention
!=
'
quaternion
'
:
if
found_
convention
:
self
.
camera
.
rotation_euler
=
\
self
.
camera
.
rotation_euler
=
\
posorient
.
loc
[[
convention
],
posorient
.
loc
[[
convention
],
[
'
alpha_0
'
,
'
alpha_1
'
,
'
alpha_2
'
]].
values
[
'
alpha_0
'
,
'
alpha_1
'
,
'
alpha_2
'
]].
values
el
se
:
el
if
convention
==
'
quaternion
'
:
self
.
camera_rotation_mode
=
'
QUATERNION
'
self
.
camera_rotation_mode
=
'
QUATERNION
'
self
.
camera
.
rotation_quaternion
=
\
self
.
camera
.
rotation_quaternion
=
\
posorient
.
loc
[[
convention
],
posorient
.
loc
[[
convention
],
[
'
q_0
'
,
'
q_1
'
,
'
q_2
'
,
'
q_3
'
]].
values
[
'
q_0
'
,
'
q_1
'
,
'
q_2
'
,
'
q_3
'
]].
values
else
:
raise
Exception
(
'
your convention is not supported
'
)
else
:
else
:
raise
TypeError
(
raise
TypeError
(
'
posorient must be of type array, list, or pandas Series
'
)
'
posorient must be of type array, list, or pandas Series
'
)
...
...
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