[Bf-extensions-cvs] [fbd1503] master: io_points_pcd added exporter for ascii .pcd files.
Aurel Wildfellner
noreply at git.blender.org
Mon Aug 24 14:43:58 CEST 2015
Commit: fbd150343912266fa131f6ba5acce3adf7eddf0e
Author: Aurel Wildfellner
Date: Mon Aug 24 14:43:37 2015 +0200
Branches: master
https://developer.blender.org/rBACfbd150343912266fa131f6ba5acce3adf7eddf0e
io_points_pcd added exporter for ascii .pcd files.
===================================================================
M io_points_pcd/__init__.py
M io_points_pcd/pcd_utils.py
M io_points_pcd/pcdparser.py
===================================================================
diff --git a/io_points_pcd/__init__.py b/io_points_pcd/__init__.py
index 30736c5..ddb87aa 100644
--- a/io_points_pcd/__init__.py
+++ b/io_points_pcd/__init__.py
@@ -1,102 +1,119 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-bl_info = {
- "name": "PCD",
- "author": "Aurel Wildfellner",
- "version": (0, 1),
- "blender": (2, 57, 0),
- "location": "File > Import-Export > Point Cloud Data",
- "description": "Imports and Exports PCD (Point Cloud Data) files. PCD files are the default format used by pcl (Point Cloud Library).",
- "warning": "",
- "wiki_url": "",
- "tracker_url": "",
-# "support": 'OFFICAL',
- "category": "Import-Export"}
-
-
-if "bpy" in locals():
- import imp
- imp.reload(pcd_utils)
-else:
- from . import pcd_utils
-
-import itertools
-import os
-
-
-import bpy
-from bpy.props import *
-from bpy_extras.io_utils import ExportHelper, ImportHelper
-
-
-class ImportPCD(bpy.types.Operator, ImportHelper):
- """Load PCD (Point Cloud Data) files"""
- bl_idname = "import_points.stl"
- bl_label = "Import PCD"
-
- filename_ext = ".pcd"
-
- filter_glob = StringProperty(default="*.pcd", options={'HIDDEN'})
-
- files = CollectionProperty(name="File Path",
- description="File path used for importing "
- "the PCD file",
- type=bpy.types.OperatorFileListElement)
-
- directory = StringProperty(subtype='DIR_PATH')
-
- def execute(self, context):
- paths = [os.path.join(self.directory, name.name) for name in self.files]
- if not paths:
- paths.append(self.filepath)
-
- for path in paths:
- pcd_utils.import_pcd(path)
-
- return {'FINISHED'}
-
-
-
-
-def menu_func_import(self, context):
- self.layout.operator(ImportPCD.bl_idname, text="Point Cloud Data (.pcd)").filepath = "*.pcd"
-
-
-def menu_func_export(self, context):
- #self.layout.operator(ExportPLY.bl_idname, text="Point Cloud Data (.pcd)")
- pass
-
-
-def register():
- bpy.utils.register_module(__name__)
-
- bpy.types.INFO_MT_file_import.append(menu_func_import)
- bpy.types.INFO_MT_file_export.append(menu_func_export)
-
-
-def unregister():
- bpy.utils.unregister_module(__name__)
-
- bpy.types.INFO_MT_file_import.remove(menu_func_import)
- bpy.types.INFO_MT_file_export.remove(menu_func_export)
-
-
-if __name__ == "__main__":
- register()
-
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+bl_info = {
+ "name": "PCD",
+ "author": "Aurel Wildfellner",
+ "version": (0, 2),
+ "blender": (2, 57, 0),
+ "location": "File > Import-Export > Point Cloud Data",
+ "description": "Imports and Exports PCD (Point Cloud Data) files. PCD files are the default format used by pcl (Point Cloud Library).",
+ "warning": "",
+ "wiki_url": "http://wiki.blender.org/index.php?title=Extensions:2.6/Py/Scripts/Import-Export/Point_Cloud_Data_IO",
+ "tracker_url": "https://developer.blender.org/T27711",
+# "support": 'OFFICAL',
+ "category": "Import-Export"}
+
+
+if "bpy" in locals():
+ import imp
+ imp.reload(pcd_utils)
+else:
+ from . import pcd_utils
+
+import itertools
+import os
+
+
+import bpy
+from bpy.props import *
+from bpy_extras.io_utils import ExportHelper, ImportHelper
+
+
+class ImportPCD(bpy.types.Operator, ImportHelper):
+ """Load PCD (Point Cloud Data) files"""
+ bl_idname = "import_points.stl"
+ bl_label = "Import PCD"
+
+ filename_ext = ".pcd"
+
+ filter_glob = StringProperty(default="*.pcd", options={'HIDDEN'})
+
+ files = CollectionProperty(name="File Path",
+ description="File path used for importing "
+ "the PCD file",
+ type=bpy.types.OperatorFileListElement)
+
+ directory = StringProperty(subtype='DIR_PATH')
+
+ def execute(self, context):
+ paths = [os.path.join(self.directory, name.name) for name in self.files]
+ if not paths:
+ paths.append(self.filepath)
+
+ for path in paths:
+ pcd_utils.import_pcd(path)
+
+ return {'FINISHED'}
+
+
+
+
+class ExportPCD(bpy.types.Operator, ExportHelper):
+ """Save PCD (Point Cloud Data) files"""
+ bl_idname = "export_points.pcd"
+ bl_label = "Export PCD"
+
+ filename_ext = ".pcd"
+
+ filter_glob = StringProperty(default="*.pcd", options={'HIDDEN'})
+
+
+ def execute(self, context):
+ pcd_utils.export_pcd(self.filepath)
+
+ return {'FINISHED'}
+
+
+
+
+def menu_func_import(self, context):
+ self.layout.operator(ImportPCD.bl_idname, text="Point Cloud Data (.pcd)").filepath = "*.pcd"
+
+
+def menu_func_export(self, context):
+ self.layout.operator(ExportPCD.bl_idname, text="Point Cloud Data (.pcd)")
+
+
+def register():
+ bpy.utils.register_module(__name__)
+
+ bpy.types.INFO_MT_file_import.append(menu_func_import)
+ bpy.types.INFO_MT_file_export.append(menu_func_export)
+
+
+def unregister():
+ bpy.utils.unregister_module(__name__)
+
+ bpy.types.INFO_MT_file_import.remove(menu_func_import)
+ bpy.types.INFO_MT_file_export.remove(menu_func_export)
+
+
+if __name__ == "__main__":
+ register()
+
diff --git a/io_points_pcd/pcd_utils.py b/io_points_pcd/pcd_utils.py
index 9f2a79e..a37af5b 100644
--- a/io_points_pcd/pcd_utils.py
+++ b/io_points_pcd/pcd_utils.py
@@ -1,55 +1,71 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-import bpy
-
-from . import pcdparser
-
-
-def create_and_link_mesh(name, points):
- """
- Create a blender mesh and object called name from a list of
- *points* and link it in the current scene.
- """
-
- mesh = bpy.data.meshes.new(name)
- mesh.from_pydata(points, [], [])
-
- # update mesh to allow proper display
- mesh.validate()
- mesh.update()
-
- scene = bpy.context.scene
-
- obj = bpy.data.objects.new(name, mesh)
- scene.objects.link(obj)
- obj.select = True
-
-
-def import_pcd(filepath, name="new_pointcloud"):
- parser = pcdparser.PCDParser.factory(filepath, pcdparser.PointXYZ)
- parser.parseFile()
- points = parser.getPoints()
-
- blender_points = []
- for point in points:
- blender_points.append((point.x, point.y, point.z))
-
- create_and_link_mesh(name, blender_points)
-
-
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import bpy
+
+from . import pcdparser
+
+
+def create_and_link_mesh(name, points):
+ """
+ Create a blender mesh and object called name from a list of
+ *points* and link it in the current scene.
+ """
+
+ mesh = bpy.data.meshes.new(name)
+ mesh.from_pydata(points, [], [])
+
+ # update mesh to allow proper display
+ mesh.validate()
+ mesh.update()
+
+ scene = bpy.context.scene
+
+ obj = bpy.data.objects.new(name, mesh)
+ scene.objects.link(obj)
+ obj.select = True
+
+
+def import_pcd(filepath, name="new_pointcloud"):
+ parser = pcdparser.PCDParser.factory(filepath, pcdparser.PointXYZ)
+ parser.parseFile()
+ points = parser.getPoints()
+ print("Number of points: " + str(len(points)))
+
+ blender_points = []
+ for p
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list