/******************************************************************************************
 * 
 * Monterey Bay Aquarium Research Institute
 * Francois Boudet summer intern 2007    
 * 07/24/2007
 *  
 * This main add one or several images to an existing database
 * 
 * ******************************************************************************************/

#include "Raster/Raster.H"
#include "SIFT/Keypoint.H"
#include "MbariVisualObject.H"
#include "MbariVisualObjectDB.H"
#include "Image/DrawOps.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.addOneImageDB(argv[2], ImName);
		std::getline(inf, ImName);
	}
  }
   	   		
  time (&end);
  dif = difftime (end,start);
  printf ("It took  %.2lf seconds to add %i the dataBase.\n", dif, argc-3 );
  return 0;
}


