============= Read / Write ============= .. contents:: :local: Create and read a Pointcloud from file ======================================= To read a cloud from a file, the following function can be used : .. code-block:: c :linenos: pcl::PointCloud::Ptr mynewcloud(new pcl::PointCloud ); pcl::io::loadPCDFile("file/path/filename.pcd", *mynewcloud); | The type of cloud can be any of pcl::Pointxxxx. pcl::PointXYZ is a simple cloud file with (x,y,z) positions. If you need color handling, pcl::PointXYZRGB can be used. | Read the PCL documentation for more information. Read from a file (FileExplorer (Windows)) ========================================== For quick use while testing on multiple files, the following method allows to pick a file from FileExplorer on Windows : .. code-block:: c :linenos: /** * @brief Get cloud from file explorer * @tparam PointT Should be a pcl::PointXYZxxx * @param emp_cloud Cloud to fill with file * @param verbose If has to output debug on console */ template void getCloud(typename pcl::PointCloud::Ptr& emp_cloud, bool verbose = false); To use it, do as follow : .. code-block:: c :linenos: pcl::PointCloud::Ptr mynewcloud(new pcl::PointCloud ); getCloud(mynewcloud); Write to file ============== To write a cloud to a file, the following function can be used : .. code-block:: c :linenos: pcl::io::savePCDFileASCII("file/path/filename.pcd", *mynewcloud); Center cloud ============= If your cloud has an offset, it can be centered with the following function : .. code-block:: c :linenos: /** * @brief Center given cloud to (0,0,0) based on closest points to center * @tparam PointT Should be a pcl::PointXYZxxx * @param emp_cloud Cloud to center * @param verbose If has to output debug on console */ template void centerCloud(typename pcl::PointCloud::Ptr& emp_cloud, bool verbose = false); What this function does is looking for the point with the smallest x (can be negative) from the center, same with the point with the smallest y and the one with the smallest z value. It then moves the whole cloud by the inverted values to have it lying around the origin. To use it, do as follow : .. code-block:: c :linenos: centerCloud(mynewcloud); Get and center cloud ===================== Combining the two last functions, the following one load a file thanks to the FileExplorer and then center it : .. code-block:: c :linenos: /** * @brief Get cloud from file explorer and center it * @tparam PointT Should be a pcl::PointXYZxxx * @param emp_cloud Cloud to fill and center with file * @param verbose If has to output debug on console * @example * pcl::PointCloud::Ptr cloud(new pcl::PointCloud); * getAndCenterCloud(cloud,true); */ template void getAndCenterCloud(typename pcl::PointCloud::Ptr& emp_cloud, bool verbose = false); :tag:`Algorithm` :tag:`3D Algorithm` :tag:`PCL` :tag:`Point Cloud`