Skip to content

Commit

Permalink
Avoid import star (from open3d import *) (isl-org#982)
Browse files Browse the repository at this point in the history
* import open3d as o3d

* rename python namespace

* format python code with yapf

* add python style

* add init.py

* fix import *

* update all line numbers

* address review comments

* check-style and apply-style for python
  • Loading branch information
yxlao authored May 23, 2019
1 parent 483275e commit d50699b
Show file tree
Hide file tree
Showing 104 changed files with 2,016 additions and 1,593 deletions.
2 changes: 2 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[style]
based_on_style = google
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ matrix:
- mkdir build
- cd build
- cmake -DPYTHON_EXECUTABLE=`which python` ..
- pip install -U yapf
- make check-style

# Build docs only
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorial/Advanced/color_map_optimization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Input
.. literalinclude:: ../../../examples/Python/Advanced/color_map_optimization.py
:language: python
:lineno-start: 19
:lines: 19-35
:lines: 19-38
:linenos:

This script reads color and depth image pairs and makes ``rgbd_image``. Note that ``convert_rgb_to_intensity`` flag is ``False``. This is to preserve 8-bit color channels instead of using single channel float type image.
Expand All @@ -27,16 +27,16 @@ It is always good practice to visualize RGBD image before applying it to color m

.. literalinclude:: ../../../examples/Python/Advanced/color_map_optimization.py
:language: python
:lineno-start: 37
:lines: 37-39
:lineno-start: 40
:lines: 40-44
:linenos:

The script reads camera trajectory and mesh.

.. literalinclude:: ../../../examples/Python/Advanced/color_map_optimization.py
:language: python
:lineno-start: 43
:lines: 43-48
:lineno-start: 46
:lines: 46-53
:linenos:

To visualize how the camera poses are not good for color mapping, this script intentionally set the iteration number as 0, which means no optimization. ``color_map_optimization`` paints a mesh using corresponding RGBD images and camera poses. Without optimization, the texture map is blurred.
Expand All @@ -55,7 +55,7 @@ The next step is to optimize camera poses to get a sharp color map.
.. literalinclude:: ../../../examples/Python/Advanced/color_map_optimization.py
:language: python
:lineno-start: 55
:lines: 55-60
:lines: 55-65
:linenos:

The script sets ``maximum_iteration = 300`` for actual iterations. The optimization displays the following energy profile.
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorial/Advanced/colored_pointcloud_registration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Point-to-plane ICP
.. literalinclude:: ../../../examples/Python/Advanced/colored_pointcloud_registration.py
:language: python
:lineno-start: 29
:lines: 29-37
:lines: 29-38
:linenos:

We first run :ref:`point_to_plane_icp` as a baseline approach. The visualization below shows misaligned green triangle textures. This is because geometric constraint does not prevent two planar surfaces from slipping.
Expand Down Expand Up @@ -89,8 +89,8 @@ To further improve efficiency, [Park2017]_ proposes a multi-scale registration s

.. literalinclude:: ../../../examples/Python/Advanced/colored_pointcloud_registration.py
:language: python
:lineno-start: 39
:lines: 39-70
:lineno-start: 40
:lines: 40-74
:linenos:

In total, 3 layers of multi-resolution point clouds are created with :ref:`voxel_downsampling`. Normals are computed with :ref:`vertex_normal_estimation`. The core registration function ``registration_colored_icp`` is called for each layer, from coarse to fine. ``lambda_geometric`` is an optional argument for ``registration_colored_icp`` that determines :math:`\lambda \in [0,1]` in the overall energy :math:`\lambda E_{G} + (1-\lambda) E_{C}`.
Expand Down
24 changes: 12 additions & 12 deletions docs/tutorial/Advanced/customized_visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Mimic draw_geometries() with Visualizer class

.. literalinclude:: ../../../examples/Python/Advanced/customized_visualization.py
:language: python
:lineno-start: 12
:lines: 12-19
:lineno-start: 13
:lines: 13-20
:linenos:

This function produces exactly the same functionality of the convenient function ``draw_geometries``.
Expand All @@ -26,8 +26,8 @@ Class ``Visualizer`` has a couple of variables such as a ``ViewControl`` and a `

.. literalinclude:: ../../../examples/Python/Advanced/customized_visualization.py
:language: python
:lineno-start: 39
:lines: 39-46
:lineno-start: 46
:lines: 46-52
:linenos:

Outputs:
Expand All @@ -42,8 +42,8 @@ To change field of view of the camera, it is necessary to get an instance of vis

.. literalinclude:: ../../../examples/Python/Advanced/customized_visualization.py
:language: python
:lineno-start: 21
:lines: 21-30
:lineno-start: 23
:lines: 23-32
:linenos:

The field of view can be set as [5,90] degree. Note that ``change_field_of_view`` adds specified FoV on the current FoV. By default, visualizer has 60 degrees of FoV. Calling the following code
Expand Down Expand Up @@ -74,8 +74,8 @@ Use callback functions

.. literalinclude:: ../../../examples/Python/Advanced/customized_visualization.py
:language: python
:lineno-start: 32
:lines: 32-37
:lineno-start: 35
:lines: 35-43
:linenos:

Function ``draw_geometries_with_animation_callback`` registers a Python callback function ``rotate_view`` as the idle function of the main loop. It rotates the view along the x-axis whenever the visualizer is idle. This defines an animation behavior.
Expand All @@ -85,8 +85,8 @@ Function ``draw_geometries_with_animation_callback`` registers a Python callback

.. literalinclude:: ../../../examples/Python/Advanced/customized_visualization.py
:language: python
:lineno-start: 48
:lines: 48-72
:lineno-start: 55
:lines: 55-84
:linenos:

Callback functions can also be registered upon key press event. This script registered four keys. For example, pressing :kbd:`k` changes the background color to black.
Expand All @@ -99,8 +99,8 @@ Capture images in a customized animation

.. literalinclude:: ../../../examples/Python/Advanced/customized_visualization.py
:language: python
:lineno-start: 74
:lines: 74-118
:lineno-start: 87
:lines: 87-134
:linenos:

This function reads a camera trajectory, then defines an animation function ``move_forward`` to travel through the camera trajectory. In this animation function, both color image and depth image are captured using ``Visualizer.capture_depth_float_buffer`` and ``Visualizer.capture_screen_float_buffer`` respectively. They are saved in files.
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorial/Advanced/fast_global_registration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Input

.. literalinclude:: ../../../examples/Python/Advanced/fast_global_registration.py
:language: python
:lineno-start: 27
:lines: 27-29
:lineno-start: 29
:lines: 29-31
:linenos:

For the pair comparison, the script reuses the ``prepare_dataset`` function defined in :ref:`global_registration`.
Expand All @@ -32,8 +32,8 @@ Baseline

.. literalinclude:: ../../../examples/Python/Advanced/fast_global_registration.py
:language: python
:lineno-start: 31
:lines: 31-37
:lineno-start: 33
:lines: 33-40
:linenos:

This script calls RANSAC based :ref:`global_registration` as a baseline. After registration it displays the following result.
Expand All @@ -52,8 +52,8 @@ With the same input used for a baseline, the next script calls the implementatio

.. literalinclude:: ../../../examples/Python/Advanced/fast_global_registration.py
:language: python
:lineno-start: 14
:lines: 14-22
:lineno-start: 15
:lines: 15-24
:linenos:

This script displays the following result.
Expand Down
16 changes: 8 additions & 8 deletions docs/tutorial/Advanced/global_registration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Input

.. literalinclude:: ../../../examples/Python/Advanced/global_registration.py
:language: python
:lineno-start: 34
:lines: 34-43
:lineno-start: 39
:lines: 39-50
:linenos:

This script reads a source point cloud and a target point cloud from two files. They are misaligned with an identity matrix as transformation.
Expand All @@ -32,8 +32,8 @@ Extract geometric feature

.. literalinclude:: ../../../examples/Python/Advanced/global_registration.py
:language: python
:lineno-start: 19
:lines: 19-31
:lineno-start: 21
:lines: 21-36
:linenos:

We down sample the point cloud, estimate normals, then compute a FPFH feature for each point. The FPFH feature is a 33-dimensional vector that describes the local geometric property of a point. A nearest neighbor query in the 33-dimensinal space can return points with similar local geometric structures. See [Rasu2009]_ for details.
Expand All @@ -45,8 +45,8 @@ RANSAC

.. literalinclude:: ../../../examples/Python/Advanced/global_registration.py
:language: python
:lineno-start: 49
:lines: 49-61
:lineno-start: 53
:lines: 53-66
:linenos:

We use RANSAC for global registration. In each RANSAC iteration, ``ransac_n`` random points are picked from the source point cloud. Their corresponding points in the target point cloud are detected by querying the nearest neighbor in the 33-dimensional FPFH feature space. A pruning step takes fast pruning algorithms to quickly reject false matches early.
Expand Down Expand Up @@ -75,8 +75,8 @@ For performance reason, the global registration is only performed on a heavily d

.. literalinclude:: ../../../examples/Python/Advanced/global_registration.py
:language: python
:lineno-start: 64
:lines: 64-71
:lineno-start: 69
:lines: 69-77
:linenos:

Outputs a tight alignment. This summarizes a complete pairwise registration workflow.
Expand Down
16 changes: 8 additions & 8 deletions docs/tutorial/Advanced/interactive_visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Crop geometry

.. literalinclude:: ../../../examples/Python/Advanced/interactive_visualization.py
:language: python
:lineno-start: 11
:lines: 11-20
:lineno-start: 12
:lines: 12-23
:linenos:

This function simply reads a point cloud and calls ``draw_geometries_with_editing``. This function provides vertex selection and cropping.
Expand Down Expand Up @@ -65,8 +65,8 @@ The following script register two point clouds using point-to-point ICP. It gets

.. literalinclude:: ../../../examples/Python/Advanced/interactive_visualization.py
:language: python
:lineno-start: 43
:lines: 43-52
:lineno-start: 51
:lines: 51-60
:linenos:

The script reads two point clouds, and visualize the point clouds before alignment.
Expand All @@ -76,8 +76,8 @@ The script reads two point clouds, and visualize the point clouds before alignme

.. literalinclude:: ../../../examples/Python/Advanced/interactive_visualization.py
:language: python
:lineno-start: 30
:lines: 30-41
:lineno-start: 35
:lines: 35-48
:linenos:

Function ``pick_points(pcd)`` makes an instance of ``VisualizerWithEditing``. To mimic ``draw_geometries``, it creates windows, adds geometry, visualize geometry, and terminates. A novel interface function from ``VisualizerWithEditing`` is ``get_picked_points()`` that returns the indices of user-picked vertices.
Expand Down Expand Up @@ -115,8 +115,8 @@ Registration using user correspondences

.. literalinclude:: ../../../examples/Python/Advanced/interactive_visualization.py
:language: python
:lineno-start: 53
:lines: 53-71
:lineno-start: 61
:lines: 61-80
:linenos:

The later part of the demo computes an initial transformation based on the user-provided correspondences. This script builds pairs of correspondences using ``Vector2iVector(corr)``. It utilizes ``TransformationEstimationPointToPoint.compute_transformation`` to compute the initial transformation from the correspondences. The initial transformation is refined using ``registration_icp``.
Expand Down
14 changes: 7 additions & 7 deletions docs/tutorial/Advanced/multiway_registration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The first part of the tutorial script reads three point clouds from files. The p
.. literalinclude:: ../../../examples/Python/Advanced/multiway_registration.py
:language: python
:lineno-start: 24
:lines: 24-58
:lines: 24-68
:linenos:

A pose graph has two key elements: nodes and edges. A node is a piece of geometry :math:`\mathbf{P}_{i}` associated with a pose matrix :math:`\mathbf{T}_{i}` which transforms :math:`\mathbf{P}_{i}` into the global space. The set :math:`\{\mathbf{T}_{i}\}` are the unknown variables to be optimized. ``PoseGraph.nodes`` is a list of ``PoseGraphNode``. We set the global space to be the space of :math:`\mathbf{P}_{0}`. Thus :math:`\mathbf{T}_{0}` is identity matrix. The other pose matrices are initialized by accumulating transformation between neighboring nodes. The neighboring nodes usually have large overlap and can be registered with :ref:`point_to_plane_icp`.
Expand All @@ -50,8 +50,8 @@ The script creates a pose graph with three nodes and three edges. Among the edge

.. literalinclude:: ../../../examples/Python/Advanced/multiway_registration.py
:language: python
:lineno-start: 72
:lines: 72-79
:lineno-start: 82
:lines: 82-89
:linenos:

Open3D uses function ``global_optimization`` to perform pose graph optimization. Two types of optimization methods can be chosen: ``GlobalOptimizationGaussNewton`` or ``GlobalOptimizationLevenbergMarquardt``. The latter is recommended since it has better convergence property. Class ``GlobalOptimizationConvergenceCriteria`` can be used to set the maximum number of iterations and various optimization parameters.
Expand Down Expand Up @@ -87,8 +87,8 @@ Visualize optimization

.. literalinclude:: ../../../examples/Python/Advanced/multiway_registration.py
:language: python
:lineno-start: 81
:lines: 81-85
:lineno-start: 91
:lines: 91-95
:linenos:

Ouputs:
Expand All @@ -105,8 +105,8 @@ Make a combined point cloud

.. literalinclude:: ../../../examples/Python/Advanced/multiway_registration.py
:language: python
:lineno-start: 87
:lines: 87-95
:lineno-start: 97
:lines: 97-106
:linenos:

.. image:: ../../_static/Advanced/multiway_registration/combined.png
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial/Advanced/non_blocking_visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Prepare example data
.. literalinclude:: ../../../examples/Python/Advanced/non_blocking_visualization.py
:language: python
:lineno-start: 13
:lines: 13-28
:lines: 13-23
:linenos:
This part reads two point clouds and downsamples them. The source point cloud is intentionally transformed for the misalignment. Both point clouds are flipped for better visualization.
Expand All @@ -62,8 +62,8 @@ Initialize Visualizer class
.. literalinclude:: ../../../examples/Python/Advanced/non_blocking_visualization.py
:language: python
:lineno-start: 30
:lines: 30-33
:lineno-start: 25
:lines: 25-28
:linenos:
These lines make an instance of the visualizer class, open a visualizer window, and add two geometries to the visualizer.
Expand All @@ -73,8 +73,8 @@ Transform geometry and visualize it
.. literalinclude:: ../../../examples/Python/Advanced/non_blocking_visualization.py
:language: python
:lineno-start: 38
:lines: 38-48
:lineno-start: 33
:lines: 33-44
:linenos:
This script calls ``registration_icp`` for every iteration. Note that it explicitly forces only one ICP iteration via ``ICPConvergenceCriteria(max_iteration = 1)``. This is a trick to retrieve a slight pose update from a single ICP iteration. After ICP, source geometry is transformed accordingly.
Expand Down
22 changes: 11 additions & 11 deletions docs/tutorial/Advanced/pointcloud_outlier_removal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and artifact that one would like to remove. This tutorial address outlier remova
.. literalinclude:: ../../../examples/Python/Advanced/pointcloud_outlier_removal.py
:language: python
:lineno-start: 5
:lines: 5-41
:lines: 5-
:linenos:


Expand All @@ -20,8 +20,8 @@ A point cloud is loaded and downsampled using ``voxel_downsample``.

.. literalinclude:: ../../../examples/Python/Advanced/pointcloud_outlier_removal.py
:language: python
:lineno-start: 21
:lines: 21-27
:lineno-start: 22
:lines: 22-28
:linenos:

.. image:: ../../_static/Advanced/pointcloud_outlier_removal/voxel_down_sample.png
Expand All @@ -31,8 +31,8 @@ For comparison, ``uniform_down_sample`` can downsample point cloud by collecting

.. literalinclude:: ../../../examples/Python/Advanced/pointcloud_outlier_removal.py
:language: python
:lineno-start: 29
:lines: 29-31
:lineno-start: 30
:lines: 30-32
:linenos:

.. image:: ../../_static/Advanced/pointcloud_outlier_removal/uniform_down_sample.png
Expand All @@ -46,8 +46,8 @@ The selected points and the non-selected points are visualized.

.. literalinclude:: ../../../examples/Python/Advanced/pointcloud_outlier_removal.py
:language: python
:lineno-start: 9
:lines: 9-16
:lineno-start: 10
:lines: 10-17
:linenos:


Expand All @@ -56,8 +56,8 @@ Statistical outlier removal

.. literalinclude:: ../../../examples/Python/Advanced/pointcloud_outlier_removal.py
:language: python
:lineno-start: 33
:lines: 33-36
:lineno-start: 34
:lines: 34-38
:linenos:

``statistical_outlier_removal`` removes points that are further away from their neighbors compared to the average for the point cloud. It takes two input parameters:
Expand All @@ -73,8 +73,8 @@ Radius outlier removal

.. literalinclude:: ../../../examples/Python/Advanced/pointcloud_outlier_removal.py
:language: python
:lineno-start: 38
:lines: 38-41
:lineno-start: 40
:lines: 40-44
:linenos:

``radius_outlier_removal`` removes points that have few neighbors in a given sphere around them. Two parameters can be used to tune the filter to your data:
Expand Down
Loading

0 comments on commit d50699b

Please sign in to comment.