mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 20:35:56 +08:00
Measuring - Fixes in plane-plane measurement - Measurements validation - Fixes in dimensioning rendering
This commit is contained in:
parent
afa003f3cb
commit
29d6127774
@ -719,21 +719,23 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature&
|
|||||||
|
|
||||||
const auto [idx1, normal1, pt1] = f1.get_plane();
|
const auto [idx1, normal1, pt1] = f1.get_plane();
|
||||||
const auto [idx2, normal2, pt2] = f2.get_plane();
|
const auto [idx2, normal2, pt2] = f2.get_plane();
|
||||||
double angle = 0.;
|
|
||||||
|
|
||||||
if (are_parallel(normal1, normal2)) {
|
if (are_parallel(normal1, normal2)) {
|
||||||
// The planes are parallel, calculate distance.
|
// The planes are parallel, calculate distance.
|
||||||
Eigen::Hyperplane<double, 3> plane(normal1, pt1);
|
const Eigen::Hyperplane<double, 3> plane(normal1, pt1);
|
||||||
result.distance_infinite = std::make_optional(DistAndPoints{plane.absDistance(pt2), Vec3d::Zero(), Vec3d::Zero()});
|
result.distance_infinite = std::make_optional(DistAndPoints{ plane.absDistance(pt2), pt2, plane.projection(pt2) }); // TODO
|
||||||
} else {
|
|
||||||
// Planes are not parallel, calculate angle.
|
|
||||||
angle = std::acos(std::abs(normal1.dot(normal2)));
|
|
||||||
}
|
}
|
||||||
result.angle = angle_plane_plane(f1.get_plane(), f2.get_plane());
|
else
|
||||||
result.distance_infinite = std::make_optional(DistAndPoints{0., Vec3d::Zero(), Vec3d::Zero()}); // TODO
|
result.angle = angle_plane_plane(f1.get_plane(), f2.get_plane());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validation
|
||||||
|
if (result.distance_infinite.has_value() && result.distance_infinite->dist < EPSILON)
|
||||||
|
result.distance_infinite.reset();
|
||||||
|
if (result.distance_strict.has_value() && result.distance_strict->dist < EPSILON)
|
||||||
|
result.distance_strict.reset();
|
||||||
|
if (result.angle.has_value() && std::abs(result.angle->angle) < EPSILON)
|
||||||
|
result.angle.reset();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,10 @@ struct MeasurementResult {
|
|||||||
std::optional<DistAndPoints> distance_strict;
|
std::optional<DistAndPoints> distance_strict;
|
||||||
std::optional<Vec3d> distance_xyz;
|
std::optional<Vec3d> distance_xyz;
|
||||||
|
|
||||||
|
bool has_distance_data() const {
|
||||||
|
return distance_infinite.has_value() || distance_strict.has_value();
|
||||||
|
}
|
||||||
|
|
||||||
bool has_any_data() const {
|
bool has_any_data() const {
|
||||||
return angle.has_value() || distance_infinite.has_value() || distance_strict.has_value() || distance_xyz.has_value();
|
return angle.has_value() || distance_infinite.has_value() || distance_strict.has_value() || distance_xyz.has_value();
|
||||||
}
|
}
|
||||||
|
@ -1062,11 +1062,14 @@ void GLGizmoMeasure::render_dimensioning()
|
|||||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||||
|
|
||||||
if (m_selected_features.second.feature.has_value()) {
|
if (m_selected_features.second.feature.has_value()) {
|
||||||
// Render the arrow between the points that the backend passed:
|
const bool has_distance = m_measurement_result.has_distance_data();
|
||||||
const Measure::DistAndPoints& dap = m_measurement_result.distance_infinite.has_value()
|
if (has_distance) {
|
||||||
? *m_measurement_result.distance_infinite
|
// Render the arrow between the points that the backend passed:
|
||||||
: *m_measurement_result.distance_strict;
|
const Measure::DistAndPoints& dap = m_measurement_result.distance_infinite.has_value()
|
||||||
point_point(dap.from, dap.to, dap.dist);
|
? *m_measurement_result.distance_infinite
|
||||||
|
: *m_measurement_result.distance_strict;
|
||||||
|
point_point(dap.from, dap.to, dap.dist);
|
||||||
|
}
|
||||||
|
|
||||||
const Measure::SurfaceFeature* f1 = &(*m_selected_features.first.feature);
|
const Measure::SurfaceFeature* f1 = &(*m_selected_features.first.feature);
|
||||||
const Measure::SurfaceFeature* f2 = &(*m_selected_features.second.feature);
|
const Measure::SurfaceFeature* f2 = &(*m_selected_features.second.feature);
|
||||||
@ -1080,7 +1083,7 @@ void GLGizmoMeasure::render_dimensioning()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Where needed, draw also the extension of the edge to where the dist is measured:
|
// Where needed, draw also the extension of the edge to where the dist is measured:
|
||||||
if (ft1 == Measure::SurfaceFeatureType::Point && ft2 == Measure::SurfaceFeatureType::Edge)
|
if (has_distance && ft1 == Measure::SurfaceFeatureType::Point && ft2 == Measure::SurfaceFeatureType::Edge)
|
||||||
point_edge(*f1, *f2);
|
point_edge(*f1, *f2);
|
||||||
|
|
||||||
// Now if there is an angle to show, draw the arc:
|
// Now if there is an angle to show, draw the arc:
|
||||||
@ -1370,7 +1373,7 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit
|
|||||||
ImGui::GetStyleColorVec4(ImGuiCol_Text));
|
ImGui::GetStyleColorVec4(ImGuiCol_Text));
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
if (measure.distance_infinite.has_value() && measure.distance_infinite->dist > 0.0) {
|
if (measure.distance_infinite.has_value()) {
|
||||||
double distance = measure.distance_infinite->dist;
|
double distance = measure.distance_infinite->dist;
|
||||||
if (use_inches)
|
if (use_inches)
|
||||||
distance = ObjectManipulation::mm_to_in * distance;
|
distance = ObjectManipulation::mm_to_in * distance;
|
||||||
@ -1379,7 +1382,8 @@ void GLGizmoMeasure::on_render_input_window(float x, float y, float bottom_limit
|
|||||||
ImGui::GetStyleColorVec4(ImGuiCol_Text));
|
ImGui::GetStyleColorVec4(ImGuiCol_Text));
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
if (measure.distance_strict.has_value() && measure.distance_strict->dist > 0.0) {
|
if (measure.distance_strict.has_value() &&
|
||||||
|
(!measure.distance_infinite.has_value() || std::abs(measure.distance_strict->dist - measure.distance_infinite->dist) > EPSILON)) {
|
||||||
double distance = measure.distance_strict->dist;
|
double distance = measure.distance_strict->dist;
|
||||||
if (use_inches)
|
if (use_inches)
|
||||||
distance = ObjectManipulation::mm_to_in * distance;
|
distance = ObjectManipulation::mm_to_in * distance;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user