Skip to content

Commit 5ad5f9c

Browse files
committed
Add export method. Adjust show view layout. Reorganize help doc to put view options first.
1 parent d2ea02c commit 5ad5f9c

File tree

4 files changed

+166
-95
lines changed

4 files changed

+166
-95
lines changed

Classes/PointView.sc

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,24 +308,23 @@ PointView : View {
308308
VLayout(
309309
HLayout(
310310
axChk,
311-
StaticText().string_("Axes").align_(\left),
312-
15,
311+
StaticText().string_("Axes").align_(\left).minWidth_(90),
312+
nil,
313313
StaticText().string_("length: ").align_(\left),
314-
axLenSl
314+
axLenSl,
315+
nil
315316
),
316317
HLayout(
317318
indcChk,
318-
StaticText().string_("Indices").align_(\left),
319+
StaticText().string_("Indices").align_(\left).minWidth_(90),
319320
nil
320321
),
321322
HLayout(
322323
connChk,
323-
StaticText().string_("Connections").align_(\left),
324+
StaticText().string_("Connections").align_(\left).minWidth_(90),
324325
nil,
325326
triBut,
326-
3,
327327
seqBut,
328-
3,
329328
origBut
330329
),
331330
statusTxt,
@@ -1512,6 +1511,42 @@ PointView : View {
15121511

15131512
numPoints { ^this.points.size }
15141513

1514+
export { |fileName, directory = (Platform.userHomeDir), format, quality = -1, hideControls = true, finishCond|
1515+
var fnPn, dirPn, path, img, win;
1516+
var visibleState;
1517+
1518+
fnPn = PathName(fileName);
1519+
dirPn = PathName(directory);
1520+
if (File.exists(dirPn.fullPath).not) {
1521+
Error("Target directory doens't exist. No image saved.").errorString.postln;
1522+
^this
1523+
};
1524+
1525+
if (hideControls) {
1526+
visibleState = this.children.collect(_.visible);
1527+
this.children.do({ |elem|
1528+
if (elem.isKindOf(UserView).not) { elem.visible = false }
1529+
});
1530+
};
1531+
1532+
path = (dirPn +/+ fnPn).fullPath;
1533+
fork ({
1534+
postf("Writing the plot to: % ...", path);
1535+
img = Image.fromWindow(this, this.bounds.origin_(0@0));
1536+
win = img.plot(freeOnClose:true);
1537+
0.3.wait;
1538+
img.write(path, format, quality);
1539+
win.close;
1540+
if (hideControls) {
1541+
this.children.do({ |elem, i|
1542+
elem.visible = visibleState[i];
1543+
});
1544+
};
1545+
"done.".postln;
1546+
finishCond !? { finishCond.test_(true).signal };
1547+
}, AppClock);
1548+
}
1549+
15151550
update { |who, what ... args|
15161551

15171552
// Support for SphericalDesign class

HelpSource/PointView.schelp

Lines changed: 120 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -107,92 +107,6 @@ METHOD:: numPoints
107107
Get the number of points displayed.
108108

109109

110-
SUBSECTION::Movement: rotation
111-
112-
METHOD:: rotate
113-
METHOD:: tilt
114-
METHOD:: tumble
115-
The rotation of the displayed points, on each axis, in radians. Default positive directions
116-
are:
117-
list::
118-
##strong::rotate::: counter-clockwise
119-
##strong::tilt::: left-up
120-
##strong::tumble::: front-up
121-
::
122-
123-
METHOD:: rotateDir
124-
METHOD:: tiltDir
125-
METHOD:: tumbleDir
126-
METHOD:: allDir
127-
A flag to specify the direction of rotation on each or all axes. A
128-
code::dir:: of code::1:: will select the default direction for that axis (see
129-
above) while code::-1:: will invert the direction of rotation.
130-
131-
METHOD:: reset
132-
Reset rotations to defaults. (code::rotate = -45.degrad, tilt = 0, tumble = 0::)
133-
134-
METHOD:: rotateMode
135-
Set the order of rotations when applying compound rotations to the points.
136-
code::'rtt':: for Rotate-Tilt-Tumble, code::'ypr':: Yaw-Pitch-Roll.
137-
138-
139-
SUBSECTION::Movement: animation
140-
141-
METHOD:: rotateOsc
142-
METHOD:: tiltOsc
143-
METHOD:: tumbleOsc
144-
METHOD:: allOsc
145-
A link::Classes/Boolean:: flag stating whether the display (including axes) will
146-
oscillate around each axis or all axes.
147-
148-
METHOD:: rotateOscPeriod
149-
METHOD:: tiltOscPeriod
150-
METHOD:: tumbleOscPeriod
151-
METHOD:: allOscPeriod
152-
The period of oscillation on each axis or all axes, in seconds.
153-
154-
METHOD:: rotateOscWidth
155-
METHOD:: tiltOscWidth
156-
METHOD:: tumbleOscWidth
157-
METHOD:: allOscWidth
158-
Set the oscillation width of each axis or all axes, in radians.
159-
160-
METHOD:: rotateCyc
161-
METHOD:: tiltCyc
162-
METHOD:: tumbleCyc
163-
METHOD:: allCyc
164-
A link::Classes/Boolean:: flag stating whether the display (including axes) will
165-
rotate cyclically around each axis or all axes.
166-
167-
METHOD:: rotateCycPeriod
168-
METHOD:: tiltCycPeriod
169-
METHOD:: tumbleCyclePeriod
170-
METHOD:: allCycPeriod
171-
The cycle period of each axis or all axes, in seconds.
172-
173-
METHOD:: rotateCycRate
174-
METHOD:: tiltCycRate
175-
METHOD:: tumbleCycRate
176-
METHOD:: allCycRate
177-
The cycle period of each axis or all axes, in Hertz.
178-
179-
METHOD:: varyMotion
180-
Set an code::axis:: (code::'rotate'::, code::'tilt'::, or code::'tumble'::)
181-
with a link::Classes/Boolean:: flag to randomize its motion, if it's
182-
oscillating or cycling.
183-
184-
METHOD:: randomVariance
185-
Set the random variance applied to those axes for which link::#-varyMotion::
186-
is code::true::. The value of variance is normalized to the phase increment of
187-
each frame, so a variance of code::0:: has no effect, while a variance of
188-
code::1:: could potentially step twice as far (twice as fast) on each frame.
189-
Default is code::0.15::.
190-
191-
METHOD:: frameRate
192-
Set the framerate of the animation if the view is set to cycle
193-
(link::#-rotateCyc::) or oscillate (link::#-rotateOsc::).
194-
195-
196110
SUBSECTION::View options
197111

198112
METHOD:: pointColors
@@ -276,7 +190,6 @@ link::Classes/SequenceableCollection#-clipExtend#-clipExtend:: is used to ensure
276190
code::normArray.size == this.numPoints::. Setting code::normArray:: to
277191
code::nil:: resets the points to the default uniform size.
278192

279-
280193
METHOD:: highlightPoints
281194
Provide emphasis on specific points in the view through color.
282195

@@ -300,6 +213,92 @@ METHOD:: units
300213
Set the units, code::'radians':: or code::'degrees'::, used by the GUI.
301214

302215

216+
SUBSECTION::Movement: rotation
217+
218+
METHOD:: rotate
219+
METHOD:: tilt
220+
METHOD:: tumble
221+
The rotation of the displayed points, on each axis, in radians. Default positive directions
222+
are:
223+
list::
224+
##strong::rotate::: counter-clockwise
225+
##strong::tilt::: left-up
226+
##strong::tumble::: front-up
227+
::
228+
229+
METHOD:: rotateDir
230+
METHOD:: tiltDir
231+
METHOD:: tumbleDir
232+
METHOD:: allDir
233+
A flag to specify the direction of rotation on each or all axes. A
234+
code::dir:: of code::1:: will select the default direction for that axis (see
235+
above) while code::-1:: will invert the direction of rotation.
236+
237+
METHOD:: reset
238+
Reset rotations to defaults. (code::rotate = -45.degrad, tilt = 0, tumble = 0::)
239+
240+
METHOD:: rotateMode
241+
Set the order of rotations when applying compound rotations to the points.
242+
code::'rtt':: for Rotate-Tilt-Tumble, code::'ypr':: Yaw-Pitch-Roll.
243+
244+
245+
SUBSECTION::Movement: animation
246+
247+
METHOD:: rotateOsc
248+
METHOD:: tiltOsc
249+
METHOD:: tumbleOsc
250+
METHOD:: allOsc
251+
A link::Classes/Boolean:: flag stating whether the display (including axes) will
252+
oscillate around each axis or all axes.
253+
254+
METHOD:: rotateOscPeriod
255+
METHOD:: tiltOscPeriod
256+
METHOD:: tumbleOscPeriod
257+
METHOD:: allOscPeriod
258+
The period of oscillation on each axis or all axes, in seconds.
259+
260+
METHOD:: rotateOscWidth
261+
METHOD:: tiltOscWidth
262+
METHOD:: tumbleOscWidth
263+
METHOD:: allOscWidth
264+
Set the oscillation width of each axis or all axes, in radians.
265+
266+
METHOD:: rotateCyc
267+
METHOD:: tiltCyc
268+
METHOD:: tumbleCyc
269+
METHOD:: allCyc
270+
A link::Classes/Boolean:: flag stating whether the display (including axes) will
271+
rotate cyclically around each axis or all axes.
272+
273+
METHOD:: rotateCycPeriod
274+
METHOD:: tiltCycPeriod
275+
METHOD:: tumbleCyclePeriod
276+
METHOD:: allCycPeriod
277+
The cycle period of each axis or all axes, in seconds.
278+
279+
METHOD:: rotateCycRate
280+
METHOD:: tiltCycRate
281+
METHOD:: tumbleCycRate
282+
METHOD:: allCycRate
283+
The cycle period of each axis or all axes, in Hertz.
284+
285+
METHOD:: varyMotion
286+
Set an code::axis:: (code::'rotate'::, code::'tilt'::, or code::'tumble'::)
287+
with a link::Classes/Boolean:: flag to randomize its motion, if it's
288+
oscillating or cycling.
289+
290+
METHOD:: randomVariance
291+
Set the random variance applied to those axes for which link::#-varyMotion::
292+
is code::true::. The value of variance is normalized to the phase increment of
293+
each frame, so a variance of code::0:: has no effect, while a variance of
294+
code::1:: could potentially step twice as far (twice as fast) on each frame.
295+
Default is code::0.15::.
296+
297+
METHOD:: frameRate
298+
Set the framerate of the animation if the view is set to cycle
299+
(link::#-rotateCyc::) or oscillate (link::#-rotateOsc::).
300+
301+
303302
SUBSECTION::Perspective
304303

305304
METHOD:: setOrtho
@@ -368,6 +367,40 @@ Return the link::Classes/Array:: of link::Classes/Cartesian:: points used
368367
internally for plotting. i.e. normalized to a radius of 1.
369368

370369

370+
SUBSECTION:: Other
371+
372+
METHOD:: export
373+
Export the view to an image file.
374+
375+
ARGUMENT:: fileName
376+
A link::Classes/String:: that is the name of the file, including the extension.
377+
The extension isn't necessary, but you'll then need to specify the
378+
strong::format:: and the file will be written without an extension.
379+
380+
ARGUMENT:: directory
381+
A link::Classes/String:: that is the directory into which the file will be
382+
written. Default is the user home directory, code::Platform.userHomeDir::.
383+
384+
ARGUMENT:: format
385+
An optional link::Classes/String:: of the format to use.
386+
code::Image.formats:: lists supported formats.
387+
If code::nil::, the format will be inferred from the path extension (the
388+
default).
389+
390+
ARGUMENT:: quality
391+
The quality factor in the range code::0::, small compressed files, to
392+
code::100::, large uncompressed files, or code::-1::, the default settings.
393+
Default is code::-1::.
394+
395+
ARGUMENT:: hideControls
396+
A link::Classes/Boolean:: specifying whether the controls should be hidden when
397+
exporting the image, so only the visualization is written to file.
398+
399+
ARGUMENT:: finishCond
400+
An optional link::Classes/Condition:: which will be set code::true:: and signal
401+
when the image has been written.
402+
403+
371404
EXAMPLES::
372405

373406
code::

PointView.quark

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
author: "Michael McCrea",
55
copyright: "Ambisonic Toolkit Community, Joseph Anderson, Michael McCrea 2018",
66
license: "GPL",
7-
version: "0.2.0",
7+
version: "0.3.0",
88
schelp: "PointView",
99
url: "https://github.com/ambisonictoolkit/PointView",
1010
dependencies: [

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Known issues are logged at
3838
Change log
3939
==========
4040

41+
0.3.0
42+
- add export view to an image, optionally with or without controls shown.
43+
4144
0.2.0
4245
- add ability to specify stroke width and color for each connection.
4346
- depth-first drawing of connections and axes to enchance 3D effect.

0 commit comments

Comments
 (0)