| 923 | //////////////////////////////////////////////////////////////////////////////////////// |
| 924 | |
| 925 | int |
| 926 | pcl::PLYWriter::writeASCII (const std::string &file_name, |
| 927 | const pcl::PCLPointCloud2 &cloud, |
| 928 | const Eigen::Vector4f &origin, |
| 929 | const Eigen::Quaternionf &orientation, |
| 930 | int precision, |
| 931 | bool use_camera) |
| 932 | { |
| 933 | if (cloud.data.empty ()) |
| 934 | { |
| 935 | PCL_ERROR ("[pcl::PLYWriter::writeASCII] Input point cloud has no data!\n"); |
| 936 | return (-1); |
| 937 | } |
| 938 | |
| 939 | std::ofstream fs; |
| 940 | fs.precision (precision); |
| 941 | // Open file |
| 942 | fs.open (file_name.c_str ()); |
| 943 | if (!fs) |
| 944 | { |
| 945 | PCL_ERROR ("[pcl::PLYWriter::writeASCII] Error during opening (%s)!\n", file_name.c_str ()); |
| 946 | return (-1); |
| 947 | } |
| 948 | |
| 949 | unsigned int nr_points = cloud.width * cloud.height; |
| 950 | |
| 951 | // Write the header information if available |
| 952 | if (use_camera) |
| 953 | { |
| 954 | fs << generateHeader (cloud, origin, orientation, false, use_camera, nr_points); |
| 955 | writeContentWithCameraASCII (nr_points, cloud, origin, orientation, fs); |
| 956 | } |
| 957 | else |
| 958 | { |
| 959 | std::ostringstream os; |
| 960 | int nr_valid_points; |
| 961 | writeContentWithRangeGridASCII (nr_points, cloud, os, nr_valid_points); |
| 962 | fs << generateHeader (cloud, origin, orientation, false, use_camera, nr_valid_points); |
| 963 | fs << os.str (); |
| 964 | } |
| 965 | |
| 966 | // Close file |
| 967 | fs.close (); |
| 968 | return (0); |
| 969 | } |
| 970 | |
| 971 | void |
| 972 | pcl::PLYWriter::writeContentWithCameraASCII (int nr_points, |