Measuring - struct AngleAndPoints reworked as struct AngleAndEdges
This commit is contained in:
parent
1c084c4f62
commit
0a8f500819
3 changed files with 23 additions and 26 deletions
|
@ -427,14 +427,12 @@ std::vector<std::vector<int>> Measuring::get_planes_triangle_indices() const
|
|||
}
|
||||
|
||||
|
||||
const AngleAndEdges AngleAndEdges::Dummy = { 0.0, Vec3d::Zero(), { Vec3d::Zero(), Vec3d::Zero() }, { Vec3d::Zero(), Vec3d::Zero() }, 0.0, true };
|
||||
|
||||
|
||||
|
||||
|
||||
static AngleAndPoints angle_edge_edge(const std::pair<Vec3d, Vec3d>& e1, const std::pair<Vec3d, Vec3d>& e2)
|
||||
static AngleAndEdges angle_edge_edge(std::pair<Vec3d, Vec3d> e1, std::pair<Vec3d, Vec3d> e2)
|
||||
{
|
||||
if (are_parallel(e1, e2))
|
||||
return AngleAndPoints(0.0, e1.first, Vec3d::UnitX(), Vec3d::UnitX(), 0., true);
|
||||
return AngleAndEdges::Dummy;
|
||||
|
||||
Vec3d e1_unit = edge_direction(e1.first, e1.second);
|
||||
Vec3d e2_unit = edge_direction(e2.first, e2.second);
|
||||
|
@ -474,10 +472,12 @@ static AngleAndPoints angle_edge_edge(const std::pair<Vec3d, Vec3d>& e1, const s
|
|||
// ensure the edges are pointing away from the center
|
||||
if ((center_rot_2d - e11_rot_2d).squaredNorm() > (center_rot_2d - e12_rot_2d).squaredNorm()) {
|
||||
std::swap(e11_proj, e12_proj);
|
||||
std::swap(e1.first, e1.second);
|
||||
e1_unit = -e1_unit;
|
||||
}
|
||||
if ((center_rot_2d - e21_rot_2d).squaredNorm() > (center_rot_2d - e22_rot_2d).squaredNorm()) {
|
||||
std::swap(e21_proj, e22_proj);
|
||||
std::swap(e2.first, e2.second);
|
||||
e2_unit = -e2_unit;
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ static AngleAndPoints angle_edge_edge(const std::pair<Vec3d, Vec3d>& e1, const s
|
|||
const Vec3d e2_proj_mid = 0.5 * (e21_proj + e22_proj);
|
||||
const double radius = std::min((center - e1_proj_mid).norm(), (center - e2_proj_mid).norm());
|
||||
|
||||
return AngleAndPoints(angle, center, e1_unit, e2_unit, radius, coplanar);
|
||||
return { angle, center, e1, e2, radius, coplanar };
|
||||
}
|
||||
|
||||
|
||||
|
@ -644,7 +644,7 @@ MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature&
|
|||
// Planes are not parallel, calculate angle.
|
||||
angle = std::acos(std::abs(normal1.dot(normal2)));
|
||||
}
|
||||
result.angle = std::make_optional(AngleAndPoints(angle, Vec3d::Zero(), Vec3d::UnitX(), Vec3d::UnitX(), 0., false)); // TODO
|
||||
result.angle = std::make_optional(AngleAndEdges(angle, Vec3d::Zero(), { Vec3d::Zero(), Vec3d::Zero() }, { Vec3d::Zero(), Vec3d::Zero() }, 0., false)); // TODO
|
||||
result.distance_infinite = std::make_optional(DistAndPoints{0., Vec3d::Zero(), Vec3d::Zero()}); // TODO
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ enum class SurfaceFeatureType : int {
|
|||
class SurfaceFeature {
|
||||
public:
|
||||
SurfaceFeature(SurfaceFeatureType type, const Vec3d& pt1, const Vec3d& pt2, std::optional<Vec3d> pt3 = std::nullopt, double value = 0.0)
|
||||
: m_type{ type }, m_pt1{ pt1 }, m_pt2{ pt2 }, m_pt3{ pt3 }, m_value{ value } {}
|
||||
: m_type(type), m_pt1(pt1), m_pt2(pt2), m_pt3(pt3), m_value(value) {}
|
||||
|
||||
explicit SurfaceFeature(const Vec3d& pt)
|
||||
: m_type{SurfaceFeatureType::Point}, m_pt1{pt} {}
|
||||
|
@ -117,19 +117,21 @@ struct DistAndPoints {
|
|||
Vec3d to;
|
||||
};
|
||||
|
||||
struct AngleAndPoints {
|
||||
AngleAndPoints(double angle_, Vec3d center_, Vec3d e1_, Vec3d e2_, double radius_, bool coplanar_)
|
||||
: angle(angle_), center(center_), e1(e1_), e2(e2_), radius(radius_), coplanar(coplanar_) {}
|
||||
struct AngleAndEdges {
|
||||
AngleAndEdges(double angle_, const Vec3d& center_, const std::pair<Vec3d, Vec3d>& e1_, const std::pair<Vec3d, Vec3d>& e2_, double radius_, bool coplanar_)
|
||||
: angle(angle_), center(center_), e1(e1_), e2(e2_), radius(radius_), coplanar(coplanar_) {}
|
||||
double angle;
|
||||
Vec3d center;
|
||||
Vec3d e1;
|
||||
Vec3d e2;
|
||||
std::pair<Vec3d, Vec3d> e1;
|
||||
std::pair<Vec3d, Vec3d> e2;
|
||||
double radius;
|
||||
bool coplanar;
|
||||
|
||||
static const AngleAndEdges Dummy;
|
||||
};
|
||||
|
||||
struct MeasurementResult {
|
||||
std::optional<AngleAndPoints> angle;
|
||||
std::optional<AngleAndEdges> angle;
|
||||
std::optional<DistAndPoints> distance_infinite;
|
||||
std::optional<DistAndPoints> distance_strict;
|
||||
std::optional<Vec3d> distance_xyz;
|
||||
|
@ -143,10 +145,10 @@ struct MeasurementResult {
|
|||
MeasurementResult get_measurement(const SurfaceFeature& a, const SurfaceFeature& b);
|
||||
|
||||
inline Vec3d edge_direction(const Vec3d& from, const Vec3d& to) { return (to - from).normalized(); }
|
||||
inline Vec3d edge_direction(const std::pair<Vec3d, Vec3d>& e) { return edge_direction(e.first, e.second); }
|
||||
inline Vec3d edge_direction(const SurfaceFeature& edge) {
|
||||
assert(edge.get_type() == SurfaceFeatureType::Edge);
|
||||
const auto [from, to] = edge.get_edge();
|
||||
return edge_direction(from, to);
|
||||
return edge_direction(edge.get_edge());
|
||||
}
|
||||
|
||||
inline Vec3d plane_normal(const SurfaceFeature& plane) {
|
||||
|
|
|
@ -867,19 +867,11 @@ void GLGizmoMeasure::render_dimensioning()
|
|||
const Measure::MeasurementResult res = Measure::get_measurement(f1, f2);
|
||||
const double angle = res.angle->angle;
|
||||
const Vec3d center = res.angle->center;
|
||||
const Vec3d e1_unit = res.angle->e1;
|
||||
const Vec3d e2_unit = res.angle->e2;
|
||||
const std::pair<Vec3d, Vec3d> e1 = res.angle->e1;
|
||||
const std::pair<Vec3d, Vec3d> e2 = res.angle->e2;
|
||||
const double radius = res.angle->radius;
|
||||
const bool coplanar = res.angle->coplanar;
|
||||
|
||||
std::pair<Vec3d, Vec3d> e1 = f1.get_edge();
|
||||
std::pair<Vec3d, Vec3d> e2 = f2.get_edge();
|
||||
|
||||
if ((e1.second - e1.first).dot(e1_unit) < 0.)
|
||||
std::swap(e1.first, e1.second);
|
||||
if ((e2.second - e2.first).dot(e2_unit) < 0.)
|
||||
std::swap(e2.first, e2.second);
|
||||
|
||||
if (radius == 0.)
|
||||
return;
|
||||
|
||||
|
@ -887,6 +879,9 @@ void GLGizmoMeasure::render_dimensioning()
|
|||
|
||||
double draw_radius = force_radius ? *force_radius : radius;
|
||||
|
||||
const Vec3d e1_unit = Measure::edge_direction(e1);
|
||||
const Vec3d e2_unit = Measure::edge_direction(e2);
|
||||
|
||||
if (!m_dimensioning.arc.is_initialized()) {
|
||||
const unsigned int resolution = std::max<unsigned int>(2, 64 * angle / double(PI));
|
||||
GLModel::Geometry init_data;
|
||||
|
|
Loading…
Add table
Reference in a new issue