
#include "NDCodebookLevelImagePooling.h"

//STL
#include <iostream>

//core
#include <core/vector/VectorT.h>

using namespace std;
using namespace NICE;
using namespace OBJREC;

  //**********************************************
  //
  //                 PROTECTED METHODS
  //
  //********************************************** 



  //**********************************************
  //
  //                 PUBLIC METHODS
  //
  //********************************************** 


NDCodebookLevelImagePooling::NDCodebookLevelImagePooling ( const Config *_conf,
                               const MultiDataset *_md, const std::string & _section )
    : NoveltyDetectorCodebookLevel ( _conf, _md, _section )
{ 
  this->section = _section;
//   d_noveltyThreshold = conf->gD ( section , "noveltyThreshold", 0.0064 );  
  d_noveltyThreshold = conf->gD ( section , "stupidNoveltyThreshold", 0.0064 );  
}

NDCodebookLevelImagePooling::~NDCodebookLevelImagePooling()
{
}

bool NDCodebookLevelImagePooling::evaluateNoveltyOfImage ( const std::string & _filename )
{
  ROADWORKSNOVDET;
}

bool NDCodebookLevelImagePooling::evaluateNoveltyOfImage ( const NICE::FloatImage & _noveltyImage )
{
    double meanNovelty ( 0.0 );
    for ( uint y = 0 ; y < ( uint ) _noveltyImage.height() ; y++ )
    {
      for ( uint x = 0 ; x < ( uint ) _noveltyImage.width(); x++ )
      {
        meanNovelty += _noveltyImage(x,y);
      }
    }      
    int imageSize ( _noveltyImage.height() * _noveltyImage.width() );
    meanNovelty /= imageSize;

      std::cerr << "  NOVELTY SCORE FOR CURRENT IMAGE: " <<  meanNovelty << " -- threshold: " << d_noveltyThreshold << std::endl;    
    
    if ( meanNovelty < d_noveltyThreshold )
    {
      // --- NOT NOVEL ---
      return false;
    }
    else
    {
      // --- NOVEL ---
      return true;
    }
}
