Example View Point Cloud

From BoofCV
Revision as of 14:08, 12 July 2021 by Peter (talk | contribs) (Created page with "Programmically creating a 3D point cloud viewer using the built in tools. '''Example Code:''' * [https://github.com/lessthanoptimal/BoofCV/blob/v0.38/examples/src/main/java/b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Programmically creating a 3D point cloud viewer using the built in tools.

Example Code:

Concepts:

  • 3D Point Cloud

Related Examples:

Example Code

/**
 * Shows you how to open a point cloud file and display it in a simple window.
 *
 * @author Peter Abeles
 */
public class ExampleViewPointCloud {
	public static void main( String[] args ) throws IOException {
		String filePath = UtilIO.pathExample("mvs/stone_sign.ply");

		// Load the PLY file
		var cloud = new DogArray<>(Point3dRgbI_F32::new);
		PointCloudIO.load(PointCloudIO.Format.PLY, new FileInputStream(filePath), PointCloudWriter.wrapF32RGB(cloud));

		System.out.println("Total Points " + cloud.size);

		// Create the 3D viewer as a Swing panel that will have some minimal controls for adjusting the clouds
		// appearance. Since a software render is used it will get a bit sluggish (on my computer)
		// around 1,000,000 points
		PointCloudViewerPanel viewerPanel = new PointCloudViewerPanel();
		viewerPanel.setPreferredSize(new Dimension(800, 600));

		PointCloudViewer viewer = viewerPanel.getViewer();
		// Change the camera's Field-of-View
		viewer.setCameraHFov(UtilAngle.radian(60));
		// So many formats to store a 3D point and color that a functional API is used here
		viewer.addCloud(
				( idx, p ) -> ConvertFloatType.convert(cloud.get(idx), p),
				( idx ) -> cloud.get(idx).rgb, cloud.size);

		// There are a ton of options for the viewer, but we will let the GUI handle most of them
		// Alternatively, you could use VisualizeData.createPointCloudViewer(). No controls are
		// provided if you use that.

		SwingUtilities.invokeLater(() -> {
			viewerPanel.handleControlChange();
			viewerPanel.repaint();
			ShowImages.showWindow(viewerPanel, "Point Cloud", true);
		});
	}
}