Пример #1
0
void Entity::internal_verify_meshobj_invariant() const
{
  PairIterRelation stk_relations = relations();
  for ( ; !stk_relations.empty(); ++stk_relations ) {
    ThrowRequireMsg(stk_relations->getMeshObj() != NULL, "Problem with: " << *stk_relations);
  }

  RelationVector& aux_relations = m_fmwk_attrs->aux_relations;
  for (RelationVector::const_iterator itr = aux_relations.begin(), end = aux_relations.end(); itr != end; ++itr) {
    ThrowRequireMsg(itr->getMeshObj() != NULL, "Problem with: " << *itr);
  }
}
void StructuralRelationsLight::computeRelations()
{
printf("StructuralRelationsLight::computeRelations start!\n");

  if(!have_input_cloud || !have_patches) {
    printf("[StructuralRelationsLight::computeRelations] Error: No input cloud and patches available.\n");
    return;
  }
  view->relations.clear();
  
  cv::Mat_<cv::Vec3b> matImage;
  ConvertPCLCloud2Image(pcl_cloud, matImage);

  std::vector<ColorHistogram3D> hist3D;
  surface::Texture texture;

  relations.resize(view->surfaces.size());

#pragma omp parallel sections
  {

    #pragma omp section
    {
      computeNeighbors();
    }

    #pragma omp section 
    {
      for(unsigned i=0; i<view->surfaces.size(); i++) { 
        int nr_hist_bins = 4;
        double uvThreshold = 0.0f;
        hist3D.push_back(ColorHistogram3D(nr_hist_bins, uvThreshold));                               
        hist3D[i].setInputCloud(pcl_cloud);
        hist3D[i].setIndices(view->surfaces[i]->indices);
        hist3D[i].compute();
      }
    }

    #pragma omp section 
    {
      texture.setInputImage(matImage);
      texture.setSurfaceModels(*view);
      texture.compute();
    }      
      
    #pragma omp section 
    {
      boundary.setInputCloud(pcl_cloud);
      boundary.setView(view);
    }

//     #pragma omp section 
//     {
//       surface::Relation rel;
//       rel.valid = false;
//       relations.clear();
//       for(unsigned i=0; i<view->surfaces.size(); i++)
//         for(unsigned j=0; j<view->surfaces.size(); j++)
//           relations[i].push_back(rel);
//     }
  } // end parallel sections


  std::vector< std::vector<surface::Relation> > relations(view->surfaces.size());
  for ( int i = 0; i < relations.size(); ++ i )
    relations[i].resize( view->surfaces.size() );
//  surface::Relation relations[view->surfaces.size()][view->surfaces.size()];
  surface::Relation rel;
  rel.valid = false;
  for(unsigned i=0; i<view->surfaces.size(); i++)
    for(unsigned j=i+1; j<view->surfaces.size(); j++)
      relations[i][j] = rel;
  
#pragma omp parallel for
  for(int i=0; i<(int)view->surfaces.size(); i++) {
    for(int j=0; j<(int)view->surfaces[i]->neighbors3D.size(); j++) {
      bool valid_relation = true;
      int p0 = i;
      int p1 = view->surfaces[i]->neighbors3D[j];
            
      if(p0 > p1)
        continue;
      
      double colorSimilarity = hist3D[p0].compare(hist3D[p1]);
      double textureRate = texture.compare(p0, p1);
      double relSize = std::min((double)view->surfaces[p0]->indices.size()/(double)view->surfaces[p1]->indices.size(), 
                                (double)view->surfaces[p1]->indices.size()/(double)view->surfaces[p0]->indices.size());
      
      std::vector<double> boundary_relations;
      if(!boundary.compare(p0, p1, boundary_relations)) {
        valid_relation = false;
        printf("[StructuralRelationsLight::computeRelations] Warning: Boundary relation invalid.\n");
      }
    
      if(valid_relation) {
          Relation r;
          r.groundTruth = -1;
          r.prediction = -1;
          r.type = 1;                                     // structural level = 1
          r.id_0 = p0;
          r.id_1 = p1;

          r.rel_value.push_back(colorSimilarity);         // r_co ... color similarity (histogram) of the patch
          r.rel_value.push_back(textureRate);             // r_tr ... difference of texture rate
          r.rel_value.push_back(relSize);                 // r_rs ... relative patch size difference

          r.rel_value.push_back(boundary_relations[0]);     // r_co3 ... color similarity on 3D border
          r.rel_value.push_back(boundary_relations[4]);     // r_cu3 ... mean curvature of 3D neighboring points
          r.rel_value.push_back(boundary_relations[1]);     // r_di2 ... depth mean value between border points (2D)
          r.rel_value.push_back(boundary_relations[2]);     // r_vd2 ... depth variance value
          r.rel_value.push_back(boundary_relations[5]);     // r_cu3 ... curvature variance of 3D neighboring points
          r.rel_value.push_back(boundary_relations[6]);     // r_3d2 ... relation 3D neighbors / 2D neighbors

          r.valid = true;
          relations[p0][p1] = r;
      }
    }
  }
  
  // copy relations to view
  for(unsigned i=0; i<view->surfaces.size(); i++)
    for(unsigned j=i+1; j<view->surfaces.size(); j++) {
      if(relations[i][j].valid) {
        view->relations.push_back(relations[i][j]);
#ifdef DEBUG
        printf("r_st_l: [%u][%u]: ", relations[i][j].id_0, relations[i][j].id_1);
        for(unsigned ridx=0; ridx<relations[i][j].rel_value.size(); ridx++)
          printf("%4.3f ", relations[i][j].rel_value[ridx]);
        printf("\n");
#endif
      }
    }
}
Пример #3
0
 /***
  * Insert waterways and relations of incomplete relations.
  */
 void ways_in_incomplete_relation() {
     clean_assembled_relations();
     for (auto relation_meta : relations()) {
         handle_relation(relation_meta);
     }
 }
Пример #4
0
int main( int argc, char * argv[ ] )
{
  // start timer
  const double t_0 = omp_get_wtime( );

  const unsigned int dim   = 3;  
  const unsigned int order = DFMM_ORDER;
  const double eps         = DFMM_EPSILON;

  typedef DimTraits<dim>::point_type point_type;
  typedef Dof<dim>                particle_type;

  // required command line arguments
#ifdef DFMM_USE_OMP
  if (argc != 5) {
#else
  if (argc != 4) {
#endif
    std::cerr << "Wrong number of command line arguments" << std::endl;
    exit(-1);
  }
  const std::string filename(    argv[1]);
  const unsigned long N   = atoi(argv[2]);
  const unsigned int lmax = atoi(argv[3]);

#ifdef DFMM_USE_OMP
  const unsigned int nthreads = atoi(argv[4]);
  omp_set_num_threads(nthreads);
  std::cout << "Using " << omp_get_max_threads() << " threads." << std::endl;
#endif

  particle_type *const particles = new particle_type [N];
  unsigned int  *const pindices  = new unsigned int  [N];
  ReadParticles(filename, N, particles);

  // fill pindices
  for (unsigned int p=0; p<N; ++p)
    pindices[p] = particles[p].getId();

  // plot particles
  //Plot<particle_type> plotter(particles, N);
  //plotter.plot();

  // get bounding box of root cluster
  const std::pair<point_type,point_type> bbx = GetBoundingBox(particles, N);

  // storage: setup and stores level infos, stores kernel wrapper, etc.
  typedef Storage<dim> storage_type;
  storage_type storage(bbx, lmax);


  // setup root cluster
  typedef Cluster<dim> cluster_type;
  cluster_type* cl = new cluster_type(N, storage.getRootClusterCenter());
  
  // subdivide root cluster, then generated level based cluster lists
  std::vector<std::vector<cluster_type*> > all_cluster_vectors;
  const unsigned int ncl = cl->subdivide(storage.getLevels(),
                                         all_cluster_vectors,
                                         particles, pindices, lmax);
  std::cout << "\n- Number of clusters " << ncl << std::endl;

  // check if particles are in correct cluster
  AreParticlesInCluster<particle_type> areThey(particles,pindices);
  bool all_particles_are_in_cluster = true;
  BOOST_FOREACH(const cluster_type *const lcl, all_cluster_vectors.back())
    if (!areThey(lcl, storage.getLevels().at(lcl->getNlevel()))) {
      std::cout << "Particles are not in cluster they belong to." << std::endl;
      all_particles_are_in_cluster = false;
    }
  assert(all_particles_are_in_cluster);



  // LAPLACE
  typedef KernelFunction<LAPLACE3D> kernel_type;
  typedef kernel_type::value_type value_type;
  kernel_type kernel;
  storage.initLevels();



  //typedef M2LHandlerSArcmp<dim,order,value_type> m2l_handler_type;
  //typedef M2LHandlerNA<dim,order,value_type> m2l_handler_type;
  //typedef M2LHandlerNAsym<dim,order,value_type> m2l_handler_type;
  //typedef M2LHandlerNAblk<dim,order,value_type> m2l_handler_type;
  //typedef M2LHandlerIA<dim,order,value_type> m2l_handler_type;
  typedef M2LHandlerIAsym<dim,order,value_type> m2l_handler_type;
  //typedef M2LHandlerIAblk<dim,order,value_type> m2l_handler_type;


  // init m2l handler 
  typedef std::vector<m2l_handler_type> m2l_handler_type_vector;
  m2l_handler_type_vector all_m2l_handler;
  storage.initialize(all_m2l_handler);
  m2l_handler_type::getInfo();




  // cluster bases
  typedef ClusterBasis<dim,order,value_type> clusterbasis_type;
  std::vector<clusterbasis_type> rbasis(ncl), cbasis(ncl);

  // cluster expansions
  typedef ExpansionHandler<dim,order,value_type> expansion_type;
  std::vector<expansion_type> rexph(ncl), cexph(ncl);
  
  // cluster relations
  typedef Relations<dim> relations_type;
  std::vector<relations_type> relations(ncl);

  // setup multilevel relations
  SetupClusterRelations(all_cluster_vectors, rexph,
                        all_cluster_vectors, cexph, 
                        relations, storage.getLevels(), all_m2l_handler);


  // write out info
  storage.writeInfo(all_m2l_handler);


  ////////////////////////////////////////////////////////////////////
  // draw cross section through cluster oct-tree at "loc" in direction "dir"
  point_type loc;
  for (unsigned int i=0; i<dim; ++i)
    loc[i] = (bbx.first[i]+bbx.second[i]) / 2;
  std::cout << "\n- Center of particles at " << loc << std::endl;
  std::cout << " - a = " << bbx.first << "\tb = " << bbx.second << std::endl;
  
  //  std::cout << "\n- Origin of PS pictures at " << loc << std::endl;
  
  //const unsigned int dir0 = 0;
  //drawCrossSection(filename, loc, dir0, 
  //                 storage.getRootClusterCenter(),
  //                 storage.getRootClusterExtension(),
  //                 all_cluster_vectors, storage.getLevels(), all_m2l_handler);
  //
  //const unsigned int dir1 = 1;
  //drawCrossSection(filename, loc, dir1, 
  //                 storage.getRootClusterCenter(),
  //                 storage.getRootClusterExtension(),
  //                 all_cluster_vectors, storage.getLevels(), all_m2l_handler);
  //
  //const unsigned int dir2 = 2;
  //drawCrossSection(filename, loc, dir2, 
  //                 storage.getRootClusterCenter(),
  //                 storage.getRootClusterExtension(),
  //                 all_cluster_vectors, storage.getLevels(), all_m2l_handler);
  //////////////////////////////////////////////////////////////////////



  // compute m2l operators
  ComputeM2Loperators(all_m2l_handler, kernel, eps);



  // l2l/m2m operators
  std::cout << "\n- Evaluating interpolation operators " << std::flush;
  const double t_io = omp_get_wtime();
  setIO(all_cluster_vectors, rbasis, all_m2l_handler, pindices, particles);
  setIO(all_cluster_vectors, cbasis, all_m2l_handler, pindices, particles);
  std::cout << " took " << omp_get_wtime() - t_io << " s" << std::endl;



  // densities and potentials
  value_type *const y = new value_type [N];
  for (unsigned int n=0; n<N; ++n)
    y[n] = (double)rand()/(double)RAND_MAX;
  value_type *const x = new value_type [N];
  for (unsigned int n=0; n<N; ++n) x[n] = 0.;





  // m2m
  std::cout << "\n- Applying M2M operators\n" << std::flush;
  const double t_m2m = omp_get_wtime();
  ApplyM2Moperators(all_cluster_vectors, cbasis, cexph, all_m2l_handler, y);
  std::cout << "  - overall " << omp_get_wtime() - t_m2m << " s" << std::endl;

  // m2l
  std::cout << "\n- Applying M2L operators\n" << std::flush;
  const double t_m2l = omp_get_wtime();
  ApplyM2Loperators(all_cluster_vectors, rexph, cexph, relations,
                    all_m2l_handler);
  std::cout << "  - overall " << omp_get_wtime() - t_m2l << " s" << std::endl;

  // l2l
  std::cout << "\n- Applying L2L operators\n" << std::flush;
  const double t_l2l = omp_get_wtime();
  ApplyL2Loperators(all_cluster_vectors, rbasis, rexph, all_m2l_handler, x);
  std::cout << "  - overall " << omp_get_wtime() - t_l2l << " s" << std::endl;

  // apply near field on the fly
  typedef NFadder<cluster_type,particle_type,relations_type,kernel_type>
    nfc_type;
  ApplyNearField(all_cluster_vectors.back(),
                 nfc_type(kernel, relations,
                          pindices, particles,
                          pindices, particles,
                          x, y));



//  std::cout << "\n- Size of value_type is " << sizeof(value_type)
//            << " byte." << std::endl;
//
//  // direct calculation
//  const long size = ndofs*ndofs;
//  const long size_in_bytes = size * sizeof(value_type);
//  const double mem_dns = (long)size_in_bytes / (1024.*1024.);
//  std::cout << "\n- Direct calculation of " << ndofs << " times " << ndofs
//            << " particles requires " 
//            << (long)size_in_bytes / (1024.*1024.)
//            << " Mb."<< std::endl;
//  const double t_direct = omp_get_wtime();
//  value_type *const x0 = new value_type [ndofs];
//  blas::setzero(ndofs, x0);
//  std::cout << " - Memory allocation " << std::flush;
//  const double t_alloc = omp_get_wtime();
//  value_type *const K = new value_type [ndofs * ndofs];
//  const double t_calc = omp_get_wtime();
//  std::cout << "took " << t_calc - t_alloc << " s" << std::endl;
//  std::cout << " - Matrix evaluation " << std::flush;
//  storage.getFundSol().compute(ndofs, dofs, ndofs, dofs, K);
//  const double t_matvec = omp_get_wtime();
//  std::cout << "took " << t_matvec - t_calc << " s" << std::endl;
//  // matrix vector product
//  std::cout << " - Matrix vector multiplication " << std::flush;
//  blas::gemva(ndofs, ndofs, 1., K, y, x0);
//  std::cout << "took " << omp_get_wtime() - t_matvec << " s" << std::endl;
//  std::cout << "  took " << omp_get_wtime() - t_direct << " s" << std::endl;


  
  // exact clusterX
  std::cout << "\n- Exact evaluation of cluster X " << std::flush;
  const double t_ex = omp_get_wtime();
  cluster_type *const clx = all_cluster_vectors.back().front();
  assert(clx->getNbeg() == 0);
  const unsigned int nx = clx->getSize();
  const unsigned int ny = N;
  value_type *const x0 = new value_type [nx];
  blas::setzero(nx, x0);
  for (unsigned int i=0; i<nx; ++i)
    for (unsigned int j=nx; j<ny; ++j)
      x0[i] += kernel(particles[pindices[i]].getPoint(),
                      particles[pindices[j]].getPoint()) * y[j];
  std::cout << "took " << omp_get_wtime() - t_ex << " s" << std::endl;


//  value_type sum_x  = 0;
//  value_type sum_x0 = 0;
//  for (unsigned int n=0; n<nx; ++n) {
//    sum_x  += x[ n];
//    sum_x0 += x0[n];
//  }
//  std::cout << "\nSize of cluster X = " << nx
//            << "\tsumx = " << sum_x
//            << "\tsumx0 = " << sum_x0 << std::endl;
//  for (unsigned int n=0; n<(10<nx?10:nx); ++n)
//    std::cout << x[n] << "\t" << x0[n] << "\t" << x[n]-x0[n] << std::endl;
  
  std::cout << "\n- L2  error " << computeL2norm( nx, x0, x) << std::endl;
  std::cout <<   "- Inf error " << computeINFnorm(nx, x0, x) << std::endl;

  std::cout << "\n- INTERPOLATION_ORDER = " << order
            << "\n- EPSILON = " << eps << std::endl;



  // clear memory
  delete [] x;
  delete [] y;
  delete [] x0;

  delete cl;
  delete [] particles;                         
  delete [] pindices;
  


  ////////////////////////////////////////////////////
  std::cout << "\n- Overall time " << omp_get_wtime( ) - t_0
            << " s" << std::endl;
  ////////////////////////////////////////////////////


  return 0;
}