[73298b]: / contrib / gel / jvid / jvx_manager.cxx  Maximize  Restore  History

Download this file

173 lines (154 with data), 4.8 kB

  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
//:
// \file
#include <vcl_vector.h>
#include <vcl_iostream.h>
#include <vcl_fstream.h>
#include <vul/vul_timer.h>
#include <vil/vil_image.h>
#include <vgui/vgui.h>
#include <vgui/vgui_error_dialog.h>
#include <vgui/vgui_adaptor.h>
#include <vgui/vgui_tableau.h>
#include <vgui/vgui_dialog.h>
#include <vgui/vgui_macro.h>
#include <vgui/vgui_easy2D.h>
#include <vgui/vgui_viewer2D.h>
#include <vgui/vgui_grid_tableau.h>
#include <vgui/vgui_image_tableau.h>
#include <vidl/vidl_io.h>
#include <vidl/vidl_frame.h>
#include <jvid/jvx_manager.h>
//-----------------------------------------------------------
// constructors/destructor
//
jvx_manager::jvx_manager()
{
width_ = 512;
height_ = 512;
my_movie_=(vidl_movie*)0;
}
jvx_manager::~jvx_manager()
{
}
//: make an event handler
// note that we have to get an adaptor and set the tableau to receive events
bool jvx_manager::handle(const vgui_event &e)
{
//example for joe to show event mastery : button up==false, button down==true
vgui_event_condition g0(vgui_LEFT, vgui_CTRL, false);
if (g0(e))
vcl_cout << "saw an left/cntl up event\n";
// just pass it back to the base class
return vgui_grid_tableau::handle(e);
}
//-----------------------------------------------------------------------------
//: Loads a video file, e.g. avi into the viewer
//-----------------------------------------------------------------------------
void jvx_manager::load_video_file()
{
vgui_dialog load_image_dl("Load video file");
static vcl_string image_filename = "c:/mundy/Vace/GeoffVideos/faces.avi";
static vcl_string ext = "*.avi";
load_image_dl.file("Filename:", ext, image_filename);
if (!load_image_dl.ask())
return;
#ifdef HAS_MPEG2
//need to define callbacks
vidl_io::load_mpegcodec_callback = &jvid_load_mpegcodec_callback;
#endif
my_movie_ = vidl_io::load_movie(image_filename.c_str());
if (!my_movie_) {
vgui_error_dialog("Failed to load movie file");
return;
}
tabs_.clear();
vidl_movie::frame_iterator pframe(my_movie_);
pframe = my_movie_->first();
vil_image img = pframe->get_image();
height_ = img.height();
width_ = img.width();
vcl_cout << "Video Height " << height_ << vcl_endl
<< " Video Width " << width_ << vcl_endl;
int i = 0;
int inc = 40;
while (pframe!=my_movie_->last())
{
//Get the image from the video and wrap it with a viewer2D tableau
vgui_easy2D_new easy2D(vgui_image_tableau_new(pframe->get_image()));
vgui_viewer2D_sptr t = vgui_viewer2D_new(easy2D);
//put it in the viewer stack
tabs_.push_back(t);
//reduce the display resolution
t->zoomin(0.5f, 0, 0); // zoom out by factor 2 around pixel (0,0)
t->center_image(width_,height_);
//Display some dots on the video that move
//This code demonstrates how to overlay dynamic stuff on the video
//It wouldn't be in this loop in the real case.
easy2D->set_foreground(0,1,1);
easy2D->set_point_radius(5);
if (inc>60)
inc = 40;
for (unsigned int j = 0; j<=height_; j+=inc)
for (unsigned int k=0; k<=width_; k+=inc)
easy2D->add_point(k,j);
++pframe;//next video frame
vcl_cout << "Loading Frame[" << i << "]:(" <<width_ <<" "<<height_ << ")\n";
++inc;
++i;
}
//Display the first frame
unsigned row=0, col=0;
this->add_at(tabs_[0], col, row);
this->post_redraw();
vgui::run_till_idle();
}
//-----------------------------------------------------------------------------
//: Return the underlying vgui_viewer2D from the tableau at the given position.
// This function returns NULL if it fails.
//-----------------------------------------------------------------------------
vgui_viewer2D_sptr jvx_manager::get_vgui_viewer2D_at(unsigned col, unsigned row)
{
vgui_tableau_sptr top_tab = this->get_tableau_at(col, row);
if (top_tab)
{
vgui_viewer2D_sptr tab;
tab.vertical_cast(top_tab);
return tab;
}
else
{
vgui_macro_warning << "Unable to get tableau at (" << col <<", "<<row<<")\n";
return NULL;
}
}
void jvx_manager::play_video()
{
vul_timer t;
for (vcl_vector<vgui_viewer2D_sptr>::iterator vit = tabs_.begin();
vit != tabs_.end(); vit++)
{
//Remove the previous frame at grid position (0,0)
unsigned row=0, col=0;
this->remove_at(col, row);
//Add the previous frame
this->add_at(*vit, col, row);
//Here we can put some stuff to control the frame rate. Hard coded to
//a delay of 10
while (t.all()<10.0) ;
//force the new frame to be displayed
this->post_redraw();
vgui::run_till_idle();
t.mark();
}
}
//Here are other functions to be coded
void jvx_manager::stop_video()
{}
void jvx_manager::go_to_frame()
{}
void jvx_manager::next_frame()
{}
void jvx_manager::prev_frame()
{}
void jvx_manager::set_speed()
{}