/******************************************************************************************
 * 
 * Monterey Bay Aquarium Research Institute
 * Francois Boudet summer intern 2007    
 * 07/24/2007
 *  
 * 
 * 
 * ******************************************************************************************/

#include "Raster/Raster.H"
#include "SIFT/Keypoint.H"
#include "MbariVisualObject.H"
#include "MbariVisualObjectDB.H"
#include "Image/DrawOps.H"
#include <time.h>
#include <iostream>
#include <fstream>

/*! Load a database, enrich it with new VisualObject entities
  extracted from the given images, and save it back. */
int main(const int argc, const char **argv)
{

  time_t start,end;
  double dif;
  
  time (&start);
	
  MYLOGVERB = LOG_INFO;

  // check command-line args:
  if (argc < 3 )
    LFATAL("USAGE: BuilDataBase <dbname.vdb> <classe> <file> ");


  std::ifstream inf(argv[3]);
  if (inf.is_open() == false)
  {
	LERROR("Cannot open '%s' -- USING EMPTY", argv[3]);
  } else {



	  // load the database:
  	MbariVisualObjectDB vdb; 
  	if (!vdb.loadFrom(argv[1]))  
  		vdb.setName(argv[1]);

	std::string ImName;
	std::getline(inf, ImName);
	while(ImName!="")
	{
		vdb.addOneImage(argv[2], ImName);
		std::getline(inf, ImName);
	}
   	   		
  	vdb.saveTo(argv[1]);
  
  	time (&end);
  	dif = difftime (end,start);
  	printf ("It took  %.2lf seconds to build the dataBase.\n", dif );
}
 
  		
  return 0;
}


