我们有这样的图像(一个绿色多分支),我们想要优化(我们可以看到黄色点线 – 简化的结果,显然是在multi_polygon的每个poligon上执行的,而不是在多分支上)
这里是可编译的代码来生成这样的图像:
#include <iostream>#include <fstream>#include <boost/assign.hpp>#include <boost/algorithm/string.hpp>#include <boost/geometry/geometry.hpp>#include <boost/geometry/geometrIEs/geometrIEs.hpp>#include <boost/geometry/multi/geometrIEs/multi_polygon.hpp>#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>template <typename Geometry1,typename Geometry2>voID create_svg(std::string const& filename,Geometry1 const& a,Geometry2 const& b){ typedef typename boost::geometry::point_type<Geometry1>::type point_type; std::ofstream svg(filename.c_str()); boost::geometry::svg_mapper<point_type> mapper(svg,400,400); mapper.add(a); mapper.add(b); mapper.map(a,"fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,0);stroke-wIDth:2"); mapper.map(b,"opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-wIDth:4;stroke-dasharray:1,7;stroke-linecap:round");}boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > make_point(int x,int y){ boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > return_item; boost::geometry::model::d2::point_xy<double> p1(x,y); boost::geometry::model::d2::point_xy<double> p2(x-1,y); boost::geometry::model::d2::point_xy<double> p3(x-1,y-1); boost::geometry::model::d2::point_xy<double> p4(x,y-1); boost::geometry::append( return_item,p1); boost::geometry::append( return_item,p2); boost::geometry::append( return_item,p3); boost::geometry::append( return_item,p4); return return_item;}int main(){ // create a container for joined points structure boost::geometry::model::multi_polygon< boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > > output,simpl; // join points one by one (because one day we would have many=)) output.push_back(make_point(1,1)); boost::geometry::correct(output); output.push_back(make_point(2,1)); boost::geometry::correct(output); output.push_back(make_point(3,1)); boost::geometry::correct(output); output.push_back(make_point(4,1)); boost::geometry::correct(output); output.push_back(make_point(5,2)); boost::geometry::correct(output); output.push_back(make_point(3,2)); boost::geometry::correct(output); output.push_back(make_point(5,5)); boost::geometry::correct(output); // simplify joined structure boost::geometry::simplify(output,simpl,0.5); // create an svg image create_svg("make_envelope.svg",output,simpl );}
至少需要从boost/geometry/extensions/io/svg/提升1.47.0和3个档案
我需要的是简单的:如何组合相关的poligons?在这种情况下,我们会在这里显示如下的红色和绿色的两个poligons:
更新:
所以我在dissolve上找到了这个信息,并创建了使用环形创建的示例代码:
#include <iostream>#include <fstream>#include <boost/assign.hpp>//Boost#include <boost/algorithm/string.hpp>#include <boost/geometry/geometry.hpp>#include <boost/geometry/geometrIEs/geometrIEs.hpp>#include <boost/geometry/multi/geometrIEs/multi_polygon.hpp>#include <boost/geometry/geometrIEs/adapted/boost_tuple.hpp>BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)#include <boost/foreach.hpp>//Boost Geometry extensions (from trunk) #include <boost/geometry/extensions/io/svg/svg_mapper.hpp>template <typename Geometry1,"fill-rule:nonzero;fill-opacity:0.5;fill:rgb(153,0);stroke-wIDth:2;"); mapper.map(b,7;stroke-linecap:round");}voID make_point(int x,int y,boost::geometry::model::ring<boost::geometry::model::d2::point_xy<double> > & ring){ using namespace boost::assign; ring += boost::geometry::model::d2::point_xy<double>(x-1,y-1),boost::geometry::model::d2::point_xy<double>(x,y),boost::geometry::model::d2::point_xy<double>(x-1,y-1);}int main(){ using namespace boost::assign; boost::geometry::model::ring<boost::geometry::model::d2::point_xy<double> > ring0,ring1,ring; boost::geometry::model::multi_polygon< boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > > outputw; make_point(1,1,ring) ; make_point(2,ring) ; make_point(3,ring) ; make_point(4,ring) ; make_point(5,2,ring) ; boost::geometry::model::ring<boost::geometry::model::d2::point_xy<double> > output; boost::geometry::simplify(ring,1); // create an svg image create_svg("make_envelope.svg",ring,output );}
它返回这样的环形图像:
如果我们可以使用溶解剂将其转化成poligon,这将真正解决我的一些问题.但是看起来像现在我们不能因为这个编译错误的问题描述了here
解决方法 如何使用Qt.如果您使用QpolygonF,您可以调用unite,它完全符合您所需要的.一致后,您可以提取积分并将其放回您的增压容器.如果qt不是一个选项,请查看这里提出的算法http://www.wykobi.com
总结以上是内存溢出为你收集整理的c – Boost :: Geometry:如何在multi_polygon中加入相交的多边形?全部内容,希望文章能够帮你解决c – Boost :: Geometry:如何在multi_polygon中加入相交的多边形?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)