primlib 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
primlib/visualizer.py ADDED
@@ -0,0 +1,179 @@
1
+ import numpy as np
2
+ import polyscope as ps
3
+
4
+ from primlib.line_set import LineSet
5
+ from primlib.point_cloud import PointCloud
6
+ from primlib.triangle_mesh import TriangleMesh
7
+
8
+
9
+ def _visualize_line_set(lineset: LineSet, params=None):
10
+ # Handle visualization parameters
11
+ default_params = {
12
+ "object": None,
13
+ "name": "Line Set",
14
+ "color": None,
15
+ "size": None,
16
+ }
17
+ if params is None:
18
+ params = {}
19
+ for p in params:
20
+ if p not in default_params:
21
+ raise Exception(f'Unknown parameter "{p}"')
22
+ params = default_params | params
23
+ # Visualize vertices and lines
24
+ ps_net = ps.register_curve_network(params["name"], lineset.vertices, lineset.lines)
25
+ ps_net.set_enabled(True)
26
+ if params["size"] is not None:
27
+ ps_net.set_radius(params["size"])
28
+ if params["color"] is None:
29
+ if lineset.has_colors:
30
+ ps_net.add_color_quantity(
31
+ "vertex colors", lineset.colors, enabled=True
32
+ )
33
+ elif lineset.has_line_colors:
34
+ ps_net.add_color_quantity(
35
+ "line colors", lineset.line_colors, defined_on="edges", enabled=True
36
+ )
37
+ else:
38
+ ps_net.set_color((0.0, 0.5, 0.5))
39
+ else:
40
+ ps_net.set_color(params["color"])
41
+
42
+
43
+ def _visualize_point_cloud(pcl: PointCloud, params=None):
44
+ # Handle visualization parameters
45
+ default_params = {
46
+ "object": None,
47
+ "name": "Point Cloud",
48
+ "color": None,
49
+ "size": None,
50
+ "normals_show": False,
51
+ "normals_color": None,
52
+ "normals_every_nth": 1,
53
+ "normals_size": None,
54
+ "normals_length": 1.0,
55
+ }
56
+ if params is None:
57
+ params = {}
58
+ for p in params:
59
+ if p not in default_params:
60
+ raise Exception(f'Unknown parameter "{p}"')
61
+ params = default_params | params
62
+ # Visualize points
63
+ ps_cloud = ps.register_point_cloud(params["name"], pcl.vertices)
64
+ ps_cloud.set_point_render_mode("quad")
65
+ ps_cloud.set_enabled(True)
66
+ if params["size"] is not None:
67
+ ps_cloud.set_radius(params["size"])
68
+ if params["color"] is None:
69
+ if pcl.has_colors:
70
+ ps_cloud.add_color_quantity("point colors", pcl.colors, enabled=True)
71
+ else:
72
+ ps_cloud.set_color((0.0, 0.5, 0.5))
73
+ else:
74
+ ps_cloud.set_color(params["color"])
75
+ # Visualize normals
76
+ if pcl.has_normals and params["normals_show"]:
77
+ normals = np.full((pcl.size, 3), np.nan)
78
+ n = pcl.size // params["normals_every_nth"]
79
+ indices = np.random.choice(pcl.size, n, replace=False)
80
+ normals[indices] = pcl.normals[indices]
81
+ ps_cloud.add_vector_quantity(
82
+ "normals",
83
+ normals,
84
+ radius=params["normals_size"],
85
+ length=params["normals_length"],
86
+ color=params["normals_color"],
87
+ # vectortype="ambient",
88
+ enabled=True,
89
+ )
90
+
91
+
92
+ def _visualize_triangle_mesh(mesh: TriangleMesh, params=None):
93
+ # Handle visualization parameters
94
+ default_params = {
95
+ "object": None,
96
+ "name": "Triangle Mesh",
97
+ "color": None,
98
+ "normals_show": False,
99
+ "normals_color": None,
100
+ "normals_every_nth": 1,
101
+ "normals_size": None,
102
+ "normals_length": 1.0,
103
+ }
104
+ if params is None:
105
+ params = {}
106
+ for p in params:
107
+ if p not in default_params:
108
+ raise Exception(f'Unknown parameter "{p}"')
109
+ params = default_params | params
110
+ # Visualize vertices and faces
111
+ ps_mesh = ps.register_surface_mesh(params["name"], mesh.vertices, mesh.faces)
112
+ ps_mesh.set_smooth_shade(True)
113
+ ps_mesh.set_back_face_policy("cull")
114
+ ps_mesh.set_enabled(True)
115
+ if params["color"] is None:
116
+ if mesh.has_colors:
117
+ ps_mesh.add_color_quantity("vertex colors", mesh.colors, enabled=True)
118
+ elif mesh.has_face_colors:
119
+ ps_mesh.add_color_quantity(
120
+ "face colors", mesh.face_colors, defined_on="faces", enabled=True
121
+ )
122
+ else:
123
+ ps_mesh.set_color((0.0, 0.5, 0.5))
124
+ else:
125
+ ps_mesh.set_color(params["color"])
126
+ # Visualize vertex normals
127
+ if mesh.has_normals and params["normals_show"]:
128
+ normals = np.full((mesh.num_vertices, 3), np.nan)
129
+ n = mesh.num_vertices // params["normals_every_nth"]
130
+ indices = np.random.choice(mesh.num_vertices, n, replace=False)
131
+ normals[indices] = mesh.normals[indices]
132
+ ps_mesh.add_vector_quantity(
133
+ "vertex normals",
134
+ normals,
135
+ radius=params["normals_size"],
136
+ length=params["normals_length"],
137
+ color=params["normals_color"],
138
+ # vectortype="ambient",
139
+ enabled=True,
140
+ )
141
+
142
+
143
+ def _keyboard_callback():
144
+ if ps.imgui.IsKeyPressed(ps.imgui.ImGuiKey_Q):
145
+ ps.unshow()
146
+
147
+
148
+ def visualize(objects):
149
+ ps.set_program_name("Lighthouse")
150
+ ps.set_verbosity(0)
151
+ ps.set_use_prefs_file(False)
152
+ ps.set_up_dir("z_up")
153
+ ps.init()
154
+ ps.remove_all_structures()
155
+ ps.reset_camera_to_home_view()
156
+ ps.set_give_focus_on_show(True)
157
+ # Disable the automatic ImGui window pane for callbacks
158
+ ps.set_open_imgui_window_for_user_callback(False)
159
+ # Register user callback function
160
+ ps.set_user_callback(_keyboard_callback)
161
+ for i, obj in enumerate(objects):
162
+ if isinstance(obj, LineSet):
163
+ _visualize_line_set(obj, {"name": f"Line Set {i}"})
164
+ elif isinstance(obj, PointCloud):
165
+ _visualize_point_cloud(obj, {"name": f"Point Cloud {i}"})
166
+ elif isinstance(obj, TriangleMesh):
167
+ _visualize_triangle_mesh(obj, {"name": f"Triangle Mesh {i}"})
168
+ elif isinstance(obj, dict):
169
+ if isinstance(obj["object"], LineSet):
170
+ _visualize_line_set(obj["object"], obj)
171
+ elif isinstance(obj["object"], PointCloud):
172
+ _visualize_point_cloud(obj["object"], obj)
173
+ elif isinstance(obj["object"], TriangleMesh):
174
+ _visualize_triangle_mesh(obj["object"], obj)
175
+ else:
176
+ raise TypeError(f"No known visualization for {type(obj['object'])}")
177
+ else:
178
+ raise TypeError(f"No known visualization for {type(obj)}")
179
+ ps.show()
@@ -0,0 +1,124 @@
1
+ Metadata-Version: 2.4
2
+ Name: primlib
3
+ Version: 0.3.0
4
+ Summary: Primlib: a Python framework for handling 3D geometric primitives
5
+ Author-email: Philipp Roebrock <philipp.roebrock@fhgr.ch>
6
+ License: MIT License
7
+
8
+ Lighthouse: https://gitlab.com/proebrock/lighthouse/
9
+ Copyright (c) 2021 Philipp Roebrock
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://gitlab.com/proebrock/primlib
30
+ Project-URL: Issues, https://gitlab.com/proebrock/primlib/issues
31
+ Requires-Python: >=3.10
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+ Requires-Dist: matplotlib
35
+ Requires-Dist: numpy
36
+ Requires-Dist: plyfile
37
+ Requires-Dist: polyscope
38
+ Requires-Dist: pyembree2
39
+ Requires-Dist: scipy
40
+ Requires-Dist: trafolib
41
+ Provides-Extra: test
42
+ Requires-Dist: pytest; extra == "test"
43
+ Requires-Dist: pytest-cov; extra == "test"
44
+ Provides-Extra: dev
45
+ Requires-Dist: pytest; extra == "dev"
46
+ Requires-Dist: pytest-cov; extra == "dev"
47
+ Requires-Dist: ruff; extra == "dev"
48
+ Dynamic: license-file
49
+
50
+ # Primlib
51
+ ![Pipeline Status](https://gitlab.com/proebrock/primlib/badges/devel/pipeline.svg)
52
+ ![Coverage](https://gitlab.com/proebrock/primlib/badges/devel/coverage.svg)
53
+
54
+ Library for processing geometrical primitives like point clouds or triangle meshes.
55
+
56
+ ## Features
57
+ - Class representation of a point cloud
58
+ - Class representation of a triangle mesh
59
+ - Class representation of a line set
60
+ - Main library has just NumPy and SciPy as external dependencies
61
+ - Fast 3d visualization using Polyscope library
62
+ - **Permissive License (MIT)**, code can be used in commercial software
63
+
64
+ ## Requirements
65
+ - [Python](https://www.python.org/) >=3.10
66
+ - [NumPy](https://numpy.org/)
67
+ - [SciPy](https://scipy.org/)
68
+ - [Matplotlib](https://matplotlib.org/)
69
+ - [trafolib](https://gitlab.com/proebrock/trafolib) for represenation of rigid body transformations
70
+ - [plyfile](https://pypi.org/project/plyfile/) for loading PLY files
71
+ - [Polyscope](https://polyscope.run/py/) for visualization
72
+ - [pyembree2](https://pypi.org/project/pyembree2/) as wrapper for Intel Embree for mesh-point distance computations
73
+ - [pytest](https://docs.pytest.org/en/stable/) and [pytest-cov](https://pypi.org/project/pytest-cov/) for testing
74
+ - [Ruff](https://github.com/astral-sh/ruff) for linting
75
+
76
+ All dependencies are declared in [`pyproject.toml`](pyproject.toml).
77
+
78
+ ## Installation
79
+ It is strongly recommended to use a **virtual environment**.
80
+
81
+ ### For Users (Runtime Only)
82
+ This will install the core libraries needed to run Primlib, without any development tools or tests.
83
+
84
+ ```bash
85
+ pip install primlib
86
+ ```
87
+
88
+ ### 2. For Developers
89
+ This installation is for **contributors** who want to run tests or modify the code.
90
+
91
+ 1. Clone the repository:
92
+ ```bash
93
+ git clone https://gitlab.com/proebrock/primlib.git
94
+ cd primlib
95
+ ```
96
+ 2. Create a virtual environment (recommended):
97
+ ```bash
98
+ python -m venv .venv
99
+ source .venv/bin/activate # Linux / macOS
100
+ .venv\Scripts\activate # Windows
101
+ ```
102
+
103
+ 3. Install the project with development extras:
104
+ ```bash
105
+ pip install -e ".[dev]"
106
+ ```
107
+ 4. Run ruff:
108
+ - As a linter:
109
+ ```bash
110
+ ruff check
111
+ ```
112
+ - As a formatter:
113
+ ```bash
114
+ ruff format
115
+ ```
116
+ 5. Run all tests:
117
+ ```bash
118
+ pytest
119
+ ```
120
+
121
+ ## About me and the project
122
+ My name is Philipp Roebrock and I work as a lecturer at the Institute for Photonics and Robotics at the University of Applied Sciences of the Grisons [FHGR](https://www.fhgr.ch/) in Chur in Switzerland.
123
+
124
+ If you have any questions or suggestions please drop and issue or a personal message to `philipp DOT roebrock AT fhgr DOT ch`.
@@ -0,0 +1,13 @@
1
+ primlib/__init__.py,sha256=2lTZ3JoTOEvRMKVFwp39BWxGxVEO_NwHuVFJM7-3cUI,159
2
+ primlib/_version.py,sha256=RCY04NY0kBCyn6ttH6lnVL6Gz2gceOrt45f0yDOOU8A,520
3
+ primlib/line_set.py,sha256=_mpAjHKVJWOKWgxkF0-NKXzcnllBB1Vsxz613mciAGU,15013
4
+ primlib/point_cloud.py,sha256=UWKDISUScSimrR9RaP8sVUlhZ7KihtkIVinok6yVFbs,27889
5
+ primlib/triangle_mesh.py,sha256=OtDG5OgdXDJF432wHopgsJHdVzdSk1ucw2pua1Y4Bak,75232
6
+ primlib/utils.py,sha256=JjA3xX2vJY3OjOrjiaCYfz7SIpLEpHIXVtdTRs8VK8w,1766
7
+ primlib/vertices.py,sha256=u2hV9rFvp6vz9d_vzfzeDhlCqs9MY7flnSv1dk-VHTU,21643
8
+ primlib/visualizer.py,sha256=gss7QQYIEw0V8ao9902XlzDN9Sq2Ev9K9S9kaJLQsOg,6261
9
+ primlib-0.3.0.dist-info/licenses/LICENSE,sha256=3qmCAKk6lAm3e04gpoSpxPED2PrFm-7F0_FxdPs7Tt0,1126
10
+ primlib-0.3.0.dist-info/METADATA,sha256=00nibDF7AyWdsltMLZY1UBhmL8uKa9RU5uIlaAosvm4,4730
11
+ primlib-0.3.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
12
+ primlib-0.3.0.dist-info/top_level.txt,sha256=2RIG5bcqke8OHr9AWqDofmb03VQXtJyyGnivp3_yERM,8
13
+ primlib-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Lighthouse: https://gitlab.com/proebrock/lighthouse/
4
+ Copyright (c) 2021 Philipp Roebrock
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ primlib