Skip to content

Commit bf6a32f

Browse files
committed
working on triangle remeshing
1 parent f2bc00d commit bf6a32f

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

src/compas/_os.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ def select_python(python_executable):
4040

4141
if PYTHON_DIRECTORY and os.path.exists(PYTHON_DIRECTORY):
4242
python = os.path.join(PYTHON_DIRECTORY, python_executable)
43-
4443
if os.path.exists(python):
4544
return python
4645

4746
python = os.path.join(PYTHON_DIRECTORY, '{0}.exe'.format(python_executable))
47+
if os.path.exists(python):
48+
return python
49+
50+
python = os.path.join(PYTHON_DIRECTORY, 'bin', python_executable)
51+
if os.path.exists(python):
52+
return python
4853

54+
python = os.path.join(PYTHON_DIRECTORY, 'bin', '{0}.exe'.format(python_executable))
4955
if os.path.exists(python):
5056
return python
5157

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
5+
from .remesh import *
6+
from .remesh_triangle import *
7+
8+
__all__ = [name for name in dir() if not name.startswith('_')]
File renamed without changes.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
5+
try:
6+
from triangle import triangulate
7+
except ImportError:
8+
pass
9+
10+
from compas.utilities import pairwise
11+
from compas.geometry import centroid_points_xy
12+
13+
14+
__all__ = ['trimesh_remesh_triangle']
15+
16+
17+
def trimesh_remesh_triangle(mesh, target, boundary=None, holes=None):
18+
segments = []
19+
_holes = []
20+
if boundary:
21+
segments += list(pairwise(boundary + boundary[:1]))
22+
# if holes:
23+
# for boundary in holes:
24+
# segments += list(pairwise(boundary + boundary[:1]))
25+
# _holes.append(centroid_points_xy(boundary))
26+
tri = {
27+
'vertices': list(mesh.get_vertices_attributes('xy')),
28+
'segments': segments,
29+
'holes' : _holes,
30+
}
31+
print(tri['vertices'])
32+
result = triangulate(tri, opts='rpa.5'.format(target))
33+
print(result)
34+
vertices = result['vertices'].tolist()
35+
triangles = result['triangles'].tolist()
36+
cls = type(mesh)
37+
return cls.from_vertices_and_faces(vertices, triangles)
38+
39+
40+
# ==============================================================================
41+
# Main
42+
# ==============================================================================
43+
44+
if __name__ == '__main__':
45+
46+
from compas.datastructures import Mesh
47+
from compas.plotters import MeshPlotter
48+
49+
vertices = [(0.0, 0.0, 0.0), (10.0, 0.0, 0.0), (6.0, 10.0, 0.0), (0.0, 10.0, 0.0)]
50+
faces = [[0, 1, 2, 3]]
51+
52+
mesh = Mesh.from_vertices_and_faces(vertices, faces)
53+
key = mesh.insert_vertex(0)
54+
55+
area = sum(mesh.face_area(fkey) for fkey in mesh.faces()) / mesh.number_of_faces()
56+
print(area)
57+
58+
for fkey in mesh.faces():
59+
print(len(mesh.face_vertices(fkey)))
60+
61+
finer = trimesh_remesh_triangle(mesh, target=area/10.0)
62+
print(finer, key)
63+
64+
plotter = MeshPlotter(finer, figsize=(10, 7))
65+
plotter.draw_edges()
66+
plotter.show()

0 commit comments

Comments
 (0)