Skip to content

Commit

Permalink
Merge pull request #2565 from mlampert/feature/Path-BoundBox
Browse files Browse the repository at this point in the history
Path: add BoundBox property to Path object
  • Loading branch information
sliptonic committed Oct 2, 2019
2 parents d2be4f1 + e323216 commit cee9f4f
Show file tree
Hide file tree
Showing 8 changed files with 656 additions and 280 deletions.
2 changes: 2 additions & 0 deletions src/Mod/Path/App/CMakeLists.txt
Expand Up @@ -88,6 +88,8 @@ SET(Path_SRCS
ParamsHelper.h
FeatureArea.cpp
FeatureArea.h
PathSegmentWalker.h
PathSegmentWalker.cpp
${Mod_SRCS}
${Python_SRCS}
)
Expand Down
73 changes: 73 additions & 0 deletions src/Mod/Path/App/Path.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Path/App/Path.h
Expand Up @@ -27,6 +27,7 @@
#include "Command.h"
//#include "Mod/Robot/App/kdl_cp/path_composite.hpp"
//#include "Mod/Robot/App/kdl_cp/frames_io.hpp"
#include <Base/BoundBox.h>
#include <Base/Persistence.h>
#include <Base/Vector3D.h>

Expand Down Expand Up @@ -62,6 +63,7 @@ namespace Path
void recalculate(void); // recalculates the points
void setFromGCode(const std::string); // sets the path from the contents of the given GCode string
std::string toGCode(void) const; // gets a gcode string representation from the Path
Base::BoundBox3d getBoundBox(void) const;

// shortcut functions
unsigned int getSize(void) const { return vpcCommands.size(); }
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/Path/App/PathPy.xml
Expand Up @@ -40,6 +40,12 @@ commands (optional) is a list of Path commands</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="BoundBox" ReadOnly="true">
<Documentation>
<UserDocu>the extent of this path</UserDocu>
</Documentation>
<Parameter Name="BoundBox" Type="Object"/>
</Attribute>
<Methode Name="addCommands">
<Documentation>
<UserDocu>adds a command or a list of commands at the end of the path</UserDocu>
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/Path/App/PathPyImp.cpp
Expand Up @@ -29,6 +29,7 @@
#include "PathPy.h"
#include "PathPy.cpp"

#include "Base/BoundBoxPy.h"
#include "Base/GeometryPyCXX.h"
#include "CommandPy.h"

Expand Down Expand Up @@ -128,6 +129,11 @@ Py::Long PathPy::getSize(void) const
return Py::Long((long)getToolpathPtr()->getSize());
}

Py::Object PathPy::getBoundBox(void) const
{
return Py::BoundingBox(getToolpathPtr()->getBoundBox());
}

// specific methods

PyObject* PathPy::copy(PyObject * args)
Expand Down

0 comments on commit cee9f4f

Please sign in to comment.