core/vidl_vil1/vidl_vil1_movie.cxx

Go to the documentation of this file.
00001 //:
00002 // \file
00003 
00004 #include "vidl_vil1_movie.h"
00005 
00006 #include <vcl_iostream.h>
00007 
00008 #include <vidl_vil1/vidl_vil1_frame.h>
00009 #include <vidl_vil1/vidl_vil1_clip.h>
00010 
00011 //=========================================================================
00012 //  Methods for vidl_vil1_movie.
00013 //_________________________________________________________________________
00014 
00015 //------------------------------------------------------------------------
00016 // CONSTRUCTOR(S) AND DESTRUCTOR
00017 
00018 //: Constructor
00019 vidl_vil1_movie::vidl_vil1_movie()
00020   : frame_rate_ ( 30 ) {}
00021 
00022 //: Constructor, build a movie with the single given clip
00023 vidl_vil1_movie::vidl_vil1_movie(vidl_vil1_clip_sptr clip)
00024   : frame_rate_ ( 30 )
00025 {
00026   // Check validity of initialisation
00027   if (!clip_.empty())
00028     vcl_cerr << "Bad initialisation of the movie.\n";
00029 
00030   add_clip(clip);
00031 }
00032 
00033 //: destructor
00034 vidl_vil1_movie::~vidl_vil1_movie()
00035 {
00036 }
00037 
00038 //: Get the frame numbered n (frames are numbered from 0 to total-1)
00039 vidl_vil1_frame_sptr vidl_vil1_movie::get_frame(int n)
00040 {
00041   vidl_vil1_frame_sptr ret_frame = NULL;
00042 
00043   vcl_list<vidl_vil1_clip_sptr>::iterator i = clip_.begin();
00044 
00045   while ((i!=clip_.end()) && (!(ret_frame=(*i)->get_frame(n))))
00046   {
00047     n = n - (*i)->length();
00048     i++;
00049   }
00050 
00051   // one can note that if the frame was not in the clip (n too big),
00052   // Then, NULL is returned.
00053   return ret_frame;
00054 }
00055 
00056 vil1_image vidl_vil1_movie::get_image(int n)
00057 {
00058   return get_frame(n)->get_image();
00059 }
00060 
00061 //: Add a clip at the end of the movie
00062 void vidl_vil1_movie::add_clip(vidl_vil1_clip_sptr clip)
00063 {
00064   clip_.push_back(clip);
00065 }
00066 
00067 
00068 //: Give back the number of frames of the movie
00069 int vidl_vil1_movie::length() const
00070 {
00071   int number = 0;
00072   for (vcl_list<vidl_vil1_clip_sptr>::const_iterator i=clip_.begin(); i!= clip_.end(); ++i)
00073     number += (*i)->length();
00074 
00075   return number;
00076 }
00077 
00078 //: Return the horizontal size of the frames in the movie
00079 // Check that all the movies do have the same size, output
00080 // an error if not
00081 int vidl_vil1_movie::width() const
00082 {
00083   // Get the size X of the first clip
00084   vcl_list<vidl_vil1_clip_sptr>::const_iterator i=clip_.begin();
00085   int sizeX = (*i)->width();
00086 
00087   // Check that the (eventually) other clips have the same size
00088   for (; i!= clip_.end(); ++i)
00089     if ((*i)->width() != sizeX)
00090     {
00091       vcl_cerr << "SizeX of the movie asked. But the different clips have different sizes.\n";
00092       return 0;
00093     }
00094 
00095   // Return the size X
00096   return sizeX;
00097 }
00098 
00099 //: Return the vertical size of the frames in the movie
00100 // Check that all the movies do have the same size, output
00101 // an error if not
00102 int vidl_vil1_movie::height() const
00103 {
00104   // Get the size Y of the first clip
00105   vcl_list<vidl_vil1_clip_sptr>::const_iterator i = clip_.begin();
00106   int sizeY = (*i)->height();
00107 
00108   // Check that the (eventually) other clips have the same size
00109   for (; i!= clip_.end(); ++i)
00110     if ((*i)->height() != sizeY)
00111     {
00112       vcl_cerr << "SizeY of the movie asked. But the different clips have different sizes.\n";
00113       return 0;
00114     }
00115 
00116   // Return the size Y
00117   return sizeY;
00118 }

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