#ifndef REMOTEAR2_SCENE_MANAGER_HPP #define REMOTEAR2_SCENE_MANAGER_HPP #include "sophiar_connect.h" #include #include #include #include #include #include #include struct scene_manager { struct actor_info { vtkSmartPointer actor; vtkSmartPointer pose; int pose_variable_id = -1; // -1 will not be updated }; using actor_pool_type = std::vector; actor_pool_type actor_pool; sophiar::variable_io *var_io = nullptr; static void transform_to_vtk_matrix(const sophiar::transform_type &trans, vtkMatrix4x4 *matrix) { if (matrix == nullptr) return; for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { matrix->SetElement(i, j, trans(i, j)); } } matrix->Modified(); } vtkActor *add_actor(std::string_view file_name, int variable_id) { vtkNew reader; reader->SetFileName(file_name.data()); reader->Update(); vtkNew mapper; mapper->SetInputData(reader->GetOutput()); vtkNew actor; actor->SetMapper(mapper); vtkNew pose_matrix; actor->SetUserMatrix(pose_matrix); auto &next_actor = actor_pool.emplace_back(); next_actor.actor = actor; next_actor.pose = pose_matrix; next_actor.pose_variable_id = variable_id; return actor; } void update_pose() { assert(var_io != nullptr); for (auto &actor: actor_pool) { assert(actor.pose_variable_id != -1); auto next_pose = var_io->query_transform_variable(actor.pose_variable_id); if (next_pose.has_value()) { transform_to_vtk_matrix(*next_pose.value(), actor.pose); actor.actor->SetVisibility(true); } else { actor.actor->SetVisibility(false); } actor.actor->Modified(); } } }; #endif //REMOTEAR2_SCENE_MANAGER_HPP