core/vidl_vil1/vidl_vil1_clip.cxx

Go to the documentation of this file.
00001 //:
00002 // \file
00003 
00004 #include "vidl_vil1_clip.h"
00005 
00006 #include <vcl_iostream.h>
00007 
00008 #include <vidl_vil1/vidl_vil1_codec_sptr.h>
00009 #include <vidl_vil1/vidl_vil1_image_list_codec.h>
00010 #include <vidl_vil1/vidl_vil1_frame.h>
00011 
00012 //=========================================================================
00013 //  Methods for vidl_vil1_clip.
00014 //_________________________________________________________________________
00015 
00016 //------------------------------------------------------------------------
00017 // CONSTRUCTOR(S) AND DESTRUCTOR
00018 
00019 //: Constructor. Takes a vidl_vil1_codec, start, end and increment frames are optional.
00020 vidl_vil1_clip::vidl_vil1_clip(
00021         vidl_vil1_codec_sptr codec,
00022         int start,
00023         int end,
00024         int increment) : frames_(codec->length()), coder_(codec)
00025 {
00026   for (unsigned int i=0; i<frames_.size(); i++)
00027     frames_[i] = new vidl_vil1_frame(i, codec);
00028 
00029   init(start, end, increment);
00030 }
00031 
00032 //: Constructor. Create a clip from a vector of images. Start, end and increment frames are optional.
00033 vidl_vil1_clip::vidl_vil1_clip(vcl_vector<vil1_image> &images,
00034                                int start,
00035                                int end,
00036                                int increment)
00037 {
00038   int position = 0; // Could not cast the iterator i into (int)
00039                     // but that would be better
00040   vidl_vil1_image_list_codec_sptr codec = new vidl_vil1_image_list_codec(images);
00041 
00042   for (vcl_vector<vil1_image>::iterator i=images.begin(); i!= images.end(); ++i)
00043   {
00044     vidl_vil1_frame_sptr f = new vidl_vil1_frame(position, codec.ptr());
00045     frames_.push_back(f);
00046     position++;
00047   }
00048 
00049   coder_ = codec.ptr();
00050 
00051   init(start, end, increment);
00052 }
00053 
00054 //: Constructor. Create a clip from a list of images. Start, end and increment frames are optional.
00055 vidl_vil1_clip::vidl_vil1_clip(vcl_list<vil1_image> &images,
00056                                int start,
00057                                int end,
00058                                int increment)
00059 {
00060   int position = 0; // Could not cast the iterator i into (int)
00061                     // but that would be better
00062   vidl_vil1_image_list_codec_sptr codec = new vidl_vil1_image_list_codec(images);
00063 
00064   for (vcl_list<vil1_image>::iterator i=images.begin(); i!= images.end(); ++i)
00065   {
00066     vidl_vil1_frame_sptr f = new vidl_vil1_frame(position, codec.ptr());
00067     frames_.push_back(f);
00068     position++;
00069   }
00070 
00071   coder_ = codec.ptr();
00072 
00073   init(start, end, increment);
00074 }
00075 
00076 //: Initialization of the clip. Protected.
00077 void vidl_vil1_clip::init(int start, int end, int increment)
00078 {
00079   // Initialize startframe_, endframe_ and increment_ in the vidl_vil1_clip
00080   //
00081   // Some sanity checks first
00082   //
00083 
00084   // Get the actual length
00085   int len = coder_->length();
00086 
00087   // Check start
00088   if (start < 0) start = 0;
00089   if (start >= len) start = len-1;
00090 
00091   // Check end
00092   if (end == 0)    end = len-1;   // Default
00093   if (end < start) end = start;
00094   if (end >= len)  end = len-1;
00095 
00096   // Check increment
00097   if (increment < 1) increment = 1;
00098 
00099   // Make end equal to start + some multiple of increment
00100   end = start + (((end-start)/increment)*increment);
00101 
00102   // Now, set the fields of vidl_vil1_clip
00103   increment_  = increment;
00104   startframe_ = start;
00105   endframe_   = end;
00106 }
00107 
00108 
00109 //: Get the frame numbered n inside the range defined by startframe, endframe and increment.
00110 // So, the returned frame is startframe_+n*increment_
00111 vidl_vil1_frame_sptr vidl_vil1_clip::get_frame(int n)
00112 {
00113   // Check that the asked frame is in the clip
00114   if (n>=length() || n < 0)
00115   {
00116     vcl_cerr << "vidl_vil1_clip::get_frame Frame number " << n << " does not exist.\n";
00117     return 0;
00118   }
00119 
00120   // return the frame
00121   return frames_[startframe_+n*increment_];
00122 }
00123 
00124 //: Return the horizontal size of the frames in the clip
00125 int vidl_vil1_clip::width() const
00126 {
00127   return coder_->width();
00128 }
00129 
00130 //: Return the vertical size of the frames in the clip
00131 int vidl_vil1_clip::height() const
00132 {
00133   return coder_->height();
00134 }

Generated on Tue Dec 2 05:09:13 2008 for core/vidl_vil1 by  doxygen 1.5.1