|
|
|
@@ -61,7 +61,7 @@ static coordf_t troctWave(coordf_t pos, coordf_t gridSize, coordf_t Zpos)
|
|
|
|
|
|
|
|
|
|
// Identify the important points of curve change within a truncated
|
|
|
|
|
// octahedron wave (as waveform fraction t):
|
|
|
|
|
// 1. Start of wave (always 0.0)
|
|
|
|
|
// 1. Start of wave (always 0.0; not needed if the pattern base starts here)
|
|
|
|
|
// 2. Transition to upper "horizontal" part
|
|
|
|
|
// 3. Transition from upper "horizontal" part
|
|
|
|
|
// 4. Transition to lower "horizontal" part
|
|
|
|
@@ -73,17 +73,11 @@ static coordf_t troctWave(coordf_t pos, coordf_t gridSize, coordf_t Zpos)
|
|
|
|
|
* \ /
|
|
|
|
|
* o---o
|
|
|
|
|
*/
|
|
|
|
|
static std::vector<coordf_t> getCriticalPoints(coordf_t Zpos, coordf_t gridSize)
|
|
|
|
|
static std::vector<coordf_t> getCriticalPoints(coordf_t Zpos, coordf_t gridSize)
|
|
|
|
|
{
|
|
|
|
|
std::vector<coordf_t> res = {0.};
|
|
|
|
|
std::vector<coordf_t> res;
|
|
|
|
|
coordf_t perpOffset = abs(triWave(Zpos, gridSize) / 2.);
|
|
|
|
|
|
|
|
|
|
coordf_t normalisedOffset = perpOffset / gridSize;
|
|
|
|
|
// // for debugging: just generate evenly-distributed points
|
|
|
|
|
// for(coordf_t i = 0; i < 2; i += 0.05){
|
|
|
|
|
// res.push_back(gridSize * i);
|
|
|
|
|
// }
|
|
|
|
|
// note: 0 == straight line
|
|
|
|
|
if(normalisedOffset > 0){
|
|
|
|
|
res.push_back(gridSize * (0. + normalisedOffset));
|
|
|
|
|
res.push_back(gridSize * (1. - normalisedOffset));
|
|
|
|
@@ -93,113 +87,251 @@ static std::vector<coordf_t> getCriticalPoints(coordf_t Zpos, coordf_t gridSize)
|
|
|
|
|
return(res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate an array of points that are in the same direction as the
|
|
|
|
|
// basic printing line (i.e. Y points for columns, X points for rows)
|
|
|
|
|
// Note: a negative offset only causes a change in the perpendicular
|
|
|
|
|
// direction
|
|
|
|
|
static std::vector<coordf_t> colinearPoints(const coordf_t Zpos, coordf_t gridSize, std::vector<coordf_t> critPoints,
|
|
|
|
|
const size_t baseLocation, size_t gridLength)
|
|
|
|
|
// Add additional dense fill in line with the pattern direction to
|
|
|
|
|
// cover the top squares of the pattern
|
|
|
|
|
static Polylines addTops(coordf_t Zpos, coordf_t gridSize, coordf_t lengthX, coordf_t lengthY, coordf_t spacing,
|
|
|
|
|
size_t multiline_count, size_t topDistance)
|
|
|
|
|
{
|
|
|
|
|
std::vector<coordf_t> points;
|
|
|
|
|
points.push_back(baseLocation);
|
|
|
|
|
for (coordf_t cLoc = baseLocation; cLoc < gridLength; cLoc+= (gridSize*2)) {
|
|
|
|
|
for(size_t pi = 0; pi < critPoints.size(); pi++){
|
|
|
|
|
points.push_back(baseLocation + cLoc + critPoints[pi]);
|
|
|
|
|
coordf_t zCycle = fmod(Zpos + gridSize/2, gridSize * 2.) / (gridSize * 2.);
|
|
|
|
|
coordf_t zHalfCycle = fmod(zCycle, 0.5) * 2.;
|
|
|
|
|
bool printVert = zCycle < 0.5;
|
|
|
|
|
coordf_t offsetX = multiline_count;
|
|
|
|
|
coordf_t offsetY = multiline_count;
|
|
|
|
|
coordf_t perpOffset = abs(triWave(Zpos, gridSize) / 2.);
|
|
|
|
|
coordf_t gridPoint = gridSize * (0. + perpOffset / gridSize);
|
|
|
|
|
coordf_t topOffset = gridSize / 2.0 - abs(troctWave(gridPoint, gridSize, Zpos));
|
|
|
|
|
coordf_t multilineAdjust = (sqrt(2) - 1.0) / 2.;
|
|
|
|
|
Polylines lines;
|
|
|
|
|
size_t pointCount = 0;
|
|
|
|
|
coordf_t gridStartL = gridSize * 0.5 - topOffset;
|
|
|
|
|
coordf_t gridEndL = gridSize * 0.5 + topOffset;
|
|
|
|
|
if((topDistance == 0) && (multiline_count == 1)){
|
|
|
|
|
// extend out a little bit on the first layer to help fuse the cover
|
|
|
|
|
gridStartL -= spacing;
|
|
|
|
|
gridEndL += spacing;
|
|
|
|
|
} else if(multiline_count > 1) {
|
|
|
|
|
// match start point to the corner edge
|
|
|
|
|
gridStartL -= spacing * multiline_count * multilineAdjust;
|
|
|
|
|
gridEndL += spacing * multiline_count * multilineAdjust;
|
|
|
|
|
}
|
|
|
|
|
// top cover extents perpendicular to the direction of travel
|
|
|
|
|
coordf_t gridStartP = gridSize * 0.5 - topOffset + spacing * multiline_count / 2. + spacing / 2.;
|
|
|
|
|
coordf_t gridEndP = gridSize * 0.5 + topOffset - spacing * multiline_count / 2. - spacing / 2.;
|
|
|
|
|
coordf_t x, y;
|
|
|
|
|
int xm, ym;
|
|
|
|
|
// if the print direction needs to be rotated, then swap the extents
|
|
|
|
|
if((topDistance % 2) == 0){
|
|
|
|
|
std::swap(gridStartL, gridStartP);
|
|
|
|
|
std::swap(gridEndL, gridEndP);
|
|
|
|
|
}
|
|
|
|
|
// adjust spacing so that it starts and ends on exactly the right place
|
|
|
|
|
// and increase fill density slightly to reduce gaps
|
|
|
|
|
coordf_t region_count = floor((gridEndP - gridStartP) / (spacing / sqrt(2)));
|
|
|
|
|
if(region_count <= 0){
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
spacing = (gridEndP - gridStartP) / region_count;
|
|
|
|
|
for (x = offsetX, xm = 0; x <= (lengthX); x+= gridSize, xm = xm ^ 1) {
|
|
|
|
|
for (y = offsetY, ym = 0; y <= (lengthY); y += gridSize, ym = ym ^ 1) {
|
|
|
|
|
if(((xm ^ ym) == 1) == printVert){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// // For debugging: remove 0,0 -> 1,1 top to help understand orientation
|
|
|
|
|
// if((x <= (gridSize + EPSILON)) && (y <= (gridSize + EPSILON)) && ((y - x) < EPSILON)){
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
Polyline newPoints;
|
|
|
|
|
int dirMod = xm ^ ym;
|
|
|
|
|
if(printVert == (topDistance % 2)){
|
|
|
|
|
if(y < (lengthY - spacing * multiline_count * 1.5)){
|
|
|
|
|
coordf_t endPMod = std::min(lengthX - (multiline_count * (spacing + 1) / 2.), x + gridEndP) - x;
|
|
|
|
|
coordf_t endLMod = std::min(lengthY - (multiline_count * (spacing + 1) / 2.), y + gridEndL) - y;
|
|
|
|
|
for(coordf_t xi = gridStartP; xi < (endPMod + EPSILON); xi += spacing, dirMod = dirMod ^ 1){
|
|
|
|
|
newPoints.points.push_back((dirMod == 0) ? Point(x + xi, y + gridStartL) : Point(x + xi, y + endLMod));
|
|
|
|
|
newPoints.points.push_back((dirMod == 0) ? Point(x + xi, y + endLMod) : Point(x + xi, y + gridStartL));
|
|
|
|
|
pointCount += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if(x < (lengthX - spacing * multiline_count * 1.5)){
|
|
|
|
|
coordf_t endPMod = std::min(lengthY - (multiline_count * (spacing + 1) / 2.), y + gridEndP) - y;
|
|
|
|
|
coordf_t endLMod = std::min(lengthX - (multiline_count * (spacing + 1) / 2.), x + gridEndL) - x;
|
|
|
|
|
for(coordf_t yi = gridStartP; yi < (endPMod + EPSILON); yi += spacing, dirMod = dirMod ^ 1){
|
|
|
|
|
newPoints.points.push_back((dirMod == 0) ? Point(x + gridStartL, y + yi) : Point(x + endLMod, y + yi));
|
|
|
|
|
newPoints.points.push_back((dirMod == 0) ? Point(x + endLMod, y + yi) : Point(x + gridStartL, y + yi));
|
|
|
|
|
pointCount += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lines.push_back(newPoints);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
points.push_back(gridLength);
|
|
|
|
|
return points;
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate an array of points for the dimension that is perpendicular to
|
|
|
|
|
// the basic printing line (i.e. X points for columns, Y points for rows)
|
|
|
|
|
static std::vector<coordf_t> perpendPoints(const coordf_t Zpos, coordf_t gridSize, std::vector<coordf_t> critPoints,
|
|
|
|
|
size_t baseLocation, size_t gridLength,
|
|
|
|
|
size_t offsetBase, coordf_t perpDir)
|
|
|
|
|
// Generate a set of polylines that complete octahedron curves on the
|
|
|
|
|
// extremities of a pattern
|
|
|
|
|
static Polylines makeEndPoints(const coordf_t Zpos, coordf_t gridSize, std::vector<coordf_t> critPoints,
|
|
|
|
|
coordf_t lengthX, coordf_t lengthY, coordf_t spacing, size_t multiline_count)
|
|
|
|
|
{
|
|
|
|
|
std::vector<coordf_t> points;
|
|
|
|
|
points.push_back(offsetBase);
|
|
|
|
|
for (coordf_t cLoc = baseLocation; cLoc < gridLength; cLoc+= gridSize*2) {
|
|
|
|
|
for(size_t pi = 0; pi < critPoints.size(); pi++){
|
|
|
|
|
Polylines lines;
|
|
|
|
|
coordf_t zCycle = fmod(Zpos + gridSize/2, gridSize * 2.) / (gridSize * 2.);
|
|
|
|
|
bool printVert = zCycle < 0.5;
|
|
|
|
|
bool printHoriz = zCycle >= 0.5;
|
|
|
|
|
int zFlipOffset = ((sgn(fmod(zCycle, 0.5) - 0.25) > 0) == printVert) ? 0 : 1;
|
|
|
|
|
// create templates for copying
|
|
|
|
|
Polylines startLines, endLines;
|
|
|
|
|
for(size_t li = 0; li < multiline_count; li++){
|
|
|
|
|
coordf_t oAdj = (li - ((multiline_count - 1) / 2.)) * spacing; // orthogonal line adjustment
|
|
|
|
|
coordf_t dAdj = oAdj * sqrt(2); // diagonal line adjustment
|
|
|
|
|
Polyline startLine, endLine;
|
|
|
|
|
// Left Bottom; Bottom Left
|
|
|
|
|
startLine.points.push_back(printHoriz ? Point(oAdj, -dAdj) : Point(-dAdj, oAdj));
|
|
|
|
|
// Right Bottom; Top Left
|
|
|
|
|
endLine.points.push_back(printHoriz ? Point(-oAdj, -dAdj) : Point(-dAdj, -oAdj));
|
|
|
|
|
for(size_t pi = 0; pi < 2; pi++){
|
|
|
|
|
int pDir = pi * 2 - 1;
|
|
|
|
|
coordf_t pAdj = pDir * (sqrt(2) - 1) * oAdj;
|
|
|
|
|
coordf_t troctOffset = abs(troctWave(critPoints[pi], gridSize, Zpos));
|
|
|
|
|
startLine.points.push_back(printHoriz ?
|
|
|
|
|
Point(-troctOffset, critPoints[pi] + pAdj) :
|
|
|
|
|
Point(critPoints[pi] + pAdj, -troctOffset));
|
|
|
|
|
endLine.points.push_back(printHoriz ?
|
|
|
|
|
Point(troctOffset, critPoints[pi] + pAdj) :
|
|
|
|
|
Point(critPoints[pi] + pAdj, troctOffset));
|
|
|
|
|
}
|
|
|
|
|
// Left Top; Bottom Right
|
|
|
|
|
startLine.points.push_back(printHoriz ? Point(oAdj, gridSize + dAdj) : Point(gridSize + dAdj, oAdj));
|
|
|
|
|
// Right Top; Top Right
|
|
|
|
|
endLine.points.push_back(printHoriz ? Point(-oAdj, gridSize + dAdj) : Point(gridSize + dAdj, -oAdj));
|
|
|
|
|
startLines.push_back(startLine);
|
|
|
|
|
endLines.push_back(endLine);
|
|
|
|
|
}
|
|
|
|
|
coordf_t gridMaxX = ceil((lengthX - EPSILON) / gridSize) * gridSize;
|
|
|
|
|
coordf_t gridMaxY = ceil((lengthY - EPSILON) / gridSize) * gridSize;
|
|
|
|
|
for(size_t li = 0; li < multiline_count; li++){
|
|
|
|
|
coordf_t mlFactor = (li - ((multiline_count - 1) / 2.)) * spacing;
|
|
|
|
|
for (coordf_t cLoc = zFlipOffset * gridSize; cLoc < ((printHoriz ? gridMaxY : gridMaxX) - EPSILON); cLoc += gridSize * 2) {
|
|
|
|
|
Polyline tsLine(startLines[li]);
|
|
|
|
|
Polyline teLine(endLines[li]);
|
|
|
|
|
tsLine.translate(printVert ? Point(cLoc, -mlFactor) : Point(-mlFactor, cLoc));
|
|
|
|
|
teLine.translate(printVert ? Point(cLoc, gridMaxY + mlFactor) : Point(gridMaxX + mlFactor, cLoc));
|
|
|
|
|
lines.push_back(tsLine);
|
|
|
|
|
lines.push_back(teLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate a polyline that describes a single path segment through
|
|
|
|
|
// the infill in the same direction as the basic printing line (i.e. X
|
|
|
|
|
// points for columns, Y points for rows)
|
|
|
|
|
static Polyline patternPoints(const coordf_t Zpos, coordf_t gridSize, std::vector<coordf_t> critPoints,
|
|
|
|
|
coordf_t gridLength, coordf_t perpDir, int print_dir, coordf_t oAdj)
|
|
|
|
|
{
|
|
|
|
|
Polyline line;
|
|
|
|
|
coordf_t dAdj = oAdj * (sqrt(2) - 1); // additional diagonal adjustment
|
|
|
|
|
coordf_t zCycle = fmod(Zpos + gridSize/2, gridSize * 2.) / (gridSize * 2.);
|
|
|
|
|
int zFlipDirection = sgn(fmod(zCycle, 0.5) - 0.25);
|
|
|
|
|
bool hitEnd = false;
|
|
|
|
|
int endPi = -1;
|
|
|
|
|
size_t pi = 0;
|
|
|
|
|
size_t piOfs = 0;
|
|
|
|
|
line.points.push_back((print_dir == 1) ? Point(dAdj, 0.) : Point(0., dAdj));
|
|
|
|
|
coordf_t gridMax = ceil((gridLength - EPSILON) / gridSize) * gridSize;
|
|
|
|
|
for (coordf_t cLoc = 0; cLoc < gridMax; cLoc += gridSize, piOfs = (piOfs + 2) % 4) {
|
|
|
|
|
for(pi = piOfs; pi < (piOfs + 2); pi++){
|
|
|
|
|
coordf_t offset = troctWave(critPoints[pi], gridSize, Zpos);
|
|
|
|
|
points.push_back(offsetBase + (offset * perpDir));
|
|
|
|
|
coordf_t offsetFlip = sgn(offset);
|
|
|
|
|
coordf_t posFlip = floor(((pi + 1) % 4) / 2) * 2 - 1;
|
|
|
|
|
coordf_t posLin = cLoc - (piOfs * gridSize / 2.) + critPoints[pi];
|
|
|
|
|
coordf_t posPerp = offset * perpDir;
|
|
|
|
|
line.points.push_back((print_dir == 1) ?
|
|
|
|
|
Point(posPerp, posLin + posFlip * dAdj * perpDir * zFlipDirection * print_dir) :
|
|
|
|
|
Point(posLin + posFlip * dAdj * perpDir * zFlipDirection * print_dir, posPerp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
points.push_back(offsetBase);
|
|
|
|
|
return points;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline Pointfs zip(const std::vector<coordf_t> &x, const std::vector<coordf_t> &y)
|
|
|
|
|
{
|
|
|
|
|
assert(x.size() == y.size());
|
|
|
|
|
Pointfs out;
|
|
|
|
|
out.reserve(x.size());
|
|
|
|
|
for (size_t i = 0; i < x.size(); ++ i)
|
|
|
|
|
out.push_back(Vec2d(x[i], y[i]));
|
|
|
|
|
return out;
|
|
|
|
|
line.points.push_back((print_dir == 1) ? Point(dAdj, gridMax) : Point(gridMax, dAdj));
|
|
|
|
|
return line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate a set of curves (array of array of 2d points) that describe a
|
|
|
|
|
// horizontal slice of a truncated regular octahedron.
|
|
|
|
|
static std::vector<Pointfs> makeActualGrid(coordf_t Zpos, coordf_t gridSize, size_t boundsX, size_t boundsY)
|
|
|
|
|
static Polylines makeZigZag(coordf_t Zpos, coordf_t gridSize, coordf_t lengthX, coordf_t lengthY,
|
|
|
|
|
coordf_t spacing, size_t multiline_count)
|
|
|
|
|
{
|
|
|
|
|
std::vector<Pointfs> points;
|
|
|
|
|
Polylines lines;
|
|
|
|
|
std::vector<coordf_t> critPoints = getCriticalPoints(Zpos, gridSize);
|
|
|
|
|
coordf_t zCycle = fmod(Zpos + gridSize/2, gridSize * 2.) / (gridSize * 2.);
|
|
|
|
|
bool printVert = zCycle < 0.5;
|
|
|
|
|
if (printVert) {
|
|
|
|
|
int perpDir = -1;
|
|
|
|
|
for (coordf_t x = 0; x <= (boundsX); x+= gridSize, perpDir *= -1) {
|
|
|
|
|
points.push_back(Pointfs());
|
|
|
|
|
Pointfs &newPoints = points.back();
|
|
|
|
|
newPoints = zip(
|
|
|
|
|
perpendPoints(Zpos, gridSize, critPoints, 0, boundsY, x, perpDir),
|
|
|
|
|
colinearPoints(Zpos, gridSize, critPoints, 0, boundsY));
|
|
|
|
|
BoundingBox extents;
|
|
|
|
|
int perpDir = -1;
|
|
|
|
|
int perpDirPattern = -1;
|
|
|
|
|
coordf_t gridMax = ceil(((printVert ? lengthX : lengthY) - EPSILON) / gridSize) * gridSize;
|
|
|
|
|
for (coordf_t pPos = 0; pPos < gridMax; pPos += gridSize, perpDirPattern *= -1) {
|
|
|
|
|
for (size_t li = 0; li < multiline_count; li++){
|
|
|
|
|
coordf_t oAdj = (li - ((multiline_count - 1) / 2.)) * spacing; // orthogonal line adjustment
|
|
|
|
|
Polyline newPoints;
|
|
|
|
|
newPoints = patternPoints(Zpos, gridSize, critPoints,
|
|
|
|
|
printVert ? lengthY : lengthX,
|
|
|
|
|
perpDirPattern, printVert ? 1 : -1, oAdj);
|
|
|
|
|
if (perpDir == 1)
|
|
|
|
|
std::reverse(newPoints.begin(), newPoints.end());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
int perpDir = 1;
|
|
|
|
|
for (coordf_t y = gridSize; y <= (boundsY); y+= gridSize, perpDir *= -1) {
|
|
|
|
|
points.push_back(Pointfs());
|
|
|
|
|
Pointfs &newPoints = points.back();
|
|
|
|
|
newPoints = zip(
|
|
|
|
|
colinearPoints(Zpos, gridSize, critPoints, 0, boundsX),
|
|
|
|
|
perpendPoints(Zpos, gridSize, critPoints, 0, boundsX, y, perpDir));
|
|
|
|
|
if (perpDir == -1)
|
|
|
|
|
std::reverse(newPoints.begin(), newPoints.end());
|
|
|
|
|
std::reverse(newPoints.points.begin(), newPoints.points.end());
|
|
|
|
|
newPoints.translate(printVert ? Point(pPos + oAdj, 0.) : Point(0., pPos + oAdj));
|
|
|
|
|
extents.merge(newPoints.points);
|
|
|
|
|
lines.push_back(newPoints);
|
|
|
|
|
perpDir *= -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return points;
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate a set of curves (array of array of 2d points) that describe a
|
|
|
|
|
// horizontal slice of a truncated regular octahedron with a specified
|
|
|
|
|
// grid square size.
|
|
|
|
|
// gridWidth and gridHeight define the width and height of the bounding box respectively
|
|
|
|
|
static Polylines makeGrid(coordf_t z, coordf_t gridSize, coordf_t boundWidth, coordf_t boundHeight, bool fillEvenly)
|
|
|
|
|
// Note: this uses the 'complete' infill parameter to determine if the
|
|
|
|
|
// square tops should be enclosed (true) or open (false). Alternatively,
|
|
|
|
|
// a rotation angle of 180 degrees or greater can be used.
|
|
|
|
|
static Polylines makeGrid(coordf_t z, coordf_t zLast, coordf_t gridSize,
|
|
|
|
|
coordf_t lengthX, coordf_t lengthY,
|
|
|
|
|
bool completeTops, coordf_t spacing, size_t multiline_count, size_t layer_count)
|
|
|
|
|
{
|
|
|
|
|
std::vector<Pointfs> polylines = makeActualGrid(z, gridSize, boundWidth, boundHeight);
|
|
|
|
|
coordf_t zCycle = fmod(z + gridSize/2, gridSize * 2.) / (gridSize * 2.);
|
|
|
|
|
bool printVert = zCycle < 0.5;
|
|
|
|
|
coordf_t zCycleLast = fmod(zLast + gridSize/2, gridSize * 2.) / (gridSize * 2.);
|
|
|
|
|
bool printVertLast = zCycleLast < 0.5;
|
|
|
|
|
Polylines result;
|
|
|
|
|
result.reserve(polylines.size());
|
|
|
|
|
for (std::vector<Pointfs>::const_iterator it_polylines = polylines.begin();
|
|
|
|
|
it_polylines != polylines.end(); ++ it_polylines) {
|
|
|
|
|
result.push_back(Polyline());
|
|
|
|
|
Polyline &polyline = result.back();
|
|
|
|
|
for (Pointfs::const_iterator it = it_polylines->begin(); it != it_polylines->end(); ++ it)
|
|
|
|
|
polyline.points.push_back(Point(coord_t((*it)(0)), coord_t((*it)(1))));
|
|
|
|
|
Polylines polyZag = makeZigZag(z, gridSize, lengthX, lengthY, spacing, multiline_count);
|
|
|
|
|
result.insert(result.end(), polyZag.begin(), polyZag.end());
|
|
|
|
|
// add end connectors
|
|
|
|
|
std::vector<coordf_t> critPoints = getCriticalPoints(z, gridSize);
|
|
|
|
|
Polylines endPoints = makeEndPoints(z, gridSize, critPoints, lengthX, lengthY, spacing, multiline_count);
|
|
|
|
|
result.insert(result.end(), endPoints.begin(), endPoints.end());
|
|
|
|
|
// add tops for the first <multiline_count> layers in each cycle
|
|
|
|
|
if(completeTops && (printVert != printVertLast)){
|
|
|
|
|
coordf_t layerHeight = (z - zLast) / (multiline_count * layer_count);
|
|
|
|
|
size_t top_distance = 0;
|
|
|
|
|
for(coordf_t zCheck = z; zCheck >= (zLast + EPSILON); zCheck -= layerHeight * layer_count, top_distance++){
|
|
|
|
|
coordf_t zCheckCycle = fmod(zCheck + gridSize/2, gridSize * 2.) / (gridSize * 2.);
|
|
|
|
|
if(printVert != (zCheckCycle < 0.5)){
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Polylines polytops = addTops(z, gridSize, lengthX, lengthY, spacing, multiline_count, top_distance);
|
|
|
|
|
result.insert(result.end(), polytops.begin(), polytops.end());
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FillParams has the following useful information:
|
|
|
|
|
// density <0 .. 1> [proportion of space to fill]
|
|
|
|
|
// anchor_length [???]
|
|
|
|
|
// anchor_length_max [???]
|
|
|
|
|
// dont_connect() [avoid connect lines]
|
|
|
|
|
// dont_adjust [avoid filling space evenly]
|
|
|
|
|
// monotonic [fill strictly left to right]
|
|
|
|
|
// complete [complete each loop]
|
|
|
|
|
// multiline [number of lines to draw for each pattern line]
|
|
|
|
|
// complete_top [should the top surfaces of the pattern be filled]
|
|
|
|
|
|
|
|
|
|
void Fill3DHoneycomb::_fill_surface_single(
|
|
|
|
|
const FillParams ¶ms,
|
|
|
|
@@ -208,78 +340,62 @@ void Fill3DHoneycomb::_fill_surface_single(
|
|
|
|
|
ExPolygon expolygon,
|
|
|
|
|
Polylines &polylines_out)
|
|
|
|
|
{
|
|
|
|
|
// no rotation is supported for this infill pattern
|
|
|
|
|
// Support infill angle
|
|
|
|
|
auto infill_angle = float(this->angle);
|
|
|
|
|
if (std::abs(infill_angle) >= EPSILON) expolygon.rotate(-infill_angle);
|
|
|
|
|
BoundingBox bb = expolygon.contour.bounding_box();
|
|
|
|
|
|
|
|
|
|
// Expand the bounding box to avoid artifacts at the edges
|
|
|
|
|
coord_t expand = 5 * (scale_(this->spacing));
|
|
|
|
|
bb.offset(expand);
|
|
|
|
|
// Increase the bounding box outwards to avoid edge clipping artefacts
|
|
|
|
|
coord_t expandSize = 5. * scale_(this->spacing);
|
|
|
|
|
bb.offset(expandSize);
|
|
|
|
|
|
|
|
|
|
// Adjustment for combining infill setting
|
|
|
|
|
size_t layersPerSlice = 1;
|
|
|
|
|
if(thickness_layers > 0){
|
|
|
|
|
layersPerSlice = thickness_layers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Note: with equally-scaled X/Y/Z, the pattern will create a vertically-stretched
|
|
|
|
|
// truncated octahedron; so Z is pre-adjusted first by scaling by sqrt(2)
|
|
|
|
|
coordf_t zScale = sqrt(2);
|
|
|
|
|
|
|
|
|
|
// adjustment to account for the additional distance of octagram curves
|
|
|
|
|
// note: this only strictly applies for a rectangular area where the total
|
|
|
|
|
// Z travel distance is a multiple of the spacing... but it should
|
|
|
|
|
// be at least better than the prevous estimate which assumed straight
|
|
|
|
|
// lines
|
|
|
|
|
// Density adjustment to account for the additional distance of
|
|
|
|
|
// octagram curves. [This only strictly applies for a rectangular
|
|
|
|
|
// area where the total Z travel distance is a multiple of the
|
|
|
|
|
// spacing]
|
|
|
|
|
// = 4 * integrate(func=4*x(sqrt(2) - 1) + 1, from=0, to=0.25)
|
|
|
|
|
// = (sqrt(2) + 1) / 2 [... I think]
|
|
|
|
|
// make a first guess at the preferred grid Size
|
|
|
|
|
coordf_t gridSize = (scale_(this->spacing) * ((zScale + 1.) / 2.) * params.multiline / params.density);
|
|
|
|
|
|
|
|
|
|
// This density calculation is incorrect for many values > 25%, possibly
|
|
|
|
|
// due to quantisation error, so this value is used as a first guess, then the
|
|
|
|
|
// Z scale is adjusted to make the layer patterns consistent / symmetric
|
|
|
|
|
// This means that the resultant infill won't be an ideal truncated octahedron,
|
|
|
|
|
// but it should look better than the equivalent quantised version
|
|
|
|
|
|
|
|
|
|
//Orca: uses a fixed layer height to avoid inconsistent bridges and variable layer height artifacts.
|
|
|
|
|
//coordf_t layerHeight = scale_(thickness_layers);
|
|
|
|
|
coordf_t layerHeight = scale_(1.0);
|
|
|
|
|
// ceiling to an integer value of layers per Z
|
|
|
|
|
// (with a little nudge in case it's close to perfect)
|
|
|
|
|
// make a first guess at the preferred grid Size (in unscaled units)
|
|
|
|
|
coordf_t gridSize = (scale_(this->spacing) *
|
|
|
|
|
((zScale + 1.) / 2.) * params.multiline / params.density);
|
|
|
|
|
coordf_t layerHeight = scale_(params.layer_height);
|
|
|
|
|
coordf_t layersPerModule = floor((gridSize * 2) / (zScale * layerHeight) + 0.05);
|
|
|
|
|
if(params.density > 0.42){ // exact layer pattern for >42% density
|
|
|
|
|
// If a density over 42% is requested, set an exact layer pattern
|
|
|
|
|
if((params.density > 0.42) || (layersPerModule < 2)){
|
|
|
|
|
layersPerModule = 2;
|
|
|
|
|
// re-adjust the grid size for a partial octahedral path
|
|
|
|
|
// (scale of 1.1 guessed based on modeling)
|
|
|
|
|
gridSize = (scale_(this->spacing) * 1.1 * params.multiline / params.density);
|
|
|
|
|
// re-adjust zScale to make layering consistent
|
|
|
|
|
zScale = (gridSize * 2) / (layersPerModule * layerHeight);
|
|
|
|
|
} else {
|
|
|
|
|
if(layersPerModule < 2){
|
|
|
|
|
layersPerModule = 2;
|
|
|
|
|
}
|
|
|
|
|
// re-adjust zScale to make layering consistent
|
|
|
|
|
zScale = (gridSize * 2) / (layersPerModule * layerHeight);
|
|
|
|
|
// re-adjust the grid size to account for the new zScale
|
|
|
|
|
gridSize = (scale_(this->spacing) * ((zScale + 1.) / 2.) * params.multiline / params.density);
|
|
|
|
|
// re-calculate layersPerModule and zScale
|
|
|
|
|
layersPerModule = floor((gridSize * 2) / (zScale * layerHeight) + 0.05);
|
|
|
|
|
if(layersPerModule < 2){
|
|
|
|
|
layersPerModule = 2;
|
|
|
|
|
}
|
|
|
|
|
zScale = (gridSize * 2) / (layersPerModule * layerHeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// align bounding box to a multiple of our honeycomb grid module
|
|
|
|
|
// (a module is 2*$gridSize since one $gridSize half-module is
|
|
|
|
|
// growing while the other $gridSize half-module is shrinking)
|
|
|
|
|
bb.merge(align_to_grid(bb.min, Point(gridSize*4, gridSize*4)));
|
|
|
|
|
// align bounding box to a multiple of the octahedron grid so that
|
|
|
|
|
// layers with different starting points have matching origins
|
|
|
|
|
bb.merge(align_to_grid(bb.min, Point(gridSize * 2., gridSize * 2.)));
|
|
|
|
|
|
|
|
|
|
// Z adjustment to start at the widest point for the lowest layer
|
|
|
|
|
coordf_t startOffset = gridSize / 2. + scale_(params.layer_height / 2.);
|
|
|
|
|
// generate pattern
|
|
|
|
|
Polylines polylines =
|
|
|
|
|
makeGrid(
|
|
|
|
|
scale_(this->z) * zScale,
|
|
|
|
|
gridSize,
|
|
|
|
|
bb.size()(0),
|
|
|
|
|
bb.size()(1),
|
|
|
|
|
!params.dont_adjust);
|
|
|
|
|
scale_(this->z) * zScale + startOffset,
|
|
|
|
|
scale_(this->z - (params.layer_height * params.multiline * layersPerSlice)) * zScale + startOffset,
|
|
|
|
|
gridSize, bb.size()(0), bb.size()(1),
|
|
|
|
|
params.infill_complete_top,
|
|
|
|
|
scale_(this->spacing),
|
|
|
|
|
params.multiline,
|
|
|
|
|
layersPerSlice);
|
|
|
|
|
|
|
|
|
|
// move pattern in place
|
|
|
|
|
for (Polyline &pl : polylines){
|
|
|
|
@@ -290,8 +406,8 @@ void Fill3DHoneycomb::_fill_surface_single(
|
|
|
|
|
smooth_polyline_corners(pl, params.smooth_factor, scaled<double>(params.resolution));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply multiline offset if needed
|
|
|
|
|
multiline_fill(polylines, params, spacing);
|
|
|
|
|
// Note: multiline fill adjustment is carried out in this code,
|
|
|
|
|
// rather than using the multiline_fill function
|
|
|
|
|
|
|
|
|
|
// clip pattern to boundaries, chain the clipped polylines
|
|
|
|
|
polylines = intersection_pl(std::move(polylines), to_polygons(expolygon));
|
|
|
|
|