Skip to content

Commit

Permalink
add resolution to draw_spline
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Mar 14, 2023
1 parent 4d99660 commit 5e71933
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/advanced/spline_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
pic = Picture(dataurl + "images/embryo.jpg")

plt = SplinePlotter(pic)
plt.show(mode="image", zoom='tightest')
plt.show(mode="image", zoom='tight')
print("Npts =", len(plt.cpoints), "NSpline =", plt.line.npoints)


#####################################################################
Expand Down
26 changes: 16 additions & 10 deletions vedo/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ def __init__(self, obj, init_points=(), **kwargs):
self.mode = 'trackball'
self.verbose = True
self.splined = True
self.resolution = None # spline resolution (None = automatic)
self.closed = False
self.lcolor = 'yellow4'
self.lwidth = 3
Expand All @@ -1066,19 +1067,24 @@ def __init__(self, obj, init_points=(), **kwargs):

if isinstance(obj, str):
self.object = vedo.io.load(obj)
# keep rgb but drop alpha channel
self.mode = 'image'
else:
self.object = obj

self += obj
if isinstance(self.object, vedo.Picture):
self.mode = 'image'

t = """Click to add a point
Right-click to remove it
Drag mouse to change constrast
Press c to clear points
Press q to continue""".replace(" ","")
self.instructions = Text2D(t, pos='bottom-left', c='white', bg='green', font='Calco')
t = (
"Click to add a point\n"
"Right-click to remove it\n"
"Drag mouse to change constrast\n"
"Press c to clear points\n"
"Press q to continue"
)
self.instructions = Text2D(
t, pos='bottom-left', c='white', bg='green', font='Calco'
)

self += [self.object, self.instructions]

self.callid1 = self.add_callback('KeyPress', self._key_press)
self.callid2 = self.add_callback('LeftButtonPress', self._on_left_click)
Expand Down Expand Up @@ -1125,7 +1131,7 @@ def _update(self):
if self.lwidth and len(self.cpoints) > minnr:
if self.splined:
try:
self.line = Spline(self.cpoints, closed=self.closed)
self.line = Spline(self.cpoints, closed=self.closed, res=self.resolution)
except ValueError:
# if clicking too close splining might fail
self.cpoints.pop()
Expand Down

0 comments on commit 5e71933

Please sign in to comment.