dcv.plot.figure

Module implements on-screen image plotting utilities.

DCV offers simple interface to show an image on screen:

1 Image image = imread("image.png");
2 
3 // Simply, show the image
4 image.imshow();
5 
6 // Optionally, show the image on the figure with given title:
7 image.imshow("Some Image");
8 
9 // ... or do some processing, then show it in-line
10 image
11     .sliced
12     .as!float
13     .slice
14     .conv!symmetric(gaussian!float(1.0f, 3, 3))
15     .imshow;
16 
17 // ... or instantiate new figure to setup some useful callbacks, than use the
18 // Figure interface to draw on it's canvas, and show it:
19 
20 auto f = figure("Figure title");  // create the figure with given title
21 
22 // set the mouse move callback
23 f.setCursorCallback( (Figure figure, double x, double y)
24 {
25     writeln("Mouse moved to: ", [x, y]);
26 })
27 
28 // set the mouse button click callback
29 f.setMouseCallback( (Figure figure, int button, int scancode, int mods)
30 {
31     writeln("Mouse clicked: ", [button, scancode, mods]);
32 });
33 
34 f.draw(image); // draw an image to the figure's canvas.
35 f.show(); // show the figure on screen.
36 
37 // Once figure's image buffer is drawn out (say you have an image, and few plots drawn on it),
38 // it can be extracted from the figure, and used in rest of the code:
39 Image plotImage = figure(title).image;
40 plotImage.imwrite("my_plot.png");
41 
42 // And at the end, you can run the event loop for each previously set up figure, to wait
43 // for key input, or given time to pass.
44 waitKey!"seconds"(10);

Figure mechanism is integrated with ggplotd library, so GGPlotD context can be directly plotted onto existing figure. To use GGPlotD library integration with DCV (dcv.plot.figure.plot), define ggplotd subConfiguration of dcv in dub configuration file:

1 "dependencies": {
2     "dcv": "~>0.1.2"
3 },
4 "subConfigurations":{
5     "dcv": "ggplotd"
6 }

This configuration is actually in dcv:plot subpackage, so if you define dcv:plot as dependency, you should define your subConfigurations as:

1 "dependencies": {
2     "dcv:plot": "~>0.1.2"
3 },
4 "subConfigurations":{
5     "dcv:plot": "ggplotd"
6 }

Members

Aliases

CharCallback
alias CharCallback = void delegate(uint key)

Character callback function.

KeyPressCallback
alias KeyPressCallback = void delegate(int key, int scancode, int action, int mods)

Key press callback function.

Classes

ContextNotInitialized
class ContextNotInitialized

Exception thrown if drawing context hasn't been properly initialized.

Figure
class Figure

Plotting figure type.

Functions

figure
Figure figure(string title = "")

Create a plotting figure.

imdestroy
void imdestroy(string title = "")

Destroy figure.

imshow
Figure imshow(Image image, string title = "")
Figure imshow(Slice!(kind, packs, Iterator) slice, string title = "")
Figure imshow(Slice!(kind, packs, Iterator) slice, ImageFormat format, string title = "")

Show an image to screen.

plot
Figure plot(Image image, GGPlotD gg, string title = "")
Figure plot(Slice!(kind, packs, Iterator) slice, GGPlotD gg, string title = "")
Figure plot(Slice!(kind, packs, Iterator) slice, ImageFormat format, GGPlotD gg, string title = "")

Show given image, and then plot given GGPlotD context on top of it.

plot
Figure plot(GGPlotD gg, string title = "")

Plot GGPlotD context onto figure with given title.

setCharCallback
void setCharCallback(CharCallback clbck)

Assign character input callback function.

setKeyPressCallback
void setKeyPressCallback(KeyPressCallback clbck)

Assign key press callback function.

waitKey
int waitKey(ulong count = 0)

Run the event loop for each present figure, and wait for key and/or given time.

Examples

1 immutable title = "Image With Point Plot";
2 // show the image
3 image.imshow(title);
4 // construct the plot
5 auto gg = GGPlotD().put(geomPoint(Aes!(double[], "x", double[], "y")([100.00, 200.0], [200.0,100.0])));
6 // draw it onto the figure with given title...
7 gg.plot(title);
Module contains:
imshow plot waitKey imdestroy Figure

Meta

Authors

Relja Ljubobratovic

License

$(LINK3 http://www.boost.org/LICENSE_1_0.txt, Boost Software License - Version 1.0).