Measuring - Fixes in plane-plane measurement - Measurements validation - Fixes in dimensioning rendering

This commit is contained in:
enricoturri1966 2022-10-04 08:17:43 +02:00
parent ccfce4db7b
commit 99e239301a
3 changed files with 27 additions and 17 deletions

View file

@ -719,21 +719,23 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature&
const auto [idx1, normal1, pt1] = f1.get_plane();
const auto [idx2, normal2, pt2] = f2.get_plane();
double angle = 0.;
if (are_parallel(normal1, normal2)) {
// The planes are parallel, calculate distance.
Eigen::Hyperplane<double, 3> plane(normal1, pt1);
result.distance_infinite = std::make_optional(DistAndPoints{plane.absDistance(pt2), Vec3d::Zero(), Vec3d::Zero()});
} else {
// Planes are not parallel, calculate angle.
angle = std::acos(std::abs(normal1.dot(normal2)));
const Eigen::Hyperplane<double, 3> plane(normal1, pt1);
result.distance_infinite = std::make_optional(DistAndPoints{ plane.absDistance(pt2), pt2, plane.projection(pt2) }); // TODO
}
result.angle = angle_plane_plane(f1.get_plane(), f2.get_plane());
result.distance_infinite = std::make_optional(DistAndPoints{0., Vec3d::Zero(), Vec3d::Zero()}); // TODO
else
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;
}

View file

@ -136,6 +136,10 @@ struct MeasurementResult {
std::optional<DistAndPoints> distance_strict;
std::optional<Vec3d> distance_xyz;
bool has_distance_data() const {
return distance_infinite.has_value() || distance_strict.has_value();
}
bool has_any_data() const {
return angle.has_value() || distance_infinite.has_value() || distance_strict.has_value() || distance_xyz.has_value();
}

View file

@ -1062,11 +1062,14 @@ void GLGizmoMeasure::render_dimensioning()
glsafe(::glDisable(GL_DEPTH_TEST));
if (m_selected_features.second.feature.has_value()) {
// Render the arrow between the points that the backend passed:
const Measure::DistAndPoints& dap = m_measurement_result.distance_infinite.has_value()
? *m_measurement_result.distance_infinite
: *m_measurement_result.distance_strict;
point_point(dap.from, dap.to, dap.dist);
const bool has_distance = m_measurement_result.has_distance_data();
if (has_distance) {
// Render the arrow between the points that the backend passed:
const Measure::DistAndPoints& dap = m_measurement_result.distance_infinite.has_value()
? *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* 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:
if (ft1 == Measure::SurfaceFeatureType::Point && ft2 == Measure::SurfaceFeatureType::Edge)
if (has_distance && ft1 == Measure::SurfaceFeatureType::Point && ft2 == Measure::SurfaceFeatureType::Edge)
point_edge(*f1, *f2);
// 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::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;
if (use_inches)
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::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;
if (use_inches)
distance = ObjectManipulation::mm_to_in * distance;