def clusterFacetSamplesKNN(self, reduceRatio=3, maxNPnts=5):
"""
cluster the samples of each facet using k nearest neighbors
the cluster center and their correspondent normals will be saved
in self.objsamplepnts_refcls and self.objsamplenrmals_refcls
:param: reduceRatio: the ratio of points to reduce
:param: maxNPnts: the maximum number of points on a facet
:return: None
author: weiwei
date: 20161129, tsukuba
"""
self.objsamplepnts_refcls = np.ndarray(shape=(self.facets.shape[0],), dtype=np.object)
self.objsamplenrmls_refcls = np.ndarray(shape=(self.facets.shape[0],), dtype=np.object)
for i, facet in enumerate(self.facets):
self.objsamplepnts_refcls[i] = np.empty(shape=(0,0))
self.objsamplenrmls_refcls[i] = np.empty(shape=(0,0))
X = self.objsamplepnts_ref[i]
nX = X.shape[0]
if nX > reduceRatio:
kmeans = KMeans(n_clusters=maxNPnts if nX/reduceRatio>maxNPnts else nX/reduceRatio, random_state=0).fit(X)
self.objsamplepnts_refcls[i] = kmeans.cluster_centers_
self.objsamplenrmls_refcls[i] = np.tile(self.facetnormals[i], [self.objsamplepnts_refcls.shape[0],1])
评论列表
文章目录