Example Load and Save Point Clouds

From BoofCV
Revision as of 14:09, 12 July 2021 by Peter (talk | contribs) (Created page with "Loading and saving a point cloud. '''Example Code:''' * [https://github.com/lessthanoptimal/BoofCV/blob/v0.38/examples/src/main/java/boofcv/examples/pointclouds/ExampleLoadAn...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Loading and saving a point cloud.

Example Code:

Concepts:

  • 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
		PointCloudIO.save3D(PointCloudIO.Format.PLY,
				PointCloudReader.wrap(
						// passed in (x,y,z) and rgb info
						( index, point ) -> point.setTo(original.getTemp(index)),
						// specifies the number of points
						original.size()),
				/* 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
		file.delete();
	}
}