The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MPKeyFrame.cpp

Go to the documentation of this file.
00001 /*
00002  *  MPKeyFrame.cpp
00003  *  
00004  *
00005  *  Created by Josh Susskind 2003.
00006  *  Copyright (c) 2003 Machine Perception Laboratory
00007  *  University of California San Diego.
00008  *  Please read the disclaimer and notes about redistribution
00009  *  at the end of this file.
00010  *
00011  *  Authors: Josh Susskind
00012  */
00013 #include "MPKeyFrame.h"
00014 #include <vector>
00015 #include <fstream>
00016 
00017 using namespace std;
00018 
00019 vector<MPKeyFrame> m_Collection;
00020 
00021 /* ================================================================ */
00022 
00023 // MPKeyFrameCollection::MPKeyFrameCollection() {
00024 //      my_memory = false;
00025 // }
00026 
00027 /* ================================================================ */
00028 
00029 // MPKeyFrameCollection::~MPKeyFrameCollection()
00030 //      if (my_memory) {
00031 //              for (vector<MPKeyFrame>::iterator it = m_Collection.begin(); it != m_Collection.end(); it++) {
00032 //                      MPKeyFrame &kf = *it;
00033 //                      delete kf;
00034 //      }
00035 // }
00036 
00037 /* ================================================================ */
00038 
00039 void MPKeyFrameCollection::add_to_collection(MPKeyFrame &frame) {
00040         m_Collection.push_back(frame);
00041 }
00042 
00043 /* ================================================================ */
00044 
00045 //void MPKeyFrameCollection::add_to_collection(const long &framenum, const int &x, const int &y, const int &w, const int &h) {
00046 //      m_Collection.push_back(MPKeyFrame(framenum, x, y, w, h));
00047 //}
00048 
00049 /* ================================================================ */
00050         
00051 void MPKeyFrameCollection::get_keyframe(MPKeyFrame &frame, int &n) {
00052         MPKeyFrame &f = m_Collection[n];
00053         frame.framenum = f.framenum;
00054         frame.x = f.x;
00055         frame.y = f.y;
00056         frame.w = f.w;
00057         frame.h = f.h;
00058 }
00059 
00060 /* ================================================================ */
00061         
00062 void MPKeyFrameCollection::get_keyframe(long &framenum, int &x, int &y, int &w, int &h, int &n) {
00063         MPKeyFrame &f = m_Collection[n];
00064         framenum =f.framenum;
00065         x = f.x;
00066         y = f.y;
00067         w = f.w;
00068         h = f.h;
00069 }
00070 
00071 /* ================================================================ */
00072 
00073 bool MPKeyFrameCollection::empty() {
00074         return(m_Collection.empty());
00075 }
00076 
00077 /* ================================================================ */
00078 
00079 int MPKeyFrameCollection::size() {
00080         return(m_Collection.size());
00081 }
00082 
00083 /* ================================================================ */
00084 
00085 void MPKeyFrameCollection::read_frames_from_file(char *filename) {
00086         ifstream is(filename);
00087         while (!is.eof()) {
00088                 int framenum = 0, x = 0, y = 0, w = 0, h = 0;
00089                 is >> framenum >> x >> y >> w >> h;
00090                 if (framenum + x + y + w + h == 0) break;
00091                 MPKeyFrame *kf = new MPKeyFrame(framenum, x, y, w, h);
00092                 MPKeyFrame &kfr = *kf;
00093                 add_to_collection(kfr);
00094                 //my_memory = true;
00095         }
00096         is.close();
00097 }
00098 
00099 /* ================================================================ */
00100 
00101 void MPKeyFrameCollection::write_frames_to_file(char *filename) {
00102         ofstream os(filename);
00103         for (vector<MPKeyFrame>::iterator it = m_Collection.begin(); it != m_Collection.end(); it++) {
00104                 MPKeyFrame &kf = *it;
00105                 os << kf.framenum << "\t";
00106                 os << kf.x << "\t";
00107                 os << kf.y << "\t";
00108                 os << kf.w << "\t";
00109                 os << kf.h << endl;
00110         }
00111         os.close();
00112 }
00113 
00114 /* ================================================================ */
00115 
00116 /*
00117  * 
00118  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00119  * 
00120  *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00121  *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00122  *    3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
00123  * 
00124  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00125  * 
00126  */

Generated on Mon Nov 8 17:07:46 2004 for MPT by  doxygen 1.3.9.1