MeshLib C++ Docs
Loading...
Searching...
No Matches
MRToolPath.h
Go to the documentation of this file.
1#pragma once
2#include "MRVoxelsFwd.h"
3
4#include "MRMesh/MRAxis.h"
5#include "MRMesh/MRMesh.h"
6#include "MRMesh/MRPolyline.h"
8#include "MRMesh/MRExpected.h"
9
10namespace MR
11{
12
13enum class BypassDirection
14{
15 Clockwise,
16 CounterClockwise
17};
18
19struct ToolPathParams
20{
21 // radius of the milling tool
22 float millRadius = {};
23 // size of voxel needed to offset mesh
24 float voxelSize = {};
25 // distance between sections built along Z axis
26 // in Constant Cusp mode sectionStep should be bigger than voxelSize (x1.2 or more is recomended)
27 float sectionStep = {};
28 // if distance to the next section is smaller than it, transition will be performed along the surface
29 // otherwise transition will be through the safe plane
30 float critTransitionLength = {};
31 // when the mill is moving down, it will be slowed down in this distance from mesh
32 float plungeLength = {};
33 // when the mill is moving up, it will be slowed down in this distance from mesh
34 float retractLength = {};
35 // speed of slow movement down
36 float plungeFeed = {};
37 // speed of slow movement up
38 float retractFeed = {};
39 // speed of regular milling
40 float baseFeed = {};
41 // z-coordinate of plane where tool can move in any direction without touching the object
42 float safeZ = {};
43 // which direction isolines or sections should be passed in
44 BypassDirection bypassDir = BypassDirection::Clockwise;
45 // mesh can be transformed using xf parameter
46 const AffineXf3f* xf = nullptr;
47 // if true then a tool path for a flat milling tool will be generated
48 bool flatTool = false;
49 // callback for reporting on progress
50 ProgressCallback cb = {};
51
52 // if > 0 - expand the trajectory creation area and create toolpath to mill excess material to make empty areas.
53 // The area has the shape of a box.
54 // Lacing specific only.
55 float toolpathExpansion = 0.f;
56
57 // optional output, stores isolines without transits
58 Contours3f* isolines = nullptr;
59 // optional output, polyline containing start vertices for isolines
60 Contours3f* startContours = nullptr;
61 // start vertices on the offset mesh used for calcutating isolines
62 std::vector<Vector3f>* startVertices = nullptr;
63
64 MeshPart* offsetMesh = nullptr;
65};
66
67struct ConstantCuspParams : ToolPathParams
68{
69 // if true isolines will be processed from center point to the boundary (usually it means from up to down)
70 bool fromCenterToBoundary = true;
71};
72
73struct LineInterpolationParams
74{
75 // maximal deviation from given line
76 float eps = {};
77 // maximal length of the line
78 float maxLength = {};
79 // callback for reporting on progress
80 ProgressCallback cb = {};
81};
82
83struct ArcInterpolationParams
84{
85 // maximal deviation of arc from given path
86 float eps = {};
87 // maximal radius of the arc
88 float maxRadius = {};
89 // callback for reporting on progress
90 ProgressCallback cb = {};
91};
92
93enum class MoveType
94{
95 None = -1,
96 FastLinear = 0,
97 Linear = 1,
98 ArcCW = 2,
99 ArcCCW = 3
100};
101
102enum class ArcPlane
103{
104 None = -1,
105 XY = 17,
106 XZ = 18,
107 YZ = 19
108};
109
110struct GCommand
111{
112 // type of command GX (G0, G1, etc). By default - G1
113 MoveType type = MoveType::Linear;
114 // Place for comment
115 ArcPlane arcPlane = ArcPlane::None;
116 // feedrate for move
117 float feed = std::numeric_limits<float>::quiet_NaN();
118 // coordinates of destination point
119 float x = std::numeric_limits<float>::quiet_NaN();
120 float y = std::numeric_limits<float>::quiet_NaN();
121 float z = std::numeric_limits<float>::quiet_NaN();
122 // if moveType is ArcCW or ArcCCW center of the arc shoult be specified
123 Vector3f arcCenter = Vector3f::diagonal( std::numeric_limits<float>::quiet_NaN() );
124};
125
126struct ToolPathResult
127{
128 // mesh after fixing undercuts and offset
129 Mesh modifiedMesh;
130 // selected region projected from the original mesh to the offset
131 FaceBitSet modifiedRegion;
132 // constains type of movement and its feed
133 std::vector<GCommand> commands;
134};
135
136// compute path of the milling tool for the given mesh with parameters ( direction of milling is from up to down along Z-direction )
137// this toolpath is built from the parallel sections along Z-axis
138// mesh can be transformed using xf parameter
139
140MRVOXELS_API Expected<ToolPathResult> constantZToolPath( const MeshPart& mp, const ToolPathParams& params );
141
142// compute path of the milling tool for the given mesh with parameters ( direction of milling is from up to down along Z-direction )
143// // this one is traditional lace-roughing toolpath
144
145// Slices are built along the axis defined by cutDirection argument (can be Axis::X or Axis::Y)
146MRVOXELS_API Expected<ToolPathResult> lacingToolPath( const MeshPart& mp, const ToolPathParams& params, Axis cutDirection );
147
148// compute path of the milling tool for the given mesh with parameters ( direction of milling is from up to down along Z-direction )
149// this toolpath is built from geodesic parallels divercing from the given start point or from the bounaries of selected areas
150// if neither is specified, the lowest section by XY plane will be used as a start contour
151// mesh can be transformed using xf parameter
152MRVOXELS_API Expected<ToolPathResult> constantCuspToolPath( const MeshPart& mp, const ConstantCuspParams& params );
153
154// generates G-Code for milling tool
155MRVOXELS_API std::shared_ptr<ObjectGcode> exportToolPathToGCode( const std::vector<GCommand>& commands );
156
157// interpolates several points lying on the same straight line with one move
158MRVOXELS_API Expected<void> interpolateLines( std::vector<GCommand>& commands, const LineInterpolationParams& params, Axis axis );
159// interpolates given path with arcs
160MRVOXELS_API Expected<void> interpolateArcs( std::vector<GCommand>& commands, const ArcInterpolationParams& params, Axis axis );
161
162// makes the given selection more smooth with shifthing a boundary of the selection outside and back. Input mesh is changed because we have to cut new edges along the new boundaries
163// \param expandOffset defines how much the boundary is expanded
164// \param expandOffset defines how much the boundary is shrinked after that
165MRVOXELS_API FaceBitSet smoothSelection( Mesh& mesh, const FaceBitSet& region, float expandOffset, float shrinkOffset );
166
167}
#define MRVOXELS_API
Definition MRVoxelsFwd.h:14
Definition MRToolPath.h:84
Definition MRToolPath.h:68
Definition MRToolPath.h:74
Definition MRMesh/MRMesh.h:23
Definition MRToolPath.h:20
Definition MRCameraOrientationPlugin.h:8
MRVOXELS_API Expected< ToolPathResult > constantCuspToolPath(const MeshPart &mp, const ConstantCuspParams &params)
MRVOXELS_API std::shared_ptr< ObjectGcode > exportToolPathToGCode(const std::vector< GCommand > &commands)
MRVOXELS_API Expected< void > interpolateLines(std::vector< GCommand > &commands, const LineInterpolationParams &params, Axis axis)
MRVOXELS_API Expected< void > interpolateArcs(std::vector< GCommand > &commands, const ArcInterpolationParams &params, Axis axis)
MRVOXELS_API FaceBitSet smoothSelection(Mesh &mesh, const FaceBitSet &region, float expandOffset, float shrinkOffset)
MRVOXELS_API Expected< ToolPathResult > constantZToolPath(const MeshPart &mp, const ToolPathParams &params)
MRVOXELS_API Expected< ToolPathResult > lacingToolPath(const MeshPart &mp, const ToolPathParams &params, Axis cutDirection)
static MR.Vector3f diagonal(float a)