1
from __future__ import division
3
roslib.load_manifest('mrol-mapping-ros-pkg')
6
#import matplotlib.axes3d as p3
7
import mpl_toolkits.mplot3d.axes3d as p3
8
import mrol_mapping.mapper as mapper
9
import mrol_mapping.poseutil as poseutil
11
import icp_mrol.icp_mrol as icp
15
def load_and_align(bestpose, fname, First=False, ICP=False):
16
xyzs = np.loadtxt(fname)
17
#(xyzs, _) = poseutil.transformPoints(xyzs, (0,0,0,np.deg2rad(60),0,0))
18
xyzs = xyzs[(xyzs[:,0]<-0.1)]
19
xyzs = xyzs[(xyzs[:,0]>-0.5)]
20
xyzs = xyzs[(xyzs[:,1]<0.5)]
21
xyzs = xyzs[(xyzs[:,1]>0.25)]
22
xyzs = xyzs[(xyzs[:,2]>1.)]
23
xyzs = xyzs[(xyzs[:,2]<1.3)]
28
bestpose = cupMapper.align_points(xyzs, bestpose)[0]
30
bestpose = icp.align(bestpose, xyzs, cupMapper.get_voxels(), reject_threshold=res*10., terminate_threshold=res/100., iterations = 100, quiet=True)[0]
31
(transform, _) = poseutil.transformPoints(xyzs, bestpose)
32
return transform, bestpose
38
cupMapper = mapper.VoxelMap(res,levels=6)
39
cupMapper.set_feature_range(0.25)
40
initpose = (0,0,0,0,0,0)
42
cup1, pose = load_and_align(initpose, 'segmented_points225.dat', First=True)
43
cupMapper.add_points(cup1,initpose)
45
ax.plot3D(cup1[:,0],cup1[:,1],cup1[:,2],'.')
50
#p.show() # ctrl-c here?
54
cup2, pose = load_and_align(initpose, 'segmented_points234.dat')
55
ax.plot3D(cup2[:,0],cup2[:,1],cup2[:,2],'.')
57
cupMapper.add_points(cup2,initpose)
59
cup3, pose = load_and_align(initpose, 'segmented_points265.dat')
60
ax.plot3D(cup3[:,0],cup3[:,1],cup3[:,2],'.')
62
cupMapper.add_points(cup3,initpose)
64
cup4, pose = load_and_align(initpose, 'segmented_points273.dat')
65
ax.plot3D(cup4[:,0],cup4[:,1],cup4[:,2],'.')
67
cupMapper.add_points(cup4,initpose)
69
cup5, pose = load_and_align(initpose, 'segmented_points296.dat')
70
ax.plot3D(cup5[:,0],cup5[:,1],cup5[:,2],'.')
72
cupMapper.add_points(cup5,initpose)
74
cup6, pose = load_and_align(initpose, 'segmented_points308.dat')
75
ax.plot3D(cup6[:,0],cup6[:,1],cup6[:,2],'.')
77
cupMapper.add_points(cup6,initpose)
79
cupModel = cupMapper.get_voxels()
80
cupModel = cupModel - np.mean(cupModel,axis=0)
82
np.savetxt('cupModel.dat',cupModel)
86
ax.plot3D(cupModel[:,0],cupModel[:,1],cupModel[:,2],'.')