summaryrefslogtreecommitdiff
path: root/src/gipfel.cxx
blob: 2b28f1e435916ef690ee5ef7f142e5718c9c3f9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// 
// "$Id: gipfel.cxx,v 1.16 2005/05/05 11:02:07 hofmann Exp $"
//
// flpsed program.
//
// Copyright 2004 by Johannes Hofmann
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_File_Chooser.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Int_Input.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Menu_Item.H>

#include "GipfelWidget.H"

char *img_file;
char *data_file;
GipfelWidget *gipf;

void open_cb() {
  char *file = fl_file_chooser("Open File?", "*.jpeg", img_file);
  if(file != NULL) {

  }  
}

void scale_cb(Fl_Slider* o, void*) {
  if (gipf) {
    gipf->set_scale((double)(o->value()));
  }
}

void angle_cb(Fl_Slider* o, void*) {
  if (gipf) {
    gipf->set_center_angle((double)(o->value()));
  }
}

void nick_cb(Fl_Slider* o, void*) {
  if (gipf) {
    gipf->set_nick_angle((double)(o->value()));
  }
}

void tilt_cb(Fl_Slider* o, void*) {
  if (gipf) {
    gipf->set_tilt_angle((double)(o->value()));
  }
}

void h_d_cb(Fl_Slider* o, void*) {
  if (gipf) {
    gipf->set_height_dist_ratio((double)(o->value()));
  }
}

void comp_cb(Fl_Widget *, void *) {
  if (gipf) {
    gipf->comp_params();
  }
}

void guess_cb(Fl_Widget *, void *) {
  if (gipf) {
    gipf->guess();
  }
}

void about_cb() {
  fl_message("flpsed -- a pseudo PostScript editor\n"
	     "(c) Johannes Hofmann 2004, 2005\n\n"
	     "PostScript is a registered trademark of Adobe Systems");
}

Fl_Menu_Item menuitems[] = {
  { "&File",              0, 0, 0, FL_SUBMENU },
    { "&Open File...",    FL_CTRL + 'o', (Fl_Callback *)open_cb },
  {0},
  { 0 }
};
  

void usage() {
  fprintf(stderr,
	  "usage: flpsed [-hbd] [-t <tag>=<value>] [<infile>] [<outfile>]\n"
	  "   -h                 print this message\n"
	  "   -b                 batch mode (no gui)\n"
	  "   -d                 dump tags and values from a document\n"
	  "                      to stdout (this implies -b)\n"
	  "   -t <tag>=<value>   set text to <value> where tag is <tag>\n"
	  "   <infile>           optional input file; in batch mode if no\n"
	  "                      input file is given, input is read from stdin\n"
	  "   <outfile>          optional output file for batch mode; if no\n"
	  "                      output file is given, output is written to stdout\n");
}


int main(int argc, char** argv) {
  char c, *sep, *tmp, **my_argv;
  char *view_point = NULL;
  int err, bflag = 0, dflag = 0, my_argc;
  Fl_Window *win;
  Fl_Scroll *scroll;
  Fl_Menu_Bar *m;
  
  err = 0;
  while ((c = getopt(argc, argv, "d:v:")) != EOF) {
    switch (c) {  
    case 'h':
      usage();
      exit(0);
      break;
    case 'd':
      data_file = optarg;
      break;
    case 'v':
      view_point = optarg;
      break;
    default:
      err++;
    }
  }
  
  if (err) {
    usage();
    exit(1);
  }

  my_argc = argc - optind;
  my_argv = argv + optind;

  if (my_argc >= 1) {
    img_file = my_argv[0];
  }

  win = new Fl_Window(800,700);
  m = new Fl_Menu_Bar(0, 0, 800, 30);
  m->menu(menuitems);
  Fl_Slider* a = new Fl_Slider(50, 30, 750, 15, "angle");
  a->type(1);
  a->box(FL_THIN_DOWN_BOX);
  a->labelsize(10);
  a->step(0.00001);
  a->bounds(-3.14, 3.14);
  a->slider(FL_UP_BOX);
  a->callback((Fl_Callback*)angle_cb);
  a->align(FL_ALIGN_LEFT);
  Fl_Slider* s = new Fl_Slider(100, 45, 160, 15, "scale");
  s->type(1);
  s->box(FL_THIN_DOWN_BOX);
  s->labelsize(10);
  s->step(5.0);
  s->bounds(0.0, 10000.0);
  s->slider(FL_UP_BOX);
  s->callback((Fl_Callback*)scale_cb);
  s->align(FL_ALIGN_LEFT);
  Fl_Slider* n = new Fl_Slider(360, 45, 160, 15, "nick");
  n->type(1);
  n->box(FL_THIN_DOWN_BOX);
  n->labelsize(10);
  n->step(0.00001);
  n->bounds(-0.5, 0.5);
  n->slider(FL_UP_BOX);
  n->callback((Fl_Callback*)nick_cb);
  n->align(FL_ALIGN_LEFT);
  Fl_Slider* r = new Fl_Slider(620, 45, 160, 15, "height-dist");
  r->type(1);
  r->box(FL_THIN_DOWN_BOX);
  r->labelsize(10);
  r->step(-0.005);
  r->bounds(0.2, 0.01);
  r->slider(FL_UP_BOX);
  r->callback((Fl_Callback*)h_d_cb);
  r->align(FL_ALIGN_LEFT);
  Fl_Slider* t = new Fl_Slider(50, 60, 160, 15, "tilt");
  t->type(1);
  t->box(FL_THIN_DOWN_BOX);
  t->labelsize(10);
  t->step(0.005);
  t->bounds(-0.1, 0.1);
  t->slider(FL_UP_BOX);
  t->callback((Fl_Callback*)tilt_cb);
  t->align(FL_ALIGN_LEFT);
  Fl_Button *b = new Fl_Button(200, 60, 20, 15, "comp");
  b->callback(comp_cb);
  Fl_Button *b1 = new Fl_Button(250, 60, 20, 15, "guess");
  b1->callback(guess_cb);

  scroll = new Fl_Scroll(0, 75, win->w(), win->h()-75);
  
  gipf = new GipfelWidget(0,75,500,500);

  gipf->load_image(img_file);
  gipf->load_data(data_file);
  if (view_point) {
    gipf->set_viewpoint(view_point);
  }
  scroll->end();  
    
  win->resizable(scroll);
  
  win->end();
  win->show(1, argv); 
  
  return Fl::run();
}