Skip to content

Commit

Permalink
Merge pull request #22434 from Tobias-Fischer/add-python-pcl
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Apr 29, 2023
2 parents 7a577c1 + 4bf0199 commit 1756533
Show file tree
Hide file tree
Showing 14 changed files with 1,998 additions and 0 deletions.
70 changes: 70 additions & 0 deletions recipes/python-pcl/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{% set name = "python-pcl" %}
{% set version = "0.3.0rc1" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
url: https://github.com/strawlab/{{ name }}/archive/refs/tags/v{{ version }}.tar.gz
sha256: 3871a8b77f389fbd1f99c5447e5174bf7bebc94e80cd7b2733ec15fc4fa55b10
patches:
- patches/0001-Mark-PCLBase-as-nogil-to-fix-compilation.patch
- patches/0002-Enable-visualization-module.patch
- patches/0003-Remove-ConditionalRemoval-API-and-add-deprecation-no.patch
- patches/0004-Add-support-for-PCL-1.9.patch
- patches/0005-add-support-for-pcl-1.10.patch
- patches/0006-use-pcl-1.11-api.patch
- patches/0007-support-for-pcl-1.12.patch
- patches/0008-fix-deprecated-collections-import-since-.patch
- patches/0009-update-for-vtk-9.1.patch
- patches/0010-use-distutils-instead-of-setuptools-for-.patch
- patches/0011-Support-PCL-1.13-and-later.patch
- patches/0012-update-for-vtk-9.2.patch
- patches/0013-add-conda-prefix.patch


build:
script: {{ PYTHON }} -m pip install . -vv
number: 0
skip: True # [win]

requirements:
build:
- {{ compiler('cxx') }}
- cmake
- make
- pkgconfig
host:
- pcl
- python
- numpy
- cython
- pip
- flann
run:
- python
- cython
- filelock
- nose
- pcl
- flann
- {{ pin_compatible('numpy') }}

test:
imports:
- pcl
commands:
- pip check
requires:
- pip

about:
home: http://github.com/strawlab/python-pcl
summary: Python bindings for the Point Cloud Library (PCL) using Cython.
license: BSD-3-Clause
license_file: LICENSE

extra:
recipe-maintainers:
- Tobias-Fischer
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
From: Jochen Sprickerhof <[email protected]>
Date: Thu, 13 Sep 2018 20:59:21 +0200
Subject: Mark PCLBase as nogil to fix compilation

---
pcl/pcl_defs.pxd | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pcl/pcl_defs.pxd b/pcl/pcl_defs.pxd
index 881f707..1117ee6 100644
--- a/pcl/pcl_defs.pxd
+++ b/pcl/pcl_defs.pxd
@@ -509,7 +509,7 @@ ctypedef shared_ptr[vector[int]] IndicesPtr_t;
# pcl_base.h
# template <typename PointT>
# class PCLBase
-cdef extern from "pcl/pcl_base.h" namespace "pcl":
+cdef extern from "pcl/pcl_base.h" namespace "pcl" nogil:
cdef cppclass PCLBase[PointT]:
PCLBase ()
# PCLBase (const PCLBase& base)
107 changes: 107 additions & 0 deletions recipes/python-pcl/patches/0002-Enable-visualization-module.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
From: Jochen Sprickerhof <[email protected]>
Date: Sun, 9 Dec 2018 19:01:14 +0100
Subject: Enable visualization module

https://build.opensuse.org/package/view_file/science/python-pcl/visualization18.patch
---
pcl/pcl_visualization_defs.pxd | 12 ++++++------
pcl/pxi/Visualization/PCLVisualizering.pxi | 12 ++++++------
setup.py | 6 +++---
3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/pcl/pcl_visualization_defs.pxd b/pcl/pcl_visualization_defs.pxd
index 81fe113..8b55e97 100644
--- a/pcl/pcl_visualization_defs.pxd
+++ b/pcl/pcl_visualization_defs.pxd
@@ -752,8 +752,8 @@ cdef extern from "pcl/visualization/pcl_visualizer.h" namespace "pcl::visualizat
# param[in] scale the scale of the axes (default: 1)
# param[in] viewport the view port where the 3D axes should be added (default: all)
#
- # void addCoordinateSystem (double scale = 1.0, int viewport = 0);
- void addCoordinateSystem (double scale, int viewport)
+ # void addCoordinateSystem (double scale = 1.0, const string &id = "reference", int viewport = 0);
+ void addCoordinateSystem (double scale, const string &id, int viewport)

# brief Adds 3D axes describing a coordinate system to screen at x, y, z
# param[in] scale the scale of the axes (default: 1)
@@ -762,8 +762,8 @@ cdef extern from "pcl/visualization/pcl_visualizer.h" namespace "pcl::visualizat
# param[in] z the Z position of the axes
# param[in] viewport the view port where the 3D axes should be added (default: all)
#
- # void addCoordinateSystem (double scale, float x, float y, float z, int viewport = 0);
- void addCoordinateSystem (double scale, float x, float y, float z, int viewport)
+ # void addCoordinateSystem (double scale, float x, float y, float z, const string &id = "reference", int viewport = 0);
+ void addCoordinateSystem (double scale, float x, float y, float z, const string &id, int viewport)

# brief Adds 3D axes describing a coordinate system to screen at x, y, z, Roll,Pitch,Yaw
# param[in] scale the scale of the axes (default: 1)
@@ -797,8 +797,8 @@ cdef extern from "pcl/visualization/pcl_visualizer.h" namespace "pcl::visualizat

# brief Removes a previously added 3D axes (coordinate system)
# param[in] viewport view port where the 3D axes should be removed from (default: all)
- # bool removeCoordinateSystem (int viewport = 0);
- bool removeCoordinateSystem (int viewport)
+ # bool removeCoordinateSystem (const string &id = "reference", int viewport = 0);
+ bool removeCoordinateSystem(const string &id, int viewport)

# brief Removes a Point Cloud from screen, based on a given ID.
# param[in] id the point cloud object id (i.e., given on \a addPointCloud)
diff --git a/pcl/pxi/Visualization/PCLVisualizering.pxi b/pcl/pxi/Visualization/PCLVisualizering.pxi
index a9cc89a..48238db 100644
--- a/pcl/pxi/Visualization/PCLVisualizering.pxi
+++ b/pcl/pxi/Visualization/PCLVisualizering.pxi
@@ -38,17 +38,17 @@ cdef class PCLVisualizering:
def SpinOnce(self, int millis_to_wait = 1, bool force_redraw = False):
self.thisptr().spinOnce (millis_to_wait, force_redraw)

- def AddCoordinateSystem(self, double scale = 1.0, int viewpoint = 0):
- self.thisptr().addCoordinateSystem(scale, viewpoint)
+ def AddCoordinateSystem(self, double scale = 1.0, const string &id = "reference", int viewpoint = 0):
+ self.thisptr().addCoordinateSystem(scale, id, viewpoint)

- def AddCoordinateSystem(self, double scale, float x, float y, float z, int viewpoint = 0):
- self.thisptr().addCoordinateSystem(scale, x, y, z, viewpoint)
+ def AddCoordinateSystem(self, double scale, float x, float y, float z, const string &id = "reference", int viewpoint = 0):
+ self.thisptr().addCoordinateSystem(scale, x, y, z, id, viewpoint)

# void addCoordinateSystem (double scale, const eigen3.Affine3f& t, int viewport)

# return bool
- def removeCoordinateSystem (self, int viewport):
- return self.thisptr().removeCoordinateSystem (viewport)
+ def removeCoordinateSystem (self, const string &id = "reference",int viewport = 0):
+ return self.thisptr().removeCoordinateSystem (id, viewport)

# return bool
def RemovePointCloud(self, string id, int viewport):
diff --git a/setup.py b/setup.py
index 8796770..0493ccc 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@ from collections import defaultdict
from Cython.Distutils import build_ext
from distutils.core import setup
from distutils.extension import Extension
-# from Cython.Build import cythonize # MacOS NG
+from Cython.Build import cythonize
from setuptools import setup, find_packages, Extension

import subprocess
@@ -546,7 +546,7 @@ else:
# ext_args['include_dirs'].append('/usr/include/vtk')
# ext_args['include_dirs'].append('/usr/local/include/vtk')
# pcl 1.7(Ubuntu)
- ext_args['include_dirs'].append('/usr/include/vtk-5.8')
+ ext_args['include_dirs'].append('/usr/include/vtk-7.1')
ext_args['library_dirs'].append('/usr/lib')
# ext_args['libraries'].append('libvtk*.so')
# pcl 1.8.1(MacOSX)
@@ -609,7 +609,7 @@ else:
]
elif pcl_version == '-1.8':
module = [Extension("pcl._pcl", ["pcl/_pcl_180.pyx", "pcl/minipcl.cpp", "pcl/ProjectInliers.cpp"], language="c++", **ext_args),
- # Extension("pcl.pcl_visualization", ["pcl/pcl_visualization.pyx"], language="c++", **ext_args),
+ Extension("pcl.pcl_visualization", ["pcl/pcl_visualization.pyx"], language="c++", extra_compile_args=['-std=c++11','-fno-strict-aliasing'], **ext_args),
# Extension("pcl.pcl_grabber", ["pcl/pcl_grabber.pyx", "pcl/grabber_callback.cpp"], language="c++", **ext_args),
# debug
# gdb_debug=True,
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
From: Jochen Sprickerhof <[email protected]>
Date: Sun, 9 Dec 2018 18:38:40 +0100
Subject: Remove ConditionalRemoval API and add deprecation notice

---
examples/official/Filtering/remove_outliers.py | 3 ++-
pcl/pcl_filters_180.pxd | 4 ----
pcl/pxi/Filters/ConditionalRemoval_180.pxi | 12 +++++++++++-
pcl/pxi/PointCloud_PointXYZ_180.pxi | 13 +++++++++++++
pcl/pxi/PointCloud_SensorPoint.pxi | 12 ++++++++++++
tests/test_filters.py | 3 ++-
6 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/examples/official/Filtering/remove_outliers.py b/examples/official/Filtering/remove_outliers.py
index b586737..fd1da1a 100644
--- a/examples/official/Filtering/remove_outliers.py
+++ b/examples/official/Filtering/remove_outliers.py
@@ -86,7 +86,8 @@ elif args.Removal == 'Condition':
range_cond.add_Comparison2('z', pcl.CythonCompareOp_Type.LT, 0.8)

# build the filter
- condrem = cloud.make_ConditionalRemoval(range_cond)
+ condrem = cloud.make_ConditionalRemoval()
+ condrem.set_Condition(range_cond)
condrem.set_KeepOrganized(True)
# apply filter
cloud_filtered = condrem.filter ()
diff --git a/pcl/pcl_filters_180.pxd b/pcl/pcl_filters_180.pxd
index c272819..cb6f075 100644
--- a/pcl/pcl_filters_180.pxd
+++ b/pcl/pcl_filters_180.pxd
@@ -616,10 +616,6 @@ cdef extern from "pcl/filters/conditional_removal.h" namespace "pcl":
ConditionalRemoval(int)
# ConditionalRemoval (ConditionBasePtr condition, bool extract_removed_indices = false)
# python invalid default param ?
- ConditionalRemoval (ConditionBasePtr_t condition, bool extract_removed_indices = false)
- ConditionalRemoval (ConditionBase_PointXYZI_Ptr_t condition, bool extract_removed_indices = false)
- ConditionalRemoval (ConditionBase_PointXYZRGB_Ptr_t condition, bool extract_removed_indices = false)
- ConditionalRemoval (ConditionBase_PointXYZRGBA_Ptr_t condition, bool extract_removed_indices = false)
# [with PointT = pcl::PointXYZ, pcl::ConditionalRemoval<PointT>::ConditionBasePtr = boost::shared_ptr<pcl::ConditionBase<pcl::PointXYZ> >]
# is deprecated (declared at /usr/include/pcl-1.7/pcl/filters/conditional_removal.h:632): ConditionalRemoval(ConditionBasePtr condition, bool extract_removed_indices = false) is deprecated,
# please use the setCondition (ConditionBasePtr condition) function instead. [-Wdeprecated-declarations]
diff --git a/pcl/pxi/Filters/ConditionalRemoval_180.pxi b/pcl/pxi/Filters/ConditionalRemoval_180.pxi
index 88a5e6d..5e25b37 100644
--- a/pcl/pxi/Filters/ConditionalRemoval_180.pxi
+++ b/pcl/pxi/Filters/ConditionalRemoval_180.pxi
@@ -19,7 +19,14 @@ cdef class ConditionalRemoval:
def __cinit__(self, ConditionAnd cond):
# self.me = new pclfil.ConditionalRemoval_t(<pclfil.ConditionBase_t*>cond.me)
# direct - NG
- self.me = new pclfil.ConditionalRemoval_t(<pclfil.ConditionBasePtr_t>cond.me)
+ from warnings import warn
+ warn("constructor with condition is deprecated, use setCondition()",
+ DeprecationWarning)
+ self.me = new pclfil.ConditionalRemoval_t()
+ self.me.setCondition(<pclfil.ConditionBasePtr_t>cond.me)
+
+ def __cinit__(self):
+ self.me = new pclfil.ConditionalRemoval_t()

# def __dealloc__(self):
# # MemoryAccessError
@@ -29,6 +36,9 @@ cdef class ConditionalRemoval:
def set_KeepOrganized(self, flag):
self.me.setKeepOrganized(flag)

+ def set_Condition(self, ConditionAnd cond):
+ self.me.setCondition(<pclfil.ConditionBasePtr_t>cond.me)
+
def filter(self):
"""
Apply the filter according to the previously set parameters and return
diff --git a/pcl/pxi/PointCloud_PointXYZ_180.pxi b/pcl/pxi/PointCloud_PointXYZ_180.pxi
index 7956c5c..f386e9c 100644
--- a/pcl/pxi/PointCloud_PointXYZ_180.pxi
+++ b/pcl/pxi/PointCloud_PointXYZ_180.pxi
@@ -468,10 +468,23 @@ cdef class PointCloud:
cdef pclfil.ConditionAnd_t *cCondAnd = <pclfil.ConditionAnd_t *>condAnd.me
return condAnd

+ def make_ConditionalRemoval(self):
+ """
+ Return a pcl.ConditionalRemoval object with this object set as the input-cloud
+ """
+ condRemoval = ConditionalRemoval()
+ cdef pclfil.ConditionalRemoval_t *cCondRemoval = <pclfil.ConditionalRemoval_t *>condRemoval.me
+ cCondRemoval.setInputCloud(<cpp.shared_ptr[cpp.PointCloud[cpp.PointXYZ]]> self.thisptr_shared)
+ return condRemoval
+
def make_ConditionalRemoval(self, ConditionAnd range_conf):
"""
Return a pcl.ConditionalRemoval object with this object set as the input-cloud
"""
+ from warnings import warn
+ warn("constructor with condition is deprecated, use setCondition()",
+ DeprecationWarning)
+
condRemoval = ConditionalRemoval(range_conf)
cdef pclfil.ConditionalRemoval_t *cCondRemoval = <pclfil.ConditionalRemoval_t *>condRemoval.me
cCondRemoval.setInputCloud(<cpp.shared_ptr[cpp.PointCloud[cpp.PointXYZ]]> self.thisptr_shared)
diff --git a/pcl/pxi/PointCloud_SensorPoint.pxi b/pcl/pxi/PointCloud_SensorPoint.pxi
index e26fca6..b8a5d79 100644
--- a/pcl/pxi/PointCloud_SensorPoint.pxi
+++ b/pcl/pxi/PointCloud_SensorPoint.pxi
@@ -466,10 +466,22 @@ cdef class PointCloud2:
cdef pclfil.ConditionAnd_t *cCondAnd = <pclfil.ConditionAnd_t *>condAnd.me
return condAnd

+ def make_ConditionalRemoval(self):
+ """
+ Return a pcl.ConditionalRemoval object with this object set as the input-cloud
+ """
+ condRemoval = ConditionalRemoval()
+ cdef pclfil.ConditionalRemoval_t *cCondRemoval = <pclfil.ConditionalRemoval_t *>condRemoval.me
+ cCondRemoval.setInputCloud(<cpp.shared_ptr[cpp.PointCloud2[cpp.PointXYZ]]> self.thisptr_shared)
+ return condRemoval
+
def make_ConditionalRemoval(self, ConditionAnd range_conf):
"""
Return a pcl.ConditionalRemoval object with this object set as the input-cloud
"""
+ warn("constructor with condition is deprecated, use setCondition()",
+ DeprecationWarning)
+
condRemoval = ConditionalRemoval(range_conf)
cdef pclfil.ConditionalRemoval_t *cCondRemoval = <pclfil.ConditionalRemoval_t *>condRemoval.me
cCondRemoval.setInputCloud(<cpp.shared_ptr[cpp.PointCloud2[cpp.PointXYZ]]> self.thisptr_shared)
diff --git a/tests/test_filters.py b/tests/test_filters.py
index 3c0c605..db40671 100644
--- a/tests/test_filters.py
+++ b/tests/test_filters.py
@@ -62,7 +62,8 @@ class TestConditionalRemoval(unittest.TestCase):
# self.p = pcl.load("tests" + os.path.sep + "flydracyl.pcd")
# self.p = pcl.PointCloud(_data)
self.p = pcl.PointCloud(_data2)
- self.fil = self.p.make_ConditionalRemoval(pcl.ConditionAnd())
+ self.fil = self.p.make_ConditionalRemoval()
+ self.fil.set_Condition(pcl.ConditionAnd())

# result
# nan nan nan
35 changes: 35 additions & 0 deletions recipes/python-pcl/patches/0004-Add-support-for-PCL-1.9.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From: Jochen Sprickerhof <[email protected]>
Date: Sun, 9 Dec 2018 19:02:37 +0100
Subject: Add support for PCL 1.9

---
setup.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 0493ccc..84addab 100644
--- a/setup.py
+++ b/setup.py
@@ -510,7 +510,7 @@ else:
os.environ['ARCHFLAGS'] = ''

# Try to find PCL. XXX we should only do this when trying to build or install.
- PCL_SUPPORTED = ["-1.8", "-1.7", "-1.6", ""] # in order of preference
+ PCL_SUPPORTED = ["-1.9", "-1.8", "-1.7", "-1.6", ""] # in order of preference

for pcl_version in PCL_SUPPORTED:
if subprocess.call(['pkg-config', 'pcl_common%s' % pcl_version]) == 0:
@@ -614,6 +614,13 @@ else:
# debug
# gdb_debug=True,
]
+ elif pcl_version == '-1.9':
+ module = [Extension("pcl._pcl", ["pcl/_pcl_180.pyx", "pcl/minipcl.cpp", "pcl/ProjectInliers.cpp"], language="c++", **ext_args),
+ Extension("pcl.pcl_visualization", ["pcl/pcl_visualization.pyx"], language="c++", extra_compile_args=['-std=c++11','-fno-strict-aliasing'], **ext_args),
+ # Extension("pcl.pcl_grabber", ["pcl/pcl_grabber.pyx", "pcl/grabber_callback.cpp"], language="c++", **ext_args),
+ # debug
+ # gdb_debug=True,
+ ]
else:
print('no pcl install or pkg-config missed.')
sys.exit(1)
Loading

0 comments on commit 1756533

Please sign in to comment.