Skip to content

Commit e3d504a

Browse files
committed
docs(readme): Update README with usage details
1 parent b3a8759 commit e3d504a

File tree

4 files changed

+179
-21
lines changed

4 files changed

+179
-21
lines changed

README.md

Lines changed: 173 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,201 @@
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
318

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
524

6-
# On powershell
7-
pip install pyenv-win --target $HOME\\.pyenv
25+
# Getting Started
826

27+
Install a Python <= 3.8.x version using [pyenv](https://github.com/pyenv/pyenv) (recommended)
28+
29+
### Windows
30+
31+
```bash
932
# With Chocolatey
1033
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
1144

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
1254
# Warning: Check if not got any error
1355
pyenv rehash
56+
```
1457

15-
# ---- Pyenv: Python versions manager -----
58+
Install same Python version inside of the file **[.python-version](.python-version)**
1659

60+
```bash
1761
cd [project-folder]
1862

1963
# Loads local version from .python-version file
2064
pyenv local
2165

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.
2368
pyenv install 3.8.2
2469

70+
# Check the installed version
2571
python --version
72+
```
2673

74+
Create a **Virtual Environment** to store the packages dependencies, and activate it
2775

28-
# ---- Virtual Environments ----
29-
76+
```bash
3077
python -m venv venv
3178

3279
# Activate
80+
81+
# Windows
3382
.\venv\Scripts\activate.bat
3483

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+
![pycharm-python-intepreter](./images/pycharm-venv-screenshot.png)
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()
36142
```
37143

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+
}
39155

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+
```

images/pycharm-venv-screenshot.png

0 Bytes
Loading

surface_reconstruction/pymeshlab_surface.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,14 @@ def __init__(self, point_cloud_file="", output_file="", filter_script_file="", c
113113
self.mesh_set = pymeshlab.MeshSet()
114114
self.point_cloud = pymeshlab.Mesh()
115115
self.mesh = pymeshlab.Mesh()
116-
self.__filter_script_file = filter_script_file
117116

118-
super().__init__(point_cloud_file, output_file, clean_up)
117+
super().__init__(point_cloud_file, output_file, filter_script_file, clean_up)
119118

120119
def load_file(self, file_path: str) -> pymeshlab.Mesh:
121120
self.mesh_set.load_new_mesh(file_path)
122121

123-
if len(self.__filter_script_file) > 0:
124-
self.mesh_set.load_filter_script(self.__filter_script_file)
122+
if len(self.filter_script_file) > 0:
123+
self.mesh_set.load_filter_script(self.filter_script_file)
125124

126125
self.point_cloud = self.mesh_set.current_mesh()
127126
return self.mesh_set.current_mesh()
@@ -130,7 +129,7 @@ def poisson_mesh(self, save_file=True, **params: {}) -> pymeshlab.Mesh:
130129

131130
self.applied_filters = False
132131

133-
if len(self.__filter_script_file) > 0:
132+
if len(self.filter_script_file) > 0:
134133
self.mesh_set.apply_filter_script()
135134
self.applied_filters = True
136135
else:

surface_reconstruction/surface_strategy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ class SurfaceStrategy(ABC):
2323

2424
_parameters_key_values = {}
2525

26-
def __init__(self, point_cloud_file="", output_file="", clean_up=True):
26+
def __init__(self, point_cloud_file="", output_file="", filter_script_file="", clean_up=True):
2727
self.output_file = output_file
28+
self.filter_script_file = filter_script_file
2829
self.normals_estimated = False
2930
self.applied_filters = False
3031

0 commit comments

Comments
 (0)