contrib/oxl/mvl/RawPMatrixStore.cxx
Go to the documentation of this file.
00001 // This is oxl/mvl/RawPMatrixStore.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author
00008 // Author: Andrew W. Fitzgibbon, Oxford RRG
00009 // Created: 22 Aug 97
00010 // Modifications:
00011 //   970822 AWF Initial version.
00012 //
00013 //-----------------------------------------------------------------------------
00014 
00015 #include "RawPMatrixStore.h"
00016 #include <vcl_fstream.h>
00017 #include <vcl_string.h>
00018 #include <mvl/PMatrix.h>
00019 
00020 #include <mvl/FileNameGenerator.h>
00021 
00022 // Operations----------------------------------------------------------------
00023 
00024 bool RawPMatrixStore::Load(int image_index)
00025 {
00026   if (!check_index(image_index))
00027     return false;
00028 
00029   vcl_string filename = fng_.frame_name(image_index);
00030 
00031   vcl_ifstream fin(filename.c_str());
00032 
00033   if (!fin.good())
00034     {
00035       vcl_cerr << "Read PMatrix [" << filename << "] failed\n";
00036       return false;
00037     }
00038 
00039   pmatrix_[image_index]= new PMatrix;
00040   pmatrix_[image_index]->read_ascii(fin);
00041 
00042   vcl_cerr << "Read PMatrix [" << filename << "]\n";
00043 
00044   return true;
00045 }
00046 
00047 // - Save not implemented
00048 bool RawPMatrixStore::Save(int)
00049 {
00050   vcl_cerr << "RawPMatrixStore::Save not implemented\n";
00051   return false;
00052 }
00053 
00054 //: Return Image for frame $i$, loading if necessary.
00055 PMatrix_sptr RawPMatrixStore::Get(int i)
00056 {
00057   if (i< 0)
00058     return 0;
00059 
00060   if (!check_index(i))
00061     return 0;
00062 
00063   if (!pmatrix_[i])
00064     Load(i);
00065 
00066   return pmatrix_[i];
00067 }
00068 
00069 
00070 bool RawPMatrixStore::check_index(int i)
00071 {
00072   if (i < 0)
00073     return false;
00074 
00075   if ((unsigned int)i >= pmatrix_.size())
00076     pmatrix_.resize(i + 10);
00077 
00078   return true;
00079 }