Skip to content

Commit 62c29fb

Browse files
Merge pull request #27 from compas-dev/tessagon_api
Tessagon api
2 parents f66b827 + 49261bf commit 62c29fb

15 files changed

+433
-257
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
### Added
2020

21+
- Added map_pattern_to_mesh function.
22+
2123
### Changed
2224

25+
- Changed map_mesh pattern to output more detailed information about the mapping: vertices, faces, normals, boundaries, group indices.
26+
- Changed examples and test to use new map_mesh function.
27+
2328
### Removed
2429

2530

docs/_images/example_mapping.png

98.1 KB
Loading
-689 Bytes
Loading

docs/api/compas_libigl.rst

Lines changed: 96 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,99 @@
22
compas_libigl
33
********************************************************************************
44

5-
.. currentmodule:: compas_libigl
6-
7-
Functions
8-
=========
9-
10-
.. autosummary::
11-
:toctree: generated/
12-
:nosignatures:
13-
14-
add
15-
get
16-
get_beetle
17-
get_armadillo
18-
intersection_ray_mesh
19-
intersection_rays_mesh
20-
trimesh_boundaries
21-
trimesh_gaussian_curvature
22-
trimesh_principal_curvature
23-
trimesh_geodistance
24-
trimesh_geodistance_multiple
25-
trimesh_isolines
26-
groupsort_isolines
27-
trimesh_massmatrix
28-
trimesh_harmonic_mapping
29-
trimesh_lsc_mapping
30-
quadmesh_planarize
31-
trimesh_remesh_along_isoline
32-
trimesh_remesh_along_isolines
5+
Boundaries
6+
----------
7+
8+
.. autosummary::
9+
:toctree: generated/
10+
:nosignatures:
11+
12+
compas_libigl.boundaries.trimesh_boundaries
13+
14+
Curvature
15+
---------
16+
17+
.. autosummary::
18+
:toctree: generated/
19+
:nosignatures:
20+
21+
compas_libigl.curvature.trimesh_gaussian_curvature
22+
compas_libigl.curvature.trimesh_principal_curvature
23+
24+
Geodesic Distance
25+
-----------------
26+
27+
.. autosummary::
28+
:toctree: generated/
29+
:nosignatures:
30+
31+
compas_libigl.geodistance.trimesh_geodistance
32+
compas_libigl.geodistance.trimesh_geodistance_multiple
33+
34+
Intersections
35+
-------------
36+
37+
.. autosummary::
38+
:toctree: generated/
39+
:nosignatures:
40+
41+
compas_libigl.intersections.intersection_ray_mesh
42+
compas_libigl.intersections.intersection_rays_mesh
43+
44+
Isolines
45+
--------
46+
47+
.. autosummary::
48+
:toctree: generated/
49+
:nosignatures:
50+
51+
compas_libigl.isolines.trimesh_isolines
52+
compas_libigl.isolines.groupsort_isolines
53+
54+
Mapping
55+
-------
56+
57+
.. autosummary::
58+
:toctree: generated/
59+
:nosignatures:
60+
61+
compas_libigl.mapping.map_mesh
62+
compas_libigl.mapping.map_pattern_to_mesh
63+
64+
Mass Matrix
65+
-----------
66+
67+
.. autosummary::
68+
:toctree: generated/
69+
:nosignatures:
70+
71+
compas_libigl.massmatrix.trimesh_massmatrix
72+
73+
Meshing
74+
-------
75+
76+
.. autosummary::
77+
:toctree: generated/
78+
:nosignatures:
79+
80+
compas_libigl.meshing.trimesh_remesh_along_isoline
81+
compas_libigl.meshing.trimesh_remesh_along_isolines
82+
83+
Parametrisation
84+
---------------
85+
86+
.. autosummary::
87+
:toctree: generated/
88+
:nosignatures:
89+
90+
compas_libigl.parametrisation.trimesh_harmonic_mapping
91+
compas_libigl.parametrisation.trimesh_lsc_mapping
92+
93+
Planarization
94+
-------------
95+
96+
.. autosummary::
97+
:toctree: generated/
98+
:nosignatures:
99+
100+
compas_libigl.planarize.quadmesh_planarize

docs/examples/example_mapping.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
from pathlib import Path
22

33
from compas.colors import Color
4+
from compas.geometry import Polyline
45
from compas.datastructures import Mesh
56
from compas_viewer import Viewer
67
from compas_viewer.config import Config
78
from tessagon.adaptors.list_adaptor import ListAdaptor
8-
from tessagon.types.hex_tessagon import HexTessagon
9+
from tessagon.types.zig_zag_tessagon import ZigZagTessagon
910

1011
from compas_libigl.mapping import map_mesh
1112
from compas_libigl.parametrisation import trimesh_lsc_mapping
1213

14+
from compas import json_dump
15+
1316
# ==============================================================================
1417
# Input geometry: 3D Mesh
1518
# ==============================================================================
1619

17-
mesh = Mesh.from_obj(Path(__file__).parent.parent.parent / "data" / "minimal_surface.obj")
20+
mesh = Mesh.from_off(Path(__file__).parent.parent.parent / "data" / "beetle.off")
1821

1922
for vertex in mesh.vertices():
2023
x, y, z = mesh.vertex_attributes(vertex, "xyz") # type: ignore
@@ -32,24 +35,51 @@
3235
"function": lambda u, v: [u * 1, v * 1, 0],
3336
"u_range": [-0.255, 1.33],
3437
"v_range": [-0.34, 1.33],
35-
"u_num": 16,
36-
"v_num": 10,
38+
"u_num": 20,
39+
"v_num": 20,
3740
"u_cyclic": False,
3841
"v_cyclic": False,
3942
"adaptor_class": ListAdaptor,
4043
}
41-
tessagon = HexTessagon(**options)
44+
tessagon = ZigZagTessagon(**options)
4245
tessagon_mesh = tessagon.create_mesh()
4346
pv = tessagon_mesh["vert_list"]
4447
pf = tessagon_mesh["face_list"]
4548

4649
# ==============================================================================
4750
# Mapping: 3D Mesh, 2D Pattern, UV
51+
# mv - mapped vertices
52+
# mf - mapped faces
53+
# mn - mapped normals
54+
# mg - mapped boundaries (True or False)
55+
# mb - mapped groups for polygons with holes (list of int)
4856
# ==============================================================================
49-
50-
mv, mf = map_mesh((v, f), (pv, pf))
57+
mv, mf, mn, mb, mg = map_mesh((v, f), (pv, pf))
5158
mesh_mapped = Mesh.from_vertices_and_faces(mv, mf)
5259

60+
# ==============================================================================
61+
# Offset mesh by normals, normals are interpolated from the original mesh.
62+
# ==============================================================================
63+
mesh_mapped_offset = mesh_mapped.copy()
64+
for i in range(mesh_mapped.number_of_vertices()):
65+
mesh_mapped_offset.vertex_attributes(i, "xyz", mesh_mapped.vertex_attributes(i, "xyz") - mn[i]*0.001)
66+
67+
# ==============================================================================
68+
# Get Boundary Polylines
69+
# ==============================================================================
70+
boundaries = []
71+
for i in range(len(mb)):
72+
if not mb[i]:
73+
continue
74+
points = []
75+
for j in range(len(mf[i])):
76+
id = mf[i][j]
77+
points.append(mesh_mapped.vertex_attributes(id, "xyz") + mn[id]*0.002)
78+
points.append(points[0])
79+
polyline = Polyline(points)
80+
boundaries.append(polyline)
81+
82+
5383
# ==============================================================================
5484
# Viewer
5585
# ==============================================================================
@@ -59,15 +89,20 @@
5989
config.camera.position = [5, 2, 1.5]
6090

6191
viewer = Viewer(config=config)
62-
viewer.scene.add(mesh, name="mesh", show_faces=False, linecolor=Color.grey(), opacity=0.2)
92+
# viewer.scene.add(mesh, name="mesh", show_faces=False, linecolor=Color.grey(), opacity=0.2)
6393
viewer.scene.add(Mesh.from_vertices_and_faces(pv, pf), name="pattern2d")
64-
viewer.scene.add(mesh_mapped, name="mesh_mapped", facecolor=Color.red())
94+
viewer.scene.add(mesh_mapped, name="mesh_mapped", facecolor=Color.pink())
95+
viewer.scene.add(mesh_mapped_offset, name="mesh_mapped", facecolor=Color.blue())
96+
for boundary in boundaries:
97+
viewer.scene.add(boundary, name="boundary", linecolor=Color.yellow(), linewidth=3)
6598

6699
# To see where the pattern is mapped:
67100
uv = trimesh_lsc_mapping((v, f))
68101
mesh_flattened = mesh.copy()
69102
for i in range(mesh.number_of_vertices()):
70103
mesh_flattened.vertex_attributes(i, "xyz", [uv[i][0], uv[i][1], 0])
71104

105+
json_dump([Mesh.from_vertices_and_faces(pv, pf), mesh_mapped, mesh_mapped_offset, boundaries, mesh_flattened], "mesh_flattened.json")
106+
72107
viewer.scene.add(mesh_flattened, name="mesh_flattened")
73108
viewer.show()

docs/examples/example_mapping_all_patterns.py

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)