1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
# XXX do a more specific import!
from ._pcl import *
# vtkSmartPointer.h error (Linux)
# from .pcl_visualization import *
# from .pcl_grabber import *
import sys
def load(path, format=None):
"""Load pointcloud from path.
Currently supports PCD and PLY files.
Format should be "pcd", "ply", or None to infer from the pathname.
"""
format = _infer_format(path, format)
p = PointCloud()
try:
loader = getattr(p, "_from_%s_file" % format)
except AttributeError:
raise ValueError("unknown file format %s" % format)
if loader(_encode(path)):
raise IOError("error while loading pointcloud from %r (format=%r)"
% (path, format))
return p
def load_XYZI(path, format=None):
"""Load pointcloud from path.
Currently supports PCD and PLY files.
Format should be "pcd", "ply", or None to infer from the pathname.
"""
format = _infer_format(path, format)
p = PointCloud_PointXYZI()
try:
loader = getattr(p, "_from_%s_file" % format)
except AttributeError:
raise ValueError("unknown file format %s" % format)
if loader(_encode(path)):
raise IOError("error while loading pointcloud from %r (format=%r)"
% (path, format))
return p
def load_XYZRGB(path, format=None):
"""
Load pointcloud from path.
Currently supports PCD and PLY files.
Format should be "pcd", "ply", or None to infer from the pathname.
"""
format = _infer_format(path, format)
p = PointCloud_PointXYZRGB()
try:
loader = getattr(p, "_from_%s_file" % format)
except AttributeError:
raise ValueError("unknown file format %s" % format)
if loader(_encode(path)):
raise IOError("error while loading pointcloud from %r (format=%r)"
% (path, format))
return p
def load_XYZRGBA(path, format=None):
"""
Load pointcloud from path.
Currently supports PCD and PLY files.
Format should be "pcd", "ply", or None to infer from the pathname.
"""
format = _infer_format(path, format)
p = PointCloud_PointXYZRGBA()
try:
loader = getattr(p, "_from_%s_file" % format)
except AttributeError:
raise ValueError("unknown file format %s" % format)
if loader(_encode(path)):
raise IOError("error while loading pointcloud from %r (format=%r)"
% (path, format))
return p
def load_PointWithViewpoint(path, format=None):
"""
Load pointcloud from path.
Currently supports PCD and PLY files.
Format should be "pcd", "ply", or None to infer from the pathname.
"""
format = _infer_format(path, format)
p = PointCloud_PointWithViewpoint()
try:
loader = getattr(p, "_from_%s_file" % format)
except AttributeError:
raise ValueError("unknown file format %s" % format)
if loader(_encode(path)):
raise IOError("error while loading pointcloud from %r (format=%r)"
% (path, format))
return p
def save(cloud, path, format=None, binary=False):
"""Save pointcloud to file.
Format should be "pcd", "ply", or None to infer from the pathname.
"""
format = _infer_format(path, format)
try:
dumper = getattr(cloud, "_to_%s_file" % format)
except AttributeError:
raise ValueError("unknown file format %s" % format)
if dumper(_encode(path), binary):
raise IOError("error while saving pointcloud to %r (format=%r)"
% (path, format))
def save_XYZRGBA(cloud, path, format=None, binary=False):
"""Save pointcloud to file.
Format should be "pcd", "ply", or None to infer from the pathname.
"""
format = _infer_format(path, format)
try:
dumper = getattr(cloud, "_to_%s_file" % format)
except AttributeError:
raise ValueError("unknown file format %s" % format)
if dumper(_encode(path), binary):
raise IOError("error while saving pointcloud to %r (format=%r)"
% (path, format))
def save_PointNormal(cloud, path, format=None, binary=False):
"""
Save pointcloud to file.
Format should be "pcd", "ply", or None to infer from the pathname.
"""
format = _infer_format(path, format)
try:
dumper = getattr(cloud, "_to_%s_file" % format)
except AttributeError:
raise ValueError("unknown file format %s" % format)
if dumper(_encode(path), binary):
raise IOError("error while saving pointcloud to %r (format=%r)"
% (path, format))
def _encode(path):
# Encode path for use in C++.
if isinstance(path, bytes):
return path
else:
return path.encode(sys.getfilesystemencoding())
def _infer_format(path, format):
if format is not None:
return format.lower()
for candidate in ["pcd", "ply"]:
if path.endswith("." + candidate):
return candidate
raise ValueError("Could not determine file format from pathname %s" % path)
|