Add BoundBox property to Path, usable without a gui.

This commit is contained in:
Markus Lampert
2019-09-30 16:24:59 -07:00
parent 2520a5e159
commit 2ba54fe4cc
4 changed files with 87 additions and 0 deletions

View File

@@ -39,6 +39,7 @@
//#include "Mod/Robot/App/kdl_cp/utilities/error.h"
#include "Path.h"
#include <Mod/Path/App/PathSegmentWalker.h>
using namespace Path;
using namespace Base;
@@ -145,6 +146,78 @@ double Toolpath::getLength()
return l;
}
class BoundBoxSegmentVisitor : public PathSegmentVisitor
{
public:
BoundBoxSegmentVisitor()
{ }
virtual void g0(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque<Base::Vector3d> &pts)
{
(void)id;
processPt(last);
processPts(pts);
processPt(next);
}
virtual void g1(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque<Base::Vector3d> &pts)
{
(void)id;
processPt(last);
processPts(pts);
processPt(next);
}
virtual void g23(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque<Base::Vector3d> &pts, const Base::Vector3d &center)
{
(void)id;
(void)center;
processPt(last);
processPts(pts);
processPt(next);
}
virtual void g8x(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque<Base::Vector3d> &pts,
const std::deque<Base::Vector3d> &p, const std::deque<Base::Vector3d> &q)
{
(void)id;
(void)q; // always within the bounds of p
processPt(last);
processPts(pts);
processPts(p);
processPt(next);
}
virtual void g38(int id, const Base::Vector3d &last, const Base::Vector3d &next)
{
(void)id;
processPt(last);
processPt(next);
}
Base::BoundBox3d bb;
private:
void processPts(const std::deque<Base::Vector3d> &pts) {
for (std::deque<Base::Vector3d>::const_iterator it=pts.begin(); pts.end() != it; ++it) {
processPt(*it);
}
}
void processPt(const Base::Vector3d &pt) {
bb.MaxX = std::max(bb.MaxX, pt.x);
bb.MinX = std::min(bb.MinX, pt.x);
bb.MaxY = std::max(bb.MaxY, pt.y);
bb.MinY = std::min(bb.MinY, pt.y);
bb.MaxZ = std::max(bb.MaxZ, pt.z);
bb.MinZ = std::min(bb.MinZ, pt.z);
}
};
Base::BoundBox3d Toolpath::getBoundBox() const
{
BoundBoxSegmentVisitor visitor;
PathSegmentWalker walker(*this);
walker.walk(visitor, Vector3d(0, 0, 0));
return visitor.bb;
}
static void bulkAddCommand(const std::string &gcodestr, std::vector<Command*> &commands, bool &inches)
{
Command *cmd = new Command();