Пример #1
0
std::vector<std::vector<Pt3dr> > cElHJaPlan3D::FacesSols(bool WithIndet)
{
   static tFullSubGrPl aSGrFul;
   for (tItSomGrPl itS=mGr->begin(aSGrFul) ; itS.go_on() ; itS++)
       for (tItArcGrPl itA=(*itS).begin(aSGrFul) ; itA.go_on() ; itA++)
           (*itA).attr().ResetCpt();

   for (INT aKF=0 ; aKF<INT(mFacettes.size()) ; aKF++)
   {
       cElHJaFacette * aFac = mFacettes[aKF];
       const  std::vector<tArcGrPl *> & aVArc = aFac->Arcs();
       if (WithIndet)
       {
          if (! aFac->IsImpossible())
             for (INT aKA =0 ; aKA<INT(aVArc.size()) ; aKA++)
             {
                  aVArc[aKA]->attr().Set1();
                  aVArc[aKA]->arc_rec().attr().Set1();
             }
       }
       else
       {
          if (aFac->IsSure())
          {
             for (INT aKA =0 ; aKA<INT(aVArc.size()) ; aKA++)
             {
                  aVArc[aKA]->attr().IncrCpt();
                  aVArc[aKA]->arc_rec().attr().IncrCpt();
             }
          }
       }
   }

   std::vector<std::vector<Pt3dr> > aRes;
   cSubGrSol aSub;
   ElPartition<tArcGrPl *>  aVFac;
   all_face_trigo(*mGr,aSub,aVFac);

   for (INT aKF=0 ; aKF<aVFac.nb() ; aKF++)
   {
         std::vector<Pt3dr> aV3;
         std::vector<Pt2dr> aV2;
	 ElSubFilo<tArcGrPl *> aF = aVFac[aKF];
	 for (INT aKA=0 ; aKA<aF.nb() ; aKA++)
         {
             aV2.push_back(aF[aKA]->s1().attr().Pt());
             aV3.push_back(mPlan.AddZ(aF[aKA]->s1().attr().Pt()));
         }
        if (surf_or_poly(aV2) < 0)
            aRes.push_back(aV3);
   }

   return aRes;
}
Пример #2
0
void OneTestNewMerge()
{
    static int aCpt=0;
    for (int aNb = 2 ; aNb < 500 ; aNb += 3)
    {
         // std::cout << "================ " << aNb << " =============================\n";
         bool MemoArc = true;
         aCpt++; 
         double aProbaPInt = NRrandom3();
         double aProbaArcGlob = NRrandom3();
         cStructMergeTieP<cVarSizeMergeTieP<Pt2df> > aVSMT(NbCamTest,MemoArc);
         cStructMergeTieP<cFixedSizeMergeTieP<NbCamTest,Pt2df> > aFSMT(NbCamTest,MemoArc);

         tGraphTestTieP aGr;
         int aFlagOr = aGr.alloc_flag_arc();
         tSubGraphTestTiepOr aSubOr(-1,aFlagOr);
         std::map<Pt2df,tSomTestTieP *> aMapS;
         

         for (int aKP=0 ; aKP<aNb ;  aKP++)
         {
             double aProbaArc = aProbaArcGlob * NRrandom3();
             std::vector<Pt2df> aVP;
             std::vector<tSomTestTieP *> aVS;
             for (int aKC = 0 ; aKC<NbCamTest ; aKC++)
             {
                 Pt2df aP;
                 if (NRrandom3() < aProbaPInt)
                 {
                     aP = Pt2df(aKC,NRrandom3(aNb*NbCamTest));
                 }
                 else
                 {
                     aP = Pt2df(aKC,aKP) ; // Chaque point est different
                 }
                 aVP.push_back(aP);

                 if (aMapS[aP] == 0)
                    aMapS[aP] = &aGr.new_som(aP);
                 aVS.push_back(aMapS[aP]);
                 
             }
             for (int aKC1=0 ; aKC1<NbCamTest ; aKC1++)
             {
                 for (int aKC2=0 ; aKC2<NbCamTest ; aKC2++)
                 {
                      if ((NRrandom3() < aProbaArc) && (aKC1!=aKC2))
                      {
                          aVSMT.AddArc(aVP[aKC1],aKC1,aVP[aKC2],aKC2);
                          aFSMT.AddArc(aVP[aKC1],aKC1,aVP[aKC2],aKC2);
                          
                          tSomTestTieP * aS1 = aVS[aKC1];
                          tSomTestTieP * aS2 = aVS[aKC2];
                          tArcTestTieP * anArc =  aGr.arc_s1s2(*aS1,*aS2);
                          if (anArc==0)
                             anArc = &aGr.add_arc(*aS1,*aS2,0);
                          anArc->flag_set_kth_true(aFlagOr);
                          anArc->attr()++;

                      }
                 }
             }
         }
         tSubGraphTestTieP aSub;
         ElPartition<tSomTestTieP * >  aPart;
         PartitionCC(aPart,aGr,aSub);
         int aNbCCOk=0;
         int aNbArcOK=0;
         cChkMerge  aChkGr;

         for (int aKSet=0 ; aKSet <aPart.nb()  ; aKSet++)
         {
             ElSubFilo<tSomTestTieP *> aSet = aPart[aKSet];
             if (aSet.size() != 1)
             {
                  bool Ok=true;
                  std::vector<int> aCpt(NbCamTest,0);
                  std::vector<Pt2df> aVPts(NbCamTest,Pt2df(0,0));
                  int aNbArc = 0;
                  for (int aKSom=0 ; aKSom<aSet.size() ; aKSom++)
                  {
                       Pt2df aP = aSet[aKSom]->attr();
                       int aKC = round_ni(aP.x);
                       aVPts[aKC] = aP;
                       if (aCpt[aKC]) 
                           Ok= false;
                       aCpt[aKC]++;
                       for (tArtIterTestTieP itA= aSet[aKSom]->begin(aSub) ; itA.go_on() ; itA++)
                          aNbArc += (*itA).attr();
                  }
                  if (Ok) 
                  {
                     aNbArcOK += aNbArc;
                     aNbCCOk++;
                     aChkGr.AddNbArc(aNbArc);
                     for (int aKC=0 ; aKC<NbCamTest ; aKC++)
                     {
                         if (aCpt[aKC])
                            aChkGr.AddSomIn(aKC,aVPts[aKC]);
                         else
                            aChkGr.AddSomAbs(aKC);
                     }
                  }
             }
         }

         aVSMT.DoExport();
         aFSMT.DoExport();

         const std::list<cVarSizeMergeTieP<Pt2df>  *> &  aLVT = aVSMT.ListMerged();
         const std::list<cFixedSizeMergeTieP<NbCamTest,Pt2df> *> &  aLFT = aFSMT.ListMerged();

         ELISE_ASSERT(int(aLVT.size())==aNbCCOk,"Tie Point CC Check");

         int aNbA1,aNbA2;
         double aChk1 = ChkSomMerge(aLVT,aNbA1,MemoArc);
         double aChk2 = ChkSomMerge(aLFT,aNbA2,MemoArc);

         // std::cout << aCpt << " ============== " << aLVT.size() << " " << aNbCCOk << " " << aNbArcOK << " " << " " << aNbA1 << "\n";
         if  (ElAbs(aChk1-aChk2)> 1E-5)  
         {
               std::cout << "HHHHH " <<   aChk1  << " " << aChk2  << " "  << "\n";
               ELISE_ASSERT(false,"Chk TieP");
         }
         if (ElAbs(aChk1-aChkGr.mRes)> 1e-5)
         {
               std::cout << "UUuuUUUi " <<   aChk1 << " " << aChkGr.mRes  << " " << "\n";
               ELISE_ASSERT(false,"Chk TieP");
         }

         if (aNbArcOK != aNbA1)
         {
             std::cout << " NB ARC : " << aNbArcOK << " " << aNbA1 << "\n";
             ELISE_ASSERT(aNbArcOK==aNbA1,"Tie Point CC Check");
         }


         // std::cout << "HHHHH " <<   ChkSomMerge(aLVT)  << " " << ChkSomMerge(aLFT)  << " " << ChkSomMerge(aLF)  << " " << "\n";
         aVSMT.Delete();
         aFSMT.Delete();
    }
}
Пример #3
0
template <class TypeIm,class TypeBase> Im2D_Bits<1> CreateGr(tGRGraf & mGr,Im2D<TypeIm,TypeBase> anIm,int aLabelOut,const cParamGrReg & aPGR)
{
    bool V8=true;
    //int aNbV = V8 ? 8 : 4;
    //Pt2di * TabV = V8 ? TAB_8_NEIGH : TAB_4_NEIGH;

    TIm2D<TypeIm,TypeBase> aTIm(anIm);
    Pt2di aSz = anIm.sz();

    Im2D_INT4 aImLabel(aSz.x,aSz.y,-1);
    TIm2D<INT4,INT4> aTL(aImLabel);
    ELISE_COPY(aImLabel.border(1),-2,aImLabel.out());

    Pt2di aP0;
    int aCpt=0;
    ElGrowingSetInd aSV(1000);
    std::vector<tGRSom *> aVSom;
    for (aP0.y=0 ; aP0.y<aSz.y ; aP0.y++)
    {
        for (aP0.x=0 ; aP0.x<aSz.x ; aP0.x++)
        {
             int aLabel = aTIm.get(aP0);
             if ((aTL.get(aP0)==-1) && (aLabel != aLabelOut))
             {
                std::vector<Pt2di> aVPts;
                CompCnx(aVPts,V8,aP0,anIm,aImLabel,INT4(aCpt),&aSV);
                int aNbPts = aVPts.size();
                if (aNbPts >= aPGR.mSzMinInit)
                {
                   cGR_AttrSom anAttr(aP0,aLabel,aCpt,aNbPts);
                 
                   tGRSom &  aSom = mGr.new_som(anAttr);
                   aVSom.push_back(&aSom);

                   for (ElGrowingSetInd::const_iterator itV=aSV.begin(); itV!=aSV.end() ; itV++)
                   {
                        tGRSom * aS2 = aVSom[*itV];
                        if (aS2)
                        {
                            cGR_AttrArc anAA;
                            mGr.add_arc(aSom,*aS2,anAA);
                        }
                   }
                }
                else
                {
                     aVSom.push_back(0);
                }
                aCpt++;
             }
        }
    }

    //std::cout << "BGIN FLAG MONT-DESC\n"; getchar();
    // Calcul des flag montant et descandant 
    int aFlagArcMont = mGr.alloc_flag_arc();
    int aFlagArcDesc = mGr.alloc_flag_arc();
    ElSubGraphe<cGR_AttrSom,cGR_AttrArc> aSubAll;
    for (int aKS=0 ; aKS<int(aVSom.size()) ; aKS++)
    {
        tGRSom * aSom = aVSom[aKS];
        if (aSom)
        {
            tGRSom * aSMax = aSom;
            tGRSom * aSMin = aSom;
            for (tGRSom::TArcIter itA=aSom->begin(aSubAll); itA.go_on(); itA++)
            {
                tGRSom * aS2 = &(itA->s2());
                if (    (aS2->attr().ValR() > aSMax->attr().ValR())
                     || ((aS2->attr().ValR()==aSMax->attr().ValR()) && (aS2->attr().Sz() > aSMax->attr().Sz()))
                   )
                {
                    aSMax = aS2;
                }

                if (    (aS2->attr().ValR() < aSMin->attr().ValR())
                     || ((aS2->attr().ValR()==aSMin->attr().ValR()) && (aS2->attr().Sz() > aSMin->attr().Sz()))
                   )
                {
                    aSMin = aS2;
                }
            }

            if (aSMax != aSom)
               mGr.arc_s1s2(*aSom,*aSMax)->sym_flag_set_kth_true(aFlagArcMont);
            if (aSMin != aSom)
               mGr.arc_s1s2(*aSom,*aSMin)->sym_flag_set_kth_true(aFlagArcDesc);
        }
    }
    // std::cout << "EeenDD  FLAG MONT-DESC\n";

    //  Analyse zone water shade
    for (int aKMD=0 ; aKMD<2 ; aKMD++)
    {
         bool isMont = (aKMD==0);
         int aFlagArc = (isMont) ? aFlagArcMont : aFlagArcDesc;
         ElPartition<tGRSom * > aPart;
         ElSubGraphe<cGR_AttrSom,cGR_AttrArc> aSubAll;
         cSubGrFlagArc< ElSubGraphe<cGR_AttrSom,cGR_AttrArc> > aSub(aSubAll,aFlagArc);
         PartitionCC(aPart,mGr,aSub);


         std::vector<tGRSom *> aVBarbs;
         cSubGrSzSup aGrCons(aPGR.mSzBarb);
         Ebarbule(mGr,aSub,aGrCons,aVBarbs);
         std::set<tGRSom *> aSetB(aVBarbs.begin(),aVBarbs.end());

         for (int aKC=0 ; aKC< aPart.nb() ; aKC++)
         {
             ElSubFilo<tGRSom *> aCC = aPart[aKC];
             int aSzTot = SomSz(aCC);
             bool Ok = aSzTot >= aPGR.mSeuilZonWS ;
             if (Ok)
             {
                 for (int aKS=0 ; aKS<aCC.size() ; aKS++)
                 {
                     if (aSetB.find(aCC[aKS])==aSetB.end())
                     {
                        aCC[aKS]->attr().Valid() = true;
                     }
                     else
                     {
                     }
                 }
             }
         }
    }
    // std::cout << "EeenDD  PARTITION\n"; getchar();

 
    double aSomT=0;
    double aMaxT=0;

    int aDelta = 1;  // 1 
    for (int aKS=0 ; aKS<int(aVSom.size()) ; aKS++)
    {
        tGRSom * aSom = aVSom[aKS];
        if (aSom && (! aSom->attr().DoneValR()))
        {
            ElTimer aChrono;
            cSubGrInterv aSG(aSom->attr().ValR()-aDelta,aSom->attr().ValR()+aDelta);
            ElFifo<tGRSom *> aCC;
            comp_connexe_som(aCC,aSom,aSG);
            int aSzCC = SomSz(aCC);
            bool Ok = aSzCC >= aPGR.mSeuilValRDelta;

            for (int aKC=0 ; aKC<int(aCC.size()) ; aKC++)
            {
                  tGRSom * aSom2 = aCC[aKC];
                  if (aSom2->attr().ValR() == aSom->attr().ValR())
                     aSom2->attr().DoneValR() = true;
                  if (Ok)
                     aSom2->attr().Valid() = true;
            }
            // ShowComp(aCC,V8,(Ok?255:0), anIm,aImLabel);

            double aT = aChrono.uval();
            aSomT += aT;
            if (aT > aMaxT)
            {
               aMaxT = aT;
            }
        }
    }

/*
*/

   //   EXPORT DES RESULTATS FINALS 
    Im2D_Bits<1>  aImRes(aSz.x,aSz.y,0);
    TIm2DBits<1>  aTImRes(aImRes);
    for (int aKS=0 ; aKS<int(aVSom.size()) ; aKS++)
    {
        tGRSom * aSom = aVSom[aKS];
        if (aSom  && aSom->attr().Valid())
        {
           std::vector<Pt2di> aVPts;
           CompCnxCste(aVPts,V8,aSom->attr().P0(),anIm,aImLabel);
           for (int aKP=0 ; aKP<int(aVPts.size()) ; aKP++)
           {
              aTImRes.oset(aVPts[aKP],1);
           }
        }
    }
    return  aImRes;
}