Exemple #1
0
void BenchcSysQuadCreuse
     (
         INT aNbVar,
         INT aNbEq,
         cNameSpaceEqF::eTypeSysResol aType
      )
{
    bool isFixe = NRrandom3() < 0.5;
    //cFormQuadCreuse aSCr(aNbVar,isFixe);
    cFormQuadCreuse aSCr( aNbVar, cElMatCreuseGen::StdNewOne( aNbVar, aNbVar, isFixe ) ); // __NEW
    //aSCr.SetEpsB(1e-10);
    cGenSysSurResol & aS1 = aSCr;

    L2SysSurResol   aSPl(aNbVar);
    cGenSysSurResol & aS2 = aSPl;

    bool SysFix = (aType == cNameSpaceEqF::eSysCreuxFixe);
    cSetEqFormelles aSet2(aType); // ,1e-10);
    cEqFormelleLineaire * anEq2_1 = aSet2.NewEqLin(1,aNbVar);
    cEqFormelleLineaire * anEq2_3 = aSet2.NewEqLin(3,aNbVar);


    Im1D_REAL8   aIm2(aNbVar,0.0);
    for (INT aK=0; aK<aNbVar; aK++)
        aSet2.Alloc().NewInc(aIm2.data()+aK);
    aSet2.SetClosed();
    //if (aType !=  cNameSpaceEqF::eSysPlein)
    //   aSet2.FQC()->SetEpsB(1e-10);


    Im1D_REAL8 aF(aNbVar,0.0);

    for (INT aNbTest=0 ; aNbTest<3 ; aNbTest++)
    {
        for (INT aX =0 ; aX<aNbVar; aX++)
        {
	    std::vector<INT> V;
	    V.push_back(aX);

            REAL aPds = 0.5;
            double C1 = 1;
            aF.data()[aX] = C1;
            REAL aCste =  NRrandom3();
	    if (isFixe)
	    {
		if (aX==0)
	           aSCr.SetOffsets(V);
                //aS1.GSSR_AddNewEquation_Indexe(V,aPds,&C1,aCste);
                aS1.GSSR_AddNewEquation_Indexe(V,aPds,&C1,aCste);
	    }
	    else 
                aS1.GSSR_AddNewEquation(aPds,aF.data(),aCste);
            aS2.GSSR_AddNewEquation(aPds,aF.data(),aCste);

	     if ((NRrandom3() < 0.5) && (! SysFix))
                anEq2_1->AddEqNonIndexee(aCste,&C1,aPds,V);
	     else
	     {
                if (SysFix)
		   aSet2.FQC()->SetOffsets(V);
                anEq2_1->AddEqIndexee(aCste,&C1,aPds,V);
	     }

            aF.data()[aX] = 0;
        }

        for (INT aK =0 ; aK<aNbEq; aK++)
	{
	     std::vector<INT> aVInd;
	     REAL   aV3[3];

             static INT I1=0;
             static INT I2=0;
             static INT I3=0;
	     bool TransI =     (NRrandom3() <0.5)
		           &&  (aK != 0)
		           &&  (I1 < aNbVar-1)
		           &&  (I2 < aNbVar-1)
		           &&  (I3 < aNbVar-1); 
	     if (TransI)
	     {
		     I1++;
		     I2++;
		     I3++;
	     }
	     else
	     {
                I1 = std::min(aNbVar-1,INT(NRrandom3()*aNbVar));
                I2 = std::min(aNbVar-1,INT(NRrandom3()*aNbVar));
                I3 = std::min(aNbVar-1,INT(NRrandom3()*aNbVar));
	     }
             REAL aCste = NRrandom3();


	     aV3[0] = NRrandom3();
	     aV3[1] = NRrandom3();
	     aV3[2] = NRrandom3();

	     aF.data()[I1] += aV3[0];
             aF.data()[I2] += aV3[1];
             aF.data()[I3] += aV3[2];
	     aVInd.push_back(I1);
	     aVInd.push_back(I2);
	     aVInd.push_back(I3);

	     if ((NRrandom3() < 0.5) && (! SysFix))
                anEq2_3->AddEqNonIndexee(aCste,aV3,1,aVInd);
	     else
	     {
		if (SysFix)
		{
                   if (! TransI)
		      aSet2.FQC()->SetOffsets(aVInd);
		}
                anEq2_3->AddEqIndexee(aCste,aV3,1,aVInd);
	     }

	     if ((NRrandom3()<0.5) || isFixe)
	     {
	         if (isFixe) 
		 {
                     if (! TransI)
                        aSCr.SetOffsets(aVInd);
		 }
                 aS1.GSSR_AddNewEquation_Indexe(aVInd,1,aV3,aCste);
	     }
	     else
                 aS1.GSSR_AddNewEquation(1,aF.data(),aCste);

	     if (NRrandom3()<0.5)
                 aS2.GSSR_AddNewEquation_Indexe(aVInd,1,aV3,aCste);
	     else
                 aS2.GSSR_AddNewEquation(1,aF.data(),aCste);


             aF.data()[I1] = 0;
             aF.data()[I2] = 0;
             aF.data()[I3] = 0;
	}
        


	bool OK;
        Im1D_REAL8 Sol1 = aS1.GSSR_Solve(&OK);
        Im1D_REAL8 Sol2 = aS2.GSSR_Solve(&OK);
	REAL aDif;
	ELISE_COPY(Sol1.all_pts(),Abs(Sol1.in()-Sol2.in()),VMax(aDif));
	cout << "a Dif " << aDif << "\n";
	BENCH_ASSERT(aDif<1e-4);

	aSet2.SolveResetUpdate();
	ELISE_COPY(Sol1.all_pts(),Abs(aIm2.in()-Sol2.in()),VMax(aDif));
	cout << "a Dif " << aDif << "\n";
	BENCH_ASSERT(aDif<1e-4);



        aS1.GSSR_Reset();
        aS2.GSSR_Reset();
    }
}
Exemple #2
0
PtsHom ReadPtsHom(string aDir, GrpVodka aGrpVodka, string Extension)
{
    PtsHom aPtsHomol;
    Pt2di aSz;
    //Looking for maxs of vectOfExpTimeISO
    double maxExpTime=0, maxISO=0;
    for (int i=0;i<int(aGrpVodka.size());i++){
        if(aGrpVodka.ExpTime[i]>maxExpTime){maxExpTime=aGrpVodka.ExpTime[i];}
        if(aGrpVodka.ISO[i]>maxISO){maxISO=aGrpVodka.ISO[i];}
    }

    //Cmpulsory for file name manipulation
    cInterfChantierNameManipulateur * aICNM = cInterfChantierNameManipulateur::BasicAlloc(aDir);

//Going through every pairs of different images
    int cpt=0;
    for (int aK1=0 ; aK1<int(aGrpVodka.size()) ; aK1++)
    {
        std::cout<<"Getting homologous points from: "<<aGrpVodka.aListIm[aK1]<<endl;

        //Reading the image and creating the objects to be manipulated
            Tiff_Im aTF1= Tiff_Im::StdConvGen(aDir + aGrpVodka.aListIm[aK1],1,false);
            aSz = aTF1.sz();
            Im2D_REAL16  aIm1(aSz.x,aSz.y);
            ELISE_COPY
                (
                   aTF1.all_pts(),
                   aTF1.in(),
                   aIm1.out()
                );

            REAL16 ** aData1 = aIm1.data();

        for (int aK2=0 ; aK2<int(aGrpVodka.size()) ; aK2++)
        {
            Tiff_Im aTF2= Tiff_Im::StdConvGen(aDir + aGrpVodka.aListIm[aK2],1,false);
            Im2D_REAL16  aIm2(aSz.x,aSz.y);
            ELISE_COPY
                (
                   aTF2.all_pts(),
                   aTF2.in(),
                   aIm2.out()
                );

            REAL16 ** aData2 = aIm2.data();

            string prefixe="";
            if (aK1!=aK2)
            {
               std::string aNamePack =  aDir +  aICNM->Assoc1To2
                                        (
                                           "NKS-Assoc-CplIm2Hom@"+prefixe + "@" + Extension,
                                           aGrpVodka.aListIm[aK1],
                                           aGrpVodka.aListIm[aK2],
                                           true
                                        );

                   bool Exist = ELISE_fp::exist_file(aNamePack);
                   if (Exist)
                   {
                      ElPackHomologue aPack = ElPackHomologue::FromFile(aNamePack);

                           for
                           (
                               ElPackHomologue::const_iterator itP=aPack.begin();
                               itP!=aPack.end();
                               itP++
                           )
                           {
                                cpt++;
                                //Compute the distance between the point and the center of the image
                                double x0=aSz.x/2-0.5;
                                double y0=aSz.y/2-0.5;
                                double Dist1=sqrt(pow(itP->P1().x-x0,2)+pow(itP->P1().y-y0,2));
                                double Dist2=sqrt(pow(itP->P2().x-x0,2)+pow(itP->P2().y-y0,2));
                                //Go looking for grey value of the point, adjusted to ISO and Exposure time induced variations
                                double Grey1 =sqrt((aGrpVodka.ExpTime[aK1]*aGrpVodka.ISO[aK1])/(maxExpTime*maxISO))*Reechantillonnage::biline(aData1, aSz.x, aSz.y, itP->P1());
                                double Grey2 =sqrt((aGrpVodka.ExpTime[aK2]*aGrpVodka.ISO[aK2])/(maxExpTime*maxISO))*Reechantillonnage::biline(aData2, aSz.x, aSz.y, itP->P2());

                                aPtsHomol.Dist1.push_back(Dist1);
                                aPtsHomol.Dist2.push_back(Dist2);
                                aPtsHomol.Gr1.push_back(Grey1);
                                aPtsHomol.Gr2.push_back(Grey2);

                   }
                   }
                   else
                      std::cout  << "     # NO PACK FOR  : " << aNamePack  << "\n";
            }
        }
    }
    int nbpts=aPtsHomol.size();
    std::cout<<"Total number tie points: "<<nbpts<<" out of "<<cpt<<endl;
    aPtsHomol.SZ=aSz;

   return aPtsHomol;
}