2017-01-30 58 views
0

情况:快速索引到数据阵列

我有UINT8的数据阵列(例如UINT8(零(24 * 30000,1))),其编码24各字节的30000点。说,我有一个指向这个数据数组的数组,例如1:2:30000。我知道想要有效地为指向向量中引用的点创建正确的数据数组。例如,当尝试使用Robotics系统工具箱从'sensor_msgs/PointCloud2'消息中删除点时会发生这种情况。

解决方案

到现在为止,我的解决办法是这样的上述

startIndices = (pointIndices-1) * double(pointCloud_out.PointStep) + 1; 
endIndices = pointIndices * double(pointCloud_out.PointStep); 
indices = zeros(pointCloud_out.RowStep,1); 
for ii = 1:numel(pointIndices) 
    indices((ii-1)*pointCloud_out.PointStep+1 : ii*pointCloud_out.PointStep) = startIndices(ii):endIndices(ii); 
end 
pointCloud_out.Data = pointCloud_in_msg.Data(indices); 

其中pointIndices是上述指数之向量和pointCloud_out.PointStep编码多少字节有一个点( 24)。然而,这个解决方案在我的机器上需要大约1.5秒,而且这个解决方案需要很长的时间。

问:

你能想到的任何(非常)快速的解决方案做到这一点的?

+0

我对你在问什么有点困惑。 pointCloud(:,indices)'有什么问题? – Suever

+0

@Suever:pointCloud(-2消息)的数据字段是一个m×1的矩阵,在这里 – user1809923

回答

1

您可以使用(0:PointStep-1)bsxfun

indices = reshape(bsxfun(@plus, startIndices , (0:pointCloud_out.PointStep-1).'),[],1); 

值加到假定startIndicesstartIndices

每个成员都有大小1 * n

+0

工作!必须改变为索引= reshape(bsxfun(@plus,startIndices,(0:double(pointCloud_out.PointStep)-1))',[],1); ,因为我的startIndices是nx1 – user1809923

0

想出了这个解决方案:

pointsInCols = reshape(pointCloud_in_msg.Data,pointCloud_in_msg.PointStep,[]); 
pointCloud_out.Data = reshape(pointsInCols(:,pointIndices),[],1); 

首先对数据数组进行重构,使每列对应一个点。然后我们将所有我们感兴趣的点再次重新塑形。这个解决方案在我的PC上大约需要0.003秒。