기본 구조 (ASCII version of cube)
ply
format ascii 1.0 { **ascii/binary**, format version number }
comment made by Greg Turk { comments keyword specified, like all lines }
comment this file is a cube
element vertex 8 { define "vertex" element, 8 of them in file }
property float x { vertex contains float "x" coordinate }
property float y { y coordinate is also a vertex property }
property float z { z coordinate, too }
element face 6 { there are 6 "face" elements in the file }
property list uchar int vertex_index { "vertex_indices" is a list of ints }
end_header { delimits the end of the header }
0 0 0 { start of vertex list }
0 0 1
0 1 1
0 1 0
1 0 0
1 0 1
1 1 1
1 1 0
4 0 1 2 3 { start of face list }
4 7 6 5 4
4 0 4 5 1
4 1 5 6 2
4 2 6 7 3
4 3 7 4 0
Reference Site
Installation
$ pip3 install open3d
Simple code for visualized .ply file
from open3d import *
def main():
ply_path = "~/xxx.ply"
cloud = io.read_point_cloud(ply_path) # Read point cloud
visualization.draw_geometries([cloud]) # Visualize point cloud
if __name__ == "__main__":
main()
Reference Site
Installation
$ pip3 install pptk
$ pip3 install plyfile
Simple code for visualized .ply file
import pptk
import numpy as np
import plyfile
ply_path = "~/xxx.ply"
data = plyfile.PlyData.read(ply_path)['vertex']
xyz = np.c_[data['x'], data['y'], data['z']]
rgb = np.c_[data['red'], data['green'], data['blue']]
n = np.c_[data['nx'], data['ny'], data['nz']]
v = pptk.viewer(xyz)
v.attributes(rgb / 255., 0.5 * (1 + n))
Reference Site
Installation
$ pip3 install pyntcloud
[참고] Plot을 위한 여려 flag 및 argument들이 존재!!
def plot(self, backend=None, scene=None, width=800, height=500,
background="black", mesh=False, use_as_color=["red", "green", "blue"],
initial_point_size=None, cmap="hsv", polylines=None,
linewidth=5, return_scene=False, output_name="pyntcloud_plot",
elev=0., azim=90., **kwargs):
"""Visualize a PyntCloud using different backends.
Parameters
----------
backend: {"pythreejs", "threejs", "pyvista", "matplotlib"}, optional
Default: "pythreejs"
Used to select one of the available libraries for plotting.
width: int, optional
Default: 800
height: int, optional
Default: 500
background: str, optional
Default: "black"
Used to select the default color of the background.
In some backends, i.e "pythreejs" the background can be dynamically changed.
use_as_color: str or ["red", "green", "blue"], optional
Default: ["red", "green", "blue"]
Indicates which scalar fields will be used to colorize the rendered
point cloud.
initial_point_size: the initial size of each point in the rendered point cloud.
Can be adjusted after rendering using slider.
cmap: str, optional
Default: "hsv"
Color map that will be used to convert a single scalar field into rgb.
Check matplotlib cmaps.
return_scene: bool, optional
Default: False.
Used with "pythreejs" backend in order to return the pythreejs.Scene object
polylines: list of dict, optional
Default None.
List of dictionaries defining polylines with the following syntax:
polylines=[
{
"color": "0xFFFFFF",
"vertices": [[0, 0, 0], [0, 0, 1]]
},
{ {
"color": "red",
"vertices": [[0, 0, 0], [0, 0, 1], [0, 2, 0]
}
]
elev: float
Elevation angle in the z plane. Used for matplotlib
azim: float
Azimuth angle in the x,y plane.
"""
from pyntcloud import PyntCloud
import matplotlib
ply_path = "./xxx.ply"
cloud = PyntCloud.from_file(ply_path)
# There are a lot of visualization method (library) !! -> **"pythreejs", "threejs", "pyvista", "matplotlib"**
# And this package also can use in Jupyter notebook !!
# cloud.plot(use_as_color="x", cmap="cool", backend="matplotlib")
cloud.plot(backend="matplotlib", mesh=True, cmap="hsv")
cloud.plot(use_as_color="x", cmap="cool", backend="matplotlib")
cloud.plot(backend="matplotlib", mesh=True, cmap="hsv")
Reference Site
필요한 형식이 담겨 있는 code (3DPlyModel.cpp)
for(auto itr = items.begin(); itr != items.end(); itr++){
if(*(itr) == string("format") && *(itr+1) != string("ascii")){
cerr << "Codification not supported. (Ply loading)" << endl;
return;
}
if(*(itr) == string("vertex")){
np = stoi(*(itr+1));
points.resize(np);
}
if(*(itr) == string("face")){
nf = stoi(*(itr+1));
faces.resize(nf);
}
if(*(itr) == string("nx")){
hasNormals = true;
normals.resize(np);
}
if(*(itr) == string("s")){
hasTexture = true;
uv_coordinates.resize(np);
}
}
items.clear();
Installation
$ pip3 install plyfile
Convert BINARY to ASCII ply file !
import plyfile
data = plyfile.PlyData.read('./xxx.ply')
data.text = True
data.write('xxx_ascii.ply')
Reference Site
Installation
$ git clone https://github.com/mateus558/PLY-models-viewer.git
$ cd ./PLY-models-viewer
$ g++ -g --std=c++11 main.cpp 3DPlyModel.cpp glcTexture.cpp -o main -lpng -lGL -lGLU -lglut
$ ./main <PLY file>
Reference Site
Installation
$ pip3 install vedo
"""Specify a colors for cells
and points of a Mesh"""
from vedo import dataurl, Plotter, Mesh
plt = Plotter(N=3, axes=11)
##################################### add a cell array
man1 = Mesh(dataurl+"man_low.vtk").linewidth(0.1)
nv = man1.ncells # nr. of cells
scals = range(nv) # coloring by the index of cell
man1.cmap("Paired", scals, on='cells').add_scalarbar("cell nr")
plt.at(0).show(man1, __doc__, elevation=-60)
##################################### Point coloring
man2 = Mesh(dataurl+"man_low.vtk")
scals = man2.points()[:, 0] + 37 # pick x coordinates of vertices
man2.cmap("hot", scals)
man2.add_scalarbar(horizontal=True)
plt.at(1).show(man2, "mesh.cmap()")
##################################### Cell coloring
man3 = Mesh(dataurl+"man_low.vtk")
scals = man3.cell_centers()[:, 2] + 37 # pick z coordinates of cells
man3.cmap("afmhot", scals, on='cells')
# add a fancier 3D scalar bar embedded in the scene
man3.add_scalarbar3d(size=[None,3])
man3.scalarbar.rotate_x(90).y(0.2)
plt.at(2).show(man3, "mesh.cmap(on='cells')")
plt.interactive().close()
from vedo import *
mesh = Mesh("~/xxx.obj",)
mesh.show()
Reference Site
Installation
$ pip3 install open3d
Simple code for visualized .obj file
from open3d import *
def main():
ply_path = "~/xxx.obj"
cloud = io.read_triangle_mesh(ply_path) # Read point cloud
vis = visualization.Visualizer()
vis.create_window()
vis.add_geometry(cloud) # Visualize point cloud
vis.run()
vis.destroy_window()
if __name__ == "__main__":
main()
Reference Site