当前位置: 首页>>代码示例>>C++>>正文


C++ Functions::find方法代码示例

本文整理汇总了C++中Functions::find方法的典型用法代码示例。如果您正苦于以下问题:C++ Functions::find方法的具体用法?C++ Functions::find怎么用?C++ Functions::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Functions的用法示例。


在下文中一共展示了Functions::find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: kantorovich

  double kantorovich (const T &densityT,
		      const Functions &densityF,
		      const Matrix &X,
		      const Vector &weights,
		      Vector &g,
		      SparseMatrix &h)
  {
    typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
    typedef CGAL::Polygon_2<K> Polygon;
    typedef K::FT FT;
    typedef CGAL::Regular_triangulation_filtered_traits_2<K> RT_Traits;
    typedef CGAL::Regular_triangulation_vertex_base_2<RT_Traits> Vbase;
    typedef CGAL::Triangulation_vertex_base_with_info_2
      <size_t, RT_Traits, Vbase> Vb;
    typedef CGAL::Regular_triangulation_face_base_2<RT_Traits> Cb;
    typedef CGAL::Triangulation_data_structure_2<Vb,Cb> Tds;
    typedef CGAL::Regular_triangulation_2<RT_Traits, Tds> RT;

    typedef RT::Vertex_handle Vertex_handle_RT;
    typedef RT::Weighted_point Weighted_point;
    typedef typename CGAL::Point_2<K> Point;
    
    size_t N = X.rows();
    assert(weights.rows() == N);
    assert(weights.cols() == 1);
    assert(X.cols() == 2);
    
    // insert points with indices in the regular triangulation
    std::vector<std::pair<Weighted_point,size_t> > Xw(N);
    for (size_t i = 0; i < N; ++i)
    {
      Xw[i] = std::make_pair(Weighted_point(Point(X(i,0), X(i,1)),
					    weights(i)), i);
    }
    RT dt (Xw.begin(), Xw.end());
    dt.infinite_vertex()->info() = -1;
    
    // compute the quadratic part
    typedef MA::Voronoi_intersection_traits<K> Traits;
    typedef typename MA::Tri_intersector<T,RT,Traits> Tri_isector;  
    typedef typename Tri_isector::Pgon Pgon;
    
    typedef Eigen::Triplet<FT> Triplet;
    std::vector<Triplet> htri;
    
    FT total(0), fval(0), total_area(0);
    g = Vector::Zero(N);

    MA::voronoi_triangulation_intersection_raw
      (densityT,dt,
       [&] (const Pgon &pgon,
	    typename T::Face_handle f,
	    Vertex_handle_RT v)
       {
	 Tri_isector isector;

	 Polygon p;
	 std::vector<Vertex_handle_RT> adj;
	 for (size_t i = 0; i < pgon.size(); ++i)
	   {
             size_t ii = (i==0)?(pgon.size()-1):(i-1);
	     //size_t ii = (i+1)%pgon.size();
	     p.push_back(isector.vertex_to_point(pgon[i], pgon[ii]));
	     adj.push_back((pgon[i].type == Tri_isector::EDGE_DT) ?
			   pgon[i].edge_dt.second : 0);
	   }

	 size_t idv = v->info();
	 auto fit = densityF.find(f);
	 assert(fit != densityF.end());
	 auto fv = fit->second; // function to integrate 
	 
	 // compute hessian
	 for (size_t i = 0; i < p.size(); ++i)
	   {
	     if (adj[i] == 0)
	       continue;
	     Vertex_handle_RT w = adj[i];
	     size_t idw = w->info();
	     
	     FT r = MA::integrate_1<FT>(p.edge(i), fv);
	     FT d = 2*sqrt(CGAL::squared_distance(v->point(),
						  w->point()));
	     htri.push_back(Triplet(idv, idw, -r/d));
	     htri.push_back(Triplet(idv, idv, +r/d));
	   }
	 
	 // compute value and gradient
	 FT warea = MA::integrate_1<FT>(p, FT(0), fv);
	 FT intg = MA::integrate_3<FT>(p, FT(0), [&](Point p)
				       {
					 return fv(p) * 
					 CGAL::squared_distance(p,
								v->point());
				       });
	 fval = fval + warea * weights[idv] - intg; 
	 g[idv] = g[idv] + warea;
	 total += warea;
         total_area += p.area();
       });
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的Functions::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。