本文整理汇总了C++中Polygons::addLine方法的典型用法代码示例。如果您正苦于以下问题:C++ Polygons::addLine方法的具体用法?C++ Polygons::addLine怎么用?C++ Polygons::addLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygons
的用法示例。
在下文中一共展示了Polygons::addLine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addLineInfill
void Infill::addLineInfill(Polygons& result, const PointMatrix& rotation_matrix, const int scanline_min_idx, const int line_distance, const AABB boundary, std::vector<std::vector<int64_t>>& cut_list, int64_t shift)
{
auto compare_int64_t = [](const void* a, const void* b)
{
int64_t n = (*(int64_t*)a) - (*(int64_t*)b);
if (n < 0)
{
return -1;
}
if (n > 0)
{
return 1;
}
return 0;
};
int scanline_idx = 0;
for(int64_t x = scanline_min_idx * line_distance + shift; x < boundary.max.X; x += line_distance)
{
std::vector<int64_t>& crossings = cut_list[scanline_idx];
qsort(crossings.data(), crossings.size(), sizeof(int64_t), compare_int64_t);
for(unsigned int crossing_idx = 0; crossing_idx + 1 < crossings.size(); crossing_idx += 2)
{
if (crossings[crossing_idx + 1] - crossings[crossing_idx] < infill_line_width / 5)
{ // segment is too short to create infill
continue;
}
result.addLine(rotation_matrix.unapply(Point(x, crossings[crossing_idx])), rotation_matrix.unapply(Point(x, crossings[crossing_idx + 1])));
}
scanline_idx += 1;
}
}
示例2: addLineSegmentsInfill
void Infill::addLineSegmentsInfill(Polygons& result, Polygons& input)
{
ClipperLib::PolyTree interior_segments_tree = in_outline.lineSegmentIntersection(input);
ClipperLib::Paths interior_segments;
ClipperLib::OpenPathsFromPolyTree(interior_segments_tree, interior_segments);
for (uint64_t idx = 0; idx < interior_segments.size(); idx++)
{
result.addLine(interior_segments[idx][0], interior_segments[idx][1]);
}
}
示例3: generateSubdivisionLines
void SubDivCube::generateSubdivisionLines(int64_t z, Polygons& result)
{
if (cube_properties_per_recursion_step.empty()) //Infill is set to 0%.
{
return;
}
Polygons directional_line_groups[3];
generateSubdivisionLines(z, result, directional_line_groups);
for (int dir_idx = 0; dir_idx < 3; dir_idx++)
{
Polygons& line_group = directional_line_groups[dir_idx];
for (unsigned int line_idx = 0; line_idx < line_group.size(); line_idx++)
{
result.addLine(line_group[line_idx][0], line_group[line_idx][1]);
}
}
}
示例4: addLineAndCombine
void SubDivCube::addLineAndCombine(Polygons& group, Point from, Point to)
{
int epsilon = 10; // the smallest distance of two points which are viewed as coincident (dist > 0 due to rounding errors)
for (unsigned int idx = 0; idx < group.size(); idx++)
{
if (std::abs(from.X - group[idx][1].X) < epsilon && std::abs(from.Y - group[idx][1].Y) < epsilon)
{
from = group[idx][0];
group.remove(idx);
idx--;
continue;
}
if (std::abs(to.X - group[idx][0].X) < epsilon && std::abs(to.Y - group[idx][0].Y) < epsilon)
{
to = group[idx][1];
group.remove(idx);
idx--;
continue;
}
}
group.addLine(from, to);
}
示例5: generateTotalGyroidInfill
void GyroidInfill::generateTotalGyroidInfill(Polygons& result_lines, bool zig_zaggify, coord_t outline_offset, coord_t infill_line_width, coord_t line_distance, const Polygons& in_outline, coord_t z)
{
// generate infill based on the gyroid equation: sin_x * cos_y + sin_y * cos_z + sin_z * cos_x = 0
// kudos to the author of the Slic3r implementation equation code, the equation code here is based on that
if (zig_zaggify)
{
outline_offset -= infill_line_width / 2; // the infill line zig zag connections must lie next to the border, not on it
}
const Polygons outline = in_outline.offset(outline_offset);
const AABB aabb(outline);
int pitch = line_distance * 2.41; // this produces similar density to the "line" infill pattern
int num_steps = 4;
int step = pitch / num_steps;
while (step > 500 && num_steps < 16)
{
num_steps *= 2;
step = pitch / num_steps;
}
pitch = step * num_steps; // recalculate to avoid precision errors
const double z_rads = 2 * M_PI * z / pitch;
const double cos_z = std::cos(z_rads);
const double sin_z = std::sin(z_rads);
std::vector<coord_t> odd_line_coords;
std::vector<coord_t> even_line_coords;
Polygons result;
std::vector<Point> chains[2]; // [start_points[], end_points[]]
std::vector<unsigned> connected_to[2]; // [chain_indices[], chain_indices[]]
std::vector<int> line_numbers; // which row/column line a chain is part of
if (std::abs(sin_z) <= std::abs(cos_z))
{
// "vertical" lines
const double phase_offset = ((cos_z < 0) ? M_PI : 0) + M_PI;
for (coord_t y = 0; y < pitch; y += step)
{
const double y_rads = 2 * M_PI * y / pitch;
const double a = cos_z;
const double b = std::sin(y_rads + phase_offset);
const double odd_c = sin_z * std::cos(y_rads + phase_offset);
const double even_c = sin_z * std::cos(y_rads + phase_offset + M_PI);
const double h = std::sqrt(a * a + b * b);
const double odd_x_rads = ((h != 0) ? std::asin(odd_c / h) + std::asin(b / h) : 0) - M_PI/2;
const double even_x_rads = ((h != 0) ? std::asin(even_c / h) + std::asin(b / h) : 0) - M_PI/2;
odd_line_coords.push_back(odd_x_rads / M_PI * pitch);
even_line_coords.push_back(even_x_rads / M_PI * pitch);
}
const unsigned num_coords = odd_line_coords.size();
unsigned num_columns = 0;
for (coord_t x = (std::floor(aabb.min.X / pitch) - 2.25) * pitch; x <= aabb.max.X + pitch/2; x += pitch/2)
{
bool is_first_point = true;
Point last;
bool last_inside = false;
unsigned chain_end_index = 0;
Point chain_end[2];
for (coord_t y = (std::floor(aabb.min.Y / pitch) - 1) * pitch; y <= aabb.max.Y + pitch; y += pitch)
{
for (unsigned i = 0; i < num_coords; ++i)
{
Point current(x + ((num_columns & 1) ? odd_line_coords[i] : even_line_coords[i])/2 + pitch, y + (coord_t)(i * step));
bool current_inside = outline.inside(current, true);
if (!is_first_point)
{
if (last_inside && current_inside)
{
// line doesn't hit the boundary, add the whole line
result.addLine(last, current);
}
else if (last_inside != current_inside)
{
// line hits the boundary, add the part that's inside the boundary
Polygons line;
line.addLine(last, current);
line = outline.intersectionPolyLines(line);
if (line.size() > 0)
{
// some of the line is inside the boundary
result.addLine(line[0][0], line[0][1]);
if (zig_zaggify)
{
chain_end[chain_end_index] = line[0][(line[0][0] != last && line[0][0] != current) ? 0 : 1];
if (++chain_end_index == 2)
{
chains[0].push_back(chain_end[0]);
chains[1].push_back(chain_end[1]);
chain_end_index = 0;
connected_to[0].push_back(std::numeric_limits<unsigned>::max());
connected_to[1].push_back(std::numeric_limits<unsigned>::max());
line_numbers.push_back(num_columns);
}
}
}
else
{
// none of the line is inside the boundary so the point that's actually on the boundary
// is the chain end
if (zig_zaggify)
{
//.........这里部分代码省略.........