#include <sensor_msgs/PointCloud.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/point_cloud_conversion.h>
sensor_msgs::Pointcloud2 input_pointcloud;
sensor_msgs::Pointcloud out_pointcloud;
sensor_msgs::convertPointCloud2ToPointCloud(input_pointcloud, out_cloud);
for(int i = 0 ; i < out_cloud.points.size(); ++i){
geometry_msgs::Point32 point;
//Dooo something here
point.z = out_cloud.points[i].z;
}