Path adaptive operation added

This commit is contained in:
kreso-t
2018-08-19 01:05:45 +02:00
committed by wmayer
parent 28c57af9a3
commit 3bde81ec85
12 changed files with 2964 additions and 3 deletions

View File

@@ -8,6 +8,7 @@
#include "Point.h"
#include "AreaDxf.h"
#include "kurve/geometry.h"
#include "Adaptive.hpp"
#if defined (_POSIX_C_SOURCE)
# undef _POSIX_C_SOURCE
@@ -38,6 +39,7 @@
#include <boost/python/wrapper.hpp>
#include <boost/python/call.hpp>
#include "clipper.hpp"
using namespace ClipperLib;
@@ -237,7 +239,6 @@ boost::python::list spanIntersect(const Span& span1, const Span& span2) {
}
//Matrix(boost::python::list &l){}
boost::shared_ptr<geoff_geometry::Matrix> matrix_constructor(const boost::python::list& lst) {
double m[16] = {1,0,0,0,0,1,0,0, 0,0,1,0, 0,0,0,1};
@@ -291,8 +292,70 @@ double AreaGetArea(const CArea& a)
return a.GetArea();
}
// Adaptive2d.Execute wrapper
bp::list AdaptiveExecute(AdaptivePath::Adaptive2d& ada,const boost::python::list &in_paths, boost::python::object progressCallbackFn) {
bp::list out_list;
// convert inputs
AdaptivePath::DPaths dpaths;
for(bp::ssize_t i=0;i<bp::len(in_paths);i++) {
bp::list in_path=bp::extract<boost::python::list>(in_paths[i]);
AdaptivePath::DPath dpath;
for(bp::ssize_t j=0;j<bp::len(in_path);j++) {
bp::list in_point = bp::extract<bp::list>(in_path[j]);
dpath.push_back(pair<double,double>(bp::extract<double>(in_point[0]),bp::extract<double>(in_point[1])));
}
dpaths.push_back(dpath);
}
// Execute with callback
std::list<AdaptivePath::AdaptiveOutput> result=ada.Execute(dpaths,[progressCallbackFn](AdaptivePath::TPaths tp)->bool {
bp::list out_paths;
for(const auto & in_pair : tp) {
bp::list path;
for(const auto & in_pt : in_pair.second) {
path.append(bp::make_tuple(in_pt.first,in_pt.second));
}
out_paths.append(bp::make_tuple(in_pair.first,path));
}
return bp::extract<bool>(progressCallbackFn(out_paths));
});
// convert outputs back
BOOST_FOREACH(const auto & res, result) {
out_list.append(res);
}
return out_list;
}
// Converts a std::pair instance to a Python tuple.
template <typename T1, typename T2>
struct std_pair_to_tuple
{
static PyObject* convert(std::pair<T1, T2> const& p)
{
return boost::python::incref(
boost::python::make_tuple(p.first, p.second).ptr());
}
static PyTypeObject const *get_pytype () {
return &PyTuple_Type;
}
};
boost::python::list AdaptiveOutput_AdaptivePaths(const AdaptivePath::AdaptiveOutput &ado) {
bp::list olist;
for(auto & ap : ado.AdaptivePaths) {
bp::list op;
for(auto & pt : ap.second) {
op.append(bp::make_tuple(pt.first, pt.second));
}
olist.append(bp::make_tuple(ap.first, op));
}
return olist;
}
BOOST_PYTHON_MODULE(area) {
bp::class_<Point>("Point")
bp::class_<Point>("Point")
.def(bp::init<double, double>())
.def(bp::init<Point>())
.def(bp::other<double>() * bp::self)
@@ -418,4 +481,43 @@ BOOST_PYTHON_MODULE(area) {
bp::def("holes_linked", holes_linked);
bp::def("AreaFromDxf", AreaFromDxf);
bp::def("TangentialArc", TangentialArc);
using namespace AdaptivePath;
boost::python::to_python_converter<std::pair<double, double>, std_pair_to_tuple<double, double>,true>();
bp::enum_<MotionType>("AdaptiveMotionType")
.value("Cutting", MotionType::mtCutting)
.value("LinkClear", MotionType::mtLinkClear)
.value("LinkNotClear", MotionType::mtLinkNotClear)
.value("LinkClearAtPrevPass", MotionType::mtLinkClearAtPrevPass);
bp::enum_<OperationType>("AdaptiveOperationType")
.value("Clearing", OperationType::otClearing)
.value("ProfilingInside", OperationType::otProfilingInside)
.value("ProfilingOutside", OperationType::otProfilingOutside);
bp::class_<AdaptiveOutput> ("AdaptiveOutput")
.def(bp::init<>())
.add_property("HelixCenterPoint", bp::make_getter(&AdaptiveOutput::HelixCenterPoint, bp::return_value_policy<bp::return_by_value>()))
.add_property("StartPoint", bp::make_getter(&AdaptiveOutput::StartPoint, bp::return_value_policy<bp::return_by_value>()))
.add_property("AdaptivePaths", &AdaptiveOutput_AdaptivePaths)
.def_readonly("ReturnMotionType",&AdaptiveOutput::ReturnMotionType);
bp::class_<Adaptive2d>("Adaptive2d")
.def(bp::init<>())
.def("Execute",&AdaptiveExecute)
.def_readwrite("stepOverFactor", &Adaptive2d::stepOverFactor)
.def_readwrite("toolDiameter", &Adaptive2d::toolDiameter)
.def_readwrite("helixRampDiameter", &Adaptive2d::helixRampDiameter)
.def_readwrite("polyTreeNestingLimit", &Adaptive2d::polyTreeNestingLimit)
.def_readwrite("tolerance", &Adaptive2d::tolerance)
.def_readwrite("opType", &Adaptive2d::opType);
}