#include "vislearning/features/localfeatures/LFCache.h"

#include <iostream>
#include <fstream>

#include "vislearning/baselib/Globals.h"
#include "core/basics/StringTools.h"
#include "core/basics/FileMgt.h"
#include "core/vector/VVector.h"

namespace OBJREC {

template <class ImageClass>
int LFCache::getDescriptorsTemplate ( const ImageClass & img, NICE::VVector & positions,	NICE::VVector & descriptors ) const
{	std::string filename = Globals::getCacheFilename( cachedir, cachemode );
	std::string filename_desc = filename + ".desc";
	std::string filename_pos = filename + ".key";
	
	std::ifstream fdesc( filename_desc.c_str());
	std::ifstream fpos( filename_pos.c_str());
	
	if(fdesc.fail() || fpos.fail())
	{
		//berechne und schreibe
		lf->getDescriptors(img, positions, descriptors);
		descriptors.save ( filename_desc, descFormat );
		positions.save ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
	}
	else
	{
		descriptors.setBufSize(lf->getDescSize());
		descriptors.read ( filename_desc, descFormat );
		positions.read ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
	}

    return 1;
}

}
