Commit f1a866a4 authored by Jonathan Lambrechts's avatar Jonathan Lambrechts

scontactplog : progress bar

parent 4edbd33d
......@@ -9,6 +9,17 @@
#include <GL/gl.h>
#include <FL/gl.h>
#include <FL/Fl_Toggle_Button.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Value_Input.H>
#include <FL/Fl_Value_Slider.H>
#include <FL/Fl_Output.H>
#include <sys/stat.h>
class ScontactPlotWindow;
Fl_Valuator *stepinput;
ScontactPlotWindow *wingl;
std::vector<int> visible_flag(10, 3);
bool clip = false;
......@@ -195,6 +206,7 @@ class ObjectCollection {
}
void display() {
static size_t count = 0;
glEnable(GL_COLOR_MATERIAL);
if (dim == 3) {
glEnable(GL_LIGHTING);
......@@ -276,7 +288,6 @@ FILE* ffmpeg = NULL;
ObjectCollection collection;
int paused = 1;
int istep = 1;
int step = 1;
double alpha = 0, beta = 0, scale = 1, shift[2] = {0, 0};
......@@ -341,7 +352,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 's' :{
if (sscanf(arg, "%d", &step) != 1)
return ARGP_ERR_UNKNOWN;
istep = step;
//istep = step;
}
break;
case 'l' :{
......@@ -349,7 +360,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
}
break;
case 'i' :{
if (sscanf(arg, "%d", &istep) != 1)
//if (sscanf(arg, "%d", &istep) != 1)
return ARGP_ERR_UNKNOWN;
}
case ARGP_KEY_ARG :
......@@ -372,8 +383,8 @@ static struct argp argp = {options, parse_opt, args_doc, doc};
class ScontactPlotWindow : public Fl_Gl_Window {
public:
void draw() {
if (istep != collection.step())
collection.read(fbasename, istep);
static int count = 0;
printf("draw %i\n", count++);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
......@@ -414,10 +425,6 @@ class ScontactPlotWindow : public Fl_Gl_Window {
if (Fl::event_key(FL_Up)) {act = true; shift[1] -= 0.1;}
if (Fl::event_key(FL_Down)) {act = true; shift[1] += 0.1;}
}
else if (Fl::event_state(FL_ALT)) {
if (Fl::event_key(FL_Right)) {act = true; istep += step;}
if (Fl::event_key(FL_Left)) {act = true; istep = std::max(step, istep -step);}
}
else {
if (Fl::event_key(FL_Right)) {act = true; alpha += 1;}
if (Fl::event_key(FL_Left)) {act = true; alpha -=1;}
......@@ -425,7 +432,7 @@ class ScontactPlotWindow : public Fl_Gl_Window {
if (Fl::event_key(FL_Down)) {act = true; beta +=1;}
if (Fl::event_key(FL_Page_Up)) {act = true; scale /= 1.1;}
if (Fl::event_key(FL_Page_Down)) {act = true; scale *= 1.1;}
if (Fl::event_key('r')) {act = true; istep = 0;}
//if (Fl::event_key('r')) {act = true; istep = 0;}
if (Fl::event_key('c')) {act = true; clip = !clip;}
if (Fl::event_key('s')) {act = true; save_opt("scontact.opt");}
if (Fl::event_key(' ')) {act = true; paused = !paused;}
......@@ -444,36 +451,112 @@ class ScontactPlotWindow : public Fl_Gl_Window {
}
return Fl_Gl_Window::handle(event);
}
static void Timer_CB(void *data) {
if (! paused && collection.step() == istep) {
istep += step;
}
if (collection.read(fbasename, istep)) {
((ScontactPlotWindow*)(data))->redraw();
}
Fl::repeat_timeout(1./24, Timer_CB, data);
}
ScontactPlotWindow(int X, int Y, int W, int H, const char *L=0) : Fl_Gl_Window(X, Y, W, H, L){
Fl::add_timeout(1.0/24.0, Timer_CB, (void*)this);
mode(FL_ALPHA|FL_DOUBLE|FL_DEPTH|FL_MULTISAMPLE);
end();
};
};
void play_btn_cb(Fl_Widget *widget, void *skip) {
Fl_Button &btn = *(Fl_Button*)widget;
paused = !btn.value();
btn.label(paused ? "@UpArrow" : "@DnArrow");
}
void step_counter_cb(Fl_Widget *widget, void *sw) {
step = (int)((Fl_Valuator*)widget)->value();
}
void istep_counter_cb(Fl_Widget *widget, void *sw) {
int istep = (int)((Fl_Valuator*)widget)->value();
if (istep != collection.step())
collection.read(fbasename, istep);
((ScontactPlotWindow*)sw)->redraw();
}
bool iexists(int i) {
std::ostringstream oss;
struct stat buffer;
oss << fbasename << "/part-" <<std::setw(5)<<std::setfill('0')<< (++i);
return (stat (oss.str().c_str(), &buffer) == 0);
}
static void Timer_CB(void *data) {
Fl_Valuator * vals = (Fl_Valuator*) data;
int istep = (int)((Fl_Valuator*)data)->value();
if (! paused && iexists(istep + step) && istep == collection.step()) {
vals->value(istep + step);
vals->do_callback();
}
Fl::repeat_timeout(1./12, Timer_CB, data);
}
static void timer_update_bound_cb(void *data) {
Fl_Valuator &vals = *(Fl_Valuator*)data;
int i = vals.maximum();
if (!iexists(i))
i = 1;
for (; iexists(i+1); i++);
if (i != (int)vals.maximum()) {
vals.maximum(i);
vals.redraw();
}
Fl::repeat_timeout(1, timer_update_bound_cb, data);
}
int main(int argc, char **argv) {
scale = -1;
argp_parse(&argp, argc, argv, 0, 0, 0);
istep = step;
collection.read(fbasename, istep);
collection.read(fbasename, step);
float bbox[6];
collection.compute_bbox(bbox);
if (scale == -1)
scale = std::max(bbox[1] - bbox[0], std::max(bbox[3] - bbox[2], bbox[5] - bbox[4]))/2;
Fl_Window win(1000, 1000, "scontactplot");
ScontactPlotWindow wingl(0, 0, win.w(), win.h());
Fl_Window win(1000, 1000, fbasename.c_str());
int BH = 20, BW = 20;
double S = 0;
wingl = new ScontactPlotWindow(0, 0, win.w(), win.h()-BH);
wingl->end();
Fl_Button *btn;
Fl_Valuator *val;
Fl_Valuator *vals = new Fl_Slider(S * BW + 2, win.h() - BH + 2, 4 * BW - 2, BH - 4);
S += 4;
vals->minimum(1);
vals->maximum(1);
vals->step(1);
vals->type(FL_HOR_SLIDER);
vals->box(FL_THIN_DOWN_BOX);
vals->callback(istep_counter_cb, wingl);
vals->value(step);
stepinput = vals;
Fl::add_timeout(0., timer_update_bound_cb, (void*)vals);
Fl::add_timeout(1./12, Timer_CB, (void*)vals);
btn = new Fl_Toggle_Button((S++) * BW, win.h() - BH, BW, BH, "@UpArrow");
btn->box(FL_NO_BOX);
btn->callback(play_btn_cb);
btn->value(!paused);
S++;
val = new Fl_Value_Input(S * BW, win.h() - BH, 1.5 * BW, BH);
val->minimum(1);
val->value(1);
val->maximum(100);
val->step(1);
val->box(FL_FLAT_BOX);
val->color(FL_BACKGROUND_COLOR);
S += 1.5;
val->callback(step_counter_cb, wingl);
val->label("+");
Fl_Widget *resize = new Fl_Group(S * BW, 0, win.w() - S * BW, win.h() - BH);
resize->hide();
Fl::focus(wingl);
win.resizable(resize);
win.end();
win.resizable(wingl);
win.show();
Fl::run();
if(ffmpeg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment