|
1 | | -```bash |
2 | | -pip install --user --upgrade pip |
| 1 | +# Poisson Surface Reconstruction: 3D point cloud |
| 2 | + |
| 3 | +Import a point cloud file and perform poisson 3D surface reconstruction algorithm, |
| 4 | +integrated with third-party libraries like [open3d](http://www.open3d.org/docs/release/tutorial/geometry/surface_reconstruction.html?highlight=surface%20reconstruction#Poisson-surface-reconstruction) and [pymeshlab](https://github.com/cnr-isti-vclab/PyMeshLab) |
| 5 | + |
| 6 | +# Installation |
| 7 | + |
| 8 | +## Dependencies |
| 9 | + |
| 10 | +- [python 3](https://www.python.org/downloads/) <= *3.8.x* |
| 11 | + > **Recommended:** Use [pyenv](https://github.com/pyenv/pyenv) to install and manage Python versions |
| 12 | +- [numpy](https://numpy.org) >= *1.20* |
| 13 | +- [open3d](http://www.open3d.org) >= *0.12* |
| 14 | +- [pymeshlab](https://github.com/cnr-isti-vclab/PyMeshLab) >= *0.2* |
| 15 | + |
| 16 | + |
| 17 | +### Development dependencies |
3 | 18 |
|
4 | | -# ---- Windows ----- |
| 19 | +- [setuptools](https://pypi.org/project/setuptools): For installation via `setup.py` |
| 20 | +- [setuptools-scm](https://pypi.org/project/setuptools-scm): To generate version numbers from **git tags** |
| 21 | +- [wheel](https://pypi.org/project/wheel/): Built packages `.whl` to install packages with PIP |
| 22 | +- [twine](https://pypi.org/project/twine): Publish packages to https://pypi.org |
| 23 | +- [tqdm](https://pypi.org/project/tqdm): CLI progressbar when publish a package |
5 | 24 |
|
6 | | -# On powershell |
7 | | -pip install pyenv-win --target $HOME\\.pyenv |
| 25 | +# Getting Started |
8 | 26 |
|
| 27 | +Install a Python <= 3.8.x version using [pyenv](https://github.com/pyenv/pyenv) (recommended) |
| 28 | + |
| 29 | +### Windows |
| 30 | + |
| 31 | +```bash |
9 | 32 | # With Chocolatey |
10 | 33 | choco install pyenv-win |
| 34 | +``` |
| 35 | + |
| 36 | +### Linux |
| 37 | + |
| 38 | +```bash |
| 39 | +# With pyenv-installer |
| 40 | +curl https://pyenv.run | bash |
| 41 | +``` |
| 42 | + |
| 43 | +### MacOS |
11 | 44 |
|
| 45 | +```bash |
| 46 | +# With homebrew |
| 47 | +brew update |
| 48 | +brew install pyenv |
| 49 | +``` |
| 50 | + |
| 51 | +Check if pyenv was installed sucessfully, and if not got any error in this project |
| 52 | + |
| 53 | +```bash |
12 | 54 | # Warning: Check if not got any error |
13 | 55 | pyenv rehash |
| 56 | +``` |
14 | 57 |
|
15 | | -# ---- Pyenv: Python versions manager ----- |
| 58 | +Install same Python version inside of the file **[.python-version](.python-version)** |
16 | 59 |
|
| 60 | +```bash |
17 | 61 | cd [project-folder] |
18 | 62 |
|
19 | 63 | # Loads local version from .python-version file |
20 | 64 | pyenv local |
21 | 65 |
|
22 | | -# PS: Latest 3.8.x Python version available in Pyenv for Windows |
| 66 | +# PS: The 3.8.2 Python version is latest available in Pyenv for Windows. |
| 67 | +# On Unix systems, is possible install 3.8.8, for example. |
23 | 68 | pyenv install 3.8.2 |
24 | 69 |
|
| 70 | +# Check the installed version |
25 | 71 | python --version |
| 72 | +``` |
26 | 73 |
|
| 74 | +Create a **Virtual Environment** to store the packages dependencies, and activate it |
27 | 75 |
|
28 | | -# ---- Virtual Environments ---- |
29 | | - |
| 76 | +```bash |
30 | 77 | python -m venv venv |
31 | 78 |
|
32 | 79 | # Activate |
| 80 | + |
| 81 | +# Windows |
33 | 82 | .\venv\Scripts\activate.bat |
34 | 83 |
|
35 | | -pip install -r .\requirements.txt |
| 84 | +# Unix systems |
| 85 | +./venv/Scripts/activate |
| 86 | +``` |
| 87 | + |
| 88 | +Install all dependencies |
| 89 | + |
| 90 | +```bash |
| 91 | +pip install -r .\requirements-dev.txt |
| 92 | +``` |
| 93 | + |
| 94 | +# Configure Pycharm (Optional) |
| 95 | + |
| 96 | +Define your interpreter in your preferable IDE (**Visual Studio, VSCode**...) from the virtual environment. In this case, we are using [Pycharm](https://www.jetbrains.com/pycharm) as example: |
| 97 | + |
| 98 | +1. Click on `File` => `Settings` => `Python Interpeter` |
| 99 | +2. Add your interpreter from your virtual environment (**recommended**) |
| 100 | +3. If you prefer, download from the official python.org FTP clicking on `"New enviroment"`, as showed in the picture below |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +## Install this package |
| 105 | + |
| 106 | +Quick way: |
| 107 | + |
| 108 | +```bash |
| 109 | +pip install surface_reconstruction |
| 110 | +``` |
| 111 | + |
| 112 | +Or clone the repository and run from the project root: |
| 113 | + |
| 114 | +```bash |
| 115 | +python setup.py install |
| 116 | +``` |
| 117 | + |
| 118 | +## Run the unit tests |
| 119 | + |
| 120 | +```bash |
| 121 | +# Run all tests of the module "surface_reconstruction_test` |
| 122 | +python -m unittest tests/surface_reconstruction_test.py |
| 123 | +``` |
| 124 | + |
| 125 | +# Usage |
| 126 | + |
| 127 | +Import a `.ply` file with point cloud vertices, and generate the mesh file |
| 128 | + |
| 129 | +```python |
| 130 | +from surface_reconstruction import SurfaceReconstruction |
| 131 | +import os |
| 132 | + |
| 133 | +# Pass a method/library that contains a Poisson algorithm implementation |
| 134 | +surface = SurfaceReconstruction( |
| 135 | + method_type='open3d', |
| 136 | + point_cloud_file=os.path.join('files', 'point_cloud.ply'), |
| 137 | + output_file=os.path.join('files', 'terrain_mesh.ply') |
| 138 | +) |
| 139 | + |
| 140 | +# Call the method from the specific library, and export a mesh file |
| 141 | +surface.poisson_mesh() |
36 | 142 | ``` |
37 | 143 |
|
38 | | -### Integrate .NET and Python: Strategies |
| 144 | +You can pass custom filters/parameters for the specific library. This is important because |
| 145 | +poisson algorithm requires some pre-filters before to be applied (e.g **estimate normals** in the point cloud) |
| 146 | + |
| 147 | +```python |
| 148 | +# ... |
| 149 | +parameters = { |
| 150 | + 'estimate_normals': { |
| 151 | + 'fast_normal_computation': False, |
| 152 | + 'normals': (1, 3) |
| 153 | + } |
| 154 | +} |
39 | 155 |
|
40 | | -1. IronPython = Interpreter para gerar Python em IL (Intermediate Language) |
41 | | -2. Biblioteca = CLI assincrona |
42 | | -3. Backend Web Python: http://aaaaaa.py => {aaa:bbbb} (C#) |
43 | | -4. Service Tray Python => C# |
| 156 | +# Unpack the dictionary "parameters" as a **kwargs |
| 157 | +surface.poisson_mesh(**{'filters': parameters}) |
| 158 | +``` |
| 159 | +> **PS:** See the unittests inside **[tests](./tests)** folder for more usage examples |
| 160 | +
|
| 161 | +# Extending: Add new libraries |
| 162 | + |
| 163 | +Is possible create and register custom strategies to allow others libraries (`Python`, `C++` bindings...) |
| 164 | + |
| 165 | +```python |
| 166 | +from surface_reconstruction import SurfaceStrategy, SurfaceReconstruction |
| 167 | + |
| 168 | +# Create a class that inherit from "SurfaceStrategy" |
| 169 | +class MyCustomSurface(SurfaceStrategy): |
| 170 | + |
| 171 | + def __init__(self, my_custom_param: dict): |
| 172 | + """ |
| 173 | + Custom constructor with custom parameters |
| 174 | + """ |
| 175 | + super.__init__() |
| 176 | + |
| 177 | + def load_file(self, file_path: str): |
| 178 | + """ |
| 179 | + Custom load point cloud file implementation here |
| 180 | + """ |
| 181 | + pass |
| 182 | + |
| 183 | + def poisson_mesh(self, save_file=True, **params: {}): |
| 184 | + """ |
| 185 | + Generate the mesh file with faces/triangles here |
| 186 | + """ |
| 187 | + pass |
| 188 | + |
| 189 | +# Register your custom strategy here |
| 190 | +SurfaceReconstruction.register_type(MyCustomSurface) |
| 191 | + |
| 192 | + |
| 193 | +# Pass a method/library that contains a Poisson algorithm implementation |
| 194 | +surface = SurfaceReconstruction( |
| 195 | + method_type='mycustom', # Don't pass the "surface" suffix |
| 196 | + my_custom_param={'extra_config': 'some_value'}, |
| 197 | +) |
| 198 | + |
| 199 | +# Call the method from the specific library, and export a mesh file |
| 200 | +surface.poisson_mesh() |
| 201 | +``` |
0 commit comments