int CPP_AllOptimTriplet_main(int argc,char ** argv)
{
   ElTimer aChrono;
   std::string aFullPat,aNameCalib;
   bool inParal=true;
   bool Quick = false;
   std::string aPrefHom="";
   bool Debug  = false;

   ElInitArgMain
   (
        argc,argv,
        LArgMain() << EAMC(aFullPat,"Pattern"),
        LArgMain() << EAM(aNameCalib,"OriCalib",true,"Orientation for calibration ", eSAM_IsExistDirOri)
                   << EAM(inParal,"Paral",true,"Execute in parallel ", eSAM_IsBool)
                   << EAM(Quick,"Quick",true,"Quick version", eSAM_IsBool)
                   << EAM(aPrefHom,"PrefHom",true,"Prefix Homologous points, def=\"\"")
                   << EAM(Debug,"Debug",true,"Debugging mode (tuning purpose)", eSAM_IsBool)
    );

   cElemAppliSetFile anEASF(aFullPat);
   const cInterfChantierNameManipulateur::tSet * aVIm = anEASF.SetIm();

   cSetName * aSetN= anEASF.mICNM->KeyOrPatSelector(aFullPat);
   std::set<std::string> aSetName(aVIm->begin(),aVIm->end());
   std::string aDir = anEASF.mDir;

   cNewO_NameManager * aNM =  new cNewO_NameManager(aPrefHom,Quick,aDir,aNameCalib,"dat");

   cSauvegardeNamedRel aLCpl =  StdGetFromPCP(aNM->NameCpleOfTopoTriplet(true),SauvegardeNamedRel);
   std::list<std::string> aLCom;
   int aNb= 0 ;
   int aNb2 = (int)aLCpl.Cple().size();
   for (std::vector<cCpleString>::const_iterator itC=aLCpl.Cple().begin() ; itC!=aLCpl.Cple().end() ; itC++)
   {
       aNb++;
       const std::string & aN1 = itC->N1();
       const std::string & aN2 = itC->N2();
       if (aSetN->SetBasicIsIn(aN1) && aSetN->SetBasicIsIn(aN2))
       {
            std::string aCom =   MM3dBinFile("TestLib NO_OneImOptTrip") 
                            + " " + aN1
                            + " " + aN2
                            + " " + cAppliOptimTriplet::KeyCple;
            if (EAMIsInit(&aNameCalib))
               aCom +=  " OriCalib=" + aNameCalib;

            aCom += " Quick=" + ToString(Quick);
            aCom += " PrefHom=" + aPrefHom;

            if (inParal)
            {
                aLCom.push_back(aCom);
                if ((aNb%40) == 0)
                {
                    cEl_GPAO::DoComInParal(aLCom);
                    aLCom.clear();
                    std::cout << "Optim triplets Done " << aNb << " pairs out of " << aNb2  << " in " << aChrono.uval() << "\n";
                }
            }
            else
            {
                std::cout << "COM " << aCom << "\n";
                System(aCom);
            }
       }
   }
   cEl_GPAO::DoComInParal(aLCom);

   return EXIT_SUCCESS;
}
int HomFilterMasq_main(int argc,char ** argv)
{
    // MemoArg(argc,argv);
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir,aPat,aFullDir;
    bool ExpTxt=false;
    std::string PostPlan="_Masq";
    std::string KeyCalcMasq;
    std::string KeyEquivNoMasq;
    std::string MasqGlob;
    double  aResol=10;
    bool AcceptNoMask;
    std::string aPostIn= "";
    std::string aPostOut= "MasqFiltered";
    std::string aOriMasq3D,aNameMasq3D;
    cMasqBin3D * aMasq3D = 0;

    Pt2dr  aSelecTer;


    ElInitArgMain
    (
        argc,argv,
        LArgMain()  << EAMC(aFullDir,"Full name (Dir+Pat)", eSAM_IsPatFile),
        LArgMain()
                    << EAM(PostPlan,"PostPlan",true,"Post to plan, Def : toto ->toto_Masq.tif like with SaisieMasq")
                    << EAM(MasqGlob,"GlobalMasq",true,"Global Masq to add to all image")
                    << EAM(KeyCalcMasq,"KeyCalculMasq",true,"For tuning masq per image")
                    << EAM(KeyEquivNoMasq,"KeyEquivNoMasq",true,"When given if KENM(i1)==KENM(i2), don't masq")
                    << EAM(aResol,"Resol",true,"Sub Resolution for masq storing, Def=10")
                    << EAM(AcceptNoMask,"ANM",true,"Accept no mask, def = true if MasqGlob and false else")
                    << EAM(ExpTxt,"ExpTxt",true,"Ascii format for in and out, def=false")
                    << EAM(aPostIn,"PostIn",true,"Post for Input dir Hom, Def=")
                    << EAM(aPostOut,"PostOut",true,"Post for Output dir Hom, Def=MasqFiltered")
                    << EAM(aOriMasq3D,"OriMasq3D",true,"Orientation for Masq 3D")
                    << EAM(aNameMasq3D,"Masq3D",true,"File of Masq3D, Def=AperiCloud_${OriMasq3D}.ply")
                    << EAM(aSelecTer,"SelecTer",true,"[Per,Prop] Period of tiling on ground selection, Prop=proporion of selected")
    );
    bool aHasOri3D =  EAMIsInit(&aOriMasq3D);
    bool HasTerSelec = EAMIsInit(&aSelecTer);


    #if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
     #endif
    SplitDirAndFile(aDir,aPat,aFullDir);
    if (EAMIsInit(&PostPlan))
    {
        CorrecNameMasq(aDir,aPat,PostPlan);
    }

    if (!EAMIsInit(&AcceptNoMask))
       AcceptNoMask = EAMIsInit(&MasqGlob) || aHasOri3D;


    cInterfChantierNameManipulateur * anICNM = cInterfChantierNameManipulateur::BasicAlloc(aDir);

    std::string aKeyOri;
    if (aHasOri3D)
    {
        anICNM->CorrecNameOrient(aOriMasq3D);
        if (! EAMIsInit(&aNameMasq3D))
        {
              aNameMasq3D = aDir + "AperiCloud_" + aOriMasq3D + "_polyg3d.xml";
        }
        if (ELISE_fp::exist_file(aDir+aNameMasq3D))
        {
            aMasq3D = cMasqBin3D::FromSaisieMasq3d(aDir+aNameMasq3D);
        }
        else
        {
            ELISE_ASSERT(EAMIsInit(&aSelecTer),"Unused OriMasq3D");
        }
        aKeyOri = "NKS-Assoc-Im2Orient@" + aOriMasq3D;
    }

    Im2D_Bits<1>  aImMasqGlob(1,1);
    if (EAMIsInit(&MasqGlob))
       aImMasqGlob = GetMasqSubResol(aDir+MasqGlob,aResol);


    const std::vector<std::string> *  aVN = anICNM->Get(aPat);
    std::vector<Im2D_Bits<1> >  aVMasq;

     std::vector<CamStenope *> aVCam;


    double aResolMoy = 0;

    for (int aKN = 0 ; aKN<int(aVN->size()) ; aKN++)
    {
        std::string aNameIm = (*aVN)[aKN];
        Tiff_Im aTF = Tiff_Im::StdConvGen(aNameIm,1,false);
        Pt2di aSzG = aTF.sz();
        Pt2di aSzR (round_ni(Pt2dr(aSzG)/aResol));
        Im2D_Bits<1> aImMasq(aSzR.x,aSzR.y,1);


        std::string aNameMasq = StdPrefix(aNameIm)+PostPlan + ".tif";
        if (EAMIsInit(&KeyCalcMasq))
        {
            aNameMasq = anICNM->Assoc1To1(KeyCalcMasq,aNameIm,true);
        }

        if (ELISE_fp::exist_file(aNameMasq))
        {
            Im2D_Bits<1> aImMasqLoc = GetMasqSubResol(aDir+aNameMasq,aResol);
            ELISE_COPY(aImMasq.all_pts(),aImMasq.in() && aImMasqLoc.in(0),aImMasq.out());
        }
        else
        {
             if (!AcceptNoMask)
             {
                 std::cout << "For Im " << aNameIm << " file " << aNameMasq << " does not exist\n";
                 ELISE_ASSERT(false,"Masq not found");
             }
        }

        if (EAMIsInit(&MasqGlob))
        {

            ELISE_COPY(aImMasq.all_pts(),aImMasq.in() && aImMasqGlob.in(0),aImMasq.out());
        }

        aVMasq.push_back(aImMasq);
        // Tiff_Im::CreateFromIm(aImMasq,"SousRes"+aNameMasq);
        if (aHasOri3D)
        {
            aVCam.push_back(anICNM->StdCamOfNames(aNameIm,aOriMasq3D));
            aResolMoy += aVCam.back()->GlobResol();
        }
    }
    if (aHasOri3D)
       aResolMoy /= aVCam.size();

    std::string anExt = ExpTxt ? "txt" : "dat";


    std::string aKHIn =   std::string("NKS-Assoc-CplIm2Hom@")
                       +  std::string(aPostIn)
                       +  std::string("@")
                       +  std::string(anExt);
    std::string aKHOut =   std::string("NKS-Assoc-CplIm2Hom@")
                        +  std::string(aPostOut)
                        +  std::string("@")
                       +  std::string(anExt);


    double aPeriodTer=0,aSeuilDistTer=0;
    if (HasTerSelec)
    {
       aPeriodTer = aSelecTer.x * aResolMoy;
       aSeuilDistTer = aPeriodTer * sqrt(aSelecTer.y);
    }

    double aNbInTer=0;
    double aNbTestTer=0;


    for (int aKN1 = 0 ; aKN1<int(aVN->size()) ; aKN1++)
    {
        for (int aKN2 = 0 ; aKN2<int(aVN->size()) ; aKN2++)
        {
             std::string aNameIm1 = (*aVN)[aKN1];
             std::string aNameIm2 = (*aVN)[aKN2];

             std::string aNameIn = aDir + anICNM->Assoc1To2(aKHIn,aNameIm1,aNameIm2,true);

             if (ELISE_fp::exist_file(aNameIn))
             {
                  bool UseMasq = true;
                  if (EAMIsInit(&KeyEquivNoMasq))
                  {
                       UseMasq =  (anICNM->Assoc1To1(KeyEquivNoMasq,aNameIm1,true) != anICNM->Assoc1To1(KeyEquivNoMasq,aNameIm2,true) );
                  }


                  TIm2DBits<1>  aMasq1 ( aVMasq[aKN1]);
                  TIm2DBits<1>  aMasq2 ( aVMasq[aKN2]);

                  ElPackHomologue aPackIn =  ElPackHomologue::FromFile(aNameIn);
                  ElPackHomologue aPackOut;
                  for (ElPackHomologue::const_iterator itP=aPackIn.begin(); itP!=aPackIn.end() ; itP++)
                  {
                      Pt2dr aP1 = itP->P1();
                      Pt2dr aP2 = itP->P2();
                      Pt2di aQ1 = round_ni(aP1/aResol);
                      Pt2di aQ2 = round_ni(aP2/aResol);

                      bool Ok = ((aMasq1.get(aQ1,0) && aMasq2.get(aQ2,0)) || (! UseMasq));

                      if (Ok &&  aHasOri3D)
                      {
                          Pt3dr  aPTer= aVCam[aKN1]->PseudoInter(aP1,*(aVCam[aKN2]),aP2);
                          if (aMasq3D && (! aMasq3D->IsInMasq(aPTer)))
                             Ok = false;

                          if (Ok && HasTerSelec)
                          {
                              bool OkTer =  (mod_real(aPTer.x,aPeriodTer) < aSeuilDistTer) && (mod_real(aPTer.y,aPeriodTer) < aSeuilDistTer);
                              Ok = OkTer;
                              aNbTestTer ++;
                              aNbInTer += OkTer;
                          }
                      }  

                      if (Ok)
                      {
                          ElCplePtsHomologues aCple(aP1,aP2);
                          aPackOut.Cple_Add(aCple);
                      }
                  }
                  std::string aNameOut = aDir + anICNM->Assoc1To2(aKHOut,aNameIm1,aNameIm2,true);
                  aPackOut.StdPutInFile(aNameOut);
                  std::cout << "IN " << aNameIn << " " << aNameOut  << " UseM " << UseMasq << "\n";
             }
        }
    }
    // std::vector<cImFMasq *> mVIm;

    if (HasTerSelec)
    {
        std::cout << "A Posteriori Prop=" << aNbInTer / aNbTestTer << "\n";
    }



   return EXIT_SUCCESS;
}
void cAppliOptimTriplet::Execute()
{
   ElTimer aChrono;
   if (! EAMIsInit(&mNbMaxSel))
   {
        mNbMaxSel = mQuick ? QuickDefNbMaxSel : StdDefNbMaxSel;
   }

   if (mShow) 
      mQuitExist = false;


   mNbMaxInit = mQuick ? QuickNbMaxInit   : StdNbMaxInit ;


   if (! EAMIsInit(&mShow))
       mShow  = EAMIsInit(&mSzShow);


   if (MMVisualMode) return;
   

   cNewO_OneIm * mNoIm3 = new cNewO_OneIm(*mNM,m3S.mV2);

   std::string aNameSauveXml = mNM->NameOriOptimTriplet(false,mNoIm1,mNoIm2,mNoIm3,false);
   std::string aNameSauveBin = mNM->NameOriOptimTriplet(true ,mNoIm1,mNoIm2,mNoIm3,false);

   if (ELISE_fp::exist_file(aNameSauveXml) && ELISE_fp::exist_file(aNameSauveBin) && mQuitExist)
      return ;

   std::string  aName3R = mNM->NameOriInitTriplet(true,mNoIm1,mNoIm2,mNoIm3);
   cXml_Ori3ImInit aXml3Ori = StdGetFromSI(aName3R,Xml_Ori3ImInit);

   mIms.push_back(new  cImOfTriplet(0,*this,mNoIm1,ElRotation3D::Id));
   mIms.push_back(new  cImOfTriplet(1,*this,mNoIm2,Xml2El(aXml3Ori.Ori2On1())));
   mIms.push_back(new  cImOfTriplet(2,*this,mNoIm3,Xml2El(aXml3Ori.Ori3On1())));

   mIm1 = mIms[0];
   mIm2 = mIms[1];
   mIm3 = mIms[2];
   mFoc =  1/ (  (1.0/mIm1->Foc()+1.0/mIm2->Foc()+1.0/mIm3->Foc()) / 3.0 ) ;


   // mP12 = new cPairOfTriplet(mIm1,mIm2,mIm3);
   // mP13 = new cPairOfTriplet(mIm1,mIm3,mIm2);
   // mP23 = new cPairOfTriplet(mIm2,mIm3,mIm1);
   mPairs.push_back(new cPairOfTriplet(mIm1,mIm2,mIm3));
   mPairs.push_back(new cPairOfTriplet(mIm1,mIm3,mIm2));
   mPairs.push_back(new cPairOfTriplet(mIm2,mIm3,mIm1));
   mP12 = mPairs[0];
   mP13 = mPairs[1];
   mP23 = mPairs[2];

   mNM->LoadTriplet(mIm1->Im(),mIm2->Im(),mIm3->Im(),&mIm1->VFullPtOf3(),&mIm2->VFullPtOf3(),&mIm3->VFullPtOf3());


   if (EAMIsInit(&mSzShow) && (!EAMIsInit(&mNbMaxSel)))
   {
      mNbMaxSel = ModeShowNbMaxSel;
   }

   if (mShow) 
      std::cout << "Time load " << aChrono.uval() << "\n";
   int aNb3 = round_up(CoutAttenueTetaMax(mIm2->VFullPtOf3().size() ,mNbMaxSel));
   

   mNbMaxSel = aNb3;

  //  mSel3 = IndPackReduit(mIm2->VFullPtOf3(),mNbMaxInit,mNbMaxSel);

   mSel3 = IndPackReduit(mIm2->VFullPtOf3(),mNbMaxInit,mNbMaxSel);

   for (int aK=0 ; aK<3 ; aK++)
   {
        mIms[aK]->SetReduce(mSel3);
        mFullH123.push_back(&(mIms[aK]->VFullPtOf3()));
        mRedH123.push_back(&(mIms[aK]->VRedPtOf3()));
   }

   mP12->SetPackRed(false,mNbMaxInit,mNbMaxSel,mSel3,*mFullH123[1]);
   mP23->SetPackRed(true ,mNbMaxInit,mNbMaxSel,mSel3,*mFullH123[1]);
   mP13->SetPackRed(true ,mNbMaxInit,mNbMaxSel,mSel3,*mFullH123[0]);
   mPds3 = ElMin(MaxSurPond3,(mP12->NbR()+mP13->NbR()+mP23->NbR())/double(mIm1->NbR()));


   mBestResidu =  ResiduGlob();
/*
   TestOPA(*mP12);
*/

   if (mShow) 
   {
      std::cout << "Time reduc " << aChrono.uval()   << "  Pds3=" << mPds3 << "\n";
   }

   for (int aKP=0 ; aKP<int(mPairs.size()) ; aKP++)
   {
       TestOPA(*(mPairs[aKP]));
   }

   if (mShow) 
   {
      std::cout << "Time opa " << aChrono.uval()   << "\n";
   }



   if (mShow)
   {
      std::cout << "NB TRIPLE " << mIm2->VFullPtOf3().size()  << " Resi3: " <<  ResiduTriplet() << " F " << mFoc << "\n";
      std::cout << "RESIDU/PAIRES " << mP12->ResiduMoy() << " " << mP13->ResiduMoy() << " " << mP23->ResiduMoy() << " " << "\n";
      std::cout << "R Glob " << ResiduGlob() << "\n";
   }

#if (ELISE_X11)

   if (EAMIsInit(&mSzShow))
   {
      mIm2->InitW(mSzShow);
      ShowPoints(mIm2,mP12->FullVP2(),P8COL::cyan,2);
      ShowPoints(mIm2,mP23->FullVP1(),P8COL::yellow,2);

      ShowPointSel(mIm2,mP12->VRedP2(),P8COL::cyan);
      ShowPointSel(mIm2,mP23->VRedP1(),P8COL::yellow);
      std::cout << "NB 12 " << mP12->VRedP2().size() << "\n";
      // ShowPoints(mIm2,mIm2->VFullPtOf3(),P8COL::blue,4);
      // ShowPointSel(mSel3.mVSel,mIm2,mIm2->VFullPtOf3(),P8COL::red);

      // 
      ShowPoints(mIm2,mIm2->VFullPtOf3(),P8COL::blue,2);
      ShowPointSel(mIm2,mIm2->VRedPtOf3(),P8COL::blue);


      //==================================
      mIm1->InitW(mSzShow);
      ShowPoints(mIm1,mP13->FullVP1(),P8COL::cyan,2);
      ShowPointSel(mIm1,mP13->VRedP1(),P8COL::cyan);

      ShowPoints(mIm1,mIm1->VFullPtOf3(),P8COL::blue,2);
      ShowPointSel(mIm1,mIm1->VRedPtOf3(),P8COL::blue);

      mIm2->W()->clik_in();
   }

#endif

/*
   SolveBundle3Image
   (
        mFoc,
        mIm2->Rot(),
        mIm3->Rot(),
        mFullH123,
        mP12->FullHoms(),
        mP13->FullHoms(),
        mP23->FullHoms()
   );
*/
   int aNbIterBundle = mQuick ? QuickNbIterBundle : StdNbIterBundle;
   double aBOnH;
   Pt3dr aPMed;
   SolveBundle3Image
   (
        mFoc,
        mIm2->Ori(),
        mIm3->Ori(),
        aPMed,
        aBOnH,
        mRedH123,
        mP12->RedHoms(),
        mP13->RedHoms(),
        mP23->RedHoms(),
        mPds3,
        aNbIterBundle
   );


   cXml_Ori3ImInit aXml;
   aXml.Ori2On1() = El2Xml(mIm2->Ori());
   aXml.Ori3On1() = El2Xml(mIm3->Ori());
   aXml.ResiduTriplet() = ResiduGlob();
   aXml.NbTriplet() = (int)mRedH123[0]->size();
   aXml.BSurH() = aBOnH;
   aXml.PMed() = aPMed;

   MakeFileXML(aXml,aNameSauveXml);
   MakeFileXML(aXml,aNameSauveBin);



   if (mShow)
   {
      std::cout << "NB TRIPLE " << mIm2->VFullPtOf3().size()  << " Resi3: " <<  ResiduTriplet() << " F " << mFoc << "\n";
      std::cout << "RESIDU/PAIRES " << mP12->ResiduMoy() << " " << mP13->ResiduMoy() << " " << mP23->ResiduMoy() << " " << "\n";
      std::cout << "R Glob " << ResiduGlob() << "\n";
      std::cout << "Time bundle " << aChrono.uval() << "\n";
   }


    for (int aK=0 ; aK<3 ; aK++)
    {
        delete  mPairs[aK];
        delete  mIms[aK];
    }
    mPairs.clear();
    mIms.clear();
    mFullH123.clear();
    mRedH123.clear();
}
int  SaisieAppuisPredic_main(int argc,char ** argv)
{
    Pt2di aSzW(800,800);
    Pt2di aNbFen(-1,-1);
    std::string aFullName,aNamePt,anOri, aModeOri, aNameMesure, aDir, aName;
    std::string aMasq3D,aPIMsFilter;
    bool aForceGray = true;
    double aZMoy,aZInc;
    std::string aInputSec;

    double aFlou=0.0;

    std::string aTypePts="Pts";

    SaisieAppuisPredic(argc, argv, aSzW, aNbFen, aFullName, aDir, aName, aNamePt, anOri, aModeOri, aNameMesure, aTypePts,aMasq3D,aPIMsFilter, aFlou, aForceGray, aZMoy, aZInc,aInputSec);

    if(!MMVisualMode)
    {
        std::string aCom =     MMDir() +"bin/SaisiePts "
                +  MMDir() +"include/XML_MicMac/SaisieAppuisPredic.xml "
                +  std::string(" DirectoryChantier=") + aDir
                +  std::string(" +Images=") + QUOTE(aName)
                +  std::string(" +Ori=") + anOri
                +  std::string(" +LargeurFlou=") + ToString(aFlou)
                +  std::string(" +Terrain=") + aNamePt
                +  std::string(" +Sauv=") + aNameMesure
                +  std::string(" +SzWx=") + ToString(aSzW.x)
                +  std::string(" +SzWy=") + ToString(aSzW.y)
                +  std::string(" +NbFx=") + ToString(aNbFen.x)
                +  std::string(" +NbFy=") + ToString(aNbFen.y)
                +  std::string(" +TypePts=") + aTypePts;

        if (aModeOri == "GRID")
        {
            aCom += " +ModeOriIm=eGeomImageGrille"
                    + std::string(" +Conik=false")
                    +  std::string(" +ZIncIsProp=false")
                    //+ " +PostFixOri=GRIBin"
                    + " +Px1Inc="+ ToString(aZInc) + std::string(" ")
                    + " +Px1Moy="+ ToString(aZMoy) + std::string(" ");

            //aCom += std::string(" +Geom=eGeomMNTFaisceauIm1ZTerrain_Px1D");
        }

       if (EAMIsInit(&aMasq3D))
          aCom = aCom + std::string(" +WithMasq3D=true +Masq3D=")+aMasq3D;

       if (EAMIsInit(&aPIMsFilter))
          aCom = aCom + std::string(" +WithPIMsFilter=true +PIMsFilter=")+aPIMsFilter;

        if (EAMIsInit(&aFlou))
            aCom = aCom + std::string(" +FlouSpecified=true");
        if (EAMIsInit(&aTypePts))
            aCom = aCom + std::string(" +TypeGlobEcras=true");
        if (EAMIsInit(&aForceGray))
           aCom = aCom + " +ForceGray=" + ToString(aForceGray);

        if (EAMIsInit(&aInputSec))
        {
           aCom = aCom + " +WithInputSec=true  +InputSec=" + aInputSec + " ";
        }

        std::cout << aCom << "\n";

        int aRes = system(aCom.c_str());

        return aRes;
    }
    else
        return EXIT_SUCCESS;
}
int AperiCloud_main(int argc,char ** argv)
{
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir,aPat,aFullDir;

    std::string AeroIn;
    //std::vector<std::string> ImPl;
    int ExpTxt=0;
    int PlyBin=1;
    bool CalPerIm=false;
    std::string Out="";

    int RGB = -1;
    double aSeuilEc = 10.0;
    double aLimBsH;
    bool   WithPoints = true;
    bool   WithCam = true;
    Pt2dr  aFocs;
    Pt3di aColCadre(255,0,0);
    Pt3di aColRay(0,255,0);
    std::string aSetHom="";
    std::string aKeyCalcName;

    ElInitArgMain
    (
               argc,argv,
               LArgMain()  << EAMC(aFullDir,"Full name (Dir+Pattern)", eSAM_IsPatFile)
                    << EAMC(AeroIn,"Orientation directory", eSAM_IsExistDirOri),
               LArgMain()
                    << EAM(ExpTxt,"ExpTxt",true,"Point in txt format ? (Def=false)", eSAM_IsBool)
                    << EAM(Out,"Out",true,"Result (Def=AperiCloud.ply)", eSAM_IsOutputFile)
                    << EAM(PlyBin,"Bin",true,"Ply in binary mode (Def=true)", eSAM_IsBool)
                    << EAM(RGB,"RGB",true,"Use RGB image to texturate points (Def=true)")
                    << EAM(aSeuilEc,"SeuilEc",true,"Max residual (Def=10)")
                    << EAM(aLimBsH,"LimBsH",true,"Limit ratio base to height (Def=1e-2)", eSAM_NoInit)
                    << EAM(WithPoints,"WithPoints",true,"Do we add point cloud? (Def=true) ",eSAM_IsBool)
                    << EAM(CalPerIm,"CalPerIm",true,"If a calibration per image was used (Def=false)",eSAM_IsBool)
                    << EAM(aFocs,"Focs",true,"Interval of Focal")
                    << EAM(WithCam,"WithCam",true,"With Camera (Def=true)")
                    << EAM(aColCadre,"ColCadre",true,"Col of camera rect Def= 255 0 0 (Red)")
                    << EAM(aColRay,"ColRay",true,"Col of camera rect Def=  0 255 0 (Green)")
                    << EAM(aSetHom,"SH",true,"Set of Hom, Def=\"\", give MasqFiltered for result of HomolFilterMasq")
                    << EAM(aKeyCalcName,"KeyName",true,"Key to compute printed string (Def contain only digit)")
    );

    if (!MMVisualMode)
    {
        if (RGB >=0)
        {
            RGB = RGB ? 3  : 1;
        }

        string aXmlName="Apero-Cloud.xml";
/*
        if (CalPerIm)
        {
            aXmlName="Apero-Cloud-PerIm.xml";
        }
*/

#if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
#endif
        SplitDirAndFile(aDir,aPat,aFullDir);

        StdCorrecNameOrient(AeroIn,aDir);
        if (Out=="")
        {
            Out="AperiCloud_" + AeroIn + ".ply";
        }


        //std::string aCom =   MMDir() + std::string("bin" ELISE_STR_DIR  "Apero ")
        //                   + MMDir() + std::string("include" ELISE_STR_DIR "XML_MicMac" ELISE_STR_DIR "Apero-Cloud.xml ")
        std::string aCom =   MM3dBinFile_quotes("Apero")
                + ToStrBlkCorr( MMDir()+std::string("include" ELISE_STR_DIR "XML_MicMac" ELISE_STR_DIR)+ aXmlName)+" "
                + std::string(" DirectoryChantier=") +aDir +  std::string(" ")
                + std::string(" +PatternAllIm=") + QUOTE(aPat) + std::string(" ")
                + std::string(" +Ext=") + (ExpTxt?"txt":"dat")
                + std::string(" +AeroIn=-") + AeroIn
                + std::string(" +Out=") + Out
                + std::string(" +PlyBin=") + (PlyBin?"true":"false")
                + std::string(" +NbChan=") +  ToString(RGB)
                + std::string(" +SeuilEc=") +  ToString(aSeuilEc)
                ;

        if (EAMIsInit(&CalPerIm))
              aCom =  aCom + " +CalPerIm=" +ToString(CalPerIm);


        if (EAMIsInit(&aFocs))
        {
            aCom = aCom + " +FocMin=" + ToString(aFocs.x) + " +FocMax=" + ToString(aFocs.y);
        }

        if (EAMIsInit(&WithCam))
        {
            aCom = aCom + " +WithCam=" + ToString(WithCam) ;
        }

        if (EAMIsInit(&aColCadre))
        {
            aCom = aCom + " +ColCadre=" + StrP2Coul(aColCadre) ;
        }
        if (EAMIsInit(&aColRay))
        {
            aCom = aCom + " +ColRay=" + StrP2Coul(aColRay) ;
        }

        if (! WithPoints)
        {
            aCom = aCom + std::string(" +KeyAssocImage=NKS-Assoc-Cste@NoPoint");
        }

        StdCorrecNameHomol(aSetHom,aDir);
        if (EAMIsInit(&aSetHom))
            aCom = aCom + std::string(" +SetHom=") + aSetHom;


        if (EAMIsInit(&aKeyCalcName))
        {
              aCom = aCom + " +WithCalcName=true +CalcName=" + aKeyCalcName;
        }
        

        if (EAMIsInit(&aLimBsH))
            aCom = aCom + std::string(" +LimBsH=") + ToString(aLimBsH);

        std::cout << "Com = " << aCom << "\n";
        int aRes = System(aCom.c_str());

        return aRes;
    }
    else
        return EXIT_SUCCESS;
}
cAppli_C3DC::cAppli_C3DC(int argc,char ** argv,bool DoMerge) :
    cAppliWithSetImage  (argc-2,argv+2,TheFlagDev16BGray|TheFlagAcceptProblem),
    mTuning             (MPD_MM()),
    mPurge              (true),
    mPlyCoul            (true),
    mMergeOut           ("C3DC.ply"),
    mSzNorm             (3),
    mDS                 (1.0),
    mZoomF              (1),
    mDoMerge            (DoMerge),
    mMMIN               (0),
    mUseGpu	       (false),
    mArgSupEpip         (""),
    mDebugMMByP         (false)
{


#if(ELISE_QT_VERSION >= 4)

    if (MMVisualMode)
    {
        QApplication app(argc, argv);

        LArgMain LAM;
        LAM << EAMC(mStrType,"Mode",eSAM_None,ListOfVal(eNbTypeMMByP));

        std::vector <cMMSpecArg> aVA = LAM.ExportMMSpec();

        cMMSpecArg aArg = aVA[0];

        list<string> liste_valeur_enum = listPossibleValues(aArg);

        QStringList items;
        list<string>::iterator it=liste_valeur_enum.begin();
        for (; it != liste_valeur_enum.end(); ++it)
            items << QString((*it).c_str());

        setStyleSheet(app);

        bool ok = false;
        int  defaultItem = 0;

        if(argc > 1)
            defaultItem = items.indexOf(QString(argv[1]));

        QInputDialog myDialog;
        QString item = myDialog.getItem(NULL, app.applicationName(),
                                        QString (aArg.Comment().c_str()), items, defaultItem, false, &ok);

        if (ok && !item.isEmpty())
            mStrType = item.toStdString();
        else
            return;

        ReadType(mStrType);
    }
    else
    {
        ELISE_ASSERT(argc >= 2,"Not enough arg");
        ReadType(argv[1]);
    }
#else
    ELISE_ASSERT(argc >= 2,"Not enough arg");
    ReadType(argv[1]);
#endif

    ElInitArgMain
    (
        argc,argv,
        LArgMain()  << EAMC(mStrType,"Type in enumerated values", eSAM_None,ListOfVal(eNbTypeMMByP))
        << EAMC(mEASF.mFullName,"Full Name (Dir+Pattern)", eSAM_IsPatFile)
        << EAMC(mOriFull,"Orientation", eSAM_IsExistDirOri),
        LArgMain()
        << EAM(mMasq3D,"Masq3D",true,"3D masq for point selection",eSAM_IsExistFileRP)
        << EAM(mMergeOut,"Out",true,"final result (Def=C3DC.ply)")
        << EAM(mSzNorm,"SzNorm",true,"Sz of param for normal evaluation (<=0 if none, Def=2 means 5x5) ")
        << EAM(mPlyCoul,"PlyCoul",true,"Colour in ply ? (Def = true)")
        << EAM(mTuning,"Tuning",true,"Will disappear one day ...",eSAM_InternalUse)
        << EAM(mPurge,"Purge",true,"Purge result, (Def=true)")
        << EAM(mDS,"DownScale",true,"DownScale of Final result, Def depends on mode")
        << EAM(mZoomF,"ZoomF",true,"Zoom final, Def depends on mode",eSAM_IsPowerOf2)
        << EAM(mUseGpu,"UseGpu",false,"Use cuda (Def=false)")
        << EAM(mDefCor,"DefCor",true,"Def correlation, context depend")
        << EAM(mZReg,"ZReg",true,"Regularisation, context depend")
        << EAM(mFilePair,"FilePair",true,"Explicit pairs of images (as in Tapioca)", eSAM_IsExistFileRP)
        << EAM(mDebugMMByP,"DebugMMByP",true,"Debug MMByPair ...")
    );

    if (MMVisualMode) return;

    if (!EAMIsInit(&mDS))
    {
        // if (mType==eQuickMac) mDS = 2.0;
    }
    if (!EAMIsInit(&mZoomF))
    {
        if (mType==eBigMac)   mZoomF = 2;
        if (mType==eMicMac)   mZoomF = 4;
        if (mType==eQuickMac) mZoomF = 8;
        if (mType==eStatue)   mZoomF = 2;
        if (mType==eForest)   mZoomF = 4;
    }

    if (EAMIsInit(&mDefCor)) mArgSupEpip +=  " DefCor=" + ToString(mDefCor);
    if (EAMIsInit(&mZReg)) mArgSupEpip +=  " ZReg=" + ToString(mZReg);

    if (! EAMIsInit(&mMergeOut)) mMergeOut = "C3DC_"+ mStrType + ".ply";

    mStrImOri0  =  BLANK + QUOTE(mEASF.mFullName) +  BLANK + Ori() + BLANK;
    mStrImOriApSec = BLANK +  DirAndPatFileMMByP() +  BLANK + Ori() + BLANK;
    mArgMasq3D = "";
    if (EAMIsInit(&mMasq3D))
        mArgMasq3D = std::string(" Masq3D=" + mMasq3D + BLANK) ;


    //=====================================

    mBaseComMMByP =    MM3dBinFile("MMByP ")
                       +  BLANK + mStrType
                       +  mStrImOri0
                       +  mArgMasq3D
                       +  " UseGpu=" + ToString(mUseGpu);
    if (mDebugMMByP)
        mBaseComMMByP = mBaseComMMByP + " DebugMMByP=true";

    if (EAMIsInit(&mFilePair))
        mBaseComMMByP  += " FilePair=" + mFilePair;


    //=====================================
    mBaseComEnv =      MM3dBinFile("TestLib MMEnvlop ")
                       +  mStrImOriApSec
                       +  std::string(" 16 ")  + ToString(mZoomF) + " "
                       +  mArgMasq3D
                       +  std::string(" AutoPurge=") + ToString(mPurge)
                       +  " Out=" + mStrType
                       ;

    /*
    if (mTuning)
    {
       mBaseComEnv = mBaseComEnv + " DoPlyDS=true";
    }
    */

    //=====================================

    mComMerge =      MM3dBinFile("TestLib  MergeCloud ")
                     +  mStrImOri0 + " ModeMerge=" + mStrType
                     +  " DownScale=" +ToString(mDS)
                     ;

    if (mSzNorm>=0)
    {
        mComMerge = mComMerge + " SzNorm=" + ToString(1+2*mSzNorm);
    }

    mComMerge +=  " PlyCoul=" + ToString(mPlyCoul);

    mMMIN = cMMByImNM::ForGlobMerge(Dir(),mDS,mStrType);

    //=====================================

    std::string aDirFusMM = mMMIN->FullDir();

    mComCatPly =  MM3dBinFile("MergePly ") + QUOTE( aDirFusMM + ".*Merge.*ply") + " Out="  + mMergeOut;

    mStrZ0ZF = " Zoom0=" + ToString(mZoomF) + " ZoomF=" + ToString(mZoomF);
    mMMIN->SetOriOfEtat(mOri);
}
int SBGlobBascule_main(int argc,char ** argv)
{
    NoInit = "NoP1P2";
    aNoPt = Pt2dr(123456,-8765432);

    // MemoArg(argc,argv);
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir,aPat,aFullDir;
    bool ExpTxt=false;
    std::string AeroIn;
    std::string AeroOut;
    std::string PostPlan="_Masq";
    std::string FileMesures ;
    std::string TargetRep = "ki" ;
    bool  CPI = false;


    double DistFE = 0;
    //Pt3dr  Normal;
    //Pt3dr  SNormal;

    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullDir,"Full name (Dir+Pat)", eSAM_IsPatFile )
                    << EAMC(AeroIn,"Orientation in", eSAM_IsExistDirOri)
                    << EAMC(FileMesures,"Images measures xml file", eSAM_IsExistFile)
                    << EAMC(AeroOut,"Out : orientation ", eSAM_IsOutputDirOri),
    LArgMain()
                    << EAM(ExpTxt,"ExpTxt",true)
                    << EAM(PostPlan,"PostPlan",true,"Set NONE if no plane")
                    << EAM(DistFE,"DistFS",true,"Distance between Ech1 and Ech2 to fix scale (if not given no scaling)")
                    << EAM(TargetRep,"Rep",true,"Target coordinate system (Def = ki, ie normal is vertical)")
                    << EAM(CPI,"CPI",true,"Calibration Per Image (Def=false)")

    );

    if (!MMVisualMode)
    {
#if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
#endif
        SplitDirAndFile(aDir,aPat,aFullDir);
        if (EAMIsInit(&PostPlan) && (PostPlan!="NONE"))
        {
            CorrecNameMasq(aDir,aPat,PostPlan);
        }

        StdCorrecNameOrient(AeroIn,aDir);


        MMD_InitArgcArgv(argc,argv);

        std::string aCom =   MM3dBinFile( "Apero" )
                + MMDir() + std::string("include/XML_MicMac/Apero-SB-Bascule.xml ")
                + std::string(" DirectoryChantier=") +aDir +  std::string(" ")
                + std::string(" +PatternAllIm=") + QUOTE(aPat) + std::string(" ")
                + std::string(" +AeroOut=-") +  AeroOut
                + std::string(" +Ext=") + (ExpTxt?"txt":"dat")
                + std::string(" +AeroIn=-") + AeroIn
                + std::string(" +PostMasq=") + PostPlan
                + std::string(" +DistFE=") + ToString(DistFE)
                + std::string(" +RepNL=") + TargetRep
                + std::string(" +FileMesures=") + FileMesures
                + std::string(" +CPI=") + ToString(CPI)
                + std::string(" +AcceptNoPointInPlan=") + ToString(PostPlan=="NONE")
                ;



        std::cout << "Com = " << aCom << "\n";
        int aRes = system_call(aCom.c_str());


        return aRes;
    }
    else
    {
        return EXIT_SUCCESS;
    }
}
Exemple #8
0
int TestCam_main(int argc,char ** argv)
{
    std::string aFullName;
    std::string aNameCam;
    std::string aNameDir;
    std::string aNameTag = "OrientationConique";
    bool ExtP = false;
    bool TOC = false;
    Pt2dr TDINV;

    double X,Y,Z;
    X = Y = Z = 0;
    bool aModeGrid = false;
    std::string Out;

    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullName,"File name", eSAM_IsPatFile)
                << EAMC(X,"x")
                << EAMC(Y,"y")
                << EAMC(Z,"z"),
    LArgMain()
                    << EAM(aNameTag,"Tag",true,"Tag to get cam")
                    << EAM(aModeGrid,"Grid",true,"Test Grid Mode", eSAM_IsBool)
                    << EAM(Out,"Out",true,"To Regenerate an orientation file",eSAM_NoInit)
                    << EAM(ExtP,"ExtP",true,"Detail on external parameter", eSAM_IsBool)
                    << EAM(TOC,"TOC",true,"Test corners", eSAM_IsBool)
                    << EAM(TDINV,"TDINV",true,"Test Dist Inv",eSAM_NoInit)
    );

    SplitDirAndFile(aNameDir,aNameCam,aFullName);

    cInterfChantierNameManipulateur * anICNM = cInterfChantierNameManipulateur::BasicAlloc(aNameDir);
/*
    cTplValGesInit<std::string>  aTplFCND;
    cInterfChantierNameManipulateur * anICNM =
        cInterfChantierNameManipulateur::StdAlloc(0,0,aNameDir,aTplFCND);
*/


   ElCamera * aCam  = Gen_Cam_Gen_From_File(aModeGrid,aFullName,aNameTag,anICNM);

   CamStenope * aCS = aCam->CS();

   if (ExtP)
   {
       std::cout << "  ###########  EXTERNAL ##############\n";
       if (aCS)
       {
           std::cout << "Center " << aCS->VraiOpticalCenter() << "\n";
       }
       std::cout <<  "  I : " << aCS->L3toR3(Pt3dr(1,0,0)) - aCS->L3toR3(Pt3dr(0,0,0)) << "\n";
       std::cout <<  "  J : " << aCS->L3toR3(Pt3dr(0,1,0)) - aCS->L3toR3(Pt3dr(0,0,0))<< "\n";
       std::cout <<  "  K : " << aCS->L3toR3(Pt3dr(0,0,1)) - aCS->L3toR3(Pt3dr(0,0,0))<< "\n";
       std::cout << "\n";
   }

    if (TOC)
       TestOneCorner(aCam);

    if (EAMIsInit(&TDINV))
       TestDistInv(aCam,TDINV);



   if (aModeGrid)
   {
       std::cout << "Camera is grid " << aCam->IsGrid() << " " << aCam->Dist().Type() << "\n";
   }


   TestCamCHC(*aCam);

   TestDirect(aCam,Pt3dr(X,Y,Z));

   if (Out!="")
   {
         cOrientationConique aCO = aCam->StdExportCalibGlob();
         MakeFileXML(aCO,Out);
   }

    return EXIT_SUCCESS;
}
cAppliTarama::cAppliTarama(int argc,char ** argv) :
    cAppliWithSetImage(argc-1,argv+1,0)
{
    NoInit = "XXXXXXXXXX";

    // MemoArg(argc,argv);
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir,aPat,aFullDir;
    std::string Aero;
    int  Zoom = 8;
    std::string  NOREP = "NO-REPERE";
    std::string Repere = NOREP;
    std::string DirOut = "TA";
    double   aZMoy = 0;
    int    aKNadir = -1;
    double aIncidMax = 1e5;
    bool   UnUseAXC = false;


    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullDir,"Full Image (Dir+Pat)", eSAM_IsPatFile)
                    << EAMC(Aero,"Orientation", eSAM_IsExistDirOri),
    LArgMain()
                    << EAM(Zoom,"Zoom",true,"Resolution, (Def=8, must be pow of 2)",eSAM_IsPowerOf2)
                    << EAM(Repere,"Repere",true,"Local coordinate system as created with RepLocBascule",eSAM_IsExistFile)
                    << EAM(DirOut,"Out",true,"Directory for output (Deg=TA)")
                    << EAM(aZMoy,"ZMoy",true,"Average value of Z")
                    << EAM(aKNadir,"KNadir",true,"KBest image or Nadir (when exist)")
                    << EAM(aIncidMax,"IncMax",true,"Maximum incidence of image", eSAM_NoInit)
                    << EAM(UnUseAXC,"UnUseAXC",true,"Internal use for unanamorphosed ortho",eSAM_InternalUse)
    );

    if (!MMVisualMode)
    {
#if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
#endif
        SplitDirAndFile(aDir,aPat,aFullDir);

        StdCorrecNameOrient(Aero,aDir);


        MMD_InitArgcArgv(argc,argv);

        std::string aCom =  MM3dBinFile( "MICMAC" )
                + MMDir() + std::string("include/XML_MicMac/MM-TA.xml ")
                + std::string(" WorkDir=") +aDir +  std::string(" ")
                + std::string(" +PatternAllIm=") + QUOTE(aPat) + std::string(" ")
                + std::string(" +Zoom=") + ToString(Zoom)
                + std::string(" +Aero=") + Aero
                + std::string(" +DirMEC=") + DirOut
                ;

        if (EAMIsInit(&aIncidMax))
        {
            aCom = aCom + " +DoIncid=true +IncidMax=" + ToString(aIncidMax) + " " + " +ZMoy=" + ToString(AltiMoy()) + " " ;
;
        }

        if (EAMIsInit(&aKNadir))
            aCom = aCom + " +KBestMasqNadir=" + ToString(aKNadir);

        if (EAMIsInit(&aZMoy))
        {
            aCom = aCom + " +FileZMoy=File-ZMoy.xml"
                    + " +ZMoy=" + ToString(aZMoy);
        }
        if (EAMIsInit(&UnUseAXC)) aCom = aCom + " +UnUseAXC=" + ToString(UnUseAXC);

        if (Repere!=NOREP)
        {
            bool IsOrthoXCste;
            bool IsAnamXsteOfCart;
            if (RepereIsAnam(aDir+Repere,IsOrthoXCste,IsAnamXsteOfCart))
            {
                aCom =    aCom
                        +  std::string(" +DoAnam=true ")
                        +  std::string(" +DoIncid=true ")
                        +  std::string(" +ParamAnam=") + Repere;
            }
            else
            {
                aCom =     aCom    + std::string(" +Repere=") + Repere ;
            }
        }

#if (ELISE_windows)
		aCom = "\"" + aCom + "\"";
#endif		
        std::cout << "Com = " << aCom << "\n";
        mResult = system_call(aCom.c_str());

    }
    else
    {
       mResult = EXIT_SUCCESS;
    }
}
int ConvertIm_main(int argc,char ** argv)
{
    MMD_InitArgcArgv(argc,argv);
    Tiff_Im::SetDefTileFile(1000000);


    std::string aNameIn ;

    INT aReducX=0;
    INT aReducY=0;
    INT aReducXY=0;
    INT aVisu=0;
    GenIm::type_el aTypeOut ;
    std::string aNameTypeOut ="";

    Tiff_Im::PH_INTER_TYPE aPhInterpOut ;
    std::string aNamePITOut ="";
    std::string PITOut[] = {"RGB","BW"};
    std::list<std::string> lOut(PITOut, PITOut + sizeof(PITOut) / sizeof(std::string) );

    std::string aNameOut;
    std::string anExt;

    Pt2di aP0(0,0);

    Pt2di aSzOut ;
    Pt2di aSzTF(-1,-1);

    REAL aDyn=1.0;

    Pt2di aSzTileInterne(-1,-1);
    int aKCh = -1;


    std::vector<int> aVPermut;
    int aNoTile = 0;
    std::string aF2 ="";


    ElInitArgMain
    (
    argc,argv,
                LArgMain()  << EAMC(aNameIn, "Image", eSAM_IsExistFile),
    LArgMain()  << EAM(aNameOut,"Out",true)
                << EAM(anExt,"Ext",true)
                    << EAM(aSzOut,"SzOut",true, "Size out", eSAM_NoInit)
                    << EAM(aP0,"P0",true)
                    << EAM(aNameTypeOut,"Type",true, "TypeMNT", eSAM_None, ListOfVal(GenIm::bits1_msbf, ""))
                    << EAM(aNamePITOut,"Col",true, "Col", eSAM_None,lOut)
                    << EAM(aReducXY,"ReducXY",true)
                    << EAM(aReducX,"ReducX",true)
                    << EAM(aReducY,"ReducY",true)
                    << EAM(aVisu,"Visu",true)
                    << EAM(aSzTF,"SzTifTile",true)
                    << EAM(aSzTileInterne,"SzTileInterne",true)
                    << EAM(aDyn,"Dyn",true)
                    << EAM(aKCh,"KCh",true)
                    << EAM(aNoTile,"NoTile",true)
                    << EAM(aVPermut,"Permut",true, "Permut", eSAM_NoInit)
                    << EAM(aF2,"F2",true)
    );

    if (!MMVisualMode)
    {
        // Tiff_Im aTifIn = Tiff_Im::BasicConvStd(aNameIn);
        Tiff_Im aTifIn = Tiff_Im::UnivConvStd(aNameIn);
        INT aNbChIn = aTifIn.nb_chan();

        if (! EAMIsInit(&aTypeOut)) aTypeOut =aTifIn.type_el();
        if (! EAMIsInit(&aPhInterpOut)) aPhInterpOut =  aTifIn.phot_interp();
        if (! EAMIsInit(&aSzOut)) aSzOut = aTifIn.sz();

        if (aReducXY)
        {
            aReducX = 1;
            aReducY = 1;
        }
        if (aNameOut=="")
        {
            if (anExt=="")
            {
                if (aReducX && aReducY)
                    anExt = "_RXY";
                else if (aReducX)
                    anExt = "_RX";
                else if (aReducY)
                    anExt = "_RY";
                else
                    anExt= "_Out";
            }
            if (IsPostfixed(aNameIn))
              aNameOut = StdPrefix(aNameIn) + anExt +"." + StdPostfix(aNameIn);
           else
              aNameOut = aNameIn + anExt + "tif";
        }

        Pt2di aCoefReduc(aReducX != 0 ? 2 : 1, aReducY != 0 ? 2 : 1);
        aSzOut = aSzOut.dcbyc(aCoefReduc);

        if (aNameTypeOut != "")
           aTypeOut = type_im(aNameTypeOut);

        if (aKCh != -1)
           aNamePITOut="BW";

        if ( aVPermut.size() !=0)
        {
             if ( aVPermut.size() ==1)
                 aPhInterpOut = Tiff_Im::BlackIsZero;
             else if ( aVPermut.size() ==3)
                 aPhInterpOut = Tiff_Im::RGB;
             else
            {
               ELISE_ASSERT(aNamePITOut=="","Nb Canaux incoherents");
            }
        }
        else
        {
            if (aNamePITOut=="RGB")
               aPhInterpOut = Tiff_Im::RGB;
            else if (aNamePITOut=="BW")
               aPhInterpOut = Tiff_Im::BlackIsZero;
            else
            {
               ELISE_ASSERT(aNamePITOut=="","Mode Couleur Inconnu");
            }
        }


        Tiff_Im::COMPR_TYPE aComprOut = Tiff_Im::No_Compr;


        L_Arg_Opt_Tiff aLArg = Tiff_Im::Empty_ARG;


        if (! aNoTile)
        {
           if (aSzTileInterne != Pt2di(-1,-1))
               aLArg = aLArg + Arg_Tiff(Tiff_Im::ATiles(aSzTileInterne));

           if (aSzTF != Pt2di(-1,-1))
               aLArg = aLArg + Arg_Tiff(Tiff_Im::AFileTiling(aSzTF));
        }
        else
        {
             aLArg = aLArg + Arg_Tiff(Tiff_Im::ANoStrip());
             aLArg = aLArg + Arg_Tiff(Tiff_Im::AFileTiling(Pt2di(-1,-1)));
        }


        Tiff_Im aTifOut
                (
                      aNameOut.c_str(),
                      aSzOut,
                      aTypeOut,
                      aComprOut,
                      aPhInterpOut,
                      aLArg
                );
        INT aNbChOut = aTifOut.nb_chan();

        Pt2di aSzROut = aSzOut;
        Output anOut = aTifOut.out();

        Fonc_Num aFin = aTifIn.in_proj();
        if (aF2!="")
        {
             Tiff_Im aT2 = Tiff_Im::BasicConvStd(DirOfFile(aNameIn)+aF2);
             aFin = Virgule(aFin,aT2.in(0));
        }

        if (aVPermut.size() != 0)
           aFin = aFin.permut(aVPermut);

        if (type_im_integral( aTypeOut))
        {
        }
        else
        {
            aFin = Rconv(aFin);
        }

        aFin = reduc_binaire_gen(aFin, aReducX != 0, aReducY != 0, 16, true, 0);
        anOut = Filtre_Out_RedBin_Gen(anOut, aReducX != 0, aReducY != 0);
        aSzROut = aSzOut.mcbyc(aCoefReduc);
        aFin = trans(aFin,aP0);

        if (aKCh!=-1)
           aFin = aFin.kth_proj(aKCh);
        else
        {

            if ((aNbChOut==1) && (aNbChIn==3))
                aFin = (aFin.v0() + aFin.v1() + aFin.v2()) / 3.0;

            if ((aNbChOut==3) && (aNbChIn==1))
               aFin = Virgule(aFin,aFin,aFin);
         }


        if (aVisu)
           anOut = anOut |  Video_Win::WiewAv(aSzROut);

        if (aDyn != 1.0)
           aFin = aFin * aDyn;

        if (type_im_integral(aTypeOut) && (aTypeOut!=GenIm::int4))
        {
            int aVMin,aVMax;
            min_max_type_num(aTypeOut,aVMin,aVMax);
            aFin = Max(aVMin,Min(aVMax-1,aFin));
        }

        ELISE_COPY(rectangle(Pt2di(0,0),aSzROut),aFin,anOut);

        return EXIT_SUCCESS;
    }
    else return EXIT_SUCCESS;
}
cAppliMMTestOrient::cAppliMMTestOrient(int argc,char ** argv)
{
    MMD_InitArgcArgv(argc,argv);

    std::string anIm1,anIm2;
    std::string AeroIn= "";
    std::string AeroInSsMinus= "";
    std::string aDir="./";
    int Zoom0=32;
    int ZoomF=2;

    double LargMin=30.0;

    bool mModePB = false;
    std::string mModeOri;
    double aZMoy,aZInc;
    bool    ShowCom = false;
    bool ExportDepl = false;
    bool mModeGB = false;

    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(anIm1,"First Image", eSAM_IsExistFile)
                    << EAMC(anIm2,"Second Image", eSAM_IsExistFile)
                    << EAMC(AeroIn,"Orientation", eSAM_IsExistFile),
    LArgMain()  << EAM(aDir,"Dir",true,"Directory, Def=./")
                    << EAM(Zoom0,"Zoom0",true,"Zoom init, pow of 2  in [128,8], Def depend of size", eSAM_IsPowerOf2)
                    << EAM(ZoomF,"ZoomF",true,"Zoom init,  pow of 2  in [4,1], Def=2",eSAM_IsPowerOf2)
                    << EAM(mModePB,"PB",true,"Push broom sensor")
                    << EAM(mModeGB,"GB",true,"Gen Bundle Mode")
                    << EAM(mModeOri,"MOri",true,"Mode Orientation (GRID or RTO), Mandatory in PB", eSAM_NoInit)
                    << EAM(aZMoy,"ZMoy",true,"Average Z, Mandatory in PB", eSAM_NoInit)
                    << EAM(aZInc,"ZInc",true,"Incertitude on Z, Mandatory in PB", eSAM_NoInit)
                    << EAM(ShowCom,"ShowCom",true,"Show MicMac command (tuning purpose)")
                    << EAM(ExportDepl,"ExportDepl",true,"Export result as displacement maps")
    );

    // cInterfChantierNameManipulateur * aICNM = cInterfChantierNameManipulateur::BasicAlloc(DirOfFile(anIm1));

    mVIms.push_back(anIm1);
    mVIms.push_back(anIm2);

    mMMV = MMVisualMode;
    if (MMVisualMode) 
    {
        return;
    }

    if (!mModePB)
    {
        StdCorrecNameOrient(AeroIn,aDir);
    }


    if (!EAMIsInit(&mModePB))
        mModePB = EAMIsInit(&mModeOri);



    std::string aFullModeOri = "eGeomImageOri";
    if (mModePB)
    {
         ELISE_ASSERT(EAMIsInit(&mModeOri) , "MOri is Mandatory in PB");
         ELISE_ASSERT(EAMIsInit(&aZMoy)    , "ZMoy is Mandatory in PB");
         ELISE_ASSERT(EAMIsInit(&aZInc)    , "ZInc is Mandatory in PB");

         if (mModeOri=="GRID")     aFullModeOri= "eGeomImageGrille";
         else if (mModeOri=="RTO") aFullModeOri= "eGeomImageRTO";
         else  {ELISE_ASSERT(false,"Unknown mode ori");}
    }

    if (mModeGB)
    {
         ELISE_ASSERT(EAMIsInit(&aZMoy)    , "ZMoy is Mandatory in GB");
         ELISE_ASSERT(EAMIsInit(&aZInc)    , "ZInc is Mandatory in GB");
         aFullModeOri= "eGeomGen";

    }

// eGeomImageRTO
// eGeomImageGrille

    if (! EAMIsInit(&Zoom0))
    {
         Zoom0 = FixSizeImage(128,aDir+anIm1,LargMin,4);
    }

#if (ELISE_windows)
     replace( aDir.begin(), aDir.end(), '\\', '/' );
#endif




   mCom =     MM3dBinFile( "MICMAC" ) + " "
                       +  Basic_XML_MM_File("MM-PxTransv.xml")
                       +  std::string(" WorkDir=") + aDir + " "
                       +  std::string(" +Im1=") + QUOTE(anIm1) + " "
                       +  std::string(" +Im2=") + QUOTE(anIm2) + " "
                       +  std::string(" +AeroIn=-") + AeroIn + " "
                       +  std::string(" +AeroInSsMinus=") + AeroIn + " "
                       +  std::string(" +Zoom0=") + ToString(Zoom0) + " "
                       +  std::string(" +ZoomF=") + ToString(ZoomF) + " "
                      ;

    if (mModePB)
    {
         mCom = mCom + " +Conik=false "
                     +  " +ModeOriIm=" + aFullModeOri + std::string(" ")
                     + " +PostFixOri=" + AeroIn     + std::string(" ")
                     + " +Px1Inc=" + ToString(aZInc) + std::string(" ")
                     + " +Px1Moy=" + ToString(aZMoy) + std::string(" ") ;
    }
    if (mModeGB)
    {
         mCom = mCom + " +Conik=false "
                     + " +UseGenBundle=true"
                     + " +ModeOriIm=" + aFullModeOri + std::string(" ")
                     + " +Px1Inc=" + ToString(aZInc) + std::string(" ")
                     + " +Px1Moy=" + ToString(aZMoy) + std::string(" ") ;
    }

    if (ShowCom) std::cout << mCom << "\n";


   if (ExportDepl) mCom = mCom + " +ExporFieldsHom=true ";
}
Exemple #12
0
cAppli_LumRas::cAppli_LumRas(int argc,char ** argv) :
   cAppliWithSetImage(argc-2,argv +2,TheFlagNoOri|TheFlagDev16BGray),
   // mTifBaseGr   (0),
   mTifBaseCoul (0),
   mImGr        (1,1),
   mImMasq      (1,1)

{
     std::vector<double> aPdsI;
     ElInitArgMain
     (
           argc,argv,
           LArgMain() << EAM(mNameImBase, "Image name",  true, "Image name", eSAM_IsExistFile)
                      << EAM(mPatImRas, "Image pattern", true, "Pattern", eSAM_IsPatFile) ,
           LArgMain() << EAM(mPostMasq,"Masq",true,"Mask for computation", eSAM_NoInit)
                      << EAM(aPdsI,"PdsIn",true,"Pds on RGB Input, def=[1,1,1]", eSAM_NoInit)
                      << EAM(mNameTargSh,"TargShade",true,"Targeted Shade", eSAM_NoInit)
    );


    if (!MMVisualMode)
    {
        for (int aK=(int)aPdsI.size() ; aK<3 ; aK++)
            aPdsI.push_back(1);
        // mTifBaseGr =   new  Tiff_Im (Tiff_Im::StdConvGen(mNameImBase,1,true));
        mTifBaseCoul = new  Tiff_Im (Tiff_Im::StdConvGen(mNameImBase,3,true));

        mSz =  mTifBaseCoul->sz();
        mImGr.Resize(mSz);
        Symb_FNum aFCoul(mTifBaseCoul->in());
        Fonc_Num aFGr =  (aPdsI[0]*aFCoul.v0()+aPdsI[1]*aFCoul.v1()+aPdsI[2]*aFCoul.v2())/(aPdsI[0]+aPdsI[1]+aPdsI[2]);

        ELISE_COPY(mImGr.all_pts(),aFGr,mImGr.out());


        mImMasq = Im2D_Bits<1>(mSz.x,mSz.y,1);
        if (EAMIsInit(&mPostMasq))
        {
            CorrecNameMasq(mEASF.mDir,NameWithoutDir(mNameImBase),mPostMasq);
            std::string aNameMasq = StdPrefix(mNameImBase)+mPostMasq+".tif";
            Tiff_Im aTM(aNameMasq.c_str());
            ELISE_COPY(mImMasq.all_pts(),aTM.in(0),mImMasq.out());
        }
        ELISE_COPY(mImMasq.border(1),0,mImMasq.out());

        mKeyHom = "NKS-Assoc-CplIm2Hom@@dat";
        // mKeyHom = "";

        Fonc_Num aGlobSh;
        for (int aK=0 ; aK<int(mVSoms.size()) ; aK++)
        {
            std::string aName = mVSoms[aK]->attr().mIma->mNameIm;
            mVIm.push_back(new cImage_LumRas(mEASF.mDir+aName,*this));
            //Fonc_Num aFShade = mVIm.back()->mImShade.in();



            // aGlobSh = (aK==0) ? aFShade : Virgule(aGlobSh,aFShade);
        }


        if (EAMIsInit(&mNameTargSh))
        {
            DoShadeByLeastSquare();
        }
        else
        {
             for (int aK=0 ; aK<int(mVIm.size()) ; aK++)
                mVIm[aK]->CalculShadeByDiff();
        }
/* 
  // RGB 

       std::string aNameOut = mEASF.mDir+ "LumRas_"+StdPrefix(mNameImBase) + ".tif";
       Tiff_Im TifTest
               (
                     aNameOut.c_str(),
                     mSz,
                     GenIm::u_int1,
                     Tiff_Im::No_Compr,
                     Tiff_Im::RGB
               );


       ELISE_COPY
       (
             TifTest.all_pts(),
             // Max(0,Min(255,128 * (1 + 5*aGlobSh))),
             Max(0,Min(255,aFCoul+ 20*aGlobSh)),
             TifTest.out()
       );
*/
    }
}
int Campari_main(int argc,char ** argv)
{
    MMD_InitArgcArgv(argc,argv);

    std::string aFullDir= "";
    std::string AeroIn= "";
    std::string AeroOut="";

    bool  CPI1 = false;
    bool  CPI2 = false;
    bool  FocFree = false;
    bool  PPFree = false;
    bool  AffineFree = false;
    bool  AllFree = false;

    bool  PoseFigee = false;

    double aSigmaTieP = 1;
    double aFactResElimTieP = 5;

    std::vector<std::string> GCP;
    std::vector<std::string> EmGPS;
    bool DetailAppuis = false;
    double Viscos = 1.0;
    bool ExpTxt = false;
    std::vector<std::string> aImMinMax;

    Pt3dr aGpsLA;

    int aDegAdd = 0;
    int aDegFree = 0;
    int aDrMax = 0;

    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullDir,"Full Directory (Dir+Pattern)", eSAM_IsPatFile)
                    << EAMC(AeroIn,"Input Orientation", eSAM_IsExistDirOri)
                    << EAMC(AeroOut,"Output Orientation", eSAM_IsOutputDirOri),
    LArgMain()  << EAM(GCP,"GCP",true,"[GrMes.xml,GrUncertainty,ImMes.xml,ImUnc]", eSAM_NoInit)
                    << EAM(EmGPS,"EmGPS",true,"Embedded GPS [Gps-Dir,GpsUnc, ?GpsAlti?], GpsAlti if != Plani", eSAM_NoInit)
                    << EAM(aGpsLA,"GpsLa",true,"Gps Lever Arm, in combination with EmGPS", eSAM_NoInit)
                    << EAM(aSigmaTieP,"SigmaTieP", true, "Sigma use for TieP weighting (Def=1)")
                    << EAM(aFactResElimTieP,"FactElimTieP", true, "Fact elimination of tie point (prop to SigmaTieP, Def=5)")
                    << EAM(CPI1,"CPI1",true,"Calib Per Im, Firt time", eSAM_IsBool)
                    << EAM(CPI2,"CPI2",true,"Calib Per Im, After first time, reUsing Calib Per Im As input", eSAM_IsBool)
                    << EAM(FocFree,"FocFree",true,"Foc Free (Def=false)", eSAM_IsBool)
                    << EAM(PPFree,"PPFree",true,"Principal Point Free (Def=false)", eSAM_IsBool)
                    << EAM(AffineFree,"AffineFree",true,"Affine Parameter (Def=false)", eSAM_IsBool)
                    << EAM(AllFree,"AllFree",true,"Affine Parameter (Def=false)", eSAM_IsBool)
                    << EAM(DetailAppuis,"DetGCP",true,"Detail on GCP (Def=false)", eSAM_IsBool)
                    << EAM(Viscos,"Visc",true,"Viscosity in Levenberg-Marquardt like resolution (Def=1.0)")
                    << EAM(ExpTxt,"ExpTxt",true, "Export in text format (Def=false)",eSAM_IsBool)
                    << EAM(aImMinMax,"ImMinMax",true, "Im max and min to avoid tricky pat")
                    << EAM(aDegAdd,"DegAdd",true, "When specified, degree of additionnal parameter")
                    << EAM(aDegFree,"DegFree",true, "When specified degree of freedom of parameters generiqs")
                    << EAM(aDrMax,"DRMax",true, "When specified degree of freedom of radial parameters")
 		    << EAM(PoseFigee,"PoseFigee",true,"Does the external orientation of the cameras are frozen or free (Def=false, i.e. camera poses are free)", eSAM_IsBool)

    );

    if (!MMVisualMode)
    {
        std::string aDir,aPat;
    #if (ELISE_windows)
         replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
    #endif
        SplitDirAndFile(aDir,aPat,aFullDir);
        StdCorrecNameOrient(AeroIn,aDir);

        Pt2dr Focales(0,100000);
        std::string aParamPatFocSetIm = "@" + aPat + "@" + ToString(Focales.x) + "@" + ToString(Focales.y) ;
        std::string aSetIm = "NKS-Set-OfPatternAndFoc" + aParamPatFocSetIm;


        if (EAMIsInit(&aImMinMax))
        {
            ELISE_ASSERT(aImMinMax.size()==2,"Bad size in vect");
            aSetIm =  "NKS-Set-OfPatternAndFocAndInterv" + aParamPatFocSetIm + "@" + aImMinMax[0] + "@" + aImMinMax[1];
        }




       std::string aCom =     MM3dBinFile_quotes( "Apero" )
                           +  ToStrBlkCorr( Basic_XML_MM_File("Apero-Compense.xml") )
                           +  std::string(" DirectoryChantier=") + aDir + " "
                           +  std::string(" +SetIm=") + QUOTE(aSetIm) + " "
                           +  std::string(" +AeroIn=-") + AeroIn + " "
                           +  std::string(" +AeroOut=-") + AeroOut + " "
                          ;

        if (CPI1 || CPI2) aCom       += " +CPI=true ";
        if (CPI2) aCom       += " +CPIInput=true ";
        if (FocFree) aCom    += " +FocFree=true ";
        if (PPFree) aCom    += " +PPFree=true ";
        if (AffineFree) aCom += " +AffineFree=true ";
        if (AllFree) aCom    += " +AllFree=true ";
        if (ExpTxt) aCom += std::string(" +Ext=") + (ExpTxt?"txt ":"dat ")  ;

 	if (PoseFigee) aCom    += " +PoseFigee=true ";

        if (EAMIsInit(&aFactResElimTieP))
           aCom =  aCom+ " +FactMaxRes=" + ToString(aFactResElimTieP);


       if (EAMIsInit(&Viscos)) aCom  +=  " +Viscos=" + ToString(Viscos) + " ";

       if (EAMIsInit(&DetailAppuis)) aCom += " +DetailAppuis=" + ToString(DetailAppuis) + " ";

        if (EAMIsInit(&GCP))
        {
            ELISE_ASSERT(GCP.size()==4,"Mandatory part of GCP requires 4 arguments");
            double aGcpGrU = RequireFromString<double>(GCP[1],"GCP-Ground uncertainty");
            double aGcpImU = RequireFromString<double>(GCP[3],"GCP-Image  uncertainty");

            std::cout << "THAT IS ::: " << aGcpGrU << " === " << aGcpImU << "\n";

            aCom =   aCom
                   + std::string("+WithGCP=true ")
                   + std::string("+FileGCP-Gr=") + GCP[0] + " "
                   + std::string("+FileGCP-Im=") + GCP[2] + " "
                   + std::string("+GrIncGr=") + ToString(aGcpGrU) + " "
                   + std::string("+GrIncIm=") + ToString(aGcpImU) + " ";
        }
        if (aDegAdd>0)  aCom = aCom + " +HasModeleAdd=true  +ModeleAdditionnel=eModelePolyDeg" +  ToString(aDegAdd);
        if (aDegFree>0)  aCom = aCom + " +DegGen=" +  ToString(aDegFree);
        if (aDrMax>0)   aCom = aCom + " +DRMax=" +  ToString(aDrMax);

        if (EAMIsInit(&EmGPS))
        {
            ELISE_ASSERT((EmGPS.size()>=2) && (EmGPS.size()<=3) ,"Mandatory part of EmGPS requires 2 arguments");
            StdCorrecNameOrient(EmGPS[0],aDir);
            double aGpsU = RequireFromString<double>(EmGPS[1],"GCP-Ground uncertainty");
            double aGpsAlti = aGpsU;
            if (EmGPS.size()>=3)
               aGpsAlti = RequireFromString<double>(EmGPS[2],"GCP-Ground Alti uncertainty");
            aCom = aCom +  " +BDDC=" + EmGPS[0]
                        +  " +SigmGPS=" + ToString(aGpsU)
                        +  " +SigmGPSAlti=" + ToString(aGpsAlti)
                        +  " +WithCenter=true";

            if (EAMIsInit(&aGpsLA))
            {
                aCom = aCom + " +WithLA=true +LaX="  + ToString(aGpsLA.x)
                                         + " +LaY=" + ToString(aGpsLA.y)
                                         + " +LaZ=" + ToString(aGpsLA.z)
                                         + " ";
            }
        }

        if (EAMIsInit(&aSigmaTieP)) aCom = aCom + " +SigmaTieP=" + ToString(aSigmaTieP);


        std::cout << aCom << "\n";
        int aRes = System(aCom.c_str());

        Campari_Banniere();
        BanniereMM3D();

        return aRes;
    }
    else
        return EXIT_SUCCESS;
}
int GCPBascule_main(int argc,char ** argv)
{
    // MemoArg(argc,argv);
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir,aPat,aFullDir;


    std::string AeroOut;
    std::string AeroIn;
    std::string DicoPts;
    std::string MesureIm;
    bool        ModeL1 = false;
    bool        CPI = false;
    bool ShowUnused = true;
    bool ShowDetail = false;
    bool NLDShow = false;
    bool NLDFTR = true;

    std::string aPatNLD;
    std::vector<std::string> NLDDegX;  NLDDegX.push_back("1");  NLDDegX.push_back("X"); NLDDegX.push_back("Y");
    std::vector<std::string> NLDDegY;  NLDDegY.push_back("1");  NLDDegY.push_back("X"); NLDDegY.push_back("Y");
    std::vector<std::string> NLDDegZ;  NLDDegZ.push_back("1");  NLDDegZ.push_back("X"); NLDDegZ.push_back("X2");
/*
    Pt3di NLDDegX(1,1,1);
    Pt3di NLDDegY(1,1,1);
    Pt3di NLDDegZ(2,0,2);
*/


    ElInitArgMain
    (
        argc,argv,
        LArgMain()  << EAMC(aFullDir,"Full name (Dir+Pat)", eSAM_IsPatFile)
                    << EAMC(AeroIn,"Orientation in", eSAM_IsExistDirOri)
                    << EAMC(AeroOut,"Orientation out", eSAM_IsOutputDirOri)
                    << EAMC(DicoPts,"Ground Control Points File", eSAM_IsExistFile)
                    << EAMC(MesureIm,"Image Measurements File", eSAM_IsExistFile),
        LArgMain()
                    <<  EAM(ModeL1,"L1",true,"L1 minimisation vs L2 (Def=false)", eSAM_IsBool)
                    <<  EAM(CPI,"CPI",true,"when Calib Per Image has to be used", eSAM_IsBool)
                    <<  EAM(ShowUnused,"ShowU",true,"Show unused point (def=true)", eSAM_IsBool)
                    <<  EAM(ShowDetail,"ShowD",true,"Show details (def=false)", eSAM_IsBool)
                    <<  EAM(aPatNLD,"PatNLD",true,"Pattern for Non linear deformation, with aerial like geometry (def,unused)")
                    <<  EAM(NLDDegX,"NLDegX",true,"Non Linear monoms for X, when PatNLD, (Def =[1,X,Y])")
                    <<  EAM(NLDDegY,"NLDegY",true,"Non Linear monoms for Y, when PatNLD, (Def =[1,X,Y])")
                    <<  EAM(NLDDegZ,"NLDegZ",true,"Non Linear monoms for Z, when PatNLD, (Def =[1,X,X2])")
                    <<  EAM(NLDFTR,"NLFR",true,"Non Linear : Force True Rot (Def=true)",eSAM_IsBool)
                    <<  EAM(NLDShow,"NLShow",true,"Non Linear : Show Details (Def=false)",eSAM_IsBool)
    );

    if (!MMVisualMode)
    {
    #if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
    #endif
    SplitDirAndFile(aDir,aPat,aFullDir);
    StdCorrecNameOrient(AeroIn,aDir);


    MMD_InitArgcArgv(argc,argv);

    std::string aCom =   MM3dBinFile_quotes( "Apero" )
                       + ToStrBlkCorr( MMDir()+"include/XML_MicMac/Apero-GCP-Bascule.xml" )+" "
                       + std::string(" DirectoryChantier=") +aDir +  std::string(" ")
                       + std::string(" +PatternAllIm=") + QUOTE(aPat) + std::string(" ")
                       + std::string(" +AeroIn=") + AeroIn
                       + std::string(" +AeroOut=") +  AeroOut
                       + std::string(" +DicoApp=") +  DicoPts
                       + std::string(" +SaisieIm=") +  MesureIm
                    ;

    if (EAMIsInit(&ShowUnused)) aCom = aCom + " +ShowUnused=" + ToString(ShowUnused);
    if (EAMIsInit(&ShowDetail)) aCom = aCom + " +ShowDetail=" + ToString(ShowDetail);

    if (ModeL1)
    {
        aCom = aCom+ std::string(" +L2Basc=") + ToString(!ModeL1);
    }

    if (CPI) aCom += " +CPI=true ";


    if (EAMIsInit(&aPatNLD))
    {
       aCom = aCom + " +UseNLD=true +PatNLD=" + QUOTE(aPatNLD)
                   + " +NLFlagX=" + ToString(FlagOfDeg(NLDDegX))
                   + " +NLFlagY=" + ToString(FlagOfDeg(NLDDegY))
                   + " +NLFlagZ=" + ToString(FlagOfDeg(NLDDegZ))
                   + " +NLDForceTR=" + ToString(NLDFTR)
                   + " +NLDShow=" + ToString(NLDShow)
              ;
    }


    std::cout << "Com = " << aCom << "\n";
    int aRes = System(aCom.c_str(),false,true,true);


    return aRes;

    }
    else return EXIT_SUCCESS;
}