/** 
* @file LFGenericLocal.cpp
* @brief generic local features
* @author Erik Rodner
* @date 02/05/2008

*/
#include <iostream>
#include <sstream>

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

#include "vislearning/features/localfeatures/LocalFeatureSift.h"
#include "vislearning/features/localfeatures/IDRandomSampling.h"

using namespace OBJREC;

using namespace std;
using namespace NICE;


///////////////////// ///////////////////// /////////////////////
//                   CONSTRUCTORS / DESTRUCTORS
///////////////////// ///////////////////// /////////////////

LFGenericLocal::LFGenericLocal()
{
    this->lf = NULL;
    this->id = NULL;
}

LFGenericLocal::LFGenericLocal( const Config *conf, int numFeatures )
{
    lf = new LocalFeatureSift(conf);
    id = new IDRandomSampling(conf, numFeatures);
}

LFGenericLocal::~LFGenericLocal()
{
  if ( this->lf != NULL )
  {
    delete this->lf;
    this->lf = NULL;
  }

  if ( this->id != NULL )
  {
    delete this->id;
    this->id = NULL;
  }
}

///////////////////// ///////////////////// /////////////////////
//                      FEATURE STUFF
///////////////////// ///////////////////// ////////////////// 

int LFGenericLocal::getDescSize () const
{
    return lf->getDescSize();
}

int LFGenericLocal::extractFeatures ( const NICE::Image & img, 
				    VVector & features, 
				    VVector & positions ) const
{
    id->getInterests ( img, positions );
    lf->getDescriptors ( img, positions, features );
    return 0;
}

void LFGenericLocal::visualizeFeatures ( NICE::Image & mark,
				 const VVector & positions,
				 size_t color ) const
{
    lf->visualizeFeatures ( mark, positions, color );
}

///////////////////// INTERFACE PERSISTENT /////////////////////
// interface specific methods for store and restore
///////////////////// INTERFACE PERSISTENT ///////////////////// 

void LFGenericLocal::restore ( std::istream & is, int format )
{ 
  fthrow ( Exception, "LFGenericLocal::restore not implemented yet." );
  //TODO
}

void LFGenericLocal::store ( std::ostream & os, int format ) const
{ 
  fthrow ( Exception, "LFGenericLocal::store not implemented yet." );
  //TODO  
}

void LFGenericLocal::clear ()
{ 
  if ( this->lf != NULL )
  {
    delete this->lf;
    this->lf = NULL;
  }

  if ( this->id != NULL )
  {
    delete this->id;
    this->id = NULL;
  }
}

