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


C++ Line2::dir方法代码示例

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


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

示例1: clipPoly2D

IntersectType clipPoly2D(const Points2D& points,
	const Line2<typename points_adaptor<Points2D>::scalar>& plane,
	std::list<ClippedPoly<typename points_adaptor<Points2D>::scalar> >& result,
	detail::ClippingContext<typename points_adaptor<Points2D>::scalar>* ctxt)
{
	typedef points_adaptor<Points2D> 					Adaptor;
	typedef typename Adaptor::scalar					T;
	typedef typename Adaptor::elem_type					point_type;
	typedef typename Adaptor::const_elem_ref			const_point_ref;
	typedef ClippedPoly<T> 								polyclip_type;
	typedef typename polyclip_type::intersection		polyclip_intersection;

	typedef std::multimap<T, unsigned int>							onplane_lookup;
	typedef boost::unordered_multimap<unsigned int, unsigned int>	edge_lookup;
	typedef boost::unordered_set<unsigned int>						visited_verts_set;
	typedef boost::unordered_map<unsigned int, unsigned int>		shared_verts_map;

	Adaptor a(points);

	unsigned int npoints = a.size();
	assert(a.size() > 2);

	static const unsigned int shared_offset = std::numeric_limits<unsigned int>::max()/2;
	bool shared_vert_check = (npoints > 4);
	visited_verts_set visited_verts;
	shared_verts_map shared_vert_remap;

	unsigned int index1, index2;
	index1 = a.index(0);
	if(shared_vert_check)
		visited_verts.insert(index1);

	std::vector<polyclip_intersection> onplanePoints;
	std::vector<unsigned int> insidePoints;

	polyclip_intersection edgeInt;
	point_type line_dir = plane.dir();
	bool anyPtOutside = false;
	bool ptInsideNext;
	bool ptInside = (ctxt)? ctxt->isPointInside(index1) : plane.isRight(a[0]);

	onplane_lookup intersectionsOut, intersectionsIn;
	edge_lookup edges(npoints);

	// do the clip. Note that onplane points are indexed as i+npoints and are adjusted after
	for(unsigned int i=0; i<npoints; ++i, ptInside=ptInsideNext, index1=index2)
	{
		unsigned int j = (i+1) % npoints;
		const_point_ref pt_i = a[i];
		const_point_ref pt_j = a[j];

		index2 = a.index(j);
		anyPtOutside |= !ptInside;
		ptInsideNext = (ctxt)? ctxt->isPointInside(index2) : plane.isRight(pt_j);

		if((j>0) && shared_vert_check && !visited_verts.insert(index2).second)
		{
			unsigned int alias_index = shared_offset + shared_vert_remap.size();
			shared_vert_remap.insert(shared_verts_map::value_type(alias_index, index2));
			index2 = alias_index;
		}

		if(ptInsideNext != ptInside)
		{
			// calc edge intersection with line
			edgeInt.m_point1 = index1;
			edgeInt.m_point2 = index2;
			plane.intersect(pt_i, pt_j, edgeInt.m_u);

			// if the edge is almost exactly parallel to the plane it is possible to
			// get a spurious value due to float-pt inaccuracy - solve the prob in double
			if((edgeInt.m_u <= 0) || (edgeInt.m_u >= 1))
			{
				if(boost::is_same<T,double>::value)
					edgeInt.m_u = std::min(std::max(edgeInt.m_u, T(0.0)), T(1.0));
				else
				{
					Line2<double> plane_d(plane);
					Imath::V2d ptd_i(pt_i);
					Imath::V2d ptd_j(pt_j);
					double u;
					plane_d.intersect(ptd_i, ptd_j, u);
					u = std::min(std::max(u, 0.0), 1.0);
					edgeInt.m_u = static_cast<T>(u);
				}
			}

			// sort intersection wrt line dir
			point_type pt_int = pt_i + (pt_j-pt_i)*edgeInt.m_u;
			T dist = pt_int.dot(line_dir);

			unsigned int vert_int = onplanePoints.size() + npoints;
			onplanePoints.push_back(edgeInt);

			if(ptInside)
				intersectionsOut.insert(typename onplane_lookup::value_type(dist, vert_int));
			else
				intersectionsIn.insert(typename onplane_lookup::value_type(dist, vert_int));

			if(ptInside)
//.........这里部分代码省略.........
开发者ID:Kthulhu,项目名称:vfxgal,代码行数:101,代码来源:clipPoly2D.hpp


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