/*
    C++ Mesh Generation Library
    Copyright (c) 2000echet <eric at bechet dot ca>

    This file is part of the C++ Mesh Generation Library.

    See the NOTICE & LICENSE files for conditions.
*/
#include <cmath>
#include <iostream>


#include "gmshNode.h"
#include "gmshElement.h"
#include "FastMarching.h"
#include "SpeedFunctor.h"
#include "ExportFunctor.h"
#include "SPoint3.h"
#include <cstring>
#include "GModel.h"
#include "GmshGlobal.h"
#include "SPointToDouble.h"
#include "FMField.h"

using namespace std;


bool Get_Options ( int narg, char  * arg[], char  * NameProblem=0, double *lc=0 )
{
  if (NameProblem)
  {
    strcpy ( NameProblem, "" ) ;

    if ( narg>1 )
    {
      strcpy ( NameProblem, arg[1] ) ;
    }
    else 
    {
      return false;
    }
  }
  if (( narg>2 ) && (lc))
    *lc=atof(arg[2]);
  else
    *lc=1.0;
  return true ;
}

int main ( int argc, char *argv[] )
{
  char pname[256];
  Get_Options ( argc,argv,pname );
  GmshInitialize(argc, argv);
  FM::FMModel *Model=new FM::FMModel();
  std::cout << Model->readMSH(pname);
  Model->buildAdj(1<<(Model->getDim()-1));// highest dimension only
  
  FMSpeedConstant sp;
  FastMarch_c fastM ( sp );

  map<FM::gmshNode,FastMarch_c::FieldPair> initvals;
  set<FM::gmshElement> bndinit;

  Init ( Model, SPlane (SPoint3( -0.05, 0.00, 0. ), SVector3 ( 1.,0.,0. ) ), SPlane ( SPoint3 ( -0.05, 0.00, 0 ), SVector3( 0.,1.,0. ) ),initvals,bndinit );


  fastM.Init ( initvals,bndinit );
  ExportMSH ef ( Model );
  fastM.SetExportFunctor ( ef );
  fastM.Export ( "ls" );

  fastM.Propagate ( 1.0 );
  fastM.Export ( "ls2" );
}

 
  //  Init(data.mesh, xCylinder(Trellis_Util::mPoint(-0.05, 0.00, 0), xfem::xVector(0.,0.,1.), .07), xPlane(Trellis_Util::mPoint(-0.05, 0.00, 0), xfem::xVector(0.,1.,0.)),initvals,bndinit);
//  Init ( data.mesh, xPlane ( Trellis_Util::mPoint ( -0.05, 0.00, 0 ), xfem::xVector ( 1.,0.,0. ) ), xPlane ( Trellis_Util::mPoint ( -0.05, 0.00, 0 ), xfem::xVector ( 0.,1.,0. ) ),initvals,bndinit );
 
