点群に利用できるファイル・メッセージの中身と相互変換

# はじめに
点群のフォーマット相互変換の際に、中身がどんな感じになっているか調べてみました。

# PointCloud
~~~
 # .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH 640
HEIGHT 480
VIEWPOINT 0 0 0 1 0 0 0
POINTS 307200
DATA ascii
0.93773 0.33763 0 4.2108e+06
0.90805 0.35641 0 4.2108e+06
 ...
~~~

### sensor_msgs/PointCloud Message
http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/PointCloud.html

# PointCloud2(PCL2)

~~~
header: 
  seq: 1071
  stamp: 
    secs: 1521699326
    nsecs: 676390000
  frame_id: "velodyne"
height: 1
width: 66811
fields: 
  - 
    name: "x"
    offset: 0
    datatype: 7
    count: 1
  - 
    name: "y"
    offset: 4
    datatype: 7
    count: 1
  - 
    name: "z"
    offset: 8
    datatype: 7
    count: 1
  - 
    name: "intensity"
    offset: 16
    datatype: 7
    count: 1
  - 
    name: "ring"
    offset: 20
    datatype: 4
    count: 1
is_bigendian: False
point_step: 32
row_step: 2137952
data: [235, 171, 54, 190, 53, 107, 250, ...
~~~
### sensor_msgs/PointCloud2 Message
http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/PointCloud2.html

# obj
~~~
# File exported by xxx 3D Scanning Solutions
# www.xxxx.com

# 249773 vertices
# 499690 triangular faces

mtllib 

v 142.617905 159.840195 -363.391907
v 141.223602 162.207703 -365.891907
 ...
~~~

https://www.hiramine.com/programming/3dmodelfileformat/objfileformat.html

# ply
データ部分はバイナリになっているが、ASCII形式でも作成可能。
可読性が落ちるが、バイナリを使用した方が効率が良い。
### バイナリ版

~~~
ply
format binary_little_endian 1.0
comment File exported by xxx 3D Scanning Solutions
comment www.xxx.com
element vertex 249773
property float x
property float y
property float z
element face 499690
property list uchar int vertex_indices
end_header
/�C�C*���>9
C,5"C*��É"C�!C-���@�����ݵ�ߠ=�Z��ô>�V�ö�$x=����õqZC�)^ê���
~~~

### ASCII版
~~~
ply
format ascii 1.0
comment author: Greg Turk
comment object: another cube
element vertex 8
property float x
property float y
property float z
property uchar red                   { start of vertex color }
property uchar green
property uchar blue
element face 7
property list uchar int vertex_index  { number of vertices for each face }
element edge 5                        { five edges in object }
property int vertex1                  { index to first vertex of edge }
property int vertex2                  { index to second vertex }
property uchar red                    { start of edge color }
property uchar green
property uchar blue
end_header
0 0 0 255 0 0                         { start of vertex list }
0 0 1 255 0 0
0 1 1 255 0 0
0 1 0 255 0 0
1 0 0 0 0 255
1 0 1 0 0 255
1 1 1 0 0 255
1 1 0 0 0 255
3 0 1 2                           { start of face list, begin with a triangle }
3 0 2 3                           { another triangle }
4 7 6 5 4                         { now some quadrilaterals }
4 0 4 5 1
4 1 5 6 2
4 2 6 7 3
4 3 7 4 0
0 1 255 255 255                   { start of edge list, begin with white edge }
1 2 255 255 255
2 3 255 255 255
3 0 255 255 255
2 0 0 0 0                         { end with a single black line }
~~~

https://jp.mathworks.com/help/vision/ug/the-ply-format.html

### 参考
https://qiita.com/SatoshiGachiFujimoto/items/d368ce499a549def1ba6

# 相互変換方法
C++のPointCloudLibraryを使えばPointCloudを起点に全ての形式で相互変換できそうです。

https://pointclouds.org/documentation/index.html

https://github.com/PointCloudLibrary