Exemplo n.º 1
0
int GrShade_main(int argc,char ** argv)
{
     std::string aNameIn;
     std::string aNameOut;
     std::string aNameCol="";
     Pt2di aP0Glob(0,0),aSzGlob(0,0);
     INT aNbDir = 20;
     REAL aFZ = 1.0;

     REAL aPdsAnis = 0.95;
     INT  aBrd = -1;
     std::string aTMNt = "real4";
     std::string aTShade = "real4";
     INT aDequant =0;
     INT aVisu = 0;
     REAL aHypsoDyn = -1.0;
     REAL aHypsoSat = 0.5;

     Pt2di aSzMaxDalles (3000,3000);
     INT aSzRecDalles = 300;
     std::string aModeOmbre="CielVu";
     std::string modeOmbre[] = {aModeOmbre,"IgnE","Local","Med","Mixte"};
     std::list<std::string> lModeOmbre(modeOmbre, modeOmbre + sizeof(modeOmbre) / sizeof(std::string) );
     std::string aFileMasq="";

     double  aDericheFact=2.0;
     int     aNbIterF = 4;
     double  aFactExp = 0.95;
     double aDyn = 1.0;
     int aNbMed = 100;
     int aNbIterMed = 1;

     Tiff_Im::SetDefTileFile(1<<15);

     std::vector<double> aVPdsFiltre;


     std::string aModeColor = "IntensShade";
     std::string modeColor[] = {aModeColor,"BackRGB","GrayBackRGB"};
     std::list<std::string> lModeColor(modeColor, modeColor + sizeof(modeColor) / sizeof(std::string) );

     double aTetaH = 25.0;
     double anAzimut = 0.0;
     double aDynMed = 1.0;

     ElInitArgMain
     (
           argc,argv,
           LArgMain() << EAMC(aNameIn, "File name", eSAM_IsExistFile) ,
           LArgMain() << EAM(aNameOut,"Out",true)
                      << EAM(aNameCol,"FileCol",true, "Color file", eSAM_IsExistFile)
                      << EAM(aVisu,"Visu",true)
                      << EAM(aP0Glob,"P0",true)
                      << EAM(aSzGlob,"Sz",true)
                      << EAM(aFZ,"FZ",true)
                      << EAM(aDynMed,"DynMed",true)
                      << EAM(aPdsAnis,"Anisotropie",true)
                      << EAM(aNbDir,"NbDir",true)
                      << EAM(aBrd,"Brd",true)
                      << EAM(aTMNt,"TypeMnt",true, "Type", eSAM_None, ListOfVal(GenIm::bits1_msbf, ""))
                      << EAM(aTShade,"TypeShade",true, "Type", eSAM_None, ListOfVal(GenIm::bits1_msbf, ""))
                      << EAM(aDequant,"Dequant",true)
                      << EAM(aHypsoDyn,"HypsoDyn",true)
                      << EAM(aHypsoSat,"HypsoSat",true)
              << EAM(aSzMaxDalles,"SzMaxDalles",true)
              << EAM(aSzRecDalles,"SzRecDalles",true)
              << EAM(aModeOmbre,"ModeOmbre",true,"in {CielVu,IgnE,Local,Med,Mixte}",eSAM_None,lModeOmbre)
              << EAM(aFileMasq,"Mask",true, "Mask file", eSAM_IsExistFile)
              << EAM(aDericheFact,"DericheFact",true)
              << EAM(aNbIterF,"NbIterF",true)
              << EAM(aFactExp,"FactExp",true)
              << EAM(aDyn,"Dyn",true)
                      << EAM(aVPdsFiltre,"PdsF",true,"[CielVu,Local,Grad,Med]", eSAM_NoInit)
                      << EAM(aModeColor,"ModeColor",true,"Color mode", eSAM_None, lModeColor)
                      << EAM(aNbMed,"NbMed",true)
                      << EAM(aNbIterMed,"NbIterMed",true)
                      << EAM(aTetaH,"TetaH",true)
                      << EAM(anAzimut,"Azimut",true)
    );

    if (!MMVisualMode)
    {

    double aPdsDef = aVPdsFiltre.size() ? 0 : 1;
    for (int aK=aVPdsFiltre.size() ; aK<4 ; aK++)
       aVPdsFiltre.push_back(aPdsDef);

    double aSPdsF = 0;
    for (int aK=0 ; aK<4 ; aK++)
       aSPdsF += aVPdsFiltre[aK];
    for (int aK=0 ; aK<4 ; aK++)
        aVPdsFiltre[aK] /= aSPdsF;


    std::string aDir,aNameFileIn;
    SplitDirAndFile(aDir,aNameFileIn,aNameIn);



     bool WithHypso = (aHypsoDyn>0) || (aNameCol != "");
     // bool WithCol =   (aNameCol != "");


    if (aNameOut=="")
       aNameOut = StdPrefix(aNameIn) +std::string("Shade.tif");

     Tiff_Im aFileIn = Tiff_Im::StdConvGen(aNameIn,1,true,false);
     if (aSzGlob== Pt2di(0,0))
        aSzGlob = aFileIn.sz() -aP0Glob;
     Fonc_Num aFIn = aFileIn.in_gen(Tiff_Im::eModeCoulGray,Tiff_Im::eModeNoProl);

    {
        Tiff_Im
        (
             aNameOut.c_str(),
             aSzGlob,
             GenIm::u_int1,
         Tiff_Im::No_Compr,
         WithHypso  ? Tiff_Im::RGB : Tiff_Im::BlackIsZero
        );
    }
    Tiff_Im aTifOut(aNameOut.c_str());

     if (aSzMaxDalles.x<0) aSzMaxDalles = aSzGlob;
     Pt2di aPRD(aSzRecDalles,aSzRecDalles);
     cDecoupageInterv2D aDecoup
                    (
                            Box2di(aP0Glob,aP0Glob+aSzGlob),
                aSzMaxDalles,
                Box2di(-aPRD,aPRD)
            );

     Im2DGen aMnt =    AllocImGen(aDecoup.SzMaxIn(),aTMNt);
     Im2DGen aShade =  AllocImGen(aDecoup.SzMaxIn(),aTShade);

     cout << "SZ Max In " << aDecoup.SzMaxIn() << endl;
     REAL aRatio = ElMin(800.0/aSzGlob.x,700.0/aSzGlob.y);
     Video_Win * pW  = aVisu                          ?
                       Video_Win::PtrWStd(Pt2di(Pt2dr(aSzGlob)*aRatio)) :
                       0                              ;

     aTetaH *= (2*PI)/360.0;
     anAzimut *= (2*PI)/360.0;

     for (int aKDec=0; aKDec<aDecoup.NbInterv() ; aKDec++)
     {

         Box2di aBoxIn = aDecoup.KthIntervIn(aKDec);
     Pt2di aSzIn = aBoxIn.sz();
     Pt2di aP0In = aBoxIn.P0();

     cout << "DEQ " << aDequant << "Sz In " << aSzIn <<endl;

         REAL aVMin;
         if (aDequant)
         {
             ElImplemDequantifier aDeq(aSzIn);
             aDeq.SetTraitSpecialCuv(true);
             aDeq.DoDequantif(aSzIn, trans(aFIn,aP0In),true);
         REAL aVMax;
             ELISE_COPY
             (
                  rectangle(Pt2di(0,0),aSzIn),
                  aDeq.ImDeqReelle() * aFZ,
                  aMnt.out() | VMax(aVMax) |VMin(aVMin)
             );

         }
         else
     {
             ELISE_COPY
             (
                  rectangle(Pt2di(0,0),aSzIn),
                  trans(aFIn,aP0In)*aFZ,
                  aMnt.out()|VMin(aVMin)
             );
     }
         Im2D_Bits<1> aIMasq(aSzIn.x,aSzIn.y,1);

     if (aFileMasq!="")
     {
             if (ELISE_fp::exist_file(aDir+aFileMasq))
                aFileMasq = aDir+aFileMasq;
         double aDif=100;
         Tiff_Im aFM = Tiff_Im::StdConvGen(aFileMasq,1,true,false);
             ELISE_COPY
             (
                  select(rectangle(Pt2di(0,0),aSzIn),trans(!aFM.in_proj(),aP0In)),
          aVMin-aDif,
                     aMnt.out()
                  |  (aIMasq.out() << 0)
             );
         aVMin-= aDif;
     }

         if (aBrd>0)
         {
            cout << "VMin = " << aVMin <<endl;
            ELISE_COPY(aMnt.border(aBrd),aVMin-1000,aMnt.out());
         }

     // Im2D_REAL4 aShade(aSzGlob.x,aSzGlob.y);
         ELISE_COPY(aShade.all_pts(),0,aShade.out());

         if (pW)
            pW = pW->PtrChc(Pt2dr(aP0Glob-aP0In),Pt2dr(aRatio,aRatio));

         REAL SPds = 0;
         REAL aSTot = 0;
         REAL Dyn = 1.0;
         if (aTShade != "u_int1")
            Dyn = 100;

         bool Done = false;
         if (   (aModeOmbre=="CielVu")
             || ((aModeOmbre=="Mixte") && (aVPdsFiltre[0] > 0.0))
            )
     {
            std::cout << "BEGIN CIEL" << endl;
            Done = true;
            for (int aK=0 ; aK< 2 ; aK++)
            {
               SPds = 0;
               for (int i=0; i<aNbDir; i++)
               {
                  REAL Teta  = (2*PI*i) / aNbDir ;
                  Pt2dr U(cos(Teta),sin(Teta));
                  Pt2di aDir = Pt2di(U * (aNbDir * 4));
                  REAL Pds = (1-aPdsAnis) + aPdsAnis *ElSquare(1.0 - euclid(U,Pt2dr(0,1))/2);
                  if (aK==1)
                     Pds = (Pds*Dyn) / (2*aSTot);
                  Symb_FNum Gr = (1-cos(PI/2-atan(gray_level_shading(aMnt.in()))))
                             *255.0;
                  cout << "Dir " << i << " Sur " << aNbDir <<  " P= " << Pds << endl;
                  SPds  += Pds;
                  if (aK==1)
                  {
                 ELISE_COPY
                 (
                     line_map_rect(aDir,Pt2di(0,0),aSzIn),
                     Min(255*Dyn,aShade.in()+Pds*Gr),
                       aShade.out()
                         // | (pW ? (pW->ogray()<<(aShade.in()/SPds)) : Output::onul())
                         | (pW ? (pW->ogray()<<(Gr)) : Output::onul())
                     );
                  }

               }
               aSTot  = SPds;
            }
            double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[0] : 1.0;
            ELISE_COPY(aShade.all_pts(),aShade.in()*(aMul/SPds),aShade.out());
            SPds = aMul;
            std::cout << "BEGIN CIEL" << endl;
     }
     if (
                      (aModeOmbre=="Local")
                   || ((aModeOmbre=="Mixte") && (aVPdsFiltre[1] > 0.0))
                 )
     {
               std::cout << "BEGIN LOCAL" << endl;
               Done = true;
               Fonc_Num aFonc = aMnt.in_proj();
               Fonc_Num aMoy = aFonc;
               for (int aK=0 ; aK<aNbIterF; aK++)
                   aMoy =    canny_exp_filt(aMoy*aIMasq.in_proj(),aFactExp,aFactExp)
                          /  Max(0.1,canny_exp_filt(aIMasq.in_proj(),aFactExp,aFactExp));

               double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[1] : 1.0;
               ELISE_COPY
               (
              rectangle(Pt2di(0,0),aSzIn),
          Max(0,Min(255, aShade.in() +(128+(aFonc-aMoy)*aDyn)* aMul)),
          aShade.out()
               );
               SPds += aMul;
               std::cout << "END LOCAL" << endl;
     }
     if (
                      (aModeOmbre=="Med")
                   || ((aModeOmbre=="Mixte") && (aVPdsFiltre[3] > 0.0))
                 )
     {
              std::cout << "BEGIN MED" << endl;

               Done = true;
               Fonc_Num aFonc = round_ni(aMnt.in_proj()*aDynMed);
               int aVMax,aVMin;

               ELISE_COPY
               (
                   rectangle(Pt2di(-1,-1),aSzIn+Pt2di(1,1)),
                   aFonc,
                   VMin(aVMin)|VMax(aVMax)
               );

               Fonc_Num aMoy = aFonc-aVMin;

               for (int aK=0 ; aK<aNbIterMed; aK++)
                   aMoy =    rect_median(aMoy,aNbMed,aVMax-aVMin+1);

               aMoy = aMoy + aVMin;

               double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[3] : 1.0;
               ELISE_COPY
               (
              rectangle(Pt2di(0,0),aSzIn),
          Max(0,Min(255, aShade.in() +(128+((aFonc-aMoy)*aDyn)/aDynMed)* aMul)),
          aShade.out()
               );
               SPds += aMul;
              std::cout << "END MED" << endl;
     }
     if (
                      (aModeOmbre=="IgnE")
                   || ((aModeOmbre=="Mixte") && (aVPdsFiltre[2] > 0.0))
                 )
     {
int aCpt=0; aCpt++;
std::cout << "IGN E " << aCpt << " " << aKDec << "\n";
             Done = true;
if (aCpt>0)
{
         Symb_FNum aGrad =  deriche(aMnt.in_proj(),aDericheFact);
             Symb_FNum aGx = (aGrad.v0());
             Symb_FNum aGy = (aGrad.v1());
         Symb_FNum aNG = sqrt(1+Square(aGx)+Square(aGy));

         Symb_FNum aNx (aGx/aNG);
         Symb_FNum aNy (aGy/aNG);
         Symb_FNum aNz (1/aNG);



         Pt2dr  aDirS = Pt2dr::FromPolar(1.0,anAzimut) * Pt2dr(1,0);

         double aSx = aDirS.x * sin(aTetaH);
         double aSy = aDirS.y * sin(aTetaH);
         double aSz = cos(aTetaH);

         Symb_FNum aScal(aNx*aSx+aNy*aSy+aNz*aSz);

std::cout << "AAAAAAAaa" << endl;
             double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[2] : 1.0;
             ELISE_COPY
             (
              rectangle(Pt2di(0,0),aSzIn),
          Max(0,aShade.in() + 255*aScal * aMul),
          aShade.out()
             );
             SPds += aMul;
std::cout << "BBBBbbb" << endl;
}
     }
     if (! Done)
     {
         ELISE_ASSERT(false,"Unknown ModeOmbre");
     }



        Fonc_Num aFoncRes = Max(0,Min(255,aShade.in()/SPds));
        if (WithHypso)
        {
            Fonc_Num  aFIntens = aFoncRes;
            Fonc_Num  aFTeinte = trans(aFIn,aP0In)*aHypsoDyn;
            Fonc_Num  aFSat = 255*aHypsoSat;

            if (aNameCol!="")
            {
                Tiff_Im aFileCol = Tiff_Im::StdConvGen(aDir+aNameCol,-1,true,false);
            Symb_FNum aFNC(trans(rgb_to_its(aFileCol.in()),aP0In));

                if (aModeColor == "IntensShade")
                {
                    aFIntens = aFoncRes;
                    aFTeinte = aFNC.v1();
                    aFSat = aFNC.v2();
                }
                else if (aModeColor == "BackRGB")
                {
                   aFIntens = aIMasq.in()*aFoncRes + (1- aIMasq.in()) * aFNC.v0();
                   aFTeinte = aFNC.v1();
                   aFSat = aFNC.v2() * (1- aIMasq.in());
                }
                else if (aModeColor == "GrayBackRGB")
                {
                   aFIntens = aIMasq.in()*aFoncRes + (1- aIMasq.in()) * aFNC.v0();
                   aFTeinte = aFNC.v1();
                   aFSat = aFNC.v2()*(1-aIMasq.in());
                }
                else
                {
                    ELISE_ASSERT(false,"Unknown mode color");
                }
            }
            aFoncRes = its_to_rgb(Virgule(aFIntens,aFTeinte,aFSat));
            //aFoncRes = its_to_rgb(Virgule(aFoncRes,trans(aFIn,aP0In)*aHypsoDyn,255*aHypsoSat));
        }
/*
    if (WithCol)
    {
            Tiff_Im aFileCol(aNameCol.c_str());
        Symb_FNum aFNC(trans(rgb_to_its(aFileCol.in()),aP0In));
        aFoncRes = its_to_rgb(Virgule(aFoncRes,aFNC.v1(),aFNC.v2()*aHypsoSat));
        // aFoncRes = aFileCol.in();
    }
*/

     // Tiff_Im::Create8BFromFonc(aNameOut,aShade.sz(),aShade.in()/SPds);


    cout << "WithHypso " << WithHypso << " DIM " << aFoncRes.dimf_out() <<  endl;
        Box2di aBoxOut = aDecoup.KthIntervOut(aKDec);
        ELISE_COPY
        (
            rectangle(aBoxOut.P0()-aP0Glob,aBoxOut.P1()-aP0Glob),
        trans(aFoncRes,aP0Glob-aP0In),
        aTifOut.out()
        );
     }

     return EXIT_SUCCESS;

    }
    else return EXIT_SUCCESS;
}
Exemplo n.º 2
0
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;
}
cElNuage3DMaille * cElNuage3DMaille::FromParam
                   (
                       const cXML_ParamNuage3DMaille & aParamOri,
                       const std::string & aDir,
                       const std::string & aMasqSpec,
                       double ExagZ,
                       const cParamModifGeomMTDNuage * aPMG,
                       bool  WithEmptyData
                   )
{
  cXML_ParamNuage3DMaille aParam = aParamOri;
  Box2di aBox(Pt2di(0,0),aParam.NbPixel());
  bool Dequant = false;

  if (aPMG)
  {
       double aScale = aPMG->mScale;
       if (aScale != 1.0)
       {
           std::string aMes = "Scale=" + ToString(aScale);
           cElWarning::ScaleInNuageFromP.AddWarn(aMes,__LINE__,__FILE__);
       }
       Pt2di  aP0 = round_down(aPMG->mBox._p0/aScale);
       Pt2di  aP1 = round_up(aPMG->mBox._p1/aScale);

       aBox = Inf(aBox,Box2di(aP0,aP1));

       aParam.NbPixel() = aBox.sz();

       ElAffin2D aAfM2C = Xml2EL(aParam.Orientation().OrIntImaM2C());
       
        aAfM2C   =   ElAffin2D::trans(-Pt2dr(aBox._p0)) * aAfM2C;
       aParam.Orientation().OrIntImaM2C().SetVal(El2Xml(aAfM2C));
       Dequant = aPMG->mDequant;
  }


  std::string aMasq =  aDir+aParam.Image_Profondeur().Val().Masq();
  if (aMasqSpec!="")
         aMasq = aMasqSpec;

  GenIm::type_el aTypeEl = GenIm::real4;
  Fonc_Num aFMasq = 0;
  Fonc_Num aFProf = 1;
  if (! WithEmptyData)
  {
     aFMasq =   trans(Tiff_Im::BasicConvStd(aMasq).in(0),aBox._p0);
     Tiff_Im aTP = Tiff_Im::BasicConvStd(aDir+aParam.Image_Profondeur().Val().Image());
     aFProf =  trans(aTP.in_proj()*ExagZ,aBox._p0);
     aTypeEl = aTP.type_el();
  }


   if (aParam.Image_Profondeur().IsInit())
   {
      bool aFaiscClassik =  (   (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauIm1PrCh_Px1D)
                             || (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauIm1PrCh_Px2D)
                             || (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTEuclid)
                             || (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauPrChSpherik)
                            );

      bool aProfIsZ =  (      (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauIm1ZTerrain_Px1D)
                             || (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauIm1ZTerrain_Px2D)
                         );


       if (aFaiscClassik || aProfIsZ)
       {
           switch (aTypeEl)
           {
               case GenIm::int2 :
                    if (Dequant) 
                        return new cElN3D_EpipGen<float,double>(aDir,aParam,aFMasq,aFProf,aProfIsZ,WithEmptyData,true);
                    else
                        return new cElN3D_EpipGen<INT2,INT>(aDir,aParam,aFMasq,aFProf,aProfIsZ,WithEmptyData,false);
               break;
               case GenIm::real4 :
                    return new cElN3D_EpipGen<float,double>(aDir,aParam,aFMasq,aFProf,aProfIsZ,WithEmptyData,false);
               break;

               default :
                   std::cout << "NAME " << aDir+aParam.Image_Profondeur().Val().Image() << "\n";
                   ELISE_ASSERT(false,"Type Image non gere dans cElNuage3DMaille::FromParam");
               break;
           }
       }
   }

   ELISE_ASSERT(false,"cElNuage3DMaille::FromParam");
   return 0;
}