@@ -13,12 +13,10 @@ cimport pcl_defs as cpp
13
13
np.import_array()
14
14
15
15
16
- cdef extern from " pcl/registration/icp .h" namespace " pcl" :
17
- cdef cppclass IterativeClosestPoint [Source, Target]:
16
+ cdef extern from " pcl/registration/registration .h" namespace " pcl" nogil :
17
+ cdef cppclass Registration [Source, Target]:
18
18
cppclass Matrix4:
19
19
float * data()
20
-
21
- IterativeClosestPoint() except +
22
20
void align(cpp.PointCloud[Source] & ) except +
23
21
Matrix4 getFinalTransformation() except +
24
22
double getFitnessScore() except +
@@ -27,49 +25,45 @@ cdef extern from "pcl/registration/icp.h" namespace "pcl":
27
25
void setInputTarget(cpp.PointCloudPtr_t) except +
28
26
void setMaximumIterations(int ) except +
29
27
30
- cdef extern from " pcl/registration/gicp.h" namespace " pcl" :
31
- cdef cppclass GeneralizedIterativeClosestPoint[Source, Target]:
32
- cppclass Matrix4:
33
- float * data()
28
+ cdef extern from " pcl/registration/icp.h" namespace " pcl" nogil:
29
+ cdef cppclass IterativeClosestPoint[Source, Target](Registration[Source, Target]):
30
+ IterativeClosestPoint() except +
34
31
32
+ cdef extern from " pcl/registration/gicp.h" namespace " pcl" nogil:
33
+ cdef cppclass GeneralizedIterativeClosestPoint[Source, Target](Registration[Source, Target]):
35
34
GeneralizedIterativeClosestPoint() except +
36
- void align(cpp.PointCloud[Source] & ) except +
37
- Matrix4 getFinalTransformation() except +
38
- double getFitnessScore() except +
39
- bool hasConverged() except +
40
- void setInputSource(cpp.PointCloudPtr_t) except +
41
- void setInputTarget(cpp.PointCloudPtr_t) except +
42
- void setMaximumIterations(int ) except +
43
35
36
+ cdef extern from " pcl/registration/icp_nl.h" namespace " pcl" nogil:
37
+ cdef cppclass IterativeClosestPointNonLinear[Source, Target](Registration[Source, Target]):
38
+ IterativeClosestPointNonLinear() except +
44
39
45
- cdef extern from " pcl/registration/icp_nl.h" namespace " pcl" :
46
- cdef cppclass IterativeClosestPointNonLinear[Source, Target]:
47
- cppclass Matrix4:
48
- float * data()
49
40
50
- IterativeClosestPointNonLinear() except +
51
- void align(cpp.PointCloud[Source] & ) except +
52
- Matrix4 getFinalTransformation() except +
53
- double getFitnessScore() except +
54
- bool hasConverged() except +
55
- void setInputSource(cpp.PointCloudPtr_t) except +
56
- void setInputTarget(cpp.PointCloudPtr_t) except +
57
- void setMaximumIterations(int ) except +
41
+ cdef object run(Registration[cpp.PointXYZ, cpp.PointXYZ] & reg,
42
+ _pcl.PointCloud source, _pcl.PointCloud target, max_iter = None ):
43
+ reg.setInputSource(source.thisptr_shared)
44
+ reg.setInputTarget(target.thisptr_shared)
45
+
46
+ if max_iter is not None :
47
+ reg.setMaximumIterations(max_iter)
48
+
49
+ cdef _pcl.PointCloud result = _pcl.PointCloud()
58
50
51
+ with nogil:
52
+ reg.align(result.thisptr()[0 ])
59
53
60
- cdef object transf_to_numpy(const float * data):
61
- # Convert (copy) transformation matrix from Eigen to NumPy format.
62
- # data should be the buffer of an Eigen 4x4 matrix.
54
+ # Get transformation matrix and convert from Eigen to NumPy format.
55
+ cdef Registration[cpp.PointXYZ, cpp.PointXYZ].Matrix4 mat
56
+ mat = reg.getFinalTransformation()
63
57
cdef np.ndarray[dtype= np.float32_t, ndim= 2 , mode= ' c' ] transf
64
58
cdef np.float32_t * transf_data
65
59
66
60
transf = np.empty((4 , 4 ), dtype = np.float32, order = ' c' )
67
61
transf_data = < np.float32_t * > np.PyArray_DATA(transf)
68
62
69
63
for i in range (16 ):
70
- transf_data[i] = data[i]
64
+ transf_data[i] = mat. data() [i]
71
65
72
- return transf
66
+ return reg.hasConverged(), transf, result, reg.getFitnessScore()
73
67
74
68
75
69
def icp (_pcl.PointCloud source , _pcl.PointCloud target , max_iter = None ):
@@ -96,22 +90,8 @@ def icp(_pcl.PointCloud source, _pcl.PointCloud target, max_iter=None):
96
90
fitness : float
97
91
Sum of squares error in the estimated transformation.
98
92
"""
99
-
100
93
cdef IterativeClosestPoint[cpp.PointXYZ, cpp.PointXYZ] icp
101
-
102
- icp.setInputSource(source.thisptr_shared)
103
- icp.setInputTarget(target.thisptr_shared)
104
-
105
- if max_iter is not None :
106
- icp.setMaximumIterations(max_iter)
107
-
108
- cdef _pcl.PointCloud result = _pcl.PointCloud()
109
-
110
- icp.align(result.thisptr()[0 ])
111
-
112
- transf = transf_to_numpy(icp.getFinalTransformation().data())
113
-
114
- return icp.hasConverged(), transf, result, icp.getFitnessScore()
94
+ return run(icp, source, target, max_iter)
115
95
116
96
117
97
def gicp (_pcl.PointCloud source , _pcl.PointCloud target , max_iter = None ):
@@ -138,22 +118,8 @@ def gicp(_pcl.PointCloud source, _pcl.PointCloud target, max_iter=None):
138
118
fitness : float
139
119
Sum of squares error in the estimated transformation.
140
120
"""
141
-
142
121
cdef GeneralizedIterativeClosestPoint[cpp.PointXYZ, cpp.PointXYZ] gicp
143
-
144
- gicp.setInputSource(source.thisptr_shared)
145
- gicp.setInputTarget(target.thisptr_shared)
146
-
147
- if max_iter is not None :
148
- gicp.setMaximumIterations(max_iter)
149
-
150
- cdef _pcl.PointCloud result = _pcl.PointCloud()
151
-
152
- gicp.align(result.thisptr()[0 ])
153
-
154
- transf = transf_to_numpy(gicp.getFinalTransformation().data())
155
-
156
- return gicp.hasConverged(), transf, result, gicp.getFitnessScore()
122
+ return run(gicp, source, target, max_iter)
157
123
158
124
159
125
def icp_nl (_pcl.PointCloud source , _pcl.PointCloud target , max_iter = None ):
@@ -181,19 +147,5 @@ def icp_nl(_pcl.PointCloud source, _pcl.PointCloud target, max_iter=None):
181
147
fitness : float
182
148
Sum of squares error in the estimated transformation.
183
149
"""
184
-
185
150
cdef IterativeClosestPointNonLinear[cpp.PointXYZ, cpp.PointXYZ] icp_nl
186
-
187
- icp_nl.setInputSource(source.thisptr_shared)
188
- icp_nl.setInputTarget(target.thisptr_shared)
189
-
190
- if max_iter is not None :
191
- icp_nl.setMaximumIterations(max_iter)
192
-
193
- cdef _pcl.PointCloud result = _pcl.PointCloud()
194
-
195
- icp_nl.align(result.thisptr()[0 ])
196
-
197
- transf = transf_to_numpy(icp_nl.getFinalTransformation().data())
198
-
199
- return icp_nl.hasConverged(), transf, result, icp_nl.getFitnessScore()
151
+ return run(icp_nl, source, target, max_iter)
0 commit comments