#include <iostream>
#include "core/basics/Config.h"
#include "vislearning/features/gradientfeatures/PHOGFeature.h"
#include <unistd.h>

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

int main(int argc, char **argv)
{	
	Config *conf;
	std::string imgfilename ("/progs/square_black.jpg");
	if(argc < 1)
	{
		std::cerr << "No config file given, use default config and ./progs/square_black.jpg instaed" << std::endl;
		conf = new Config();
		
		char path_c[512];
		getcwd(path_c, 512);

		if (path_c == NULL)
		{ 
			std::cerr << "default image is not readable. Aborting." << std::endl; 
			return -1 ;
		}
		std::string path(path_c);
		imgfilename = path + imgfilename;
	}
	else
	{
		conf = new Config( argc, argv );

		imgfilename = conf->gS("main", "imgfilename", "");
		if (imgfilename.compare("") == 0)
		{
			std::cerr << "No input image given. Aborting!" << std::endl;
			return -1;
		}
	}

	PHOGFeature PHOG(conf);
	
	PHOG.sayYourName();
	
	std::cerr << "Concatenating NONE histograms resulting in \\sum_{i=0}{level} 4^i histograms." << std::endl;
	PHOG.set_histrogram_concatenation(OBJREC::PHOGFeature::NONE);
	std::vector<std::vector<float> > resulting_feature = PHOG.createOneFeatureVector(imgfilename);
	for (std::vector<std::vector<float> >::const_iterator i = resulting_feature.begin(); i != resulting_feature.end(); i++)
	{
		for (std::vector<float>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
		{
			std::cerr << *j << " ";
		}
		std::cerr << std::endl << std::endl;
	}
	
	std::cerr << "Concatenating histograms LEVELWISE resulting in #level histograms." << std::endl;
	PHOG.set_histrogram_concatenation(OBJREC::PHOGFeature::LEVELWISE);
	resulting_feature = PHOG.createOneFeatureVector(imgfilename);
	for (std::vector<std::vector<float> >::const_iterator i = resulting_feature.begin(); i != resulting_feature.end(); i++)
	{
		for (std::vector<float>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
		{
			std::cerr << *j << " ";
		}
		std::cerr << std::endl << std::endl;
	}
	
	std::cerr << "Concatenating ALL histograms resulting in 1 final histogram." << std::endl;
	PHOG.set_histrogram_concatenation(OBJREC::PHOGFeature::ALL);
	resulting_feature = PHOG.createOneFeatureVector(imgfilename);
	for (std::vector<std::vector<float> >::const_iterator i = resulting_feature.begin(); i != resulting_feature.end(); i++)
	{
		for (std::vector<float>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
		{
			std::cerr << *j << " ";
		}
		std::cerr << std::endl << std::endl;
	}

	return 0;
}
