Exemplo n.º 1
0
QSize
ConfigDelegateBase::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    int width = QStyledItemDelegate::sizeHint( option, index ).width();

    QStyleOptionViewItemV4 opt = option;
    initStyleOption( &opt, index );


    QFont name = opt.font;
    name.setPointSize( name.pointSize() + 2 );
    name.setBold( true );

    QFont path = opt.font;
    path.setItalic( true );
    path.setPointSize( path.pointSize() - 1 );


    QFontMetrics bfm( name );
    QFontMetrics sfm( path );
    return QSize( width, 2 * PADDING + bfm.height() + sfm.height() );
}
Exemplo n.º 2
0
void test_solver(BfmSolver solver)
{

  g5dParams parms;

  int Ls=16;
  double M5=1.8;
  double mq=0.0001;
  double wilson_lo = 0.05;
  double wilson_hi = 6.8;
  double shamir_lo = 0.025;
  double shamir_hi = 1.7;
  double ht_scale=1.7;
  double hw_scale=1.0;

  if ( solver != DWF ) { 
    exit(0);
    Printf("Should be testing HtCayleyTanh aka DWF\n");
  }
  parms.pDWF(mq,M5,Ls);

  multi1d<LatticeColorMatrix> u(4);
  HotSt(u);
  //  ArchivGauge_t Header ; readArchiv(Header,u,"ckpoint_lat.3000");  

  multi1d<LatticeFermion> src(Ls);

/* Rudy calculate some eigenvectors */


  BfmWrapperParams BWP;
  BWP.BfmInverter = BfmInv_CG; 
  BWP.BfmMatrix   = BfmMat_M;
  BWP.BfmPrecision= Bfm64bit;
  BWP.MaxIter     = 10000;
  BWP.RsdTarget.resize(1);
  BWP.RsdTarget[0]= 1.0e-9;
  BWP.Delta = 1.0e-4;
  BWP.BAP = parms;
  BfmWrapper bfm(BWP);

    bfmarg bfma;
#if defined(QDP_USE_OMP_THREADS)
    bfma.Threads(omp_get_max_threads());
#else
    bfma.Threads(16);
#endif
    bfma.Verbose(0);

    //Physics parameters
    bfmActionParams *bfmap = (bfmActionParams *) &bfma;
    *bfmap = bfm.invParam.BAP;
    
    // Algorithm & code control
    bfma.time_report_iter=-100;
    bfma.max_iter     = bfm.invParam.MaxIter;
    bfma.residual     = toDouble(bfm.invParam.RsdTarget[0]);

  int lx = QDP::Layout::subgridLattSize()[0];
  int ly = QDP::Layout::subgridLattSize()[1];
  int lz = QDP::Layout::subgridLattSize()[2];
  int lt = QDP::Layout::subgridLattSize()[3];
    //Geometry
    bfma.node_latt[0] = lx;
    bfma.node_latt[1] = ly;
    bfma.node_latt[2] = lz;
    bfma.node_latt[3] = lt;
    
    multi1d<int> procs = QDP::Layout::logicalSize();
    for(int mu=0;mu<4;mu++){
      if (procs[mu]>1) bfma.local_comm[mu] = 0;
      else             bfma.local_comm[mu] = 1;
    }
    
    // Bfm object
    bfm_qdp<double> bfm_eig; 
    bfm_eig.init(bfma);

    //Gauge field import
    bfm_eig.importGauge(u);

    //Subspace
#define NumberGaussian (1)
  Fermion_t subspace[NumberGaussian];
  Fermion_t check;
  Fermion_t mp;
  Fermion_t mmp;
  Fermion_t tmp_t;
  check = bfm_eig.allocFermion();
     mp = bfm_eig.allocFermion();
    mmp = bfm_eig.allocFermion();
  tmp_t = bfm_eig.allocFermion();
  bfm_eig.importFermion(src,check,1);

  QDPIO::cout << "Ls = "<<Ls<<endl;
  for(int g=0;g<NumberGaussian;g++){
    for(int s=0;s<Ls;s++){
      gaussian(src[s]);
    }
    subspace[g]=bfm_eig.allocFermion();
    bfm_eig.importFermion(src,subspace[g],1); // Half parity gaussian
    if ( g==0) {
      bfm_eig.importFermion(src,check,1);
    }
    for(int s=0;s<Ls;s++){
      src[s]=zero;
    }
    bfm_eig.exportFermion(src,subspace[g],1);
    QDPIO::cout << "Subspace norm " << norm2(src)<<endl;
  }
  for(int s=0;s<Ls;s++){
    gaussian(src[s]);
  }
  QDPIO::cout << "Got here " << endl;

  //  Handle< LinearOperatorArray<T> > linop =GetLinOp(u, parms);
  int block[5];
  for(int i=0;i<5;i++) block[i]=4;

  QDPIO::cout << "Initialised dirac op"<<endl;
  BfmLittleDiracOperator ldop(Ls,NumberGaussian,block,subspace,&bfm_eig);

  int ns = ldop.SubspaceDimension();
  QDPIO::cout << "subspace dimension is "<< ns<<endl;
  ns = ldop.SubspaceLocalDimension();
  QDPIO::cout << "subspace dimension per node is "<< ns<<endl;

  std::vector<std::complex<double> > decomp(ns);
  ldop.ProjectToSubspace(check,decomp);
  if (QMP_is_primary_node()){
    FILE * fp = fopen("coeff.dat","w");
    for(int s=0;s<ns;s++){
      fprintf(fp,"coeff %d %le %le\n",s,real(decomp[s]),imag(decomp[s]));
    }
    fclose(fp);
  }
  for(int s=0;s<ns;s++){
    QDPIO::cout << "coeff "<<s<<" " << real(decomp[s]) << " " << imag(decomp[s])<<endl;
  }
  ldop.PromoteFromSubspace(decomp,mp);
  double n;
#pragma omp parallel 
  {
    omp_set_num_threads(bfm_eig.nthread);
#pragma omp for 
    for(int t=0;t<bfm_eig.nthread;t++) {
      bfm_eig.axpy(check,mp,check,-1);
      n = bfm_eig.norm(check);
    }
  }
  QDPIO::cout << "project/promote n2diff "<< n<<endl;
  QMP_barrier();

QDPIO::cout << "Computing little dirac matrix"<<endl;
  ldop.ComputeLittleMatrixColored();

  QDPIO::cout << "Done"<<endl;

  std::vector<std::complex<double> > Aphi(ns);
  //        phi^dag DdagD phi = |Dphi|^2 with phi a subspace vector
  //        should be equal to Project/Apply/Promote + inner product

#pragma omp parallel 
  {
#pragma omp for 
    for(int t=0;t<bfm_eig.nthread;t++) {
      bfm_eig.Mprec(subspace[0],mp,tmp_t,0);
    }
  }

  QDPIO::cout << "Applied BFM matrix "<<endl;

  double n2;
#pragma omp parallel 
  {
    omp_set_num_threads(bfm_eig.nthread);
#pragma omp for 
    for(int t=0;t<bfm_eig.nthread;t++) {
      n2 = bfm_eig.norm(mp);
    }
  }

  QDPIO::cout << "Applied BFM matrix "<<n2<<endl;

  ldop.ProjectToSubspace(subspace[0],decomp);
  QDPIO::cout << "Projected to subspace "<<endl;
  ldop.Apply(decomp,Aphi);
  QDPIO::cout << "Applied A "<<endl;
  ldop.PromoteFromSubspace(Aphi,check);
  QDPIO::cout << "Promoted "<<endl;

  complex<double> inn;
#pragma omp parallel 
  {
#pragma omp for 
    for(int t=0;t<bfm_eig.nthread;t++) {
      inn = bfm_eig.inner(subspace[0],check);
    }
  }

  QDPIO::cout << "phi^dag Ddag D phi check " << n2 << " " <<real(inn) << imag(inn) <<endl;

  std::vector<std::complex<double> > AinvAphi(ns);
  ldop.ProjectToSubspace(subspace[0],decomp);
  ldop.Apply(decomp,Aphi);
  for(int s=0;s<ns;s++){
    QDPIO::cout << "Aphi "<<s<<" " << real(Aphi[s]) <<" " << imag(Aphi[s])<<endl;
  }
  ldop.PromoteFromSubspace(Aphi,check);

#pragma omp parallel 
  {
#pragma omp for 
    for(int t=0;t<bfm_eig.nthread;t++) {
      bfm_eig.Mprec(subspace[0],mp,tmp_t,0);
      bfm_eig.Mprec(mp,mmp,tmp_t,1);
    }
  }
  ldop.ProjectToSubspace(mmp,decomp);
  ldop.PromoteFromSubspace(decomp,mmp);
#pragma omp parallel 
  {
#pragma omp for 
    for(int t=0;t<bfm_eig.nthread;t++) {
      bfm_eig.axpy(check,mmp,check,-1.0);
      n2 = bfm_eig.norm(check);
    }
  }
  QDPIO::cout << "PMdagMP check n2diff "<< n2<<endl;


  QMP_barrier();
  QDPIO::cout << "Applying inverse"<<endl;
  ldop.ApplyInverse(Aphi,AinvAphi);
  QMP_barrier();
  for(int s=0;s<ns;s++){
    QDPIO::cout << "AinvAphi "<<s<<" " << real(AinvAphi[s]) << " " << imag(AinvAphi[s])<<endl;
  }
  ldop.PromoteFromSubspace(AinvAphi,check);

#pragma omp parallel 
  {
#pragma omp for 
    for(int t=0;t<bfm_eig.nthread;t++) {
      bfm_eig.axpy(check,subspace[0],check,-1.0);
      n2 = bfm_eig.norm(check);
    }
  }
  QDPIO::cout << "AinvA check n2diff "<< n2<<endl;
  

}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    std::string img0_str, img1_str;

    if(argc == 3) {
        img0_str = argv[1];
        img1_str = argv[2];
    } else {
        img0_str = "../data/input/features/balcony_0.png";
        img1_str = "../data/input/augmented_reality/desk.png";
    }

    //computing K matrix from manufacturer data
    double fx = pic::getFocalLengthPixels(3.3, 3.8, 2592.0);
    double fy = pic::getFocalLengthPixels(3.3, 2.9, 1936.0);
    Eigen::Matrix3d K = pic::getIntrinsicsMatrix(fx, fy, 2592.0 / 2.0, 1936.0 / 2.0);

    printf("Reading LDR images...");
    pic::Image img0, img1;
    img0.Read(img0_str, pic::LT_NOR);
    img1.Read(img1_str, pic::LT_NOR);

    printf("Ok\n");

    printf("Are they both valid? ");
    if(img0.isValid() && img1.isValid()) {
        printf("OK\n");

        //output corners
        std::vector< Eigen::Vector2f > corners_from_img0;
        std::vector< Eigen::Vector2f > corners_from_img1;

        //compute the luminance images
        pic::Image *L0 = pic::FilterLuminance::Execute(&img0, NULL, pic::LT_CIE_LUMINANCE);
        pic::Image *L1 = pic::FilterLuminance::Execute(&img1, NULL, pic::LT_CIE_LUMINANCE);

        //get corners
        printf("Extracting corners...\n");
        pic::HarrisCornerDetector hcd(2.5f, 5);
        hcd.execute(L0, &corners_from_img0);
        hcd.getCornersImage(&corners_from_img0, NULL, L0->width, L0->height, true)->Write("../test1.bmp");

        hcd.execute(L1, &corners_from_img1);
        hcd.getCornersImage(&corners_from_img1, NULL, L1->width, L1->height, true)->Write("../test2.bmp");

        //compute ORB descriptors for each corner and image
        //compute luminance images
        pic::Image *L0_flt = pic::FilterGaussian2D::Execute(L0, NULL, 2.5f);
        pic::Image *L1_flt = pic::FilterGaussian2D::Execute(L1, NULL, 2.5f);

        printf("Computing ORB descriptors...\n");

        //pic::PoissonDescriptor b_desc(16);
        pic::ORBDescriptor b_desc(31, 512);

        std::vector< unsigned int *> descs0;
        b_desc.getAll(L0_flt, corners_from_img0 , descs0);

        std::vector< unsigned int *> descs1;
        b_desc.getAll(L1_flt, corners_from_img1 , descs1);

        printf("Matching ORB descriptors...\n");
        int n = b_desc.getDescriptorSize();

        pic::BinaryFeatureBruteForceMatcher bfm(&descs1, n);

        printf("Descriptor size: %d\n", n);

        printf("Matching...");
        std::vector< Eigen::Vector3i > matches;
        bfm.getAllMatches(descs0, matches);
        printf(" we found %d matches ", matches.size());
        printf("Ok\n");

        //filter
        std::vector< Eigen::Vector2f > m0, m1;
        pic::BinaryFeatureMatcher::filterMatches(corners_from_img0, corners_from_img1, matches, m0, m1);

        printf("Estimating a homography matrix H from the matches...");

        std::vector< unsigned int > inliers;
        Eigen::Matrix3d H = pic::estimateHomographyWithNonLinearRefinement(m0, m1, inliers, 10000, 2.5f, 1, 10000, 1e-5f);

        Eigen::Matrix34d cam = pic::getCameraMatrixFromHomography(H, K);

        img1 *= 0.25f;

        //Augmentation: drawing a 3D grid
        int res = 10;
        for(int i=1;i<(res + 1);i++) {
            float u = float(i) / 50.0f;

            for(int j=1;j<(res + 1);j++) {
                float v = float(j) / 50.0f;

                Eigen::Vector4d point(u, v, 0.0f, 1.0f);
                Eigen::Vector2i coord = pic::cameraMatrixProject(cam, point);

                float *tmp = img1(coord[0], coord[1]);
                tmp[0] = 1.0f;
                tmp[1] = 0.25f;
                tmp[2] = 0.25f;
            }

        }

        //Augmentation: drawing 3D axis
        Eigen::Vector4d p0(0.0, 0.0, 0.0, 1.0);
        Eigen::Vector2i coord0 = pic::cameraMatrixProject(cam, p0);

        Eigen::Vector4d p1(0.2, 0.0, 0.0, 1.0);
        Eigen::Vector2i coord1 = pic::cameraMatrixProject(cam, p1);

        Eigen::Vector4d p2(0.0, 0.2, 0.0, 1.0);
        Eigen::Vector2i coord2 = pic::cameraMatrixProject(cam, p2);

        Eigen::Vector4d p3(0.0, 0.0, 0.2, 1.0);
        Eigen::Vector2i coord3 = pic::cameraMatrixProject(cam, p3);

        float color[]={0.25f, 1.0f, 0.25f};
        pic::drawLine(&img1, pic::convertFromEigenToVec(coord0), pic::convertFromEigenToVec(coord1), color);
        pic::drawLine(&img1, pic::convertFromEigenToVec(coord0), pic::convertFromEigenToVec(coord2), color);
        pic::drawLine(&img1, pic::convertFromEigenToVec(coord0), pic::convertFromEigenToVec(coord3), color);

        img1.Write("../data/output/simple_augmented_reality.png", pic::LT_NOR);

    } else {
        printf("No, there is at least an invalid file!\n");
    }

    return 0;
}