WxGL application example: drawing point cloud

WxGL comes with several utility functions, among which read_pcfile is used to parse point cloud files in .ply and .pcd formats. This function returns an instance of the PointCloudData class, which contains the following properties:

  • PointCloudData.ok - whether the data is available, Boolean
  • PointCloudData.info - data availability description, string
  • PointCloudData.raw - interpreted raw data, dictionary
  • PointCloudData.fields - list of data field (item) names
  • PointCloudData.xyz - point coordinate data, None or numpy array (ndarray)
  • PointCloudData.rgb - point color data, None or numpy array (ndarray)
  • PointCloudData.intensity - point intensity data, None or numpy array (ndarray)

The following code demonstrates the use of the read_pcfile function in IDLE, and the point cloud file used can be downloaded from this address: https://github.com/xufive/wxgl/tree/master/example/res/pointcloud .

>>> import wxgl
>>> ds = wxgl.read_pcfile('/Users/xufive/MyCode/pc/bunny.ply')
>>> ds.ok
True
>>> ds.info
'正常:数据可用'
>>> ds.fields
['x', 'y', 'z', 'confidence', 'intensity']
>>> ds.raw['intensity'].shape
(35947,)
>>> ds.xyz.shape
(35947, 3)

After the data is interpreted, the point cloud model can be drawn by calling the app.scatter method.

>>> app = wxgl.App()
>>> app.scatter(ds.xyz)
>>> app.show()

insert image description here

Usually point cloud data does not carry color information, but may contain laser reflection intensity. If there is color information in the data, or the intensity information is used to map to color, the user needs to judge by himself and provide the color (color) parameter, or data (data) and cm (palette) parameters in the app.scatter method. There is another simpler way, which is to directly use the app.pointcloud method, which only needs one point cloud file parameter to draw the point cloud model, and this method will automatically identify whether the file contains color information and laser intensity information.

>>> import wxgl
>>> app = wxgl.App(haxis='z', bg='#001020')
>>> app.pointcloud('/Users/xufive/MyCode/pc/isprs/4.pcd')
>>> app.show()

insert image description here

Guess you like

Origin blog.csdn.net/xufive/article/details/130489670