Exemple #1
0
void bench_least_square()
{
   BenchcSysQuadCreuse();
   bench_triviale_opt_sous_contrainte();
   for (INT k=0 ; k<100 ; k++)
   {
       bench_opt_contrainte();
   }

   bool Ok;
   SystLinSurResolu mSys(1,1);
   Im1D_REAL8  aFlin(1,"2.0");
   mSys.PushEquation(aFlin,3.0,1.0);
   mSys.L2Solve(&Ok); 
   BENCH_ASSERT(Ok);


    for (INT k=0 ; k< 200 ; k++)
    {
       bool SomForm = (k&1 ==0);
       INT aNbVar = 2 + (INT)(10 * NRrandom3());
       INT aNbEq = 2+aNbVar * (1 + (INT)(10 * NRrandom3()));
       if (SomForm)
	  aNbEq += 10;
       cBenchLeastSquare aBLS(aNbVar,aNbEq,SomForm);
       aBLS.TestFoncNVar();
       cout << k << "\n";
    }
}
void TestOriBundle()
{
  
      for (int aT=0 ; aT<10000 ; aT++)
      {
             Pt3dr aPA1 = GrP3dRand(0,3);
             Pt3dr aPA2 = GrP3dRand(1,3);
             Pt3dr aPA3 = GrP3dRand(2,3);

             Pt3dr aBase = Pt3dr(0,-1,0) + P3dRand() * 0.1;
             double aT12 = 0.1*NRrandom3();
             double aT13 = 0.1*NRrandom3();
             double aT23 = 0.1*NRrandom3();
             ElMatrix<double> aRot =  ElMatrix<double>::Rotation(aT12,aT13,aT23);


             std::cout << "TETAIN " << aT12 << " " << aT13 << " " << aT23 << "\n\n";

             Pt3dr aPB1 = PInBCoord(aBase,aRot,aPA1);
             Pt3dr aPB2 = PInBCoord(aBase,aRot,aPA2);
             Pt3dr aPB3 = PInBCoord(aBase,aRot,aPA3);

              
/*
          Pt3dr aP1 =  Pt3dr(NRrandom3(),NRrandom3(),10+NRrandom3());
          Pt3dr aP1 =  Pt3dr(NRrandom3(),NRrandom3(),10+NRrandom3());
*/
            std::list<ElMatrix<double> > aLR = OriFromBundle(aBase,aPA1,aPA2,aPA3,aPB1,aPB2,aPB3,30000,10,10);
            std::cout << "================== " << aT << "\n"; getchar();
      }
}
Exemple #3
0
void Optim_L1FormLin::BenchRand(INT NbVar,INT NbForm,INT NbTest,bool Comb)
{
   Optim_L1FormLin OLF = RandOLF(NbVar,NbForm);

   ElMatrix<REAL>  Sol = OLF.Solve();
   REAL ScS = OLF.score(Sol);


   for (;NbTest>=0; NbTest --)
   {
      REAL eps = std::max(1e-3,0.2*ElSquare(NRrandom3()));
      ElMatrix<REAL>  D = Sol;
      for (INT k=0 ; k<NbVar ; k++)
          D(0,k) += eps * (NRrandom3()-0.5);

       REAL sd = OLF.score(D);

       if (ScS> sd) 
       {
          if (Comb)
              OLF.BenchCombin(ScS);
          cout << ScS << " " << sd 
               << " " << ((ScS-sd)/eps) 
               << " " << eps << "\n";
          BENCH_ASSERT(std::abs((ScS-sd)/eps) < 1e-7);
       }
   }
}
Exemple #4
0
void BenchGaussjPrec(INT N,INT M)
{
    GaussjPrec  GP(N,M);

    for (INT y=0; y<N ; y++)
    {
        for (INT x=0; x<N ; x++)
            GP.M()(x,y) = NRrandom3()-0.5 + 2 * N * (x==y);
		{
        for (INT x=0; x<M ; x++)
            GP.b()(x,y) = NRrandom3();
		}
    }

    bool OK = GP.init_rec();
    BENCH_ASSERT(OK);
	{
    for (INT y=0; y<N ; y++)
        for (INT x=0; x<N ; x++)
            GP.M()(x,y) +=  (NRrandom3()-0.5) * N * 5e-2;
	}

    for (INT k=0 ; k<10 ; k++)
    {
      GP.amelior_sol();
    }
    BENCH_ASSERT(GP.ecart()<epsilon);
}
Exemple #5
0
void BenchcDbleGrid
     (
         Pt2dr aP0In,Pt2dr aP1In,
         REAL               aStepDir,
         ElDistortion22_Gen & aDist
     )
{
     //cDbleGrid aDGr(aP0In,aP1In,aStepDir,aDist);
     Pt2dr stepDir2(aStepDir,aStepDir);                // __NEW
     cDbleGrid aDGr(false,aP0In,aP1In,stepDir2,aDist); // __NEW

     for (REAL aX = aP0In.x ; aX<aP1In.x ; aX += aStepDir)
         for (REAL aY = aP0In.y ; aY<aP1In.y ; aY += aStepDir)
         {
             REAL x = aX + NRrandom3() * aStepDir;
             SetInRange(aP0In.x,x,aP1In.x);
             REAL y = aY + NRrandom3() * aStepDir;
             SetInRange(aP0In.y,y,aP1In.y);

	     Pt2dr aP(x,y);
	     Pt2dr aQ0 = aDist.Direct(aP);
	     Pt2dr aQ1 = aDGr.Direct(aP);
	     Pt2dr aR0 = aDist.Inverse(aQ0);
	     Pt2dr aR1 = aDist.Inverse(aQ1);

	     REAL aDQ = euclid(aQ0,aQ1);
	     REAL aDR = euclid(aR0,aP) +  euclid(aR1,aP);
	     aDQ /= ElSquare(aStepDir);
	     aDR /= ElSquare(aStepDir);
	     BENCH_ASSERT(aDQ<0.1);
	     BENCH_ASSERT(aDR<0.1);
         }
}
Exemple #6
0
void bench_seg_mean_square()
{
    for (int i = 0; i<100 ; i++)
    {
        INT nx = (INT) (10 +NRrandom3()*20);
        INT ny = nx  -5;

        Pt2dr  tr = Pt2dr((NRrandom3()-0.5)*1e4,(NRrandom3()-0.5)*1e4);
        Pt2dr  rot = Pt2dr::FromPolar(1.0,NRrandom3() *100);

        RMat_Inertie m;
        for (int x= -nx; x <= nx ; x++)
            for (int y= -ny; y <= ny ; y++)
            {
                 Pt2dr Z = tr+rot*Pt2dr(x,y);
                 m.add_pt_en_place(Z.x,Z.y);
            }

        Seg2d s = seg_mean_square(m,100.0);
        Pt2dr cdg = s.p0();
        Pt2dr all = (s.p1()-s.p0())/ 100.0;

        BENCH_ASSERT
        (
                (euclid(cdg-tr) < BIG_epsilon)
             && (std::abs(all^rot)   < BIG_epsilon)
        );

        // BENCH_ASSERT(Abs(d0 -d1) < BIG_epsilon);
   }
}
cElHomographie cElHomographie::RansacInitH(const ElPackHomologue & aPack,int aNbRansac,int aNbMaxPts)
{
   if ((aPack.size()<10)  || (aNbMaxPts<4))
      return cElHomographie(aPack,false);
   

   cRandNParmiQ aRand(aNbMaxPts,aPack.size());
   std::vector<ElCplePtsHomologues> aVCH;

   for (ElPackHomologue::tCstIter itH=aPack.begin() ; itH!=aPack.end() ; itH++)
   {
      if (aRand.GetNext())
      {
          aVCH.push_back(itH->ToCple());
      }
   }

   double anEcMin = 1e30;
   cElHomographie aHMin = cElHomographie::Id();

   while (aNbRansac)
   {
       int aK1 = NRrandom3(aVCH.size());
       int aK2 = NRrandom3(aVCH.size());
       int aK3 = NRrandom3(aVCH.size());
       int aK4 = NRrandom3(aVCH.size());
       if ( 
               (aK1!=aK2) && (aK1!=aK3) &&  (aK1!=aK4)
            && (aK2!=aK3) && (aK2!=aK4)
            && (aK3!=aK4)
          )
        {
            aNbRansac--;
            ElPackHomologue aP4;
            aP4.Cple_Add(aVCH[aK1]);
            aP4.Cple_Add(aVCH[aK2]);
            aP4.Cple_Add(aVCH[aK3]);
            aP4.Cple_Add(aVCH[aK4]);

            cElHomographie aSol = cElHomographie(aP4,true);
            double anEcart = 0;
            for (int aKP=0 ; aKP<int(aVCH.size()) ;  aKP++)
            {
                anEcart += euclid(aSol.Direct(aVCH[aKP].P1()),aVCH[aKP].P2());
            }
            anEcart /= aVCH.size();
            if (anEcart<anEcMin)
            {
                anEcMin = anEcart;
                aHMin = aSol;
            }
        }
   }
   std::cout << "ECART H " << anEcMin << "\n";
   return aHMin;
 
}
static Pt3dr GrP3dRand(int aK,int aN)
{
   return Pt3dr::TyFromSpherique
          (
                10.0 + NRrandom3(),
                ((aK*2*PI) + NRrandom3() *0.5 ) / aN,
                0.5 + NRrandom3() * 0.1
          );
}
Exemple #9
0
BenchDMR::BenchDMR(INT deg) :
    _pol  ((char *)0,deg),
    _dpol ()
{
    for (INT k=0 ; k< deg; k++)
        _pol[k] = (NRrandom3()-0.5)*10;
    _pol[deg] = NRrandom3()+0.5;

    _dpol = _pol.deriv();
}
// Calcul les vecteur qui sont |_  dans un plan contenant la base
void cMEPCoCentrik::ComputePlanBase(const ElMatrix<REAL>  & aMat)
{
    Pt3di aRouge(255,0,0);
    Pt3di aVert(0,255,0);

    Pt3di aGrayFonc(64,64,64);
    Pt3di aGrayClair(180,180,180);
    double aMulP = 1.1;

    std::vector<Pt3dr> aVpt;
    for (int aKP =0 ; aKP< int(mVP1.size()) ; aKP++)
    {
         Pt3dr aQ1 = vunit(PZ1(mVP1[aKP]));
         Pt3dr aQ2 = aMat * vunit(PZ1(mVP2[aKP]));
         Pt3dr anOB = aQ1^aQ2;
         if (euclid(anOB) != 0)
         {
            anOB = vunit(anOB);
            if (mDoPly)
            {
                 mColPly.push_back(aRouge);
                 mPtsPly.push_back(anOB);


                 mColPly.push_back(aGrayFonc);
                 mPtsPly.push_back(aQ1*aMulP);
                 mColPly.push_back(aGrayClair);
                 mPtsPly.push_back(aQ2*aMulP);
            } 
            mVPlanBase.push_back(anOB);
          }
    }


    if (mDoPly)
    {
         for (int aK=0 ; aK<10000  ; aK++)
         {
              int aKA = NRrandom3(mVPlanBase.size());
              int aKB = NRrandom3(mVPlanBase.size());

             
              Pt3dr aBase = mVPlanBase[aKA] ^  mVPlanBase[aKB];
              if (euclid (aBase)>1e-6)
              {
                  mColPly.push_back(aVert);
                  mPtsPly.push_back(vunit(aBase));
              }

         }
    }
}
void Bench_Rank()
{
    std::cout << "Begin Bench Rank \n";
   
    for (int aTime=0 ; aTime<10000; aTime++)
    {
        int aNb = round_ni(1 + ElSquare(10*NRrandom3()));
        std::vector<double> aV;
        for (int aK=0 ; aK<aNb ; aK++)
           aV.push_back(NRrandC());

        for (int aK=0 ; aK < aNb ; aK++)
        {
            for (int aK2=0 ; aK2 < 3 ; aK2++)
                if (NRrandom3()<0.2)
                   aV.push_back(aV[aK]);

            for (int aK2=0 ; aK2 < int(aV.size()) ; aK2++)
                if (NRrandom3()<0.02)
                   aV[aK2] = aV[aK];
         }

        aNb = aV.size();

        std::vector<double>  aV2 = aV;
        std::vector<double>  aV3 = aV;

         int aRnk = NRrandom3(aNb);

         double aVK =KthVal(VData(aV),aNb,aRnk);

         std::sort(aV2.begin(),aV2.end());
         double aVK2 = aV2[aRnk];

         // std::cout << "Bench Rank " << aVK-aVK2 << "\n";
         ELISE_ASSERT(ElAbs(aVK-aVK2)<1e-10,"Bench rnk");

/*
   Ne marche pas : la valeur RrnK est n'importe ou

         SplitArrounKthValue(VData(aV3),aNb,aRnk);
         double aVK3 = aV3[aRnk];
         std::cout << "Bench Rank " << aVK-aVK2 << " " << aVK-aVK3<< "\n";
         ELISE_ASSERT(ElAbs(aVK-aVK2)<1e-10,"Bench rnk");
         ELISE_ASSERT(ElAbs(aVK-aVK3)<1e-10,"Bench rnk");
*/

    }
    std::cout << "OK BENCH RANK \n";
}
Exemple #12
0
void bench_dist_InerMat_seg_droite()
{
    for (int i = 0; i<100 ; i++)
    {
        Pt2dr p1  = Pt2dr((NRrandom3()-0.5)*1e4,(NRrandom3()-0.5)*1e4);
        Pt2dr p2 = p1;

        while (euclid(p1-p2) < 1e2)
              p2  = Pt2dr((NRrandom3()-0.5)*1e4,(NRrandom3()-0.5)*1e4);

        SegComp s(p1,p2);
        int nb = (int)(50 * NRrandom3());
        REAL d0 = 0.0;
        RMat_Inertie m;
        for (int j =0; j<nb ; j++)
        {
             Pt2dr q  = Pt2dr((NRrandom3()-0.5)*1e4,(NRrandom3()-0.5)*1e4);
             REAL pds = NRrandom3();
             m = m.plus_cple(q.x,q.y,pds);
             d0 += pds * s.square_dist_droite(q);
        }
        REAL d1 = square_dist_droite(s,m);

        BENCH_ASSERT(std::abs(d0 -d1) < BIG_epsilon);
    }
}
Exemple #13
0
Optim_L1FormLin Optim_L1FormLin::RandOLF(INT NbVar,INT NbForm,INT Nb0)
{
   ElMatrix<REAL> M(NbVar+1,NbForm);
   for (INT l=0 ; l < NbForm ; l++)
   {
       for (INT c=0 ; c < NbVar ; c++ )
           M(c,l) = NRrandom3()-0.5;
       M(NbVar,l) = 50*(NRrandom3()-0.5);
       if (l < Nb0)
          M(NbVar,l) = 0;
   }

   return Optim_L1FormLin(M);
}
Exemple #14
0
void bench_inter_Hor()
{

   for (INT k=0; k<5000 ; k++)
   {
       Pt2dr p0 = random_pt();
       Pt2dr p1 = random_pt();
       if (std::abs(p0.y-p1.y)<1e-2)
          p1.y += 1;
       SegComp aSp(p0,p1);

       REAL anY =  NRrandom3() *100;
       Pt2dr q0 (0,anY);
       Pt2dr q1 (1,anY);

       SegComp aSq(q0,q1);

       bool OkInter;
       Pt2dr aInter0 = aSp.inter(aSq,OkInter);
       Pt2dr aInter2(aSp.AbsiceInterDroiteHoriz(anY),anY);

       REAL DH = euclid(aInter0,aInter2) ;
       BENCH_ASSERT(DH<BIG_epsilon);
   }
}
void BenchSort3()
{
   for (int aK=0 ; aK<1000000 ; aK++)
   {
       int Tab[3];
       for (int aK=0 ; aK<3 ; aK++)
           Tab[aK] = NRrandom3(4);

       int aRnk[3]; 
       Rank3(aRnk,Tab[0],Tab[1],Tab[2]);
       int Sort[3];
      
       for (int aK=0 ; aK<3 ; aK++)
           Sort[aRnk[aK]] = Tab[aK];
       ELISE_ASSERT(Sort[0] <= Sort[1],"BenchSort3");
       ELISE_ASSERT(Sort[1] <= Sort[2],"BenchSort3");

       cTplTriplet<int> aTT(Tab[0],Tab[1],Tab[2]);
       ELISE_ASSERT(aTT.mV0 <= aTT.mV1,"BenchSort3");
       ELISE_ASSERT(aTT.mV1 <= aTT.mV2,"BenchSort3");

       cTplTripletByRef<int> aPtrTT(Tab[0],Tab[1],Tab[2]);
       ELISE_ASSERT(*aPtrTT.mV0 <= *aPtrTT.mV1,"BenchSort3");
       ELISE_ASSERT(*aPtrTT.mV1 <= *aPtrTT.mV2,"BenchSort3");
   }
   std::cout << "DONE BenchSort3\n";
}
Exemple #16
0
REAL test_cox(INT tx,INT ty,INT tz)
{
   ElTimer aT;
   cInterfaceCoxAlgo * pSCA =     cInterfaceCoxAlgo::StdNewOne
              (
                  Pt2di(tx,ty),
                  0,
                  tz,
                  2
              );
   for (INT x=0; x<tx ; x++)
       for (INT y=0; y<ty ; y++)
           for (INT z=0; z<tz ; z++)
                  pSCA->SetCost(Pt3di(x,y,z),INT(100*NRrandom3()));
    pSCA->PccMaxFlow();

    REAL  aRes =  aT.uval();
    cout 
	    << "tCox : "
            << aRes  << " ; "
	    << tx << " " 
	    << ty << " " 
	    << tz << " " 
	    << (aRes *1e4 / (tx*ty*tz)) << "\n";
    delete pSCA;
    return aRes;
}
Exemple #17
0
cBenchLeastSquare::cBenchLeastSquare
(
    INT aNbVar,
    INT aNbEq,
    bool SomForm
)  :
   FoncNVarDer<REAL> (aNbVar),
   mNbVar (aNbVar),
   mNbEq  (aNbEq),
   mSys (aNbVar,aNbEq),
   mSol (1),
   mSolEps (aNbVar),  
   mTmpVF  (aNbVar),
   mDataTmpVF (mTmpVF.data())
{
   Im1D_REAL8 aFLin(aNbVar);
   REAL8* aDLin = aFLin.data();

   for (INT iEq = 0 ; iEq < aNbEq ; iEq++)
   {
       for (INT iVar=0 ; iVar<aNbVar ; iVar++)
       {
	    if (SomForm)
	    {
		if (iEq<2*aNbVar)
	           aDLin[iVar] = (iVar==(iEq%mNbVar));
		else
	           aDLin[iVar] = NRrandC() * (NRrandC()>0);
	    }
	    else
	       aDLin[iVar] = NRrandC();
       }
       mSys.PushEquation
       (
           aFLin,
	   NRrandC() * 1e3,
	   0.1 + NRrandom3()
       );
   }

   bool Ok;
   mSol = mSys.L2Solve(&Ok);
   mResidu = mSys.L2SomResiduPond(mSol);
   BENCH_ASSERT(Ok);

   for (INT k=0 ; k< 200 ; k++)
   {
	ELISE_COPY
	(
	    mSolEps.all_pts(),
	    mSol.in() + (frandr()-0.5),
	    mSolEps.out()
	);
	REAL ResEps =  mSys.L2SomResiduPond(mSolEps);
	 // cout << (ResEps-mResidu) << " " << mResidu << "\n";
	BENCH_ASSERT(ResEps>mResidu);
   }
   // getchar();
}
Exemple #18
0
void bench_delaunay()
{
    Pt2di sz (950,950);

    Disc_Pal       Pdisc  = Disc_Pal::P8COL();

    Elise_Set_Of_Palette SOP(NewLElPal(Pdisc));
    Video_Display Ecr((char *) NULL);
    Ecr.load(SOP);                         
    Video_Win   W  (Ecr,SOP,Pt2di(50,50),sz);  


    for (INT nb = 100; nb < 500 ; nb +=50)
    {

       std::list<PtDelTest> L;
       ElFilo<PtDelTest> Pts;

       for (INT k= 0; k< nb; k++)
       {
           PtDelTest pt
                     (
                             (INT)(  10 + (sz.x -20) * NRrandom3()),
                             (INT)(  10 + (sz.y -20) * NRrandom3())
                     );
            // Pts.pushlast(pt);
            L.push_back(pt);
            //W.draw_circle_loc(pt.pt(),4,Pdisc(P8COL::red));
            W.draw_circle_loc(Pt2dr(pt.pt()),4,Pdisc(P8COL::red)); // __NEW
       }
       DelTestAct Act(W);
       Delaunay_Mediatrice 
       (
             L.begin(),
             L.end(),
             Pt_of_DPT,
             Act,
	     200.0,
            (PtDelTest *) 0
       );

       // W.clik_in();
       W.clear();
    }
}
void Test_Arrondi_LG()
{
    Pt2di aSz(100,100);
    double aVTest = 117;

    Im2D_REAL16 anIm(aSz.x,aSz.y);
    TIm2D<REAL16,REAL16> aTIm(anIm);

    ELISE_COPY(anIm.all_pts(),aVTest,anIm.out());

    while (1)
    {
         Pt2dr aP0 = Pt2dr(10,10) + Pt2dr(NRrandom3(),NRrandom3()) *50.123456701765;
         double aV0 = aTIm.getr(aP0);
         double aV1 = Reechantillonnage::biline(anIm.data(),aSz.x,aSz.y,aP0);

         std::cout << " TEST " << (aV0-aVTest) * 1e50 << " " << (aV1-aVTest) * 1e50  << " " << aP0 << "\n";
         getchar();
    }
}
Exemple #20
0
bool cRandNParmiQ::GetNext()
{
   ELISE_ASSERT(mQ!=0,"cRandNParmiQ::GetNext");
   bool aRes =(NRrandom3() * mQ) <= mN;
    mQ--;
    if (aRes)
       mN--;

   return aRes;

}
Exemple #21
0
template <class Type> Bench_PackB_IM<Type>::Bench_PackB_IM
(
	Pt2di SZ,
	Fonc_Num f
) :
	sz     (SZ),
	im1    (ImInit(sz,f)),
        mPer   (16 * (INT)(2+(NRrandom3()*20))),
	pck    (sz.x,sz.y,im1.in(),mPer)
{
	verif();
}
Exemple #22
0
std::vector<int> RandPermut(int aN)
{
    std::vector<Pt2dr> aV;
    for (int aK=0 ; aK<aN ; aK++)
       aV.push_back(Pt2dr(NRrandom3(),aK));

   std::sort(aV.begin(),aV.end());
   std::vector<int> aRes;
   for (int aK=0 ; aK<aN ; aK++)
       aRes.push_back(round_ni(aV[aK].y));

  return aRes;
}
Exemple #23
0
void bench_opt_contrainte()
{ 
     INT NbVar = round_ni(1 + 10 * NRrandom3());
     L2SysSurResol aSys1(NbVar);
     L2SysSurResol aSys2(NbVar);

     INT NbContr = round_ni(NbVar*NRrandom3());
     INT NbEq =  round_ni(NbVar + 2 + 10 * NRrandom3());

     for (INT fois=0 ; fois < 3 ; fois++)
     {
         for (INT k=0 ;k<NbContr +NbEq ; k++)
         {
             Im1D_REAL8 C(NbVar);
	     ELISE_COPY(C.all_pts(), frandr(),C.out());
             REAL aVal = NRrandom3();
	     if (k<NbContr)
             {
	         aSys1.GSSR_AddContrainte(C.data(),aVal);
	         aSys2.GSSR_AddNewEquation(1e9,C.data(),aVal);
             }
	     else
             {
	         aSys1.GSSR_AddNewEquation(1,C.data(),aVal);
	         aSys2.GSSR_AddNewEquation(1,C.data(),aVal);
             }
         }

	 Im1D_REAL8 Sol1 = aSys1.GSSR_Solve(0);
	 Im1D_REAL8 Sol2 = aSys2.GSSR_Solve(0);

	 REAL Dif;
	 ELISE_COPY(Sol1.all_pts(),Abs(Sol1.in()-Sol2.in()),VMax(Dif));
         BENCH_ASSERT(Dif<GIGANTESQUE_epsilon);
         aSys1.GSSR_Reset();
         aSys2.GSSR_Reset();
     }
    
}
Exemple #24
0
void bench_graphe_grille()
{
    bench_graphe_grille(SZ_PCC,1,true);

    bench_graphe_grille(Pt2di(3,3),100);
    bench_graphe_grille(Pt2di(9,7));
    bench_graphe_grille(Pt2di(12,21));

    for (INT k = 0; k<50 ; k++)
        bench_graphe_grille
        (
              Pt2di(3,3)
	      +Pt2di
               (
		  Pt2dr
		  (
                     NRrandom3()*10.0,
                     NRrandom3()*10.0
		  )
	       )
	);
}
ElMatrix<REAL> GlobMepRelCocentrique(double & anEcartMin,const ElPackHomologue & aPack, int aNbRansac,int aNbMaxPts) 
{
   aNbMaxPts = ElMin(aNbMaxPts,aPack.size());

   std::vector<Pt3dr> aVDir1;
   std::vector<Pt3dr> aVDir2;

   cRandNParmiQ aRand(aNbMaxPts,aPack.size());

   for (ElPackHomologue::tCstIter itH=aPack.begin() ; itH!=aPack.end() ; itH++)
   {
      if (aRand.GetNext())
      {
          aVDir1.push_back(vunit(PZ1(itH->P1())));
          aVDir2.push_back(vunit(PZ1(itH->P2())));
      }
   }

   ElMatrix<REAL> aRes(3,3);
   anEcartMin = 1e60;

   while (aNbRansac)
   {
       int aKA = NRrandom3(aVDir1.size());
       int aKB = NRrandom3(aVDir2.size());
       if (aKA!=aKB)
       {
          aNbRansac--;
          ElMatrix<REAL> aMat = ComplemRotation(aVDir1[aKA],aVDir1[aKB],aVDir2[aKA],aVDir2[aKB]);
          double anEc = SomEcartDist(aMat,aVDir1,aVDir2);
          if (anEc<anEcartMin)
          {
              anEcartMin = anEc;
              aRes = aMat;
          }
       }
   }
   return aRes;
}
Exemple #26
0
cHomogFormelle::cHomogFormelle
(
     const cElHomographie & anHomog,
     cSetEqFormelles &         aSet,
     eModeContrHom                   aModeContr
)  :
     cElemEqFormelle(aSet,false),
     mHomInit     (anHomog),
     mCurHom      (anHomog),
     mCX          (mCurHom.HX(),aSet,false),
     mCY          (mCurHom.HY(),aSet,false),
     mCZ          (mCurHom.HZ(),aSet,true),
     mModeContr   (aModeContr),
     mHomFTol     (cContrainteEQF::theContrStricte)
{
   CloseEEF();

   for (int aK=0 ; aK<0 ; aK++)
   {
       cElComposHomographie aHX = mHomInit.HX();
       cElComposHomographie aHY = mHomInit.HY();
       cElComposHomographie aHZ = mHomInit.HZ();

        Pt2dr aP(NRrandom3()*100,NRrandom3()*100);
        Pt2dr aQ =  mHomInit.Direct(aP);

        Pt2dr aR = InvHom(
                         aHX.CoeffX(), aHX.CoeffY(), aHX.Coeff1(),
                         aHY.CoeffX(), aHY.CoeffY(), aHY.Coeff1(),
                         aHZ.CoeffX(), aHZ.CoeffY(),
                         aQ.x,aQ.y
                   );
        double aDist =  euclid(aP,aR);
        std::cout << "TESINV HOM " << aP << aR << aDist  << " B=" <<  aHX.CoeffY() << "\n";
        ELISE_ASSERT(aDist<1e-5,"TESINV HOM ");
   }

}
Exemple #27
0
void cElRanGen::InitOfTime(int aNb) //  aNb=1000
{
// std::cout << "cElRanGen::InitOfTime::AAAAAAlllll\n"; getchar();


   double aT = ElTimeOfDay();
   aT = aT -round_down(aT);
   aNb  = round_ni(aT * aNb);
   std::cout << "cElRanGen::InitOfTime, GERM = " << aNb << "\n";
   while (aNb>=0)
   {
        NRrandom3();
        aNb--;
   }
}
void cOneRotPowelOptimize::InitPts()
{
    for 
    (
       std::list<cPowPointLiaisons>::const_iterator itP=mOP->PowPointLiaisons().begin();
       itP!=mOP->PowPointLiaisons().end();
       itP++
    )
    {
        std::list<cPoseCam *> aLCam = mAppli->ListCamInitAvecPtCom(itP->Id(),mCam);
    
    // Pour l'insntant la selec se fait par simple tirage aleatoire
        int aNbPtsTot = 0;
        for (std::list<cPoseCam *>::iterator itC=aLCam.begin();itC!=aLCam.end();itC++)
        {

             ElPackHomologue aPack ;
             mAppli->InitPack(itP->Id(),aPack,mCam->Name(),(*itC)->Name());
             aNbPtsTot += aPack.size();
        }

        int aNbCible = itP->NbTot();
        for (std::list<cPoseCam *>::iterator itC=aLCam.begin();itC!=aLCam.end();itC++)
        {
             mLIais.push_back(cLiaisORPO(*itP,mCam,*itC));
             ElPackHomologue aPack ;
             mAppli->InitPackPhgrm
             (
                  itP->Id(),aPack,
                  mCam->Name(),&mCam->Calib()->CamInit(),
                  (*itC)->Name(),&(*itC)->Calib()->CamInit()
             );
             for (ElPackHomologue::iterator itPt=aPack.begin(); itPt!=aPack.end() ; itPt++)
             {
                 if (NRrandom3() < double(aNbCible)/aNbPtsTot)
                 {
                     mLIais.back().Pack().Cple_Add(itPt->ToCple());
                     mNbMes++;
                     aNbCible--;
                 }
                 aNbPtsTot--;
             }
        }
    }
}
Exemple #29
0
void bench_im_rle()
{
     for (INT k=0 ; k < 20 ; k++)
     {
          All_Memo_counter MC_INIT;
          stow_memory_counter(MC_INIT);
          bench_im_rle
          (
                Pt2di(150,150) + Pt2di(Pt2dr(50*NRrandom3(),50*NRrandom3())),
                INT(2+6*NRrandom3()),
                Pt2di(Pt2dr(4+20*NRrandom3(),4+20*NRrandom3())),
                (INT)(1+4 * NRrandom3())
          );
          verif_memory_state(MC_INIT);      
     }
     cout << "END Bench RLE \n";
}
Exemple #30
0
void bench_pcc(TGr41 & gr, TSom41 *** TABS,Pt2di sz)
{
     TPcc41                  PCC;
     TPtSubGr41              GrAll;
     TSubGr41_xeg            GrXeq;
     TSubGr41_xy2            Gr_xy2;
     TEmpGr41                GrEmpty;


     for (int k =0; k < 300  ; k ++)
     {
          INT x1 = ((INT)(NRrandom3() * 100)) % sz.x;
          INT y1 = ((INT)(NRrandom3() * 100)) % sz.y;
          INT x2 = (x1+13*k)%sz.x;
          INT y2 = (y1+3*k)%sz.y;
          Pt2di p1 (x1,y1);
          Pt2di p2 (x2,y2);
          TSom41 & s1  = *(TABS[y1][x1]);
          TSom41 & s2  = *(TABS[y2][x2]);
          
          //TSom41 * res = PCC.pcc(s1,s2,GrAll);
          TSom41 * res = PCC.pcc(s1,s2,GrAll,eModePCC_Somme); // __NEW
          BENCH_ASSERT(PCC.pds(s2)==dist4(p1-p2));

          ElFilo<TSom41 *> f41;
          PCC.chemin(f41,s2);
          BENCH_ASSERT(PCC.pds(s2)==f41.nb()-1);
          for (INT S=1 ; S<f41.nb() ; S++)
               BENCH_ASSERT(gr.arc_s1s2(*f41[S-1],*f41[S]));


          //res = PCC.pcc(s1,s2,GrXeq);
          res = PCC.pcc(s1,s2,GrXeq,eModePCC_Somme); // __NEW
          BENCH_ASSERT((res==&s2) == (x1==x2));

          //res = PCC.pcc(s1,GrEmpty,GrXeq);
          res = PCC.pcc(s1,GrEmpty,GrXeq,eModePCC_Somme); // __NEW
          BENCH_ASSERT(res==0);
          for 
          (
                TSIt41 sit = gr.begin(GrAll);
                sit.go_on();
                sit ++
          )
          {
              TSom41 & s = (*sit);
              BENCH_ASSERT(PCC.reached(s) == (s.attr()._pt.x == x1));
              if (PCC.reached(s))
              {
                  INT y = s.attr()._pt.y;
                  INT x = s.attr()._pt.x;
                  BENCH_ASSERT(PCC.pds(s) == std::abs(y-y1));
                  if (y == y1)
                     BENCH_ASSERT(PCC.pere(s) == 0);
                  else if (y> y1)
                     BENCH_ASSERT(PCC.pere(s) == TABS[y-1][x]);
                  else
                     BENCH_ASSERT(PCC.pere(s) == TABS[y+1][x]);
              }
          }

          //res = PCC.pcc(s1,s2,Gr_xy2);
          res = PCC.pcc(s1,s2,Gr_xy2,eModePCC_Somme); // __NEW
          BENCH_ASSERT
          (
                (res==&s2) 
            ==  (
                       ((x1%2==0) || (y1%2==0))
                   &&  ((x2%2==0) || (y2%2==0))
                )
          );
          if (res==&s2)
             BENCH_ASSERT(PCC.pds(s2)==dist4(p1-p2));
     }
}