Skip to content

Commit 9720c11

Browse files
committed
First draft - where to implement faces (rudimentary)
1 parent a9e7e74 commit 9720c11

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

splinepy/io/svg.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
_color_map = ModuleImportRaiser(_error_message_vedo_import, err)
1515
_get_color = ModuleImportRaiser(_error_message_vedo_import, err)
1616

17+
from gustaf import Faces as _Faces
1718
from gustaf import Vertices as _Vertices
19+
from gustaf import Volumes as _Volumes
1820

1921
from splinepy.utils.log import debug as _debug
2022
from splinepy.utils.log import warning as _warning
@@ -260,8 +262,11 @@ def _export_gustaf_object(
260262
r, g, b = _get_color(gus_object.show_options.get("c", "red"))
261263
a = gus_object.show_options.get("alpha", 1.0)
262264
radius = gus_object.show_options.get("r", 0.1)
265+
stroke_width = gus_object.show_options.get("lw", 0.1)
263266

264-
if isinstance(gus_object, _Vertices):
267+
if isinstance(gus_object, _Vertices) and not isinstance(
268+
gus_object, _Faces
269+
):
265270
data_name = gus_object.show_options.get("data", None)
266271
if data_name is not None:
267272
# Retrieve information on colors and values
@@ -330,6 +335,31 @@ def _export_gustaf_object(
330335
dy=str(dx),
331336
)
332337
text_element.text = label
338+
if isinstance(gus_object, _Faces) and not isinstance(gus_object, _Volumes):
339+
svg_faces = _ET.SubElement(
340+
svg_spline_element,
341+
"g",
342+
id="faces",
343+
style=(
344+
f"fill:none;stroke:{_rgb_2_hex(r,g,b)};stroke-opacity:{a};"
345+
f"stroke-width:{stroke_width};stroke-linecap:round"
346+
),
347+
)
348+
349+
# Create a new face-group
350+
for face in gus_object.faces:
351+
edge_points = gus_object.vertices[[*face, face[0]], :]
352+
353+
_ET.SubElement(
354+
svg_faces,
355+
"polyline",
356+
points=" ".join(
357+
[
358+
str(xx - box_min_x) + "," + str(box_max_y - xy)
359+
for (xx, xy) in edge_points
360+
]
361+
),
362+
)
333363

334364
else:
335365
raise NotImplementedError(

0 commit comments

Comments
 (0)