#ifndef _NOMAGICK_
#include <Magick++.h>
#endif

#include <iostream>
#include <string>
#include <math.h>
#include "imagealign.h"
#include "image2d.h"
#include <fftw3.h> 
#include <tclap/CmdLine.h>
#include "bdbenv.h"
#include "dbimage.h"
#include "dbalnimage.h"

int main( int argc, char *argv[] )
{
  try
    {
      ///set up the command line parsing
      TCLAP::CmdLine cmd("Image alignment program", ' ', "0.001");

      TCLAP::ValueArg<std::string> dbdir("d", "db", "database dirctory", true, "", "databaase");
      cmd.add(dbdir);

      cmd.parse(argc, argv);

      bdbenv bdb;
      dbimage imstore;
      dbalnimage imaln;
      bdb.open( dbdir.getValue() );
      imstore.init( bdb.envptr() );
      imaln.init( bdb.envptr() );
      bdb.adddb( &imstore );
      bdb.adddb( &imaln );


      std::vector< int > ids;
      std::vector< int > x, y;
      std::vector< int > ans;
      for( int i = 0; i < 10; i++ )
        {
          ids.push_back( i );
          x.push_back( i + i );
          y.push_back( i * i );
        }
      for( int i = 0; i < 10; i++ )
        {
          ans.push_back( imaln.create_align( 0, ids, x, y ) );
          imaln.create_align( 1, ids, x, y );
          imaln.create_align( 2, ids, x, y );
          imaln.create_align( 3, ids, x, y );
        }
      imaln.get_align_sets( 0, ids );
      for( unsigned i = 0; i < ids.size(); i++ )
        std::cout << ids[i] << " ";
      std::cout << "\n";
      for( unsigned i = 0; i < ans.size(); i++ )
        std::cout << ans[i] << " ";
      std::cout << "\n";
      imaln.close();
      imstore.close();
      bdb.close();
    }
  catch (TCLAP::ArgException &e)
    {
      std::cout << "ERROR: " << e.error() 
                << " for arg " << e.argId() << "\n";
      return 0;
    }
  return 0;
}
