Skip to content

Commit 0fd7d52

Browse files
author
Tanbakuchi
committed
Starting attempt for adding fitting functions, not yet working. Need to figure out how to subclass to make it work.
1 parent f17c686 commit 0fd7d52

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

pcl/_pcl.pyx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,19 @@ cdef class SegmentationNormal:
9595
is currently unable to do so.
9696
"""
9797
cdef cpp.SACSegmentationNormal_t *me
98+
# cdef cpp.ModelCoefficients *coeffs
9899
def __cinit__(self):
99100
self.me = new cpp.SACSegmentationNormal_t()
101+
# self._coeffs = None
100102
def __dealloc__(self):
101103
del self.me
104+
# del self._coeffs
102105

103106
def segment(self):
104107
cdef cpp.PointIndices ind
105108
cdef cpp.ModelCoefficients coeffs
106109
self.me.segment (ind, coeffs)
110+
# self._coeffs = coeffs
107111
return [ind.indices[i] for i in range(ind.indices.size())],\
108112
[coeffs.values[i] for i in range(coeffs.values.size())]
109113

@@ -127,6 +131,41 @@ cdef class SegmentationNormal:
127131
self.me.setEpsAngle (ea)
128132
def set_axis(self, double ax, double ay, double az):
129133
mpcl_sacnormal_set_axis(deref(self.me),ax,ay,az)
134+
def set_min_max_opening_angle(self, double min_angle, double max_angle):
135+
""" Set the minimum and maximum cone opening angles in radians for a cone model.
136+
"""
137+
self.me.setMinMaxOpeningAngle(min_angle, max_angle)
138+
def get_min_max_opening_angle(self):
139+
min_angle = 0.0
140+
max_angle = 0.0
141+
self.me.getMinMaxOpeningAngle(min_angle, max_angle)
142+
return min_angle, max_angle
143+
144+
145+
cdef class SampleConsensusModelCylinder(SegmentationNormal):
146+
147+
cdef cpp.SampleConsensusModelCylinder_t *me
148+
# cdef cpp.ModelCoefficients *coeffs
149+
def __cinit__(self):
150+
self.me = new cpp.SACSegmentationNormal_t()
151+
152+
def get_distance_to_model(self, list model_coefficients):
153+
""" Compute all distances from the model. You must have already fit the model.
154+
:return: vector of distances
155+
"""
156+
157+
cdef vector[double] distances
158+
159+
self.me.getDistancesToModel(self._coeffs, distances)
160+
# def count_within_distance(self, list model_coefficients, double threshold):
161+
# cdef cpp.ModelCoefficients coeffs
162+
# cdef vector[float] vals = model_coefficients
163+
# coeffs.values = vals
164+
# #coeffs.values.resize(len(model_coefficients))
165+
# # for i, v in enumerate(model_coefficients):
166+
# # coeffs.value[i] = v
167+
# return self.me.countWithinDistance(vals, threshold)
168+
130169

131170

132171
# Empirically determine strides, for buffer support.

pcl/pcl_defs.pxd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ cdef extern from "pcl/segmentation/sac_segmentation.h" namespace "pcl":
6868
void setInputNormals (shared_ptr[PointCloud[N]])
6969
void setEpsAngle (double ea)
7070
void segment (PointIndices, ModelCoefficients)
71+
void setMinMaxOpeningAngle(double, double)
72+
void getMinMaxOpeningAngle(double, double)
73+
7174

7275
cdef cppclass SACSegmentation[T]:
7376
void setOptimizeCoefficients (bool)
@@ -77,6 +80,14 @@ cdef extern from "pcl/segmentation/sac_segmentation.h" namespace "pcl":
7780
void setInputCloud (shared_ptr[PointCloud[T]])
7881
void segment (PointIndices, ModelCoefficients)
7982

83+
cdef extern from "pcl/sample_consensus/sac_model_cylinder.h" namespace "pcl":
84+
85+
cdef cppclass SampleConsensusModelCylinder[T, N]:
86+
int countWithinDistance(vector[double], double)
87+
void getDistancesToModel(vector[double], vector[double])
88+
89+
90+
8091
ctypedef SACSegmentation[PointXYZ] SACSegmentation_t
8192
ctypedef SACSegmentationFromNormals[PointXYZ,Normal] SACSegmentationNormal_t
8293

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy