OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Circle Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Circle.hpp>

Inheritance diagram for Slic3r::Circle:
Collaboration diagram for Slic3r::Circle:

Public Member Functions

 Circle ()
 Circle (Point &p, double r)
Point get_closest_point (const Point &input)
double get_polar_radians (const Point &p1) const
bool is_over_deviation (const Points &points, const double tolerance)
bool get_deviation_sum_squared (const Points &points, const double tolerance, double &sum_deviation)

Static Public Member Functions

static bool try_create_circle (const Point &p1, const Point &p2, const Point &p3, const double max_radius, Circle &new_circle)
static bool try_create_circle (const Points &points, const double max_radius, const double tolerance, Circle &new_circle)
static bool try_create_circle (const Points3 &points, const double max_radius, const double tolerance, Circle &new_circle)
static Vec3f calc_tangential_vector (const Vec3f &pos, const Vec3f &center_pos, const bool is_ccw)
static bool get_closest_perpendicular_point (const Point &p1, const Point &p2, const Point &c, Point &out)
static bool is_equal (double x, double y, double tolerance=ZERO_TOLERANCE)
static bool greater_than (double x, double y, double tolerance=ZERO_TOLERANCE)
static bool greater_than_or_equal (double x, double y, double tolerance=ZERO_TOLERANCE)
static bool less_than (double x, double y, double tolerance=ZERO_TOLERANCE)
static bool less_than_or_equal (double x, double y, double tolerance=ZERO_TOLERANCE)

Public Attributes

Point center
double radius

Detailed Description

Constructor & Destructor Documentation

◆ Circle() [1/2]

Slic3r::Circle::Circle ( )
inline
16 {
17 center = Point(0,0);
18 radius = 0;
19 }
double radius
Definition Circle.hpp:25
Point center
Definition Circle.hpp:24
Kernel::Point_3 Point
Definition MeshRepair.cpp:81

References center, and radius.

Referenced by Slic3r::ArcSegment::ArcSegment(), Slic3r::ArcSegment::ArcSegment(), Slic3r::ArcSegment::try_create_arc(), Slic3r::ArcSegment::try_create_arc(), Slic3r::ArcSegment::try_create_arc(), try_create_circle(), try_create_circle(), and try_create_circle().

Here is the caller graph for this function:

◆ Circle() [2/2]

Slic3r::Circle::Circle ( Point & p,
double r )
inline
20 {
21 center = p;
22 radius = r;
23 }

References center, and radius.

Member Function Documentation

◆ calc_tangential_vector()

Vec3f Slic3r::Circle::calc_tangential_vector ( const Vec3f & pos,
const Vec3f & center_pos,
const bool is_ccw )
static
202{
203 Vec3f dir = center_pos - pos;
204 dir(2,0) = 0;
205 dir.normalize();
206 Vec3f res;
207 if (is_ccw)
208 res = { dir(1, 0), -dir(0, 0), 0.0f };
209 else
210 res = { -dir(1, 0), dir(0, 0), 0.0f };
211 return res;
212}
static bool is_ccw(const Polygon &poly)
Definition Geometry.hpp:66
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:65

References Slic3r::Geometry::is_ccw().

Here is the call graph for this function:

◆ get_closest_perpendicular_point()

bool Slic3r::Circle::get_closest_perpendicular_point ( const Point & p1,
const Point & p2,
const Point & c,
Point & out )
static
145{
146 double x1 = p1.x();
147 double y1 = p1.y();
148 double x2 = p2.x();
149 double y2 = p2.y();
150 double x_dif = x2 - x1;
151 double y_dif = y2 - y1;
152 //BBS: [(Cx - Ax)(Bx - Ax) + (Cy - Ay)(By - Ay)] / [(Bx - Ax) ^ 2 + (By - Ay) ^ 2]
153 double num = (c[0] - x1) * x_dif + (c[1] - y1) * y_dif;
154 double denom = (x_dif * x_dif) + (y_dif * y_dif);
155 double t = num / denom;
156
157 //BBS: Considering this a failure if t == 0 or t==1 within tolerance. In that case we hit the endpoint, which is OK.
159 return false;
160
161 out[0] = x1 + t * (x2 - x1);
162 out[1] = y1 + t * (y2 - y1);
163 return true;
164}
static bool greater_than_or_equal(double x, double y, double tolerance=ZERO_TOLERANCE)
Definition Circle.hpp:49
static bool less_than_or_equal(double x, double y, double tolerance=ZERO_TOLERANCE)
Definition Circle.hpp:55

References greater_than_or_equal(), and less_than_or_equal().

Referenced by get_deviation_sum_squared(), and is_over_deviation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_closest_point()

Point Slic3r::Circle::get_closest_point ( const Point & input)
inline
27 {
28 Vec2d v = (input - center).cast<double>().normalized();
29 return (center + (v * radius).cast<coord_t>());
30 }
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67
auto cast(const BoundingBoxBase< Tin > &b)
Definition BoundingBox.hpp:299

References Slic3r::cast(), center, and radius.

Referenced by Slic3r::ArcSegment::clip_end(), Slic3r::ArcSegment::clip_start(), and Slic3r::ArcSegment::split_at().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_deviation_sum_squared()

bool Slic3r::Circle::get_deviation_sum_squared ( const Points & points,
const double tolerance,
double & sum_deviation )
167{
168 total_deviation = 0;
169 Point temp;
170 double distance_from_center, deviation;
171 // BBS: skip the first and last points since they are on the circle
172 for (int index = 1; index < points.size() - 1; index++)
173 {
174 //BBS: make sure the length from the center of our circle to the test point is
175 // at or below our max distance.
176 temp = points[index] - center;
177 distance_from_center = sqrt((double)temp.x() * (double)temp.x() + (double)temp.y() * (double)temp.y());
178 deviation = std::fabs(distance_from_center - radius);
179 total_deviation += deviation * deviation;
180 if (deviation > tolerance)
181 return false;
182
183 }
184 Point closest_point;
185 //BBS: check the point perpendicular from the segment to the circle's center
186 for (int index = 0; index < points.size() - 1; index++)
187 {
188 if (get_closest_perpendicular_point(points[index], points[(size_t)index + 1], center, closest_point)) {
189 temp = closest_point - center;
190 distance_from_center = sqrt((double)temp.x() * (double)temp.x() + (double)temp.y() * (double)temp.y());
191 deviation = std::fabs(distance_from_center - radius);
192 total_deviation += deviation * deviation;
193 if (deviation > tolerance)
194 return false;
195 }
196 }
197 return true;
198}
static bool get_closest_perpendicular_point(const Point &p1, const Point &p2, const Point &c, Point &out)
Definition Circle.cpp:144

References center, get_closest_perpendicular_point(), and radius.

Referenced by try_create_circle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_polar_radians()

double Slic3r::Circle::get_polar_radians ( const Point & p1) const
109{
110 double polar_radians = atan2(p1.y() - center.y(), p1.x() - center.x());
111 if (polar_radians < 0)
112 polar_radians = (2.0 * PI) + polar_radians;
113 return polar_radians;
114}
static constexpr double PI
Definition libslic3r.h:81

References center, and PI.

Referenced by Slic3r::ArcSegment::are_points_within_slice(), Slic3r::ArcSegment::are_points_within_slice(), Slic3r::ArcSegment::is_point_inside(), Slic3r::ArcSegment::try_create_arc(), and Slic3r::ArcSegment::update_angle_and_length().

Here is the caller graph for this function:

◆ greater_than()

bool Slic3r::Circle::greater_than ( double x,
double y,
double tolerance = ZERO_TOLERANCE )
inlinestatic
46 {
47 return x > y && !Circle::is_equal(x, y, tolerance);
48 };
static bool is_equal(double x, double y, double tolerance=ZERO_TOLERANCE)
Definition Circle.hpp:42

References is_equal(), and Slic3r::ZERO_TOLERANCE.

Here is the call graph for this function:

◆ greater_than_or_equal()

bool Slic3r::Circle::greater_than_or_equal ( double x,
double y,
double tolerance = ZERO_TOLERANCE )
inlinestatic
49 {
50 return x > y || Circle::is_equal(x, y, tolerance);
51 };

References is_equal(), and Slic3r::ZERO_TOLERANCE.

Referenced by get_closest_perpendicular_point().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_equal()

bool Slic3r::Circle::is_equal ( double x,
double y,
double tolerance = ZERO_TOLERANCE )
inlinestatic
42 {
43 double abs_difference = std::fabs(x - y);
44 return abs_difference < tolerance;
45 };

References Slic3r::ZERO_TOLERANCE.

Referenced by greater_than(), greater_than_or_equal(), less_than(), and less_than_or_equal().

Here is the caller graph for this function:

◆ is_over_deviation()

bool Slic3r::Circle::is_over_deviation ( const Points & points,
const double tolerance )
117{
118 Point closest_point;
119 Point temp;
120 double distance_from_center;
121 // BBS: skip the first and last points since they has fit perfectly.
122 for (size_t index = 0; index < points.size() - 1; index++)
123 {
124 if (index != 0)
125 {
126 //BBS: check fitting tolerance
127 temp = points[index] - center;
128 distance_from_center = sqrt((double)temp.x() * (double)temp.x() + (double)temp.y() * (double)temp.y());
129 if (std::fabs(distance_from_center - radius) > tolerance)
130 return true;
131 }
132
133 //BBS: Check the point perpendicular from the segment to the circle's center
134 if (get_closest_perpendicular_point(points[index], points[(size_t)index + 1], center, closest_point)) {
135 temp = closest_point - center;
136 distance_from_center = sqrt((double)temp.x() * (double)temp.x() + (double)temp.y() * (double)temp.y());
137 if (std::fabs(distance_from_center - radius) > tolerance)
138 return true;
139 }
140 }
141 return false;
142}

References center, get_closest_perpendicular_point(), and radius.

Referenced by try_create_circle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ less_than()

bool Slic3r::Circle::less_than ( double x,
double y,
double tolerance = ZERO_TOLERANCE )
inlinestatic
52 {
53 return x < y && !Circle::is_equal(x, y, tolerance);
54 };

References is_equal(), and Slic3r::ZERO_TOLERANCE.

Here is the call graph for this function:

◆ less_than_or_equal()

bool Slic3r::Circle::less_than_or_equal ( double x,
double y,
double tolerance = ZERO_TOLERANCE )
inlinestatic
55 {
56 return x < y || Circle::is_equal(x, y, tolerance);
57 };

References is_equal(), and Slic3r::ZERO_TOLERANCE.

Referenced by get_closest_perpendicular_point().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_create_circle() [1/3]

bool Slic3r::Circle::try_create_circle ( const Point & p1,
const Point & p2,
const Point & p3,
const double max_radius,
Circle & new_circle )
static
21{
22 double x1 = p1.x();
23 double y1 = p1.y();
24 double x2 = p2.x();
25 double y2 = p2.y();
26 double x3 = p3.x();
27 double y3 = p3.y();
28
29 //BBS: use area of triangle to judge whether three points are almostly on one line
30 //Because the point is scale_ once, so area should scale_ twice.
31 if (fabs((y1 - y2) * (x1 - x3) - (y1 - y3) * (x1 - x2)) <= scale_(scale_(Parallel_area_threshold)))
32 return false;
33
34 double a = x1 * (y2 - y3) - y1 * (x2 - x3) + x2 * y3 - x3 * y2;
35 //BBS: take out to figure out how we handle very small values
36 if (fabs(a) < SCALED_EPSILON)
37 return false;
38
39 double b = (x1 * x1 + y1 * y1) * (y3 - y2)
40 + (x2 * x2 + y2 * y2) * (y1 - y3)
41 + (x3 * x3 + y3 * y3) * (y2 - y1);
42
43 double c = (x1 * x1 + y1 * y1) * (x2 - x3)
44 + (x2 * x2 + y2 * y2) * (x3 - x1)
45 + (x3 * x3 + y3 * y3) * (x1 - x2);
46
47 double center_x = -b / (2.0 * a);
48 double center_y = -c / (2.0 * a);
49
50 double delta_x = center_x - x1;
51 double delta_y = center_y - y1;
52 double radius = sqrt(delta_x * delta_x + delta_y * delta_y);
53 if (radius > max_radius)
54 return false;
55
56 new_circle.center = Point(center_x, center_y);
57 new_circle.radius = radius;
58
59 return true;
60}
#define SCALED_EPSILON
Definition libslic3r.h:109
#define scale_(val)
Definition libslic3r.h:106
static const double Parallel_area_threshold
Definition Circle.cpp:18

References Circle(), center, Slic3r::Parallel_area_threshold, radius, scale_, and SCALED_EPSILON.

Referenced by Slic3r::ArcSegment::try_create_arc(), Slic3r::ArcSegment::try_create_arc(), try_create_circle(), and try_create_circle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_create_circle() [2/3]

bool Slic3r::Circle::try_create_circle ( const Points & points,
const double max_radius,
const double tolerance,
Circle & new_circle )
static
63{
64 size_t count = points.size();
65 size_t middle_index = count / 2;
66 // BBS: the middle point will almost always produce the best arcs with high possibility.
67 if (count == 3) {
68 return (Circle::try_create_circle(points[0], points[middle_index], points[count - 1], max_radius, new_circle)
69 && !new_circle.is_over_deviation(points, tolerance));
70 } else {
71 Point middle_point = (count % 2 == 0) ? (points[middle_index] + points[middle_index - 1]) / 2 :
72 (points[middle_index - 1] + points[middle_index + 1]) / 2;
73 if (Circle::try_create_circle(points[0], middle_point, points[count - 1], max_radius, new_circle)
74 && !new_circle.is_over_deviation(points, tolerance))
75 return true;
76 }
77
78 // BBS: Find the circle with the least deviation, if one exists.
79 Circle test_circle;
80 double least_deviation;
81 bool found_circle = false;
82 double current_deviation;
83 for (int index = 1; index < count - 1; index++)
84 {
85 if (index == middle_index)
86 // BBS: We already checked this one, and it failed. don't need to do again
87 continue;
88
89 if (Circle::try_create_circle(points[0], points[index], points[count - 1], max_radius, test_circle) && test_circle.get_deviation_sum_squared(points, tolerance, current_deviation))
90 {
91 if (!found_circle || current_deviation < least_deviation)
92 {
93 found_circle = true;
94 least_deviation = current_deviation;
95 new_circle = test_circle;
96 }
97 }
98 }
99 return found_circle;
100}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246
Circle()
Definition Circle.hpp:16
static bool try_create_circle(const Point &p1, const Point &p2, const Point &p3, const double max_radius, Circle &new_circle)
Definition Circle.cpp:20

References Circle(), count, get_deviation_sum_squared(), is_over_deviation(), and try_create_circle().

Here is the call graph for this function:

◆ try_create_circle() [3/3]

bool Slic3r::Circle::try_create_circle ( const Points3 & points,
const double max_radius,
const double tolerance,
Circle & new_circle )
static
103{
104 return Circle::try_create_circle(to_points(points), max_radius, tolerance, new_circle);
105}
Points to_points(const ExPolygons &src)
Definition ExPolygon.hpp:222

References Circle(), Slic3r::to_points(), and try_create_circle().

Here is the call graph for this function:

Member Data Documentation

◆ center

◆ radius


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Circle.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Circle.cpp