Example Load and Save Point Clouds

From BoofCV
Jump to navigationJump to search

Loading and saving a point cloud.

Example Code:


  • 3D Point Cloud

Related Examples:

Example Code

 * Example showing how to load and save a point cloud.
 * @author Peter Abeles
public class ExampleLoadAndSavePointCloud {
	public static void main( String[] args ) throws IOException {
		File file = File.createTempFile("boofcv", "txt");

		// Creating a point cloud and storing it in a more "exotic" format used when dealing with a very large
		// number of points.
		PackedArray<Point3D_F64> original = new PackedBigArrayPoint3D_F64();
		for (int i = 0; i < 100; i++) {
			// create arbitrary points
			original.append(new Point3D_F64(i, i + 1, -i));

		System.out.println("original.size=" + original.size());

		// Save the colorless point cloud
						// passed in (x,y,z) and rgb info
						( index, point ) -> point.setTo(original.getTemp(index)),
						// specifies the number of points
				/* saveRGB */false, new FileOutputStream(file));

		// create another arbitrary format to store the loaded results
		List<Point3D_F64> found = new ArrayList<>();

		PointCloudIO.load(PointCloudIO.Format.PLY, new FileInputStream(file),
				( x, y, z, rgb ) -> found.add(new Point3D_F64(x, y, z)));
		// There's a non functional version of load() which will provide the writer with information about the
		// clouds size and format.

		System.out.println("found.size=" + found.size());

		// clean up