|
|
@@ -6,12 +6,8 @@
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
#include <glm/gtx/rotate_vector.hpp>
|
|
|
|
|
|
-#include <glm/gtx/string_cast.hpp>
|
|
|
-
|
|
|
#include <boost/asio/post.hpp>
|
|
|
|
|
|
-#include <vtkSphereSource.h>
|
|
|
-
|
|
|
using boost::asio::post;
|
|
|
|
|
|
void camera_augment_helper_v2::impl::freedom_info_type::reset() {
|
|
|
@@ -60,7 +56,6 @@ void camera_augment_helper_v2::impl::freedom_info_type::move_right(float dis) {
|
|
|
translate(-axis * dis);
|
|
|
}
|
|
|
|
|
|
-// TODO: using accelerometer determined world coordinate
|
|
|
void camera_augment_helper_v2::impl::freedom_info_type::move_up(float dis) {
|
|
|
translate(view_up * dis);
|
|
|
}
|
|
|
@@ -115,7 +110,6 @@ camera_augment_helper_v2::impl::impl(const create_config &conf) {
|
|
|
case 3: {
|
|
|
mode = MODE_RELATIVE;
|
|
|
auto info = std::get<3>(conf.camera);
|
|
|
- fov = info.fov;
|
|
|
relative_info.parent = info.parent->pimpl.get();
|
|
|
relative_info.transform = info.transform;
|
|
|
break;
|
|
|
@@ -162,6 +156,7 @@ void camera_augment_helper_v2::impl::update_relative() {
|
|
|
par->update_transform();
|
|
|
is_missing = par->is_missing;
|
|
|
transform = par->transform * relative_info.transform;
|
|
|
+ fov = par->fov;
|
|
|
}
|
|
|
|
|
|
void camera_augment_helper_v2::impl::update_transform() {
|
|
|
@@ -178,15 +173,16 @@ void camera_augment_helper_v2::impl::update_camera() {
|
|
|
update_transform();
|
|
|
last_camera = camera_info{
|
|
|
.transform = transform, .fov = fov,
|
|
|
- .near = near, .far = far
|
|
|
+ .near = ui->near, .far = ui->far
|
|
|
};
|
|
|
}
|
|
|
|
|
|
void camera_augment_helper_v2::impl::render() {
|
|
|
- if (!is_missing || ignore_missing) {
|
|
|
+ if (!is_missing || ui->ignore_missing) {
|
|
|
update_camera();
|
|
|
- manager->render(last_camera);
|
|
|
last_vp_size = query_viewport_size();
|
|
|
+ manager->record_current_camera_helper(q_this);
|
|
|
+ manager->render(last_camera);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -265,9 +261,11 @@ void camera_augment_helper_v2::impl::show_fixed() {
|
|
|
}
|
|
|
|
|
|
void camera_augment_helper_v2::impl::show() {
|
|
|
- ImGui::Checkbox("Ignore Missing", &ignore_missing); // TODO: enable sync with another
|
|
|
- ImGui::SliderFloat("Clip Near", &near, 1.0f, far, "%.f", ImGuiSliderFlags_Logarithmic);
|
|
|
- ImGui::SliderFloat("Clip Far", &far, near, 10000.0f, "%.f", ImGuiSliderFlags_Logarithmic);
|
|
|
+ ImGui::Checkbox("Ignore Missing", &ui->ignore_missing); // TODO: enable sync with another
|
|
|
+ ImGui::SameLine();
|
|
|
+ ImGui::Checkbox("Guidance", &ui->enable_active_guide);
|
|
|
+ ImGui::SliderFloat("Clip Near", &ui->near, 1.0f, ui->far, "%.f", ImGuiSliderFlags_Logarithmic);
|
|
|
+ ImGui::SliderFloat("Clip Far", &ui->far, ui->near, 10000.0f, "%.f", ImGuiSliderFlags_Logarithmic);
|
|
|
|
|
|
switch (mode) {
|
|
|
// @formatter:off
|
|
|
@@ -279,25 +277,18 @@ void camera_augment_helper_v2::impl::show() {
|
|
|
RET_ERROR;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (is_interactive) {
|
|
|
- ImGui::Checkbox("Cursor Guide", &enable_cursor_guide);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
-void camera_augment_helper_v2::impl::update_cursor_coordinate() {
|
|
|
- assert(enable_cursor_guide);
|
|
|
- cursor_pos = {};
|
|
|
-
|
|
|
- auto s_pos = ImGui::GetMousePos();
|
|
|
+std::optional<glm::vec3> camera_augment_helper_v2::impl::
|
|
|
+get_cursor_coordinate(glm::vec2 s_pos) {
|
|
|
auto w = last_vp_size.width, h = last_vp_size.height;
|
|
|
- if (s_pos.x < 0 || s_pos.x > w) return;
|
|
|
- if (s_pos.y < 0 || s_pos.y > h) return;
|
|
|
+ if (s_pos.x < 0 || s_pos.x > w) return {};
|
|
|
+ if (s_pos.y < 0 || s_pos.y > h) return {};
|
|
|
s_pos.y = h - s_pos.y; // flip y to texture coordinate
|
|
|
|
|
|
float depth;
|
|
|
glReadPixels(s_pos.x, s_pos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
|
|
- if (depth == 1.f) return;
|
|
|
+ if (depth == 1.f) return {};
|
|
|
|
|
|
auto proj = last_camera.projection(last_vp_size.aspectRatio());
|
|
|
auto ndc = glm::vec3(s_pos.x / w, s_pos.y / h, depth);
|
|
|
@@ -308,52 +299,40 @@ void camera_augment_helper_v2::impl::update_cursor_coordinate() {
|
|
|
glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)); // camera -> viewport
|
|
|
auto w_pos_h = cam_mat * to_homo(c_pos);
|
|
|
auto w_pos = from_homo(w_pos_h);
|
|
|
- cursor_pos = w_pos;
|
|
|
+ return w_pos;
|
|
|
}
|
|
|
|
|
|
-void camera_augment_helper_v2::impl::cursor_guide_slot(const scene_ptr &info) {
|
|
|
- assert(enable_cursor_guide);
|
|
|
-
|
|
|
- if (cursor_symbol == nullptr) [[unlikely]] {
|
|
|
- vtkNew<vtkSphereSource> source;
|
|
|
- source->SetRadius(5); // TODO: make this adjustable
|
|
|
- source->SetCenter(0, 0, 0);
|
|
|
- source->Update();
|
|
|
- cursor_symbol = mesh_type::from_vtk(source->GetOutput());
|
|
|
- }
|
|
|
-
|
|
|
- // record cursor position
|
|
|
- auto rec_info = scene_render_info::custom_info{
|
|
|
- .func = [this] { update_cursor_coordinate(); },
|
|
|
- };
|
|
|
- info->items.push_back({.info = rec_info});
|
|
|
-
|
|
|
- if (cursor_pos.has_value()) {
|
|
|
- auto color = glm::vec3(0.0f, 1.0f, 0.0f); // TODO: make this adjustable
|
|
|
- auto amb_factor = 0.9f;
|
|
|
- auto item_info = scene_render_info::mesh_info{
|
|
|
- .mesh = cursor_symbol,
|
|
|
- .material = {.ambient = color * amb_factor, .diffuse = color,},
|
|
|
- .enable_depth_alpha = true, .alpha_factor = 0.f,
|
|
|
+void camera_augment_helper_v2::impl::pre_render_slot(const scene_ptr &info) {
|
|
|
+ if (ui->enable_active_guide && allow_active_guide) {
|
|
|
+ auto s_pos = ImGui::GetMousePos();
|
|
|
+ auto rec_info = scene_render_info::custom_info{
|
|
|
+ .func = [=, this] {
|
|
|
+ if (manager->get_current_camera_helper() != q_this) {
|
|
|
+ return; // not current camera helper
|
|
|
+ }
|
|
|
+ auto w_pos = get_cursor_coordinate(to_vec2(s_pos));
|
|
|
+ act_guide.update({.position = w_pos});
|
|
|
+ },
|
|
|
};
|
|
|
- info->items.push_back(
|
|
|
- {.info = item_info, .transform = glm::translate(*cursor_pos),});
|
|
|
+ info->items.push_back({.info = rec_info});
|
|
|
+ act_guide.pre_render_slot(info);
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-void camera_augment_helper_v2::impl::pre_render_slot(const scene_ptr &info) {
|
|
|
- if (!is_interactive) return;
|
|
|
- if (enable_cursor_guide) {
|
|
|
- cursor_guide_slot(info);
|
|
|
+ if (enable_passive_guide) {
|
|
|
+ auto rec_info = scene_render_info::custom_info{
|
|
|
+ .func = [=, this] {
|
|
|
+ auto w_pos = get_cursor_coordinate(pas_info.pos);
|
|
|
+ pas_guide.update({.position = w_pos});
|
|
|
+ },
|
|
|
+ };
|
|
|
+ info->items.push_back({.info = rec_info});
|
|
|
+ pas_guide.pre_render_slot(info);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void camera_augment_helper_v2::impl::set_interactive(bool flag) {
|
|
|
- is_interactive = flag;
|
|
|
-}
|
|
|
-
|
|
|
camera_augment_helper_v2::camera_augment_helper_v2(const create_config &conf)
|
|
|
: pimpl(std::make_unique<impl>(conf)) {
|
|
|
+ pimpl->q_this = this;
|
|
|
}
|
|
|
|
|
|
camera_augment_helper_v2::~camera_augment_helper_v2() = default;
|
|
|
@@ -370,11 +349,20 @@ void camera_augment_helper_v2::show() {
|
|
|
pimpl->show();
|
|
|
}
|
|
|
|
|
|
-void camera_augment_helper_v2::set_interactive(bool flag) {
|
|
|
- pimpl->set_interactive(flag);
|
|
|
+void camera_augment_helper_v2::sync_with(camera_augment_helper_v2 *other) {
|
|
|
+ pimpl->ui = other->pimpl->ui;
|
|
|
}
|
|
|
|
|
|
camera_info camera_augment_helper_v2::get_camera() {
|
|
|
pimpl->update_camera();
|
|
|
return pimpl->last_camera;
|
|
|
+}
|
|
|
+
|
|
|
+void camera_augment_helper_v2::set_active_guidance(bool flag) {
|
|
|
+ pimpl->allow_active_guide = flag;
|
|
|
+}
|
|
|
+
|
|
|
+void camera_augment_helper_v2::set_passive_guidance(bool flag, const guide_info &info) {
|
|
|
+ pimpl->enable_passive_guide = flag;
|
|
|
+ pimpl->pas_info = info;
|
|
|
}
|