2
Copyright (c) 2013 Daniel Stahlke
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
11
The above copyright notice and this permission notice shall be included in
12
all copies or substantial portions of the Software.
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
// This must be included before gnuplot-iostream.h in order to support plotting blitz arrays.
26
#include <blitz/array.h>
28
#include "gnuplot-iostream.h"
30
// Yes, I'm including a *.cc file. It contains main().
31
#include "examples-framework.cc"
33
void demo_blitz_basic() {
34
// -persist option makes the window not disappear when your program exits
35
Gnuplot gp("gnuplot -persist");
37
blitz::Array<double, 2> arr(100, 100);
41
arr = (i-50) * (j-50);
43
gp << "set pm3d map; set palette" << std::endl;
44
gp << "splot '-'" << std::endl;
48
void demo_blitz_waves_binary() {
49
Gnuplot gp("gnuplot -persist");
51
// example from Blitz manual:
52
int N = 64, cycles = 3;
53
double midpoint = (N-1)/2.;
54
double omega = 2.0 * M_PI * cycles / double(N);
55
double tau = - 10.0 / N;
56
blitz::Array<double, 2> F(N, N);
59
F = cos(omega * sqrt(pow2(i-midpoint) + pow2(j-midpoint)))
60
* exp(tau * sqrt(pow2(i-midpoint) + pow2(j-midpoint)));
62
gp << "splot '-' binary" << gp.binfmt(F) << "dx=10 dy=10 origin=(5,5,0) with pm3d notitle" << std::endl;
66
void demo_blitz_sierpinski_binary() {
67
Gnuplot gp("gnuplot -persist");
70
blitz::Array<blitz::TinyVector<uint8_t, 4>, 2> F(N, N);
71
for(int i=0; i<N; i++)
72
for(int j=0; j<N; j++) {
76
F(i, j)[3] = (i&j) ? 0 : 255;
79
gp << "plot '-' binary" << gp.binfmt(F) << "with rgbalpha notitle" << std::endl;
83
void demo_blitz_waves_binary_file() {
84
Gnuplot gp("gnuplot -persist");
86
// example from Blitz manual:
87
int N = 64, cycles = 3;
88
double midpoint = (N-1)/2.;
89
double omega = 2.0 * M_PI * cycles / double(N);
90
double tau = - 10.0 / N;
91
blitz::Array<double, 2> F(N, N);
94
F = cos(omega * sqrt(pow2(i-midpoint) + pow2(j-midpoint)))
95
* exp(tau * sqrt(pow2(i-midpoint) + pow2(j-midpoint)));
97
gp << "splot" << gp.binaryFile(F) << "dx=10 dy=10 origin=(5,5,0) with pm3d notitle" << std::endl;
100
void demo_blitz_sierpinski_binary_file() {
101
Gnuplot gp("gnuplot -persist");
104
blitz::Array<blitz::TinyVector<uint8_t, 4>, 2> F(N, N);
105
for(int i=0; i<N; i++)
106
for(int j=0; j<N; j++) {
110
F(i, j)[3] = (i&j) ? 0 : 255;
113
gp << "plot" << gp.binaryFile(F) << "with rgbalpha notitle" << std::endl;
116
void register_demos() {
117
register_demo("basic", demo_blitz_basic);
118
register_demo("waves_binary", demo_blitz_waves_binary);
119
register_demo("sierpinski_binary", demo_blitz_sierpinski_binary);
120
register_demo("waves_binary_file", demo_blitz_waves_binary_file);
121
register_demo("sierpinski_binary_file", demo_blitz_sierpinski_binary_file);