gui.cpp 5.33 KB
Newer Older
1 2 3
#include <iostream>
#include <vector>

plgruener's avatar
plgruener committed
4 5 6
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_PNG_Image.H>
7 8
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Window.H>
plgruener's avatar
plgruener committed
9

10 11 12 13 14 15
#include <FL/Fl_Button.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Value_Input.H>

#include "compute.hpp"

16
class SimpleWindow : public Fl_Window {
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 public:
  SimpleWindow(int w, int h, const char* title);
  ~SimpleWindow();

  Fl_Scroll* scroll;
  Fl_Box* imagebox;

  Fl_Group* group;

  Fl_PNG_Image* image;

  Fl_Button* button_compute;

  Fl_Value_Input* in_num_iterations;
  Fl_Value_Input* in_threshold;
  Fl_Value_Input* in_alphamin;
  Fl_Value_Input* in_alphamax;
  Fl_Value_Input* in_alpha_num_intervals;
  Fl_Value_Input* in_betamin;
  Fl_Value_Input* in_betamax;
  Fl_Value_Input* in_beta_num_intervals;
  Fl_Value_Input* in_num_seedpoints;
  Fl_Value_Input* in_special_seedpoint;
  Fl_Check_Button* in_output_csv;

 private:
  static void callback_compute(Fl_Widget*, void*);
  inline void callback_compute_il();
45 46 47
};

int main() {
48
  SimpleWindow win(600, 500, "Dynamic Systems");
49
  return Fl::run();
50 51
}

52
// Constructor
53 54
SimpleWindow::SimpleWindow(int w, int h, const char* title)
    : Fl_Window(w, h, title) {
55
  // between begin...end comes what to show in window
56 57
  this->begin();  // this-> is implicit

58
  // Top: scrolling box containing the picture
59 60
  image = new Fl_PNG_Image("picture.png");

61 62
  int scrollheight = 400;
  int scrollwidth = 600;
63
  scroll = new Fl_Scroll(0, 0, 600, 400);
64

65
  scroll->begin();
66
  imagebox = new Fl_Box(0, 0, image->w(), image->h());
67
  imagebox->image(image);
68 69 70 71
  scroll->end();

  // Bottom: inputboxes and button

72
  int boxwidth = 80;   // width input boxes
73
  int boxheight = 20;  // height input boxes
74 75
  int firstrow = scrollheight + 1 * boxheight;
  int secondrow = firstrow + 2 * boxheight;
76 77
  int padding = 100;

78
  group = new Fl_Group(0, scrollheight, 6 * padding, 100);
79
  group->begin();
80 81
  in_alphamin = new Fl_Value_Input(0 * padding, firstrow, boxwidth, boxheight,
                                   "alpha_min");
82
  in_alphamin->align(FL_ALIGN_TOP);
83
  in_alphamin->value(0.0);
84

85 86
  in_alphamax = new Fl_Value_Input(1 * padding, firstrow, boxwidth, boxheight,
                                   "alpha_max");
87
  in_alphamax->align(FL_ALIGN_TOP);
88
  in_alphamax->value(1.0);
89

90 91
  in_alpha_num_intervals =
      new Fl_Value_Input(2 * padding, firstrow, boxwidth, boxheight, "width");
92
  in_alpha_num_intervals->align(FL_ALIGN_TOP);
93
  in_alpha_num_intervals->value(400);
plgruener's avatar
plgruener committed
94
  in_alpha_num_intervals->step(1);
95

96 97
  in_num_iterations = new Fl_Value_Input(3 * padding, firstrow, boxwidth,
                                         boxheight, "iterations");
98 99
  in_num_iterations->align(FL_ALIGN_TOP);
  in_num_iterations->value(100);
plgruener's avatar
plgruener committed
100
  in_num_iterations->step(1);
101

102 103
  in_threshold = new Fl_Value_Input(4 * padding, firstrow, boxwidth, boxheight,
                                    "threshold");
104 105 106
  in_threshold->align(FL_ALIGN_TOP);
  in_threshold->value(1);

107 108
  button_compute =
      new Fl_Button(5 * padding, firstrow, boxwidth, boxheight, "compute");
109 110
  button_compute->type(FL_NORMAL_BUTTON);
  button_compute->color(FL_RED);
111
  button_compute->callback(callback_compute, this);
112

113 114
  in_betamin = new Fl_Value_Input(0 * padding, secondrow, boxwidth, boxheight,
                                  "beta_min");
115
  in_betamin->align(FL_ALIGN_TOP);
116
  in_betamin->value(0.0);
117

118 119
  in_betamax = new Fl_Value_Input(1 * padding, secondrow, boxwidth, boxheight,
                                  "beta_max");
120
  in_betamax->align(FL_ALIGN_TOP);
121
  in_betamax->value(1.0);
122

123 124
  in_beta_num_intervals =
      new Fl_Value_Input(2 * padding, secondrow, boxwidth, boxheight, "height");
125
  in_beta_num_intervals->align(FL_ALIGN_TOP);
126
  in_beta_num_intervals->value(400);
plgruener's avatar
plgruener committed
127
  in_beta_num_intervals->step(1);
128

129 130
  in_num_seedpoints = new Fl_Value_Input(3 * padding, secondrow, boxwidth,
                                         boxheight, "# seedpoints");
131 132
  in_num_seedpoints->align(FL_ALIGN_TOP);
  in_num_seedpoints->value(8);
plgruener's avatar
plgruener committed
133
  in_num_seedpoints->step(1);
134

135 136
  in_special_seedpoint = new Fl_Value_Input(4 * padding, secondrow, boxwidth,
                                            boxheight, "special seed");
137 138
  in_special_seedpoint->align(FL_ALIGN_TOP);
  in_special_seedpoint->value(0);
139

140 141
  in_output_csv = new Fl_Check_Button(5 * padding, secondrow, boxwidth,
                                      boxheight, "csv output");
142

143 144
  group->end();

145
  this->end();
146
  this->resizable(scroll);
147 148 149 150 151 152 153 154
  this->show();
}

// Destructor
SimpleWindow::~SimpleWindow() {}

// Button callback, just cast object and call real function
void SimpleWindow::callback_compute(Fl_Widget* o, void* v) {
155
  ((SimpleWindow*)v)->callback_compute_il();
plgruener's avatar
plgruener committed
156
}
157 158 159 160 161

// no arguments needed, because has access to all class members
void SimpleWindow::callback_compute_il() {
  std::cout << "start computation..." << std::endl;

162 163
  std::vector<float> seedpoints;
  seedpoints.push_back(in_special_seedpoint->value());
164

165 166 167 168 169
  compute_all(in_num_iterations->value(), in_threshold->value(),
              in_alphamin->value(), in_alphamax->value(),
              in_alpha_num_intervals->value(), in_betamin->value(),
              in_betamax->value(), in_beta_num_intervals->value(),
              in_num_seedpoints->value(), in_output_csv->value(), seedpoints);
170 171

  image = new Fl_PNG_Image("picture.png");
172
  imagebox->image(image);
173
  imagebox->resize(0, 0, image->w(), image->h());
174
  redraw();
plgruener's avatar
plgruener committed
175
  std::cout << "finished computation." << std::endl;
176
}