Measuring - Refactoring in GLGizmoMeasure related to scene raycasters state cache

Fixed conflicts while rebasing to master
This commit is contained in:
enricoturri1966 2022-09-27 10:21:57 +02:00
parent 10459706b8
commit aee76f0c11
3 changed files with 43 additions and 16 deletions

View File

@ -372,11 +372,13 @@ void GLGizmoMeasure::on_set_state()
else {
m_mode = EMode::BasicSelection;
// store current state of scene raycaster for later use
m_scene_raycaster_state.clear();
m_scene_raycasters = m_parent.get_raycasters_for_picking(SceneRaycaster::EType::Volume);
if (m_scene_raycasters != nullptr) {
for (const auto& r : *m_scene_raycasters) {
m_scene_raycaster_state.emplace_back(r->is_active());
m_scene_raycasters.clear();
auto scene_raycasters = m_parent.get_raycasters_for_picking(SceneRaycaster::EType::Volume);
if (scene_raycasters != nullptr) {
m_scene_raycasters.reserve(scene_raycasters->size());
for (auto r : *scene_raycasters) {
SceneRaycasterState state = { r, r->is_active() };
m_scene_raycasters.emplace_back(state);
}
}
}
@ -772,20 +774,15 @@ void GLGizmoMeasure::update_if_needed()
void GLGizmoMeasure::disable_scene_raycasters()
{
if (m_scene_raycasters != nullptr) {
for (auto r : *m_scene_raycasters) {
r->set_active(false);
}
for (auto r : m_scene_raycasters) {
r.raycaster->set_active(false);
}
}
void GLGizmoMeasure::restore_scene_raycasters_state()
{
if (m_scene_raycasters != nullptr) {
assert(m_scene_raycasters->size() == m_scene_raycaster_state.size());
for (size_t i = 0; i < m_scene_raycasters->size(); ++i) {
(*m_scene_raycasters)[i]->set_active(m_scene_raycaster_state[i]);
}
for (auto r : m_scene_raycasters) {
r.raycaster->set_active(r.state);
}
}

View File

@ -89,8 +89,13 @@ class GLGizmoMeasure : public GLGizmoBase
std::map<int, std::shared_ptr<SceneRaycasterItem>> m_raycasters;
std::optional<Measure::SurfaceFeature> m_curr_feature;
std::optional<Vec3d> m_curr_point_on_feature_position;
std::vector<std::shared_ptr<SceneRaycasterItem>>* m_scene_raycasters{ nullptr };
std::vector<bool> m_scene_raycaster_state;
struct SceneRaycasterState
{
std::shared_ptr<SceneRaycasterItem> raycaster{ nullptr };
bool state{true};
};
std::vector<SceneRaycasterState> m_scene_raycasters;
// These hold information to decide whether recalculation is necessary:
std::vector<Transform3d> m_volumes_matrices;

View File

@ -173,6 +173,31 @@ void SceneRaycaster::render_hit(const Camera& camera)
shader->stop_using();
}
size_t SceneRaycaster::active_beds_count() const {
size_t count = 0;
for (const auto& b : m_bed) {
if (b->is_active())
++count;
}
return count;
}
size_t SceneRaycaster::active_volumes_count() const {
size_t count = 0;
for (const auto& v : m_volumes) {
if (v->is_active())
++count;
}
return count;
}
size_t SceneRaycaster::active_gizmos_count() const {
size_t count = 0;
for (const auto& g : m_gizmos) {
if (g->is_active())
++count;
}
return count;
}
#endif // ENABLE_RAYCAST_PICKING_DEBUG
std::vector<std::shared_ptr<SceneRaycasterItem>>* SceneRaycaster::get_raycasters(EType type)