歡迎訪問我的個人博客: zengzeyu.com
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 );
}
以上。