Tip
在针对类中非 public
成员函数编写函数接口时,不应该像 public
成员函数一样不写传参变量。非 public
成员函数传参变量在函数内部被调用时,有利于及时输出数据进行可视化,在调用该非 public
成员函数的函数内部进行调试时,可只对数据输入输出进行观察,而不用关心非 public
成员函数内部实现细节,内部实现细节应该和调试阶段分开。
同时,对每一个输出非 public
成员函数的形参变量,在调用该非 public
成员函数内部的开始应进行数据清楚,以达到在调用该函数的内部相同类型临时变量容器的重复利用,这样做的目的是节省内存运行空间。
实例
bool KittiPCL::filtCloudWithNormalZ(const PointCloudXYZI::ConstPtr &in_cloud,
PointCloudXYZI::Ptr &out_cloud, const float &beam_range)
{
if ( beam_range <= 0 || beam_range > 1 )
{
std::cerr << "KittiPCL::filtCloudWithNormalZ(): Beam range NOT correct!" << std::endl;
return false;
}
out_cloud->clear();
//classify point with normal z
PointCloudXYZINormal::Ptr cloud_normal ( new PointCloudXYZINormal );
this->computeNormal( in_cloud, cloud_normal );
int beam_size;
beam_size = static_cast<int >( 1 / beam_range );
std::vector<PointCloudXYZI> classify_cloud_vec;
classify_cloud_vec.resize( beam_size );
int beam_num = 0;
for (int i = 0; i < cloud_normal->size(); ++i)
{
if ( isnan( cloud_normal->at(i).x ) )
continue;
if ( cloud_normal->at(i).normal_z < 0 )
beam_num = - static_cast< int > ( cloud_normal->at(i).normal_z / beam_range );
else
beam_num = static_cast< int > ( cloud_normal->at(i).normal_z / beam_range );
if ( beam_num >= 0 && beam_num < beam_size )
classify_cloud_vec[ beam_num ].push_back( in_cloud->at(i) );
}
//find the largest size point cloud
size_t pts_size = 0;
size_t largest_num = 0;
for (int j = 0; j < classify_cloud_vec.size(); ++j)
{
if ( pts_size < classify_cloud_vec[j].size() )
{
pts_size = classify_cloud_vec[j].size();
largest_num = j;
}
}
*out_cloud = classify_cloud_vec[largest_num];
return true;
}
void KittiPCL::generateGroundCloud(PointCloudXYZI::Ptr &out_cloud, visualization_msgs::MarkerPtr &plane_marker)
{
PointCloudXYZI::Ptr operat_cloud ( new PointCloudXYZI );
*operat_cloud = *kitti_organised_cloud_ptr_;
//1. compute transform matrix
PointCloudXYZI::Ptr normal_filt_cloud ( new PointCloudXYZI );
this->filtCloudWithNormalZ( operat_cloud, normal_filt_cloud );
}