// OpenMP might seem like a good idea, but it didn't speed this up for me //#pragma omp parallel for for (int i=0; i<pc.rows; i++)//遍历pc中每一个点i { constfloat* point = pc.ptr<float>(i); //定义指针* point指向pc的第i个元素(六维) // quantize a point // xr/numSamplesDim=xr×sampleStep=实际采样距离 //(point[0]-xrange[0])/实际采样距离:代表当前坐标point[0]在第(int) 几个采样距离处 constint xCell =(int) ((float)numSamplesDim*(point[0]-xrange[0])/xr); constint yCell =(int) ((float)numSamplesDim*(point[1]-yrange[0])/yr); constint zCell =(int) ((float)numSamplesDim*(point[2]-zrange[0])/zr); constint index = xCell*numSamplesDim*numSamplesDim+yCell*numSamplesDim+zCell;
for (int j=0; j<cn; j++)//体素栅格中每一点 { constint ptInd = curCell[j];//ptInd是pc中的点的索引 float* point = pc.ptr<float>(ptInd); constdouble dx = point[0]-xc; constdouble dy = point[1]-yc; constdouble dz = point[2]-zc;//计算体素栅格中每一点与质心的距离:d constdouble d = sqrt(dx*dx+dy*dy+dz*dz); double w = 0;
if (d>EPS) { // it is possible to use different weighting schemes. // inverse weigthing was just good for me // exp( - (distance/h)**2 ) //const double w = exp(-d*d); w = 1.0/d;//由d计算权重,inverse weigthing }