Measurement: optimize plane highlighting

This commit is contained in:
Lukas Matena 2022-12-05 13:28:56 +01:00
parent 7b569c4eb7
commit bed64cb7c7
3 changed files with 31 additions and 23 deletions

View File

@ -68,7 +68,8 @@ public:
std::vector<SurfaceFeature> get_all_features() const;
std::optional<SurfaceFeature> get_feature(size_t face_idx, const Vec3d& point) const;
std::vector<std::vector<int>> get_planes_triangle_indices() const;
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 TriangleMesh& get_mesh() const;
@ -554,12 +555,17 @@ std::optional<SurfaceFeature> MeasuringImpl::get_feature(size_t face_idx, const
std::vector<std::vector<int>> MeasuringImpl::get_planes_triangle_indices() const
int MeasuringImpl::get_num_of_planes() const
{
std::vector<std::vector<int>> out;
for (const PlaneData& plane : m_planes)
out.emplace_back(plane.facets);
return out;
return (m_planes.size());
}
const std::vector<int>& MeasuringImpl::get_plane_triangle_indices(int idx) const
{
assert(idx >= 0 && idx < int(m_planes.size()));
return m_planes[idx].facets;
}
const std::vector<SurfaceFeature>& MeasuringImpl::get_plane_features(unsigned int plane_id) const
@ -602,10 +608,15 @@ std::optional<SurfaceFeature> Measuring::get_feature(size_t face_idx, const Vec3
}
std::vector<std::vector<int>> Measuring::get_planes_triangle_indices() const
int Measuring::get_num_of_planes() const
{
return priv->get_planes_triangle_indices();
return priv->get_num_of_planes();
}
const std::vector<int>& Measuring::get_plane_triangle_indices(int idx) const
{
return priv->get_plane_triangle_indices(idx);
}
const std::vector<SurfaceFeature>& Measuring::get_plane_features(unsigned int plane_id) const

View File

@ -102,11 +102,12 @@ public:
// should be highlighted (if any).
std::optional<SurfaceFeature> get_feature(size_t face_idx, const Vec3d& point) const;
// Returns a list of triangle indices for each identified plane. Each
// Plane object contains an index into this vector. Expensive, do not
// call too often.
std::vector<std::vector<int>> get_planes_triangle_indices() const;
// Return total number of planes.
int get_num_of_planes() const;
// Returns a list of triangle indices for given plane.
const std::vector<int>& get_plane_triangle_indices(int idx) const;
// Returns the surface features of the plane with the given index
const std::vector<SurfaceFeature>& get_plane_features(unsigned int plane_id) const;

View File

@ -93,11 +93,8 @@ static std::string center_on_feature_type_as_string(Measure::SurfaceFeatureType
return ret;
}
static GLModel::Geometry init_plane_data(const indexed_triangle_set& its, const std::vector<std::vector<int>>& planes_triangles, int idx)
static GLModel::Geometry init_plane_data(const indexed_triangle_set& its, const std::vector<int>& triangle_indices)
{
assert(0 <= idx && idx < (int)planes_triangles.size());
const std::vector<int>& triangle_indices = planes_triangles[idx];
GLModel::Geometry init_data;
init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 };
unsigned int i = 0;
@ -653,8 +650,8 @@ void GLGizmoMeasure::on_render()
if (m_last_plane_idx != idx) {
m_last_plane_idx = idx;
const indexed_triangle_set& its = m_measuring->get_mesh().its;
const std::vector<std::vector<int>> planes_triangles = m_measuring->get_planes_triangle_indices();
GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx);
const std::vector<int>& plane_triangles = m_measuring->get_plane_triangle_indices(idx);
GLModel::Geometry init_data = init_plane_data(its, plane_triangles);
m_plane.reset();
m_plane.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(init_data.get_as_indexed_triangle_set()));
m_plane.model.init_from(std::move(init_data));
@ -1041,10 +1038,9 @@ void GLGizmoMeasure::update_if_needed()
{
auto update_plane_models_cache = [this](const indexed_triangle_set& its) {
m_plane_models_cache.clear();
const std::vector<std::vector<int>> planes_triangles = m_measuring->get_planes_triangle_indices();
for (int idx = 0; idx < (int)planes_triangles.size(); ++idx) {
for (int idx = 0; idx < m_measuring->get_num_of_planes(); ++idx) {
m_plane_models_cache.emplace_back(GLModel());
GLModel::Geometry init_data = init_plane_data(its, planes_triangles, idx);
GLModel::Geometry init_data = init_plane_data(its, m_measuring->get_plane_triangle_indices(idx));
m_plane_models_cache.back().init_from(std::move(init_data));
}
};