Measurement: extract features on the fly, not when the tool is opened
This commit is contained in:
parent
a37f09edaa
commit
a47bb5bf1b
@ -8,6 +8,8 @@
|
||||
|
||||
#include <numeric>
|
||||
|
||||
#define DEBUG_EXTRACT_ALL_FEATURES_AT_ONCE 0
|
||||
|
||||
namespace Slic3r {
|
||||
namespace Measure {
|
||||
|
||||
@ -63,17 +65,18 @@ public:
|
||||
std::vector<SurfaceFeature> surface_features;
|
||||
Vec3d normal;
|
||||
float area;
|
||||
bool features_extracted = false;
|
||||
};
|
||||
|
||||
std::optional<SurfaceFeature> get_feature(size_t face_idx, const Vec3d& point) const;
|
||||
std::optional<SurfaceFeature> get_feature(size_t face_idx, const Vec3d& point);
|
||||
int get_num_of_planes() const;
|
||||
const std::vector<int>& get_plane_triangle_indices(int idx) const;
|
||||
const std::vector<SurfaceFeature>& get_plane_features(unsigned int plane_id) const;
|
||||
const std::vector<SurfaceFeature>& get_plane_features(unsigned int plane_id);
|
||||
const TriangleMesh& get_mesh() const;
|
||||
|
||||
private:
|
||||
void update_planes();
|
||||
void extract_features();
|
||||
void extract_features(int plane_idx);
|
||||
|
||||
std::vector<PlaneData> m_planes;
|
||||
std::vector<size_t> m_face_to_plane;
|
||||
@ -89,7 +92,13 @@ MeasuringImpl::MeasuringImpl(const indexed_triangle_set& its)
|
||||
: m_mesh(its)
|
||||
{
|
||||
update_planes();
|
||||
extract_features();
|
||||
|
||||
// Extracting features will be done as needed.
|
||||
// To extract all planes at once, run the following:
|
||||
#if DEBUG_EXTRACT_ALL_FEATURES_AT_ONCE
|
||||
for (int i=0; i<int(m_planes.size()); ++i)
|
||||
extract_features(i);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -251,14 +260,11 @@ void MeasuringImpl::update_planes()
|
||||
|
||||
|
||||
|
||||
void MeasuringImpl::extract_features()
|
||||
void MeasuringImpl::extract_features(int plane_idx)
|
||||
{
|
||||
std::vector<double> angles; // placed in outer scope to prevent reallocations
|
||||
std::vector<double> lengths;
|
||||
assert(! m_planes[plane_idx].features_extracted);
|
||||
|
||||
|
||||
for (int i=0; i<(int)m_planes.size(); ++i) {
|
||||
PlaneData& plane = m_planes[i];
|
||||
PlaneData& plane = m_planes[plane_idx];
|
||||
plane.surface_features.clear();
|
||||
const Vec3d& normal = plane.normal;
|
||||
|
||||
@ -268,6 +274,9 @@ void MeasuringImpl::extract_features()
|
||||
trafo.rotate(q);
|
||||
const Transform3d trafo_inv = trafo.inverse();
|
||||
|
||||
std::vector<double> angles; // placed in outer scope to prevent reallocations
|
||||
std::vector<double> lengths;
|
||||
|
||||
for (const std::vector<Vec3d>& border : plane.borders) {
|
||||
if (border.size() <= 1)
|
||||
continue;
|
||||
@ -478,11 +487,12 @@ void MeasuringImpl::extract_features()
|
||||
}
|
||||
cog /= double(counter);
|
||||
plane.surface_features.emplace_back(SurfaceFeature(SurfaceFeatureType::Plane,
|
||||
plane.normal, cog, std::optional<Vec3d>(), i + 0.0001));
|
||||
plane.normal, cog, std::optional<Vec3d>(), plane_idx + 0.0001));
|
||||
|
||||
plane.borders.clear();
|
||||
plane.borders.shrink_to_fit();
|
||||
}
|
||||
|
||||
plane.features_extracted = true;
|
||||
}
|
||||
|
||||
|
||||
@ -492,13 +502,16 @@ void MeasuringImpl::extract_features()
|
||||
|
||||
|
||||
|
||||
std::optional<SurfaceFeature> MeasuringImpl::get_feature(size_t face_idx, const Vec3d& point) const
|
||||
std::optional<SurfaceFeature> MeasuringImpl::get_feature(size_t face_idx, const Vec3d& point)
|
||||
{
|
||||
if (face_idx >= m_face_to_plane.size())
|
||||
return std::optional<SurfaceFeature>();
|
||||
|
||||
const PlaneData& plane = m_planes[m_face_to_plane[face_idx]];
|
||||
|
||||
if (! plane.features_extracted)
|
||||
extract_features(m_face_to_plane[face_idx]);
|
||||
|
||||
size_t closest_feature_idx = size_t(-1);
|
||||
double min_dist = std::numeric_limits<double>::max();
|
||||
|
||||
@ -560,9 +573,11 @@ const std::vector<int>& MeasuringImpl::get_plane_triangle_indices(int idx) const
|
||||
return m_planes[idx].facets;
|
||||
}
|
||||
|
||||
const std::vector<SurfaceFeature>& MeasuringImpl::get_plane_features(unsigned int plane_id) const
|
||||
const std::vector<SurfaceFeature>& MeasuringImpl::get_plane_features(unsigned int plane_id)
|
||||
{
|
||||
assert(plane_id < m_planes.size());
|
||||
if (! m_planes[plane_id].features_extracted)
|
||||
extract_features(plane_id);
|
||||
return m_planes[plane_id].surface_features;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user