/******************************************************************************************
> [KAZOE]                                                                                 <
> Initial Sofware by [Yannick Verdie, Florent Lafarge], Copyright (C) Inria (GEOMETRICA)  <
> All Rights Reserved, 2012, [Version 1.0].                                               <
******************************************************************************************/
#include <iostream>
using namespace std;


#include "Simulation_GPU.h"


void Flamengo( char* folder, char* name, bool writeonOriginal = true)
{
	cout << "MPP & RJMCMC (flamingo)" << endl;

	stringstream ss;
	ss<<folder<<"/"<<name<<".bmp";

	CImg<int> inputImage (ss.str().c_str());

	ss.str("");
	ParameterFile *parameters;	  		
	GPU_Stat* stat;

	{
		printf("----------- RJMCMC GPU------------\n");
		ss<<folder<<"/stat_Simulation_GPU_"<<name<<".txt";
		stat = new GPU_Stat(ss.str().c_str());ss.str("");

		ss<<folder<<"/ParametersConvergence_Simulation_GPU_"<<name<<".ini";
		parameters = new ParameterFile( ss.str().c_str());ss.str("");
		
		Simulation_GPU* recuit_GPU = new Simulation_GPU(inputImage,*parameters);
		recuit_GPU->setStat(stat);
		recuit_GPU->init(METHOD_DATATERM::BHATTACHARYA);


		recuit_GPU->startTimer();
		recuit_GPU->geometricalDecrease(parameters->Verbose, false);
		float time = recuit_GPU->getToTalTime();
		recuit_GPU->waitUntilDone();


		cout << endl << "- Executions Results : " << endl;    
		cout << "  Number of Shapes found : " << recuit_GPU -> getNbShapes() << endl;

		cout<< "Time : "<< time/1000. <<" s" <<endl; 
		printf("Energy: %f\n",recuit_GPU->getToTalEnergy());

		ss<<"Results_GPU_RJMCMC_"<<name<<".bmp";

		if (parameters->NameFiletoDraw.compare("") == 0)
			recuit_GPU -> save (ss.str().c_str());
		else
			recuit_GPU -> save (ss.str().c_str(),const_cast<char*>(parameters->NameFiletoDraw.c_str()));
		ss.str("");
		delete recuit_GPU;
		delete parameters;
		delete stat;

		system("pause");
	}

}



int main(int argc, char** argv)
{	
	if (argc < 3) {printf("not enough arg\n");return 1;	 }

	Flamengo(argv[1],argv[2]);//Fushimi_Data/sample_big_cropped sample_big_cropped

	return 0;
}	
