From bc896e00555ea90bff87925681fdcd3f01d078b5 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Tue, 1 Feb 2022 11:46:03 -0500 Subject: [PATCH 01/23] add camera point of interests feature --- include/UI/UIView.h | 4 +- include/interaction/ArcBall.h | 90 ------------ include/vrapp/VRVolumeApp.h | 6 +- include/vrapp/VolumeVisualizationApp.h | 2 +- src/UI/UIView.cpp | 101 ++++++++++---- src/interaction/ArcBall.cpp | 181 ------------------------- src/vrapp/VRVolumeApp.cpp | 14 +- superbuild/CMakeLists.txt | 6 +- 8 files changed, 91 insertions(+), 313 deletions(-) delete mode 100644 include/interaction/ArcBall.h delete mode 100644 src/interaction/ArcBall.cpp diff --git a/include/UI/UIView.h b/include/UI/UIView.h index 4afb3f7..dfb9f87 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -181,7 +181,9 @@ class UIView glm::vec3 m_clip_ypr; glm::vec3 m_clip_pos; - int m_table_selection; + int m_trnfnc_table_selection; + + int m_camera_poi_table_selection; bool m_initialized; diff --git a/include/interaction/ArcBall.h b/include/interaction/ArcBall.h deleted file mode 100644 index 9c663d2..0000000 --- a/include/interaction/ArcBall.h +++ /dev/null @@ -1,90 +0,0 @@ -// ---------------------------------- -// Copyright © 2017, Brown University, Providence, RI. -// -// All Rights Reserved -// -// Use of the software is provided under the terms of the GNU General Public License version 3 -// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided -// that this copyright notice appear in all copies and that the name of Brown University not be used in -// advertising or publicity pertaining to the use or distribution of the software without specific written -// prior permission from Brown University. -// -// See license.txt for further information. -// -// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED “AS IS”, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY -// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING -// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION -// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -// ---------------------------------- -// -///\file ArcBall.h -///\author Benjamin Knorlein -///\date 10/17/2019 - -#ifndef ARCBALL_H -#define ARCBALL_H - -#include -#include - -enum WASD_KEYS -{ - W = 1 << 0, // binary 000001 - A = 1 << 1, // binary 000010 - S = 1 << 2, // binary 000100 - D = 1 << 3, // binary 001000 - Q = 1 << 4, // binary 010000 - E = 1 << 5, // binary 100000 -}; - -/** Adds a HeadMatrix to the RenderState that gets updated repeatedly based - upon head tracking events. - */ -class ArcBall { -public: - - ArcBall(); - - virtual ~ArcBall(); - - void mouse_pressed(int button, bool isDown); - void mouse_move(float x, float y); - void mouse_scroll(float dist); - void setCameraCenterRotation(bool useCameraCenter); - void wasd_pressed(int awsd); - - glm::mat4& getViewmatrix() - { - updateCameraMatrix(); - return viewmatrix; - } - -protected: - void Rotate(float dTheta, float dPhi); - void RotateEyeAxis(float dy); - void Zoom(float distance); - void Pan(float dx, float dy); - void updateCameraMatrix(); - - float m_radius; - glm::vec3 m_target; - glm::vec3 m_up; - glm::vec3 m_eye; - - glm::mat4 viewmatrix; - bool m_mouse_left_pressed; - bool m_mouse_right_pressed; - bool m_mouse_center_pressed; - float last_x, last_y; - float m_PanFactor; - float m_RotateFactor; - float m_cameraScrollFactor; - - bool m_rotate_camera_center; -}; - -#endif - diff --git a/include/vrapp/VRVolumeApp.h b/include/vrapp/VRVolumeApp.h index a2dcca8..b61a4a7 100644 --- a/include/vrapp/VRVolumeApp.h +++ b/include/vrapp/VRVolumeApp.h @@ -6,7 +6,7 @@ #include #include #include "interaction/Labels.h" -#include "interaction/ArcBall.h" +#include "interaction/ArcBallCamera.h" #include "render/Volume.h" #include "Model.h" @@ -152,7 +152,7 @@ class VRVolumeApp std::vector< Volume* >& get_volume(int volume); - + ArcBallCamera& get_trackball_camera(); protected: @@ -230,7 +230,7 @@ class VRVolumeApp glm::mat4 m_model_view; - ArcBall m_trackball; + ArcBallCamera m_trackball; bool m_lookingGlass; glm::mat4 m_object_pose; diff --git a/include/vrapp/VolumeVisualizationApp.h b/include/vrapp/VolumeVisualizationApp.h index 8d4f779..fe57f6f 100644 --- a/include/vrapp/VolumeVisualizationApp.h +++ b/include/vrapp/VolumeVisualizationApp.h @@ -33,7 +33,7 @@ #include "render/VolumeRaycastRenderer.h" #include "render/DepthTexture.h" #include -#include "interaction/ArcBall.h" +#include "interaction/ArcBallCamera.h" diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index a15a2f6..a3f6263 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -19,11 +19,11 @@ UIView::UIView(VRVolumeApp& controllerApp) :m_controller_app(controllerApp), m_m m_z_scale(0.16f), m_scale{ 1.0f }, m_slices(256), m_dynamic_slices(false), m_renderVolume(true), m_selectedTrnFnc(0), m_animated(false), m_ui_frame_controller(0.0f), m_menu_handler(nullptr), m_initialized(false), m_use_transferfunction(false), m_clip_max(1.0), m_clip_min(0.0), m_clip_ypr(0.0), m_clip_pos(0.0), m_useCustomClipPlane(false), m_rendermethod(1), m_renderchannel(0), -m_table_selection(-1), m_trn_fct_opitions_window(false), m_save_trnfct_open(false), m_trnfnct_counter(1), m_file_dialog_open(false), +m_trnfnc_table_selection(-1), m_trn_fct_opitions_window(false), m_save_trnfct_open(false), m_trnfnct_counter(1), m_file_dialog_open(false), m_file_load_trnsf(false), m_file_dialog_save_dir(false), m_save_session_dialog_open(false), m_current_save_modal(SAVE_NONE), m_current_load_modal(LOAD_NONE), m_file_extension_filter(".txt"), m_non_trns_functions_selected_modal(false), m_ui_background(false), m_column_selection_state(0), m_compute_new_histogram(true), m_histogram_point_1(0.0), -m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"),m_show_menu(true) +m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0) { m_ocean_color_maps_names = { "algae.png","amp.png","balance.png","curl.png","deep.png","delta.png","dense.png", "diff.png","gray.png","haline.png","ice.png","matter.png","oxy.png","phase.png","rain.png","solar.png","speed.png","tarn.png","tempo.png", @@ -120,7 +120,7 @@ void UIView::draw_ui_callback() addTransferFunction(); if (m_tfns.size() == 1) { - m_table_selection = 0; + m_trnfnc_table_selection = 0; } }; @@ -136,16 +136,16 @@ void UIView::draw_ui_callback() tfn_widget.push_back(TransferFunctionWidget()); tfn_widget_multi.push_back(TransferFunctionMultiChannelWidget()); addTransferFunction(); - m_table_selection = 0; + m_trnfnc_table_selection = 0; } - else if (m_tfns.size() > 1 && m_table_selection >= 0) + else if (m_tfns.size() > 1 && m_trnfnc_table_selection >= 0) { - tfn_widget.erase(tfn_widget.begin() + m_table_selection); ; - tfn_widget_multi.erase(tfn_widget_multi.begin() + m_table_selection); - m_tfns.erase(m_tfns.begin() + m_table_selection); - if (m_table_selection != 0) + tfn_widget.erase(tfn_widget.begin() + m_trnfnc_table_selection); ; + tfn_widget_multi.erase(tfn_widget_multi.begin() + m_trnfnc_table_selection); + m_tfns.erase(m_tfns.begin() + m_trnfnc_table_selection); + if (m_trnfnc_table_selection != 0) { - m_table_selection = m_table_selection - 1; + m_trnfnc_table_selection = m_trnfnc_table_selection - 1; } } @@ -169,7 +169,7 @@ void UIView::draw_ui_callback() trfntc.volumes.push_back(false); } m_tfns.push_back(trfntc); - m_table_selection = 0; + m_trnfnc_table_selection = 0; }; ImGui::SameLine(); @@ -246,17 +246,17 @@ void UIView::draw_ui_callback() { ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_AllowDoubleClick; - bool item_is_selected = (row == m_table_selection) ? true : false; + bool item_is_selected = (row == m_trnfnc_table_selection) ? true : false; if (ImGui::Selectable(m_tfns[row].Name.c_str(), item_is_selected, selectable_flags)) { - m_table_selection = row; + m_trnfnc_table_selection = row; if (ImGui::IsMouseDoubleClicked(0)) { m_copy_trnfnct_name = m_tfns[row].Name; float q_min = 0; float q_max = 0; - tfn_widget[m_table_selection].get_Quantiles(q_min, q_max); + tfn_widget[m_trnfnc_table_selection].get_Quantiles(q_min, q_max); m_histogram_quantiles[0] = q_min; m_histogram_quantiles[1] = q_max; m_trn_fct_opitions_window = true; @@ -351,12 +351,12 @@ void UIView::draw_ui_callback() if (ImGui::Button("Adjust to Histogram")) { adjust_transfer_function_to_histogram(); - tfn_widget[m_table_selection].alpha_control_pts.clear(); - tfn_widget[m_table_selection].alpha_control_pts.push_back(vec2f(0.0, 0.0)); - tfn_widget[m_table_selection].alpha_control_pts.push_back(m_histogram_point_1); - tfn_widget[m_table_selection].alpha_control_pts.push_back(m_histogram_point_2); - tfn_widget[m_table_selection].alpha_control_pts.push_back(vec2f(1.0, 1.0)); - tfn_widget[m_table_selection].set_Quantiles(m_histogram_quantiles[0], m_histogram_quantiles[1]); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.clear(); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(vec2f(0.0, 0.0)); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(m_histogram_point_1); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(m_histogram_point_2); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(vec2f(1.0, 1.0)); + tfn_widget[m_trnfnc_table_selection].set_Quantiles(m_histogram_quantiles[0], m_histogram_quantiles[1]); ImGui::OpenPopup("Confirmation"); ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); } @@ -376,7 +376,7 @@ void UIView::draw_ui_callback() if (ImGui::Button("Ok")) { - m_tfns[m_table_selection].Name = m_copy_trnfnct_name; + m_tfns[m_trnfnc_table_selection].Name = m_copy_trnfnct_name; m_trn_fct_opitions_window = false; m_current_save_modal = SAVE_MODAL::SAVE_NONE; ImGui::CloseCurrentPopup(); @@ -426,7 +426,7 @@ void UIView::draw_ui_callback() } m_controller_app.set_multi_transfer(true); //tfn_widget_multi[m_selectedTrnFnc].draw_histogram(); - tfn_widget_multi[m_table_selection].draw_ui(); + tfn_widget_multi[m_trnfnc_table_selection].draw_ui(); } else { @@ -448,7 +448,7 @@ void UIView::draw_ui_callback() m_controller_app.set_multi_transfer(false); m_histogram.draw_histogram(); - tfn_widget[m_table_selection].draw_ui(); + tfn_widget[m_trnfnc_table_selection].draw_ui(); } } @@ -521,6 +521,49 @@ void UIView::draw_ui_callback() } ImGui::EndTabItem(); } + + if (ImGui::BeginTabItem("Camera")) + { + + ImGui::Text("Points of Interest"); + + if (ImGui::Button("Add")) { + m_controller_app.get_trackball_camera().add_camera_poi(); + m_camera_poi_table_selection = 0; + } + ImGui::SameLine(); + if (ImGui::Button("Remove")) { + if (m_controller_app.get_trackball_camera().get_camera_poi().size() > 0) + { + m_controller_app.get_trackball_camera().remove_poi(m_camera_poi_table_selection); + m_camera_poi_table_selection = m_camera_poi_table_selection - 1 < 0 ? 0 : m_camera_poi_table_selection--; + m_controller_app.get_trackball_camera().set_current_poi(m_camera_poi_table_selection); + } + + } + + + ImGui::BeginTable("##Camera Point of interest (POI) Editor", 1, ImGuiTableFlags_Borders); + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 120.0f); + + + for (int row = 0 ; row < m_controller_app.get_trackball_camera().get_camera_poi().size(); ++row) + { + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + bool item_is_selected = (row == m_camera_poi_table_selection) ? true : false; + if (ImGui::Selectable(m_controller_app.get_trackball_camera().get_poi_at(row).label.c_str(), item_is_selected)) + { + m_camera_poi_table_selection = row; + m_controller_app.get_trackball_camera().set_current_poi(row); + + } + } + ImGui::EndTable(); + + ImGui::EndTabItem(); + } + ImGui::EndTabBar(); //file loading @@ -549,9 +592,9 @@ void UIView::draw_ui_callback() promises.push_back(new std::promise); futures.push_back(promises.back()->get_future()); threads.push_back(new std::thread(&VolumeVisualizationApp::loadVolume, this, vals, promises.back()));*/ - } -#endif } +#endif +} @@ -615,7 +658,7 @@ void UIView::draw_ui_callback() std::string filePath = fileDialogLoadTrnsFnc.selected_path; std::ifstream fileToLoad(filePath); load_trans_functions(fileToLoad); - m_table_selection = 0; + m_trnfnc_table_selection = 0; m_current_load_modal = LOAD_NONE; } } @@ -628,7 +671,7 @@ void UIView::draw_ui_callback() tfn_widget_multi.clear(); m_tfns.clear(); load_user_session(fileDialogLoadTrnsFnc.selected_path); - m_table_selection = 0; + m_trnfnc_table_selection = 0; m_current_load_modal = LOAD_NONE; } } @@ -702,7 +745,7 @@ void UIView::update_ui(int numVolumes) trfntc.volumes.push_back(false); } m_tfns.push_back(trfntc); - m_table_selection = 0; + m_trnfnc_table_selection = 0; load_ocean_color_maps(); } @@ -1269,7 +1312,7 @@ void UIView::adjust_transfer_function_to_histogram() const std::size_t pos1 = std::floor(m_histogram_quantiles[0] * std::distance(histogram_copy.begin(), histogram_copy.end())); const std::size_t pos2 = std::floor(m_histogram_quantiles[1] * std::distance(histogram_copy.begin(), histogram_copy.end())); - if (histogram_copy.size() > pos1&& histogram_copy.size() > pos2) + if (histogram_copy.size() > pos1 && histogram_copy.size() > pos2) { std::nth_element(histogram_copy.begin(), histogram_copy.begin() + pos1, histogram_copy.end()); diff --git a/src/interaction/ArcBall.cpp b/src/interaction/ArcBall.cpp deleted file mode 100644 index 13ef64d..0000000 --- a/src/interaction/ArcBall.cpp +++ /dev/null @@ -1,181 +0,0 @@ -// ---------------------------------- -// Copyright © 2017, Brown University, Providence, RI. -// -// All Rights Reserved -// -// Use of the software is provided under the terms of the GNU General Public License version 3 -// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided -// that this copyright notice appear in all copies and that the name of Brown University not be used in -// advertising or publicity pertaining to the use or distribution of the software without specific written -// prior permission from Brown University. -// -// See license.txt for further information. -// -// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED “AS IS”, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY -// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING -// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION -// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -// ---------------------------------- -// -///\file ArcBall.cpp -///\author Benjamin Knorlein -///\date 10/17/2019 - - -#include "../../include/interaction/ArcBall.h" -#include -#include "glm/ext.hpp" -#include -#define GLM_ENABLE_EXPERIMENTAL -#include - -#ifndef _PI -#define _PI 3.141592653 -#endif - -ArcBall::ArcBall() : m_radius(1), m_mouse_left_pressed(false), m_mouse_center_pressed(false), m_mouse_right_pressed(false), last_x(0), last_y(0) -, m_PanFactor(1), m_RotateFactor(1), m_cameraScrollFactor(0.1), m_target(0, 0, 0), m_eye(0, 0, 1), m_up(0, 1, 0), m_rotate_camera_center{ false } -{ - - -} - -ArcBall::~ArcBall() -{ - -} - -void ArcBall::updateCameraMatrix() -{ - m_eye = glm::normalize(m_eye); - viewmatrix = glm::lookAt(m_radius * m_eye + m_target, m_target, m_up); -} - -void ArcBall::mouse_pressed(int button, bool isDown) -{ - if (button == 0) //left -> rotate - { - m_mouse_left_pressed = isDown; - } - else if (button == 1) // right ->pan - { - m_mouse_right_pressed = isDown; - - } - else if (button == 2) - { - - m_mouse_center_pressed = isDown; - } -} - -void ArcBall::mouse_move(float x, float y) { - if (m_mouse_left_pressed) { - // Calculate the new phi and theta based on mouse position relative to where the user clicked - float dx = ((float)(last_x - x)) / 300.0f; - float dy = ((float)(last_y - y)) / 300.0f; - - Rotate(dx * m_RotateFactor, -dy * m_RotateFactor); - } - else if (m_mouse_center_pressed) { - float dy = ((float)(last_y - y)) / 300.0f; - - RotateEyeAxis(dy * m_RotateFactor); - } - else if (m_mouse_right_pressed) { - float dx = ((float)(last_x - x)) / 300.0f; - float dy = ((float)(last_y - y)) / 300.0f; - - Pan(-dx * m_PanFactor, -dy * m_PanFactor); - } - - last_x = x; - last_y = y; -} - -void ArcBall::mouse_scroll(float dist) { - Zoom(dist); -} - -void ArcBall::setCameraCenterRotation(bool useCameraCenter) { - if (useCameraCenter != m_rotate_camera_center) { - m_rotate_camera_center = useCameraCenter; - if (!m_rotate_camera_center) { - m_target = glm::vec3{ 0.0 }; - } - } -} - -void ArcBall::wasd_pressed(int awsd) { - glm::vec3 dir = glm::normalize(-m_eye); - glm::vec3 right = glm::cross(dir, m_up); - - if (W & awsd) { - m_target = m_target + dir * glm::vec3(0.001); - updateCameraMatrix(); - } - if (S & awsd) { - m_target = m_target - dir * glm::vec3(0.001); - updateCameraMatrix(); - } - if (A & awsd) { - m_target = m_target - (right)*glm::vec3(0.001); - updateCameraMatrix(); - } - if (D & awsd) { - m_target = m_target + (right)*glm::vec3(0.001); - updateCameraMatrix(); - } - if (Q & awsd) { - m_target = m_target - (m_up)*glm::vec3(0.001); - updateCameraMatrix(); - } - if (E & awsd) { - m_target = m_target + (m_up)*glm::vec3(0.001); - updateCameraMatrix(); - } -} - -void ArcBall::Rotate(float dx, float dy) { - glm::vec3 right = glm::cross(glm::normalize(m_eye), m_up); - glm::mat4 rot = glm::mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); - rot = glm::rotate(rot, dx, m_up); - rot = glm::rotate(rot, dy, right); - - if (m_rotate_camera_center) - m_target += m_radius * glm::normalize(m_eye); - - m_eye = rot * glm::vec4(m_eye, 1); - m_up = rot * glm::vec4(m_up, 1); - - if (m_rotate_camera_center) - m_target -= m_radius * glm::normalize(m_eye); - else - m_target = rot * glm::vec4(m_target, 1); -} - -void ArcBall::RotateEyeAxis(float dy) { - glm::mat4 rot = glm::mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); - rot = glm::rotate(rot, dy, m_eye); - m_up = rot * glm::vec4(m_up, 1); -} - -void ArcBall::Zoom(float distance) { - m_radius -= distance; - - if (m_radius < 0) - m_radius = 0.000001; -} - -void ArcBall::Pan(float dx, float dy) { - - glm::vec3 right = glm::cross(m_eye, m_up); - - m_target = m_target + (right * dx) + (m_up * dy); -} - - - diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index 9cd822f..f1ee5d3 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -166,7 +166,7 @@ void VRVolumeApp::update_trackBall_state() { if (m_wasd_pressed) { - m_trackball.wasd_pressed(m_wasd_pressed); + get_trackball_camera().wasd_pressed(m_wasd_pressed); } } @@ -532,7 +532,7 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) //overwrite MV for 2D viewing if (m_is2d) - m_model_view = m_trackball.getViewmatrix(); + m_model_view = get_trackball_camera().getViewmatrix(); glMatrixMode(GL_PROJECTION); glLoadMatrixf(glm::value_ptr(m_projection_mtrx)); @@ -993,7 +993,7 @@ void VRVolumeApp::set_num_volumes(int nVolumes) void VRVolumeApp::mouse_pos_event(glm::vec2& mPos) { - m_trackball.mouse_move(mPos.x, mPos.y); + get_trackball_camera().mouse_move(mPos.x, mPos.y); if (m_ui_view) { m_ui_view->set_cursor_pos(mPos); @@ -1013,7 +1013,7 @@ void VRVolumeApp::update_ui_events(float value) void VRVolumeApp::update_track_ball_event(float value) { - m_trackball.mouse_scroll(value); + get_trackball_camera().mouse_scroll(value); } void VRVolumeApp::button_events_ui_handle(int button, int state) @@ -1027,7 +1027,7 @@ void VRVolumeApp::button_events_ui_handle(int button, int state) void VRVolumeApp::button_event_trackBall_handle(int button, int state) { - m_trackball.mouse_pressed(button, state); + get_trackball_camera().mouse_pressed(button, state); } void VRVolumeApp::enable_grab(bool grab) @@ -1108,3 +1108,7 @@ void VRVolumeApp::do_grab(glm::mat4& newPose) m_controller_pose = newPose; } +ArcBallCamera& VRVolumeApp::get_trackball_camera() +{ + return m_trackball; +} diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index 27f5c54..ee6f631 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -391,7 +391,7 @@ if(OpenCV_FOUND) message(STATUS "OpenCV found ${OpenCV_INSTALL_PATH}") if(WIN32) set(OPENCV_PATH ${_OpenCV_LIB_PATH} ) - set(OPENCV_SUFIX "454" ) + set(OPENCV_SUFIX "455" ) elseif(APPLE) set(OPENCV_PATH "${CMAKE_BINARY_DIR}/install_${CMAKE_SYSTEM_NAME}/lib") set(OPENCV_PREFIX "lib" ) @@ -537,7 +537,7 @@ endif() ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/transfer_function_multichannel_widget.cpp ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/histogram.cpp ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/Vec2.cpp - ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/ArcBall.cpp + ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/ArcBallCamera.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/HelperFunctions.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/CreateMovieAction.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/loader/LoadDescriptionAction.cpp @@ -565,7 +565,7 @@ set(header_files ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/embedded_colormaps.h ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/histogram.h ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/Vec2.h - ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/ArcBall.h + ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/ArcBallCamera.h ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/HelperFunctions.h ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/CreateMovieAction.h ${CMAKE_CURRENT_BINARY_DIR}/../include/loader/LoadDescriptionAction.h From ce019e5d452504988c5c3b5dc73ae4e981c0266f Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Tue, 1 Feb 2022 19:59:04 -0500 Subject: [PATCH 02/23] add poi to save and load session functionality --- include/UI/UIView.h | 5 +++ src/UI/UIView.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/include/UI/UIView.h b/include/UI/UIView.h index dfb9f87..8189f5c 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -138,6 +138,11 @@ class UIView void load_user_session(std::string filePath); + void save_camera_poi(std::ofstream& loadPath, int num_poi); + + void load_camera_poi(std::ifstream& loadPath,int num_poi); + + void read_file_line(std::string& line, std::vector& values); VRVolumeApp& m_controller_app; VRMenuHandler* m_menu_handler; diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index a3f6263..ad2518e 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -1091,7 +1091,7 @@ void UIView::save_trans_functions(std::ofstream& saveFile) } saveFile << "\n"; } - saveFile.close(); + } } @@ -1122,11 +1122,21 @@ void UIView::save_user_session(std::ofstream& savefile) savefile << "ClipZmax " << std::to_string(m_clip_max.z) << "\n"; savefile << "Use_transferfunction " << std::to_string(m_use_transferfunction) << "\n"; + int num_camera_poi = m_controller_app.get_trackball_camera().get_camera_poi().size(); + if (num_camera_poi > 0) + { + savefile << "POI " << num_camera_poi << "\n"; + save_camera_poi(savefile, num_camera_poi); + } + if (m_use_transferfunction) { savefile << "Trnfncs" << "\n"; save_trans_functions(savefile); } + + + savefile.close(); } @@ -1142,7 +1152,7 @@ void UIView::load_trans_functions(std::ifstream& loadFile) { while (std::getline(loadFile, line)) { - std::vector vals; // Create vector to hold our words + std::vector vals; std::stringstream ss(line); std::string buf; @@ -1291,9 +1301,73 @@ void UIView::load_user_session(std::string filePath) { load_trans_functions(loadFile); } + else if (tag == "POI") + { + load_camera_poi(loadFile, std::stoi(vals[1])); + } } loadFile.close(); + m_controller_app.get_trackball_camera().rest_camera(); + } +} + +void UIView::save_camera_poi(std::ofstream& saveFile,int num_camera_poi) +{ + if (saveFile.is_open()) + { + + auto poit_iterator = m_controller_app.get_trackball_camera().get_camera_poi().begin(); + for (poit_iterator; poit_iterator != m_controller_app.get_trackball_camera().get_camera_poi().end(); poit_iterator++) + { + saveFile << poit_iterator->label << " " + << std::to_string(poit_iterator->eye.x) + " " + std::to_string(poit_iterator->eye.y) + " " + std::to_string(poit_iterator->eye.z) + " " + << std::to_string(poit_iterator->target.x) + " " + std::to_string(poit_iterator->target.y) + " " + std::to_string(poit_iterator->target.z) + " " + << std::to_string(poit_iterator->up.x) + " " + std::to_string(poit_iterator->up.y) + " " + std::to_string(poit_iterator->up.z) + " " + << std::to_string(poit_iterator->radius) + "\n"; + } + } +} + +void UIView::load_camera_poi(std::ifstream& loadFile, int num_poi) +{ + std::string line; + if (loadFile.is_open()) + { + for (int i = 0; i < num_poi; ++i) + { + std::getline(loadFile, line); + std::vector poiVals; + read_file_line(line, poiVals); + + if (poiVals.size() > 0) + { + std::string label = poiVals[0]; + float eye_x = std::stof(poiVals[1]); + float eye_y = std::stof(poiVals[2]); + float eye_z = std::stof(poiVals[3]); + float target_x = std::stof(poiVals[4]); + float target_y = std::stof(poiVals[5]); + float target_z = std::stof(poiVals[6]); + float up_x = std::stof(poiVals[7]); + float up_y = std::stof(poiVals[8]); + float up_z = std::stof(poiVals[9]); + float radius = std::stof(poiVals[10]); + m_controller_app.get_trackball_camera().add_camera_poi(label,eye_x, eye_y, eye_z, target_x, target_y, target_z, up_x, up_y, up_z, radius); + } + + } + } + +} + + +void UIView::read_file_line(std::string& line, std::vector& values) +{ + std::stringstream ss(line); + std::string buf; + while (ss >> buf) { + values.push_back(buf); } } From 4cf1ec74bb2a85cf64615896498e0204a0c510fd Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Wed, 23 Feb 2022 09:17:03 -0500 Subject: [PATCH 03/23] more changes on UI control --- include/UI/UIView.h | 5 +++++ include/vrapp/VRVolumeApp.h | 3 +++ src/UI/UIView.cpp | 29 +++++++++++++++++++++++------ src/vrapp/VRVolumeApp.cpp | 32 ++++++++++++++++++++------------ 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/include/UI/UIView.h b/include/UI/UIView.h index 8189f5c..8b83532 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -116,6 +116,8 @@ class UIView void addTransferFunction(); + void set_animation_length(int num_frames); + private: struct MyTransFerFunctions @@ -177,6 +179,7 @@ class UIView bool m_animated; float m_ui_frame_controller; + unsigned int m_num_animation_frames; float m_stopped; glm::vec3 m_clip_min; @@ -236,6 +239,8 @@ class UIView std::string m_color_map_directory; + float m_animation_speed; + }; diff --git a/include/vrapp/VRVolumeApp.h b/include/vrapp/VRVolumeApp.h index b61a4a7..7324f6b 100644 --- a/include/vrapp/VRVolumeApp.h +++ b/include/vrapp/VRVolumeApp.h @@ -154,6 +154,8 @@ class VRVolumeApp ArcBallCamera& get_trackball_camera(); + void set_animation_speed(float time); + protected: glm::vec4 m_noColor;// (0.0f, 0.0f, 0.0f, 0.0f); @@ -206,6 +208,7 @@ class VRVolumeApp bool m_animated; float m_threshold; int m_descriptionHeight; + float m_animation_speed; float m_frame; float m_speed; diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index ad2518e..8550250 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -14,6 +14,7 @@ #include "common/common.h" #include +#include UIView::UIView(VRVolumeApp& controllerApp) :m_controller_app(controllerApp), m_multiplier(1.0f), m_threshold(0.0f), m_z_scale(0.16f), m_scale{ 1.0f }, m_slices(256), m_dynamic_slices(false), m_renderVolume(true), m_selectedTrnFnc(0), @@ -23,7 +24,8 @@ m_trnfnc_table_selection(-1), m_trn_fct_opitions_window(false), m_save_trnfct_op m_file_load_trnsf(false), m_file_dialog_save_dir(false), m_save_session_dialog_open(false), m_current_save_modal(SAVE_NONE), m_current_load_modal(LOAD_NONE), m_file_extension_filter(".txt"), m_non_trns_functions_selected_modal(false), m_ui_background(false), m_column_selection_state(0), m_compute_new_histogram(true), m_histogram_point_1(0.0), -m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0) +m_histogram_point_2(1.1), m_stopped(true), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0), +m_num_animation_frames(0), m_animation_speed(1.0f) { m_ocean_color_maps_names = { "algae.png","amp.png","balance.png","curl.png","deep.png","delta.png","dense.png", "diff.png","gray.png","haline.png","ice.png","matter.png","oxy.png","phase.png","rain.png","solar.png","speed.png","tarn.png","tempo.png", @@ -202,7 +204,6 @@ void UIView::draw_ui_callback() const char* column_name = ImGui::TableGetColumnName(column); ImGui::PushID(column); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - //ImGui::RadioButton("", &m_column_selected, column-1); ImGui::SameLine(); ImGui::Checkbox("##checkall", &m_column_selected[column - 1]); ImGui::SameLine(); ImGui::PopStyleVar(); ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); @@ -462,15 +463,26 @@ void UIView::draw_ui_callback() ImGui::SetNextItemWidth(-100 - ImGui::GetStyle().ItemSpacing.x); float frame_tmp = m_controller_app.get_current_frame() + 1; //controls animated multi datasets - //ImGui::SliderFloat("##Timestep", &frame_tmp, 1, m_volumes[m_selectedVolume].size()); - m_ui_frame_controller = frame_tmp - 1; + ImGui::SliderFloat("##Timestep", &frame_tmp, 1, m_num_animation_frames); + m_ui_frame_controller = (frame_tmp) - 1; m_controller_app.set_frame(m_ui_frame_controller); - ImGui::SameLine(); + std::string text = m_stopped ? "Play" : "Stop"; - if (ImGui::Button(text.c_str(), ImVec2(100, 0))) { + if (ImGui::Button(text.c_str(), ImVec2(50, 0))) { m_stopped = !m_stopped; } + ImGui::SameLine(); + float value = (int)(m_animation_speed * 100 + .5); + std::string speed_text = ">>X "+std::to_string(value/100); + if (ImGui::Button(speed_text.c_str(), ImVec2(80, 0))) { + m_animation_speed += 0.5; + if (m_animation_speed > 4.0f) + { + m_animation_speed = 1.0f; + } + m_controller_app.set_animation_speed(m_animation_speed); + } #if (!defined(__APPLE__)) if (ImGui::Button("Write Movie")) @@ -1371,6 +1383,11 @@ void UIView::read_file_line(std::string& line, std::vector& values) } } +void UIView::set_animation_length(int num_frames) +{ + m_num_animation_frames = num_frames; +} + void UIView::adjust_transfer_function_to_histogram() { diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index f1ee5d3..fede336 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -40,7 +40,7 @@ #include #include "GLMLoader.h" #include - +#include #include @@ -49,7 +49,7 @@ VRVolumeApp::VRVolumeApp() :m_mesh_model(nullptr), m_clip_max{ 1.0f }, m_clip_mi m_lookingGlass(false), m_isInitailized(false), m_speed(0.01f), m_movieAction(nullptr), m_moviename("movie.mp4"), m_noColor(0.0f), m_ambient(0.2f, 0.2f, 0.2f, 1.0f), m_diffuse(0.5f, 0.5f, 0.5f, 1.0f), m_ui_view(nullptr), m_animated(false), m_numVolumes(0), m_selectedVolume(0), m_multiplier(1.0f), m_threshold(0.0f), m_frame(0.0f), m_use_multi_transfer(false), m_clipping(false), m_show_menu(true), -m_window_properties(nullptr) +m_window_properties(nullptr), m_animation_speed(1.0f) { m_renders.push_back(new VolumeSliceRenderer()); m_renders.push_back(new VolumeRaycastRenderer()); @@ -177,7 +177,7 @@ void VRVolumeApp::update_animation() { if (m_volumes.size()) { - m_ui_view->update_animation(m_speed, m_volumes[m_selectedVolume].size() - 1); + m_ui_view->update_animation(m_speed * m_animation_speed, m_volumes[m_selectedVolume].size() - 1); } } } @@ -637,7 +637,7 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) }*/ //drawTime - if (m_is2d && m_animated) { + /*if (m_is2d && m_animated) { unsigned int active_volume = floor(m_frame); unsigned int active_volume2 = ceil(m_frame); if (active_volume < m_volumes[0].size() && active_volume2 < m_volumes[0].size() && m_volumes[0][active_volume]->texture_initialized() && m_volumes[0][active_volume2]->texture_initialized()) { @@ -645,7 +645,7 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) time_t time = m_volumes[0][active_volume]->getTime() * (1 - alpha) + m_volumes[0][active_volume2]->getTime() * alpha; FontHandler::getInstance()->drawClock(time); } - } + }*/ glFlush(); @@ -659,7 +659,7 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) #endif std::cerr << "Add Frame" << std::endl; m_movieAction->addFrame(); - if (m_frame > m_volumes[m_selectedVolume].size() - 1 - m_speed) { + if (m_frame > m_volumes[m_selectedVolume].size() - 1 - (m_speed * m_animation_speed)) { std::cerr << "Save Movie" << std::endl; #ifdef _MSC_VER m_movieAction->save(m_moviename); @@ -767,16 +767,18 @@ void VRVolumeApp::animated_render(int tfn, int vol) { unsigned int active_volume = floor(m_frame); unsigned int active_volume2 = ceil(m_frame); - int renderMethod = m_ui_view->get_render_method(); - bool useTranferFunction = m_ui_view->is_use_transfer_function_enabled(); + int render_method = m_ui_view->get_render_method(); + bool use_tranferFunction = m_ui_view->is_use_transfer_function_enabled(); //bool useMultitransferFunction = m_ui_view->isUseMultiTransfer(); + size_t max_animation_length = 0; if (m_ui_view && m_ui_view->is_transfer_function_enabled(tfn, vol)) { + max_animation_length = std::max(max_animation_length, m_volumes[vol].size()); if (active_volume < m_volumes[vol].size() && active_volume2 < m_volumes[vol].size() && m_volumes[vol][active_volume]->texture_initialized() && m_volumes[vol][active_volume2]->texture_initialized()) { - m_renders[renderMethod]->set_blending(true, m_frame - active_volume, m_volumes[vol][active_volume2]); + m_renders[render_method]->set_blending(true, m_frame - active_volume, m_volumes[vol][active_volume2]); if (m_ui_view->is_render_volume_enabled()) { @@ -784,7 +786,7 @@ void VRVolumeApp::animated_render(int tfn, int vol) GLint colorMap = m_ui_view->get_transfer_function_colormap(tfn); GLint colorMapMult = m_ui_view->get_multitransfer_function_colormap(tfn); GLint lut = -1; - if (useTranferFunction) + if (use_tranferFunction) { if (m_use_multi_transfer) { @@ -797,11 +799,12 @@ void VRVolumeApp::animated_render(int tfn, int vol) } - m_renders[renderMethod]->render(m_volumes[vol][active_volume], m_volumes[vol][active_volume]->get_volume_mv(), m_projection_mtrx, m_volumes[vol][active_volume]->get_volume_scale().x / m_volumes[vol][active_volume]->get_volume_scale().z, + m_renders[render_method]->render(m_volumes[vol][active_volume], m_volumes[vol][active_volume]->get_volume_mv(), m_projection_mtrx, m_volumes[vol][active_volume]->get_volume_scale().x / m_volumes[vol][active_volume]->get_volume_scale().z, lut, m_ui_view->get_render_channel()); } } } + m_ui_view->set_animation_length(max_animation_length); } @@ -838,7 +841,7 @@ void VRVolumeApp::update_frame_state() glLightfv(GL_LIGHT0, GL_POSITION, m_light_pos); if (m_animated && !m_ui_view->is_stopped()) { - m_frame += m_speed; + m_frame += (m_speed * m_animation_speed); if (m_frame > m_volumes[m_selectedVolume].size() - 1) m_frame = 0.0; } m_rendercount = 0; @@ -1112,3 +1115,8 @@ ArcBallCamera& VRVolumeApp::get_trackball_camera() { return m_trackball; } + +void VRVolumeApp::set_animation_speed(float time) +{ + m_animation_speed = time; +} From 9142b5fb1023bcf56457dda5ece20f37489637ee Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Wed, 23 Feb 2022 15:51:18 -0500 Subject: [PATCH 04/23] add missed files in the last comment --- include/interaction/ArcBallCamera.h | 126 +++++++++++++++ src/interaction/ArcBallCamera.cpp | 235 ++++++++++++++++++++++++++++ 2 files changed, 361 insertions(+) create mode 100644 include/interaction/ArcBallCamera.h create mode 100644 src/interaction/ArcBallCamera.cpp diff --git a/include/interaction/ArcBallCamera.h b/include/interaction/ArcBallCamera.h new file mode 100644 index 0000000..70d4101 --- /dev/null +++ b/include/interaction/ArcBallCamera.h @@ -0,0 +1,126 @@ +// ---------------------------------- +// Copyright © 2017, Brown University, Providence, RI. +// +// All Rights Reserved +// +// Use of the software is provided under the terms of the GNU General Public License version 3 +// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided +// that this copyright notice appear in all copies and that the name of Brown University not be used in +// advertising or publicity pertaining to the use or distribution of the software without specific written +// prior permission from Brown University. +// +// See license.txt for further information. +// +// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS +// PROVIDED “AS IS”, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY +// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING +// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION +// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// ---------------------------------- +// +///\file ArcBall.h +///\author Benjamin Knorlein +///\date 10/17/2019 + +#ifndef ARCBALL_H +#define ARCBALL_H + +#include +#include +#include + + +enum WASD_KEYS +{ + W = 1 << 0, // binary 000001 + A = 1 << 1, // binary 000010 + S = 1 << 2, // binary 000100 + D = 1 << 3, // binary 001000 + Q = 1 << 4, // binary 010000 + E = 1 << 5, // binary 100000 +}; + +struct PointOfInterest { + std::string label; + glm::vec3 eye = glm::vec3(0.0f, 0.0f, 1.0f); + glm::vec3 target = glm::vec3(0.0f, 0.0f, 0.0f); + glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); + float radius = 1.f; + + glm::vec3 get_camera_position() + { + eye = glm::normalize(eye); + return radius * eye + target; + } + +}; + +/** Adds a HeadMatrix to the RenderState that gets updated repeatedly based + upon head tracking events. + */ +class ArcBallCamera { +public: + + ArcBallCamera(); + + virtual ~ArcBallCamera(); + + void mouse_pressed(int button, bool isDown); + void mouse_move(float x, float y); + void mouse_scroll(float dist); + void setCameraCenterRotation(bool useCameraCenter); + void wasd_pressed(int awsd); + + glm::mat4& getViewmatrix() + { + updateCameraMatrix(); + return viewmatrix; + } + + std::list& get_camera_poi(); + + void add_camera_poi(); + void add_camera_poi(std::string& label, float eye_x, float eye_y, float eye_z, + float target_x, float target_y, float target_z, + float up_x, float up_y, float up_z, float radius); + + int get_current_poi(); + + void set_current_poi(int val); + + void remove_poi(int val); + + void rest_camera(); + + PointOfInterest& get_poi_at(int val); + +protected: + void Rotate(float dTheta, float dPhi); + void RotateEyeAxis(float dy); + void Zoom(float distance); + void Pan(float dx, float dy); + void updateCameraMatrix(); + + float m_radius; + glm::vec3 m_target; + glm::vec3 m_up; + glm::vec3 m_eye; + std::list m_camera_poi; + PointOfInterest m_current_poi; + + glm::mat4 viewmatrix; + bool m_mouse_left_pressed; + bool m_mouse_right_pressed; + bool m_mouse_center_pressed; + float last_x, last_y; + float m_PanFactor; + float m_RotateFactor; + float m_cameraScrollFactor; + + bool m_rotate_camera_center; +}; + +#endif + diff --git a/src/interaction/ArcBallCamera.cpp b/src/interaction/ArcBallCamera.cpp new file mode 100644 index 0000000..4802bee --- /dev/null +++ b/src/interaction/ArcBallCamera.cpp @@ -0,0 +1,235 @@ +// ---------------------------------- +// Copyright © 2017, Brown University, Providence, RI. +// +// All Rights Reserved +// +// Use of the software is provided under the terms of the GNU General Public License version 3 +// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided +// that this copyright notice appear in all copies and that the name of Brown University not be used in +// advertising or publicity pertaining to the use or distribution of the software without specific written +// prior permission from Brown University. +// +// See license.txt for further information. +// +// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS +// PROVIDED “AS IS”, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY +// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING +// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION +// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// ---------------------------------- +// +///\file ArcBall.cpp +///\author Benjamin Knorlein +///\date 10/17/2019 + + +#include "../../include/interaction/ArcBallCamera.h" +#include +#include "glm/ext.hpp" +#include +#define GLM_ENABLE_EXPERIMENTAL +#include + +#ifndef _PI +#define _PI 3.141592653 +#endif + +ArcBallCamera::ArcBallCamera() : m_radius(1), m_mouse_left_pressed(false), m_mouse_center_pressed(false), m_mouse_right_pressed(false), last_x(0), last_y(0) +, m_PanFactor(1), m_RotateFactor(1), m_cameraScrollFactor(0.1), m_target(0, 0, 0), m_eye(0, 0, 1), m_up(0, 1, 0), m_rotate_camera_center{ false } +{ + +} + +ArcBallCamera::~ArcBallCamera() +{ + +} + +void ArcBallCamera::updateCameraMatrix() +{ + viewmatrix = glm::lookAt(m_current_poi.get_camera_position(), m_current_poi.target, m_current_poi.up); +} + +void ArcBallCamera::mouse_pressed(int button, bool isDown) +{ + if (button == 0) //left -> rotate + { + m_mouse_left_pressed = isDown; + } + else if (button == 1) // right ->pan + { + m_mouse_right_pressed = isDown; + + } + else if (button == 2) + { + + m_mouse_center_pressed = isDown; + } +} + +void ArcBallCamera::mouse_move(float x, float y) { + if (m_mouse_left_pressed) { + // Calculate the new phi and theta based on mouse position relative to where the user clicked + float dx = ((float)(last_x - x)) / 300.0f; + float dy = ((float)(last_y - y)) / 300.0f; + + Rotate(dx * m_RotateFactor, -dy * m_RotateFactor); + } + else if (m_mouse_center_pressed) { + float dy = ((float)(last_y - y)) / 300.0f; + + RotateEyeAxis(dy * m_RotateFactor); + } + else if (m_mouse_right_pressed) { + float dx = ((float)(last_x - x)) / 300.0f; + float dy = ((float)(last_y - y)) / 300.0f; + + Pan(-dx * m_PanFactor, -dy * m_PanFactor); + } + + last_x = x; + last_y = y; +} + +void ArcBallCamera::mouse_scroll(float dist) { + Zoom(dist); +} + +void ArcBallCamera::setCameraCenterRotation(bool useCameraCenter) { + if (useCameraCenter != m_rotate_camera_center) { + m_rotate_camera_center = useCameraCenter; + if (!m_rotate_camera_center) { + m_current_poi.target = glm::vec3{ 0.0 }; + } + } +} + +void ArcBallCamera::wasd_pressed(int awsd) { + glm::vec3 dir = glm::normalize(-m_current_poi.eye); + glm::vec3 right = glm::cross(dir, m_current_poi.up); + + if (W & awsd) { + m_current_poi.target = m_current_poi.target + dir * glm::vec3(0.001); + updateCameraMatrix(); + } + if (S & awsd) { + m_current_poi.target = m_current_poi.target - dir * glm::vec3(0.001); + updateCameraMatrix(); + } + if (A & awsd) { + m_current_poi.target = m_current_poi.target - (right)*glm::vec3(0.001); + updateCameraMatrix(); + } + if (D & awsd) { + m_current_poi.target = m_current_poi.target + (right)*glm::vec3(0.001); + updateCameraMatrix(); + } + if (Q & awsd) { + m_current_poi.target = m_target - m_current_poi.up * glm::vec3(0.001); + updateCameraMatrix(); + } + if (E & awsd) { + m_current_poi.target = m_target + m_current_poi.up * glm::vec3(0.001); + updateCameraMatrix(); + } +} + +void ArcBallCamera::Rotate(float dx, float dy) { + glm::vec3 right = glm::cross(glm::normalize(m_current_poi.eye), m_current_poi.up); + glm::mat4 rot = glm::mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + rot = glm::rotate(rot, dx, m_current_poi.up); + rot = glm::rotate(rot, dy, right); + + if (m_rotate_camera_center) + m_current_poi.target += m_current_poi.radius * glm::normalize(m_current_poi.eye); + + m_current_poi.eye = rot * glm::vec4(m_current_poi.eye, 1); + m_current_poi.up = rot * glm::vec4(m_current_poi.up, 1); + + if (m_rotate_camera_center) + m_current_poi.target -= m_current_poi.radius * glm::normalize(m_current_poi.eye); + else + m_current_poi.target = rot * glm::vec4(m_current_poi.target, 1); +} + +void ArcBallCamera::RotateEyeAxis(float dy) { + glm::mat4 rot = glm::mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + rot = glm::rotate(rot, dy, m_current_poi.eye); + m_current_poi.up = rot * glm::vec4(m_current_poi.up, 1); +} + +void ArcBallCamera::Zoom(float distance) { + m_current_poi.radius -= distance; + + if (m_current_poi.radius < 0) + { + m_current_poi.radius = 0.000001; + } + +} + +void ArcBallCamera::Pan(float dx, float dy) { + + glm::vec3 right = glm::cross(m_current_poi.eye, m_current_poi.up); + + m_current_poi.target = m_current_poi.target + (right * dx) + (m_current_poi.up * dy); +} + +std::list& ArcBallCamera::get_camera_poi() +{ + return m_camera_poi; +} + +void ArcBallCamera::add_camera_poi() +{ + m_current_poi.label = "Position-" + std::to_string(m_camera_poi.size() + 1); + m_camera_poi.push_front(m_current_poi); +} + +void ArcBallCamera::add_camera_poi(std::string& label, float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z, float radius) +{ + PointOfInterest poi; + poi.label = label; + poi.eye = glm::vec3(eye_x, eye_y, eye_z); + poi.target = glm::vec3(target_x, target_y, target_z); + poi.up = glm::vec3(up_x, up_y, up_z); + poi.radius = radius; + m_camera_poi.push_front(poi); +} + +int ArcBallCamera::get_current_poi() +{ + return 0; +} + +void ArcBallCamera::set_current_poi(int val) +{ + std::list::iterator it = m_camera_poi.begin(); + for (int i = 0; i < val; i++) { + ++it; + } + m_current_poi = *it; +} + +void ArcBallCamera::remove_poi(int val) +{ + auto poi_iterator = m_camera_poi.begin(); + std::advance(poi_iterator, val); + m_camera_poi.erase(poi_iterator); +} + +void ArcBallCamera::rest_camera() +{ + m_current_poi = PointOfInterest(); +} + +PointOfInterest& ArcBallCamera::get_poi_at(int val) +{ + auto poi_iterator = m_camera_poi.begin(); + std::advance(poi_iterator, val); + return *poi_iterator; +} + From 649d5bc732d33d8b9ce3d20181c50729cebbbd76 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Fri, 25 Feb 2022 20:16:21 -0500 Subject: [PATCH 05/23] add camera name edit. fix input text field no input on active. fix crash modal window on close event --- include/UI/UIView.h | 41 +++--- include/interaction/ArcBallCamera.h | 2 +- src/UI/UIView.cpp | 196 ++++++++++++++++++++-------- src/interaction/ArcBallCamera.cpp | 4 +- src/vrapp/VRVolumeApp.cpp | 10 +- 5 files changed, 173 insertions(+), 80 deletions(-) diff --git a/include/UI/UIView.h b/include/UI/UIView.h index 8189f5c..40db7b8 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -12,17 +12,20 @@ #include #include + + class VRVolumeApp; class CreateMovieAction; #define INPUT_TEXT_SIZE 200 #define MAX_COLUMS 50 -enum SAVE_MODAL {SAVE_NONE, SAVE_SESSION, SAVE_TRFR_FNC}; -enum LOAD_MODAL {LOAD_NONE, LOAD_SESSION, LOAD_TRFR_FNC }; +enum SAVE_MODAL { SAVE_NONE, SAVE_SESSION, SAVE_TRFR_FNC }; +enum LOAD_MODAL { LOAD_NONE, LOAD_SESSION, LOAD_TRFR_FNC }; +enum BUTTON_ACTION { NONE, ADD, EDIT, REMOVE }; struct Window_Properties { - + int window_w = 0; int window_h = 0; int framebuffer_w = 0; @@ -46,7 +49,7 @@ class UIView public: UIView(VRVolumeApp& controllerApp); ~UIView(); - + void draw_ui_callback(); void init_ui(bool is2D, bool lookingGlass); @@ -108,7 +111,7 @@ class UIView glm::vec3 get_clip_min(); glm::vec3 get_clip_max(); - void set_chracter(char c); + void add_character(char c); void remove_character(); @@ -116,6 +119,8 @@ class UIView void addTransferFunction(); + void get_Quantiles(int row); + private: struct MyTransFerFunctions @@ -125,8 +130,8 @@ class UIView std::vector volumes; }; - void open_save_modal_dialog(std::string& id, bool& window_state, - std::function save_function, std::string& extension); + void open_save_modal_dialog(std::string& id, bool& window_state, + std::function save_function, std::string& extension); void add_trans_function(); @@ -140,7 +145,7 @@ class UIView void save_camera_poi(std::ofstream& loadPath, int num_poi); - void load_camera_poi(std::ifstream& loadPath,int num_poi); + void load_camera_poi(std::ifstream& loadPath, int num_poi); void read_file_line(std::string& line, std::vector& values); @@ -192,9 +197,9 @@ class UIView bool m_initialized; - bool m_trn_fct_opitions_window; + bool m_trn_fct_options_window; - bool m_save_trnfct_open; + bool m_save_trnfct_open; bool m_save_session_dialog_open; @@ -206,6 +211,12 @@ class UIView std::string m_copy_trnfnct_name; + std::string m_copy_camera_name; + + bool m_camera_name_window_open; + + BUTTON_ACTION m_camera_button_action; + std::string m_save_file_name; unsigned int m_trnfnct_counter; @@ -214,8 +225,8 @@ class UIView bool m_ui_background; - - + + bool m_column_selected[MAX_COLUMS]; unsigned int m_column_selection_state; @@ -227,9 +238,9 @@ class UIView vec2f m_histogram_point_1; vec2f m_histogram_point_2; - float m_histogram_quantiles[2]; + float m_histogram_quantiles[2]; + - void load_ocean_color_maps(); std::vector m_ocean_color_maps_names; @@ -238,5 +249,5 @@ class UIView }; - + #endif diff --git a/include/interaction/ArcBallCamera.h b/include/interaction/ArcBallCamera.h index 70d4101..1d49629 100644 --- a/include/interaction/ArcBallCamera.h +++ b/include/interaction/ArcBallCamera.h @@ -81,7 +81,7 @@ class ArcBallCamera { std::list& get_camera_poi(); - void add_camera_poi(); + void add_camera_poi(std::string & label); void add_camera_poi(std::string& label, float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z, float radius); diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index ad2518e..346599c 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -13,17 +13,23 @@ #include "UIHelpers/stb_image.h" #include "common/common.h" + #include + +#include + + UIView::UIView(VRVolumeApp& controllerApp) :m_controller_app(controllerApp), m_multiplier(1.0f), m_threshold(0.0f), m_z_scale(0.16f), m_scale{ 1.0f }, m_slices(256), m_dynamic_slices(false), m_renderVolume(true), m_selectedTrnFnc(0), m_animated(false), m_ui_frame_controller(0.0f), m_menu_handler(nullptr), m_initialized(false), m_use_transferfunction(false), m_clip_max(1.0), m_clip_min(0.0), m_clip_ypr(0.0), m_clip_pos(0.0), m_useCustomClipPlane(false), m_rendermethod(1), m_renderchannel(0), -m_trnfnc_table_selection(-1), m_trn_fct_opitions_window(false), m_save_trnfct_open(false), m_trnfnct_counter(1), m_file_dialog_open(false), +m_trnfnc_table_selection(-1), m_trn_fct_options_window(false), m_save_trnfct_open(false), m_trnfnct_counter(1), m_file_dialog_open(false), m_file_load_trnsf(false), m_file_dialog_save_dir(false), m_save_session_dialog_open(false), m_current_save_modal(SAVE_NONE), m_current_load_modal(LOAD_NONE), m_file_extension_filter(".txt"), m_non_trns_functions_selected_modal(false), m_ui_background(false), m_column_selection_state(0), m_compute_new_histogram(true), m_histogram_point_1(0.0), -m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0) +m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0), +m_camera_name_window_open(false), m_camera_button_action(BUTTON_ACTION::NONE) { m_ocean_color_maps_names = { "algae.png","amp.png","balance.png","curl.png","deep.png","delta.png","dense.png", "diff.png","gray.png","haline.png","ice.png","matter.png","oxy.png","phase.png","rain.png","solar.png","speed.png","tarn.png","tempo.png", @@ -250,16 +256,15 @@ void UIView::draw_ui_callback() if (ImGui::Selectable(m_tfns[row].Name.c_str(), item_is_selected, selectable_flags)) { m_trnfnc_table_selection = row; - if (ImGui::IsMouseDoubleClicked(0)) { - m_copy_trnfnct_name = m_tfns[row].Name; + m_copy_trnfnct_name = m_tfns[m_trnfnc_table_selection].Name; float q_min = 0; float q_max = 0; tfn_widget[m_trnfnc_table_selection].get_Quantiles(q_min, q_max); m_histogram_quantiles[0] = q_min; m_histogram_quantiles[1] = q_max; - m_trn_fct_opitions_window = true; + m_trn_fct_options_window = true; } @@ -323,20 +328,16 @@ void UIView::draw_ui_callback() } - if (m_trn_fct_opitions_window) + if (m_trn_fct_options_window) { ImGui::OpenPopup("Transfer Function Options"); ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); - if (ImGui::BeginPopupModal("Transfer Function Options", &m_trn_fct_opitions_window)) + if (ImGui::BeginPopupModal("Transfer Function Options", &m_trn_fct_options_window)) { ImGui::Text("Change Name"); - char* writable = new char[m_copy_trnfnct_name.size() + 1]; - std::copy(m_copy_trnfnct_name.begin(), m_copy_trnfnct_name.end(), writable); - writable[m_copy_trnfnct_name.size()] = '\0'; // don't forget the terminating 0 - //ImGui::PushItemWidth(-1); - ImGui::InputText("##text1", writable, IM_ARRAYSIZE(writable)); + ImGui::InputText("##text1", &m_copy_trnfnct_name); ImGui::IsItemActive(); - //ImGui::PopItemWidth(); + ImGui::Separator(); /*float q_min = 0; @@ -377,14 +378,14 @@ void UIView::draw_ui_callback() if (ImGui::Button("Ok")) { m_tfns[m_trnfnc_table_selection].Name = m_copy_trnfnct_name; - m_trn_fct_opitions_window = false; + m_trn_fct_options_window = false; m_current_save_modal = SAVE_MODAL::SAVE_NONE; ImGui::CloseCurrentPopup(); } ImGui::SameLine(); if (ImGui::Button("Cancel")) { - m_trn_fct_opitions_window = false; + m_trn_fct_options_window = false; m_current_save_modal = SAVE_MODAL::SAVE_NONE; ImGui::CloseCurrentPopup(); } @@ -526,10 +527,11 @@ void UIView::draw_ui_callback() { ImGui::Text("Points of Interest"); - + if (ImGui::Button("Add")) { - m_controller_app.get_trackball_camera().add_camera_poi(); - m_camera_poi_table_selection = 0; + m_camera_name_window_open = true; + m_camera_button_action = BUTTON_ACTION::ADD; + } ImGui::SameLine(); if (ImGui::Button("Remove")) { @@ -539,24 +541,29 @@ void UIView::draw_ui_callback() m_camera_poi_table_selection = m_camera_poi_table_selection - 1 < 0 ? 0 : m_camera_poi_table_selection--; m_controller_app.get_trackball_camera().set_current_poi(m_camera_poi_table_selection); } - + } - + ImGui::BeginTable("##Camera Point of interest (POI) Editor", 1, ImGuiTableFlags_Borders); ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 120.0f); - - for (int row = 0 ; row < m_controller_app.get_trackball_camera().get_camera_poi().size(); ++row) + + for (int row = 0; row < m_controller_app.get_trackball_camera().get_camera_poi().size(); ++row) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); bool item_is_selected = (row == m_camera_poi_table_selection) ? true : false; - if (ImGui::Selectable(m_controller_app.get_trackball_camera().get_poi_at(row).label.c_str(), item_is_selected)) + if (ImGui::Selectable(m_controller_app.get_trackball_camera().get_poi_at(row).label.c_str(), item_is_selected), ImGuiSelectableFlags_AllowDoubleClick) { m_camera_poi_table_selection = row; - m_controller_app.get_trackball_camera().set_current_poi(row); - + m_controller_app.get_trackball_camera().set_current_poi(m_camera_poi_table_selection); + if (ImGui::IsMouseDoubleClicked(0)) + { + m_copy_camera_name = m_controller_app.get_trackball_camera().get_poi_at(m_camera_poi_table_selection).label; + m_camera_name_window_open = true; + m_camera_button_action = BUTTON_ACTION::EDIT; + } } } ImGui::EndTable(); @@ -566,6 +573,54 @@ void UIView::draw_ui_callback() ImGui::EndTabBar(); + if (m_camera_name_window_open) + { + std::string modal_window_name; + + switch (m_camera_button_action) + { + case ADD: + modal_window_name = "Add Camera"; + break; + case EDIT: + modal_window_name = "Edit Camera"; + break; + default: + break; + } + + ImGui::OpenPopup(modal_window_name.c_str()); + ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); + if (ImGui::BeginPopupModal(modal_window_name.c_str(), &m_camera_name_window_open)) + { + ImGui::Text("Camera Name"); + ImGui::InputText("##textcameraname", &m_copy_camera_name); + if (ImGui::Button("Ok")) + { + + if (m_camera_button_action == ADD) + { + m_controller_app.get_trackball_camera().add_camera_poi(m_copy_camera_name); + m_camera_poi_table_selection = 0; + } + else if (m_camera_button_action == EDIT) + { + m_controller_app.get_trackball_camera().get_poi_at(m_camera_poi_table_selection).label = m_copy_camera_name; + } + m_camera_name_window_open = false; + ImGui::CloseCurrentPopup(); + } + ImGui::SameLine(); + if (ImGui::Button("Cancel")) + { + m_camera_name_window_open = false; + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + + } + //file loading if (m_file_dialog_open) { @@ -592,9 +647,9 @@ void UIView::draw_ui_callback() promises.push_back(new std::promise); futures.push_back(promises.back()->get_future()); threads.push_back(new std::thread(&VolumeVisualizationApp::loadVolume, this, vals, promises.back()));*/ - } + } #endif -} + } @@ -975,21 +1030,30 @@ glm::vec3 UIView::get_clip_max() return m_clip_max; } -void UIView::set_chracter(char c) +void UIView::add_character(char c) { - if (m_trn_fct_opitions_window) + if (m_trn_fct_options_window) { + ImGui::ClearActiveID(); m_copy_trnfnct_name += c; + } if (m_save_trnfct_open || m_save_session_dialog_open) { + ImGui::ClearActiveID(); m_save_file_name += c; } + + if (m_camera_name_window_open) + { + ImGui::ClearActiveID(); + m_copy_camera_name += c; + } } void UIView::remove_character() { - if (m_trn_fct_opitions_window) + if (m_trn_fct_options_window) { if (!m_copy_trnfnct_name.empty()) { @@ -1006,6 +1070,14 @@ void UIView::remove_character() } } + + if (m_camera_name_window_open) + { + if (!m_copy_camera_name.empty()) + { + m_copy_camera_name.pop_back(); + } + } } void UIView::open_save_modal_dialog(std::string& id, bool& window_state, @@ -1015,9 +1087,7 @@ void UIView::open_save_modal_dialog(std::string& id, bool& window_state, ImGui::SetNextWindowSize(ImVec2(350, 200), ImGuiCond_FirstUseEver); if (ImGui::BeginPopupModal(id.c_str(), &window_state)) { - char* writable = new char[m_save_file_name.size() + 1]; - std::copy(m_save_file_name.begin(), m_save_file_name.end(), writable); - writable[m_save_file_name.size()] = '\0'; + ImGui::Text(m_dir_to_save.c_str()); ImGui::SameLine(); if (ImGui::Button("...")) @@ -1025,7 +1095,7 @@ void UIView::open_save_modal_dialog(std::string& id, bool& window_state, m_file_dialog_save_dir = true; } - ImGui::InputText("##filename", writable, IM_ARRAYSIZE(writable)); + ImGui::InputText("##filename", &m_save_file_name); ImGui::IsItemActive(); @@ -1091,7 +1161,7 @@ void UIView::save_trans_functions(std::ofstream& saveFile) } saveFile << "\n"; } - + } } @@ -1134,9 +1204,9 @@ void UIView::save_user_session(std::ofstream& savefile) savefile << "Trnfncs" << "\n"; save_trans_functions(savefile); } - - - + + + savefile.close(); } @@ -1152,7 +1222,7 @@ void UIView::load_trans_functions(std::ifstream& loadFile) { while (std::getline(loadFile, line)) { - std::vector vals; + std::vector vals; std::stringstream ss(line); std::string buf; @@ -1311,11 +1381,11 @@ void UIView::load_user_session(std::string filePath) } } -void UIView::save_camera_poi(std::ofstream& saveFile,int num_camera_poi) +void UIView::save_camera_poi(std::ofstream& saveFile, int num_camera_poi) { if (saveFile.is_open()) { - + auto poit_iterator = m_controller_app.get_trackball_camera().get_camera_poi().begin(); for (poit_iterator; poit_iterator != m_controller_app.get_trackball_camera().get_camera_poi().end(); poit_iterator++) { @@ -1341,23 +1411,23 @@ void UIView::load_camera_poi(std::ifstream& loadFile, int num_poi) if (poiVals.size() > 0) { - std::string label = poiVals[0]; - float eye_x = std::stof(poiVals[1]); - float eye_y = std::stof(poiVals[2]); - float eye_z = std::stof(poiVals[3]); - float target_x = std::stof(poiVals[4]); - float target_y = std::stof(poiVals[5]); - float target_z = std::stof(poiVals[6]); - float up_x = std::stof(poiVals[7]); - float up_y = std::stof(poiVals[8]); - float up_z = std::stof(poiVals[9]); - float radius = std::stof(poiVals[10]); - m_controller_app.get_trackball_camera().add_camera_poi(label,eye_x, eye_y, eye_z, target_x, target_y, target_z, up_x, up_y, up_z, radius); - } + std::string label = poiVals[0]; + float eye_x = std::stof(poiVals[1]); + float eye_y = std::stof(poiVals[2]); + float eye_z = std::stof(poiVals[3]); + float target_x = std::stof(poiVals[4]); + float target_y = std::stof(poiVals[5]); + float target_z = std::stof(poiVals[6]); + float up_x = std::stof(poiVals[7]); + float up_y = std::stof(poiVals[8]); + float up_z = std::stof(poiVals[9]); + float radius = std::stof(poiVals[10]); + m_controller_app.get_trackball_camera().add_camera_poi(label, eye_x, eye_y, eye_z, target_x, target_y, target_z, up_x, up_y, up_z, radius); + } } - } - + } + } @@ -1386,7 +1456,7 @@ void UIView::adjust_transfer_function_to_histogram() const std::size_t pos1 = std::floor(m_histogram_quantiles[0] * std::distance(histogram_copy.begin(), histogram_copy.end())); const std::size_t pos2 = std::floor(m_histogram_quantiles[1] * std::distance(histogram_copy.begin(), histogram_copy.end())); - if (histogram_copy.size() > pos1 && histogram_copy.size() > pos2) + if (histogram_copy.size() > pos1&& histogram_copy.size() > pos2) { std::nth_element(histogram_copy.begin(), histogram_copy.begin() + pos1, histogram_copy.end()); @@ -1465,6 +1535,18 @@ void UIView::addTransferFunction() } m_tfns.push_back(trfntc); } + +void UIView::get_Quantiles(int row) +{ + m_copy_trnfnct_name = m_tfns[row].Name; + float q_min = 0; + float q_max = 0; + tfn_widget[m_trnfnc_table_selection].get_Quantiles(q_min, q_max); + m_histogram_quantiles[0] = q_min; + m_histogram_quantiles[1] = q_max; + m_trn_fct_options_window = true; +} + void UIView::load_ocean_color_maps() { int w, h, n; diff --git a/src/interaction/ArcBallCamera.cpp b/src/interaction/ArcBallCamera.cpp index 4802bee..c639d0a 100644 --- a/src/interaction/ArcBallCamera.cpp +++ b/src/interaction/ArcBallCamera.cpp @@ -183,9 +183,9 @@ std::list& ArcBallCamera::get_camera_poi() return m_camera_poi; } -void ArcBallCamera::add_camera_poi() +void ArcBallCamera::add_camera_poi(std::string& label) { - m_current_poi.label = "Position-" + std::to_string(m_camera_poi.size() + 1); + m_current_poi.label = label; m_camera_poi.push_front(m_current_poi); } diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index f1ee5d3..9ccb5e0 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -368,7 +368,7 @@ void VRVolumeApp::set_character_state(std::string& eventName, int state) { if (m_ui_view) { - m_ui_view->set_chracter(keyStr[0]); + m_ui_view->add_character(keyStr[0]); } } /* if (std::isalpha(keyStr[0], loc) || isdigit(keyStr[0])) @@ -390,7 +390,7 @@ void VRVolumeApp::set_character_state(std::string& eventName, int state) } else if (keyStr == "Space") { - m_ui_view->set_chracter(32); + m_ui_view->add_character(32); /*std::string space(" "); addTextToInputField(space);*/ } @@ -1108,7 +1108,7 @@ void VRVolumeApp::do_grab(glm::mat4& newPose) m_controller_pose = newPose; } -ArcBallCamera& VRVolumeApp::get_trackball_camera() -{ - return m_trackball; +ArcBallCamera& VRVolumeApp::get_trackball_camera() +{ + return m_trackball; } From 60b136e29a4ae07a891498443c85b7acf516ca9c Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Tue, 1 Mar 2022 11:51:46 -0500 Subject: [PATCH 06/23] fix camera ui table selection --- src/UI/UIView.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index 346599c..ea43db8 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -538,8 +538,17 @@ void UIView::draw_ui_callback() if (m_controller_app.get_trackball_camera().get_camera_poi().size() > 0) { m_controller_app.get_trackball_camera().remove_poi(m_camera_poi_table_selection); - m_camera_poi_table_selection = m_camera_poi_table_selection - 1 < 0 ? 0 : m_camera_poi_table_selection--; - m_controller_app.get_trackball_camera().set_current_poi(m_camera_poi_table_selection); + if (m_camera_poi_table_selection - 1 < 0) + { + m_camera_poi_table_selection = 0; + } + else + { + m_camera_poi_table_selection--; + m_controller_app.get_trackball_camera().set_current_poi(m_camera_poi_table_selection); + } + + } } @@ -554,7 +563,7 @@ void UIView::draw_ui_callback() ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); bool item_is_selected = (row == m_camera_poi_table_selection) ? true : false; - if (ImGui::Selectable(m_controller_app.get_trackball_camera().get_poi_at(row).label.c_str(), item_is_selected), ImGuiSelectableFlags_AllowDoubleClick) + if (ImGui::Selectable(m_controller_app.get_trackball_camera().get_poi_at(row).label.c_str(), item_is_selected, ImGuiSelectableFlags_AllowDoubleClick)) { m_camera_poi_table_selection = row; m_controller_app.get_trackball_camera().set_current_poi(m_camera_poi_table_selection); @@ -593,6 +602,7 @@ void UIView::draw_ui_callback() ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); if (ImGui::BeginPopupModal(modal_window_name.c_str(), &m_camera_name_window_open)) { + ImGui::Text("Camera Name"); ImGui::InputText("##textcameraname", &m_copy_camera_name); if (ImGui::Button("Ok")) @@ -601,6 +611,7 @@ void UIView::draw_ui_callback() if (m_camera_button_action == ADD) { m_controller_app.get_trackball_camera().add_camera_poi(m_copy_camera_name); + m_copy_camera_name.clear(); m_camera_poi_table_selection = 0; } else if (m_camera_button_action == EDIT) @@ -614,6 +625,7 @@ void UIView::draw_ui_callback() if (ImGui::Button("Cancel")) { m_camera_name_window_open = false; + m_copy_camera_name.clear(); ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); @@ -773,7 +785,7 @@ void UIView::init_ui(bool is2D, bool lookingGlass) m_initialized = true; - } +} } From 52bab9bc9c951c04e47e2f075379806c20e8bb30 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Tue, 1 Mar 2022 20:50:37 -0500 Subject: [PATCH 07/23] fix resize window and frame buffer --- CMakeLists.txt | 2 ++ src/UI/UIView.cpp | 10 +++++----- src/render/VolumeRaycastShader.cpp | 11 +++++----- src/vrapp/VRVolumeApp.cpp | 1 + src/vrapp/VolumeVisualizationApp.cpp | 30 ++++++++++++++++++++-------- superbuild/MinVR/CMakeLists.txt | 4 +--- superbuild/macros.cmake | 3 +-- 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aff900d..61c88bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ set(source_files src/render/VolumeRaycastRenderer.cpp src/render/VolumeRaycastShader.cpp src/UI/UIView.cpp + src/UI/UIDoubleClickedTableCell.cpp libs/glm.cpp src/render/FrameBufferObject.cpp src/render/DepthTexture.cpp @@ -79,6 +80,7 @@ set(header_files include/render/VolumeRaycastRenderer.h include/render/VolumeRaycastShader.h include/UI/UIView.h + include/UI/UIDoubleClickedTableCell.h libs/glm.h include/render/FrameBufferObject.h include/render/DepthTexture.h diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index ea43db8..dc2710a 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -547,8 +547,8 @@ void UIView::draw_ui_callback() m_camera_poi_table_selection--; m_controller_app.get_trackball_camera().set_current_poi(m_camera_poi_table_selection); } - - + + } } @@ -785,7 +785,7 @@ void UIView::init_ui(bool is2D, bool lookingGlass) m_initialized = true; -} + } } @@ -839,8 +839,8 @@ void UIView::render_3D(glm::mat4& space_matrix, Window_Properties& window_proper if (m_show_menu) { - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(glm::value_ptr(space_matrix)); + // glMatrixMode(GL_MODELVIEW); + // glLoadMatrixf(glm::value_ptr(space_matrix)); m_menu_handler->drawMenu(window_properties.window_w, window_properties.window_h, window_properties.framebuffer_w, window_properties.framebuffer_h); } diff --git a/src/render/VolumeRaycastShader.cpp b/src/render/VolumeRaycastShader.cpp index d532ede..1ef1793 100644 --- a/src/render/VolumeRaycastShader.cpp +++ b/src/render/VolumeRaycastShader.cpp @@ -55,12 +55,13 @@ VolumeRaycastShader::VolumeRaycastShader() : m_use_blending{ false }, m_blend_vo //vertex position. Since the unit cube is at origin (min: (-0.5,-0.5,-0.5) and max: (0.5,0.5,0.5)) //adding (0.5,0.5,0.5) to the unit cube object space position gives us values from (0,0,0) to //(1,1,1) - "vUV = vVertex + vec3(0.5); \n" + "vUV = vVertex + vec3(0.5001); \n" "}\n"; m_fragmentShader = "#version 330 core\n" "vec2 intersect_box(vec3 orig, vec3 dir, vec3 clip_min, vec3 clip_max) { \n" + "dir += vec3(0.0000001); \n" "vec3 inv_dir = 1.0 / dir; \n" "vec3 tmin_tmp = (clip_min - orig) * inv_dir; \n" "vec3 tmax_tmp = (clip_max - orig) * inv_dir; \n" @@ -115,7 +116,7 @@ VolumeRaycastShader::VolumeRaycastShader() : m_use_blending{ false }, m_blend_vo //To ensure we update dataPos and t_hit to reflect a ray from entry point to exit "dataPos = camPos + t_hit.x * geomDir;\n" "t_hit.y = t_hit.y-t_hit.x; \n" - "t_hit.x = 0.0f; \n" + "t_hit.x = 0.0001f; \n" //get t for the clipping plane and overwrite the entry point "if(clipping){ \n" @@ -148,8 +149,8 @@ VolumeRaycastShader::VolumeRaycastShader() : m_use_blending{ false }, m_blend_vo "d_ndc = d_ndc / d_ndc.w; \n" //compute t_occ and check if it closer than the exit point - "float t_occ = ((d_ndc.x + 0.5) - dataPos.x) / geomDir.x; \n" - "t_hit.y = min(t_hit.y, t_occ); \n" + /*"float t_occ = ((d_ndc.x + 0.5) - dataPos.x) / geomDir.x; \n" + "t_hit.y = min(t_hit.y, t_occ); \n"*/ //first value should always be lower by definition and this case should never occur. If it does discard the fragment. "if (t_hit.x > t_hit.y) \n" @@ -325,5 +326,5 @@ void VolumeRaycastShader::initGL() glUniform1i(m_blendVolume_uniform, 3); unbindProgram(); - + } diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index 9ccb5e0..3b94142 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -528,6 +528,7 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) //setup projection m_projection_mtrx = glm::make_mat4(renderState.getProjectionMatrix()); + //m_projection_mtrx = m_trackball.get_projection_camera(); m_model_view = glm::make_mat4(renderState.getViewMatrix()); //overwrite MV for 2D viewing diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index 6b6a1e0..0c4f7ac 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -441,7 +441,7 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { } } - + } @@ -493,6 +493,20 @@ void VolumeVisualizationApp::onGenericEvent(const VRDataIndex& index) if (index.getName() == "WindowClose") { shutdown(); } + + if (index.getName() == "WindowSize") { + /* + some code to update projection matrix + */ + } + + if (index.getName() == "BufferSize") { + const std::vector* v = index.getValue("WindowSize"); + const float* f = &(v->front()); + std::cout << "new buffer size: " << GLint(f[0]) << ", " << GLint(f[1]) << std::endl; + glViewport(0, 0, GLint(f[0]), GLint(f[1])); + } + } void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& renderState) { @@ -522,7 +536,7 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend std::cout << "Error initializing GLEW." << std::endl; } #endif -std::cout << "init vizapp " << std::endl; + std::cout << "init vizapp " << std::endl; if (m_vrVolumeApp) { m_vrVolumeApp->initialize(); @@ -542,15 +556,15 @@ std::cout << "init vizapp " << std::endl; glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glClearColor(0.0, 0.0, 0.0, 1); - std::cout << "init vizapp end" << std::endl; + std::cout << "init vizapp end" << std::endl; } - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glLightfv(GL_LIGHT0, GL_POSITION, m_light_pos); + + //glMatrixMode(GL_MODELVIEW); + //glLoadIdentity(); + //glLightfv(GL_LIGHT0, GL_POSITION, m_light_pos); if (m_vrVolumeApp) { @@ -558,7 +572,7 @@ std::cout << "init vizapp " << std::endl; { m_vrVolumeApp->load_mesh_model(); } - + m_vrVolumeApp->initialize_textures(); m_vrVolumeApp->update_3D_ui(); m_vrVolumeApp->update_trackBall_state(); diff --git a/superbuild/MinVR/CMakeLists.txt b/superbuild/MinVR/CMakeLists.txt index 62d3694..25a2dc7 100644 --- a/superbuild/MinVR/CMakeLists.txt +++ b/superbuild/MinVR/CMakeLists.txt @@ -5,15 +5,13 @@ include(GNUInstallDirs) include(${CMAKE_SOURCE_DIR}/../macros.cmake) message("${CMAKE_PROJECT_NAME} INSTALL_DIR_ABSOLUTE ${INSTALL_DIR_ABSOLUTE}") -message("MINVR CMAKELISTS MINVR_PATCH_PATH ${MINVR_PATCH_PATH}") set(EXTERNAL_DIR_LOCATION ${CMAKE_BINARY_DIR}) set(EXTERNAL_DIR_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/../install/) build_minvr_subproject( NAME MinVR - URL "https://github.com/MinVR/MinVR.git" - PATCH ${MINVR_PATCH_PATH} + URL "https://github.com/brown-ccv/MinVR.git" BUILD_ARGS -DWITH_PLUGIN_OPENGL=ON -DWITH_PLUGIN_GLFW=ON diff --git a/superbuild/macros.cmake b/superbuild/macros.cmake index 1b8d9da..9148320 100644 --- a/superbuild/macros.cmake +++ b/superbuild/macros.cmake @@ -80,12 +80,11 @@ macro(build_minvr_subproject) # Setup SUBPROJECT_* variables (containing paths) for this function setup_subproject_path_vars(${BUILD_SUBPROJECT_NAME}) - message("BUILD_SUBPROJECT_PATCH ${BUILD_SUBPROJECT_PATCH}") + # Build the actual subproject ExternalProject_Add(${SUBPROJECT_NAME} PREFIX ${SUBPROJECT_NAME} DOWNLOAD_DIR ${SUBPROJECT_NAME} - PATCH_COMMAND git apply ${BUILD_SUBPROJECT_PATCH}/minvr_patch_09142021.patch STAMP_DIR ${SUBPROJECT_STAMP_PATH} SOURCE_DIR ${SUBPROJECT_SOURCE_PATH} BINARY_DIR ${SUBPROJECT_BUILD_PATH} From 0d7d3c416d62bc2dc62153a99653a71a264b72a6 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Wed, 9 Mar 2022 21:32:58 -0500 Subject: [PATCH 08/23] adde camera animation. camera zoom is broken --- include/UI/UIView.h | 4 +- include/interaction/ArcBallCamera.h | 33 +++++- include/vrapp/VRVolumeApp.h | 2 +- include/vrapp/VolumeVisualizationApp.h | 21 +++- src/UI/UIView.cpp | 28 +++-- src/interaction/ArcBallCamera.cpp | 136 ++++++++++++++++++++++++- src/vrapp/VRVolumeApp.cpp | 10 +- src/vrapp/VolumeVisualizationApp.cpp | 51 +++++++++- 8 files changed, 255 insertions(+), 30 deletions(-) diff --git a/include/UI/UIView.h b/include/UI/UIView.h index 662dc25..d64c571 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -13,7 +13,6 @@ #include - class VRVolumeApp; class CreateMovieAction; #define INPUT_TEXT_SIZE 200 @@ -253,7 +252,8 @@ class UIView std::string m_color_map_directory; float m_animation_speed; - + + }; diff --git a/include/interaction/ArcBallCamera.h b/include/interaction/ArcBallCamera.h index 1d49629..d090abe 100644 --- a/include/interaction/ArcBallCamera.h +++ b/include/interaction/ArcBallCamera.h @@ -31,6 +31,7 @@ #include #include +#include "choreograph/Choreograph.h" enum WASD_KEYS { @@ -57,6 +58,13 @@ struct PointOfInterest { }; +enum CAMERA_ANIMATION_STATE +{ + STOP, + PLAYING, + PAUSE +}; + /** Adds a HeadMatrix to the RenderState that gets updated repeatedly based upon head tracking events. */ @@ -76,7 +84,7 @@ class ArcBallCamera { glm::mat4& getViewmatrix() { updateCameraMatrix(); - return viewmatrix; + return m_viewmatrix; } std::list& get_camera_poi(); @@ -92,10 +100,20 @@ class ArcBallCamera { void remove_poi(int val); - void rest_camera(); + void reset_camera(); PointOfInterest& get_poi_at(int val); + void update_animation(); + + void set_animation_path(); + + void set_animation_state(); + + CAMERA_ANIMATION_STATE get_animation_state(); + + std::string get_camera_animation_state(); + protected: void Rotate(float dTheta, float dPhi); void RotateEyeAxis(float dy); @@ -110,7 +128,7 @@ class ArcBallCamera { std::list m_camera_poi; PointOfInterest m_current_poi; - glm::mat4 viewmatrix; + glm::mat4 m_viewmatrix; bool m_mouse_left_pressed; bool m_mouse_right_pressed; bool m_mouse_center_pressed; @@ -120,6 +138,15 @@ class ArcBallCamera { float m_cameraScrollFactor; bool m_rotate_camera_center; + ch::Output m_target_animation; + ch::Output m_eye_animation; + ch::Output m_up_animation; + ch::Timeline m_timeline; + + bool m_is_animate_path; + + CAMERA_ANIMATION_STATE m_camera_animation_state; + std::string animation_button_label; }; #endif diff --git a/include/vrapp/VRVolumeApp.h b/include/vrapp/VRVolumeApp.h index 7324f6b..0e40d20 100644 --- a/include/vrapp/VRVolumeApp.h +++ b/include/vrapp/VRVolumeApp.h @@ -90,7 +90,7 @@ class VRVolumeApp void update_trackBall_state(); - void update_animation(); + void update_animation(float fps); #if (!defined(__APPLE__)) void run_movie(); diff --git a/include/vrapp/VolumeVisualizationApp.h b/include/vrapp/VolumeVisualizationApp.h index fe57f6f..4f02280 100644 --- a/include/vrapp/VolumeVisualizationApp.h +++ b/include/vrapp/VolumeVisualizationApp.h @@ -33,7 +33,6 @@ #include "render/VolumeRaycastRenderer.h" #include "render/DepthTexture.h" #include -#include "interaction/ArcBallCamera.h" @@ -51,6 +50,9 @@ using namespace MinVR; #include "../render/VolumeSliceRenderer.h" #include "../interaction/CreateMovieAction.h" + +#include "choreograph/Choreograph.h" + #include "ShaderProgram.h" #include "VRVolumeApp.h" @@ -112,6 +114,23 @@ class VolumeVisualizationApp : public VRApp { VRVolumeApp* m_vrVolumeApp; + int m_num_frames; + + const double fps_Limit = 1.0 / 60.0; + std::chrono::steady_clock::time_point last_Update_Time ; // number of seconds since the last loop + + ch::Timeline _timeline; + ch::Output target = 0.0f; + ch::Output _control_a = 0; + ch::Output _control_b ; + float v1 = 0.0f; + float v2 = 100.0f; + + //std::vector control_points + glm::vec3 pos1 = glm::vec3(1.0f, 0.0f, 10.0f); + glm::vec3 pos2 = glm::vec3(50.0f, 150.0f, 50.0f); + glm::vec3 pos3 = glm::vec3(-10.0f, 100.0f, 250.0f); + glm::vec3 pos4 = glm::vec3(-10.0f, 180.0f, 290.0f); }; diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index 472ed1c..6b4eb63 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -338,13 +338,7 @@ void UIView::draw_ui_callback() ImGui::InputText("##text1", &m_copy_trnfnct_name); ImGui::IsItemActive(); - ImGui::Separator(); - /*float q_min = 0; - float q_max = 0; - tfn_widget[m_table_selection].get_Quantiles(q_min, q_max); - m_histogram_quantiles[0] = q_min; - m_histogram_quantiles[1] = q_max;*/ ImGui::Text("Quantiles"); ImGui::SliderFloat2("##Quantiles", m_histogram_quantiles, 0.05f, 0.95f); @@ -473,7 +467,7 @@ void UIView::draw_ui_callback() m_stopped = !m_stopped; } ImGui::SameLine(); - float value = (int)(m_animation_speed * 100 + .5); + int value = int(m_animation_speed * 100.0 + .5); std::string speed_text = ">>X "+std::to_string(value/100); if (ImGui::Button(speed_text.c_str(), ImVec2(80, 0))) { m_animation_speed += 0.5; @@ -563,8 +557,10 @@ void UIView::draw_ui_callback() } } - - + ImGui::SameLine(); + if (ImGui::Button("Reset")) { + m_controller_app.get_trackball_camera().reset_camera(); + } ImGui::BeginTable("##Camera Point of interest (POI) Editor", 1, ImGuiTableFlags_Borders); ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 120.0f); @@ -587,6 +583,16 @@ void UIView::draw_ui_callback() } } ImGui::EndTable(); + + std::string is_animation_playing = m_controller_app.get_trackball_camera().get_camera_animation_state(); + + if (ImGui::Button(is_animation_playing.c_str())) { + + m_controller_app.get_trackball_camera().set_animation_state(); + + } + + ImGui::EndTabItem(); } @@ -623,7 +629,7 @@ void UIView::draw_ui_callback() { m_controller_app.get_trackball_camera().add_camera_poi(m_copy_camera_name); m_copy_camera_name.clear(); - m_camera_poi_table_selection = 0; + m_camera_poi_table_selection = m_controller_app.get_trackball_camera().get_camera_poi().size()-1; } else if (m_camera_button_action == EDIT) { @@ -1400,7 +1406,7 @@ void UIView::load_user_session(std::string filePath) } } loadFile.close(); - m_controller_app.get_trackball_camera().rest_camera(); + m_controller_app.get_trackball_camera().reset_camera(); } } diff --git a/src/interaction/ArcBallCamera.cpp b/src/interaction/ArcBallCamera.cpp index c639d0a..b98f286 100644 --- a/src/interaction/ArcBallCamera.cpp +++ b/src/interaction/ArcBallCamera.cpp @@ -38,6 +38,7 @@ ArcBallCamera::ArcBallCamera() : m_radius(1), m_mouse_left_pressed(false), m_mouse_center_pressed(false), m_mouse_right_pressed(false), last_x(0), last_y(0) , m_PanFactor(1), m_RotateFactor(1), m_cameraScrollFactor(0.1), m_target(0, 0, 0), m_eye(0, 0, 1), m_up(0, 1, 0), m_rotate_camera_center{ false } +, m_is_animate_path(false), m_camera_animation_state(STOP), animation_button_label("ANIMATE") { } @@ -49,7 +50,33 @@ ArcBallCamera::~ArcBallCamera() void ArcBallCamera::updateCameraMatrix() { - viewmatrix = glm::lookAt(m_current_poi.get_camera_position(), m_current_poi.target, m_current_poi.up); + if (m_is_animate_path) + { + /*glm::vec3 animation_position = m_animation; + viewmatrix = glm::lookAt(animation_position, m_current_poi.target, m_current_poi.up);*/ + if (m_camera_animation_state != PAUSE ) + { + update_animation(); + + } + if (m_timeline.isFinished()) + { + m_camera_animation_state = STOP; + animation_button_label = "Animate"; + m_timeline.resetTime(); + } + + + + m_viewmatrix = glm::lookAt(m_eye_animation.value(), m_target_animation.value(), m_up_animation.value()); + + + } + else + { + m_viewmatrix = glm::lookAt(m_current_poi.eye, m_current_poi.target, m_current_poi.up); + } + } void ArcBallCamera::mouse_pressed(int button, bool isDown) @@ -168,7 +195,8 @@ void ArcBallCamera::Zoom(float distance) { { m_current_poi.radius = 0.000001; } - + + std::cout << m_current_poi.radius << std::endl; } void ArcBallCamera::Pan(float dx, float dy) { @@ -186,7 +214,7 @@ std::list& ArcBallCamera::get_camera_poi() void ArcBallCamera::add_camera_poi(std::string& label) { m_current_poi.label = label; - m_camera_poi.push_front(m_current_poi); + m_camera_poi.push_back(m_current_poi); } void ArcBallCamera::add_camera_poi(std::string& label, float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z, float radius) @@ -207,11 +235,13 @@ int ArcBallCamera::get_current_poi() void ArcBallCamera::set_current_poi(int val) { + m_is_animate_path = false; std::list::iterator it = m_camera_poi.begin(); for (int i = 0; i < val; i++) { ++it; } m_current_poi = *it; + } void ArcBallCamera::remove_poi(int val) @@ -221,8 +251,17 @@ void ArcBallCamera::remove_poi(int val) m_camera_poi.erase(poi_iterator); } -void ArcBallCamera::rest_camera() +void ArcBallCamera::reset_camera() { + m_is_animate_path = false; + last_x = 0; + last_y = 0; + m_PanFactor = 1; + m_RotateFactor = 1; + m_cameraScrollFactor = 0.1; + m_target = glm::vec3(0, 0, 0); + m_eye = glm::vec3(0, 0, 1); + m_up = glm::vec3(0, 1, 0); m_current_poi = PointOfInterest(); } @@ -233,3 +272,92 @@ PointOfInterest& ArcBallCamera::get_poi_at(int val) return *poi_iterator; } +void ArcBallCamera::update_animation() +{ + if (m_is_animate_path) + { + m_timeline.step(1.0 / 60.0); + + } + + +} + +void ArcBallCamera::set_animation_path() +{ + if (m_camera_poi.size() > 1) + { + + PointOfInterest first_position = m_camera_poi.front(); + + ch::Sequence sequence_eye(first_position.eye); + ch::Sequence sequence_target(first_position.target); + ch::Sequence sequence_up(first_position.up); + + + for (auto next_camera_poi_interator = std::next(m_camera_poi.begin()); next_camera_poi_interator != m_camera_poi.end(); next_camera_poi_interator++) + { + sequence_eye.then(next_camera_poi_interator->eye, 10.f); + sequence_target.then(next_camera_poi_interator->target, 10.f); + sequence_up.then(next_camera_poi_interator->up, 10.f); + } + + + auto group= std::make_shared(); + group->apply(&m_eye_animation, sequence_eye); + group->apply(&m_target_animation, sequence_target); + group->apply(&m_up_animation, sequence_up); + + m_timeline.addShared(group); + + } + +} + +void ArcBallCamera::set_animation_state() +{ + if (m_camera_animation_state == STOP) + { + set_animation_path(); + m_camera_animation_state = PLAYING; + animation_button_label = "PAUSE"; + } + else if (m_camera_animation_state == PLAYING) + { + if (!m_timeline.isFinished()) + { + m_camera_animation_state = PAUSE; + animation_button_label = "ANIMATE"; + } + } + else if (m_camera_animation_state == PAUSE) + { + m_camera_animation_state = PLAYING; + animation_button_label = "PAUSE"; + } + + m_is_animate_path = true; + +} + +CAMERA_ANIMATION_STATE ArcBallCamera::get_animation_state() +{ + if (m_timeline.isFinished()) + { + return STOP; + } + else if (!m_timeline.isFinished() && m_camera_animation_state == PLAYING) + { + return PLAYING; + } + else if (!m_timeline.isFinished() && m_camera_animation_state == STOP) + { + return PAUSE; + } +} + +std::string ArcBallCamera::get_camera_animation_state() +{ + return animation_button_label; +} + diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index 9aa75b0..06a9be9 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -171,13 +171,14 @@ void VRVolumeApp::update_trackBall_state() } -void VRVolumeApp::update_animation() +void VRVolumeApp::update_animation(float fps) { if (m_ui_view) { if (m_volumes.size()) { - m_ui_view->update_animation(m_speed * m_animation_speed, m_volumes[m_selectedVolume].size() - 1); + //m_animation_speed = fps; + m_ui_view->update_animation(m_speed, m_volumes[m_selectedVolume].size() - 1); } } } @@ -843,7 +844,10 @@ void VRVolumeApp::update_frame_state() if (m_animated && !m_ui_view->is_stopped()) { m_frame += (m_speed * m_animation_speed); - if (m_frame > m_volumes[m_selectedVolume].size() - 1) m_frame = 0.0; + if (m_frame > m_volumes[m_selectedVolume].size() - 1) + { + m_frame = 0.0; + } } m_rendercount = 0; } diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index 0c4f7ac..94ef2dd 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -28,7 +28,7 @@ #include "render/FontHandler.h" -VolumeVisualizationApp::VolumeVisualizationApp(int argc, char** argv) : VRApp(argc, argv), m_vrVolumeApp(nullptr) +VolumeVisualizationApp::VolumeVisualizationApp(int argc, char** argv) : VRApp(argc, argv), m_vrVolumeApp(nullptr), m_num_frames(0) { int argc_int = this->getLeftoverArgc(); char** argv_int = this->getLeftoverArgv(); @@ -514,10 +514,16 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend // rendering process. So, this is the place to initialize textures, // load models, or do other operations that you only want to do once per // frame when in stereo mode. + m_num_frames++; std::chrono::steady_clock::time_point nowTime = std::chrono::steady_clock::now(); - std::chrono::duration time_span = std::chrono::duration(nowTime - m_lastTime); - float fps = 1000.0f / std::chrono::duration_cast(time_span).count(); + std::chrono::duration delta_time = std::chrono::duration(nowTime - m_lastTime); + float delta_time_to_milliseconds = std::chrono::duration_cast(delta_time).count(); + float fps = 1000.0f / delta_time_to_milliseconds; + + std::chrono::duration time_lapse = std::chrono::duration(nowTime - last_Update_Time); + float time_lapse_to_seconds = std::chrono::duration_cast(time_lapse).count(); + if (m_vrVolumeApp) { m_vrVolumeApp->update_fps(fps); @@ -525,7 +531,8 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend } m_lastTime = nowTime; - + + if (renderState.isInitialRenderCall()) { @@ -557,6 +564,22 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend glDepthFunc(GL_LEQUAL); glClearColor(0.0, 0.0, 0.0, 1); std::cout << "init vizapp end" << std::endl; + const float duration = 10.5f; + + + auto ramp_a = ch::makeRamp(v1, v2, duration); + auto ramp_b = ch::makeRamp(pos1, pos2, duration); + auto group = std::make_shared(); + auto my_sequence = ch::Sequence(glm::vec3()); + my_sequence.then(pos1, 10.0f); + my_sequence.then(pos1, 5.0f); + my_sequence.then(pos2, 20.0f); + //ch::Motion motion(&_control_b, my_sequence); + //group->apply(&_control_a, ramp_a); + group->apply(&_control_b, my_sequence); + + _timeline.addShared(group); + } @@ -566,6 +589,14 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend //glLoadIdentity(); //glLightfv(GL_LIGHT0, GL_POSITION, m_light_pos); + + + //_timeline.step(1.0 / 60.0); + //std::cout << target << std::endl; + //std::cout << _control_b.value().x<<" , "<< _control_b.value().y << " , " << _control_b.value().z << std::endl; + + + if (m_vrVolumeApp) { if (m_vrVolumeApp->pending_models_to_load()) @@ -576,7 +607,17 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend m_vrVolumeApp->initialize_textures(); m_vrVolumeApp->update_3D_ui(); m_vrVolumeApp->update_trackBall_state(); - m_vrVolumeApp->update_animation(); + + + //if (time_lapse_to_seconds >= fps_Limit) + if (true) + { + //std::cout << "animate" << std::endl; + m_vrVolumeApp->update_animation(delta_time.count()); + last_Update_Time = nowTime; + + } + m_vrVolumeApp->set_render_count(0); } From e3559dd39dba670c08249e9bdb323e3ff2131f59 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Thu, 10 Mar 2022 00:05:42 -0500 Subject: [PATCH 09/23] add animationdurantion input text --- include/UI/UIView.h | 2 +- include/interaction/ArcBallCamera.h | 9 +++- src/UI/UIView.cpp | 12 ++++- src/interaction/ArcBallCamera.cpp | 73 +++++++++++++++++------------ 4 files changed, 63 insertions(+), 33 deletions(-) diff --git a/include/UI/UIView.h b/include/UI/UIView.h index d64c571..00b8cdc 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -252,7 +252,7 @@ class UIView std::string m_color_map_directory; float m_animation_speed; - + std::string m_str_animation_duration; }; diff --git a/include/interaction/ArcBallCamera.h b/include/interaction/ArcBallCamera.h index d090abe..3c6b76a 100644 --- a/include/interaction/ArcBallCamera.h +++ b/include/interaction/ArcBallCamera.h @@ -44,11 +44,13 @@ enum WASD_KEYS }; struct PointOfInterest { - std::string label; + + glm::vec3 eye = glm::vec3(0.0f, 0.0f, 1.0f); glm::vec3 target = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); float radius = 1.f; + std::string label; glm::vec3 get_camera_position() { @@ -114,6 +116,9 @@ class ArcBallCamera { std::string get_camera_animation_state(); + float get_camera_animation_duration(); + void set_camera_animation_duration(float duration); + protected: void Rotate(float dTheta, float dPhi); void RotateEyeAxis(float dy); @@ -141,9 +146,11 @@ class ArcBallCamera { ch::Output m_target_animation; ch::Output m_eye_animation; ch::Output m_up_animation; + ch::Output m_radius_animation; ch::Timeline m_timeline; bool m_is_animate_path; + float m_animation_duration; CAMERA_ANIMATION_STATE m_camera_animation_state; std::string animation_button_label; diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index 6b4eb63..f9d6221 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -530,7 +530,7 @@ void UIView::draw_ui_callback() if (ImGui::BeginTabItem("Camera")) { - + ImGui::Text("Points of Interest"); if (ImGui::Button("Add")) { @@ -584,6 +584,7 @@ void UIView::draw_ui_callback() } ImGui::EndTable(); + //Camera animator std::string is_animation_playing = m_controller_app.get_trackball_camera().get_camera_animation_state(); if (ImGui::Button(is_animation_playing.c_str())) { @@ -592,7 +593,16 @@ void UIView::draw_ui_callback() } + ImGui::Text("Duration (seconds)"); + + m_str_animation_duration = std::to_string(m_controller_app.get_trackball_camera().get_camera_animation_duration()); + ImGui::InputText("##textanimationtime", &m_str_animation_duration); + if (ImGui::Button("OK")) { + + + m_controller_app.get_trackball_camera().set_camera_animation_duration(std::stof(m_str_animation_duration)); + } ImGui::EndTabItem(); } diff --git a/src/interaction/ArcBallCamera.cpp b/src/interaction/ArcBallCamera.cpp index b98f286..ea31fac 100644 --- a/src/interaction/ArcBallCamera.cpp +++ b/src/interaction/ArcBallCamera.cpp @@ -38,9 +38,9 @@ ArcBallCamera::ArcBallCamera() : m_radius(1), m_mouse_left_pressed(false), m_mouse_center_pressed(false), m_mouse_right_pressed(false), last_x(0), last_y(0) , m_PanFactor(1), m_RotateFactor(1), m_cameraScrollFactor(0.1), m_target(0, 0, 0), m_eye(0, 0, 1), m_up(0, 1, 0), m_rotate_camera_center{ false } -, m_is_animate_path(false), m_camera_animation_state(STOP), animation_button_label("ANIMATE") +, m_is_animate_path(false), m_camera_animation_state(STOP), animation_button_label("ANIMATE"), m_animation_duration(10.f) { - + } ArcBallCamera::~ArcBallCamera() @@ -54,7 +54,7 @@ void ArcBallCamera::updateCameraMatrix() { /*glm::vec3 animation_position = m_animation; viewmatrix = glm::lookAt(animation_position, m_current_poi.target, m_current_poi.up);*/ - if (m_camera_animation_state != PAUSE ) + if (m_camera_animation_state != PAUSE) { update_animation(); @@ -65,18 +65,18 @@ void ArcBallCamera::updateCameraMatrix() animation_button_label = "Animate"; m_timeline.resetTime(); } - - - - m_viewmatrix = glm::lookAt(m_eye_animation.value(), m_target_animation.value(), m_up_animation.value()); + + + PointOfInterest poi { m_eye_animation.value(), m_target_animation.value(), m_up_animation.value(), m_radius_animation.value() }; + m_viewmatrix = glm::lookAt(poi.get_camera_position(), poi.target, poi.up); } else { - m_viewmatrix = glm::lookAt(m_current_poi.eye, m_current_poi.target, m_current_poi.up); + m_viewmatrix = glm::lookAt(m_current_poi.get_camera_position(), m_current_poi.target, m_current_poi.up); } - + } void ArcBallCamera::mouse_pressed(int button, bool isDown) @@ -195,7 +195,7 @@ void ArcBallCamera::Zoom(float distance) { { m_current_poi.radius = 0.000001; } - + std::cout << m_current_poi.radius << std::endl; } @@ -229,12 +229,12 @@ void ArcBallCamera::add_camera_poi(std::string& label, float eye_x, float eye_y, } int ArcBallCamera::get_current_poi() -{ - return 0; +{ + return 0; } -void ArcBallCamera::set_current_poi(int val) -{ +void ArcBallCamera::set_current_poi(int val) +{ m_is_animate_path = false; std::list::iterator it = m_camera_poi.begin(); for (int i = 0; i < val; i++) { @@ -276,42 +276,45 @@ void ArcBallCamera::update_animation() { if (m_is_animate_path) { - m_timeline.step(1.0 / 60.0); - + m_timeline.step(1.0 / 30.0); + } - + } void ArcBallCamera::set_animation_path() { if (m_camera_poi.size() > 1) { - + PointOfInterest first_position = m_camera_poi.front(); - + ch::Sequence sequence_eye(first_position.eye); ch::Sequence sequence_target(first_position.target); ch::Sequence sequence_up(first_position.up); + ch::Sequence sequence_radius(first_position.radius); - + for (auto next_camera_poi_interator = std::next(m_camera_poi.begin()); next_camera_poi_interator != m_camera_poi.end(); next_camera_poi_interator++) { - sequence_eye.then(next_camera_poi_interator->eye, 10.f); - sequence_target.then(next_camera_poi_interator->target, 10.f); - sequence_up.then(next_camera_poi_interator->up, 10.f); + sequence_eye.then(next_camera_poi_interator->eye, m_animation_duration); + sequence_target.then(next_camera_poi_interator->target, m_animation_duration); + sequence_up.then(next_camera_poi_interator->up, m_animation_duration); + sequence_radius.then(next_camera_poi_interator->radius, m_animation_duration); } - - - auto group= std::make_shared(); + + + auto group = std::make_shared(); group->apply(&m_eye_animation, sequence_eye); group->apply(&m_target_animation, sequence_target); group->apply(&m_up_animation, sequence_up); + group->apply(&m_radius_animation, sequence_radius); m_timeline.addShared(group); - + } - + } void ArcBallCamera::set_animation_state() @@ -319,7 +322,7 @@ void ArcBallCamera::set_animation_state() if (m_camera_animation_state == STOP) { set_animation_path(); - m_camera_animation_state = PLAYING; + m_camera_animation_state = PLAYING; animation_button_label = "PAUSE"; } else if (m_camera_animation_state == PLAYING) @@ -337,7 +340,7 @@ void ArcBallCamera::set_animation_state() } m_is_animate_path = true; - + } CAMERA_ANIMATION_STATE ArcBallCamera::get_animation_state() @@ -361,3 +364,13 @@ std::string ArcBallCamera::get_camera_animation_state() return animation_button_label; } +float ArcBallCamera::get_camera_animation_duration() +{ + return m_animation_duration; +} + +void ArcBallCamera::set_camera_animation_duration(float duration) +{ + m_animation_duration = duration; +} + From 73d67896c80d2d21fbc880fab9c9c513b311901f Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Thu, 14 Apr 2022 10:11:21 -0400 Subject: [PATCH 10/23] add slice animation and 3d terrain lables --- include/UI/UIView.h | 27 +++ include/interaction/ArcBallCamera.h | 13 +- include/interaction/Labels.h | 47 ++++- include/render/VolumeRenderer.h | 12 ++ include/vrapp/VRVolumeApp.h | 40 +++- libs/GLMLoader/VertexBuffer.h | 2 +- libs/Model/Model.cpp | 26 +-- libs/Model/Model.h | 7 +- libs/ShaderProgram/ShaderProgram.cpp | 4 + libs/ShaderProgram/ShaderProgram.h | 10 +- libs/Texture/Texture.cpp | 68 ++++++- libs/Texture/Texture.h | 4 +- libs/UIHelpers/transfer_function_widget.cpp | 21 ++ libs/UIHelpers/transfer_function_widget.h | 2 + shaders/lines_shader.frag | 7 + shaders/lines_shader.vert | 11 + src/UI/UIView.cpp | 213 +++++++++++++++++++- src/interaction/ArcBallCamera.cpp | 26 ++- src/interaction/Labels.cpp | 150 ++++++++++---- src/loader/VRDataLoader.cpp | 2 +- src/main.cpp | 1 + src/vrapp/VRVolumeApp.cpp | 169 +++++++++++++--- 22 files changed, 745 insertions(+), 117 deletions(-) create mode 100644 shaders/lines_shader.frag create mode 100644 shaders/lines_shader.vert diff --git a/include/UI/UIView.h b/include/UI/UIView.h index 00b8cdc..c1dfe0e 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -110,6 +110,9 @@ class UIView glm::vec3 get_clip_min(); glm::vec3 get_clip_max(); + void set_clip_min(glm::vec3 clip_min); + void set_clip_max(glm::vec3 clip_max); + void add_character(char c); void remove_character(); @@ -123,6 +126,11 @@ class UIView void get_Quantiles(int row); + void set_volume_time_info(time_t time); + + void draw_tranfer_funciton_legend(); + + void set_trns_fnct_min_max(float min, float max); private: @@ -254,6 +262,25 @@ class UIView float m_animation_speed; std::string m_str_animation_duration; + bool m_camera_animation_duration_open; + + std::vector m_clip_maxs; + std::vector m_clip_mins; + + + bool m_show_clock; + float halfScreen; + float m_clock_pos_x; + float m_clock_pos_y; + float m_clock_width; + float m_clock_height; + + float m_legend_pos_y; + + std::string m_time_info; + std::string m_day_info; + + std::string months[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; }; diff --git a/include/interaction/ArcBallCamera.h b/include/interaction/ArcBallCamera.h index 3c6b76a..4b3d2c7 100644 --- a/include/interaction/ArcBallCamera.h +++ b/include/interaction/ArcBallCamera.h @@ -50,6 +50,9 @@ struct PointOfInterest { glm::vec3 target = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); float radius = 1.f; + glm::vec3 max_clip; + glm::vec3 min_clip; + std::string label; glm::vec3 get_camera_position() @@ -70,6 +73,8 @@ enum CAMERA_ANIMATION_STATE /** Adds a HeadMatrix to the RenderState that gets updated repeatedly based upon head tracking events. */ + +class VRVolumeApp; class ArcBallCamera { public: @@ -91,7 +96,7 @@ class ArcBallCamera { std::list& get_camera_poi(); - void add_camera_poi(std::string & label); + void add_camera_poi(std::string & label, glm::vec3& clip_max, glm::vec3& clip_min); void add_camera_poi(std::string& label, float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z, float radius); @@ -119,6 +124,8 @@ class ArcBallCamera { float get_camera_animation_duration(); void set_camera_animation_duration(float duration); + void set_controller_application(VRVolumeApp* vr_app); + protected: void Rotate(float dTheta, float dPhi); void RotateEyeAxis(float dy); @@ -147,6 +154,8 @@ class ArcBallCamera { ch::Output m_eye_animation; ch::Output m_up_animation; ch::Output m_radius_animation; + ch::Output m_clip_max_animation; + ch::Output m_clip_min_animation; ch::Timeline m_timeline; bool m_is_animate_path; @@ -154,6 +163,8 @@ class ArcBallCamera { CAMERA_ANIMATION_STATE m_camera_animation_state; std::string animation_button_label; + + VRVolumeApp* m_controller_app; }; #endif diff --git a/include/interaction/Labels.h b/include/interaction/Labels.h index 5ec3b9e..2b18d5b 100644 --- a/include/interaction/Labels.h +++ b/include/interaction/Labels.h @@ -24,30 +24,67 @@ ///\author Benjamin Knorlein ///\date 6/25/2019 -#pragma once - #ifndef LABELS_H #define LABELS_H #include #include #include +#include + + + + + +class Model; +class Texture; +class VRVolumeApp; +class ShaderProgram; + +struct LabelBillboard +{ + unsigned int line_vba; + Texture* label_texture; + Model* label_model; + glm::vec3 position; +}; class Labels { public: - Labels(); + Labels(ShaderProgram& lines_shader, ShaderProgram& plane_shader); ~Labels(); - void add(std::string text, float x, float y, float z, float textPosZ, float size, int volume); - void draw(std::vector& MV, glm::mat4& headpose, float z_scale); + + void add(std::string texture, float x, float y, float z, float textPosZ, float size, int volume); + void drawLabels( glm::mat4 MV, glm::mat4 projection_matrix, glm::mat4& headpose, float z_scale); + void drawLines(); + void clear(); + void set_parent_directory(std::string& directory); + private: + + unsigned int create_line_vba(glm::vec3& start, glm::vec3& end); + + std::vector m_billboard_labels; + std::vector m_text; std::vector m_position; std::vector m_position2; std::vector m_size; std::vector m_volume; + + std::vector m_lines_vba; + std::vector m_lines_vbo; + bool m_init_plane_model; + Model* m_plane_model; + // VRVolumeApp& m_controller_app; + std::map m_texture_cache; + std::string m_parent_directory; + + ShaderProgram& m_lines_shader_program; + ShaderProgram& m_plane_shader_program; }; #endif // LABELS_H diff --git a/include/render/VolumeRenderer.h b/include/render/VolumeRenderer.h index 75e75c6..1dda794 100644 --- a/include/render/VolumeRenderer.h +++ b/include/render/VolumeRenderer.h @@ -31,6 +31,7 @@ #include "FrameBufferObject.h" #include "Volume.h" +#include "choreograph/Choreograph.h" class VolumeRenderer { @@ -50,6 +51,13 @@ class VolumeRenderer virtual void setClipMinMax(glm::vec3 min_clip, glm::vec3 max_clip) = 0; + + void set_animation() + { + + } + + void setClipping(bool isClipping, glm::mat4 * clipPlane) { m_clipping = isClipping; @@ -60,5 +68,9 @@ class VolumeRenderer protected: bool m_clipping; glm::mat4 m_clipPlane; + + }; + + #endif // VOLUMERENDER_H diff --git a/include/vrapp/VRVolumeApp.h b/include/vrapp/VRVolumeApp.h index 0e40d20..fc4a598 100644 --- a/include/vrapp/VRVolumeApp.h +++ b/include/vrapp/VRVolumeApp.h @@ -1,15 +1,17 @@ #ifndef VRVOLUMEAPP_H #define VRVOLUMEAPP_H + #include #include #include #include -#include "interaction/Labels.h" + #include "interaction/ArcBallCamera.h" #include "render/Volume.h" -#include "Model.h" + +#include "ShaderProgram.h" class UIView; @@ -17,6 +19,16 @@ class CreateMovieAction; class VolumeRenderer; class DepthTexture; class Window_Properties; +class Model; +class Texture; +class Simulation; +class Labels; + +enum MovieState +{ + MOVIE_STOP, + MOVIE_RECORD +}; class VRVolumeApp { @@ -93,7 +105,8 @@ class VRVolumeApp void update_animation(float fps); #if (!defined(__APPLE__)) - void run_movie(); + void run_movie(bool is_animation); + void stop_movie(); #endif @@ -156,6 +169,15 @@ class VRVolumeApp void set_animation_speed(float time); + Simulation& get_simulation(); + + void set_clip_min(glm::vec3 clip_min); + void set_clip_max(glm::vec3 clip_max); + + std::string get_movie_state_label(); + + MovieState get_movie_state(); + protected: glm::vec4 m_noColor;// (0.0f, 0.0f, 0.0f, 0.0f); @@ -169,7 +191,7 @@ class VRVolumeApp - void render_labels(const MinVR::VRGraphicsState& renderState); + void render_labels(glm::mat4& volume_mv, const MinVR::VRGraphicsState& renderState); void render_mesh(const MinVR::VRGraphicsState& renderState); void render_volume(const MinVR::VRGraphicsState& renderState); void render_ui(const MinVR::VRGraphicsState& renderState); @@ -181,7 +203,7 @@ class VRVolumeApp std::vector < std::vector< Volume* >> m_volumes; std::vector m_description; - Labels m_labels; + Labels* m_labels; std::vector m_models_filenames; std::vector m_models_displayLists; std::vector m_models_position; @@ -200,6 +222,8 @@ class VRVolumeApp Model* m_mesh_model; ShaderProgram m_simple_texture_shader; + ShaderProgram m_line_shader; + std::string m_shader_file_path; std::string m_texture_filePath; Texture* m_texture; @@ -276,5 +300,11 @@ class VRVolumeApp std::string m_current_file_loaded; Window_Properties* m_window_properties; + + Simulation* m_simulation; + + MovieState m_current_movie_state; + bool m_stop_movie; + }; #endif diff --git a/libs/GLMLoader/VertexBuffer.h b/libs/GLMLoader/VertexBuffer.h index 0e492cd..2919554 100644 --- a/libs/GLMLoader/VertexBuffer.h +++ b/libs/GLMLoader/VertexBuffer.h @@ -36,7 +36,7 @@ #include #include #include -#include + class VertexBuffer { diff --git a/libs/Model/Model.cpp b/libs/Model/Model.cpp index cfee664..93e20bd 100644 --- a/libs/Model/Model.cpp +++ b/libs/Model/Model.cpp @@ -1,7 +1,7 @@ #include "Model.h" #include #include - +#include "ShaderProgram.h" Model::Model():m_position(0),m_orientation(glm::quat()),m_scale(1), m_bounding_volumen_radius(1) { @@ -12,10 +12,8 @@ Model::Model():m_position(0),m_orientation(glm::quat()),m_scale(1), m_bounding_v Model::~Model() { delete m_Obj_Model; - for (int i = 0 ; i < m_textures.size(); ++i) - { - delete m_textures[i]; - } + + delete m_texture; } @@ -31,12 +29,12 @@ void Model::setObjModel(VertexBuffer* val) Texture& Model::texture(int index) const { - return *m_textures[index]; + return *m_texture; } -void Model::addTexture(Texture* val) +void Model::setTexture(Texture* val) { - m_textures.push_back(val); + m_texture = val; } void Model::render(ShaderProgram& shaderProgram) @@ -52,16 +50,20 @@ void Model::render(ShaderProgram& shaderProgram) assert(m_Obj_Model && "NO MODEL TO RENDER"); // bind texture - for (int i = 0; i < m_textures.size(); ++i) - { - m_textures[i]->Bind(i); - } + + m_texture->Bind(0); + //render geometry if (m_Obj_Model) { m_Obj_Model->render(); } + + //Unbind Text + + m_texture->UnBind(0); + } glm::vec3& Model::position() diff --git a/libs/Model/Model.h b/libs/Model/Model.h index ad20b17..85813c1 100644 --- a/libs/Model/Model.h +++ b/libs/Model/Model.h @@ -2,8 +2,9 @@ #define MODEL_H #include "VertexBuffer.h" #include "Texture.h" -#include "ShaderProgram.h" + +class ShaderProgram; class Model { public: @@ -15,7 +16,7 @@ class Model Texture& texture(int index) const; - void addTexture(Texture* val); + void setTexture(Texture* val); void render( ShaderProgram& shader); @@ -52,7 +53,7 @@ class Model Model(); VertexBuffer* m_Obj_Model; - std::vector m_textures; + Texture* m_texture; friend class GLMLoader; friend class AssimpLoader; diff --git a/libs/ShaderProgram/ShaderProgram.cpp b/libs/ShaderProgram/ShaderProgram.cpp index 5b5fc36..4476ed6 100644 --- a/libs/ShaderProgram/ShaderProgram.cpp +++ b/libs/ShaderProgram/ShaderProgram.cpp @@ -2,6 +2,10 @@ #include #include +#include +#include + + ShaderProgram::ShaderProgram() :m_progarm_id(0) { } diff --git a/libs/ShaderProgram/ShaderProgram.h b/libs/ShaderProgram/ShaderProgram.h index 2c1de24..c728f9d 100644 --- a/libs/ShaderProgram/ShaderProgram.h +++ b/libs/ShaderProgram/ShaderProgram.h @@ -23,17 +23,11 @@ #endif #define GLM_ENABLE_EXPERIMENTAL -#include -#include -#include -#include -#include + #include #include - - - +#include class ShaderProgram { diff --git a/libs/Texture/Texture.cpp b/libs/Texture/Texture.cpp index c006a12..25e34c0 100644 --- a/libs/Texture/Texture.cpp +++ b/libs/Texture/Texture.cpp @@ -3,6 +3,7 @@ #include #include + Texture::Texture(GLenum TextureTarget, const std::string& filename) : m_texture_target(TextureTarget) , m_file_name(filename.c_str()) { @@ -15,7 +16,7 @@ Texture::~Texture() void Texture::Bind(GLenum TextureUnit) { - glActiveTexture(GL_TEXTURE0 + TextureUnit); + glActiveTexture(GL_TEXTURE0 + 0); glBindTexture(m_texture_target, m_texture_id); } @@ -24,6 +25,12 @@ GLuint Texture::GetTextureId() return m_texture_id; } +void Texture::UnBind(GLenum TextureUnit) +{ + glActiveTexture(GL_TEXTURE0 + TextureUnit); + glBindTexture(m_texture_target, 0); +} + int Texture::Load2DTexture() { @@ -46,6 +53,65 @@ int Texture::Load2DTexture() return textureID; } +int Texture::Load3DTexture(const std::vector& paths) +{ + if (paths.size() == 0) + { + assert(false && "no paths to load from"); + } + + GLsizei width, height, depth = paths.size(); + + std::vector formatedImages(paths.size()); + + // load and format each image + for (int i = 0; i < paths.size(); ++i) + { + BYTE* bits(0); + int bbp = 0; + if (!LoadTexture(paths[i], width, height, &bits, bbp)) + { + assert(false && "Image failed to load 2"); + } + image img(width, height, bits); + formatedImages[i] = img; + } + + GLuint textureID; + glGenTextures(1, &textureID); + glBindTexture(GL_TEXTURE_2D_ARRAY, textureID); + //Create storage for the texture. (100 layers of 1x1 texels) + glTexStorage3D(GL_TEXTURE_2D_ARRAY, + 1, //No mipmaps as textures are 1x1 + GL_RGBA8, //Internal format + width, height, //width,height + depth //Number of layers + ); + + for (unsigned int i = 0; i < formatedImages.size(); ++i) + { + //Specify i-essim image + glTexSubImage3D(GL_TEXTURE_2D_ARRAY, + 0, //Mipmap number + 0, 0, i, //xoffset, yoffset, zoffset + formatedImages[i].imageWidth, formatedImages[i].imageHeight, 1, //width, height, depth + GL_RGB, //format + GL_UNSIGNED_BYTE, //type + formatedImages[i].imageData); //pointer to data + } + + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); + + + glBindTexture(GL_TEXTURE_2D_ARRAY, 0); + // Return the ID of the texture we just created + return textureID; + +} + int Texture::LoadTexture(const std::string & fileName, int & width, int & height, unsigned char ** data, int& bbp) { diff --git a/libs/Texture/Texture.h b/libs/Texture/Texture.h index f182412..9f4fb89 100644 --- a/libs/Texture/Texture.h +++ b/libs/Texture/Texture.h @@ -23,6 +23,7 @@ #endif #include +#include class Texture { @@ -32,6 +33,7 @@ class Texture void Bind(GLenum TextureUnit); GLuint GetTextureId(); + void UnBind(GLenum TextureUnit); int LoadTexture(const std::string& fileName, int& width, int& height, unsigned char ** data, int& bbp); @@ -48,7 +50,7 @@ class Texture }; int Load2DTexture(); - + int Load3DTexture(const std::vector& paths); GLuint m_texture_id; diff --git a/libs/UIHelpers/transfer_function_widget.cpp b/libs/UIHelpers/transfer_function_widget.cpp index 8942a2d..2e7bb31 100644 --- a/libs/UIHelpers/transfer_function_widget.cpp +++ b/libs/UIHelpers/transfer_function_widget.cpp @@ -415,6 +415,27 @@ void TransferFunctionWidget::drawLegend() { } +void TransferFunctionWidget::drawLegend( float legend_pos_x, float legend_pos_y, float legend_width, float legend_height) +{ + bool show_legend = true; + ImGui::SetNextWindowPos(ImVec2(legend_pos_x, legend_pos_y)); + ImGui::SetNextWindowSize(ImVec2(legend_width, legend_height)); + ImGui::Begin("##legend", &show_legend, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); + ImGuiIO& io = ImGui::GetIO(); + ImTextureID my_tex_id = io.Fonts->TexID; + float my_tex_w = (float)io.Fonts->TexWidth; + float my_tex_h = (float)io.Fonts->TexHeight; + std::string max_str = std::to_string(m_min_max_val[1]); + float offset = 0.008 * (my_tex_w * max_str.size()); + ImGui::Image(reinterpret_cast(colormap_img), ImVec2(legend_width, 16)); + ImGui::Text("%.0f", m_min_max_val[0]); + ImGui::SameLine((legend_width /2) ); + ImGui::Text("%.0f", (m_min_max_val[0]+ m_min_max_val[1]) /2); + ImGui::SameLine(ImGui::GetWindowWidth() - offset); + ImGui::Text(" %.0f", m_min_max_val[1]); + ImGui::End(); +} + void TransferFunctionWidget::draw_histogram() { diff --git a/libs/UIHelpers/transfer_function_widget.h b/libs/UIHelpers/transfer_function_widget.h index 47ff3e7..ea592ae 100644 --- a/libs/UIHelpers/transfer_function_widget.h +++ b/libs/UIHelpers/transfer_function_widget.h @@ -104,6 +104,8 @@ class TransferFunctionWidget { void drawLegend(); + void drawLegend(float legend_pos_x, float legend_pos_y, float legend_width, float legend_height); + void draw_histogram(); void update_colormap(); diff --git a/shaders/lines_shader.frag b/shaders/lines_shader.frag new file mode 100644 index 0000000..3656050 --- /dev/null +++ b/shaders/lines_shader.frag @@ -0,0 +1,7 @@ +#version 410 + +out vec4 frag_colour; + +void main () { + frag_colour = vec4 (1.0, 0.0, 0.0, 1.0); +} \ No newline at end of file diff --git a/shaders/lines_shader.vert b/shaders/lines_shader.vert new file mode 100644 index 0000000..11a8b8a --- /dev/null +++ b/shaders/lines_shader.vert @@ -0,0 +1,11 @@ +#version 410 + +layout (location = 0 )in vec3 vp; +uniform mat4 mv; +uniform mat4 p; + + +void main () { + + gl_Position = p * mv * vec4(vp,1); +} \ No newline at end of file diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index f9d6221..d35f601 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -30,7 +30,9 @@ m_file_load_trnsf(false), m_file_dialog_save_dir(false), m_save_session_dialog_o m_current_load_modal(LOAD_NONE), m_file_extension_filter(".txt"), m_non_trns_functions_selected_modal(false), m_ui_background(false), m_column_selection_state(0), m_compute_new_histogram(true), m_histogram_point_1(0.0), m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0), -m_camera_name_window_open(false), m_camera_button_action(BUTTON_ACTION::NONE), m_num_animation_frames(0), m_animation_speed(1.0f) +m_camera_name_window_open(false), m_camera_button_action(BUTTON_ACTION::NONE), m_num_animation_frames(0), m_animation_speed(1.0f), +m_camera_animation_duration_open(false), m_show_clock(true), m_clock_width(250), m_clock_height(200), +m_time_info(""),m_day_info("") { m_ocean_color_maps_names = { "algae.png","amp.png","balance.png","curl.png","deep.png","delta.png","dense.png", "diff.png","gray.png","haline.png","ice.png","matter.png","oxy.png","phase.png","rain.png","solar.png","speed.png","tarn.png","tempo.png", @@ -444,6 +446,7 @@ void UIView::draw_ui_callback() m_histogram.draw_histogram(); tfn_widget[m_trnfnc_table_selection].draw_ui(); + //tfn_widget[m_trnfnc_table_selection].setMinMax() } } @@ -479,10 +482,22 @@ void UIView::draw_ui_callback() } #if (!defined(__APPLE__)) - if (ImGui::Button("Write Movie")) + std::string movie_button_label = m_controller_app.get_movie_state_label(); + if (movie_button_label == "Write Movie") { - m_controller_app.run_movie(); + if (ImGui::Button(movie_button_label.c_str())) + { + m_controller_app.run_movie(false); + } + } + else + { + if (ImGui::Button(movie_button_label.c_str())) + { + m_controller_app.stop_movie(); + } } + #endif } ImGui::EndTabItem(); @@ -590,25 +605,96 @@ void UIView::draw_ui_callback() if (ImGui::Button(is_animation_playing.c_str())) { m_controller_app.get_trackball_camera().set_animation_state(); - + } ImGui::Text("Duration (seconds)"); - m_str_animation_duration = std::to_string(m_controller_app.get_trackball_camera().get_camera_animation_duration()); - ImGui::InputText("##textanimationtime", &m_str_animation_duration); - if (ImGui::Button("OK")) { + + std::stringstream text; + text << std::fixed << std::setprecision(1) << m_controller_app.get_trackball_camera().get_camera_animation_duration(); + std::string str_animation_duration = text.str(); + + if (ImGui::Button(str_animation_duration.c_str())) + { + m_camera_animation_duration_open = true; + m_str_animation_duration= std::string( str_animation_duration); + } +#if (!defined(__APPLE__)) + std::string movie_button_label = m_controller_app.get_movie_state_label(); + if (movie_button_label == "Write Movie") + { + if (ImGui::Button(movie_button_label.c_str())) + { + m_controller_app.get_trackball_camera().set_animation_state(); + m_controller_app.run_movie(true); + } + } + else + { + if (ImGui::Button(movie_button_label.c_str())) + { + m_controller_app.stop_movie(); + } + } +#endif + + ImGui::EndTabItem(); + } + + if (ImGui::BeginTabItem("Animation")) + { + std::string is_animation_playing = m_controller_app.get_trackball_camera().get_camera_animation_state(); + + if (ImGui::Button(is_animation_playing.c_str())) { - m_controller_app.get_trackball_camera().set_camera_animation_duration(std::stof(m_str_animation_duration)); + m_controller_app.get_trackball_camera().set_animation_state(); } + ImGui::Text("Duration (seconds)"); + + + std::stringstream text; + text << std::fixed << std::setprecision(1) << m_controller_app.get_trackball_camera().get_camera_animation_duration(); + std::string str_animation_duration = text.str(); + + if (ImGui::Button(str_animation_duration.c_str())) + { + m_camera_animation_duration_open = true; + m_str_animation_duration = std::string(str_animation_duration); + } +#if (!defined(__APPLE__)) + if (ImGui::Button("Write Movie")) + { + m_controller_app.get_trackball_camera().set_animation_state(); + m_controller_app.run_movie(true); + } +#endif + ImGui::EndTabItem(); } ImGui::EndTabBar(); + + float width = 11.0f; + ImGui::SetNextWindowPos(ImVec2(m_clock_pos_x, m_clock_pos_y)); + ImGui::SetNextWindowSize(ImVec2(m_clock_width, m_clock_height)); + ImGui::Begin("##clock", &m_show_clock, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); + ImGui::SetWindowFontScale(1.3f); + ImGui::Text(m_time_info.c_str()); + ImGui::Text(m_day_info.c_str()); + ImGui::End(); + + if (m_use_transferfunction) + { + tfn_widget[0].drawLegend(0, m_legend_pos_y + 80, m_clock_width + 50, m_clock_height - 140); + } + + + if (m_camera_name_window_open) { std::string modal_window_name; @@ -637,7 +723,8 @@ void UIView::draw_ui_callback() if (m_camera_button_action == ADD) { - m_controller_app.get_trackball_camera().add_camera_poi(m_copy_camera_name); + m_controller_app.get_trackball_camera().add_camera_poi(m_copy_camera_name, m_clip_max,m_clip_min); + m_copy_camera_name.clear(); m_camera_poi_table_selection = m_controller_app.get_trackball_camera().get_camera_poi().size()-1; } @@ -660,6 +747,32 @@ void UIView::draw_ui_callback() } + if (m_camera_animation_duration_open) + { + ImGui::OpenPopup("Animation Time"); + ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); + if (ImGui::BeginPopupModal("Animation Time", &m_camera_animation_duration_open)) + { + ImGui::Text("Camera Name"); + ImGui::InputText("##textanimationtime", &m_str_animation_duration, ImGuiInputTextFlags_CharsDecimal); + if (ImGui::Button("Ok")) + { + m_controller_app.get_trackball_camera().set_camera_animation_duration(std::stof(m_str_animation_duration)); + m_str_animation_duration.clear(); + m_camera_animation_duration_open = false; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Cancel")) + { + m_camera_animation_duration_open = false; + m_str_animation_duration.clear(); + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + } + + //file loading if (m_file_dialog_open) { @@ -822,12 +935,12 @@ void UIView::update_ui(int numVolumes) tfn_widget_multi.resize(1); tfn_widget.resize(1); m_use_transferfunction = true; - /* m_selected_volume_TrFn.resize(1); + m_selected_volume_TrFn.resize(1); m_selected_volume_TrFn[0].resize(numVolumes); for (int i = 0; i < numVolumes; i++) { m_selected_volume_TrFn[0][i] = false; - }*/ + } MyTransFerFunctions trfntc; char label[32]; @@ -850,6 +963,11 @@ void UIView::render_2D(Window_Properties& window_properties) if (m_show_menu) { + m_clock_pos_x = window_properties.window_w - m_clock_width; + m_clock_pos_y = window_properties.window_h - m_clock_height; + m_legend_pos_y = window_properties.window_h - m_clock_height; + + m_menu_handler->drawMenu(window_properties.window_w, window_properties.window_h, window_properties.framebuffer_w, window_properties.framebuffer_h); @@ -1069,6 +1187,16 @@ glm::vec3 UIView::get_clip_max() return m_clip_max; } +void UIView::set_clip_min(glm::vec3 clip_min) +{ + m_clip_min = clip_min; +} + +void UIView::set_clip_max(glm::vec3 clip_max) +{ + m_clip_max = clip_max; +} + void UIView::add_character(char c) { if (m_trn_fct_options_window) @@ -1088,6 +1216,16 @@ void UIView::add_character(char c) ImGui::ClearActiveID(); m_copy_camera_name += c; } + + if (m_camera_animation_duration_open) + { + ImGui::ClearActiveID(); + if ((c >= '0' && c <= '9') || (c == '.')) + { + m_str_animation_duration += c; + } + + } } void UIView::remove_character() @@ -1117,6 +1255,16 @@ void UIView::remove_character() m_copy_camera_name.pop_back(); } } + + if (m_camera_animation_duration_open) + { + if (!m_str_animation_duration.empty()) + { + ImGui::ClearActiveID(); + m_str_animation_duration.pop_back(); + } + + } } void UIView::open_save_modal_dialog(std::string& id, bool& window_state, @@ -1591,6 +1739,49 @@ void UIView::get_Quantiles(int row) m_trn_fct_options_window = true; } +void UIView::set_volume_time_info(time_t time) +{ + + tm* time_info = localtime(&time); + + bool pm = time_info->tm_hour >= 12; + int hour_12 = (time_info->tm_hour >= 13) ? time_info->tm_hour - 12 : time_info->tm_hour; + + std::stringstream ss_time; + ss_time << std::setw(2) << std::setfill('0') << hour_12 << ":"; + ss_time << std::setw(2) << std::setfill('0') << time_info->tm_min << " "; + ss_time << (pm ? "PM" : "AM"); + + std::stringstream ss_day; + ss_day << months[time_info->tm_mon] << " "; + ss_day << std::setw(2) << std::setfill('0') << time_info->tm_mday; + ss_day << ", " << time_info->tm_year + 1900; + + m_time_info = ss_time.str(); + m_day_info = ss_day.str(); + +} + +void UIView::draw_tranfer_funciton_legend() +{ + if (m_use_transferfunction) + { + tfn_widget[0].drawLegend(); + } + +} + +void UIView::set_trns_fnct_min_max(float min, float max) +{ + /*tfn_widget[0].setMinMax(m_volumes[m_selectedVolume][active_volume]->getMin() * alpha + m_volumes[m_selectedVolume][active_volume2]->getMin() * (1.0 - alpha), + m_volumes[m_selectedVolume][active_volume]->getMax() * alpha + m_volumes[m_selectedVolume][active_volume2]->getMax() * (1.0 - alpha));*/ + if (m_use_transferfunction) + { + tfn_widget[0].setMinMax(min, max); + } + +} + void UIView::load_ocean_color_maps() { int w, h, n; diff --git a/src/interaction/ArcBallCamera.cpp b/src/interaction/ArcBallCamera.cpp index ea31fac..de61bd7 100644 --- a/src/interaction/ArcBallCamera.cpp +++ b/src/interaction/ArcBallCamera.cpp @@ -31,6 +31,7 @@ #include #define GLM_ENABLE_EXPERIMENTAL #include +#include "../../include/vrapp/VRVolumeApp.h" #ifndef _PI #define _PI 3.141592653 @@ -57,6 +58,8 @@ void ArcBallCamera::updateCameraMatrix() if (m_camera_animation_state != PAUSE) { update_animation(); + m_controller_app->set_clip_max(m_clip_max_animation.value()); + m_controller_app->set_clip_min(m_clip_min_animation.value()); } if (m_timeline.isFinished()) @@ -64,6 +67,11 @@ void ArcBallCamera::updateCameraMatrix() m_camera_animation_state = STOP; animation_button_label = "Animate"; m_timeline.resetTime(); + if (m_controller_app->get_movie_state() == MOVIE_RECORD) + { + m_controller_app->stop_movie(); + } + } @@ -211,9 +219,12 @@ std::list& ArcBallCamera::get_camera_poi() return m_camera_poi; } -void ArcBallCamera::add_camera_poi(std::string& label) +void ArcBallCamera::add_camera_poi(std::string& label, glm::vec3& clip_max, glm::vec3& clip_min) { m_current_poi.label = label; + m_current_poi.max_clip = clip_max; + m_current_poi.min_clip = clip_min; + m_camera_poi.push_back(m_current_poi); } @@ -226,6 +237,8 @@ void ArcBallCamera::add_camera_poi(std::string& label, float eye_x, float eye_y, poi.up = glm::vec3(up_x, up_y, up_z); poi.radius = radius; m_camera_poi.push_front(poi); + + } int ArcBallCamera::get_current_poi() @@ -294,6 +307,8 @@ void ArcBallCamera::set_animation_path() ch::Sequence sequence_target(first_position.target); ch::Sequence sequence_up(first_position.up); ch::Sequence sequence_radius(first_position.radius); + ch::Sequence sequence_clip_max(first_position.max_clip); + ch::Sequence sequence_clip_min(first_position.min_clip); for (auto next_camera_poi_interator = std::next(m_camera_poi.begin()); next_camera_poi_interator != m_camera_poi.end(); next_camera_poi_interator++) @@ -302,6 +317,8 @@ void ArcBallCamera::set_animation_path() sequence_target.then(next_camera_poi_interator->target, m_animation_duration); sequence_up.then(next_camera_poi_interator->up, m_animation_duration); sequence_radius.then(next_camera_poi_interator->radius, m_animation_duration); + sequence_clip_max.then(next_camera_poi_interator->max_clip, m_animation_duration); + sequence_clip_min.then(next_camera_poi_interator->min_clip, m_animation_duration); } @@ -310,6 +327,8 @@ void ArcBallCamera::set_animation_path() group->apply(&m_target_animation, sequence_target); group->apply(&m_up_animation, sequence_up); group->apply(&m_radius_animation, sequence_radius); + group->apply(&m_clip_max_animation, sequence_clip_max); + group->apply(&m_clip_min_animation, sequence_clip_min); m_timeline.addShared(group); @@ -374,3 +393,8 @@ void ArcBallCamera::set_camera_animation_duration(float duration) m_animation_duration = duration; } +void ArcBallCamera::set_controller_application(VRVolumeApp* vr_app) +{ + m_controller_app = vr_app; +} + diff --git a/src/interaction/Labels.cpp b/src/interaction/Labels.cpp index e60d6cd..83d1016 100644 --- a/src/interaction/Labels.cpp +++ b/src/interaction/Labels.cpp @@ -35,8 +35,8 @@ #if defined(WIN32) #define NOMINMAX #include -#include -#include +#include "GL/glew.h" +#include "GL/wglew.h" #elif defined(__APPLE__) #include #include @@ -50,9 +50,13 @@ #include #include #include "../../include/render/FontHandler.h" -#include +#include "GLMLoader.h" +#include +#include + -Labels::Labels() +Labels::Labels( ShaderProgram& lines_shader, ShaderProgram& plane_shader): + m_init_plane_model(false), m_lines_shader_program(lines_shader), m_plane_shader_program(plane_shader), m_plane_model(nullptr) { } @@ -60,8 +64,15 @@ Labels::Labels() Labels::~Labels() { clear(); + std::map::iterator it; + for (it = m_texture_cache.begin(); it != m_texture_cache.end(); it++) + { + delete it->second; + } + delete m_plane_model; } + void Labels::clear() { m_text.clear(); m_position.clear(); @@ -70,52 +81,119 @@ void Labels::clear() { m_volume.clear(); } -void Labels::add(std::string text, float x, float y, float z, float textPosZ, float size, int volume) +void Labels::set_parent_directory(std::string& directory) +{ + m_parent_directory = directory; +} + +unsigned int Labels::create_line_vba(glm::vec3& start, glm::vec3& end) +{ + unsigned int vba; + unsigned int vbo; + glGenVertexArrays(1, &vba); + glGenBuffers(1, &vbo); + + std::vector line; + line.push_back(start); + line.push_back(end); + + glBindVertexArray(vba); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData( + GL_ARRAY_BUFFER, + sizeof(glm::vec3) * 2, + &line[0], + GL_STATIC_DRAW + ); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); + glEnableVertexAttribArray(0); + + m_lines_vba.push_back(vba); + m_lines_vbo.push_back(vbo); + + return vba; +} + +void Labels::add( std::string texture_path, float x, float y, float z, float textPosZ, float size, int volume) { - m_text.push_back(text); + if (!m_init_plane_model) + { + std::string plane_obj_path = m_parent_directory+"Resources/Models/plane.obj"; + m_plane_model = GLMLoader::loadObjModel(plane_obj_path); + m_init_plane_model = true; + } + + if (m_texture_cache.find(texture_path) == m_texture_cache.end()) + { + + Texture* texture = new Texture(GL_TEXTURE_2D, texture_path); + m_texture_cache[texture_path] = texture; + } + + + LabelBillboard billboard; + glm::vec3 line_start(x, y, z); + glm::vec3 line_end(x, y, textPosZ + 200); + unsigned int line_vba = create_line_vba(line_start, line_end); + billboard.line_vba = line_vba; + billboard.label_texture = m_texture_cache[texture_path]; + billboard.label_model = m_plane_model; + billboard.position = glm::vec3(x, y, textPosZ+250); + m_billboard_labels.push_back(billboard); + m_position.push_back(glm::vec3(x, y, z)); m_position2.push_back(glm::vec3(x, y, textPosZ)); m_size.push_back(size); m_volume.push_back(volume); } -void Labels::draw(std::vector& MV, glm::mat4& headpose, float z_scale) +void Labels::drawLabels(glm::mat4 volume_mv, glm::mat4 projection_matrix, glm::mat4& headpose, float z_scale) { - for (int i = 0; i < m_text.size(); i++) + for (int i = 0; i < m_billboard_labels.size(); i++) { - glm::vec4 markerpos = MV[m_volume[i]] * glm::vec4(m_position[i].x, m_position[i].y, 1, 1); + //draw line + m_lines_shader_program.start(); + m_lines_shader_program.setUniform("p", projection_matrix); + m_lines_shader_program.setUniform("mv", volume_mv); + glLineWidth(2); + glBindVertexArray(m_billboard_labels[i].line_vba); + glDrawArrays(GL_LINES, 0, 2); + glBindVertexArray(0); + m_lines_shader_program.stop(); + + glm::vec4 markerpos = volume_mv * glm::vec4(m_billboard_labels[i].position.x, m_billboard_labels[i].position.y, 1, 1); glm::vec4 headpos = headpose * glm::vec4(0, 0, 0, 1); glm::vec4 dir = headpos / headpos.w - markerpos / markerpos.w; dir.w = 0; - dir = inverse(MV[m_volume[i]]) * dir; + dir = inverse(volume_mv) * dir; dir.z = 0; dir = normalize(dir); - double angle = 180.0f / M_PI * atan2(dir.x, dir.y); - - glDisable(GL_LIGHTING); - glPushMatrix(); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(glm::value_ptr(MV[m_volume[i]])); - glLineWidth(2); - glBegin(GL_LINES); - glColor4f(1.0f, 0.0f, 0.0f, 1.0f); - // Yellow - glVertex3f(m_position[i].x, m_position[i].y, m_position[i].z); - glVertex3f(m_position[i].x, m_position[i].y, m_position2[i].z - 3); - glEnd(); - - glPushMatrix(); - glTranslatef(m_position[i].x, m_position[i].y, m_position2[i].z); - glRotatef(180 - angle, 0, 0, 1); - glRotatef(90, 1, 0, 0); - glScalef(1.0f, 1.0f / z_scale, 1.0f); - FontHandler::getInstance()->renderTextBox(m_text[i], -1000.0, 0, 0, 2000.0, m_size[i], TextAlignment::CENTER); - glEnable(GL_LIGHTING); - - - + float angle = 180.0f / M_PI * atan2(dir.x, dir.y); + glm::mat4 label_mv; + + label_mv = glm::translate(volume_mv, m_billboard_labels[i].position); + label_mv = glm::scale(label_mv, glm::vec3(50.0f, 50.0f, 100.0f)); + label_mv = glm::rotate(label_mv, glm::radians(180.0f - angle),glm::vec3(0.0f, 0.0f, 1.0f)); + label_mv = glm::rotate(label_mv, glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f)); + //label_mv = glm::scale(label_mv, glm::vec3(1.0f, 1.0f / z_scale, 1.0f)); + m_plane_shader_program.start(); + m_plane_shader_program.setUniform("p", projection_matrix); + m_plane_model->setMVMatrix(label_mv); + m_billboard_labels[i].label_model->setTexture(m_billboard_labels[i].label_texture); + m_billboard_labels[i].label_model->render(m_plane_shader_program); + m_plane_shader_program.stop(); + } + +} - glPopMatrix(); - glPopMatrix(); +void Labels::drawLines() +{ + + for (size_t i =0; i < m_lines_vba.size();++i) + { + glBindVertexArray(m_lines_vba[i]); + glDrawArrays(GL_LINES, 0, 2); + glBindVertexArray(0); } + } diff --git a/src/loader/VRDataLoader.cpp b/src/loader/VRDataLoader.cpp index aa9295c..df2ce5e 100644 --- a/src/loader/VRDataLoader.cpp +++ b/src/loader/VRDataLoader.cpp @@ -73,7 +73,7 @@ void VRDataLoader::load_txt_file(VRVolumeApp& vrVolumeApp, std::string& filename std::cerr << "text at position " << vals[2] << " , " << vals[3] << " , " << vals[5] << std::endl; std::cerr << "text Size " << vals[6] << std::endl; std::cerr << "for Volume " << vals[7] << std::endl; - std::string label = vals[1]; + std::string label = p_filename.directoryPath() + OS_SLASH_LOCAL + vals[1]; vrVolumeApp.add_label(label, stof(vals[2]), stof(vals[3]), stof(vals[4]), stof(vals[5]), stof(vals[6]), stoi(vals[7]) - 1); } if (tag == "desc") diff --git a/src/main.cpp b/src/main.cpp index 4e30369..30f208d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ int main(int argc, char **argv) { int num_parameters = 4; char * arguments[] = { argv[0],"-c","desktop_observer.minvr", "use2DUI"}; + //char* arguments[] = { argv[0],"-c","desktop.minvr", "use2DUI" }; VolumeVisualizationApp app(num_parameters, arguments); diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index 06a9be9..ad602e8 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -10,6 +10,8 @@ #include "interaction/HelperFunctions.h" #include "render/FontHandler.h" #include "interaction/CreateMovieAction.h" +#include "interaction/Simulation.h" +#include "interaction/Labels.h" #ifdef _WIN32 #include "GL/glew.h" @@ -44,12 +46,15 @@ #include +#include "Model.h" +#include "Texture.h" + VRVolumeApp::VRVolumeApp() :m_mesh_model(nullptr), m_clip_max{ 1.0f }, m_clip_min{ 0.0f }, m_clip_ypr{ 0.0f }, m_clip_pos{ 0.0 }, m_wasd_pressed(0), m_lookingGlass(false), m_isInitailized(false), m_speed(0.01f), m_movieAction(nullptr), m_moviename("movie.mp4"), m_noColor(0.0f), m_ambient(0.2f, 0.2f, 0.2f, 1.0f), m_diffuse(0.5f, 0.5f, 0.5f, 1.0f), m_ui_view(nullptr), m_animated(false), m_numVolumes(0), m_selectedVolume(0), m_multiplier(1.0f), m_threshold(0.0f), m_frame(0.0f), m_use_multi_transfer(false), m_clipping(false), m_show_menu(true), -m_window_properties(nullptr), m_animation_speed(1.0f) +m_window_properties(nullptr), m_animation_speed(1.0f),m_simulation(nullptr), m_current_movie_state(MOVIE_STOP) { m_renders.push_back(new VolumeSliceRenderer()); m_renders.push_back(new VolumeRaycastRenderer()); @@ -62,6 +67,16 @@ VRVolumeApp::~VRVolumeApp() delete m_ui_view; } + for (int i = 0; i < m_volumes.size(); i++) { + std::vector< Volume* > v = m_volumes[i]; + for (int j = 0; j < v.size(); j++) + { + delete v[j]; + } + + } + m_volumes.clear(); + delete m_window_properties; } @@ -83,6 +98,11 @@ void VRVolumeApp::initialize() m_ui_view->init_ui(m_is2d, m_lookingGlass); } m_window_properties = new Window_Properties(); + //m_simulation = new Simulation() + m_labels = new Labels(m_line_shader, m_simple_texture_shader); + m_labels->set_parent_directory(get_directory_path()); + + m_trackball.set_controller_application(this); m_isInitailized = true; m_rendercount = 0; std::cout << "initialize end" << std::endl; @@ -124,7 +144,7 @@ void VRVolumeApp::load_mesh_model() if (m_texture) { - m_mesh_model->addTexture(m_texture); + m_mesh_model->setTexture(m_texture); } @@ -141,6 +161,12 @@ void VRVolumeApp::load_shaders() m_simple_texture_shader.LoadShaders(vertexShaderFolderPath.c_str(), fragmentShaderFolderPath.c_str()); m_simple_texture_shader.addUniform("p"); m_simple_texture_shader.addUniform("mv"); + + std::string linesVertexShaderFolderPath = m_shader_file_path + OS_SLASH + std::string("lines_shader.vert"); + std::string linesFragmentShaderFolderPath = m_shader_file_path + OS_SLASH + std::string("lines_shader.frag"); + m_line_shader.LoadShaders(linesVertexShaderFolderPath.c_str(), linesFragmentShaderFolderPath.c_str()); + m_line_shader.addUniform("p"); + m_line_shader.addUniform("mv"); } void VRVolumeApp::initialize_textures() @@ -184,7 +210,7 @@ void VRVolumeApp::update_animation(float fps) } #if (!defined(__APPLE__)) -void VRVolumeApp::run_movie() +void VRVolumeApp::run_movie(bool is_animation) { #ifndef _MSC_VER fs::create_directory("movie"); @@ -194,8 +220,24 @@ void VRVolumeApp::run_movie() m_movieAction = new CreateMovieAction(); m_frame = 0; - m_show_menu = false; + if (is_animation) + { + m_show_menu = false; + } + m_current_movie_state = MOVIE_RECORD; } + +void VRVolumeApp::stop_movie() +{ + m_current_movie_state = MOVIE_STOP; +#ifdef _MSC_VER + m_movieAction->save(m_moviename); +#endif + delete m_movieAction; + m_movieAction = nullptr; + m_show_menu = true; +} + #endif void VRVolumeApp::set_render_count(unsigned int rendercount) @@ -265,7 +307,10 @@ void VRVolumeApp::set_threshold(float threshold) void VRVolumeApp::add_label(std::string& text, float x, float y, float z, float textPosZ, float size, int volume) { - m_labels.add(text, x, y, z, textPosZ, size, volume); + if (m_labels) + { + m_labels->add(text, x, y, z, textPosZ, size, volume); + } } void VRVolumeApp::set_description(int descriptionHeight, std::string& descriptionFilename) @@ -522,11 +567,6 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) m_depthTextures.push_back(new DepthTexture); } - int window_w = renderState.index().getValue("WindowWidth"); - int window_h = renderState.index().getValue("WindowHeight"); - int framebuffer_w = renderState.index().getValue("FramebufferWidth"); - int framebuffer_h = renderState.index().getValue("FramebufferHeight"); - //setup projection m_projection_mtrx = glm::make_mat4(renderState.getProjectionMatrix()); //m_projection_mtrx = m_trackball.get_projection_camera(); @@ -534,7 +574,7 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) //overwrite MV for 2D viewing if (m_is2d) - m_model_view = get_trackball_camera().getViewmatrix(); + m_model_view = m_trackball.getViewmatrix(); glMatrixMode(GL_PROJECTION); glLoadMatrixf(glm::value_ptr(m_projection_mtrx)); @@ -552,11 +592,12 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) } //setup Modelview for meshes + glm::mat4 volume_mv; if (m_mesh_model) { int i = 0; if (m_volumes.size() > m_models_volumeID[i]) { - glm::mat4 volume_mv = m_volumes[0][m_models_volumeID[i]]->get_volume_mv(); + volume_mv = m_volumes[0][m_models_volumeID[i]]->get_volume_mv(); volume_mv = glm::translate(volume_mv, glm::vec3(-0.5f, -0.5f, -0.5f * m_volumes[0][m_models_volumeID[i]]->get_volume_scale().x / (m_volumes[0][m_models_volumeID[i]]->get_volume_scale().z))); volume_mv = glm::scale(volume_mv, glm::vec3(m_volumes[0][m_models_volumeID[i]]->get_volume_scale().x, m_volumes[0][m_models_volumeID[i]]->get_volume_scale().y, m_volumes[0][m_models_volumeID[i]]->get_volume_scale().x)); @@ -615,7 +656,11 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) } //render labels - render_labels(renderState); + m_line_shader.start(); + m_line_shader.setUniform("p", m_projection_mtrx); + m_line_shader.setUniform("mv", volume_mv); + render_labels(volume_mv, renderState); + m_line_shader.stop(); /*if (m_ui_view && !m_is2d) { @@ -628,27 +673,36 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) m_depthTextures[m_rendercount]->copyDepthbuffer(); (static_cast (m_renders[1]))->setDepthTexture(m_depthTextures[m_rendercount]); - render_volume(renderState); - - - render_ui(renderState); - - /*if (m_ui_view && m_is2d) - { - m_ui_view->render_2D(); - }*/ + if (m_is2d ) { + m_ui_view->draw_tranfer_funciton_legend(); + } //drawTime - /*if (m_is2d && m_animated) { + if (m_is2d && m_animated) { unsigned int active_volume = floor(m_frame); unsigned int active_volume2 = ceil(m_frame); if (active_volume < m_volumes[0].size() && active_volume2 < m_volumes[0].size() && m_volumes[0][active_volume]->texture_initialized() && m_volumes[0][active_volume2]->texture_initialized()) { float alpha = m_frame - active_volume; time_t time = m_volumes[0][active_volume]->getTime() * (1 - alpha) + m_volumes[0][active_volume2]->getTime() * alpha; - FontHandler::getInstance()->drawClock(time); + m_ui_view->set_volume_time_info(time); } + } + + render_volume(renderState); + + if (m_show_menu) + { + render_ui(renderState); + } + + + /*if (m_ui_view && m_is2d) + { + m_ui_view->render_2D(); }*/ + + glFlush(); m_rendercount++; @@ -661,7 +715,7 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) #endif std::cerr << "Add Frame" << std::endl; m_movieAction->addFrame(); - if (m_frame > m_volumes[m_selectedVolume].size() - 1 - (m_speed * m_animation_speed)) { + /*if (m_frame > m_volumes[m_selectedVolume].size() - 1 - (m_speed * m_animation_speed)) { std::cerr << "Save Movie" << std::endl; #ifdef _MSC_VER m_movieAction->save(m_moviename); @@ -669,19 +723,24 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) delete m_movieAction; m_movieAction = nullptr; m_show_menu = true; - } + }*/ } } -void VRVolumeApp::render_labels(const MinVR::VRGraphicsState& renderState) +void VRVolumeApp::render_labels(glm::mat4& volume_mv, const MinVR::VRGraphicsState& renderState) { //render labels - m_labels.draw(m_models_MV, m_headpose, m_ui_view->get_z_scale()); + if (m_labels) + { + m_labels->drawLabels(volume_mv, m_projection_mtrx, m_headpose, m_ui_view->get_z_scale()); + + } + - if (m_is2d && !m_description.empty()) - FontHandler::getInstance()->renderMultiLineTextBox2D(m_description, 50, 950, 200, m_descriptionHeight); + /*if (m_is2d && !m_description.empty()) + FontHandler::getInstance()->renderMultiLineTextBox2D(m_description, 50, 950, 200, m_descriptionHeight);*/ } void VRVolumeApp::render_mesh(const MinVR::VRGraphicsState& renderState) @@ -774,9 +833,16 @@ void VRVolumeApp::animated_render(int tfn, int vol) //bool useMultitransferFunction = m_ui_view->isUseMultiTransfer(); size_t max_animation_length = 0; + float global_min = std::numeric_limits::max(); + float global_max = std::numeric_limits::min(); + bool dirty = false; if (m_ui_view && m_ui_view->is_transfer_function_enabled(tfn, vol)) { + dirty = true; max_animation_length = std::max(max_animation_length, m_volumes[vol].size()); + global_min = std::min(global_min, m_volumes[vol][active_volume]->getMin()); + global_max = std::max(global_max, m_volumes[vol][active_volume]->getMax()); + if (active_volume < m_volumes[vol].size() && active_volume2 < m_volumes[vol].size() && m_volumes[vol][active_volume]->texture_initialized() && m_volumes[vol][active_volume2]->texture_initialized()) { @@ -808,6 +874,12 @@ void VRVolumeApp::animated_render(int tfn, int vol) } m_ui_view->set_animation_length(max_animation_length); + if (dirty) + { + m_ui_view->set_trns_fnct_min_max(global_min, global_max); + } + + } void VRVolumeApp::render_ui(const MinVR::VRGraphicsState& renderState) @@ -935,7 +1007,11 @@ void VRVolumeApp::clear_data() } m_volumes.clear(); m_description.clear(); - m_labels.clear(); + if (m_labels) + { + m_labels->clear(); + } + m_models_filenames.clear(); m_models_displayLists.clear(); @@ -1125,3 +1201,34 @@ void VRVolumeApp::set_animation_speed(float time) { m_animation_speed = time; } + +Simulation& VRVolumeApp::get_simulation() +{ + return *m_simulation; +} + +void VRVolumeApp::set_clip_min(glm::vec3 clip_min) +{ + m_ui_view->set_clip_min(clip_min); +} + +void VRVolumeApp::set_clip_max(glm::vec3 clip_max) +{ + m_ui_view->set_clip_max(clip_max); +} + +std::string VRVolumeApp::get_movie_state_label() +{ + if (m_current_movie_state == STOP) + { + return "Write Movie"; + } + + return "STOP RECORD"; + +} + +MovieState VRVolumeApp::get_movie_state() +{ + return m_current_movie_state; +} From 1cc9c27f0888faa98432c3edf4d956211b6886f3 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Tue, 19 Apr 2022 19:35:39 -0400 Subject: [PATCH 11/23] add Choreograph to superbuild script --- superbuild/CMakeLists.txt | 46 +++++++++++++++++++--- superbuild/Choreograph/CMakeLists.txt | 17 +++++++++ superbuild/cmake/FindChoreograph.cmake | 30 +++++++++++++++ superbuild/macros.cmake | 53 +++++++++++++++++++++++++- 4 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 superbuild/Choreograph/CMakeLists.txt create mode 100644 superbuild/cmake/FindChoreograph.cmake diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index ee6f631..22cbfb5 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -45,7 +45,7 @@ endif() message("CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}") if(NOT DEBUG_SUFFIX AND CMAKE_BUILD_TYPE MATCHES "Debug") - set(DEBUG_SUFFIX "d") + set(CMAKE_DEBUG_SUFFIX "d") endif() message("DEBUG_SUFFIX ${DEBUG_SUFFIX}") @@ -107,6 +107,40 @@ else() message("====== MINVR IS NOT WIN 32") endif (WIN32) + +#Choreograph +# Configure external project +IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/Choreograph/Choreograph) +execute_process( + COMMAND ${CMAKE_COMMAND} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -DINSTALL_DIR_ABSOLUTE=${INSTALL_DIR_ABSOLUTE} + -DDEFAULT_BUILD_COMMAND=${DEFAULT_BUILD_COMMAND} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + ${CMAKE_SOURCE_DIR}/Choreograph + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Choreograph + ) + + +#Build external project +execute_process( COMMAND ${CMAKE_COMMAND} + --build ${CMAKE_BINARY_DIR}/Choreograph + --config ${CMAKE_BUILD_TYPE} +) + + +ENDIF() + +find_package(Choreograph REQUIRED) +if(Choreograph_FOUND) + message(STATUS "Choreograph found") + message(STATUS "CHOREOGRAPH_INCLUDE_DIR ${CHOREOGRAPH_INCLUDE_DIR}") + message(STATUS "CHOREOGRAPH_LIBRARY ${CHOREOGRAPH_LIBRARY}") +else() + message(STATUS "Choreograph NOT found" ) +endif() + + #MinVR # Configure external project IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/MinVR/MinVR) @@ -399,10 +433,10 @@ if(OpenCV_FOUND) #set(OPENCV_SUFIX "4.5.3" ) endif() - file(COPY "${OPENCV_PATH}/${OPENCV_PREFIX}opencv_videoio${OPENCV_SUFIX}${DEBUG_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin" ) - file(COPY "${OPENCV_PATH}/${OPENCV_PREFIX}opencv_imgcodecs${OPENCV_SUFIX}${DEBUG_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin" ) - file(COPY "${OPENCV_PATH}/${OPENCV_PREFIX}opencv_imgproc${OPENCV_SUFIX}${DEBUG_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin" ) - file(COPY "${OPENCV_PATH}/${OPENCV_PREFIX}opencv_core${OPENCV_SUFIX}${DEBUG_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin" ) + file(COPY "${OPENCV_PATH}/${OPENCV_PREFIX}opencv_videoio${OPENCV_SUFIX}${CMAKE_DEBUG_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin" ) + file(COPY "${OPENCV_PATH}/${OPENCV_PREFIX}opencv_imgcodecs${OPENCV_SUFIX}${CMAKE_DEBUG_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin" ) + file(COPY "${OPENCV_PATH}/${OPENCV_PREFIX}opencv_imgproc${OPENCV_SUFIX}${CMAKE_DEBUG_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin" ) + file(COPY "${OPENCV_PATH}/${OPENCV_PREFIX}opencv_core${OPENCV_SUFIX}${CMAKE_DEBUG_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin" ) endif() @@ -585,6 +619,7 @@ set(header_files ${CPPFS_INCLUDE_DIRS} ${Imgui_INCLUDE_DIR} ${IMGUIVR_INCLUDE_DIR} + ${CHOREOGRAPH_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../libs/ ${CMAKE_CURRENT_SOURCE_DIR}/../include/ ${Model_INCLUDE_DIR} @@ -596,6 +631,7 @@ set(header_files set(LIBRARIES ${OPENGL_LIBRARY} + ${CHOREOGRAPH_LIBRARY} ${OpenCV_LIBS} ${GLM_LIBRARIES} ${GLEW_LIBRARY} diff --git a/superbuild/Choreograph/CMakeLists.txt b/superbuild/Choreograph/CMakeLists.txt new file mode 100644 index 0000000..09ec15f --- /dev/null +++ b/superbuild/Choreograph/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required (VERSION 3.15) +project(Choreograph) +include(ExternalProject) +include(GNUInstallDirs) +include(${CMAKE_SOURCE_DIR}/../macros.cmake) + +message("${CMAKE_PROJECT_NAME} INSTALL_DIR_ABSOLUTE ${INSTALL_DIR_ABSOLUTE}") + +set(EXTERNAL_DIR_LOCATION ${CMAKE_BINARY_DIR}) +set(EXTERNAL_DIR_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/../install/) + +build_choerograph_subproject( + NAME Choreograph + URL https://github.com/brown-ccv/Choreograph.git + BUILD_ARGS + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} +) diff --git a/superbuild/cmake/FindChoreograph.cmake b/superbuild/cmake/FindChoreograph.cmake new file mode 100644 index 0000000..afbd964 --- /dev/null +++ b/superbuild/cmake/FindChoreograph.cmake @@ -0,0 +1,30 @@ +message("FINDChoreograph CMAKE") +message("CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}") +message("CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}") +set(LIBNAME Choreograph${CMAKE_DEBUG_SUFFIX}) + +find_path(CHOREOGRAPH_INCLUDE_DIR + NAMES + Choreograph.h + HINTS + ${CMAKE_INSTALL_PREFIX}/include/Choreograph +) + +message(STATUS "CHOREOGRAPH_INCLUDE_DIR ${CHOREOGRAPH_INCLUDE_DIR}") + + +find_library(CHOREOGRAPH_LIBRARY + NAMES + ${LIBNAME} + HINTS + ${CMAKE_INSTALL_PREFIX}/lib/ +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Choreograph + DEFAULT_MSG + CHOREOGRAPH_INCLUDE_DIR + CHOREOGRAPH_LIBRARY +) + + diff --git a/superbuild/macros.cmake b/superbuild/macros.cmake index 9148320..6db2972 100644 --- a/superbuild/macros.cmake +++ b/superbuild/macros.cmake @@ -33,7 +33,7 @@ macro(build_git_subproject) # Setup SUBPROJECT_* variables (containing paths) for this function setup_subproject_path_vars(${BUILD_SUBPROJECT_NAME}) - + # Build the actual subproject ExternalProject_Add(${SUBPROJECT_NAME} PREFIX ${SUBPROJECT_NAME} @@ -69,6 +69,55 @@ macro(build_git_subproject) append_cmake_prefix_path(${SUBPROJECT_INSTALL_PATH}) endmacro() + +macro(build_choerograph_subproject) + # See cmake_parse_arguments docs to see how args get parsed here: + # https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html + set(oneValueArgs NAME URL ) + set(multiValueArgs BUILD_ARGS DEPENDS_ON) + cmake_parse_arguments(BUILD_SUBPROJECT "" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + # Setup SUBPROJECT_* variables (containing paths) for this function + setup_subproject_path_vars(${BUILD_SUBPROJECT_NAME}) + + # Build the actual subproject + ExternalProject_Add(${SUBPROJECT_NAME} + PREFIX ${SUBPROJECT_NAME} + DOWNLOAD_DIR ${SUBPROJECT_NAME} + STAMP_DIR ${SUBPROJECT_STAMP_PATH} + SOURCE_DIR ${SUBPROJECT_SOURCE_PATH} + BINARY_DIR ${SUBPROJECT_BUILD_PATH} + GIT_REPOSITORY ${BUILD_SUBPROJECT_URL} + GIT_TAG stable + LIST_SEPARATOR | # Use the alternate list separator + CMAKE_ARGS + -S ${CMAKE_CURRENT_SOURCE_DIR}/Choreograph/source/src + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_INSTALL_PREFIX:PATH=${SUBPROJECT_INSTALL_PATH} + -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR} + -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} + -DCMAKE_INSTALL_DOCDIR=${CMAKE_INSTALL_DOCDIR} + -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} + -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + ${BUILD_SUBPROJECT_BUILD_ARGS} + BUILD_COMMAND ${DEFAULT_BUILD_COMMAND} + BUILD_ALWAYS OFF + ) + + if(BUILD_SUBPROJECT_DEPENDS_ON) + ExternalProject_Add_StepDependencies(${SUBPROJECT_NAME} + configure ${BUILD_SUBPROJECT_DEPENDS_ON} + ) + endif() + + # Place installed component on CMAKE_PREFIX_PATH for downstream consumption + append_cmake_prefix_path(${SUBPROJECT_INSTALL_PATH}) +endmacro() + + macro(build_minvr_subproject) # See cmake_parse_arguments docs to see how args get parsed here: # https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html @@ -326,7 +375,7 @@ macro(build_glm_subproject) SOURCE_DIR ${SUBPROJECT_SOURCE_PATH} BINARY_DIR ${SUBPROJECT_BUILD_PATH} GIT_REPOSITORY ${BUILD_SUBPROJECT_URL} - GIT_TAG ${BUILD_SUBPROJECT_TAG} + GIT_TAG ${BUILD_SUBPROJECT_TAG} LIST_SEPARATOR | # Use the alternate list separator CMAKE_ARGS From ddc0572fb246e87078709cde4fdb0cdec61dc8d0 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Tue, 19 Apr 2022 22:41:17 -0400 Subject: [PATCH 12/23] add slice and camera animation. fix animation ui. fix memory leak on close window --- Resources/Models/plane.obj | 14 + Resources/Models/plane2.obj | 14 + Resources/Models/plane3.obj | 17 + include/UI/UIView.h | 14 +- include/interaction/ArcBallCamera.h | 99 +- include/interaction/PointOfInterests.h | 43 + include/interaction/Simulation.h | 95 ++ include/loader/VRDataLoader.h | 12 +- include/render/VolumeRenderer.h | 1 - include/vrapp/VRVolumeApp.h | 15 +- include/vrapp/VolumeVisualizationApp.h | 5 - shaders/shader.frag | 6 +- src/UI/UIView.cpp | 1414 +++++++++++++----------- src/interaction/ArcBallCamera.cpp | 332 ++---- src/interaction/Simulation.cpp | 189 ++++ src/loader/VRDataLoader.cpp | 31 +- src/vrapp/VRVolumeApp.cpp | 53 +- src/vrapp/VolumeVisualizationApp.cpp | 16 +- superbuild/CMakeLists.txt | 3 + 19 files changed, 1342 insertions(+), 1031 deletions(-) create mode 100644 Resources/Models/plane.obj create mode 100644 Resources/Models/plane2.obj create mode 100644 Resources/Models/plane3.obj create mode 100644 include/interaction/PointOfInterests.h create mode 100644 include/interaction/Simulation.h create mode 100644 src/interaction/Simulation.cpp diff --git a/Resources/Models/plane.obj b/Resources/Models/plane.obj new file mode 100644 index 0000000..3ed0e51 --- /dev/null +++ b/Resources/Models/plane.obj @@ -0,0 +1,14 @@ +# Blender v2.82 (sub 7) OBJ File: '' +# www.blender.org +v -1.000000 0.000000 1.000000 +v 1.000000 0.000000 1.000000 +v -1.000000 0.000000 -1.000000 +v 1.000000 0.000000 -1.000000 +vt 0.000000 0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vt 1.000000 0.000000 +vn 0.0000 1.0000 0.0000 +s off +f 2/1/1 3/2/1 1/3/1 +f 2/1/1 4/4/1 3/2/1 diff --git a/Resources/Models/plane2.obj b/Resources/Models/plane2.obj new file mode 100644 index 0000000..3ed0e51 --- /dev/null +++ b/Resources/Models/plane2.obj @@ -0,0 +1,14 @@ +# Blender v2.82 (sub 7) OBJ File: '' +# www.blender.org +v -1.000000 0.000000 1.000000 +v 1.000000 0.000000 1.000000 +v -1.000000 0.000000 -1.000000 +v 1.000000 0.000000 -1.000000 +vt 0.000000 0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vt 1.000000 0.000000 +vn 0.0000 1.0000 0.0000 +s off +f 2/1/1 3/2/1 1/3/1 +f 2/1/1 4/4/1 3/2/1 diff --git a/Resources/Models/plane3.obj b/Resources/Models/plane3.obj new file mode 100644 index 0000000..67d154a --- /dev/null +++ b/Resources/Models/plane3.obj @@ -0,0 +1,17 @@ +# Blender v2.82 (sub 7) OBJ File: '' +# www.blender.org +mtllib plane3.mtl +o plane +v 1.000000 1.000000 0.000000 +v -1.000000 -1.000000 0.000000 +v -1.000000 1.000000 0.000000 +v 1.000000 -1.000000 0.000000 +vt 0.000000 0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vt 1.000000 0.000000 +vn 0.0000 0.0000 -1.0000 +usemtl Default_OBJ +s 1 +f 1/1/1 2/2/1 3/3/1 +f 1/1/1 4/4/1 2/2/1 diff --git a/include/UI/UIView.h b/include/UI/UIView.h index c1dfe0e..3e3f910 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -132,6 +132,10 @@ class UIView void set_trns_fnct_min_max(float min, float max); + bool get_show_movie_saved_pop_up() const { return m_show_movie_saved_pop_up; } + + void set_show_movie_saved_pop_up(bool val) { m_show_movie_saved_pop_up = val; } + private: struct MyTransFerFunctions @@ -154,7 +158,7 @@ class UIView void load_user_session(std::string filePath); - void save_camera_poi(std::ofstream& loadPath, int num_poi); + void save_simulation_states(std::ofstream& loadPath, int num_poi); void load_camera_poi(std::ifstream& loadPath, int num_poi); @@ -180,6 +184,7 @@ class UIView float m_scale; int m_slices; bool m_dynamic_slices; + bool m_show_menu; bool m_renderVolume; @@ -281,6 +286,13 @@ class UIView std::string m_day_info; std::string months[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; + + + int m_simulation_state_selection; + bool m_time_frame_edited; + + bool m_show_movie_saved_pop_up; + }; diff --git a/include/interaction/ArcBallCamera.h b/include/interaction/ArcBallCamera.h index 4b3d2c7..20059a4 100644 --- a/include/interaction/ArcBallCamera.h +++ b/include/interaction/ArcBallCamera.h @@ -31,7 +31,7 @@ #include #include -#include "choreograph/Choreograph.h" +#include "PointOfInterests.h" enum WASD_KEYS { @@ -43,38 +43,33 @@ enum WASD_KEYS E = 1 << 5, // binary 100000 }; -struct PointOfInterest { - - - glm::vec3 eye = glm::vec3(0.0f, 0.0f, 1.0f); - glm::vec3 target = glm::vec3(0.0f, 0.0f, 0.0f); - glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); - float radius = 1.f; - glm::vec3 max_clip; - glm::vec3 min_clip; +//struct PointOfInterest { +// +// +// glm::vec3 eye = glm::vec3(0.0f, 0.0f, 1.0f); +// glm::vec3 target = glm::vec3(0.0f, 0.0f, 0.0f); +// glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); +// float radius = 1.f; +// glm::vec3 max_clip; +// glm::vec3 min_clip; +// +// std::string label; +// +// glm::vec3 get_camera_position() +// { +// eye = glm::normalize(eye); +// return radius * eye + target; +// } +// +//}; - std::string label; - glm::vec3 get_camera_position() - { - eye = glm::normalize(eye); - return radius * eye + target; - } - -}; - -enum CAMERA_ANIMATION_STATE -{ - STOP, - PLAYING, - PAUSE -}; /** Adds a HeadMatrix to the RenderState that gets updated repeatedly based upon head tracking events. */ -class VRVolumeApp; + class ArcBallCamera { public: @@ -94,51 +89,33 @@ class ArcBallCamera { return m_viewmatrix; } - std::list& get_camera_poi(); - - void add_camera_poi(std::string & label, glm::vec3& clip_max, glm::vec3& clip_min); - void add_camera_poi(std::string& label, float eye_x, float eye_y, float eye_z, - float target_x, float target_y, float target_z, - float up_x, float up_y, float up_z, float radius); + void updateCameraMatrix(); - int get_current_poi(); + void update_sim_poi(PointOfInterest& poi); - void set_current_poi(int val); + + PointOfInterest& get_current_poi(); - void remove_poi(int val); + void set_current_poi(const PointOfInterest& poi); void reset_camera(); - PointOfInterest& get_poi_at(int val); - - void update_animation(); - - void set_animation_path(); - - void set_animation_state(); - - CAMERA_ANIMATION_STATE get_animation_state(); - - std::string get_camera_animation_state(); - - float get_camera_animation_duration(); - void set_camera_animation_duration(float duration); - - void set_controller_application(VRVolumeApp* vr_app); + void set_app_mode(unsigned int mode); protected: void Rotate(float dTheta, float dPhi); void RotateEyeAxis(float dy); void Zoom(float distance); void Pan(float dx, float dy); - void updateCameraMatrix(); + float m_radius; glm::vec3 m_target; glm::vec3 m_up; glm::vec3 m_eye; - std::list m_camera_poi; + PointOfInterest m_current_poi; + PointOfInterest m_simulation_poi; glm::mat4 m_viewmatrix; bool m_mouse_left_pressed; @@ -150,21 +127,13 @@ class ArcBallCamera { float m_cameraScrollFactor; bool m_rotate_camera_center; - ch::Output m_target_animation; - ch::Output m_eye_animation; - ch::Output m_up_animation; - ch::Output m_radius_animation; - ch::Output m_clip_max_animation; - ch::Output m_clip_min_animation; - ch::Timeline m_timeline; - - bool m_is_animate_path; - float m_animation_duration; - CAMERA_ANIMATION_STATE m_camera_animation_state; + std::string animation_button_label; - VRVolumeApp* m_controller_app; + + + unsigned int m_aap_mode; }; #endif diff --git a/include/interaction/PointOfInterests.h b/include/interaction/PointOfInterests.h new file mode 100644 index 0000000..b76abd4 --- /dev/null +++ b/include/interaction/PointOfInterests.h @@ -0,0 +1,43 @@ +#ifndef PointOfInterest_H +#define PointOfInterest_H + +#include +#include + +class PointOfInterest { + +public : + + PointOfInterest():eye(glm::vec3(0.0f, 0.0f, 1.0f)), target(glm::vec3(0.0f, 0.0f, 0.0f)), up(glm::vec3(0.0f, 1.0f, 0.0f)), radius(1.f) + { + } + + PointOfInterest(glm::vec3 p_eye, glm::vec3 p_target, glm::vec3 p_up, float p_radius):eye(p_eye),target(p_target),up(p_up),radius(p_radius) + { + + } + + PointOfInterest(const PointOfInterest& other) + { + eye = other.eye; + radius = other.radius; + target =other.target; + up = other.up; + }; + + glm::vec3 get_camera_position() + { + eye = (glm::normalize(eye)); + return radius * eye + target; + } + + glm::vec3 eye; + glm::vec3 target; + glm::vec3 up; + float radius; + std::string label; + + +}; + +#endif \ No newline at end of file diff --git a/include/interaction/Simulation.h b/include/interaction/Simulation.h new file mode 100644 index 0000000..70c7de5 --- /dev/null +++ b/include/interaction/Simulation.h @@ -0,0 +1,95 @@ +#ifndef ANIMATOR_H +#define ANIMATOR_H + +#include "choreograph/Choreograph.h" + +#include + +#include "PointOfInterests.h" + + + +enum ANIMATION_STATE +{ + STOP, + PLAYING, + PAUSE +}; + +struct SimulationState +{ + SimulationState() {}; + + SimulationState(const SimulationState& other) + { + poi = other.poi; + max_clip = other.max_clip; + min_clip = other.min_clip; + } + + std::string time_label; + PointOfInterest poi; + glm::vec3 max_clip; + glm::vec3 min_clip; +}; + +class VRVolumeApp; + +class Simulation +{ +public: + Simulation(VRVolumeApp& controller_app,float time = 10.0f); + + void add_simulation_state(SimulationState& simulationState); + + void create_animations(); + void update_simulation(); + + void set_animation_state(); + + ANIMATION_STATE get_animation_state(); + std::string get_camera_animation_state(); + float get_camera_animation_duration(); + void set_camera_animation_duration(float duration); + + const std::list& get_simulation_states(); + + SimulationState& get_simulation_state_at(unsigned int index); + + SimulationState get_current_simulation_state(); + + void remove_simulation_state(unsigned int index); + + float get_animation_duration(); + +private: + + void update_time_step(); + + ch::Timeline m_timeline; + float m_animation_duration; + + std::list m_simulation_states; + + std::vector> m_vec3_sequences; + std::vector> m_float_sequences; + + ch::Output m_target_animation; + ch::Output m_eye_animation; + ch::Output m_up_animation; + ch::Output m_radius_animation; + ch::Output m_max_clip_animation; + ch::Output m_min_clip_animation; + + bool m_is_animate_path; + + + ANIMATION_STATE m_animation_state; + std::string animation_button_label; + + VRVolumeApp& m_controller_app; + + +}; + +#endif \ No newline at end of file diff --git a/include/loader/VRDataLoader.h b/include/loader/VRDataLoader.h index ae48bf5..ee1d664 100644 --- a/include/loader/VRDataLoader.h +++ b/include/loader/VRDataLoader.h @@ -4,20 +4,20 @@ #include class VRVolumeApp; + class VRDataLoader { public: + VRDataLoader(); + + static void load_txt_file( VRVolumeApp& vrVolumeApp, std::string& filename); - static VRDataLoader* get_instance(); - - static void load_txt_file(VRVolumeApp& vrVolumeApp, std::string& filename); + private: - VRDataLoader(); - - static VRDataLoader* m_instance; + }; #endif diff --git a/include/render/VolumeRenderer.h b/include/render/VolumeRenderer.h index 1dda794..2ea3f1f 100644 --- a/include/render/VolumeRenderer.h +++ b/include/render/VolumeRenderer.h @@ -31,7 +31,6 @@ #include "FrameBufferObject.h" #include "Volume.h" -#include "choreograph/Choreograph.h" class VolumeRenderer { diff --git a/include/vrapp/VRVolumeApp.h b/include/vrapp/VRVolumeApp.h index fc4a598..48d2681 100644 --- a/include/vrapp/VRVolumeApp.h +++ b/include/vrapp/VRVolumeApp.h @@ -30,11 +30,20 @@ enum MovieState MOVIE_RECORD }; +enum APPMODE +{ + MANUAL, + SIMULATION +}; + class VRVolumeApp { public: VRVolumeApp(); + + + ~VRVolumeApp(); @@ -178,6 +187,8 @@ class VRVolumeApp MovieState get_movie_state(); + void set_app_mode(APPMODE ); + protected: glm::vec4 m_noColor;// (0.0f, 0.0f, 0.0f, 0.0f); @@ -280,7 +291,7 @@ class VRVolumeApp bool m_use_multi_transfer; bool m_show_menu; - + bool m_end_load; /*Input Events*/ @@ -306,5 +317,7 @@ class VRVolumeApp MovieState m_current_movie_state; bool m_stop_movie; + APPMODE m_app_mode; + }; #endif diff --git a/include/vrapp/VolumeVisualizationApp.h b/include/vrapp/VolumeVisualizationApp.h index 4f02280..2ff658f 100644 --- a/include/vrapp/VolumeVisualizationApp.h +++ b/include/vrapp/VolumeVisualizationApp.h @@ -51,7 +51,6 @@ using namespace MinVR; #include "../render/VolumeSliceRenderer.h" #include "../interaction/CreateMovieAction.h" -#include "choreograph/Choreograph.h" #include "ShaderProgram.h" @@ -119,10 +118,6 @@ class VolumeVisualizationApp : public VRApp { const double fps_Limit = 1.0 / 60.0; std::chrono::steady_clock::time_point last_Update_Time ; // number of seconds since the last loop - ch::Timeline _timeline; - ch::Output target = 0.0f; - ch::Output _control_a = 0; - ch::Output _control_b ; float v1 = 0.0f; float v2 = 100.0f; diff --git a/shaders/shader.frag b/shaders/shader.frag index 1d2a8e3..0fe6b91 100644 --- a/shaders/shader.frag +++ b/shaders/shader.frag @@ -11,6 +11,10 @@ uniform sampler2D myTextureSampler; void main() { - fragColor = vec4(texture( myTextureSampler, TexCoord ).rgb,1); + fragColor = vec4(texture( myTextureSampler, TexCoord )); + if(fragColor.a < 0.1) + { + discard; + } } \ No newline at end of file diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index d35f601..ec710fa 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -12,14 +12,14 @@ #include "UIHelpers/stb_image.h" #include "common/common.h" - +#include "../include/interaction/Simulation.h" #include #include #include - +#include UIView::UIView(VRVolumeApp& controllerApp) :m_controller_app(controllerApp), m_multiplier(1.0f), m_threshold(0.0f), m_z_scale(0.16f), m_scale{ 1.0f }, m_slices(256), m_dynamic_slices(false), m_renderVolume(true), m_selectedTrnFnc(0), @@ -31,8 +31,8 @@ m_current_load_modal(LOAD_NONE), m_file_extension_filter(".txt"), m_non_trns_fun m_ui_background(false), m_column_selection_state(0), m_compute_new_histogram(true), m_histogram_point_1(0.0), m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0), m_camera_name_window_open(false), m_camera_button_action(BUTTON_ACTION::NONE), m_num_animation_frames(0), m_animation_speed(1.0f), -m_camera_animation_duration_open(false), m_show_clock(true), m_clock_width(250), m_clock_height(200), -m_time_info(""),m_day_info("") +m_camera_animation_duration_open(false), m_show_clock(false), m_clock_width(250), m_clock_height(200), +m_time_info(""),m_day_info(""), m_time_frame_edited(false), m_show_movie_saved_pop_up(false) { m_ocean_color_maps_names = { "algae.png","amp.png","balance.png","curl.png","deep.png","delta.png","dense.png", "diff.png","gray.png","haline.png","ice.png","matter.png","oxy.png","phase.png","rain.png","solar.png","speed.png","tarn.png","tempo.png", @@ -54,431 +54,625 @@ void UIView::draw_ui_callback() return; } - - m_ui_background = m_menu_handler->windowIsActive() ? true : false; + if (m_controller_app.is_show_menu()) + { + m_ui_background = m_menu_handler->windowIsActive() ? true : false; - int flags = ImGuiWindowFlags_NoResize; - if (!m_ui_background) - { - flags |= ImGuiWindowFlags_NoBackground; - } - ImGui::SetNextWindowSize(ImVec2(544, 798)); - ImGui::Begin("Volumeviewer", NULL, flags); - ImGui::BeginTabBar("##tabs"); - if (ImGui::BeginTabItem("General")) - { - if (ImGui::Button("load file", ImVec2(ImGui::GetWindowSize().x * 0.5f - 1.5 * ImGui::GetStyle().ItemSpacing.x, 0.0f))) + int flags = ImGuiWindowFlags_NoResize; + if (!m_ui_background) { - m_file_dialog_open = true; - m_file_extension_filter = ".txt"; + flags |= ImGuiWindowFlags_NoBackground; } - - ImGui::SameLine(); - if (ImGui::Button("Clear all", ImVec2(ImGui::GetWindowSize().x * 0.5f - 1.5 * ImGui::GetStyle().ItemSpacing.x, 0.0f))) + ImGui::SetNextWindowSize(ImVec2(544, 798)); + ImGui::Begin("Volumeviewer", NULL, flags); + ImGui::BeginTabBar("##tabs"); + if (ImGui::BeginTabItem("General")) { - m_controller_app.clear_data(); - } + if (ImGui::Button("load file", ImVec2(ImGui::GetWindowSize().x * 0.5f - 1.5 * ImGui::GetStyle().ItemSpacing.x, 0.0f))) + { + m_file_dialog_open = true; + m_file_extension_filter = ".txt"; + } + + ImGui::SameLine(); + if (ImGui::Button("Clear all", ImVec2(ImGui::GetWindowSize().x * 0.5f - 1.5 * ImGui::GetStyle().ItemSpacing.x, 0.0f))) + { + m_controller_app.clear_data(); + } - ImGui::SliderFloat("alpha multiplier", &m_multiplier, 0.0f, 1.0f, "%.3f"); - ImGui::SliderFloat("threshold", &m_threshold, 0.0f, 1.0f, "%.3f"); - ImGui::SliderFloat("scale", &m_scale, 0.001f, 5.0f, "%.3f"); - ImGui::SliderFloat("z - scale", &m_z_scale, 0.001f, 5.0f, "%.3f"); - ImGui::SliderInt("Slices", &m_slices, 10, 1024, "%d"); - ImGui::Checkbox("automatic slice adjustment", &m_dynamic_slices); + ImGui::SliderFloat("alpha multiplier", &m_multiplier, 0.0f, 1.0f, "%.3f"); + ImGui::SliderFloat("threshold", &m_threshold, 0.0f, 1.0f, "%.3f"); + ImGui::SliderFloat("scale", &m_scale, 0.001f, 5.0f, "%.3f"); + ImGui::SliderFloat("z - scale", &m_z_scale, 0.001f, 5.0f, "%.3f"); + ImGui::SliderInt("Slices", &m_slices, 10, 1024, "%d"); + ImGui::Checkbox("automatic slice adjustment", &m_dynamic_slices); + ImGui::Checkbox("Show Clock", &m_show_clock); - ImGui::SameLine(ImGui::GetWindowSize().x * 0.5f, 0); - ImGui::Text("FPS = %f", m_controller_app.get_fps()); - const char* items[] = { "sliced" , "raycast" }; - ImGui::Combo("RenderMethod", &m_rendermethod, items, IM_ARRAYSIZE(items)); + ImGui::SameLine(ImGui::GetWindowSize().x * 0.5f, 0); + ImGui::Text("FPS = %f", m_controller_app.get_fps()); + const char* items[] = { "sliced" , "raycast" }; + ImGui::Combo("RenderMethod", &m_rendermethod, items, IM_ARRAYSIZE(items)); - const char* items_channel[] = { "based on data" , "red", "green" , "blue", "alpha", "rgba", "rgba with alpha as max rgb" }; - ImGui::Combo("Render Channel", &m_renderchannel, items_channel, IM_ARRAYSIZE(items_channel)); + const char* items_channel[] = { "based on data" , "red", "green" , "blue", "alpha", "rgba", "rgba with alpha as max rgb" }; + ImGui::Combo("Render Channel", &m_renderchannel, items_channel, IM_ARRAYSIZE(items_channel)); - ImGui::Checkbox("Render Volume data", &m_renderVolume); + ImGui::Checkbox("Render Volume data", &m_renderVolume); - int numVolumes = m_controller_app.get_num_volumes(); + int numVolumes = m_controller_app.get_num_volumes(); - if (numVolumes > 0) { - if (ImGui::SmallButton("Save Session")) { - m_save_session_dialog_open = true; + if (numVolumes > 0) { + if (ImGui::SmallButton("Save Session")) { + m_save_session_dialog_open = true; + } + ImGui::SameLine(); } - ImGui::SameLine(); - } - if (ImGui::SmallButton("Load Session")) { - m_file_load_trnsf = true; - m_current_load_modal = LOAD_MODAL::LOAD_SESSION; - m_file_extension_filter = ".usr"; - } + if (ImGui::SmallButton("Load Session")) { + m_file_load_trnsf = true; + m_current_load_modal = LOAD_MODAL::LOAD_SESSION; + m_file_extension_filter = ".usr"; + } - if (numVolumes > 0) - { - if (ImGui::SmallButton("Add Function")) { - tfn_widget.push_back(TransferFunctionWidget()); - tfn_widget_multi.push_back(TransferFunctionMultiChannelWidget()); - int index = m_selected_volume_TrFn.size(); - m_selected_volume_TrFn.push_back(std::vector(numVolumes)); - for (int i = 0; i < numVolumes; i++) - { - m_selected_volume_TrFn[index][i] = false; - } + if (numVolumes > 0) + { + if (ImGui::SmallButton("Add Function")) { + tfn_widget.push_back(TransferFunctionWidget()); + tfn_widget_multi.push_back(TransferFunctionMultiChannelWidget()); + int index = m_selected_volume_TrFn.size(); + m_selected_volume_TrFn.push_back(std::vector(numVolumes)); + for (int i = 0; i < numVolumes; i++) + { + m_selected_volume_TrFn[index][i] = false; + } - addTransferFunction(); - if (m_tfns.size() == 1) - { - m_trnfnc_table_selection = 0; - } + addTransferFunction(); + if (m_tfns.size() == 1) + { + m_trnfnc_table_selection = 0; + } - }; - ImGui::SameLine(); - if (ImGui::SmallButton("Remove Function")) { + }; + ImGui::SameLine(); + if (ImGui::SmallButton("Remove Function")) { - if (m_tfns.size() == 1) - { - //there should be one by default + if (m_tfns.size() == 1) + { + //there should be one by default + tfn_widget.clear(); + tfn_widget_multi.clear(); + m_tfns.clear(); + tfn_widget.push_back(TransferFunctionWidget()); + tfn_widget_multi.push_back(TransferFunctionMultiChannelWidget()); + addTransferFunction(); + m_trnfnc_table_selection = 0; + } + else if (m_tfns.size() > 1 && m_trnfnc_table_selection >= 0) + { + tfn_widget.erase(tfn_widget.begin() + m_trnfnc_table_selection); ; + tfn_widget_multi.erase(tfn_widget_multi.begin() + m_trnfnc_table_selection); + m_tfns.erase(m_tfns.begin() + m_trnfnc_table_selection); + if (m_trnfnc_table_selection != 0) + { + m_trnfnc_table_selection = m_trnfnc_table_selection - 1; + } + + } + }; + + + + if (ImGui::SmallButton("Clear All Functions")) { tfn_widget.clear(); tfn_widget_multi.clear(); m_tfns.clear(); tfn_widget.push_back(TransferFunctionWidget()); tfn_widget_multi.push_back(TransferFunctionMultiChannelWidget()); - addTransferFunction(); - m_trnfnc_table_selection = 0; - } - else if (m_tfns.size() > 1 && m_trnfnc_table_selection >= 0) - { - tfn_widget.erase(tfn_widget.begin() + m_trnfnc_table_selection); ; - tfn_widget_multi.erase(tfn_widget_multi.begin() + m_trnfnc_table_selection); - m_tfns.erase(m_tfns.begin() + m_trnfnc_table_selection); - if (m_trnfnc_table_selection != 0) + MyTransFerFunctions trfntc; + char label[32]; + sprintf(label, "TF%d", (int)tfn_widget.size()); + trfntc.ID = tfn_widget.size(); + trfntc.Name = label; + for (int i = 0; i < numVolumes; i++) { - m_trnfnc_table_selection = m_trnfnc_table_selection - 1; + trfntc.volumes.push_back(false); } + m_tfns.push_back(trfntc); + m_trnfnc_table_selection = 0; + }; - } - }; - - - - if (ImGui::SmallButton("Clear All Functions")) { - tfn_widget.clear(); - tfn_widget_multi.clear(); - m_tfns.clear(); - tfn_widget.push_back(TransferFunctionWidget()); - tfn_widget_multi.push_back(TransferFunctionMultiChannelWidget()); - MyTransFerFunctions trfntc; - char label[32]; - sprintf(label, "TF%d", (int)tfn_widget.size()); - trfntc.ID = tfn_widget.size(); - trfntc.Name = label; - for (int i = 0; i < numVolumes; i++) - { - trfntc.volumes.push_back(false); - } - m_tfns.push_back(trfntc); - m_trnfnc_table_selection = 0; - }; + ImGui::SameLine(); + if (ImGui::SmallButton("Save Functions")) { + m_save_trnfct_open = true; + m_non_trns_functions_selected_modal = !m_use_transferfunction; + }; - ImGui::SameLine(); - if (ImGui::SmallButton("Save Functions")) { - m_save_trnfct_open = true; - m_non_trns_functions_selected_modal = !m_use_transferfunction; - }; + ImGui::SameLine(); + if (ImGui::SmallButton("Load Functions")) { - ImGui::SameLine(); - if (ImGui::SmallButton("Load Functions")) { + m_file_load_trnsf = true; + m_current_load_modal = LOAD_MODAL::LOAD_TRFR_FNC; + m_file_extension_filter = ".fnc"; + }; - m_file_load_trnsf = true; - m_current_load_modal = LOAD_MODAL::LOAD_TRFR_FNC; - m_file_extension_filter = ".fnc"; - }; + int selection = 0; - int selection = 0; + ImGui::BeginTable("##Transfer Function Editor", numVolumes + 1, ImGuiTableFlags_Borders); + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 120.0f); - ImGui::BeginTable("##Transfer Function Editor", numVolumes + 1, ImGuiTableFlags_Borders); - ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 120.0f); + for (int column = 0; column < numVolumes; column++) + { + ImGui::TableSetupColumn(m_dataLabels[column].c_str()); + } + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + for (int column = 1; column < numVolumes + 1; column++) + { + ImGui::TableSetColumnIndex(column); + const char* column_name = ImGui::TableGetColumnName(column); + ImGui::PushID(column); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + ImGui::Checkbox("##checkall", &m_column_selected[column - 1]); ImGui::SameLine(); + ImGui::PopStyleVar(); + ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); + ImGui::TableHeader(column_name); + ImGui::PopID(); - for (int column = 0; column < numVolumes; column++) - { - ImGui::TableSetupColumn(m_dataLabels[column].c_str()); - } - ImGui::TableNextRow(ImGuiTableRowFlags_Headers); - for (int column = 1; column < numVolumes + 1; column++) - { - ImGui::TableSetColumnIndex(column); - const char* column_name = ImGui::TableGetColumnName(column); - ImGui::PushID(column); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - ImGui::Checkbox("##checkall", &m_column_selected[column - 1]); ImGui::SameLine(); - ImGui::PopStyleVar(); - ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); - ImGui::TableHeader(column_name); - ImGui::PopID(); + } - } + compute_new_histogram_view(); - compute_new_histogram_view(); + /* check state of check boxes */ + int colum_select_check_sum = 0; + for (int column_select = 1; column_select <= numVolumes; column_select++) + { - /* check state of check boxes */ - int colum_select_check_sum = 0; - for (int column_select = 1; column_select <= numVolumes; column_select++) - { + if (m_column_selected[column_select - 1]) + { + colum_select_check_sum |= column_select; + } + } - if (m_column_selected[column_select - 1]) + if (colum_select_check_sum != m_column_selection_state) { - colum_select_check_sum |= column_select; + m_compute_new_histogram = true; + m_column_selection_state = colum_select_check_sum; } - } - - if (colum_select_check_sum != m_column_selection_state) - { - m_compute_new_histogram = true; - m_column_selection_state = colum_select_check_sum; - } - else - { - m_compute_new_histogram = false; - } - - for (int row = 0; row < m_tfns.size(); row++) - { - ImGui::TableNextRow(); - for (int col = 0; col < numVolumes + 1; col++) + else { - ImGui::TableSetColumnIndex(col); + m_compute_new_histogram = false; + } - if (col == 0) + for (int row = 0; row < m_tfns.size(); row++) + { + ImGui::TableNextRow(); + for (int col = 0; col < numVolumes + 1; col++) { + ImGui::TableSetColumnIndex(col); - ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_AllowDoubleClick; - bool item_is_selected = (row == m_trnfnc_table_selection) ? true : false; - if (ImGui::Selectable(m_tfns[row].Name.c_str(), item_is_selected, selectable_flags)) + if (col == 0) { - m_trnfnc_table_selection = row; - if (ImGui::IsMouseDoubleClicked(0)) + + ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_AllowDoubleClick; + bool item_is_selected = (row == m_trnfnc_table_selection) ? true : false; + if (ImGui::Selectable(m_tfns[row].Name.c_str(), item_is_selected, selectable_flags)) { - m_copy_trnfnct_name = m_tfns[m_trnfnc_table_selection].Name; - float q_min = 0; - float q_max = 0; - tfn_widget[m_trnfnc_table_selection].get_Quantiles(q_min, q_max); - m_histogram_quantiles[0] = q_min; - m_histogram_quantiles[1] = q_max; - m_trn_fct_options_window = true; + m_trnfnc_table_selection = row; + if (ImGui::IsMouseDoubleClicked(0)) + { + m_copy_trnfnct_name = m_tfns[m_trnfnc_table_selection].Name; + float q_min = 0; + float q_max = 0; + tfn_widget[m_trnfnc_table_selection].get_Quantiles(q_min, q_max); + m_histogram_quantiles[0] = q_min; + m_histogram_quantiles[1] = q_max; + m_trn_fct_options_window = true; + } + + } } + else + { + char buf[32]; + sprintf(buf, "##On%d%d", col, row); + bool b = m_tfns[row].volumes[col - 1]; + ImGui::Checkbox(buf, &b); + m_tfns[row].volumes[col - 1] = b; + } } - else - { - char buf[32]; - sprintf(buf, "##On%d%d", col, row); - bool b = m_tfns[row].volumes[col - 1]; - ImGui::Checkbox(buf, &b); - m_tfns[row].volumes[col - 1] = b; - - } - } - } - ImGui::EndTable(); - if (m_save_session_dialog_open) - { - m_current_save_modal = SAVE_SESSION; - std::string save_user_session_window_id = "Save User Session"; - - std::string extension = ".usr"; - auto save_funtion = std::bind(&UIView::save_user_session, this, std::placeholders::_1); - open_save_modal_dialog(save_user_session_window_id, m_save_session_dialog_open, save_funtion, extension); + ImGui::EndTable(); + if (m_save_session_dialog_open) + { + m_current_save_modal = SAVE_SESSION; + std::string save_user_session_window_id = "Save User Session"; - } + std::string extension = ".usr"; + auto save_funtion = std::bind(&UIView::save_user_session, this, std::placeholders::_1); + open_save_modal_dialog(save_user_session_window_id, m_save_session_dialog_open, save_funtion, extension); - if (m_save_trnfct_open) - { - m_current_save_modal = SAVE_TRFR_FNC; - std::string save_Trnf_window_id = "Save Transfer Functions"; - if (m_use_transferfunction) - { - std::string extension = ".fnc"; - auto save_funtion = std::bind(&UIView::save_trans_functions, this, std::placeholders::_1); - open_save_modal_dialog(save_Trnf_window_id, m_save_trnfct_open, save_funtion, extension); } - else + + if (m_save_trnfct_open) { - ImGui::OpenPopup("No Functions Selected"); - ImGui::SetNextWindowSize(ImVec2(150, 70), ImGuiCond_FirstUseEver); - if (ImGui::BeginPopupModal("No Functions Selected", &m_non_trns_functions_selected_modal)) + m_current_save_modal = SAVE_TRFR_FNC; + std::string save_Trnf_window_id = "Save Transfer Functions"; + if (m_use_transferfunction) + { + std::string extension = ".fnc"; + auto save_funtion = std::bind(&UIView::save_trans_functions, this, std::placeholders::_1); + open_save_modal_dialog(save_Trnf_window_id, m_save_trnfct_open, save_funtion, extension); + } + else { - ImGui::Text("Transfer functions are not enabled."); - ImGui::Text("Please, check the 'Use Transfer function' option."); - if (ImGui::Button("Close")) + ImGui::OpenPopup("No Functions Selected"); + ImGui::SetNextWindowSize(ImVec2(150, 70), ImGuiCond_FirstUseEver); + if (ImGui::BeginPopupModal("No Functions Selected", &m_non_trns_functions_selected_modal)) { - m_non_trns_functions_selected_modal = false; - m_save_trnfct_open = false; - ImGui::CloseCurrentPopup(); + ImGui::Text("Transfer functions are not enabled."); + ImGui::Text("Please, check the 'Use Transfer function' option."); + if (ImGui::Button("Close")) + { + m_non_trns_functions_selected_modal = false; + m_save_trnfct_open = false; + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); } - ImGui::EndPopup(); } - } - } + } - if (m_trn_fct_options_window) - { - ImGui::OpenPopup("Transfer Function Options"); - ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); - if (ImGui::BeginPopupModal("Transfer Function Options", &m_trn_fct_options_window)) + if (m_trn_fct_options_window) { - ImGui::Text("Change Name"); - ImGui::InputText("##text1", &m_copy_trnfnct_name); - ImGui::IsItemActive(); + ImGui::OpenPopup("Transfer Function Options"); + ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); + if (ImGui::BeginPopupModal("Transfer Function Options", &m_trn_fct_options_window)) + { + ImGui::Text("Change Name"); + ImGui::InputText("##text1", &m_copy_trnfnct_name); + ImGui::IsItemActive(); - ImGui::Separator(); + ImGui::Separator(); - ImGui::Text("Quantiles"); - ImGui::SliderFloat2("##Quantiles", m_histogram_quantiles, 0.05f, 0.95f); + ImGui::Text("Quantiles"); + ImGui::SliderFloat2("##Quantiles", m_histogram_quantiles, 0.05f, 0.95f); - if (ImGui::Button("Adjust to Histogram")) - { - adjust_transfer_function_to_histogram(); - tfn_widget[m_trnfnc_table_selection].alpha_control_pts.clear(); - tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(vec2f(0.0, 0.0)); - tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(m_histogram_point_1); - tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(m_histogram_point_2); - tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(vec2f(1.0, 1.0)); - tfn_widget[m_trnfnc_table_selection].set_Quantiles(m_histogram_quantiles[0], m_histogram_quantiles[1]); - ImGui::OpenPopup("Confirmation"); - ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); - } + if (ImGui::Button("Adjust to Histogram")) + { + adjust_transfer_function_to_histogram(); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.clear(); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(vec2f(0.0, 0.0)); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(m_histogram_point_1); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(m_histogram_point_2); + tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(vec2f(1.0, 1.0)); + tfn_widget[m_trnfnc_table_selection].set_Quantiles(m_histogram_quantiles[0], m_histogram_quantiles[1]); + ImGui::OpenPopup("Confirmation"); + ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); + } - bool unused_open = true; - if (ImGui::BeginPopupModal("Confirmation", &unused_open)) - { - ImGui::Text("Change Applied"); - if (ImGui::Button("Close")) + bool unused_open = true; + if (ImGui::BeginPopupModal("Confirmation", &unused_open)) { - ImGui::CloseCurrentPopup(); + ImGui::Text("Change Applied"); + if (ImGui::Button("Close")) + { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); } - ImGui::EndPopup(); - } - if (ImGui::Button("Ok")) - { - m_tfns[m_trnfnc_table_selection].Name = m_copy_trnfnct_name; - m_trn_fct_options_window = false; - m_current_save_modal = SAVE_MODAL::SAVE_NONE; - ImGui::CloseCurrentPopup(); - } - ImGui::SameLine(); - if (ImGui::Button("Cancel")) - { - m_trn_fct_options_window = false; - m_current_save_modal = SAVE_MODAL::SAVE_NONE; - ImGui::CloseCurrentPopup(); - } + if (ImGui::Button("Ok")) + { + m_tfns[m_trnfnc_table_selection].Name = m_copy_trnfnct_name; + m_trn_fct_options_window = false; + m_current_save_modal = SAVE_MODAL::SAVE_NONE; + ImGui::CloseCurrentPopup(); + } + ImGui::SameLine(); + if (ImGui::Button("Cancel")) + { + m_trn_fct_options_window = false; + m_current_save_modal = SAVE_MODAL::SAVE_NONE; + ImGui::CloseCurrentPopup(); + } - ImGui::EndPopup(); + ImGui::EndPopup(); + } } - } - ImGui::Checkbox("use transferfunction", &m_use_transferfunction); - if (m_use_transferfunction) - { + ImGui::Checkbox("use transferfunction", &m_use_transferfunction); + if (m_use_transferfunction) + { - bool is_multi_channel = m_controller_app.data_is_multi_channel(); - if (is_multi_channel) - { - for (int i = 0; i < 3; i++) { + bool is_multi_channel = m_controller_app.data_is_multi_channel(); + if (is_multi_channel) + { + for (int i = 0; i < 3; i++) { + if (m_animated) + { + /* + frame by frame animation + + unsigned int active_volume = floor(m_frame); + unsigned int active_volume2 = ceil(m_frame); + double alpha = m_frame - active_volume; + if (active_volume < m_volumes[m_selectedVolume].size() && active_volume2 < m_volumes[m_selectedVolume].size()) + { + tfn_widget_multi[m_selectedVolume].setBlendedHistogram( + m_volumes[m_selectedVolume][active_volume]->getTransferfunction(i), + m_volumes[m_selectedVolume][active_volume2]->getTransferfunction(i), alpha, i); + }*/ + + } + else { + /* tfn_widget_multi[m_selectedVolume].setHistogram(m_volumes[m_selectedVolume][0]->getTransferfunction(i), i);*/ + } + } + m_controller_app.set_multi_transfer(true); + //tfn_widget_multi[m_selectedTrnFnc].draw_histogram(); + tfn_widget_multi[m_trnfnc_table_selection].draw_ui(); + } + else + { if (m_animated) { /* - frame by frame animation + frame by frame animation - unsigned int active_volume = floor(m_frame); + unsigned int active_volume = floor(m_frame); unsigned int active_volume2 = ceil(m_frame); double alpha = m_frame - active_volume; + tfn_widget[m_selectedVolume].setMinMax(m_volumes[m_selectedVolume][active_volume]->getMin() * alpha + m_volumes[m_selectedVolume][active_volume2]->getMin() * (1.0 - alpha), + m_volumes[m_selectedVolume][active_volume]->getMax() * alpha + m_volumes[m_selectedVolume][active_volume2]->getMax() * (1.0 - alpha)); if (active_volume < m_volumes[m_selectedVolume].size() && active_volume2 < m_volumes[m_selectedVolume].size()) - { - tfn_widget_multi[m_selectedVolume].setBlendedHistogram( - m_volumes[m_selectedVolume][active_volume]->getTransferfunction(i), - m_volumes[m_selectedVolume][active_volume2]->getTransferfunction(i), alpha, i); - }*/ + tfn_widget[m_selectedVolume].setBlendedHistogram(m_volumes[m_selectedVolume][active_volume]->getTransferfunction(0), m_volumes[m_selectedVolume][active_volume2]->getTransferfunction(0), alpha);*/ } - else { - /* tfn_widget_multi[m_selectedVolume].setHistogram(m_volumes[m_selectedVolume][0]->getTransferfunction(i), i);*/ - } + + m_controller_app.set_multi_transfer(false); + + m_histogram.draw_histogram(); + tfn_widget[m_trnfnc_table_selection].draw_ui(); + //tfn_widget[m_trnfnc_table_selection].setMinMax() + } + } + + + } + + + if (m_animated) { + ImGui::Text("Timestep"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(-100 - ImGui::GetStyle().ItemSpacing.x); + float frame_tmp = m_controller_app.get_current_frame() + 1; + //controls animated multi datasets + ImGui::SliderFloat("##Timestep", &frame_tmp, 1, m_num_animation_frames); + m_ui_frame_controller = (frame_tmp)-1; + m_controller_app.set_frame(m_ui_frame_controller); + + + std::string text = m_stopped ? "Play" : "Stop"; + if (ImGui::Button(text.c_str(), ImVec2(50, 0))) { + m_stopped = !m_stopped; + } + ImGui::SameLine(); + int value = int(m_animation_speed * 100.0 + .5); + std::string speed_text = ">>X " + std::to_string(value / 100); + if (ImGui::Button(speed_text.c_str(), ImVec2(80, 0))) { + m_animation_speed += 0.5; + if (m_animation_speed > 4.0f) + { + m_animation_speed = 1.0f; + } + m_controller_app.set_animation_speed(m_animation_speed); + } + +#if (!defined(__APPLE__)) + std::string movie_button_label = m_controller_app.get_movie_state_label(); + if (movie_button_label == "Write Movie") + { + if (ImGui::Button(movie_button_label.c_str())) + { + m_controller_app.run_movie(false); } - m_controller_app.set_multi_transfer(true); - //tfn_widget_multi[m_selectedTrnFnc].draw_histogram(); - tfn_widget_multi[m_trnfnc_table_selection].draw_ui(); } else { - if (m_animated) + if (ImGui::Button(movie_button_label.c_str())) { - /* - frame by frame animation - - unsigned int active_volume = floor(m_frame); - unsigned int active_volume2 = ceil(m_frame); - double alpha = m_frame - active_volume; - tfn_widget[m_selectedVolume].setMinMax(m_volumes[m_selectedVolume][active_volume]->getMin() * alpha + m_volumes[m_selectedVolume][active_volume2]->getMin() * (1.0 - alpha), - m_volumes[m_selectedVolume][active_volume]->getMax() * alpha + m_volumes[m_selectedVolume][active_volume2]->getMax() * (1.0 - alpha)); - if (active_volume < m_volumes[m_selectedVolume].size() && active_volume2 < m_volumes[m_selectedVolume].size()) - tfn_widget[m_selectedVolume].setBlendedHistogram(m_volumes[m_selectedVolume][active_volume]->getTransferfunction(0), m_volumes[m_selectedVolume][active_volume2]->getTransferfunction(0), alpha);*/ - + m_controller_app.stop_movie(); } + } - m_controller_app.set_multi_transfer(false); +#endif + } + ImGui::EndTabItem(); + } - m_histogram.draw_histogram(); - tfn_widget[m_trnfnc_table_selection].draw_ui(); - //tfn_widget[m_trnfnc_table_selection].setMinMax() - } + if (ImGui::BeginTabItem("Clipping")) + { + ImGui::Text("Axis aligned clip"); + glm::vec2 bound = { m_clip_min.x * 100 ,m_clip_max.x * 100 }; + ImGui::DragFloatRange2("X", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + m_clip_min.x = bound.x / 100; + m_clip_max.x = bound.y / 100; + + bound = { m_clip_min.y * 100 ,m_clip_max.y * 100 }; + ImGui::DragFloatRange2("Y", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + m_clip_min.y = bound.x / 100; + m_clip_max.y = bound.y / 100; + + bound = { m_clip_min.z * 100 ,m_clip_max.z * 100 }; + ImGui::DragFloatRange2("Z", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + m_clip_min.z = bound.x / 100; + m_clip_max.z = bound.y / 100; + + if (ImGui::Button("Reset")) { + m_clip_min = glm::vec3(0.0f); + m_clip_max = glm::vec3(1.0f); } + ImGui::Checkbox("Custom Clipping plane", &m_useCustomClipPlane); + if (m_useCustomClipPlane) { + ImGui::SliderAngle("Pitch", &m_clip_ypr.y, -90, 90); + ImGui::SliderAngle("Roll", &m_clip_ypr.z, -180, 180); + + ImGui::SliderFloat("Position X", &m_clip_pos.x, -0.5, 0.5); + ImGui::SliderFloat("Position y", &m_clip_pos.y, -0.5, 0.5); + ImGui::SliderFloat("Position z", &m_clip_pos.z, -0.5, 0.5); + if (ImGui::Button("Reset##Reset2")) { + m_clip_ypr = glm::vec3(0.0f); + m_clip_pos = glm::vec3(0.0f); + } + } + ImGui::EndTabItem(); } + if (ImGui::BeginTabItem("Animation")) + { + + ImGui::Text("Time Frames"); + + if (ImGui::Button("Add")) { + m_camera_name_window_open = true; + m_camera_button_action = BUTTON_ACTION::ADD; - if (m_animated) { - ImGui::Text("Timestep"); + } ImGui::SameLine(); - ImGui::SetNextItemWidth(-100 - ImGui::GetStyle().ItemSpacing.x); - float frame_tmp = m_controller_app.get_current_frame() + 1; - //controls animated multi datasets - ImGui::SliderFloat("##Timestep", &frame_tmp, 1, m_num_animation_frames); - m_ui_frame_controller = (frame_tmp) - 1; - m_controller_app.set_frame(m_ui_frame_controller); - - - std::string text = m_stopped ? "Play" : "Stop"; - if (ImGui::Button(text.c_str(), ImVec2(50, 0))) { - m_stopped = !m_stopped; + if (ImGui::Button("Remove")) { + if (m_controller_app.get_simulation().get_simulation_states().size() > 0) + { + m_controller_app.get_simulation().remove_simulation_state(m_simulation_state_selection); + if (m_simulation_state_selection - 1 < 0) + { + m_simulation_state_selection = 0; + } + else + { + m_simulation_state_selection--; + SimulationState next_sim_state = m_controller_app.get_simulation().get_simulation_state_at(m_simulation_state_selection); + m_controller_app.get_trackball_camera().set_current_poi(next_sim_state.poi); + } + + + } + } ImGui::SameLine(); - int value = int(m_animation_speed * 100.0 + .5); - std::string speed_text = ">>X "+std::to_string(value/100); - if (ImGui::Button(speed_text.c_str(), ImVec2(80, 0))) { - m_animation_speed += 0.5; - if (m_animation_speed > 4.0f) + if (ImGui::Button("Reset Camera")) { + m_controller_app.get_trackball_camera().reset_camera(); + } + ImGui::BeginTable("##Camera Point of interest (POI) Editor", 1, ImGuiTableFlags_Borders); + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 120.0f); + + + for (int row = 0; row < m_controller_app.get_simulation().get_simulation_states().size(); ++row) + { + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + bool item_is_selected = (row == m_simulation_state_selection) ? true : false; + SimulationState sim_state = m_controller_app.get_simulation().get_simulation_state_at(row); + if (ImGui::Selectable(sim_state.poi.label.c_str(), item_is_selected, ImGuiSelectableFlags_AllowDoubleClick)) { - m_animation_speed = 1.0f; + m_simulation_state_selection = row; + m_controller_app.get_trackball_camera().set_current_poi(sim_state.poi); + m_clip_min = sim_state.min_clip; + m_clip_max = sim_state.max_clip; + if (ImGui::IsMouseDoubleClicked(0)) + { + m_copy_camera_name = sim_state.poi.label; + m_camera_name_window_open = true; + m_camera_button_action = BUTTON_ACTION::EDIT; + } + } + } + ImGui::EndTable(); + + if (m_controller_app.get_simulation().get_simulation_states().size() > 0) + { + SimulationState& sim_state = m_controller_app.get_simulation().get_simulation_state_at(m_simulation_state_selection); + std::string edit_text = "Edit Time Frame " + sim_state.poi.label; + ImGui::Text(edit_text.c_str()); + + ImGui::Text("Axis aligned clip"); + glm::vec2 bound = { m_clip_min.x * 100 ,m_clip_max.x * 100 }; + ImGui::DragFloatRange2("X", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + m_clip_min.x = bound.x / 100; + m_clip_max.x = bound.y / 100; + + ImGui::SameLine(); + if (ImGui::Button("Reset##XAXIS")) { + m_clip_min.x = 0.0f; + m_clip_max.x = 1.0f; + } + + bound = { m_clip_min.y * 100 ,m_clip_max.y * 100 }; + ImGui::DragFloatRange2("Y", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + m_clip_min.y = bound.x / 100; + m_clip_max.y = bound.y / 100; + ImGui::SameLine(); + if (ImGui::Button("Reset##YAXIS")) { + m_clip_min.y = 0.0f; + m_clip_max.y = 1.0f; } - m_controller_app.set_animation_speed(m_animation_speed); + + bound = { m_clip_min.z * 100 ,m_clip_max.z * 100 }; + ImGui::DragFloatRange2("Z", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + m_clip_min.z = bound.x / 100; + m_clip_max.z = bound.y / 100; + ImGui::SameLine(); + if (ImGui::Button("Reset##ZAXIS")) { + m_clip_min.z = 0.0f; + m_clip_max.z = 1.0f; + } + + if (ImGui::Button("Save Changes##EDITTIMEFRAME")) { + sim_state.min_clip = m_clip_min; + sim_state.max_clip = m_clip_max; + sim_state.poi = m_controller_app.get_trackball_camera().get_current_poi(); + m_time_frame_edited = true; + } + + + } + + //Simulation animator + std::string is_animation_playing = m_controller_app.get_simulation().get_camera_animation_state(); + + if (ImGui::Button(is_animation_playing.c_str())) { + + m_controller_app.get_simulation().set_animation_state(); + + } + + ImGui::Text("Duration (seconds)"); + + + std::stringstream text; + text << std::fixed << std::setprecision(1) << m_controller_app.get_simulation().get_animation_duration(); + std::string str_animation_duration = text.str(); + + if (ImGui::Button(str_animation_duration.c_str())) + { + m_camera_animation_duration_open = true; + m_str_animation_duration = std::string(str_animation_duration); } #if (!defined(__APPLE__)) @@ -487,7 +681,8 @@ void UIView::draw_ui_callback() { if (ImGui::Button(movie_button_label.c_str())) { - m_controller_app.run_movie(false); + m_controller_app.get_simulation().set_animation_state(); + m_controller_app.run_movie(true); } } else @@ -497,394 +692,267 @@ void UIView::draw_ui_callback() m_controller_app.stop_movie(); } } - #endif - } - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("Clipping")) - { - ImGui::Text("Axis aligned clip"); - glm::vec2 bound = { m_clip_min.x * 100 ,m_clip_max.x * 100 }; - ImGui::DragFloatRange2("X", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); - m_clip_min.x = bound.x / 100; - m_clip_max.x = bound.y / 100; - - bound = { m_clip_min.y * 100 ,m_clip_max.y * 100 }; - ImGui::DragFloatRange2("Y", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); - m_clip_min.y = bound.x / 100; - m_clip_max.y = bound.y / 100; - - bound = { m_clip_min.z * 100 ,m_clip_max.z * 100 }; - ImGui::DragFloatRange2("Z", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); - m_clip_min.z = bound.x / 100; - m_clip_max.z = bound.y / 100; - - if (ImGui::Button("Reset")) { - m_clip_min = glm::vec3(0.0f); - m_clip_max = glm::vec3(1.0f); + ImGui::EndTabItem(); } - ImGui::Checkbox("Custom Clipping plane", &m_useCustomClipPlane); - if (m_useCustomClipPlane) { - ImGui::SliderAngle("Pitch", &m_clip_ypr.y, -90, 90); - ImGui::SliderAngle("Roll", &m_clip_ypr.z, -180, 180); - - ImGui::SliderFloat("Position X", &m_clip_pos.x, -0.5, 0.5); - ImGui::SliderFloat("Position y", &m_clip_pos.y, -0.5, 0.5); - ImGui::SliderFloat("Position z", &m_clip_pos.z, -0.5, 0.5); - if (ImGui::Button("Reset##Reset2")) { - m_clip_ypr = glm::vec3(0.0f); - m_clip_pos = glm::vec3(0.0f); + + ImGui::EndTabBar(); + + if (m_time_frame_edited) + { + ImGui::OpenPopup("Time frame Changed##successchange"); + ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); + if (ImGui::BeginPopupModal("Time frame Changed##successchange", &m_time_frame_edited)) + { + ImGui::Text("Changes saved"); + if (ImGui::Button("Ok")) + { + m_time_frame_edited = false; + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); } } - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("Camera")) - { - - ImGui::Text("Points of Interest"); + if (m_camera_name_window_open) + { + std::string modal_window_name; - if (ImGui::Button("Add")) { - m_camera_name_window_open = true; - m_camera_button_action = BUTTON_ACTION::ADD; + switch (m_camera_button_action) + { + case ADD: + modal_window_name = "Add Simulation State"; + break; + case EDIT: + modal_window_name = "Edit Simulation Name"; + break; + default: + break; + } - } - ImGui::SameLine(); - if (ImGui::Button("Remove")) { - if (m_controller_app.get_trackball_camera().get_camera_poi().size() > 0) + ImGui::OpenPopup(modal_window_name.c_str()); + ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); + if (ImGui::BeginPopupModal(modal_window_name.c_str(), &m_camera_name_window_open)) { - m_controller_app.get_trackball_camera().remove_poi(m_camera_poi_table_selection); - if (m_camera_poi_table_selection - 1 < 0) + + ImGui::Text("Camera Name"); + ImGui::InputText("##textcameraname", &m_copy_camera_name); + if (ImGui::Button("Ok")) { - m_camera_poi_table_selection = 0; + + if (m_camera_button_action == ADD) + { + SimulationState sim_state; + sim_state.poi = m_controller_app.get_trackball_camera().get_current_poi(); + sim_state.poi.label = m_copy_camera_name; + sim_state.max_clip = m_clip_max; + sim_state.min_clip = m_clip_min; + m_controller_app.get_simulation().add_simulation_state(sim_state); + + m_copy_camera_name.clear(); + m_simulation_state_selection = m_controller_app.get_simulation().get_simulation_states().size() - 1; + } + else if (m_camera_button_action == EDIT) + { + m_controller_app.get_simulation().get_simulation_state_at(m_camera_poi_table_selection).poi.label = m_copy_camera_name; + } + m_camera_name_window_open = false; + ImGui::CloseCurrentPopup(); } - else + ImGui::SameLine(); + if (ImGui::Button("Cancel")) { - m_camera_poi_table_selection--; - m_controller_app.get_trackball_camera().set_current_poi(m_camera_poi_table_selection); + m_camera_name_window_open = false; + m_copy_camera_name.clear(); + ImGui::CloseCurrentPopup(); } - - + ImGui::EndPopup(); } } - ImGui::SameLine(); - if (ImGui::Button("Reset")) { - m_controller_app.get_trackball_camera().reset_camera(); - } - ImGui::BeginTable("##Camera Point of interest (POI) Editor", 1, ImGuiTableFlags_Borders); - ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 120.0f); - - for (int row = 0; row < m_controller_app.get_trackball_camera().get_camera_poi().size(); ++row) + if (m_camera_animation_duration_open) { - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - bool item_is_selected = (row == m_camera_poi_table_selection) ? true : false; - if (ImGui::Selectable(m_controller_app.get_trackball_camera().get_poi_at(row).label.c_str(), item_is_selected, ImGuiSelectableFlags_AllowDoubleClick)) + ImGui::OpenPopup("Animation Time"); + ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); + if (ImGui::BeginPopupModal("Animation Time", &m_camera_animation_duration_open)) { - m_camera_poi_table_selection = row; - m_controller_app.get_trackball_camera().set_current_poi(m_camera_poi_table_selection); - if (ImGui::IsMouseDoubleClicked(0)) + ImGui::Text("Camera Name"); + ImGui::InputText("##textanimationtime", &m_str_animation_duration, ImGuiInputTextFlags_CharsDecimal); + if (ImGui::Button("Ok")) + { + m_controller_app.get_simulation().set_camera_animation_duration(std::stof(m_str_animation_duration)); + m_str_animation_duration.clear(); + m_camera_animation_duration_open = false; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Cancel")) { - m_copy_camera_name = m_controller_app.get_trackball_camera().get_poi_at(m_camera_poi_table_selection).label; - m_camera_name_window_open = true; - m_camera_button_action = BUTTON_ACTION::EDIT; + m_camera_animation_duration_open = false; + m_str_animation_duration.clear(); + ImGui::CloseCurrentPopup(); } + ImGui::EndPopup(); } } - ImGui::EndTable(); - - //Camera animator - std::string is_animation_playing = m_controller_app.get_trackball_camera().get_camera_animation_state(); - - if (ImGui::Button(is_animation_playing.c_str())) { - - m_controller_app.get_trackball_camera().set_animation_state(); - - } - ImGui::Text("Duration (seconds)"); - - - std::stringstream text; - text << std::fixed << std::setprecision(1) << m_controller_app.get_trackball_camera().get_camera_animation_duration(); - std::string str_animation_duration = text.str(); - if (ImGui::Button(str_animation_duration.c_str())) + //file loading + if (m_file_dialog_open) { - m_camera_animation_duration_open = true; - m_str_animation_duration= std::string( str_animation_duration); + ImGui::OpenPopup("Open File"); + m_file_dialog_open = false; } -#if (!defined(__APPLE__)) - std::string movie_button_label = m_controller_app.get_movie_state_label(); - if (movie_button_label == "Write Movie") - { - if (ImGui::Button(movie_button_label.c_str())) - { - m_controller_app.get_trackball_camera().set_animation_state(); - m_controller_app.run_movie(true); - } - } - else - { - if (ImGui::Button(movie_button_label.c_str())) - { - m_controller_app.stop_movie(); - } - } -#endif - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("Animation")) - { - std::string is_animation_playing = m_controller_app.get_trackball_camera().get_camera_animation_state(); - if (ImGui::Button(is_animation_playing.c_str())) { + if (fileDialog.showFileDialog("Open File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 310), m_file_extension_filter)) + { - m_controller_app.get_trackball_camera().set_animation_state(); + if (helper::ends_with_string(fileDialog.selected_fn, ".txt")) + { + //VRDataLoader* insta = VRDataLoader::get_instance(); + //std::thread t1 ( &VRDataLoader::load_txt_file, std::ref(m_controller_app), fileDialog.selected_path); + //t1.join(); + //std:thread t1([=] {VRDataLoader::load_txt_file(m_controller_app, fileDialog.selected_path); }); + VRDataLoader::load_txt_file(m_controller_app, fileDialog.selected_path); + // m_controller_app.load_txt_file(fileDialog.GetSelected().string()); + } +#ifdef WITH_TEEM + else if (helper::ends_with_string(fileDialog.selected_fn, ".nrrd")) { + std::vector vals; + /* vals.push_back(fileDialog.GetSelected().string()); + promises.push_back(new std::promise); + futures.push_back(promises.back()->get_future()); + threads.push_back(new std::thread(&VolumeVisualizationApp::loadVolume, this, vals, promises.back()));*/ + } +#endif } - ImGui::Text("Duration (seconds)"); - std::stringstream text; - text << std::fixed << std::setprecision(1) << m_controller_app.get_trackball_camera().get_camera_animation_duration(); - std::string str_animation_duration = text.str(); - if (ImGui::Button(str_animation_duration.c_str())) - { - m_camera_animation_duration_open = true; - m_str_animation_duration = std::string(str_animation_duration); - } -#if (!defined(__APPLE__)) - if (ImGui::Button("Write Movie")) + if (m_file_dialog_save_dir) { - m_controller_app.get_trackball_camera().set_animation_state(); - m_controller_app.run_movie(true); - } -#endif - - ImGui::EndTabItem(); - } - - ImGui::EndTabBar(); - - - float width = 11.0f; - ImGui::SetNextWindowPos(ImVec2(m_clock_pos_x, m_clock_pos_y)); - ImGui::SetNextWindowSize(ImVec2(m_clock_width, m_clock_height)); - ImGui::Begin("##clock", &m_show_clock, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); - ImGui::SetWindowFontScale(1.3f); - ImGui::Text(m_time_info.c_str()); - ImGui::Text(m_day_info.c_str()); - ImGui::End(); + ImGui::OpenPopup("Save File"); + m_file_dialog_save_dir = false; + switch (m_current_save_modal) + { + case SAVE_SESSION: + m_save_session_dialog_open = false; + break; + case SAVE_TRFR_FNC: + m_save_trnfct_open = false; + break; + default: + break; + } - if (m_use_transferfunction) - { - tfn_widget[0].drawLegend(0, m_legend_pos_y + 80, m_clock_width + 50, m_clock_height - 140); - } - + } - if (m_camera_name_window_open) - { - std::string modal_window_name; + if (m_file_load_trnsf) + { + ImGui::OpenPopup("Load File"); + m_file_load_trnsf = false; - switch (m_camera_button_action) + } + if (saveDialogLoadTrnsFnc.showFileDialog("Save File", imgui_addons::ImGuiFileBrowser::DialogMode::SELECT, + ImVec2(700, 310))) { - case ADD: - modal_window_name = "Add Camera"; - break; - case EDIT: - modal_window_name = "Edit Camera"; - break; - default: - break; + m_dir_to_save = saveDialogLoadTrnsFnc.selected_path; + switch (m_current_save_modal) + { + case SAVE_SESSION: + m_save_session_dialog_open = true; + break; + case SAVE_TRFR_FNC: + m_save_trnfct_open = true; + break; + default: + break; + } + } - ImGui::OpenPopup(modal_window_name.c_str()); - ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); - if (ImGui::BeginPopupModal(modal_window_name.c_str(), &m_camera_name_window_open)) + + if (fileDialogLoadTrnsFnc.showFileDialog("Load File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, + ImVec2(700, 310), m_file_extension_filter)) { - ImGui::Text("Camera Name"); - ImGui::InputText("##textcameraname", &m_copy_camera_name); - if (ImGui::Button("Ok")) + if (m_current_load_modal == LOAD_MODAL::LOAD_TRFR_FNC) { - - if (m_camera_button_action == ADD) + if (helper::ends_with_string(fileDialogLoadTrnsFnc.selected_fn, ".fnc")) { - m_controller_app.get_trackball_camera().add_camera_poi(m_copy_camera_name, m_clip_max,m_clip_min); - m_copy_camera_name.clear(); - m_camera_poi_table_selection = m_controller_app.get_trackball_camera().get_camera_poi().size()-1; - } - else if (m_camera_button_action == EDIT) - { - m_controller_app.get_trackball_camera().get_poi_at(m_camera_poi_table_selection).label = m_copy_camera_name; + tfn_widget.clear(); + tfn_widget_multi.clear(); + m_tfns.clear(); + std::string filePath = fileDialogLoadTrnsFnc.selected_path; + std::ifstream fileToLoad(filePath); + load_trans_functions(fileToLoad); + m_trnfnc_table_selection = 0; + m_current_load_modal = LOAD_NONE; } - m_camera_name_window_open = false; - ImGui::CloseCurrentPopup(); } - ImGui::SameLine(); - if (ImGui::Button("Cancel")) + if (m_current_load_modal == LOAD_MODAL::LOAD_SESSION) { - m_camera_name_window_open = false; - m_copy_camera_name.clear(); - ImGui::CloseCurrentPopup(); + if (helper::ends_with_string(fileDialogLoadTrnsFnc.selected_fn, ".usr")) + { + + tfn_widget.clear(); + tfn_widget_multi.clear(); + m_tfns.clear(); + load_user_session(fileDialogLoadTrnsFnc.selected_path); + m_trnfnc_table_selection = 0; + m_current_load_modal = LOAD_NONE; + } } - ImGui::EndPopup(); } + ImGui::End(); + } - if (m_camera_animation_duration_open) + if (m_show_movie_saved_pop_up) { - ImGui::OpenPopup("Animation Time"); + ImGui::OpenPopup("Movie saved##POPUP"); ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); - if (ImGui::BeginPopupModal("Animation Time", &m_camera_animation_duration_open)) + if (ImGui::BeginPopupModal("Movie saved##POPUP", &m_show_movie_saved_pop_up)) { - ImGui::Text("Camera Name"); - ImGui::InputText("##textanimationtime", &m_str_animation_duration, ImGuiInputTextFlags_CharsDecimal); + ImGui::Text("Movie saved"); if (ImGui::Button("Ok")) { - m_controller_app.get_trackball_camera().set_camera_animation_duration(std::stof(m_str_animation_duration)); - m_str_animation_duration.clear(); - m_camera_animation_duration_open = false; - ImGui::CloseCurrentPopup(); - } - if (ImGui::Button("Cancel")) - { - m_camera_animation_duration_open = false; - m_str_animation_duration.clear(); + m_show_movie_saved_pop_up = false; ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); } } - - //file loading - if (m_file_dialog_open) - { - ImGui::OpenPopup("Open File"); - m_file_dialog_open = false; - } - - - - - if (fileDialog.showFileDialog("Open File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 310), m_file_extension_filter)) + if (m_show_clock) { - - if (helper::ends_with_string(fileDialog.selected_fn, ".txt")) - { - VRDataLoader::get_instance()->load_txt_file(m_controller_app, fileDialog.selected_path); - - // m_controller_app.load_txt_file(fileDialog.GetSelected().string()); - } -#ifdef WITH_TEEM - else if (helper::ends_with_string(fileDialog.selected_fn, ".nrrd")) { - std::vector vals; - /* vals.push_back(fileDialog.GetSelected().string()); - promises.push_back(new std::promise); - futures.push_back(promises.back()->get_future()); - threads.push_back(new std::thread(&VolumeVisualizationApp::loadVolume, this, vals, promises.back()));*/ - } -#endif + ImGui::SetNextWindowPos(ImVec2(m_clock_pos_x, m_clock_pos_y)); + ImGui::SetNextWindowSize(ImVec2(m_clock_width, m_clock_height)); + ImGui::Begin("##clock", &m_show_clock, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); + ImGui::SetWindowFontScale(1.3f); + ImGui::Text(m_time_info.c_str()); + ImGui::Text(m_day_info.c_str()); + ImGui::End(); } + - - - - if (m_file_dialog_save_dir) - { - ImGui::OpenPopup("Save File"); - m_file_dialog_save_dir = false; - switch (m_current_save_modal) - { - case SAVE_SESSION: - m_save_session_dialog_open = false; - break; - case SAVE_TRFR_FNC: - m_save_trnfct_open = false; - break; - default: - break; - } - - - } - - if (m_file_load_trnsf) - { - ImGui::OpenPopup("Load File"); - m_file_load_trnsf = false; - - } - if (saveDialogLoadTrnsFnc.showFileDialog("Save File", imgui_addons::ImGuiFileBrowser::DialogMode::SELECT, - ImVec2(700, 310))) - { - m_dir_to_save = saveDialogLoadTrnsFnc.selected_path; - switch (m_current_save_modal) - { - case SAVE_SESSION: - m_save_session_dialog_open = true; - break; - case SAVE_TRFR_FNC: - m_save_trnfct_open = true; - break; - default: - break; - } - - } - - - if (fileDialogLoadTrnsFnc.showFileDialog("Load File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, - ImVec2(700, 310), m_file_extension_filter)) + if (m_use_transferfunction) { - - if (m_current_load_modal == LOAD_MODAL::LOAD_TRFR_FNC) - { - if (helper::ends_with_string(fileDialogLoadTrnsFnc.selected_fn, ".fnc")) - { - - tfn_widget.clear(); - tfn_widget_multi.clear(); - m_tfns.clear(); - std::string filePath = fileDialogLoadTrnsFnc.selected_path; - std::ifstream fileToLoad(filePath); - load_trans_functions(fileToLoad); - m_trnfnc_table_selection = 0; - m_current_load_modal = LOAD_NONE; - } - } - if (m_current_load_modal == LOAD_MODAL::LOAD_SESSION) - { - if (helper::ends_with_string(fileDialogLoadTrnsFnc.selected_fn, ".usr")) - { - - tfn_widget.clear(); - tfn_widget_multi.clear(); - m_tfns.clear(); - load_user_session(fileDialogLoadTrnsFnc.selected_path); - m_trnfnc_table_selection = 0; - m_current_load_modal = LOAD_NONE; - } - } + tfn_widget[0].drawLegend(0, m_legend_pos_y + 80, m_clock_width + 50, m_clock_height - 140); } - - ImGui::End(); + + } void UIView::init_ui(bool is2D, bool lookingGlass) @@ -959,10 +1027,7 @@ void UIView::update_ui(int numVolumes) void UIView::render_2D(Window_Properties& window_properties) { - - if (m_show_menu) - { - + m_clock_pos_x = window_properties.window_w - m_clock_width; m_clock_pos_y = window_properties.window_h - m_clock_height; m_legend_pos_y = window_properties.window_h - m_clock_height; @@ -971,10 +1036,6 @@ void UIView::render_2D(Window_Properties& window_properties) m_menu_handler->drawMenu(window_properties.window_w, window_properties.window_h, window_properties.framebuffer_w, window_properties.framebuffer_h); - if (m_use_transferfunction) { - tfn_widget[m_selectedTrnFnc].drawLegend(); - } - } } @@ -984,8 +1045,7 @@ void UIView::render_3D(glm::mat4& space_matrix, Window_Properties& window_proper if (m_show_menu) { - // glMatrixMode(GL_MODELVIEW); - // glLoadMatrixf(glm::value_ptr(space_matrix)); + m_menu_handler->drawMenu(window_properties.window_w, window_properties.window_h, window_properties.framebuffer_w, window_properties.framebuffer_h); } @@ -1379,11 +1439,11 @@ void UIView::save_user_session(std::ofstream& savefile) savefile << "ClipZmax " << std::to_string(m_clip_max.z) << "\n"; savefile << "Use_transferfunction " << std::to_string(m_use_transferfunction) << "\n"; - int num_camera_poi = m_controller_app.get_trackball_camera().get_camera_poi().size(); + int num_camera_poi = m_controller_app.get_simulation().get_simulation_states().size(); if (num_camera_poi > 0) { - savefile << "POI " << num_camera_poi << "\n"; - save_camera_poi(savefile, num_camera_poi); + savefile << "SIM " << num_camera_poi << "\n"; + save_simulation_states(savefile, num_camera_poi); } if (m_use_transferfunction) @@ -1506,7 +1566,7 @@ void UIView::load_user_session(std::string filePath) if (tag == "volume_loaded") { std::string fileToLoad = vals[1]; - VRDataLoader::get_instance()->load_txt_file(m_controller_app, fileToLoad); + VRDataLoader::load_txt_file(m_controller_app, fileToLoad); } else if (tag == "alpha_multiplier") { @@ -1568,19 +1628,22 @@ void UIView::load_user_session(std::string filePath) } } -void UIView::save_camera_poi(std::ofstream& saveFile, int num_camera_poi) +void UIView::save_simulation_states(std::ofstream& saveFile, int num_camera_poi) { if (saveFile.is_open()) { - auto poit_iterator = m_controller_app.get_trackball_camera().get_camera_poi().begin(); - for (poit_iterator; poit_iterator != m_controller_app.get_trackball_camera().get_camera_poi().end(); poit_iterator++) + auto sim_iterator = m_controller_app.get_simulation().get_simulation_states().begin(); + for (sim_iterator; sim_iterator != m_controller_app.get_simulation().get_simulation_states().end(); sim_iterator++) { - saveFile << poit_iterator->label << " " - << std::to_string(poit_iterator->eye.x) + " " + std::to_string(poit_iterator->eye.y) + " " + std::to_string(poit_iterator->eye.z) + " " - << std::to_string(poit_iterator->target.x) + " " + std::to_string(poit_iterator->target.y) + " " + std::to_string(poit_iterator->target.z) + " " - << std::to_string(poit_iterator->up.x) + " " + std::to_string(poit_iterator->up.y) + " " + std::to_string(poit_iterator->up.z) + " " - << std::to_string(poit_iterator->radius) + "\n"; + saveFile << sim_iterator->poi.label << " " + << std::to_string(sim_iterator->poi.eye.x) + " " + std::to_string(sim_iterator->poi.eye.y) + " " + std::to_string(sim_iterator->poi.eye.z) + " " + << std::to_string(sim_iterator->poi.target.x) + " " + std::to_string(sim_iterator->poi.target.y) + " " + std::to_string(sim_iterator->poi.target.z) + " " + << std::to_string(sim_iterator->poi.up.x) + " " + std::to_string(sim_iterator->poi.up.y) + " " + std::to_string(sim_iterator->poi.up.z) + " " + << std::to_string(sim_iterator->poi.radius) + " " + << std::to_string(sim_iterator->min_clip.x) + " " + std::to_string(sim_iterator->min_clip.y) + " " + std::to_string(sim_iterator->min_clip.z) + " " + << std::to_string(sim_iterator->max_clip.x) + " " + std::to_string(sim_iterator->max_clip.y) + " " + std::to_string(sim_iterator->max_clip.z) + "\n"; + } } } @@ -1609,7 +1672,23 @@ void UIView::load_camera_poi(std::ifstream& loadFile, int num_poi) float up_y = std::stof(poiVals[8]); float up_z = std::stof(poiVals[9]); float radius = std::stof(poiVals[10]); - m_controller_app.get_trackball_camera().add_camera_poi(label, eye_x, eye_y, eye_z, target_x, target_y, target_z, up_x, up_y, up_z, radius); + float min_clip_x = std::stof(poiVals[11]); + float min_clip_y = std::stof(poiVals[12]); + float min_clip_z = std::stof(poiVals[13]); + float max_clip_x = std::stof(poiVals[14]); + float max_clip_y = std::stof(poiVals[15]); + float max_clip_z = std::stof(poiVals[16]); + + SimulationState sim; + sim.poi.label = label; + sim.poi.eye = glm::vec3(eye_x, eye_y, eye_z); + sim.poi.target = glm::vec3(target_x, target_y, target_z); + sim.poi.up = glm::vec3(up_x, up_y, up_z); + sim.poi.radius = radius; + sim.min_clip = glm::vec3(min_clip_x, min_clip_y, min_clip_z); + sim.max_clip = glm::vec3(max_clip_x, max_clip_y, max_clip_z); + m_controller_app.get_simulation().add_simulation_state(sim); + } } @@ -1743,22 +1822,25 @@ void UIView::set_volume_time_info(time_t time) { tm* time_info = localtime(&time); + if (time_info) + { + bool pm = time_info->tm_hour >= 12; + int hour_12 = (time_info->tm_hour >= 13) ? time_info->tm_hour - 12 : time_info->tm_hour; - bool pm = time_info->tm_hour >= 12; - int hour_12 = (time_info->tm_hour >= 13) ? time_info->tm_hour - 12 : time_info->tm_hour; - - std::stringstream ss_time; - ss_time << std::setw(2) << std::setfill('0') << hour_12 << ":"; - ss_time << std::setw(2) << std::setfill('0') << time_info->tm_min << " "; - ss_time << (pm ? "PM" : "AM"); + std::stringstream ss_time; + ss_time << std::setw(2) << std::setfill('0') << hour_12 << ":"; + ss_time << std::setw(2) << std::setfill('0') << time_info->tm_min << " "; + ss_time << (pm ? "PM" : "AM"); - std::stringstream ss_day; - ss_day << months[time_info->tm_mon] << " "; - ss_day << std::setw(2) << std::setfill('0') << time_info->tm_mday; - ss_day << ", " << time_info->tm_year + 1900; + std::stringstream ss_day; + ss_day << months[time_info->tm_mon] << " "; + ss_day << std::setw(2) << std::setfill('0') << time_info->tm_mday; + ss_day << ", " << time_info->tm_year + 1900; - m_time_info = ss_time.str(); - m_day_info = ss_day.str(); + m_time_info = ss_time.str(); + m_day_info = ss_day.str(); + } + } diff --git a/src/interaction/ArcBallCamera.cpp b/src/interaction/ArcBallCamera.cpp index de61bd7..175202e 100644 --- a/src/interaction/ArcBallCamera.cpp +++ b/src/interaction/ArcBallCamera.cpp @@ -39,7 +39,6 @@ ArcBallCamera::ArcBallCamera() : m_radius(1), m_mouse_left_pressed(false), m_mouse_center_pressed(false), m_mouse_right_pressed(false), last_x(0), last_y(0) , m_PanFactor(1), m_RotateFactor(1), m_cameraScrollFactor(0.1), m_target(0, 0, 0), m_eye(0, 0, 1), m_up(0, 1, 0), m_rotate_camera_center{ false } -, m_is_animate_path(false), m_camera_animation_state(STOP), animation_button_label("ANIMATE"), m_animation_duration(10.f) { } @@ -51,86 +50,80 @@ ArcBallCamera::~ArcBallCamera() void ArcBallCamera::updateCameraMatrix() { - if (m_is_animate_path) + if (m_aap_mode == 0) { - /*glm::vec3 animation_position = m_animation; - viewmatrix = glm::lookAt(animation_position, m_current_poi.target, m_current_poi.up);*/ - if (m_camera_animation_state != PAUSE) - { - update_animation(); - m_controller_app->set_clip_max(m_clip_max_animation.value()); - m_controller_app->set_clip_min(m_clip_min_animation.value()); - - } - if (m_timeline.isFinished()) - { - m_camera_animation_state = STOP; - animation_button_label = "Animate"; - m_timeline.resetTime(); - if (m_controller_app->get_movie_state() == MOVIE_RECORD) - { - m_controller_app->stop_movie(); - } - - } - - - PointOfInterest poi { m_eye_animation.value(), m_target_animation.value(), m_up_animation.value(), m_radius_animation.value() }; - m_viewmatrix = glm::lookAt(poi.get_camera_position(), poi.target, poi.up); - - + m_viewmatrix = glm::lookAt(m_current_poi.get_camera_position(), m_current_poi.target, m_current_poi.up); } else { - m_viewmatrix = glm::lookAt(m_current_poi.get_camera_position(), m_current_poi.target, m_current_poi.up); + m_viewmatrix = glm::lookAt(m_simulation_poi.get_camera_position(), m_simulation_poi.target, m_simulation_poi.up); } + + +} +void ArcBallCamera::update_sim_poi(PointOfInterest& poi) +{ + m_simulation_poi = poi; } void ArcBallCamera::mouse_pressed(int button, bool isDown) { - if (button == 0) //left -> rotate - { - m_mouse_left_pressed = isDown; - } - else if (button == 1) // right ->pan + if (m_aap_mode == 0) { - m_mouse_right_pressed = isDown; + if (button == 0) //left -> rotate + { + m_mouse_left_pressed = isDown; + } + else if (button == 1) // right ->pan + { + m_mouse_right_pressed = isDown; - } - else if (button == 2) - { + } + else if (button == 2) + { - m_mouse_center_pressed = isDown; + m_mouse_center_pressed = isDown; + } } + } void ArcBallCamera::mouse_move(float x, float y) { - if (m_mouse_left_pressed) { - // Calculate the new phi and theta based on mouse position relative to where the user clicked - float dx = ((float)(last_x - x)) / 300.0f; - float dy = ((float)(last_y - y)) / 300.0f; + if (m_aap_mode == 0) + { + if (m_mouse_left_pressed) { + // Calculate the new phi and theta based on mouse position relative to where the user clicked + float dx = ((float)(last_x - x)) / 300.0f; + float dy = ((float)(last_y - y)) / 300.0f; - Rotate(dx * m_RotateFactor, -dy * m_RotateFactor); - } - else if (m_mouse_center_pressed) { - float dy = ((float)(last_y - y)) / 300.0f; + Rotate(dx * m_RotateFactor, -dy * m_RotateFactor); + } + else if (m_mouse_center_pressed) { + float dy = ((float)(last_y - y)) / 300.0f; - RotateEyeAxis(dy * m_RotateFactor); - } - else if (m_mouse_right_pressed) { - float dx = ((float)(last_x - x)) / 300.0f; - float dy = ((float)(last_y - y)) / 300.0f; + RotateEyeAxis(dy * m_RotateFactor); + } + else if (m_mouse_right_pressed) { + float dx = ((float)(last_x - x)) / 300.0f; + float dy = ((float)(last_y - y)) / 300.0f; + + Pan(-dx * m_PanFactor, -dy * m_PanFactor); + } - Pan(-dx * m_PanFactor, -dy * m_PanFactor); + last_x = x; + last_y = y; } - last_x = x; - last_y = y; + } void ArcBallCamera::mouse_scroll(float dist) { - Zoom(dist); + if (m_aap_mode == 0) + { + Zoom(dist); + } + } void ArcBallCamera::setCameraCenterRotation(bool useCameraCenter) { @@ -143,36 +136,43 @@ void ArcBallCamera::setCameraCenterRotation(bool useCameraCenter) { } void ArcBallCamera::wasd_pressed(int awsd) { - glm::vec3 dir = glm::normalize(-m_current_poi.eye); - glm::vec3 right = glm::cross(dir, m_current_poi.up); - if (W & awsd) { - m_current_poi.target = m_current_poi.target + dir * glm::vec3(0.001); - updateCameraMatrix(); - } - if (S & awsd) { - m_current_poi.target = m_current_poi.target - dir * glm::vec3(0.001); - updateCameraMatrix(); - } - if (A & awsd) { - m_current_poi.target = m_current_poi.target - (right)*glm::vec3(0.001); - updateCameraMatrix(); - } - if (D & awsd) { - m_current_poi.target = m_current_poi.target + (right)*glm::vec3(0.001); - updateCameraMatrix(); - } - if (Q & awsd) { - m_current_poi.target = m_target - m_current_poi.up * glm::vec3(0.001); - updateCameraMatrix(); - } - if (E & awsd) { - m_current_poi.target = m_target + m_current_poi.up * glm::vec3(0.001); - updateCameraMatrix(); + if (m_aap_mode == 0) + { + glm::vec3 dir = glm::normalize(-m_current_poi.eye); + glm::vec3 right = glm::cross(dir, m_current_poi.up); + + if (W & awsd) { + m_current_poi.target = m_current_poi.target + dir * glm::vec3(0.001); + updateCameraMatrix(); + } + if (S & awsd) { + m_current_poi.target = m_current_poi.target - dir * glm::vec3(0.001); + updateCameraMatrix(); + } + if (A & awsd) { + m_current_poi.target = m_current_poi.target - (right)*glm::vec3(0.001); + updateCameraMatrix(); + } + if (D & awsd) { + m_current_poi.target = m_current_poi.target + (right)*glm::vec3(0.001); + updateCameraMatrix(); + } + if (Q & awsd) { + m_current_poi.target = m_target - m_current_poi.up * glm::vec3(0.001); + updateCameraMatrix(); + } + if (E & awsd) { + m_current_poi.target = m_target + m_current_poi.up * glm::vec3(0.001); + updateCameraMatrix(); + } } + + } -void ArcBallCamera::Rotate(float dx, float dy) { +void ArcBallCamera::Rotate(float dx, float dy) +{ glm::vec3 right = glm::cross(glm::normalize(m_current_poi.eye), m_current_poi.up); glm::mat4 rot = glm::mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); rot = glm::rotate(rot, dx, m_current_poi.up); @@ -188,6 +188,8 @@ void ArcBallCamera::Rotate(float dx, float dy) { m_current_poi.target -= m_current_poi.radius * glm::normalize(m_current_poi.eye); else m_current_poi.target = rot * glm::vec4(m_current_poi.target, 1); + + } void ArcBallCamera::RotateEyeAxis(float dy) { @@ -214,59 +216,21 @@ void ArcBallCamera::Pan(float dx, float dy) { m_current_poi.target = m_current_poi.target + (right * dx) + (m_current_poi.up * dy); } -std::list& ArcBallCamera::get_camera_poi() -{ - return m_camera_poi; -} - -void ArcBallCamera::add_camera_poi(std::string& label, glm::vec3& clip_max, glm::vec3& clip_min) -{ - m_current_poi.label = label; - m_current_poi.max_clip = clip_max; - m_current_poi.min_clip = clip_min; - - m_camera_poi.push_back(m_current_poi); -} - -void ArcBallCamera::add_camera_poi(std::string& label, float eye_x, float eye_y, float eye_z, float target_x, float target_y, float target_z, float up_x, float up_y, float up_z, float radius) -{ - PointOfInterest poi; - poi.label = label; - poi.eye = glm::vec3(eye_x, eye_y, eye_z); - poi.target = glm::vec3(target_x, target_y, target_z); - poi.up = glm::vec3(up_x, up_y, up_z); - poi.radius = radius; - m_camera_poi.push_front(poi); - - -} -int ArcBallCamera::get_current_poi() +PointOfInterest& ArcBallCamera::get_current_poi() { - return 0; + return m_current_poi; } -void ArcBallCamera::set_current_poi(int val) -{ - m_is_animate_path = false; - std::list::iterator it = m_camera_poi.begin(); - for (int i = 0; i < val; i++) { - ++it; - } - m_current_poi = *it; - -} -void ArcBallCamera::remove_poi(int val) +void ArcBallCamera::set_current_poi(const PointOfInterest& poi) { - auto poi_iterator = m_camera_poi.begin(); - std::advance(poi_iterator, val); - m_camera_poi.erase(poi_iterator); + // deep copy + m_current_poi = poi; } void ArcBallCamera::reset_camera() { - m_is_animate_path = false; last_x = 0; last_y = 0; m_PanFactor = 1; @@ -278,123 +242,9 @@ void ArcBallCamera::reset_camera() m_current_poi = PointOfInterest(); } -PointOfInterest& ArcBallCamera::get_poi_at(int val) -{ - auto poi_iterator = m_camera_poi.begin(); - std::advance(poi_iterator, val); - return *poi_iterator; -} - -void ArcBallCamera::update_animation() -{ - if (m_is_animate_path) - { - m_timeline.step(1.0 / 30.0); - - } - - -} - -void ArcBallCamera::set_animation_path() -{ - if (m_camera_poi.size() > 1) - { - - PointOfInterest first_position = m_camera_poi.front(); - - ch::Sequence sequence_eye(first_position.eye); - ch::Sequence sequence_target(first_position.target); - ch::Sequence sequence_up(first_position.up); - ch::Sequence sequence_radius(first_position.radius); - ch::Sequence sequence_clip_max(first_position.max_clip); - ch::Sequence sequence_clip_min(first_position.min_clip); - - - for (auto next_camera_poi_interator = std::next(m_camera_poi.begin()); next_camera_poi_interator != m_camera_poi.end(); next_camera_poi_interator++) - { - sequence_eye.then(next_camera_poi_interator->eye, m_animation_duration); - sequence_target.then(next_camera_poi_interator->target, m_animation_duration); - sequence_up.then(next_camera_poi_interator->up, m_animation_duration); - sequence_radius.then(next_camera_poi_interator->radius, m_animation_duration); - sequence_clip_max.then(next_camera_poi_interator->max_clip, m_animation_duration); - sequence_clip_min.then(next_camera_poi_interator->min_clip, m_animation_duration); - } - - - auto group = std::make_shared(); - group->apply(&m_eye_animation, sequence_eye); - group->apply(&m_target_animation, sequence_target); - group->apply(&m_up_animation, sequence_up); - group->apply(&m_radius_animation, sequence_radius); - group->apply(&m_clip_max_animation, sequence_clip_max); - group->apply(&m_clip_min_animation, sequence_clip_min); - - m_timeline.addShared(group); - - } - -} - -void ArcBallCamera::set_animation_state() -{ - if (m_camera_animation_state == STOP) - { - set_animation_path(); - m_camera_animation_state = PLAYING; - animation_button_label = "PAUSE"; - } - else if (m_camera_animation_state == PLAYING) - { - if (!m_timeline.isFinished()) - { - m_camera_animation_state = PAUSE; - animation_button_label = "ANIMATE"; - } - } - else if (m_camera_animation_state == PAUSE) - { - m_camera_animation_state = PLAYING; - animation_button_label = "PAUSE"; - } - - m_is_animate_path = true; - -} - -CAMERA_ANIMATION_STATE ArcBallCamera::get_animation_state() -{ - if (m_timeline.isFinished()) - { - return STOP; - } - else if (!m_timeline.isFinished() && m_camera_animation_state == PLAYING) - { - return PLAYING; - } - else if (!m_timeline.isFinished() && m_camera_animation_state == STOP) - { - return PAUSE; - } -} - -std::string ArcBallCamera::get_camera_animation_state() -{ - return animation_button_label; -} - -float ArcBallCamera::get_camera_animation_duration() -{ - return m_animation_duration; -} - -void ArcBallCamera::set_camera_animation_duration(float duration) -{ - m_animation_duration = duration; -} -void ArcBallCamera::set_controller_application(VRVolumeApp* vr_app) +void ArcBallCamera::set_app_mode(unsigned int mode) { - m_controller_app = vr_app; + m_aap_mode = mode; } diff --git a/src/interaction/Simulation.cpp b/src/interaction/Simulation.cpp new file mode 100644 index 0000000..52aaf25 --- /dev/null +++ b/src/interaction/Simulation.cpp @@ -0,0 +1,189 @@ +#include "../include/interaction/Simulation.h" +#include "../include/vrapp/VRVolumeApp.h" + +Simulation::Simulation(VRVolumeApp& controller_app,float time ):m_animation_duration(time), m_controller_app(controller_app), +animation_button_label("ANIMATE"), m_animation_state(STOP) +{ + +} + + + +void Simulation::add_simulation_state(SimulationState& simulationState) +{ + float time = m_simulation_states.size() * m_animation_duration; + + int mins = (int)time / 60; + int seconds = (int)time % 60; + + simulationState.time_label = std::to_string(mins) + ":" + std::to_string(seconds); + m_simulation_states.push_back(simulationState); +} + +void Simulation::create_animations() +{ + if (m_simulation_states.size() > 1) + { + SimulationState first_position = m_simulation_states.front(); + ch::Sequence sequence_eye(first_position.poi.eye); + ch::Sequence sequence_target(first_position.poi.target); + ch::Sequence sequence_up(first_position.poi.up); + ch::Sequence sequence_radius(first_position.poi.radius); + ch::Sequence sequence_clip_max(first_position.max_clip); + ch::Sequence sequence_clip_min(first_position.min_clip); + + for (auto iterator = std::next(m_simulation_states.begin()); iterator != m_simulation_states.end(); iterator++) + { + sequence_eye.then(iterator->poi.eye, m_animation_duration); + sequence_target.then(iterator->poi.target, m_animation_duration); + sequence_up.then(iterator->poi.up, m_animation_duration); + sequence_radius.then(iterator->poi.radius, m_animation_duration); + sequence_clip_max.then(iterator->max_clip, m_animation_duration); + sequence_clip_min.then(iterator->min_clip, m_animation_duration); + } + + + auto group = std::make_shared(); + group->apply(&m_eye_animation, sequence_eye); + group->apply(&m_target_animation, sequence_target); + group->apply(&m_up_animation, sequence_up); + group->apply(&m_radius_animation, sequence_radius); + group->apply(&m_max_clip_animation, sequence_clip_max); + group->apply(&m_min_clip_animation, sequence_clip_min); + + m_timeline.addShared(group); + + } +} + +void Simulation::update_simulation() +{ + if (m_animation_state != PAUSE) + { + update_time_step(); + + } + if (m_timeline.isFinished()) + { + m_animation_state = STOP; + animation_button_label = "Animate"; + m_controller_app.set_app_mode(MANUAL); + m_timeline.resetTime(); + if (m_controller_app.get_movie_state() == MOVIE_RECORD) + { + m_controller_app.stop_movie(); + } + } + +} + +void Simulation::update_time_step() +{ + m_timeline.step(1.0 / 30.0); + +} + + +void Simulation::set_animation_state() +{ + if (m_animation_state == STOP) + { + create_animations(); + m_controller_app.set_app_mode(SIMULATION); + m_animation_state = PLAYING; + animation_button_label = "PAUSE"; + } + else if (m_animation_state == PLAYING) + { + if (!m_timeline.isFinished()) + { + m_animation_state = PAUSE; + animation_button_label = "ANIMATE"; + } + } + else if (m_animation_state == PAUSE) + { + m_animation_state = PLAYING; + animation_button_label = "PAUSE"; + } + + m_is_animate_path = true; + +} + +ANIMATION_STATE Simulation::get_animation_state() +{ + if (m_timeline.isFinished()) + { + return STOP; + } + else if (!m_timeline.isFinished() && m_animation_state == PLAYING) + { + return PLAYING; + } + else if (!m_timeline.isFinished() && m_animation_state == STOP) + { + return PAUSE; + } +} + +std::string Simulation::get_camera_animation_state() +{ + return animation_button_label; +} + +float Simulation::get_camera_animation_duration() +{ + return m_animation_duration; +} + +void Simulation::set_camera_animation_duration(float duration) +{ + m_animation_duration = duration; +} + +const std::list& Simulation::get_simulation_states() +{ + return m_simulation_states; +} + +SimulationState& Simulation::get_simulation_state_at(unsigned int index) +{ + auto poi_iterator = m_simulation_states.begin(); + std::advance(poi_iterator, index); + return *poi_iterator; +} + +SimulationState Simulation::get_current_simulation_state() +{ + PointOfInterest poi(m_eye_animation.value(), m_target_animation.value(), m_up_animation.value(), m_radius_animation.value()); + + + SimulationState current_state; + current_state.poi = poi; + current_state.max_clip = m_max_clip_animation; + current_state.min_clip = m_min_clip_animation; + + return current_state; +} + +void Simulation::remove_simulation_state(unsigned int index) +{ + auto poi_iterator = m_simulation_states.begin(); + std::advance(poi_iterator, index); + std::string time_label = poi_iterator->time_label; + poi_iterator = m_simulation_states.erase(poi_iterator); + for (poi_iterator ; poi_iterator != m_simulation_states.end();poi_iterator++) + { + std::string current_time_label = poi_iterator->time_label; + poi_iterator->time_label = time_label; + time_label = current_time_label; + } + +} + +float Simulation::get_animation_duration() +{ + return m_animation_duration; +} + diff --git a/src/loader/VRDataLoader.cpp b/src/loader/VRDataLoader.cpp index df2ce5e..8166789 100644 --- a/src/loader/VRDataLoader.cpp +++ b/src/loader/VRDataLoader.cpp @@ -21,24 +21,33 @@ -VRDataLoader* VRDataLoader::m_instance = nullptr; +//VRDataLoader* VRDataLoader::m_instance = nullptr; VRDataLoader::VRDataLoader() { } -VRDataLoader* VRDataLoader::get_instance() -{ - if (!m_instance) - { - m_instance = new VRDataLoader; - } - return m_instance; -} - -void VRDataLoader::load_txt_file(VRVolumeApp& vrVolumeApp, std::string& filename) +//VRDataLoader* VRDataLoader::get_instance() +//{ +// if (!m_instance) +// { +// m_instance = new VRDataLoader; +// } +// return m_instance; +//}VRDataLoader* VRDataLoader::get_instance() +//{ +// if (!m_instance) +// { +// m_instance = new VRDataLoader; +// } +// return m_instance; +//} + + +void VRDataLoader::load_txt_file( VRVolumeApp& vrVolumeApp, std::string& filename) { + std::ifstream inFile; inFile.open(filename); diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index ad602e8..eda44cf 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -54,12 +54,14 @@ VRVolumeApp::VRVolumeApp() :m_mesh_model(nullptr), m_clip_max{ 1.0f }, m_clip_mi m_lookingGlass(false), m_isInitailized(false), m_speed(0.01f), m_movieAction(nullptr), m_moviename("movie.mp4"), m_noColor(0.0f), m_ambient(0.2f, 0.2f, 0.2f, 1.0f), m_diffuse(0.5f, 0.5f, 0.5f, 1.0f), m_ui_view(nullptr), m_animated(false), m_numVolumes(0), m_selectedVolume(0), m_multiplier(1.0f), m_threshold(0.0f), m_frame(0.0f), m_use_multi_transfer(false), m_clipping(false), m_show_menu(true), -m_window_properties(nullptr), m_animation_speed(1.0f),m_simulation(nullptr), m_current_movie_state(MOVIE_STOP) +m_window_properties(nullptr), m_animation_speed(1.0f), m_current_movie_state(MOVIE_STOP), m_app_mode(MANUAL), m_end_load(false) { m_renders.push_back(new VolumeSliceRenderer()); m_renders.push_back(new VolumeRaycastRenderer()); } + + VRVolumeApp::~VRVolumeApp() { if (m_ui_view) @@ -98,11 +100,11 @@ void VRVolumeApp::initialize() m_ui_view->init_ui(m_is2d, m_lookingGlass); } m_window_properties = new Window_Properties(); - //m_simulation = new Simulation() + m_simulation = new Simulation(*this); m_labels = new Labels(m_line_shader, m_simple_texture_shader); m_labels->set_parent_directory(get_directory_path()); - m_trackball.set_controller_application(this); + m_isInitailized = true; m_rendercount = 0; std::cout << "initialize end" << std::endl; @@ -172,8 +174,9 @@ void VRVolumeApp::load_shaders() void VRVolumeApp::initialize_textures() { add_lodaded_textures(); - for (int i = 0; i < m_volumes.size(); i++) { - + + for (int i = 0; i < m_volumes.size(); i++) + { std::vector< Volume* > vlm = m_volumes[i]; for (int j = 0; j < vlm.size(); j++) { @@ -232,6 +235,7 @@ void VRVolumeApp::stop_movie() m_current_movie_state = MOVIE_STOP; #ifdef _MSC_VER m_movieAction->save(m_moviename); + m_ui_view->set_show_movie_saved_pop_up(true); #endif delete m_movieAction; m_movieAction = nullptr; @@ -553,6 +557,20 @@ void VRVolumeApp::load_nrrd_file(std::string& filename) void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) { + m_trackball.set_app_mode(m_app_mode); + if (m_app_mode == SIMULATION) + { + if (m_simulation) + { + m_simulation->update_simulation(); + SimulationState sim_state = m_simulation->get_current_simulation_state(); + m_trackball.update_sim_poi(sim_state.poi); + m_ui_view->set_clip_max(sim_state.max_clip); + m_ui_view->set_clip_min(sim_state.min_clip); + } + } + + if (m_is2d) { m_headpose = glm::make_mat4(renderState.getViewMatrix()); m_headpose = glm::inverse(m_headpose); @@ -569,7 +587,6 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) //setup projection m_projection_mtrx = glm::make_mat4(renderState.getProjectionMatrix()); - //m_projection_mtrx = m_trackball.get_projection_camera(); m_model_view = glm::make_mat4(renderState.getViewMatrix()); //overwrite MV for 2D viewing @@ -690,17 +707,9 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) render_volume(renderState); - if (m_show_menu) - { - render_ui(renderState); - } + render_ui(renderState); - - /*if (m_ui_view && m_is2d) - { - m_ui_view->render_2D(); - }*/ - + glFlush(); @@ -885,8 +894,7 @@ void VRVolumeApp::animated_render(int tfn, int vol) void VRVolumeApp::render_ui(const MinVR::VRGraphicsState& renderState) { //render menu - glm::mat4 mvMatrix = glm::make_mat4(renderState.getViewMatrix()); - + if (m_ui_view && m_window_properties) { m_window_properties->window_w = renderState.index().getValue("WindowWidth"); @@ -897,6 +905,7 @@ void VRVolumeApp::render_ui(const MinVR::VRGraphicsState& renderState) if (!m_is2d) { + glm::mat4 mvMatrix = glm::make_mat4(renderState.getViewMatrix()); m_ui_view->render_3D(mvMatrix, *m_window_properties); } else @@ -991,7 +1000,8 @@ void VRVolumeApp::add_lodaded_textures() m_threads.clear(); m_promises.clear(); m_futures.clear(); - // m_ui_view->compute_new_histogram(); + + } } @@ -1232,3 +1242,8 @@ MovieState VRVolumeApp::get_movie_state() { return m_current_movie_state; } + +void VRVolumeApp::set_app_mode(APPMODE mode) +{ + m_app_mode = mode; +} diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index 94ef2dd..0ab64a0 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -63,7 +63,7 @@ VolumeVisualizationApp::VolumeVisualizationApp(int argc, char** argv) : VRApp(ar else if (helper::ends_with_string(std::string(argv_int[i]), ".txt")) { std::string fileName = argv_int[i]; - VRDataLoader::get_instance()->load_txt_file(*m_vrVolumeApp, fileName); + VRDataLoader::load_txt_file(*m_vrVolumeApp, fileName); } else if (helper::ends_with_string(std::string(argv_int[i]), ".nrrd")) { @@ -567,19 +567,7 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend const float duration = 10.5f; - auto ramp_a = ch::makeRamp(v1, v2, duration); - auto ramp_b = ch::makeRamp(pos1, pos2, duration); - auto group = std::make_shared(); - auto my_sequence = ch::Sequence(glm::vec3()); - my_sequence.then(pos1, 10.0f); - my_sequence.then(pos1, 5.0f); - my_sequence.then(pos2, 20.0f); - //ch::Motion motion(&_control_b, my_sequence); - //group->apply(&_control_a, ramp_a); - group->apply(&_control_b, my_sequence); - - _timeline.addShared(group); - + } diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index ee6f631..61b7b71 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -540,6 +540,7 @@ endif() ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/ArcBallCamera.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/HelperFunctions.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/CreateMovieAction.cpp + ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/Simulation.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/loader/LoadDescriptionAction.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/loader/VRDataLoader.cpp ) @@ -568,6 +569,8 @@ set(header_files ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/ArcBallCamera.h ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/HelperFunctions.h ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/CreateMovieAction.h + ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/PointOfInterests.h + ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/Simulation.h ${CMAKE_CURRENT_BINARY_DIR}/../include/loader/LoadDescriptionAction.h ${CMAKE_CURRENT_BINARY_DIR}/../include/loader/VRDataLoader.h From 86c62e27e75008baf18199cee8ce9086599f01f7 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Wed, 20 Apr 2022 13:27:53 -0400 Subject: [PATCH 13/23] add copy command to move Resource folder to executable folder --- superbuild/CMakeLists.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index 472684d..d76f11e 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -110,7 +110,7 @@ endif (WIN32) #Choreograph # Configure external project -IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/Choreograph/Choreograph) +#IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/Choreograph/Choreograph) execute_process( COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} @@ -129,7 +129,7 @@ execute_process( COMMAND ${CMAKE_COMMAND} ) -ENDIF() +#ENDIF() find_package(Choreograph REQUIRED) if(Choreograph_FOUND) @@ -676,10 +676,11 @@ add_executable(${PROJECT_NAME} ${source_files} ${header_files}) target_link_libraries(${PROJECT_NAME} ${LIBRARIES}) file(COPY "${CMAKE_SOURCE_DIR}/../shaders" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin") -file(COPY "${CMAKE_SOURCE_DIR}/../fonts/" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin") -file(COPY "${CMAKE_SOURCE_DIR}/../observers/" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin") +file(COPY "${CMAKE_SOURCE_DIR}/../fonts" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin") +file(COPY "${CMAKE_SOURCE_DIR}/../observers" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin") file(COPY "${CMAKE_SOURCE_DIR}/../colormaps" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin") - +message(STATUS "COPY RESOURCES FOLDER") +file(COPY "${CMAKE_SOURCE_DIR}/../Resources" DESTINATION "${INSTALL_DIR_ABSOLUTE}/bin") enable_testing() From 1e7a79f1cdfedede8740116d44ff176efa6e294f Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Wed, 20 Apr 2022 16:10:15 -0400 Subject: [PATCH 14/23] add Choreograph folder to be exclude in the clean superbuild folder script --- superbuild/clean/clean.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superbuild/clean/clean.py b/superbuild/clean/clean.py index b28de99..f8d155f 100644 --- a/superbuild/clean/clean.py +++ b/superbuild/clean/clean.py @@ -18,7 +18,7 @@ def handleRemoveReadonly(func, path, exc): current_dir = pathlib.Path(__file__).parent.resolve() parent_dir = dirname(dirname(abspath(__file__))) print("working directory " + parent_dir) -folders_to_operate = ["CPPFSD","freetype","FTGL","glew","glfw","glm","MinVR","opencv","teem","vr-imgui","zlib"] +folders_to_operate = ["CPPFSD","freetype","FTGL","glew","glfw","glm","MinVR","opencv","teem","vr-imgui","zlib","Choreograph"] files_to_exclude = ["CMakeLists.txt","macros.cmake","minvr_patch_082021.patch"] folders_to_exclude = ["cmake","clean","scripts","bat2exe"] From 14bb1ecaa74cedcc5ae6b036bda9447fa2dd8ea0 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Thu, 21 Apr 2022 15:58:56 -0400 Subject: [PATCH 15/23] fix file format and identation. remove comments and unused variables. renaming variables to camel notation. --- Resources/README.md | 3 + include/UI/UIView.h | 104 +++-- include/interaction/ArcBallCamera.h | 88 ++-- include/interaction/Labels.h | 71 ++- include/interaction/Simulation.h | 44 +- include/loader/VRDataLoader.h | 11 +- include/render/VolumeRenderer.h | 7 - include/vrapp/VRVolumeApp.h | 10 +- include/vrapp/VolumeVisualizationApp.h | 54 +-- libs/Model/Model.cpp | 81 ++-- libs/Texture/Texture.cpp | 151 +++--- libs/Texture/Texture.h | 4 +- libs/UIHelpers/transfer_function_widget.cpp | 251 +++++----- libs/UIHelpers/transfer_function_widget.h | 106 ++--- shaders/lines_shader.frag | 4 +- shaders/lines_shader.vert | 1 - shaders/shader.frag | 6 +- src/UI/UIView.cpp | 488 +++++++++----------- src/interaction/ArcBallCamera.cpp | 151 +++--- src/interaction/Labels.cpp | 83 ++-- src/interaction/Simulation.cpp | 46 +- src/loader/VRDataLoader.cpp | 68 +-- src/main.cpp | 3 +- src/render/VolumeRaycastShader.cpp | 426 +++++++++-------- src/vrapp/VRVolumeApp.cpp | 348 ++++++-------- src/vrapp/VolumeVisualizationApp.cpp | 234 ++++------ superbuild/CMakeLists.txt | 1 + 27 files changed, 1252 insertions(+), 1592 deletions(-) create mode 100644 Resources/README.md diff --git a/Resources/README.md b/Resources/README.md new file mode 100644 index 0000000..5f3e820 --- /dev/null +++ b/Resources/README.md @@ -0,0 +1,3 @@ +### Resource folder + +All the [Models - obj files ](https://en.wikipedia.org/wiki/Wavefront_.obj_file) used by applications must go on this folder. Make sure the .objs have both vertex and texture coordinates (normals are optional). \ No newline at end of file diff --git a/include/UI/UIView.h b/include/UI/UIView.h index 3e3f910..d1befa6 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -12,15 +12,30 @@ #include #include - class VRVolumeApp; class CreateMovieAction; #define INPUT_TEXT_SIZE 200 #define MAX_COLUMS 50 -enum SAVE_MODAL { SAVE_NONE, SAVE_SESSION, SAVE_TRFR_FNC }; -enum LOAD_MODAL { LOAD_NONE, LOAD_SESSION, LOAD_TRFR_FNC }; -enum BUTTON_ACTION { NONE, ADD, EDIT, REMOVE }; +enum SAVE_MODAL +{ + SAVE_NONE, + SAVE_SESSION, + SAVE_TRFR_FNC +}; +enum LOAD_MODAL +{ + LOAD_NONE, + LOAD_SESSION, + LOAD_TRFR_FNC +}; +enum BUTTON_ACTION +{ + NONE, + ADD, + EDIT, + REMOVE +}; struct Window_Properties { @@ -30,12 +45,12 @@ struct Window_Properties int framebuffer_w = 0; int framebuffer_h = 0; - bool operator==(Window_Properties& other) + bool operator==(Window_Properties &other) { if (other.window_w == window_w && - other.window_h == window_h && - other.framebuffer_w == framebuffer_w && - other.framebuffer_h == framebuffer_h) + other.window_h == window_h && + other.framebuffer_w == framebuffer_w && + other.framebuffer_h == framebuffer_h) { return true; } @@ -46,18 +61,17 @@ struct Window_Properties class UIView { public: - UIView(VRVolumeApp& controllerApp); + UIView(VRVolumeApp &controllerApp); ~UIView(); - void draw_ui_callback(); void init_ui(bool is2D, bool lookingGlass); void update_ui(int numVolumes); - void render_2D(Window_Properties& window_properties); - void render_3D(glm::mat4& space_matrix, Window_Properties& window_properties); + void render_2D(Window_Properties &window_properties); + void render_3D(glm::mat4 &space_matrix, Window_Properties &window_properties); void update_3D_ui_frame(); - void set_cursor_pos(glm::vec2&); + void set_cursor_pos(glm::vec2 &); void set_analog_value(float); int get_num_transfer_functions(); @@ -74,7 +88,7 @@ class UIView void set_enable_render_volume(); - void set_controller_pose(glm::mat4& pose); + void set_controller_pose(glm::mat4 &pose); void set_dynamic_slices(bool); bool is_dynamic_slices(); @@ -89,7 +103,7 @@ class UIView void update_animation(float speed, int numFrames); - void add_data_label(std::string& dataLabel); + void add_data_label(std::string &dataLabel); void clear_data_labels(); @@ -119,53 +133,55 @@ class UIView void compute_new_histogram_view(); - void addTransferFunction(); - + void add_transfer_function(); void set_animation_length(int num_frames); - void get_Quantiles(int row); + void get_quantiles(int row); void set_volume_time_info(time_t time); - void draw_tranfer_funciton_legend(); + void draw_transfer_function_legend(); - void set_trns_fnct_min_max(float min, float max); + void set_transfer_function_min_max(float min, float max); bool get_show_movie_saved_pop_up() const { return m_show_movie_saved_pop_up; } void set_show_movie_saved_pop_up(bool val) { m_show_movie_saved_pop_up = val; } private: - struct MyTransFerFunctions { - int ID; + int ID; std::string Name; std::vector volumes; }; - void open_save_modal_dialog(std::string& id, bool& window_state, - std::function save_function, std::string& extension); + void open_save_modal_dialog(std::string &id, bool &window_state, + std::function save_function, std::string &extension); void add_trans_function(); - void save_trans_functions(std::ofstream& saveFile); + void save_trans_functions(std::ofstream &saveFile); - void save_user_session(std::ofstream& saveFile); + void save_user_session(std::ofstream &saveFile); - void load_trans_functions(std::ifstream& loadPath); + void load_trans_functions(std::ifstream &loadPath); void load_user_session(std::string filePath); - void save_simulation_states(std::ofstream& loadPath, int num_poi); + void save_simulation_states(std::ofstream &loadPath, int num_poi); + + void load_camera_poi(std::ifstream &loadPath, int num_poi); - void load_camera_poi(std::ifstream& loadPath, int num_poi); + void read_file_line(std::string &line, std::vector &values); - void read_file_line(std::string& line, std::vector& values); + void load_ocean_color_maps(); + + void adjust_transfer_function_to_histogram(); - VRVolumeApp& m_controller_app; - VRMenuHandler* m_menu_handler; + VRVolumeApp &m_controller_app; + VRMenuHandler *m_menu_handler; imgui_addons::ImGuiFileBrowser fileDialog; bool m_file_dialog_open; bool m_file_dialog_save_dir; @@ -184,7 +200,6 @@ class UIView float m_scale; int m_slices; bool m_dynamic_slices; - bool m_show_menu; bool m_renderVolume; @@ -214,7 +229,7 @@ class UIView bool m_initialized; - bool m_trn_fct_options_window; + bool m_transfer_function_options_window; bool m_save_trnfct_open; @@ -242,39 +257,31 @@ class UIView bool m_ui_background; - - bool m_column_selected[MAX_COLUMS]; unsigned int m_column_selection_state; + bool m_compute_new_histogram; Histogram m_histogram; - void adjust_transfer_function_to_histogram(); - vec2f m_histogram_point_1; vec2f m_histogram_point_2; float m_histogram_quantiles[2]; - - void load_ocean_color_maps(); - std::vector m_ocean_color_maps_names; std::string m_color_map_directory; float m_animation_speed; - std::string m_str_animation_duration; - + std::string m_animation_duration_to_string; + bool m_camera_animation_duration_open; - + std::vector m_clip_maxs; std::vector m_clip_mins; - bool m_show_clock; - float halfScreen; float m_clock_pos_x; float m_clock_pos_y; float m_clock_width; @@ -285,15 +292,12 @@ class UIView std::string m_time_info; std::string m_day_info; - std::string months[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; - + std::string m_months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int m_simulation_state_selection; bool m_time_frame_edited; bool m_show_movie_saved_pop_up; - }; - #endif diff --git a/include/interaction/ArcBallCamera.h b/include/interaction/ArcBallCamera.h index 20059a4..7f2d4c7 100644 --- a/include/interaction/ArcBallCamera.h +++ b/include/interaction/ArcBallCamera.h @@ -1,25 +1,25 @@ // ---------------------------------- -// Copyright © 2017, Brown University, Providence, RI. -// +// Copyright � 2017, Brown University, Providence, RI. +// // All Rights Reserved -// -// Use of the software is provided under the terms of the GNU General Public License version 3 -// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided -// that this copyright notice appear in all copies and that the name of Brown University not be used in -// advertising or publicity pertaining to the use or distribution of the software without specific written +// +// Use of the software is provided under the terms of the GNU General Public License version 3 +// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided +// that this copyright notice appear in all copies and that the name of Brown University not be used in +// advertising or publicity pertaining to the use or distribution of the software without specific written // prior permission from Brown University. -// +// // See license.txt for further information. -// -// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED “AS IS”, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY -// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING -// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION -// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS +// PROVIDED �AS IS�, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY +// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING +// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION +// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // ---------------------------------- -// +// ///\file ArcBall.h ///\author Benjamin Knorlein ///\date 10/17/2019 @@ -43,36 +43,13 @@ enum WASD_KEYS E = 1 << 5, // binary 100000 }; -//struct PointOfInterest { -// -// -// glm::vec3 eye = glm::vec3(0.0f, 0.0f, 1.0f); -// glm::vec3 target = glm::vec3(0.0f, 0.0f, 0.0f); -// glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); -// float radius = 1.f; -// glm::vec3 max_clip; -// glm::vec3 min_clip; -// -// std::string label; -// -// glm::vec3 get_camera_position() -// { -// eye = glm::normalize(eye); -// return radius * eye + target; -// } -// -//}; - - - /** Adds a HeadMatrix to the RenderState that gets updated repeatedly based upon head tracking events. */ - -class ArcBallCamera { +class ArcBallCamera +{ public: - ArcBallCamera(); virtual ~ArcBallCamera(); @@ -81,22 +58,21 @@ class ArcBallCamera { void mouse_move(float x, float y); void mouse_scroll(float dist); void setCameraCenterRotation(bool useCameraCenter); - void wasd_pressed(int awsd); + void wasd_pressed(int wasd); - glm::mat4& getViewmatrix() + glm::mat4 &get_view_matrix() { - updateCameraMatrix(); + update_camera_matrix(); return m_viewmatrix; } - void updateCameraMatrix(); + void update_camera_matrix(); - void update_sim_poi(PointOfInterest& poi); + void update_sim_poi(PointOfInterest &poi); - - PointOfInterest& get_current_poi(); + PointOfInterest &get_current_poi(); - void set_current_poi(const PointOfInterest& poi); + void set_current_poi(const PointOfInterest &poi); void reset_camera(); @@ -107,13 +83,12 @@ class ArcBallCamera { void RotateEyeAxis(float dy); void Zoom(float distance); void Pan(float dx, float dy); - float m_radius; glm::vec3 m_target; glm::vec3 m_up; glm::vec3 m_eye; - + PointOfInterest m_current_poi; PointOfInterest m_simulation_poi; @@ -125,16 +100,9 @@ class ArcBallCamera { float m_PanFactor; float m_RotateFactor; float m_cameraScrollFactor; - bool m_rotate_camera_center; - - - std::string animation_button_label; - - - unsigned int m_aap_mode; + unsigned int m_app_mode; }; #endif - diff --git a/include/interaction/Labels.h b/include/interaction/Labels.h index 2b18d5b..75ae2ad 100644 --- a/include/interaction/Labels.h +++ b/include/interaction/Labels.h @@ -1,25 +1,25 @@ // ---------------------------------- // Copyright © 2015, Brown University, Providence, RI. -// +// // All Rights Reserved -// -// Use of the software is provided under the terms of the GNU General Public License version 3 -// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided -// that this copyright notice appear in all copies and that the name of Brown University not be used in -// advertising or publicity pertaining to the use or distribution of the software without specific written +// +// Use of the software is provided under the terms of the GNU General Public License version 3 +// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided +// that this copyright notice appear in all copies and that the name of Brown University not be used in +// advertising or publicity pertaining to the use or distribution of the software without specific written // prior permission from Brown University. -// +// // See license.txt for further information. -// -// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED “AS ISâ€, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY -// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING -// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION -// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS +// PROVIDED “AS ISâ€, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY +// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING +// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION +// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // ---------------------------------- -// +// ///\file Labels.h ///\author Benjamin Knorlein ///\date 6/25/2019 @@ -31,10 +31,6 @@ #include #include - - - - class Model; class Texture; class VRVolumeApp; @@ -43,48 +39,45 @@ class ShaderProgram; struct LabelBillboard { unsigned int line_vba; - Texture* label_texture; - Model* label_model; + Texture *label_texture; + Model *label_model; glm::vec3 position; }; class Labels { public: - Labels(ShaderProgram& lines_shader, ShaderProgram& plane_shader); + Labels(ShaderProgram &lines_shader, ShaderProgram &plane_shader); ~Labels(); - void add(std::string texture, float x, float y, float z, float textPosZ, float size, int volume); - void drawLabels( glm::mat4 MV, glm::mat4 projection_matrix, glm::mat4& headpose, float z_scale); + void drawLabels(glm::mat4 MV, glm::mat4 projection_matrix, glm::mat4 &headpose, float z_scale); void drawLines(); - - void clear(); - void set_parent_directory(std::string& directory); + void clear(); + void set_parent_directory(std::string &directory); private: + unsigned int create_line_vba(glm::vec3 &start, glm::vec3 &end); - unsigned int create_line_vba(glm::vec3& start, glm::vec3& end); - std::vector m_billboard_labels; - + std::vector m_text; - std::vector m_position; - std::vector m_position2; + std::vector m_position; + std::vector m_position2; std::vector m_size; std::vector m_volume; std::vector m_lines_vba; std::vector m_lines_vbo; bool m_init_plane_model; - Model* m_plane_model; - // VRVolumeApp& m_controller_app; - std::map m_texture_cache; + Model *m_plane_model; + + std::map m_texture_cache; std::string m_parent_directory; - - ShaderProgram& m_lines_shader_program; - ShaderProgram& m_plane_shader_program; + + ShaderProgram &m_lines_shader_program; + ShaderProgram &m_plane_shader_program; }; #endif // LABELS_H diff --git a/include/interaction/Simulation.h b/include/interaction/Simulation.h index 70c7de5..f519033 100644 --- a/include/interaction/Simulation.h +++ b/include/interaction/Simulation.h @@ -1,5 +1,5 @@ -#ifndef ANIMATOR_H -#define ANIMATOR_H +#ifndef SIMULATION_H +#define SIMULATION_H #include "choreograph/Choreograph.h" @@ -7,8 +7,6 @@ #include "PointOfInterests.h" - - enum ANIMATION_STATE { STOP, @@ -18,9 +16,9 @@ enum ANIMATION_STATE struct SimulationState { - SimulationState() {}; - - SimulationState(const SimulationState& other) + SimulationState(){}; + + SimulationState(const SimulationState &other) { poi = other.poi; max_clip = other.max_clip; @@ -38,10 +36,10 @@ class VRVolumeApp; class Simulation { public: - Simulation(VRVolumeApp& controller_app,float time = 10.0f); + Simulation(VRVolumeApp &controller_app, float time = 10.0f); + + void add_simulation_state(SimulationState &simulationState); - void add_simulation_state(SimulationState& simulationState); - void create_animations(); void update_simulation(); @@ -52,21 +50,20 @@ class Simulation float get_camera_animation_duration(); void set_camera_animation_duration(float duration); - const std::list& get_simulation_states(); + const std::list &get_simulation_states(); - SimulationState& get_simulation_state_at(unsigned int index); + SimulationState &get_simulation_state_at(unsigned int index); SimulationState get_current_simulation_state(); void remove_simulation_state(unsigned int index); float get_animation_duration(); - -private: +private: void update_time_step(); - ch::Timeline m_timeline; + ch::Timeline m_timeline; float m_animation_duration; std::list m_simulation_states; @@ -74,22 +71,19 @@ class Simulation std::vector> m_vec3_sequences; std::vector> m_float_sequences; - ch::Output m_target_animation; - ch::Output m_eye_animation; - ch::Output m_up_animation; - ch::Output m_radius_animation; - ch::Output m_max_clip_animation; - ch::Output m_min_clip_animation; + ch::Output m_target_animation; + ch::Output m_eye_animation; + ch::Output m_up_animation; + ch::Output m_radius_animation; + ch::Output m_max_clip_animation; + ch::Output m_min_clip_animation; bool m_is_animate_path; - ANIMATION_STATE m_animation_state; std::string animation_button_label; - VRVolumeApp& m_controller_app; - - + VRVolumeApp &m_controller_app; }; #endif \ No newline at end of file diff --git a/include/loader/VRDataLoader.h b/include/loader/VRDataLoader.h index ee1d664..e99ea7e 100644 --- a/include/loader/VRDataLoader.h +++ b/include/loader/VRDataLoader.h @@ -4,21 +4,12 @@ #include class VRVolumeApp; - class VRDataLoader { public: - VRDataLoader(); - - static void load_txt_file( VRVolumeApp& vrVolumeApp, std::string& filename); - - -private: - - + static void load_txt_file(VRVolumeApp &vrVolumeApp, std::string &filename); }; #endif - diff --git a/include/render/VolumeRenderer.h b/include/render/VolumeRenderer.h index 2ea3f1f..9db1d96 100644 --- a/include/render/VolumeRenderer.h +++ b/include/render/VolumeRenderer.h @@ -50,13 +50,6 @@ class VolumeRenderer virtual void setClipMinMax(glm::vec3 min_clip, glm::vec3 max_clip) = 0; - - void set_animation() - { - - } - - void setClipping(bool isClipping, glm::mat4 * clipPlane) { m_clipping = isClipping; diff --git a/include/vrapp/VRVolumeApp.h b/include/vrapp/VRVolumeApp.h index 48d2681..06c9fc4 100644 --- a/include/vrapp/VRVolumeApp.h +++ b/include/vrapp/VRVolumeApp.h @@ -24,7 +24,7 @@ class Texture; class Simulation; class Labels; -enum MovieState +enum MOVIESTATE { MOVIE_STOP, MOVIE_RECORD @@ -42,12 +42,8 @@ class VRVolumeApp VRVolumeApp(); - - ~VRVolumeApp(); - - void render(const MinVR::VRGraphicsState& renderState); void initialize(); @@ -185,7 +181,7 @@ class VRVolumeApp std::string get_movie_state_label(); - MovieState get_movie_state(); + MOVIESTATE get_movie_state(); void set_app_mode(APPMODE ); @@ -314,7 +310,7 @@ class VRVolumeApp Simulation* m_simulation; - MovieState m_current_movie_state; + MOVIESTATE m_current_movie_state; bool m_stop_movie; APPMODE m_app_mode; diff --git a/include/vrapp/VolumeVisualizationApp.h b/include/vrapp/VolumeVisualizationApp.h index 2ff658f..d4a7f5d 100644 --- a/include/vrapp/VolumeVisualizationApp.h +++ b/include/vrapp/VolumeVisualizationApp.h @@ -22,7 +22,6 @@ #include #endif - #include "VRMenuHandler.h" #include "UIHelpers/transfer_function_multichannel_widget.h" #include "UIHelpers/transfer_function_widget.h" @@ -34,8 +33,6 @@ #include "render/DepthTexture.h" #include - - using namespace MinVR; #include @@ -51,7 +48,6 @@ using namespace MinVR; #include "../render/VolumeSliceRenderer.h" #include "../interaction/CreateMovieAction.h" - #include "ShaderProgram.h" #include "VRVolumeApp.h" @@ -61,72 +57,50 @@ class Texture; class UIView; class VRVolumeApp; -class VolumeVisualizationApp : public VRApp { +class VolumeVisualizationApp : public VRApp +{ public: - /** The constructor passes argc, argv, and a MinVR config file on to VRApp. */ - VolumeVisualizationApp(int argc, char** argv); + VolumeVisualizationApp(int argc, char **argv); virtual ~VolumeVisualizationApp(); - - /** USER INTERFACE CALLBACKS **/ - virtual void onCursorMove(const VRCursorEvent& state); + virtual void onCursorMove(const VRCursorEvent &state); - virtual void onAnalogChange(const VRAnalogEvent& state); + virtual void onAnalogChange(const VRAnalogEvent &state); - virtual void onButtonDown(const VRButtonEvent& state); + virtual void onButtonDown(const VRButtonEvent &state); - virtual void onButtonUp(const VRButtonEvent& state); + virtual void onButtonUp(const VRButtonEvent &state); - virtual void onTrackerMove(const VRTrackerEvent& state); + virtual void onTrackerMove(const VRTrackerEvent &state); - virtual void onGenericEvent(const VRDataIndex& index); + virtual void onGenericEvent(const VRDataIndex &index); /** RENDERING CALLBACKS **/ - virtual void onRenderGraphicsScene(const VRGraphicsState& state); - - virtual void onRenderGraphicsContext(const VRGraphicsState& state); - + virtual void onRenderGraphicsScene(const VRGraphicsState &state); + virtual void onRenderGraphicsContext(const VRGraphicsState &state); private: - int width; int height; - GLfloat m_light_pos[4]; - unsigned int rendercount; - - - std::chrono::steady_clock::time_point m_lastTime; - - - VRVolumeApp* m_vrVolumeApp; + VRVolumeApp *m_vrVolumeApp; int m_num_frames; - const double fps_Limit = 1.0 / 60.0; - std::chrono::steady_clock::time_point last_Update_Time ; // number of seconds since the last loop - - float v1 = 0.0f; - float v2 = 100.0f; - - //std::vector control_points - glm::vec3 pos1 = glm::vec3(1.0f, 0.0f, 10.0f); - glm::vec3 pos2 = glm::vec3(50.0f, 150.0f, 50.0f); - glm::vec3 pos3 = glm::vec3(-10.0f, 100.0f, 250.0f); - glm::vec3 pos4 = glm::vec3(-10.0f, 180.0f, 290.0f); + const double fps_limit = 1.0 / 60.0; + std::chrono::steady_clock::time_point last_Update_Time; // number of seconds since the last loop }; - #endif \ No newline at end of file diff --git a/libs/Model/Model.cpp b/libs/Model/Model.cpp index 93e20bd..ed9e3df 100644 --- a/libs/Model/Model.cpp +++ b/libs/Model/Model.cpp @@ -3,70 +3,57 @@ #include #include "ShaderProgram.h" -Model::Model():m_position(0),m_orientation(glm::quat()),m_scale(1), m_bounding_volumen_radius(1) +Model::Model() : m_position(0), m_orientation(glm::quat()), m_scale(1), m_bounding_volumen_radius(1) { - } - Model::~Model() { delete m_Obj_Model; - + delete m_texture; - } -VertexBuffer& Model::objModel() const +VertexBuffer &Model::objModel() const { return *m_Obj_Model; } -void Model::setObjModel(VertexBuffer* val) +void Model::setObjModel(VertexBuffer *val) { m_Obj_Model = val; } -Texture& Model::texture(int index) const +Texture &Model::texture(int index) const { return *m_texture; } -void Model::setTexture(Texture* val) +void Model::setTexture(Texture *val) { m_texture = val; } -void Model::render(ShaderProgram& shaderProgram) +void Model::render(ShaderProgram &shaderProgram) { - - /*glm::mat4 m_model = glm::mat4(1.0f); - m_model *= glm::translate(myPosition); - m_model *= glm::toMat4(myOrientation); - m_model *= glm::scale(myScale);*/ - - //shaderProgram.setUniform("m", m_model); shaderProgram.setUniform("mv", m_model_view_mtrx); assert(m_Obj_Model && "NO MODEL TO RENDER"); // bind texture - m_texture->Bind(0); - - //render geometry + // render geometry if (m_Obj_Model) { m_Obj_Model->render(); } - //Unbind Text - - m_texture->UnBind(0); - + // Unbind Text + + m_texture->UnBind(0); } -glm::vec3& Model::position() +glm::vec3 &Model::position() { return m_position; } @@ -76,7 +63,7 @@ void Model::setPosition(glm::vec3 val) m_position = val; } -glm::quat& Model::orientation() +glm::quat &Model::orientation() { return m_orientation; } @@ -86,7 +73,7 @@ void Model::setOrientation(glm::quat val) m_orientation = val; } -glm::vec3& Model::scale() +glm::vec3 &Model::scale() { return m_scale; } @@ -106,38 +93,34 @@ void Model::setBoundingVolumenRadius(float val) m_bounding_volumen_radius = val; } -bool Model::RayInstersection(const glm::vec3& start, const glm::vec3& rayDirection) +bool Model::RayInstersection(const glm::vec3 &start, const glm::vec3 &rayDirection) { - - glm::vec3 Position = m_position; - float b = 2.f * (rayDirection.x * (start.x - Position.x) + - rayDirection.y * (start.y - Position.y) + rayDirection.z * (start.z - Position.z)); - float c = start.x * start.x - 2.f * start.x * Position.x + Position.x * Position.x - + start.y * start.y - 2.f * start.y * Position.y + Position.y * Position.y - + start.z * start.z - 2.f * start.z * Position.z + Position.z * Position.z - m_bounding_volumen_radius * m_bounding_volumen_radius; + glm::vec3 Position = m_position; - float discr = (b * b - 4.f * c); - if (discr < 0.f) - { - m_selected = false; - - } - else - { - m_selected = true; - - } + float b = 2.f * (rayDirection.x * (start.x - Position.x) + + rayDirection.y * (start.y - Position.y) + rayDirection.z * (start.z - Position.z)); + float c = start.x * start.x - 2.f * start.x * Position.x + Position.x * Position.x + start.y * start.y - 2.f * start.y * Position.y + Position.y * Position.y + start.z * start.z - 2.f * start.z * Position.z + Position.z * Position.z - m_bounding_volumen_radius * m_bounding_volumen_radius; + + float discr = (b * b - 4.f * c); + if (discr < 0.f) + { + m_selected = false; + } + else + { + m_selected = true; + } - return m_selected; + return m_selected; } bool Model::isSelected() { - return m_selected; + return m_selected; } void Model::seleted(bool selected) { - m_selected = selected; + m_selected = selected; } diff --git a/libs/Texture/Texture.cpp b/libs/Texture/Texture.cpp index 25e34c0..7abcb3e 100644 --- a/libs/Texture/Texture.cpp +++ b/libs/Texture/Texture.cpp @@ -3,20 +3,18 @@ #include #include - -Texture::Texture(GLenum TextureTarget, const std::string& filename) : m_texture_target(TextureTarget) -, m_file_name(filename.c_str()) +Texture::Texture(GLenum TextureTarget, const std::string &filename) : m_texture_target(TextureTarget), m_file_name(filename.c_str()) { m_texture_id = Load2DTexture(); } - + Texture::~Texture() { } -void Texture::Bind(GLenum TextureUnit) +void Texture::Bind() { - glActiveTexture(GL_TEXTURE0 + 0); + glActiveTexture(GL_TEXTURE0); glBindTexture(m_texture_target, m_texture_id); } @@ -25,109 +23,104 @@ GLuint Texture::GetTextureId() return m_texture_id; } -void Texture::UnBind(GLenum TextureUnit) +void Texture::UnBind() { - glActiveTexture(GL_TEXTURE0 + TextureUnit); - glBindTexture(m_texture_target, 0); + glActiveTexture(GL_TEXTURE0); + glBindTexture(m_texture_target, 0); } int Texture::Load2DTexture() { - int width = 0; int height = 0; int bbp = 0; - //pointer to the image data - unsigned char * bits(0); + // pointer to the image data + unsigned char *bits(0); - //retrieve the image data - //if this somehow one of these failed (they shouldn't), return failure + // retrieve the image data + // if this somehow one of these failed (they shouldn't), return failure GLuint textureID = LoadTexture(m_file_name, width, height, &bits, bbp); if (textureID == -1) { assert(false && "Image failed to load 2"); } - return textureID; } -int Texture::Load3DTexture(const std::vector& paths) +int Texture::Load3DTexture(const std::vector &paths) { - if (paths.size() == 0) - { - assert(false && "no paths to load from"); - } + if (paths.size() == 0) + { + assert(false && "no paths to load from"); + } - GLsizei width, height, depth = paths.size(); + GLsizei width, height, depth = paths.size(); - std::vector formatedImages(paths.size()); + std::vector formatedImages(paths.size()); - // load and format each image - for (int i = 0; i < paths.size(); ++i) - { - BYTE* bits(0); + // load and format each image + for (int i = 0; i < paths.size(); ++i) + { + BYTE *bits(0); int bbp = 0; - if (!LoadTexture(paths[i], width, height, &bits, bbp)) - { - assert(false && "Image failed to load 2"); - } - image img(width, height, bits); - formatedImages[i] = img; - } - - GLuint textureID; - glGenTextures(1, &textureID); - glBindTexture(GL_TEXTURE_2D_ARRAY, textureID); - //Create storage for the texture. (100 layers of 1x1 texels) - glTexStorage3D(GL_TEXTURE_2D_ARRAY, - 1, //No mipmaps as textures are 1x1 - GL_RGBA8, //Internal format - width, height, //width,height - depth //Number of layers - ); - - for (unsigned int i = 0; i < formatedImages.size(); ++i) - { - //Specify i-essim image - glTexSubImage3D(GL_TEXTURE_2D_ARRAY, - 0, //Mipmap number - 0, 0, i, //xoffset, yoffset, zoffset - formatedImages[i].imageWidth, formatedImages[i].imageHeight, 1, //width, height, depth - GL_RGB, //format - GL_UNSIGNED_BYTE, //type - formatedImages[i].imageData); //pointer to data - } - - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); - - - glBindTexture(GL_TEXTURE_2D_ARRAY, 0); - // Return the ID of the texture we just created - return textureID; + if (!LoadTexture(paths[i], width, height, &bits, bbp)) + { + assert(false && "Image failed to load 2"); + } + image img(width, height, bits); + formatedImages[i] = img; + } + GLuint textureID; + glGenTextures(1, &textureID); + glBindTexture(GL_TEXTURE_2D_ARRAY, textureID); + // Create storage for the texture. (100 layers of 1x1 texels) + glTexStorage3D(GL_TEXTURE_2D_ARRAY, + 1, // No mipmaps as textures are 1x1 + GL_RGBA8, // Internal format + width, height, // width,height + depth // Number of layers + ); + + for (unsigned int i = 0; i < formatedImages.size(); ++i) + { + // Specify i-essim image + glTexSubImage3D(GL_TEXTURE_2D_ARRAY, + 0, // Mipmap number + 0, 0, i, // xoffset, yoffset, zoffset + formatedImages[i].imageWidth, formatedImages[i].imageHeight, 1, // width, height, depth + GL_RGB, // format + GL_UNSIGNED_BYTE, // type + formatedImages[i].imageData); // pointer to data + } + + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glBindTexture(GL_TEXTURE_2D_ARRAY, 0); + // Return the ID of the texture we just created + return textureID; } -int Texture::LoadTexture(const std::string & fileName, - int & width, int & height, unsigned char ** data, int& bbp) +int Texture::LoadTexture(const std::string &fileName, + int &width, int &height, unsigned char **data, int &bbp) { - unsigned int texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); // all upcoming GL_TEXTURE_2D operations now have effect on this texture object // set the texture wrapping parameters - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // set texture filtering parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - //int width, height, nrChannels; + + // int width, height, nrChannels; stbi_set_flip_vertically_on_load(1); *data = stbi_load(fileName.c_str(), &width, &height, &bbp, 0); @@ -135,23 +128,23 @@ int Texture::LoadTexture(const std::string & fileName, { if (bbp == 3) { - //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, *data); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height,0, GL_RGB, GL_UNSIGNED_BYTE, *data); + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, *data); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, *data); } else if (bbp == 4) { - //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, *data); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,0, GL_RGBA, GL_UNSIGNED_BYTE, *data); + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, *data); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, *data); } - - //glGenerateMipmap(GL_TEXTURE_2D); + + // glGenerateMipmap(GL_TEXTURE_2D); } else { std::cout << "Failed to load texture" << std::endl; return -1; } - glBindTexture(GL_TEXTURE_2D,0); + glBindTexture(GL_TEXTURE_2D, 0); stbi_image_free(*data); return texture; diff --git a/libs/Texture/Texture.h b/libs/Texture/Texture.h index 9f4fb89..490a19b 100644 --- a/libs/Texture/Texture.h +++ b/libs/Texture/Texture.h @@ -31,9 +31,9 @@ class Texture Texture(GLenum TextureTarget, const std::string& filename); ~Texture(); - void Bind(GLenum TextureUnit); + void Bind(); GLuint GetTextureId(); - void UnBind(GLenum TextureUnit); + void UnBind(); int LoadTexture(const std::string& fileName, int& width, int& height, unsigned char ** data, int& bbp); diff --git a/libs/UIHelpers/transfer_function_widget.cpp b/libs/UIHelpers/transfer_function_widget.cpp index 2e7bb31..5dce27b 100644 --- a/libs/UIHelpers/transfer_function_widget.cpp +++ b/libs/UIHelpers/transfer_function_widget.cpp @@ -29,7 +29,6 @@ #include "embedded_colormaps.h" #include "../../include/render/FontHandler.h" - #ifndef TFN_WIDGET_NO_STB_IMAGE_IMPL #define STB_IMAGE_IMPLEMENTATION #endif @@ -39,22 +38,22 @@ template T clamp(T x, T min, T max) { - if (x < min) { + if (x < min) + { return min; } - if (x > max) { + if (x > max) + { return max; } return x; } -Colormap::Colormap(const std::string& name, const std::vector& img) - : name(name), colormap(img) +Colormap::Colormap(const std::string &name, const std::vector &img) + : name(name), colormap(img) { } - - TransferFunctionWidget::TransferFunctionWidget() { // Load up the embedded colormaps as the default options @@ -70,19 +69,17 @@ TransferFunctionWidget::TransferFunctionWidget() load_embedded_preset(blue_gold, sizeof(blue_gold), "Blue Gold"); load_embedded_preset(ice_fire, sizeof(ice_fire), "Ice Fire"); load_embedded_preset(nic_edge, sizeof(nic_edge), "nic Edge"); - //load_embedded_preset(Algae, sizeof(Algae), "Algae"); + // load_embedded_preset(Algae, sizeof(Algae), "Algae"); // Initialize the colormap alpha channel w/ a linear ramp update_colormap(); for (int i = 0; i < 256; i++) { - //current_histogram.push_back(static_cast (rand()) / static_cast (RAND_MAX)); + // current_histogram.push_back(static_cast (rand()) / static_cast (RAND_MAX)); current_histogram.push_back(0); } - - m_min_max_val[0] = 0.0f; m_min_max_val[1] = 1.0f; @@ -90,7 +87,7 @@ TransferFunctionWidget::TransferFunctionWidget() m_quantiles[1] = 0.95f; } -void TransferFunctionWidget::add_colormap(const Colormap& map) +void TransferFunctionWidget::add_colormap(const Colormap &map) { colormaps.push_back(map); } @@ -100,16 +97,19 @@ void TransferFunctionWidget::draw_ui() update_gpu_image(); colormap_changed = false; - const ImGuiIO& io = ImGui::GetIO(); + const ImGuiIO &io = ImGui::GetIO(); ImGui::Text("Transfer Function"); ImGui::TextWrapped( - "Left click to add a point, right click remove. " - "Left click + drag to move points."); + "Left click to add a point, right click remove. " + "Left click + drag to move points."); - if (ImGui::BeginCombo("Colormap", colormaps[selected_colormap].name.c_str())) { - for (size_t i = 0; i < colormaps.size(); ++i) { - if (ImGui::Selectable(colormaps[i].name.c_str(), selected_colormap == i)) { + if (ImGui::BeginCombo("Colormap", colormaps[selected_colormap].name.c_str())) + { + for (size_t i = 0; i < colormaps.size(); ++i) + { + if (ImGui::Selectable(colormaps[i].name.c_str(), selected_colormap == i)) + { selected_colormap = i; update_colormap(); } @@ -120,13 +120,13 @@ void TransferFunctionWidget::draw_ui() vec2f canvas_size = ImGui::GetContentRegionAvail(); // Note: If you're not using OpenGL for rendering your UI, the setup for // displaying the colormap texture in the UI will need to be updated. - ImGui::Image(reinterpret_cast(colormap_img), ImVec2(canvas_size.x, 16)); + ImGui::Image(reinterpret_cast(colormap_img), ImVec2(canvas_size.x, 16)); vec2f canvas_pos = ImGui::GetCursorScreenPos(); canvas_size.y -= 80; const float point_radius = 20.f; - ImDrawList* draw_list = ImGui::GetWindowDrawList(); + ImDrawList *draw_list = ImGui::GetWindowDrawList(); draw_list->PushClipRect(canvas_pos, canvas_pos + canvas_size); const vec2f view_scale(canvas_size.x, -canvas_size.y); @@ -135,65 +135,78 @@ void TransferFunctionWidget::draw_ui() draw_list->AddRect(canvas_pos, canvas_pos + canvas_size, ImColor(180, 180, 180, 255)); ImGui::InvisibleButton("tfn_canvas", canvas_size); - if (ImGui::IsItemHovered() || selected_point != (size_t)-1) { + if (ImGui::IsItemHovered() || selected_point != (size_t)-1) + { vec2f mouse_pos = (vec2f(io.MousePos) - view_offset) / view_scale; mouse_pos.x = clamp(mouse_pos.x, 0.f, 1.f); mouse_pos.y = clamp(mouse_pos.y, 0.f, 1.f); - - if (io.MouseDown[0]) { - if (selected_point != (size_t)-1) { + if (io.MouseDown[0]) + { + if (selected_point != (size_t)-1) + { alpha_control_pts[selected_point] = mouse_pos; - //make sure point does not cross + // make sure point does not cross - // Keep the first and last control points at the edges - if (selected_point == 0) { + // Keep the first and last control points at the edges + if (selected_point == 0) + { alpha_control_pts[selected_point].x = 0.f; } - else if (selected_point == alpha_control_pts.size() - 1) { + else if (selected_point == alpha_control_pts.size() - 1) + { alpha_control_pts[selected_point].x = 1.f; } - //make sure the other points do not cross + // make sure the other points do not cross else { alpha_control_pts[selected_point].x = (alpha_control_pts[selected_point].x < alpha_control_pts[selected_point - 1].x) - ? alpha_control_pts[selected_point - 1].x + 0.01 : alpha_control_pts[selected_point].x; + ? alpha_control_pts[selected_point - 1].x + 0.01 + : alpha_control_pts[selected_point].x; alpha_control_pts[selected_point].x = (alpha_control_pts[selected_point].x > alpha_control_pts[selected_point + 1].x) - ? alpha_control_pts[selected_point + 1].x - 0.01 : alpha_control_pts[selected_point].x; + ? alpha_control_pts[selected_point + 1].x - 0.01 + : alpha_control_pts[selected_point].x; } } - else { + else + { // See if we're selecting a point or adding one - if (io.MousePos.x - canvas_pos.x <= point_radius) { + if (io.MousePos.x - canvas_pos.x <= point_radius) + { selected_point = 0; } - else if (io.MousePos.x - canvas_pos.x >= canvas_size.x - point_radius) { + else if (io.MousePos.x - canvas_pos.x >= canvas_size.x - point_radius) + { selected_point = alpha_control_pts.size() - 1; } - else { + else + { auto fnd = std::find_if( - alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f& p) { + alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f &p) + { const vec2f pt_pos = p * view_scale + view_offset; float dist = (pt_pos - vec2f(io.MousePos)).length(); - return dist <= point_radius; - }); + return dist <= point_radius; }); // No nearby point, we're adding a new one - if (fnd == alpha_control_pts.end()) { + if (fnd == alpha_control_pts.end()) + { alpha_control_pts.push_back(mouse_pos); // Keep alpha control points ordered by x coordinate, update // selected point index to match std::sort(alpha_control_pts.begin(), - alpha_control_pts.end(), - [](const vec2f& a, const vec2f& b) { return a.x < b.x; }); - if (selected_point != 0 && selected_point != alpha_control_pts.size() - 1) { + alpha_control_pts.end(), + [](const vec2f &a, const vec2f &b) + { return a.x < b.x; }); + if (selected_point != 0 && selected_point != alpha_control_pts.size() - 1) + { fnd = std::find_if( - alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f& p) { + alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f &p) + { const vec2f pt_pos = p * view_scale + view_offset; float dist = (pt_pos - vec2f(io.MousePos)).length(); - return dist <= point_radius; - }); + return dist <= point_radius; }); } } selected_point = std::distance(alpha_control_pts.begin(), fnd); @@ -201,23 +214,26 @@ void TransferFunctionWidget::draw_ui() } update_colormap(); } - else if (ImGui::IsMouseClicked(1)) { + else if (ImGui::IsMouseClicked(1)) + { selected_point = -1; // Find and remove the point auto fnd = std::find_if( - alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f& p) { + alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f &p) + { const vec2f pt_pos = p * view_scale + view_offset; float dist = (pt_pos - vec2f(io.MousePos)).length(); - return dist <= point_radius; - }); + return dist <= point_radius; }); // We also want to prevent erasing the first and last points if (fnd != alpha_control_pts.end() && fnd != alpha_control_pts.begin() && - fnd != alpha_control_pts.end() - 1) { + fnd != alpha_control_pts.end() - 1) + { alpha_control_pts.erase(fnd); } update_colormap(); } - else { + else + { selected_point = -1; } } @@ -225,17 +241,17 @@ void TransferFunctionWidget::draw_ui() // Draw the alpha control points, and build the points for the polyline // which connects them std::vector polyline_pts; - for (const auto& pt : alpha_control_pts) { + for (const auto &pt : alpha_control_pts) + { const vec2f pt_pos = pt * view_scale + view_offset; polyline_pts.push_back(pt_pos); draw_list->AddCircleFilled(pt_pos, point_radius, 0xFFFFFFFF); } - draw_list->AddPolyline(polyline_pts.data(), polyline_pts.size(), 0xFFFFFFFF, false, 2.f); draw_list->PopClipRect(); - //Add Label tick marks + // Add Label tick marks int nbTicks = 5; vec2f tick_pos = ImGui::GetCursorScreenPos(); tick_pos.y -= ImGui::GetStyle().ItemSpacing.y; @@ -243,27 +259,32 @@ void TransferFunctionWidget::draw_ui() tick_size.y = 5; draw_list->PushClipRect(tick_pos, ImVec2(tick_pos.x + tick_size.x, tick_pos.y + tick_size.y)); - for (int i = 0; i < nbTicks; i++) { + for (int i = 0; i < nbTicks; i++) + { float percentage = float(i) / (nbTicks - 1); draw_list->AddLine(ImVec2(tick_pos.x + percentage * (tick_size.x - 1), tick_size.y), - ImVec2(tick_pos.x + percentage * (tick_size.x - 1), tick_pos.y + tick_size.y), ImColor(255, 255, 255, 255), 1); + ImVec2(tick_pos.x + percentage * (tick_size.x - 1), tick_pos.y + tick_size.y), ImColor(255, 255, 255, 255), 1); } draw_list->PopClipRect(); - //Add Label text + // Add Label text const float ItemSpacing = ImGui::GetStyle().ItemSpacing.x; - for (int i = 0; i < nbTicks; i++) { + for (int i = 0; i < nbTicks; i++) + { float percentage = float(i) / (nbTicks - 1); float val = (m_min_max_val[1] - m_min_max_val[0]) * percentage + m_min_max_val[0]; std::stringstream text; text << std::fixed << std::setprecision(4) << val; - if (i == 0) { + if (i == 0) + { } - else if (i == nbTicks - 1) { + else if (i == nbTicks - 1) + { ImGui::SameLine(ImGui::GetWindowWidth() - ItemSpacing - ImGui::CalcTextSize(text.str().c_str()).x); } - else { + else + { ImGui::SameLine((ImGui::GetWindowWidth()) * percentage - ImGui::CalcTextSize(text.str().c_str()).x * 0.5); } ImGui::Text(text.str().c_str()); @@ -283,29 +304,30 @@ std::vector TransferFunctionWidget::get_colormap() std::vector TransferFunctionWidget::get_colormapf() { std::vector colormapf(current_colormap.size(), 0.f); - for (size_t i = 0; i < current_colormap.size(); ++i) { + for (size_t i = 0; i < current_colormap.size(); ++i) + { colormapf[i] = current_colormap[i] / 255.f; } return colormapf; } -void TransferFunctionWidget::setHistogram(const std::vector& hist) +void TransferFunctionWidget::setHistogram(const std::vector &hist) { current_histogram = hist; } -std::vector& TransferFunctionWidget::getHistogram() +std::vector &TransferFunctionWidget::getHistogram() { return current_histogram; } -void TransferFunctionWidget::setMinMax(const float min, const float max) { +void TransferFunctionWidget::setMinMax(const float min, const float max) +{ m_min_max_val[0] = min; m_min_max_val[1] = max; } - -void TransferFunctionWidget::setBlendedHistogram(const std::vector& hist1, const std::vector& hist2, float alpha) +void TransferFunctionWidget::setBlendedHistogram(const std::vector &hist1, const std::vector &hist2, float alpha) { if (hist1.size() != hist2.size()) return; @@ -315,12 +337,12 @@ void TransferFunctionWidget::setBlendedHistogram(const std::vector& hist1 current_histogram.push_back(hist1[i] * alpha + hist2[i] * (1.0f - alpha)); } - -void TransferFunctionWidget::get_colormapf(std::vector& color, std::vector& opacity) +void TransferFunctionWidget::get_colormapf(std::vector &color, std::vector &opacity) { color.resize((current_colormap.size() / 4) * 3); opacity.resize(current_colormap.size() / 4); - for (size_t i = 0; i < current_colormap.size() / 4; ++i) { + for (size_t i = 0; i < current_colormap.size() / 4; ++i) + { color[i * 3] = current_colormap[i * 4] / 255.f; color[i * 3 + 1] = current_colormap[i * 4 + 1] / 255.f; color[i * 3 + 2] = current_colormap[i * 4 + 2] / 255.f; @@ -328,14 +350,14 @@ void TransferFunctionWidget::get_colormapf(std::vector& color, std::vecto } } -void TransferFunctionWidget::drawLegend() { +void TransferFunctionWidget::draw_legend() +{ GLint viewport[4]; GLfloat projection[16]; GLfloat modelview[16]; - int min[2] = { 50 , 100 }; - int max[2] = { 400 , 120 }; - + int min[2] = {50, 100}; + int max[2] = {400, 120}; glGetIntegerv(GL_VIEWPORT, &viewport[0]); glGetFloatv(GL_PROJECTION_MATRIX, &projection[0]); @@ -383,12 +405,11 @@ void TransferFunctionWidget::drawLegend() { glBindTexture(GL_TEXTURE_2D, 0); - - - //Add Label tick marks + // Add Label tick marks int nbTicks = 4; float diff = (max[0] - min[0]) / nbTicks; - for (int i = 0; i <= nbTicks; i++) { + for (int i = 0; i <= nbTicks; i++) + { float pos_x = min[0] + i * diff; glBegin(GL_LINES); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); @@ -410,27 +431,24 @@ void TransferFunctionWidget::drawLegend() { glLoadMatrixf(projection); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(modelview); - - - } -void TransferFunctionWidget::drawLegend( float legend_pos_x, float legend_pos_y, float legend_width, float legend_height) +void TransferFunctionWidget::draw_legend(float legend_pos_x, float legend_pos_y, float legend_width, float legend_height) { bool show_legend = true; ImGui::SetNextWindowPos(ImVec2(legend_pos_x, legend_pos_y)); ImGui::SetNextWindowSize(ImVec2(legend_width, legend_height)); ImGui::Begin("##legend", &show_legend, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); - ImGuiIO& io = ImGui::GetIO(); + ImGuiIO &io = ImGui::GetIO(); ImTextureID my_tex_id = io.Fonts->TexID; float my_tex_w = (float)io.Fonts->TexWidth; float my_tex_h = (float)io.Fonts->TexHeight; std::string max_str = std::to_string(m_min_max_val[1]); float offset = 0.008 * (my_tex_w * max_str.size()); - ImGui::Image(reinterpret_cast(colormap_img), ImVec2(legend_width, 16)); + ImGui::Image(reinterpret_cast(colormap_img), ImVec2(legend_width, 16)); ImGui::Text("%.0f", m_min_max_val[0]); - ImGui::SameLine((legend_width /2) ); - ImGui::Text("%.0f", (m_min_max_val[0]+ m_min_max_val[1]) /2); + ImGui::SameLine((legend_width / 2)); + ImGui::Text("%.0f", (m_min_max_val[0] + m_min_max_val[1]) / 2); ImGui::SameLine(ImGui::GetWindowWidth() - offset); ImGui::Text(" %.0f", m_min_max_val[1]); ImGui::End(); @@ -439,18 +457,18 @@ void TransferFunctionWidget::drawLegend( float legend_pos_x, float legend_pos_y, void TransferFunctionWidget::draw_histogram() { - const ImGuiIO& io = ImGui::GetIO(); + const ImGuiIO &io = ImGui::GetIO(); ImGui::Text("Histogram"); vec2f canvas_size = ImGui::GetContentRegionAvail(); // Note: If you're not using OpenGL for rendering your UI, the setup for // displaying the colormap texture in the UI will need to be updated. - // ImGui::Image(reinterpret_cast(colormap_img), ImVec2(canvas_size.x, 16)); + // ImGui::Image(reinterpret_cast(colormap_img), ImVec2(canvas_size.x, 16)); vec2f canvas_pos = ImGui::GetCursorScreenPos(); canvas_size.y -= 250; - ImDrawList* draw_list = ImGui::GetWindowDrawList(); + ImDrawList *draw_list = ImGui::GetWindowDrawList(); draw_list->PushClipRect(canvas_pos, canvas_pos + canvas_size); const vec2f view_scale(canvas_size.x, -canvas_size.y); @@ -460,24 +478,18 @@ void TransferFunctionWidget::draw_histogram() ImGui::InvisibleButton("hstg_canvas", canvas_size); - // Draw the alpha control points, and build the points for the polyline // which connects them - - //Code to Draw histogram in the UI - for (int i = 0; i < current_histogram.size(); i++) { + // Code to Draw histogram in the UI + for (int i = 0; i < current_histogram.size(); i++) + { vec2f lp = vec2f(((float)i) / current_histogram.size(), 0.0f); vec2f hp = vec2f(((float)i + 1.0f) / current_histogram.size(), current_histogram[i]); draw_list->AddRectFilled(lp * view_scale + view_offset, hp * view_scale + view_offset, 0x77777777); } - draw_list->PopClipRect(); - - - - } void TransferFunctionWidget::update_gpu_image() @@ -485,7 +497,8 @@ void TransferFunctionWidget::update_gpu_image() GLint prev_tex_2d = 0; glGetIntegerv(GL_TEXTURE_BINDING_2D, &prev_tex_2d); - if (colormap_img == (GLuint)-1) { + if (colormap_img == (GLuint)-1) + { glGenTextures(1, &colormap_img); glBindTexture(GL_TEXTURE_2D, colormap_img); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -493,19 +506,21 @@ void TransferFunctionWidget::update_gpu_image() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } - if (colormap_changed) { + if (colormap_changed) + { glBindTexture(GL_TEXTURE_2D, colormap_img); glTexImage2D(GL_TEXTURE_2D, - 0, - GL_RGBA, - current_colormap.size() / 4, - 1, - 0, - GL_RGBA, - GL_UNSIGNED_BYTE, - current_colormap.data()); + 0, + GL_RGBA, + current_colormap.size() / 4, + 1, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + current_colormap.data()); } - if (prev_tex_2d != 0) { + if (prev_tex_2d != 0) + { glBindTexture(GL_TEXTURE_2D, prev_tex_2d); } } @@ -519,10 +534,12 @@ void TransferFunctionWidget::update_colormap() auto a_it = alpha_control_pts.begin(); const size_t npixels = current_colormap.size() / 4; - for (size_t i = 0; i < npixels; ++i) { + for (size_t i = 0; i < npixels; ++i) + { float x = static_cast(i) / npixels; auto high = a_it + 1; - if (x > high->x) { + if (x > high->x) + { ++a_it; ++high; } @@ -538,21 +555,19 @@ void TransferFunctionWidget::set_Quantiles(float min, float max) m_quantiles[1] = max; } - -void TransferFunctionWidget::get_Quantiles(float& min, float& max) +void TransferFunctionWidget::get_Quantiles(float &min, float &max) { min = m_quantiles[0]; max = m_quantiles[1]; } -void TransferFunctionWidget::load_embedded_preset(const uint8_t* buf, - size_t size, - const std::string& name) +void TransferFunctionWidget::load_embedded_preset(const uint8_t *buf, + size_t size, + const std::string &name) { int w, h, n; - uint8_t* img_data = stbi_load_from_memory(buf, size, &w, &h, &n, 4); + uint8_t *img_data = stbi_load_from_memory(buf, size, &w, &h, &n, 4); auto img = std::vector(img_data, img_data + w * 1 * 4); stbi_image_free(img_data); colormaps.emplace_back(name, img); } - diff --git a/libs/UIHelpers/transfer_function_widget.h b/libs/UIHelpers/transfer_function_widget.h index ea592ae..7a15b1c 100644 --- a/libs/UIHelpers/transfer_function_widget.h +++ b/libs/UIHelpers/transfer_function_widget.h @@ -1,7 +1,6 @@ #ifndef TransferFunctionWidget_H_ #define TransferFunctionWidget_H_ - #ifdef _WIN32 #include "GL/glew.h" #include "GL/wglew.h" @@ -23,107 +22,98 @@ #include #endif - - - #include #include #include #include "imgui/imgui.h" #include "Vec2.h" -struct Colormap { - std::string name; - // An RGBA8 1D image - std::vector colormap; +struct Colormap +{ + std::string name; + // An RGBA8 1D image + std::vector colormap; - Colormap(const std::string &name, const std::vector &img); + Colormap(const std::string &name, const std::vector &img); }; -class TransferFunctionWidget { - +class TransferFunctionWidget +{ - std::vector colormaps; - - std::vector current_colormap; + std::vector colormaps; - - size_t selected_point = -1; + std::vector current_colormap; - bool colormap_changed = true; - GLuint colormap_img = -1; + size_t selected_point = -1; - std::vector current_histogram; - float m_min_max_val[2]; + bool colormap_changed = true; + GLuint colormap_img = -1; -public: + std::vector current_histogram; + float m_min_max_val[2]; - +public: size_t selected_colormap = 0; - std::vector alpha_control_pts = { vec2f(0.f), vec2f(1.f) }; + std::vector alpha_control_pts = {vec2f(0.f), vec2f(1.f)}; - TransferFunctionWidget(); + TransferFunctionWidget(); - // Add a colormap preset. The image should be a 1D RGBA8 image - void add_colormap(const Colormap &map); + // Add a colormap preset. The image should be a 1D RGBA8 image + void add_colormap(const Colormap &map); - // Add the transfer function UI into the currently active window - void draw_ui(); + // Add the transfer function UI into the currently active window + void draw_ui(); - // Returns true if the colormap was updated since the last - // call to draw_ui - bool changed() const; + // Returns true if the colormap was updated since the last + // call to draw_ui + bool changed() const; - // Get back the RGBA8 color data for the transfer function - std::vector get_colormap(); + // Get back the RGBA8 color data for the transfer function + std::vector get_colormap(); - // Get back the RGBA32F color data for the transfer function - std::vector get_colormapf(); + // Get back the RGBA32F color data for the transfer function + std::vector get_colormapf(); - void setHistogram(const std::vector &hist); + void setHistogram(const std::vector &hist); - std::vector& getHistogram(); + std::vector &getHistogram(); - void setMinMax(const float min, const float max); + void setMinMax(const float min, const float max); - void setBlendedHistogram(const std::vector& hist1, const std::vector& hist2, float alpha); + void setBlendedHistogram(const std::vector &hist1, const std::vector &hist2, float alpha); - // Get back the RGBA32F color data for the transfer function - // as separate color and opacity vectors - void get_colormapf(std::vector &color, std::vector &opacity); + // Get back the RGBA32F color data for the transfer function + // as separate color and opacity vectors + void get_colormapf(std::vector &color, std::vector &opacity); - GLint get_colormap_gpu() - { - return colormap_img; - } + GLint get_colormap_gpu() + { + return colormap_img; + } void set_colormap_gpu(GLint colormap) { colormap_img = colormap; } - - void drawLegend(); - void drawLegend(float legend_pos_x, float legend_pos_y, float legend_width, float legend_height); + void draw_legend(); + + void draw_legend(float legend_pos_x, float legend_pos_y, float legend_width, float legend_height); void draw_histogram(); void update_colormap(); - void set_Quantiles(float min, float max); + void set_quantiles(float min, float max); - void get_Quantiles(float& min, float& max); + void get_quantiles(float &min, float &max); private: - void update_gpu_image(); + void update_gpu_image(); - + void load_embedded_preset(const uint8_t *buf, size_t size, const std::string &name); - void load_embedded_preset(const uint8_t *buf, size_t size, const std::string &name); - - float m_quantiles[2]; - + float m_quantiles[2]; }; - #endif \ No newline at end of file diff --git a/shaders/lines_shader.frag b/shaders/lines_shader.frag index 3656050..7cce2a7 100644 --- a/shaders/lines_shader.frag +++ b/shaders/lines_shader.frag @@ -1,7 +1,7 @@ #version 410 -out vec4 frag_colour; +out vec4 frag_color; void main () { - frag_colour = vec4 (1.0, 0.0, 0.0, 1.0); + frag_color = vec4 (1.0, 0.0, 0.0, 1.0); } \ No newline at end of file diff --git a/shaders/lines_shader.vert b/shaders/lines_shader.vert index 11a8b8a..d2b0d0c 100644 --- a/shaders/lines_shader.vert +++ b/shaders/lines_shader.vert @@ -6,6 +6,5 @@ uniform mat4 p; void main () { - gl_Position = p * mv * vec4(vp,1); } \ No newline at end of file diff --git a/shaders/shader.frag b/shaders/shader.frag index 0fe6b91..76423ff 100644 --- a/shaders/shader.frag +++ b/shaders/shader.frag @@ -10,11 +10,9 @@ out vec4 fragColor; uniform sampler2D myTextureSampler; void main() { - fragColor = vec4(texture( myTextureSampler, TexCoord )); - if(fragColor.a < 0.1) + if(fragColor.a < 0.1) { discard; - } - + } } \ No newline at end of file diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index ec710fa..2fba745 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -9,7 +9,6 @@ #include "loader/VRDataLoader.h" - #include "UIHelpers/stb_image.h" #include "common/common.h" #include "../include/interaction/Simulation.h" @@ -17,26 +16,25 @@ #include #include - #include #include -UIView::UIView(VRVolumeApp& controllerApp) :m_controller_app(controllerApp), m_multiplier(1.0f), m_threshold(0.0f), -m_z_scale(0.16f), m_scale{ 1.0f }, m_slices(256), m_dynamic_slices(false), m_renderVolume(true), m_selectedTrnFnc(0), -m_animated(false), m_ui_frame_controller(0.0f), m_menu_handler(nullptr), m_initialized(false), m_use_transferfunction(false), -m_clip_max(1.0), m_clip_min(0.0), m_clip_ypr(0.0), m_clip_pos(0.0), m_useCustomClipPlane(false), m_rendermethod(1), m_renderchannel(0), -m_trnfnc_table_selection(-1), m_trn_fct_options_window(false), m_save_trnfct_open(false), m_trnfnct_counter(1), m_file_dialog_open(false), -m_file_load_trnsf(false), m_file_dialog_save_dir(false), m_save_session_dialog_open(false), m_current_save_modal(SAVE_NONE), -m_current_load_modal(LOAD_NONE), m_file_extension_filter(".txt"), m_non_trns_functions_selected_modal(false), -m_ui_background(false), m_column_selection_state(0), m_compute_new_histogram(true), m_histogram_point_1(0.0), -m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0), -m_camera_name_window_open(false), m_camera_button_action(BUTTON_ACTION::NONE), m_num_animation_frames(0), m_animation_speed(1.0f), -m_camera_animation_duration_open(false), m_show_clock(false), m_clock_width(250), m_clock_height(200), -m_time_info(""),m_day_info(""), m_time_frame_edited(false), m_show_movie_saved_pop_up(false) +UIView::UIView(VRVolumeApp &controllerApp) : m_controller_app(controllerApp), m_multiplier(1.0f), m_threshold(0.0f), + m_z_scale(0.16f), m_scale{1.0f}, m_slices(256), m_dynamic_slices(false), m_renderVolume(true), m_selectedTrnFnc(0), + m_animated(false), m_ui_frame_controller(0.0f), m_menu_handler(nullptr), m_initialized(false), m_use_transferfunction(false), + m_clip_max(1.0), m_clip_min(0.0), m_clip_ypr(0.0), m_clip_pos(0.0), m_useCustomClipPlane(false), m_rendermethod(1), m_renderchannel(0), + m_trnfnc_table_selection(-1), m_transfer_function_options_window(false), m_save_trnfct_open(false), m_trnfnct_counter(1), m_file_dialog_open(false), + m_file_load_trnsf(false), m_file_dialog_save_dir(false), m_save_session_dialog_open(false), m_current_save_modal(SAVE_NONE), + m_current_load_modal(LOAD_NONE), m_file_extension_filter(".txt"), m_non_trns_functions_selected_modal(false), + m_ui_background(false), m_column_selection_state(0), m_compute_new_histogram(true), m_histogram_point_1(0.0), + m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0), + m_camera_name_window_open(false), m_camera_button_action(BUTTON_ACTION::NONE), m_num_animation_frames(0), m_animation_speed(1.0f), + m_camera_animation_duration_open(false), m_show_clock(false), m_clock_width(250), m_clock_height(200), + m_time_info(""), m_day_info(""), m_time_frame_edited(false), m_show_movie_saved_pop_up(false) { - m_ocean_color_maps_names = { "algae.png","amp.png","balance.png","curl.png","deep.png","delta.png","dense.png", -"diff.png","gray.png","haline.png","ice.png","matter.png","oxy.png","phase.png","rain.png","solar.png","speed.png","tarn.png","tempo.png", -"thermal.png","topo.png","turbid.png" }; + m_ocean_color_maps_names = {"algae.png", "amp.png", "balance.png", "curl.png", "deep.png", "delta.png", "dense.png", + "diff.png", "gray.png", "haline.png", "ice.png", "matter.png", "oxy.png", "phase.png", "rain.png", "solar.png", "speed.png", "tarn.png", "tempo.png", + "thermal.png", "topo.png", "turbid.png"}; m_histogram_quantiles[0] = 0.05; m_histogram_quantiles[1] = 0.95; } @@ -44,7 +42,6 @@ m_time_info(""),m_day_info(""), m_time_frame_edited(false), m_show_movie_saved_p UIView::~UIView() { delete m_menu_handler; - } void UIView::draw_ui_callback() @@ -58,7 +55,6 @@ void UIView::draw_ui_callback() { m_ui_background = m_menu_handler->windowIsActive() ? true : false; - int flags = ImGuiWindowFlags_NoResize; if (!m_ui_background) { @@ -91,26 +87,27 @@ void UIView::draw_ui_callback() ImGui::SameLine(ImGui::GetWindowSize().x * 0.5f, 0); ImGui::Text("FPS = %f", m_controller_app.get_fps()); - const char* items[] = { "sliced" , "raycast" }; + const char *items[] = {"sliced", "raycast"}; ImGui::Combo("RenderMethod", &m_rendermethod, items, IM_ARRAYSIZE(items)); - const char* items_channel[] = { "based on data" , "red", "green" , "blue", "alpha", "rgba", "rgba with alpha as max rgb" }; + const char *items_channel[] = {"based on data", "red", "green", "blue", "alpha", "rgba", "rgba with alpha as max rgb"}; ImGui::Combo("Render Channel", &m_renderchannel, items_channel, IM_ARRAYSIZE(items_channel)); ImGui::Checkbox("Render Volume data", &m_renderVolume); int numVolumes = m_controller_app.get_num_volumes(); - - if (numVolumes > 0) { - if (ImGui::SmallButton("Save Session")) { + if (numVolumes > 0) + { + if (ImGui::SmallButton("Save Session")) + { m_save_session_dialog_open = true; } ImGui::SameLine(); } - - if (ImGui::SmallButton("Load Session")) { + if (ImGui::SmallButton("Load Session")) + { m_file_load_trnsf = true; m_current_load_modal = LOAD_MODAL::LOAD_SESSION; m_file_extension_filter = ".usr"; @@ -118,7 +115,8 @@ void UIView::draw_ui_callback() if (numVolumes > 0) { - if (ImGui::SmallButton("Add Function")) { + if (ImGui::SmallButton("Add Function")) + { tfn_widget.push_back(TransferFunctionWidget()); tfn_widget_multi.push_back(TransferFunctionMultiChannelWidget()); int index = m_selected_volume_TrFn.size(); @@ -128,43 +126,40 @@ void UIView::draw_ui_callback() m_selected_volume_TrFn[index][i] = false; } - addTransferFunction(); - if (m_tfns.size() == 1) - { - m_trnfnc_table_selection = 0; - } - + add_transfer_function(); + if (m_tfns.size() == 1) m_trnfnc_table_selection = 0; + }; ImGui::SameLine(); - if (ImGui::SmallButton("Remove Function")) { + if (ImGui::SmallButton("Remove Function")) + { if (m_tfns.size() == 1) { - //there should be one by default + // there should be one by default tfn_widget.clear(); tfn_widget_multi.clear(); m_tfns.clear(); tfn_widget.push_back(TransferFunctionWidget()); tfn_widget_multi.push_back(TransferFunctionMultiChannelWidget()); - addTransferFunction(); + add_transfer_function(); m_trnfnc_table_selection = 0; } else if (m_tfns.size() > 1 && m_trnfnc_table_selection >= 0) { - tfn_widget.erase(tfn_widget.begin() + m_trnfnc_table_selection); ; + tfn_widget.erase(tfn_widget.begin() + m_trnfnc_table_selection); + ; tfn_widget_multi.erase(tfn_widget_multi.begin() + m_trnfnc_table_selection); m_tfns.erase(m_tfns.begin() + m_trnfnc_table_selection); if (m_trnfnc_table_selection != 0) { m_trnfnc_table_selection = m_trnfnc_table_selection - 1; } - } }; - - - if (ImGui::SmallButton("Clear All Functions")) { + if (ImGui::SmallButton("Clear All Functions")) + { tfn_widget.clear(); tfn_widget_multi.clear(); m_tfns.clear(); @@ -184,13 +179,15 @@ void UIView::draw_ui_callback() }; ImGui::SameLine(); - if (ImGui::SmallButton("Save Functions")) { + if (ImGui::SmallButton("Save Functions")) + { m_save_trnfct_open = true; m_non_trns_functions_selected_modal = !m_use_transferfunction; }; ImGui::SameLine(); - if (ImGui::SmallButton("Load Functions")) { + if (ImGui::SmallButton("Load Functions")) + { m_file_load_trnsf = true; m_current_load_modal = LOAD_MODAL::LOAD_TRFR_FNC; @@ -210,20 +207,19 @@ void UIView::draw_ui_callback() for (int column = 1; column < numVolumes + 1; column++) { ImGui::TableSetColumnIndex(column); - const char* column_name = ImGui::TableGetColumnName(column); + const char *column_name = ImGui::TableGetColumnName(column); ImGui::PushID(column); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - ImGui::Checkbox("##checkall", &m_column_selected[column - 1]); ImGui::SameLine(); + ImGui::Checkbox("##checkall", &m_column_selected[column - 1]); + ImGui::SameLine(); ImGui::PopStyleVar(); ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); ImGui::TableHeader(column_name); ImGui::PopID(); - } compute_new_histogram_view(); - /* check state of check boxes */ int colum_select_check_sum = 0; for (int column_select = 1; column_select <= numVolumes; column_select++) @@ -265,16 +261,12 @@ void UIView::draw_ui_callback() m_copy_trnfnct_name = m_tfns[m_trnfnc_table_selection].Name; float q_min = 0; float q_max = 0; - tfn_widget[m_trnfnc_table_selection].get_Quantiles(q_min, q_max); + tfn_widget[m_trnfnc_table_selection].get_quantiles(q_min, q_max); m_histogram_quantiles[0] = q_min; m_histogram_quantiles[1] = q_max; - m_trn_fct_options_window = true; + m_transfer_function_options_window = true; } - - } - - } else { @@ -283,9 +275,7 @@ void UIView::draw_ui_callback() bool b = m_tfns[row].volumes[col - 1]; ImGui::Checkbox(buf, &b); m_tfns[row].volumes[col - 1] = b; - } - } } @@ -298,7 +288,6 @@ void UIView::draw_ui_callback() std::string extension = ".usr"; auto save_funtion = std::bind(&UIView::save_user_session, this, std::placeholders::_1); open_save_modal_dialog(save_user_session_window_id, m_save_session_dialog_open, save_funtion, extension); - } if (m_save_trnfct_open) @@ -328,15 +317,13 @@ void UIView::draw_ui_callback() ImGui::EndPopup(); } } - - } - if (m_trn_fct_options_window) + if (m_transfer_function_options_window) { ImGui::OpenPopup("Transfer Function Options"); ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); - if (ImGui::BeginPopupModal("Transfer Function Options", &m_trn_fct_options_window)) + if (ImGui::BeginPopupModal("Transfer Function Options", &m_transfer_function_options_window)) { ImGui::Text("Change Name"); ImGui::InputText("##text1", &m_copy_trnfnct_name); @@ -355,7 +342,7 @@ void UIView::draw_ui_callback() tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(m_histogram_point_1); tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(m_histogram_point_2); tfn_widget[m_trnfnc_table_selection].alpha_control_pts.push_back(vec2f(1.0, 1.0)); - tfn_widget[m_trnfnc_table_selection].set_Quantiles(m_histogram_quantiles[0], m_histogram_quantiles[1]); + tfn_widget[m_trnfnc_table_selection].set_quantiles(m_histogram_quantiles[0], m_histogram_quantiles[1]); ImGui::OpenPopup("Confirmation"); ImGui::SetNextWindowSize(ImVec2(350, 400), ImGuiCond_FirstUseEver); } @@ -371,19 +358,17 @@ void UIView::draw_ui_callback() ImGui::EndPopup(); } - - if (ImGui::Button("Ok")) { m_tfns[m_trnfnc_table_selection].Name = m_copy_trnfnct_name; - m_trn_fct_options_window = false; + m_transfer_function_options_window = false; m_current_save_modal = SAVE_MODAL::SAVE_NONE; ImGui::CloseCurrentPopup(); } ImGui::SameLine(); if (ImGui::Button("Cancel")) { - m_trn_fct_options_window = false; + m_transfer_function_options_window = false; m_current_save_modal = SAVE_MODAL::SAVE_NONE; ImGui::CloseCurrentPopup(); } @@ -392,17 +377,15 @@ void UIView::draw_ui_callback() } } - - ImGui::Checkbox("use transferfunction", &m_use_transferfunction); if (m_use_transferfunction) { - bool is_multi_channel = m_controller_app.data_is_multi_channel(); if (is_multi_channel) { - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) + { if (m_animated) { /* @@ -417,14 +400,14 @@ void UIView::draw_ui_callback() m_volumes[m_selectedVolume][active_volume]->getTransferfunction(i), m_volumes[m_selectedVolume][active_volume2]->getTransferfunction(i), alpha, i); }*/ - } - else { + else + { /* tfn_widget_multi[m_selectedVolume].setHistogram(m_volumes[m_selectedVolume][0]->getTransferfunction(i), i);*/ } } m_controller_app.set_multi_transfer(true); - //tfn_widget_multi[m_selectedTrnFnc].draw_histogram(); + // tfn_widget_multi[m_selectedTrnFnc].draw_histogram(); tfn_widget_multi[m_trnfnc_table_selection].draw_ui(); } else @@ -441,40 +424,38 @@ void UIView::draw_ui_callback() m_volumes[m_selectedVolume][active_volume]->getMax() * alpha + m_volumes[m_selectedVolume][active_volume2]->getMax() * (1.0 - alpha)); if (active_volume < m_volumes[m_selectedVolume].size() && active_volume2 < m_volumes[m_selectedVolume].size()) tfn_widget[m_selectedVolume].setBlendedHistogram(m_volumes[m_selectedVolume][active_volume]->getTransferfunction(0), m_volumes[m_selectedVolume][active_volume2]->getTransferfunction(0), alpha);*/ - } m_controller_app.set_multi_transfer(false); m_histogram.draw_histogram(); tfn_widget[m_trnfnc_table_selection].draw_ui(); - //tfn_widget[m_trnfnc_table_selection].setMinMax() + // tfn_widget[m_trnfnc_table_selection].setMinMax() } } - - } - - if (m_animated) { + if (m_animated) + { ImGui::Text("Timestep"); ImGui::SameLine(); ImGui::SetNextItemWidth(-100 - ImGui::GetStyle().ItemSpacing.x); float frame_tmp = m_controller_app.get_current_frame() + 1; - //controls animated multi datasets + // controls animated multi datasets ImGui::SliderFloat("##Timestep", &frame_tmp, 1, m_num_animation_frames); m_ui_frame_controller = (frame_tmp)-1; m_controller_app.set_frame(m_ui_frame_controller); - std::string text = m_stopped ? "Play" : "Stop"; - if (ImGui::Button(text.c_str(), ImVec2(50, 0))) { + if (ImGui::Button(text.c_str(), ImVec2(50, 0))) + { m_stopped = !m_stopped; } ImGui::SameLine(); int value = int(m_animation_speed * 100.0 + .5); std::string speed_text = ">>X " + std::to_string(value / 100); - if (ImGui::Button(speed_text.c_str(), ImVec2(80, 0))) { + if (ImGui::Button(speed_text.c_str(), ImVec2(80, 0))) + { m_animation_speed += 0.5; if (m_animation_speed > 4.0f) { @@ -508,39 +489,41 @@ void UIView::draw_ui_callback() if (ImGui::BeginTabItem("Clipping")) { ImGui::Text("Axis aligned clip"); - glm::vec2 bound = { m_clip_min.x * 100 ,m_clip_max.x * 100 }; + glm::vec2 bound = {m_clip_min.x * 100, m_clip_max.x * 100}; ImGui::DragFloatRange2("X", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); m_clip_min.x = bound.x / 100; m_clip_max.x = bound.y / 100; - bound = { m_clip_min.y * 100 ,m_clip_max.y * 100 }; + bound = {m_clip_min.y * 100, m_clip_max.y * 100}; ImGui::DragFloatRange2("Y", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); m_clip_min.y = bound.x / 100; m_clip_max.y = bound.y / 100; - bound = { m_clip_min.z * 100 ,m_clip_max.z * 100 }; + bound = {m_clip_min.z * 100, m_clip_max.z * 100}; ImGui::DragFloatRange2("Z", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); m_clip_min.z = bound.x / 100; m_clip_max.z = bound.y / 100; - if (ImGui::Button("Reset")) { + if (ImGui::Button("Reset")) + { m_clip_min = glm::vec3(0.0f); m_clip_max = glm::vec3(1.0f); } ImGui::Checkbox("Custom Clipping plane", &m_useCustomClipPlane); - if (m_useCustomClipPlane) { + if (m_useCustomClipPlane) + { ImGui::SliderAngle("Pitch", &m_clip_ypr.y, -90, 90); ImGui::SliderAngle("Roll", &m_clip_ypr.z, -180, 180); ImGui::SliderFloat("Position X", &m_clip_pos.x, -0.5, 0.5); ImGui::SliderFloat("Position y", &m_clip_pos.y, -0.5, 0.5); ImGui::SliderFloat("Position z", &m_clip_pos.z, -0.5, 0.5); - if (ImGui::Button("Reset##Reset2")) { + if (ImGui::Button("Reset##Reset2")) + { m_clip_ypr = glm::vec3(0.0f); m_clip_pos = glm::vec3(0.0f); } - } ImGui::EndTabItem(); } @@ -550,13 +533,14 @@ void UIView::draw_ui_callback() ImGui::Text("Time Frames"); - if (ImGui::Button("Add")) { + if (ImGui::Button("Add")) + { m_camera_name_window_open = true; m_camera_button_action = BUTTON_ACTION::ADD; - } ImGui::SameLine(); - if (ImGui::Button("Remove")) { + if (ImGui::Button("Remove")) + { if (m_controller_app.get_simulation().get_simulation_states().size() > 0) { m_controller_app.get_simulation().remove_simulation_state(m_simulation_state_selection); @@ -570,19 +554,16 @@ void UIView::draw_ui_callback() SimulationState next_sim_state = m_controller_app.get_simulation().get_simulation_state_at(m_simulation_state_selection); m_controller_app.get_trackball_camera().set_current_poi(next_sim_state.poi); } - - } - } ImGui::SameLine(); - if (ImGui::Button("Reset Camera")) { + if (ImGui::Button("Reset Camera")) + { m_controller_app.get_trackball_camera().reset_camera(); } ImGui::BeginTable("##Camera Point of interest (POI) Editor", 1, ImGuiTableFlags_Borders); ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 120.0f); - for (int row = 0; row < m_controller_app.get_simulation().get_simulation_states().size(); ++row) { ImGui::TableNextRow(); @@ -607,64 +588,65 @@ void UIView::draw_ui_callback() if (m_controller_app.get_simulation().get_simulation_states().size() > 0) { - SimulationState& sim_state = m_controller_app.get_simulation().get_simulation_state_at(m_simulation_state_selection); + SimulationState &sim_state = m_controller_app.get_simulation().get_simulation_state_at(m_simulation_state_selection); std::string edit_text = "Edit Time Frame " + sim_state.poi.label; ImGui::Text(edit_text.c_str()); ImGui::Text("Axis aligned clip"); - glm::vec2 bound = { m_clip_min.x * 100 ,m_clip_max.x * 100 }; + glm::vec2 bound = {m_clip_min.x * 100, m_clip_max.x * 100}; ImGui::DragFloatRange2("X", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); m_clip_min.x = bound.x / 100; m_clip_max.x = bound.y / 100; ImGui::SameLine(); - if (ImGui::Button("Reset##XAXIS")) { + if (ImGui::Button("Reset##XAXIS")) + { m_clip_min.x = 0.0f; m_clip_max.x = 1.0f; } - bound = { m_clip_min.y * 100 ,m_clip_max.y * 100 }; + bound = {m_clip_min.y * 100, m_clip_max.y * 100}; ImGui::DragFloatRange2("Y", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); m_clip_min.y = bound.x / 100; m_clip_max.y = bound.y / 100; ImGui::SameLine(); - if (ImGui::Button("Reset##YAXIS")) { + if (ImGui::Button("Reset##YAXIS")) + { m_clip_min.y = 0.0f; m_clip_max.y = 1.0f; } - bound = { m_clip_min.z * 100 ,m_clip_max.z * 100 }; + bound = {m_clip_min.z * 100, m_clip_max.z * 100}; ImGui::DragFloatRange2("Z", &bound.x, &bound.y, 0.1f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); m_clip_min.z = bound.x / 100; m_clip_max.z = bound.y / 100; ImGui::SameLine(); - if (ImGui::Button("Reset##ZAXIS")) { + if (ImGui::Button("Reset##ZAXIS")) + { m_clip_min.z = 0.0f; m_clip_max.z = 1.0f; } - if (ImGui::Button("Save Changes##EDITTIMEFRAME")) { + if (ImGui::Button("Save Changes##EDITTIMEFRAME")) + { sim_state.min_clip = m_clip_min; sim_state.max_clip = m_clip_max; sim_state.poi = m_controller_app.get_trackball_camera().get_current_poi(); m_time_frame_edited = true; } - - } - //Simulation animator + // Simulation animator std::string is_animation_playing = m_controller_app.get_simulation().get_camera_animation_state(); - if (ImGui::Button(is_animation_playing.c_str())) { + if (ImGui::Button(is_animation_playing.c_str())) + { m_controller_app.get_simulation().set_animation_state(); - } ImGui::Text("Duration (seconds)"); - std::stringstream text; text << std::fixed << std::setprecision(1) << m_controller_app.get_simulation().get_animation_duration(); std::string str_animation_duration = text.str(); @@ -672,7 +654,7 @@ void UIView::draw_ui_callback() if (ImGui::Button(str_animation_duration.c_str())) { m_camera_animation_duration_open = true; - m_str_animation_duration = std::string(str_animation_duration); + m_animation_duration_to_string = std::string(str_animation_duration); } #if (!defined(__APPLE__)) @@ -697,7 +679,6 @@ void UIView::draw_ui_callback() ImGui::EndTabItem(); } - ImGui::EndTabBar(); if (m_time_frame_edited) @@ -714,7 +695,6 @@ void UIView::draw_ui_callback() } ImGui::EndPopup(); } - } if (m_camera_name_window_open) @@ -771,7 +751,6 @@ void UIView::draw_ui_callback() } ImGui::EndPopup(); } - } if (m_camera_animation_duration_open) @@ -781,50 +760,41 @@ void UIView::draw_ui_callback() if (ImGui::BeginPopupModal("Animation Time", &m_camera_animation_duration_open)) { ImGui::Text("Camera Name"); - ImGui::InputText("##textanimationtime", &m_str_animation_duration, ImGuiInputTextFlags_CharsDecimal); + ImGui::InputText("##textanimationtime", &m_animation_duration_to_string, ImGuiInputTextFlags_CharsDecimal); if (ImGui::Button("Ok")) { - m_controller_app.get_simulation().set_camera_animation_duration(std::stof(m_str_animation_duration)); - m_str_animation_duration.clear(); + m_controller_app.get_simulation().set_camera_animation_duration(std::stof(m_animation_duration_to_string)); + m_animation_duration_to_string.clear(); m_camera_animation_duration_open = false; ImGui::CloseCurrentPopup(); } if (ImGui::Button("Cancel")) { m_camera_animation_duration_open = false; - m_str_animation_duration.clear(); + m_animation_duration_to_string.clear(); ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); } } - - //file loading + // file loading if (m_file_dialog_open) { ImGui::OpenPopup("Open File"); m_file_dialog_open = false; } - - - if (fileDialog.showFileDialog("Open File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 310), m_file_extension_filter)) { if (helper::ends_with_string(fileDialog.selected_fn, ".txt")) { - //VRDataLoader* insta = VRDataLoader::get_instance(); - //std::thread t1 ( &VRDataLoader::load_txt_file, std::ref(m_controller_app), fileDialog.selected_path); - //t1.join(); - //std:thread t1([=] {VRDataLoader::load_txt_file(m_controller_app, fileDialog.selected_path); }); VRDataLoader::load_txt_file(m_controller_app, fileDialog.selected_path); - - // m_controller_app.load_txt_file(fileDialog.GetSelected().string()); } #ifdef WITH_TEEM - else if (helper::ends_with_string(fileDialog.selected_fn, ".nrrd")) { + else if (helper::ends_with_string(fileDialog.selected_fn, ".nrrd")) + { std::vector vals; /* vals.push_back(fileDialog.GetSelected().string()); promises.push_back(new std::promise); @@ -834,9 +804,6 @@ void UIView::draw_ui_callback() #endif } - - - if (m_file_dialog_save_dir) { ImGui::OpenPopup("Save File"); @@ -852,18 +819,15 @@ void UIView::draw_ui_callback() default: break; } - - } if (m_file_load_trnsf) { ImGui::OpenPopup("Load File"); m_file_load_trnsf = false; - } if (saveDialogLoadTrnsFnc.showFileDialog("Save File", imgui_addons::ImGuiFileBrowser::DialogMode::SELECT, - ImVec2(700, 310))) + ImVec2(700, 310))) { m_dir_to_save = saveDialogLoadTrnsFnc.selected_path; switch (m_current_save_modal) @@ -877,12 +841,10 @@ void UIView::draw_ui_callback() default: break; } - } - if (fileDialogLoadTrnsFnc.showFileDialog("Load File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, - ImVec2(700, 310), m_file_extension_filter)) + ImVec2(700, 310), m_file_extension_filter)) { if (m_current_load_modal == LOAD_MODAL::LOAD_TRFR_FNC) @@ -916,7 +878,6 @@ void UIView::draw_ui_callback() } ImGui::End(); - } if (m_show_movie_saved_pop_up) @@ -945,14 +906,11 @@ void UIView::draw_ui_callback() ImGui::Text(m_day_info.c_str()); ImGui::End(); } - if (m_use_transferfunction) { - tfn_widget[0].drawLegend(0, m_legend_pos_y + 80, m_clock_width + 50, m_clock_height - 140); + tfn_widget[0].draw_legend(0, m_legend_pos_y + 80, m_clock_width + 50, m_clock_height - 140); } - - } void UIView::init_ui(bool is2D, bool lookingGlass) @@ -960,28 +918,30 @@ void UIView::init_ui(bool is2D, bool lookingGlass) if (!m_initialized) { - //fileDialog.SetTitle("load data"); + // fileDialog.SetTitle("load data"); #ifdef WITH_NRRD - fileDialog.SetTypeFilters({ ".txt", ".nrrd" }); - #elseif - fileDialog.SetTypeFilters({ ".txt" }); + fileDialog.SetTypeFilters({".txt", ".nrrd"}); +#elseif + fileDialog.SetTypeFilters({".txt"}); #endif float fontsize = 2.0; - if (is2D) { + if (is2D) + { fontsize = 1.0; } - if (lookingGlass) { + if (lookingGlass) + { fontsize = 3.0; } std::cout << "is2d: " << (is2D ? "true" : "false") << std::endl; m_menu_handler = new VRMenuHandler(is2D); if (!m_menu_handler) { - std::cout << "m_menu_handler: " << "NULL" << std::endl; - + std::cout << "m_menu_handler: " + << "NULL" << std::endl; } - VRMenu* menu = m_menu_handler->addNewMenu(std::bind(&UIView::draw_ui_callback, this), 1024, 1024, 1, 1, fontsize); + VRMenu *menu = m_menu_handler->addNewMenu(std::bind(&UIView::draw_ui_callback, this), 1024, 1024, 1, 1, fontsize); menu->setMenuPose(glm::mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 2, -1, 1)); m_dir_to_save = m_controller_app.get_directory_path().c_str(); @@ -991,11 +951,7 @@ void UIView::init_ui(bool is2D, bool lookingGlass) } m_initialized = true; - - } - - } void UIView::update_ui(int numVolumes) @@ -1003,12 +959,12 @@ void UIView::update_ui(int numVolumes) tfn_widget_multi.resize(1); tfn_widget.resize(1); m_use_transferfunction = true; - m_selected_volume_TrFn.resize(1); - m_selected_volume_TrFn[0].resize(numVolumes); - for (int i = 0; i < numVolumes; i++) - { - m_selected_volume_TrFn[0][i] = false; - } + m_selected_volume_TrFn.resize(1); + m_selected_volume_TrFn[0].resize(numVolumes); + for (int i = 0; i < numVolumes; i++) + { + m_selected_volume_TrFn[0][i] = false; + } MyTransFerFunctions trfntc; char label[32]; @@ -1025,40 +981,35 @@ void UIView::update_ui(int numVolumes) load_ocean_color_maps(); } -void UIView::render_2D(Window_Properties& window_properties) +void UIView::render_2D(Window_Properties &window_properties) { - - m_clock_pos_x = window_properties.window_w - m_clock_width; - m_clock_pos_y = window_properties.window_h - m_clock_height; - m_legend_pos_y = window_properties.window_h - m_clock_height; - - - m_menu_handler->drawMenu(window_properties.window_w, window_properties.window_h, - window_properties.framebuffer_w, window_properties.framebuffer_h); + m_clock_pos_x = window_properties.window_w - m_clock_width; + m_clock_pos_y = window_properties.window_h - m_clock_height; + m_legend_pos_y = window_properties.window_h - m_clock_height; + m_menu_handler->drawMenu(window_properties.window_w, window_properties.window_h, + window_properties.framebuffer_w, window_properties.framebuffer_h); } -void UIView::render_3D(glm::mat4& space_matrix, Window_Properties& window_properties) +void UIView::render_3D(glm::mat4 &space_matrix, Window_Properties &window_properties) { - //render menu + // render menu if (m_show_menu) { - + m_menu_handler->drawMenu(window_properties.window_w, window_properties.window_h, - window_properties.framebuffer_w, window_properties.framebuffer_h); + window_properties.framebuffer_w, window_properties.framebuffer_h); } - } - void UIView::update_3D_ui_frame() { m_menu_handler->renderToTexture(); } -void UIView::set_cursor_pos(glm::vec2& mPos) +void UIView::set_cursor_pos(glm::vec2 &mPos) { if (m_menu_handler) { @@ -1081,7 +1032,7 @@ int UIView::get_num_transfer_functions() bool UIView::is_transfer_function_enabled(int tfn, int vol) { - //return m_selected_volume_TrFn[tfn][vol]; + // return m_selected_volume_TrFn[tfn][vol]; return m_tfns[tfn].volumes[vol]; } @@ -1121,7 +1072,6 @@ void UIView::set_button_click(int button, int state) { m_menu_handler->setButtonClick(button, state); } - } void UIView::set_enable_render_volume() @@ -1129,13 +1079,12 @@ void UIView::set_enable_render_volume() m_renderVolume = !m_renderVolume; } -void UIView::set_controller_pose(glm::mat4& pose) +void UIView::set_controller_pose(glm::mat4 &pose) { if (m_menu_handler) { m_menu_handler->setControllerPose(pose); } - } void UIView::set_dynamic_slices(bool dynamicSlices) @@ -1186,13 +1135,12 @@ void UIView::update_animation(float speed, int numFrames) { m_ui_frame_controller = 0.0f; - } m_controller_app.set_frame(m_ui_frame_controller); } } -void UIView::add_data_label(std::string& dataLabel) +void UIView::add_data_label(std::string &dataLabel) { m_dataLabels.push_back(dataLabel); } @@ -1259,11 +1207,10 @@ void UIView::set_clip_max(glm::vec3 clip_max) void UIView::add_character(char c) { - if (m_trn_fct_options_window) + if (m_transfer_function_options_window) { ImGui::ClearActiveID(); m_copy_trnfnct_name += c; - } if (m_save_trnfct_open || m_save_session_dialog_open) { @@ -1282,21 +1229,19 @@ void UIView::add_character(char c) ImGui::ClearActiveID(); if ((c >= '0' && c <= '9') || (c == '.')) { - m_str_animation_duration += c; + m_animation_duration_to_string += c; } - } } void UIView::remove_character() { - if (m_trn_fct_options_window) + if (m_transfer_function_options_window) { if (!m_copy_trnfnct_name.empty()) { m_copy_trnfnct_name.pop_back(); } - } if (m_save_trnfct_open || m_save_session_dialog_open) @@ -1305,7 +1250,6 @@ void UIView::remove_character() { m_save_file_name.pop_back(); } - } if (m_camera_name_window_open) @@ -1318,17 +1262,16 @@ void UIView::remove_character() if (m_camera_animation_duration_open) { - if (!m_str_animation_duration.empty()) + if (!m_animation_duration_to_string.empty()) { ImGui::ClearActiveID(); - m_str_animation_duration.pop_back(); + m_animation_duration_to_string.pop_back(); } - } } -void UIView::open_save_modal_dialog(std::string& id, bool& window_state, - std::function save_function, std::string& extension) +void UIView::open_save_modal_dialog(std::string &id, bool &window_state, + std::function save_function, std::string &extension) { ImGui::OpenPopup(id.c_str()); ImGui::SetNextWindowSize(ImVec2(350, 200), ImGuiCond_FirstUseEver); @@ -1345,7 +1288,6 @@ void UIView::open_save_modal_dialog(std::string& id, bool& window_state, ImGui::InputText("##filename", &m_save_file_name); ImGui::IsItemActive(); - if (ImGui::Button("Save")) { std::string fileName = m_dir_to_save + helper::get_OS_path_separator() + m_save_file_name + extension; @@ -1366,10 +1308,9 @@ void UIView::open_save_modal_dialog(std::string& id, bool& window_state, void UIView::add_trans_function() { - } -void UIView::save_trans_functions(std::ofstream& saveFile) +void UIView::save_trans_functions(std::ofstream &saveFile) { std::string pointsLine; if (saveFile.is_open()) @@ -1377,7 +1318,7 @@ void UIView::save_trans_functions(std::ofstream& saveFile) saveFile << "numFunction " << std::to_string(m_tfns.size()) << "\n"; for (int i = 0; i < m_tfns.size(); i++) { - //savefile << m_tfns[i].ID + ","; + // savefile << m_tfns[i].ID + ","; saveFile << "FuncName " + std::to_string(i + 1) + " " + m_tfns[i].Name + " " + std::to_string(tfn_widget[i].get_colormap_gpu()) + "\n"; /* for (int j = 0; j < tfn_widget_multi[i].alpha_control_pts.size(); j++) { @@ -1404,15 +1345,13 @@ void UIView::save_trans_functions(std::ofstream& saveFile) { saveFile << std::to_string(tfn_widget[i].alpha_control_pts[j].x) + "," + std::to_string(tfn_widget[i].alpha_control_pts[j].y); } - } saveFile << "\n"; } - } } -void UIView::save_user_session(std::ofstream& savefile) +void UIView::save_user_session(std::ofstream &savefile) { if (savefile.is_open()) @@ -1448,18 +1387,16 @@ void UIView::save_user_session(std::ofstream& savefile) if (m_use_transferfunction) { - savefile << "Trnfncs" << "\n"; + savefile << "Trnfncs" + << "\n"; save_trans_functions(savefile); } - - - savefile.close(); } } -void UIView::load_trans_functions(std::ifstream& loadFile) +void UIView::load_trans_functions(std::ifstream &loadFile) { std::string line; @@ -1473,7 +1410,8 @@ void UIView::load_trans_functions(std::ifstream& loadFile) std::stringstream ss(line); std::string buf; - while (ss >> buf) { + while (ss >> buf) + { vals.push_back(buf); } @@ -1488,8 +1426,6 @@ void UIView::load_trans_functions(std::ifstream& loadFile) tfn_widget_multi.resize(numFunctions); m_tfns.resize(numFunctions); m_trnfnct_counter = numFunctions + 1; - - } if (tag == "FuncName") { @@ -1510,11 +1446,13 @@ void UIView::load_trans_functions(std::ifstream& loadFile) size_t pos = 0; std::string token; std::string delimiter = ";"; - size_t last = 0; size_t next = 0; + size_t last = 0; + size_t next = 0; std::string point; int poinCounter = 0; tfn_widget[index].alpha_control_pts.clear(); - while ((next = points.find(delimiter, last)) != std::string::npos) { + while ((next = points.find(delimiter, last)) != std::string::npos) + { point = points.substr(last, next - last); int comaPos = point.find(","); @@ -1522,7 +1460,6 @@ void UIView::load_trans_functions(std::ifstream& loadFile) float pointY = std::stof(point.substr(comaPos + 1)); tfn_widget[index].alpha_control_pts.push_back(vec2f(pointX, pointY)); - last = next + 1; poinCounter++; } @@ -1532,14 +1469,11 @@ void UIView::load_trans_functions(std::ifstream& loadFile) float pointY = std::stof(point.substr(comaPos + 1)); tfn_widget[index].alpha_control_pts.push_back(vec2f(pointX, pointY)); std::cout << points.substr(last) << std::endl; - } - } } loadFile.close(); } - } void UIView::load_user_session(std::string filePath) @@ -1547,7 +1481,6 @@ void UIView::load_user_session(std::string filePath) std::string line; std::ifstream loadFile(filePath); - if (loadFile.is_open()) { while (std::getline(loadFile, line)) @@ -1556,62 +1489,77 @@ void UIView::load_user_session(std::string filePath) std::stringstream ss(line); std::string buf; - while (ss >> buf) { + while (ss >> buf) + { vals.push_back(buf); } std::string tag = vals[0]; - if (tag == "volume_loaded") { std::string fileToLoad = vals[1]; VRDataLoader::load_txt_file(m_controller_app, fileToLoad); } - else if (tag == "alpha_multiplier") { + else if (tag == "alpha_multiplier") + { m_multiplier = std::stof(vals[1]); } - else if (tag == "threshold") { + else if (tag == "threshold") + { m_threshold = std::stof(vals[1]); } - else if (tag == "scale") { + else if (tag == "scale") + { m_scale = std::stof(vals[1]); } - else if (tag == "z-scale") { + else if (tag == "z-scale") + { m_z_scale = std::stof(vals[1]); } - else if (tag == "Slices") { + else if (tag == "Slices") + { m_slices = std::stof(vals[1]); } - else if (tag == "automatic _slice adjustment") { + else if (tag == "automatic _slice adjustment") + { m_dynamic_slices = std::stof(vals[1]); } - else if (tag == "RenderMethod") { + else if (tag == "RenderMethod") + { m_rendermethod = std::stof(vals[1]); } - else if (tag == "Render_Channel") { + else if (tag == "Render_Channel") + { m_renderchannel = std::stof(vals[1]); } - else if (tag == "Render_Volume_data") { + else if (tag == "Render_Volume_data") + { m_renderVolume = std::stoi(vals[1]); } - else if (tag == "ClipXmin") { + else if (tag == "ClipXmin") + { m_clip_min.x = std::stof(vals[1]); } - else if (tag == "ClipXmax") { + else if (tag == "ClipXmax") + { m_clip_max.x = std::stof(vals[1]); } - else if (tag == "ClipYmin") { + else if (tag == "ClipYmin") + { m_clip_min.y = std::stof(vals[1]); } - else if (tag == "ClipYmax") { + else if (tag == "ClipYmax") + { m_clip_max.y = std::stof(vals[1]); } - else if (tag == "ClipZmin") { + else if (tag == "ClipZmin") + { m_clip_min.z = std::stof(vals[1]); } - else if (tag == "ClipZmax") { + else if (tag == "ClipZmax") + { m_clip_max.z = std::stof(vals[1]); } else if (tag == "Trnfncs") @@ -1628,7 +1576,7 @@ void UIView::load_user_session(std::string filePath) } } -void UIView::save_simulation_states(std::ofstream& saveFile, int num_camera_poi) +void UIView::save_simulation_states(std::ofstream &saveFile, int num_camera_poi) { if (saveFile.is_open()) { @@ -1637,18 +1585,17 @@ void UIView::save_simulation_states(std::ofstream& saveFile, int num_camera_poi) for (sim_iterator; sim_iterator != m_controller_app.get_simulation().get_simulation_states().end(); sim_iterator++) { saveFile << sim_iterator->poi.label << " " - << std::to_string(sim_iterator->poi.eye.x) + " " + std::to_string(sim_iterator->poi.eye.y) + " " + std::to_string(sim_iterator->poi.eye.z) + " " - << std::to_string(sim_iterator->poi.target.x) + " " + std::to_string(sim_iterator->poi.target.y) + " " + std::to_string(sim_iterator->poi.target.z) + " " - << std::to_string(sim_iterator->poi.up.x) + " " + std::to_string(sim_iterator->poi.up.y) + " " + std::to_string(sim_iterator->poi.up.z) + " " - << std::to_string(sim_iterator->poi.radius) + " " - << std::to_string(sim_iterator->min_clip.x) + " " + std::to_string(sim_iterator->min_clip.y) + " " + std::to_string(sim_iterator->min_clip.z) + " " - << std::to_string(sim_iterator->max_clip.x) + " " + std::to_string(sim_iterator->max_clip.y) + " " + std::to_string(sim_iterator->max_clip.z) + "\n"; - + << std::to_string(sim_iterator->poi.eye.x) + " " + std::to_string(sim_iterator->poi.eye.y) + " " + std::to_string(sim_iterator->poi.eye.z) + " " + << std::to_string(sim_iterator->poi.target.x) + " " + std::to_string(sim_iterator->poi.target.y) + " " + std::to_string(sim_iterator->poi.target.z) + " " + << std::to_string(sim_iterator->poi.up.x) + " " + std::to_string(sim_iterator->poi.up.y) + " " + std::to_string(sim_iterator->poi.up.z) + " " + << std::to_string(sim_iterator->poi.radius) + " " + << std::to_string(sim_iterator->min_clip.x) + " " + std::to_string(sim_iterator->min_clip.y) + " " + std::to_string(sim_iterator->min_clip.z) + " " + << std::to_string(sim_iterator->max_clip.x) + " " + std::to_string(sim_iterator->max_clip.y) + " " + std::to_string(sim_iterator->max_clip.z) + "\n"; } } } -void UIView::load_camera_poi(std::ifstream& loadFile, int num_poi) +void UIView::load_camera_poi(std::ifstream &loadFile, int num_poi) { std::string line; if (loadFile.is_open()) @@ -1688,21 +1635,18 @@ void UIView::load_camera_poi(std::ifstream& loadFile, int num_poi) sim.min_clip = glm::vec3(min_clip_x, min_clip_y, min_clip_z); sim.max_clip = glm::vec3(max_clip_x, max_clip_y, max_clip_z); m_controller_app.get_simulation().add_simulation_state(sim); - } - } } - } - -void UIView::read_file_line(std::string& line, std::vector& values) +void UIView::read_file_line(std::string &line, std::vector &values) { std::stringstream ss(line); std::string buf; - while (ss >> buf) { + while (ss >> buf) + { values.push_back(buf); } } @@ -1727,7 +1671,7 @@ void UIView::adjust_transfer_function_to_histogram() const std::size_t pos1 = std::floor(m_histogram_quantiles[0] * std::distance(histogram_copy.begin(), histogram_copy.end())); const std::size_t pos2 = std::floor(m_histogram_quantiles[1] * std::distance(histogram_copy.begin(), histogram_copy.end())); - if (histogram_copy.size() > pos1&& histogram_copy.size() > pos2) + if (histogram_copy.size() > pos1 && histogram_copy.size() > pos2) { std::nth_element(histogram_copy.begin(), histogram_copy.begin() + pos1, histogram_copy.end()); @@ -1737,7 +1681,6 @@ void UIView::adjust_transfer_function_to_histogram() m_histogram_point_1.x = index1; m_histogram_point_1.y = 0.0f; - std::nth_element(histogram_copy.begin(), histogram_copy.begin() + pos2, histogram_copy.end()); std::vector::iterator it2 = std::find(m_histogram.getHistogram().begin(), m_histogram.getHistogram().end(), histogram_copy[pos2]); @@ -1745,11 +1688,9 @@ void UIView::adjust_transfer_function_to_histogram() m_histogram_point_2.x = index2; m_histogram_point_2.y = 1.0f; - } } - void UIView::compute_new_histogram_view() { if (!m_compute_new_histogram) @@ -1763,7 +1704,6 @@ void UIView::compute_new_histogram_view() for (int i = 0; i < m_controller_app.get_num_volumes(); i++) { - if (m_column_selected[i]) { if (m_controller_app.get_volume(i)[0]->getMin() < global_min) @@ -1781,9 +1721,7 @@ void UIView::compute_new_histogram_view() { histogram[j] += current_histogram[j]; } - } - } m_histogram.setHistogram(histogram); @@ -1791,8 +1729,7 @@ void UIView::compute_new_histogram_view() m_compute_new_histogram = false; } - -void UIView::addTransferFunction() +void UIView::add_transfer_function() { int numVolumes = m_controller_app.get_num_volumes(); MyTransFerFunctions trfntc; @@ -1807,21 +1744,21 @@ void UIView::addTransferFunction() m_tfns.push_back(trfntc); } -void UIView::get_Quantiles(int row) +void UIView::get_quantiles(int row) { m_copy_trnfnct_name = m_tfns[row].Name; float q_min = 0; float q_max = 0; - tfn_widget[m_trnfnc_table_selection].get_Quantiles(q_min, q_max); + tfn_widget[m_trnfnc_table_selection].get_quantiles(q_min, q_max); m_histogram_quantiles[0] = q_min; m_histogram_quantiles[1] = q_max; - m_trn_fct_options_window = true; + m_transfer_function_options_window = true; } void UIView::set_volume_time_info(time_t time) { - tm* time_info = localtime(&time); + tm *time_info = localtime(&time); if (time_info) { bool pm = time_info->tm_hour >= 12; @@ -1833,35 +1770,29 @@ void UIView::set_volume_time_info(time_t time) ss_time << (pm ? "PM" : "AM"); std::stringstream ss_day; - ss_day << months[time_info->tm_mon] << " "; + ss_day << m_months[time_info->tm_mon] << " "; ss_day << std::setw(2) << std::setfill('0') << time_info->tm_mday; ss_day << ", " << time_info->tm_year + 1900; m_time_info = ss_time.str(); m_day_info = ss_day.str(); } - - } -void UIView::draw_tranfer_funciton_legend() +void UIView::draw_transfer_function_legend() { if (m_use_transferfunction) { - tfn_widget[0].drawLegend(); + tfn_widget[0].draw_legend(); } - } -void UIView::set_trns_fnct_min_max(float min, float max) +void UIView::set_transfer_function_min_max(float min, float max) { - /*tfn_widget[0].setMinMax(m_volumes[m_selectedVolume][active_volume]->getMin() * alpha + m_volumes[m_selectedVolume][active_volume2]->getMin() * (1.0 - alpha), - m_volumes[m_selectedVolume][active_volume]->getMax() * alpha + m_volumes[m_selectedVolume][active_volume2]->getMax() * (1.0 - alpha));*/ if (m_use_transferfunction) { tfn_widget[0].setMinMax(min, max); } - } void UIView::load_ocean_color_maps() @@ -1872,11 +1803,11 @@ void UIView::load_ocean_color_maps() for (std::string color_map_name : m_ocean_color_maps_names) { std::string file_name_path = m_controller_app.get_directory_path() + OS_SLASH + m_color_map_directory + OS_SLASH + color_map_name; - uint8_t* img_data = stbi_load(file_name_path.c_str(), &w, &h, &comp, 4); + uint8_t *img_data = stbi_load(file_name_path.c_str(), &w, &h, &comp, 4); auto img = std::vector(img_data, img_data + w * 1 * 4); stbi_image_free(img_data); - //set name + // set name std::string name = color_map_name.substr(0, color_map_name.find_first_of(".")); @@ -1884,4 +1815,3 @@ void UIView::load_ocean_color_maps() tfn_widget[0].add_colormap(color_map); } } - diff --git a/src/interaction/ArcBallCamera.cpp b/src/interaction/ArcBallCamera.cpp index 175202e..7ace944 100644 --- a/src/interaction/ArcBallCamera.cpp +++ b/src/interaction/ArcBallCamera.cpp @@ -1,30 +1,29 @@ // ---------------------------------- -// Copyright © 2017, Brown University, Providence, RI. -// +// Copyright � 2017, Brown University, Providence, RI. +// // All Rights Reserved -// -// Use of the software is provided under the terms of the GNU General Public License version 3 -// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided -// that this copyright notice appear in all copies and that the name of Brown University not be used in -// advertising or publicity pertaining to the use or distribution of the software without specific written +// +// Use of the software is provided under the terms of the GNU General Public License version 3 +// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided +// that this copyright notice appear in all copies and that the name of Brown University not be used in +// advertising or publicity pertaining to the use or distribution of the software without specific written // prior permission from Brown University. -// +// // See license.txt for further information. -// -// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED “AS IS”, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY -// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING -// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION -// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS +// PROVIDED �AS IS�, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY +// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING +// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION +// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // ---------------------------------- -// +// ///\file ArcBall.cpp ///\author Benjamin Knorlein ///\date 10/17/2019 - #include "../../include/interaction/ArcBallCamera.h" #include #include "glm/ext.hpp" @@ -37,20 +36,17 @@ #define _PI 3.141592653 #endif -ArcBallCamera::ArcBallCamera() : m_radius(1), m_mouse_left_pressed(false), m_mouse_center_pressed(false), m_mouse_right_pressed(false), last_x(0), last_y(0) -, m_PanFactor(1), m_RotateFactor(1), m_cameraScrollFactor(0.1), m_target(0, 0, 0), m_eye(0, 0, 1), m_up(0, 1, 0), m_rotate_camera_center{ false } +ArcBallCamera::ArcBallCamera() : m_radius(1), m_mouse_left_pressed(false), m_mouse_center_pressed(false), m_mouse_right_pressed(false), last_x(0), last_y(0), m_PanFactor(1), m_RotateFactor(1), m_cameraScrollFactor(0.1), m_target(0, 0, 0), m_eye(0, 0, 1), m_up(0, 1, 0), m_rotate_camera_center{false} { - } ArcBallCamera::~ArcBallCamera() { - } -void ArcBallCamera::updateCameraMatrix() +void ArcBallCamera::update_camera_matrix() { - if (m_aap_mode == 0) + if (m_app_mode == 0) { m_viewmatrix = glm::lookAt(m_current_poi.get_camera_position(), m_current_poi.target, m_current_poi.up); } @@ -58,27 +54,24 @@ void ArcBallCamera::updateCameraMatrix() { m_viewmatrix = glm::lookAt(m_simulation_poi.get_camera_position(), m_simulation_poi.target, m_simulation_poi.up); } - - } -void ArcBallCamera::update_sim_poi(PointOfInterest& poi) +void ArcBallCamera::update_sim_poi(PointOfInterest &poi) { m_simulation_poi = poi; } void ArcBallCamera::mouse_pressed(int button, bool isDown) { - if (m_aap_mode == 0) + if (m_app_mode == 0) { - if (button == 0) //left -> rotate + if (button == 0) // left -> rotate { m_mouse_left_pressed = isDown; } else if (button == 1) // right ->pan { m_mouse_right_pressed = isDown; - } else if (button == 2) { @@ -86,25 +79,28 @@ void ArcBallCamera::mouse_pressed(int button, bool isDown) m_mouse_center_pressed = isDown; } } - } -void ArcBallCamera::mouse_move(float x, float y) { - if (m_aap_mode == 0) +void ArcBallCamera::mouse_move(float x, float y) +{ + if (m_app_mode == 0) { - if (m_mouse_left_pressed) { + if (m_mouse_left_pressed) + { // Calculate the new phi and theta based on mouse position relative to where the user clicked float dx = ((float)(last_x - x)) / 300.0f; float dy = ((float)(last_y - y)) / 300.0f; Rotate(dx * m_RotateFactor, -dy * m_RotateFactor); } - else if (m_mouse_center_pressed) { + else if (m_mouse_center_pressed) + { float dy = ((float)(last_y - y)) / 300.0f; RotateEyeAxis(dy * m_RotateFactor); } - else if (m_mouse_right_pressed) { + else if (m_mouse_right_pressed) + { float dx = ((float)(last_x - x)) / 300.0f; float dy = ((float)(last_y - y)) / 300.0f; @@ -114,64 +110,70 @@ void ArcBallCamera::mouse_move(float x, float y) { last_x = x; last_y = y; } - - } -void ArcBallCamera::mouse_scroll(float dist) { - if (m_aap_mode == 0) +void ArcBallCamera::mouse_scroll(float dist) +{ + if (m_app_mode == 0) { Zoom(dist); } - } -void ArcBallCamera::setCameraCenterRotation(bool useCameraCenter) { - if (useCameraCenter != m_rotate_camera_center) { +void ArcBallCamera::setCameraCenterRotation(bool useCameraCenter) +{ + if (useCameraCenter != m_rotate_camera_center) + { m_rotate_camera_center = useCameraCenter; - if (!m_rotate_camera_center) { - m_current_poi.target = glm::vec3{ 0.0 }; + if (!m_rotate_camera_center) + { + m_current_poi.target = glm::vec3{0.0}; } } } -void ArcBallCamera::wasd_pressed(int awsd) { +void ArcBallCamera::wasd_pressed(int wasd) +{ - if (m_aap_mode == 0) + if (m_app_mode == 0) { glm::vec3 dir = glm::normalize(-m_current_poi.eye); - glm::vec3 right = glm::cross(dir, m_current_poi.up); + glm::vec3 right = glm::cross(dir, m_current_poi.up); - if (W & awsd) { + if (W & wasd) + { m_current_poi.target = m_current_poi.target + dir * glm::vec3(0.001); - updateCameraMatrix(); + update_camera_matrix(); } - if (S & awsd) { + if (S & wasd) + { m_current_poi.target = m_current_poi.target - dir * glm::vec3(0.001); - updateCameraMatrix(); + update_camera_matrix(); } - if (A & awsd) { + if (A & wasd) + { m_current_poi.target = m_current_poi.target - (right)*glm::vec3(0.001); - updateCameraMatrix(); + update_camera_matrix(); } - if (D & awsd) { + { + if (D & wasd) m_current_poi.target = m_current_poi.target + (right)*glm::vec3(0.001); - updateCameraMatrix(); + update_camera_matrix(); } - if (Q & awsd) { + if (Q & wasd) + { m_current_poi.target = m_target - m_current_poi.up * glm::vec3(0.001); - updateCameraMatrix(); + update_camera_matrix(); } - if (E & awsd) { + if (E & wasd) + { m_current_poi.target = m_target + m_current_poi.up * glm::vec3(0.001); - updateCameraMatrix(); + update_camera_matrix(); } } - - } -void ArcBallCamera::Rotate(float dx, float dy) +void ArcBallCamera::Rotate(float dx, float dy) { glm::vec3 right = glm::cross(glm::normalize(m_current_poi.eye), m_current_poi.up); glm::mat4 rot = glm::mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); @@ -188,17 +190,17 @@ void ArcBallCamera::Rotate(float dx, float dy) m_current_poi.target -= m_current_poi.radius * glm::normalize(m_current_poi.eye); else m_current_poi.target = rot * glm::vec4(m_current_poi.target, 1); - - } -void ArcBallCamera::RotateEyeAxis(float dy) { +void ArcBallCamera::RotateEyeAxis(float dy) +{ glm::mat4 rot = glm::mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); rot = glm::rotate(rot, dy, m_current_poi.eye); m_current_poi.up = rot * glm::vec4(m_current_poi.up, 1); } -void ArcBallCamera::Zoom(float distance) { +void ArcBallCamera::Zoom(float distance) +{ m_current_poi.radius -= distance; if (m_current_poi.radius < 0) @@ -209,21 +211,20 @@ void ArcBallCamera::Zoom(float distance) { std::cout << m_current_poi.radius << std::endl; } -void ArcBallCamera::Pan(float dx, float dy) { +void ArcBallCamera::Pan(float dx, float dy) +{ - glm::vec3 right = glm::cross(m_current_poi.eye, m_current_poi.up); + glm::vec3 right = glm::cross(m_current_poi.eye, m_current_poi.up); m_current_poi.target = m_current_poi.target + (right * dx) + (m_current_poi.up * dy); } - -PointOfInterest& ArcBallCamera::get_current_poi() +PointOfInterest &ArcBallCamera::get_current_poi() { return m_current_poi; } - -void ArcBallCamera::set_current_poi(const PointOfInterest& poi) +void ArcBallCamera::set_current_poi(const PointOfInterest &poi) { // deep copy m_current_poi = poi; @@ -242,9 +243,7 @@ void ArcBallCamera::reset_camera() m_current_poi = PointOfInterest(); } - void ArcBallCamera::set_app_mode(unsigned int mode) { - m_aap_mode = mode; + m_app_mode = mode; } - diff --git a/src/interaction/Labels.cpp b/src/interaction/Labels.cpp index 83d1016..0f6eefc 100644 --- a/src/interaction/Labels.cpp +++ b/src/interaction/Labels.cpp @@ -1,25 +1,25 @@ // ---------------------------------- // Copyright © 2015, Brown University, Providence, RI. -// +// // All Rights Reserved -// -// Use of the software is provided under the terms of the GNU General Public License version 3 -// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided -// that this copyright notice appear in all copies and that the name of Brown University not be used in -// advertising or publicity pertaining to the use or distribution of the software without specific written +// +// Use of the software is provided under the terms of the GNU General Public License version 3 +// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided +// that this copyright notice appear in all copies and that the name of Brown University not be used in +// advertising or publicity pertaining to the use or distribution of the software without specific written // prior permission from Brown University. -// +// // See license.txt for further information. -// -// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED “AS ISâ€, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY -// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING -// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION -// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS +// PROVIDED “AS ISâ€, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY +// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING +// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION +// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // ---------------------------------- -// +// ///\file Labels.cpp ///\author Benjamin Knorlein ///\date 6/25/2019 @@ -54,17 +54,14 @@ #include #include - -Labels::Labels( ShaderProgram& lines_shader, ShaderProgram& plane_shader): - m_init_plane_model(false), m_lines_shader_program(lines_shader), m_plane_shader_program(plane_shader), m_plane_model(nullptr) +Labels::Labels(ShaderProgram &lines_shader, ShaderProgram &plane_shader) : m_init_plane_model(false), m_lines_shader_program(lines_shader), m_plane_shader_program(plane_shader), m_plane_model(nullptr) { - } Labels::~Labels() { clear(); - std::map::iterator it; + std::map::iterator it; for (it = m_texture_cache.begin(); it != m_texture_cache.end(); it++) { delete it->second; @@ -72,8 +69,8 @@ Labels::~Labels() delete m_plane_model; } - -void Labels::clear() { +void Labels::clear() +{ m_text.clear(); m_position.clear(); m_position2.clear(); @@ -81,12 +78,12 @@ void Labels::clear() { m_volume.clear(); } -void Labels::set_parent_directory(std::string& directory) +void Labels::set_parent_directory(std::string &directory) { m_parent_directory = directory; } -unsigned int Labels::create_line_vba(glm::vec3& start, glm::vec3& end) +unsigned int Labels::create_line_vba(glm::vec3 &start, glm::vec3 &end) { unsigned int vba; unsigned int vbo; @@ -100,11 +97,10 @@ unsigned int Labels::create_line_vba(glm::vec3& start, glm::vec3& end) glBindVertexArray(vba); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData( - GL_ARRAY_BUFFER, - sizeof(glm::vec3) * 2, - &line[0], - GL_STATIC_DRAW - ); + GL_ARRAY_BUFFER, + sizeof(glm::vec3) * 2, + &line[0], + GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray(0); @@ -114,22 +110,21 @@ unsigned int Labels::create_line_vba(glm::vec3& start, glm::vec3& end) return vba; } -void Labels::add( std::string texture_path, float x, float y, float z, float textPosZ, float size, int volume) +void Labels::add(std::string texture_path, float x, float y, float z, float textPosZ, float size, int volume) { if (!m_init_plane_model) { - std::string plane_obj_path = m_parent_directory+"Resources/Models/plane.obj"; + std::string plane_obj_path = m_parent_directory + "Resources/Models/plane.obj"; m_plane_model = GLMLoader::loadObjModel(plane_obj_path); m_init_plane_model = true; } if (m_texture_cache.find(texture_path) == m_texture_cache.end()) { - - Texture* texture = new Texture(GL_TEXTURE_2D, texture_path); + + Texture *texture = new Texture(GL_TEXTURE_2D, texture_path); m_texture_cache[texture_path] = texture; } - LabelBillboard billboard; glm::vec3 line_start(x, y, z); @@ -138,20 +133,20 @@ void Labels::add( std::string texture_path, float x, float y, float z, float tex billboard.line_vba = line_vba; billboard.label_texture = m_texture_cache[texture_path]; billboard.label_model = m_plane_model; - billboard.position = glm::vec3(x, y, textPosZ+250); + billboard.position = glm::vec3(x, y, textPosZ + 250); m_billboard_labels.push_back(billboard); - + m_position.push_back(glm::vec3(x, y, z)); m_position2.push_back(glm::vec3(x, y, textPosZ)); m_size.push_back(size); m_volume.push_back(volume); } -void Labels::drawLabels(glm::mat4 volume_mv, glm::mat4 projection_matrix, glm::mat4& headpose, float z_scale) +void Labels::drawLabels(glm::mat4 volume_mv, glm::mat4 projection_matrix, glm::mat4 &headpose, float z_scale) { for (int i = 0; i < m_billboard_labels.size(); i++) { - //draw line + // draw line m_lines_shader_program.start(); m_lines_shader_program.setUniform("p", projection_matrix); m_lines_shader_program.setUniform("mv", volume_mv); @@ -173,9 +168,9 @@ void Labels::drawLabels(glm::mat4 volume_mv, glm::mat4 projection_matrix, glm::m label_mv = glm::translate(volume_mv, m_billboard_labels[i].position); label_mv = glm::scale(label_mv, glm::vec3(50.0f, 50.0f, 100.0f)); - label_mv = glm::rotate(label_mv, glm::radians(180.0f - angle),glm::vec3(0.0f, 0.0f, 1.0f)); + label_mv = glm::rotate(label_mv, glm::radians(180.0f - angle), glm::vec3(0.0f, 0.0f, 1.0f)); label_mv = glm::rotate(label_mv, glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f)); - //label_mv = glm::scale(label_mv, glm::vec3(1.0f, 1.0f / z_scale, 1.0f)); + // label_mv = glm::scale(label_mv, glm::vec3(1.0f, 1.0f / z_scale, 1.0f)); m_plane_shader_program.start(); m_plane_shader_program.setUniform("p", projection_matrix); m_plane_model->setMVMatrix(label_mv); @@ -183,17 +178,15 @@ void Labels::drawLabels(glm::mat4 volume_mv, glm::mat4 projection_matrix, glm::m m_billboard_labels[i].label_model->render(m_plane_shader_program); m_plane_shader_program.stop(); } - } void Labels::drawLines() { - - for (size_t i =0; i < m_lines_vba.size();++i) + + for (size_t i = 0; i < m_lines_vba.size(); ++i) { glBindVertexArray(m_lines_vba[i]); glDrawArrays(GL_LINES, 0, 2); glBindVertexArray(0); } - } diff --git a/src/interaction/Simulation.cpp b/src/interaction/Simulation.cpp index 52aaf25..d9a62e1 100644 --- a/src/interaction/Simulation.cpp +++ b/src/interaction/Simulation.cpp @@ -1,15 +1,12 @@ #include "../include/interaction/Simulation.h" #include "../include/vrapp/VRVolumeApp.h" -Simulation::Simulation(VRVolumeApp& controller_app,float time ):m_animation_duration(time), m_controller_app(controller_app), -animation_button_label("ANIMATE"), m_animation_state(STOP) +Simulation::Simulation(VRVolumeApp &controller_app, float time) : m_animation_duration(time), m_controller_app(controller_app), + animation_button_label("ANIMATE"), m_animation_state(STOP) { - } - - -void Simulation::add_simulation_state(SimulationState& simulationState) +void Simulation::add_simulation_state(SimulationState &simulationState) { float time = m_simulation_states.size() * m_animation_duration; @@ -42,7 +39,6 @@ void Simulation::create_animations() sequence_clip_min.then(iterator->min_clip, m_animation_duration); } - auto group = std::make_shared(); group->apply(&m_eye_animation, sequence_eye); group->apply(&m_target_animation, sequence_target); @@ -52,7 +48,6 @@ void Simulation::create_animations() group->apply(&m_min_clip_animation, sequence_clip_min); m_timeline.addShared(group); - } } @@ -61,7 +56,6 @@ void Simulation::update_simulation() if (m_animation_state != PAUSE) { update_time_step(); - } if (m_timeline.isFinished()) { @@ -74,16 +68,13 @@ void Simulation::update_simulation() m_controller_app.stop_movie(); } } - } void Simulation::update_time_step() { m_timeline.step(1.0 / 30.0); - } - void Simulation::set_animation_state() { if (m_animation_state == STOP) @@ -108,23 +99,29 @@ void Simulation::set_animation_state() } m_is_animate_path = true; - } ANIMATION_STATE Simulation::get_animation_state() { - if (m_timeline.isFinished()) + switch (m_timeline.isFinished()) { + case true: return STOP; - } - else if (!m_timeline.isFinished() && m_animation_state == PLAYING) + case false: { - return PLAYING; + if (m_animation_state == STOP) + { + return PAUSE; + } + else + { + return PLAYING; + } } - else if (!m_timeline.isFinished() && m_animation_state == STOP) - { - return PAUSE; + default: + return STOP; } + } std::string Simulation::get_camera_animation_state() @@ -142,12 +139,12 @@ void Simulation::set_camera_animation_duration(float duration) m_animation_duration = duration; } -const std::list& Simulation::get_simulation_states() +const std::list &Simulation::get_simulation_states() { return m_simulation_states; } -SimulationState& Simulation::get_simulation_state_at(unsigned int index) +SimulationState &Simulation::get_simulation_state_at(unsigned int index) { auto poi_iterator = m_simulation_states.begin(); std::advance(poi_iterator, index); @@ -158,7 +155,6 @@ SimulationState Simulation::get_current_simulation_state() { PointOfInterest poi(m_eye_animation.value(), m_target_animation.value(), m_up_animation.value(), m_radius_animation.value()); - SimulationState current_state; current_state.poi = poi; current_state.max_clip = m_max_clip_animation; @@ -173,17 +169,15 @@ void Simulation::remove_simulation_state(unsigned int index) std::advance(poi_iterator, index); std::string time_label = poi_iterator->time_label; poi_iterator = m_simulation_states.erase(poi_iterator); - for (poi_iterator ; poi_iterator != m_simulation_states.end();poi_iterator++) + for (poi_iterator; poi_iterator != m_simulation_states.end(); poi_iterator++) { std::string current_time_label = poi_iterator->time_label; poi_iterator->time_label = time_label; time_label = current_time_label; } - } float Simulation::get_animation_duration() { return m_animation_duration; } - diff --git a/src/loader/VRDataLoader.cpp b/src/loader/VRDataLoader.cpp index 8166789..23edbb7 100644 --- a/src/loader/VRDataLoader.cpp +++ b/src/loader/VRDataLoader.cpp @@ -1,12 +1,11 @@ #include "loader/VRDataLoader.h" #include - //#include #include #include -#include +#include #include "vrapp/VRVolumeApp.h" #ifdef _MSC_VER @@ -20,52 +19,34 @@ #endif - -//VRDataLoader* VRDataLoader::m_instance = nullptr; - VRDataLoader::VRDataLoader() { - } -//VRDataLoader* VRDataLoader::get_instance() -//{ -// if (!m_instance) -// { -// m_instance = new VRDataLoader; -// } -// return m_instance; -//}VRDataLoader* VRDataLoader::get_instance() -//{ -// if (!m_instance) -// { -// m_instance = new VRDataLoader; -// } -// return m_instance; -//} - - -void VRDataLoader::load_txt_file( VRVolumeApp& vrVolumeApp, std::string& filename) +void VRDataLoader::load_txt_file(VRVolumeApp &vrVolumeApp, std::string &filename) { - + std::ifstream inFile; inFile.open(filename); std::string line; - //std::filesystem::path p_filename(filename); cppfs::FilePath p_filename(filename); - while (getline(inFile, line)) { - if (line[0] != '#') { + while (getline(inFile, line)) + { + if (line[0] != '#') + { std::vector vals; // Create vector to hold our words std::stringstream ss(line); std::string buf; - while (ss >> buf) { + while (ss >> buf) + { vals.push_back(buf); } - if (vals.size() > 0) { + if (vals.size() > 0) + { std::string tag = vals[0]; if (tag == "animated") { @@ -82,7 +63,7 @@ void VRDataLoader::load_txt_file( VRVolumeApp& vrVolumeApp, std::string& filena std::cerr << "text at position " << vals[2] << " , " << vals[3] << " , " << vals[5] << std::endl; std::cerr << "text Size " << vals[6] << std::endl; std::cerr << "for Volume " << vals[7] << std::endl; - std::string label = p_filename.directoryPath() + OS_SLASH_LOCAL + vals[1]; + std::string label = p_filename.directoryPath() + OS_SLASH_LOCAL + vals[1]; vrVolumeApp.add_label(label, stof(vals[2]), stof(vals[3]), stof(vals[4]), stof(vals[5]), stof(vals[6]), stoi(vals[7]) - 1); } if (tag == "desc") @@ -92,29 +73,19 @@ void VRDataLoader::load_txt_file( VRVolumeApp& vrVolumeApp, std::string& filena int descHeight = stoi(vals[2]); std::string fileName = vals[1]; vrVolumeApp.set_description(descHeight, fileName); - } if (tag == "mesh") { - // std::cerr << "Load Mesh " << vals[1] << std::endl; - // std::cerr << "for Volume " << vals[2] << std::endl; - - //std::string fullPath = p_filename.parent_path().string() + OS_SLASH_LOCAL + vals[1]; std::string fullPath = p_filename.directoryPath() + OS_SLASH_LOCAL + vals[1]; std::cerr << "Load Mesh " << fullPath << std::endl; std::string shaderFilePath = p_filename.directoryPath() + OS_SLASH_LOCAL + "shaders"; vrVolumeApp.set_mesh(stoi(vals[2]), fullPath, shaderFilePath); - } if (tag == "texture") { - - //std::cerr << "for Volume " << vals[2] << std::endl; std::string fullPath = p_filename.directoryPath() + OS_SLASH_LOCAL + vals[1]; vrVolumeApp.set_texture(fullPath); - - } if (tag == "numVolumes") { @@ -125,7 +96,6 @@ void VRDataLoader::load_txt_file( VRVolumeApp& vrVolumeApp, std::string& filena { vrVolumeApp.add_data_label(vals[i + 2]); } - } else if (tag.rfind("volume") == 0) { @@ -135,20 +105,17 @@ void VRDataLoader::load_txt_file( VRVolumeApp& vrVolumeApp, std::string& filena std::string strVolumeIndex = tag.substr(6); size_t volumeIndex = std::stoi(strVolumeIndex); - vals[1] = p_filename.directoryPath() + OS_SLASH_LOCAL + vals[1]; - - - std::vector*>& v = vrVolumeApp.get_promise(volumeIndex); - std::promise* pm = new std::promise(); + std::vector *> &v = vrVolumeApp.get_promise(volumeIndex); + std::promise *pm = new std::promise(); v.push_back(pm); - std::vector>* fut; + std::vector> *fut; if (!vrVolumeApp.get_future(volumeIndex)) { - vrVolumeApp.set_future(volumeIndex, new std::vector>); + vrVolumeApp.set_future(volumeIndex, new std::vector>); } fut = vrVolumeApp.get_future(volumeIndex); @@ -158,12 +125,9 @@ void VRDataLoader::load_txt_file( VRVolumeApp& vrVolumeApp, std::string& filena vrVolumeApp.set_future(volumeIndex, fut); vrVolumeApp.init_volume_loading(volumeIndex, vals); - - } } } - } inFile.close(); vrVolumeApp.set_loaded_file(filename); diff --git a/src/main.cpp b/src/main.cpp index 30f208d..29eaf21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,8 +17,7 @@ int main(int argc, char **argv) { int num_parameters = 4; char * arguments[] = { argv[0],"-c","desktop_observer.minvr", "use2DUI"}; - //char* arguments[] = { argv[0],"-c","desktop.minvr", "use2DUI" }; - + VolumeVisualizationApp app(num_parameters, arguments); diff --git a/src/render/VolumeRaycastShader.cpp b/src/render/VolumeRaycastShader.cpp index 1ef1793..3e670e7 100644 --- a/src/render/VolumeRaycastShader.cpp +++ b/src/render/VolumeRaycastShader.cpp @@ -1,26 +1,26 @@ // ----------------------------------. // Copyright © 2015, Brown University, Providence, RI. -// +// // All Rights Reserved -// -// Use of the software is provided under the terms of the GNU General Public License version 3 -// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided -// that this copyright notice appear in all copies and that the name of Brown University not be used in -// advertising or publicity pertaining to the use or distribution of the software without specific written +// +// Use of the software is provided under the terms of the GNU General Public License version 3 +// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided +// that this copyright notice appear in all copies and that the name of Brown University not be used in +// advertising or publicity pertaining to the use or distribution of the software without specific written // prior permission from Brown University. -// +// // See license.txt for further information. -// -// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED “AS ISâ€, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY -// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING -// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION -// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS +// PROVIDED “AS ISâ€, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY +// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING +// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION +// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // ---------------------------------- -// +// ///\file VolumeRaycastShader.cpp ///\author Benjamin Knorlein ///\date 11/30/2017 @@ -31,218 +31,214 @@ #include "render/VolumeRaycastShader.h" - #include -VolumeRaycastShader::VolumeRaycastShader() : m_use_blending{ false }, m_blend_volume{ 0 }, m_blending_alpha{ 0 }, m_clip_min{ 0.0 }, m_clip_max{ 1.0 } -//: m_threshold{ 0.0f }, m_multiplier{ 0.5 } +VolumeRaycastShader::VolumeRaycastShader() : m_use_blending{false}, m_blend_volume{0}, m_blending_alpha{0}, m_clip_min{0.0}, m_clip_max{1.0} { - /*m_viewport[0] = 1.0; - m_viewport[1] = 1.0;*/ - m_shader = "VolumeRaycastShader"; m_vertexShader = "#version 330 core\n" - "layout(location = 0) in vec3 vVertex;\n" //object space vertex position - "uniform mat4 MVP; \n" //combined modelview projection matrix - "smooth out vec3 vUV; \n" //3D texture coordinates for texture lookup in the fragment shader - "void main()\n" - "{\n" - //get the clipspace position - "gl_Position = MVP*vec4(vVertex, 1); \n" - //get the 3D texture coordinates by adding (0.5,0.5,0.5) to the object space - //vertex position. Since the unit cube is at origin (min: (-0.5,-0.5,-0.5) and max: (0.5,0.5,0.5)) - //adding (0.5,0.5,0.5) to the unit cube object space position gives us values from (0,0,0) to - //(1,1,1) - "vUV = vVertex + vec3(0.5001); \n" - "}\n"; + "layout(location = 0) in vec3 vVertex;\n" // object space vertex position + "uniform mat4 MVP; \n" // combined modelview projection matrix + "smooth out vec3 vUV; \n" // 3D texture coordinates for texture lookup in the fragment shader + "void main()\n" + "{\n" + // get the clipspace position + "gl_Position = MVP*vec4(vVertex, 1); \n" + // get the 3D texture coordinates by adding (0.5,0.5,0.5) to the object space + // vertex position. Since the unit cube is at origin (min: (-0.5,-0.5,-0.5) and max: (0.5,0.5,0.5)) + // adding (0.5,0.5,0.5) to the unit cube object space position gives us values from (0,0,0) to + //(1,1,1) + "vUV = vVertex + vec3(0.5); \n" + "}\n"; m_fragmentShader = - "#version 330 core\n" - "vec2 intersect_box(vec3 orig, vec3 dir, vec3 clip_min, vec3 clip_max) { \n" - "dir += vec3(0.0000001); \n" - "vec3 inv_dir = 1.0 / dir; \n" - "vec3 tmin_tmp = (clip_min - orig) * inv_dir; \n" - "vec3 tmax_tmp = (clip_max - orig) * inv_dir; \n" - "vec3 tmin = min(tmin_tmp, tmax_tmp); \n" - "vec3 tmax = max(tmin_tmp, tmax_tmp); \n" - "float t0 = max(tmin.x, max(tmin.y, tmin.z)); \n" - "float t1 = min(tmax.x, min(tmax.y, tmax.z)); \n" - "return vec2(t0, t1); \n" - "}\n" - - "layout(location = 0) out vec4 vFragColor; \n" //fragment shader output - "smooth in vec3 vUV; \n" //3D texture coordinates form vertex shader interpolated by rasterizer - "uniform sampler3D volume;\n" //volume dataset - "uniform mat4 clipPlane; \n" - "uniform bool clipping;\n" - "uniform float threshold;\n" - "uniform float multiplier;\n" - "uniform vec3 camPos;\n" //camera position - "uniform vec3 step_size;\n" //ray step size - "const int MAX_SAMPLES = 3000;\n" //total samples for each ray march step - "uniform int channel;\n" - "uniform sampler2D lut;\n" //transferfunction - "uniform bool useLut;\n" - "uniform bool useMultiLut;\n" - "uniform sampler2D depth;\n" - "uniform vec2 viewport;\n" - "uniform mat4 P_inv; \n" - "uniform bool useBlend;\n" - "uniform sampler3D blendVolume;\n" //volume dataset - "uniform float blendAlpha;\n" - "uniform vec3 clip_min;\n" - "uniform vec3 clip_max;\n" - "void main()\n" - "{\n" - //get the 3D texture coordinates for lookup into the volume dataset - "vec3 dataPos = vUV; \n" - - //get the object space position by subracting 0.5 from the - //3D texture coordinates. Then subtraact it from camera position - //and normalize to get the ray marching direction - "vec3 geomDir = normalize( dataPos - camPos); \n" - - //get the t values for the intersection with the box" - "vec2 t_hit = intersect_box(camPos, geomDir,clip_min,clip_max); \n" - - // We don't want to sample voxels behind the eye if it's - // inside the volume, so keep the starting point at or in front - // of the eye - "if(t_hit.x < 0.0f) t_hit.x= max(t_hit.x, 0.0); \n" - - //We not know if the ray was cast from the back or the front face. (Note: For now we also render the back face only) - //To ensure we update dataPos and t_hit to reflect a ray from entry point to exit - "dataPos = camPos + t_hit.x * geomDir;\n" - "t_hit.y = t_hit.y-t_hit.x; \n" - "t_hit.x = 0.0001f; \n" - - //get t for the clipping plane and overwrite the entry point - "if(clipping){ \n" - "vec4 p_in = clipPlane * vec4(dataPos + t_hit.x * geomDir, 1);\n" - "vec4 p_out = clipPlane * vec4(dataPos + t_hit.y * geomDir, 1);\n" - "if(p_in.y * p_out.y < 0.0f ){\n" - //both points lie on different sides of the plane - //we need to compute a new clippoint - "vec4 c_pos = clipPlane * vec4(dataPos, 1);\n" - "vec4 c_dir = clipPlane * vec4(geomDir, 0);\n" - "float t_clip = -c_pos.y / c_dir.y ;\n" - //update either entry or exit based on which is on the clipped side - "if (p_in.y > 0.0f){\n" - "t_hit.x = t_clip; \n" - "}else{\n" - "t_hit.y = t_clip; \n" - "}\n" - "}else{\n" - //both points lie on the same side of the plane. - //if one of them is on the wrong side they can be clipped - "if(p_in.y > 0.0f)\n" - "discard;\n" - "}\n" - "}\n" - - //Compute occlusion point in volume coordinates - "float d = texture(depth, vec2(gl_FragCoord.x/viewport.x,gl_FragCoord.y/viewport.y)).r; \n" - "vec4 d_ndc = vec4((gl_FragCoord.x / viewport.x - 0.5) * 2.0,(gl_FragCoord.y / viewport.y - 0.5) * 2.0, (d - 0.5) * 2.0, 1.0); \n" - "d_ndc = P_inv * d_ndc; \n " - "d_ndc = d_ndc / d_ndc.w; \n" - - //compute t_occ and check if it closer than the exit point - /*"float t_occ = ((d_ndc.x + 0.5) - dataPos.x) / geomDir.x; \n" - "t_hit.y = min(t_hit.y, t_occ); \n"*/ - - //first value should always be lower by definition and this case should never occur. If it does discard the fragment. - "if (t_hit.x > t_hit.y) \n" - "discard; \n" - - //compute step size as the minimum of the stepsize - "float dt = min(step_size.x, min(step_size.y, step_size.z)) ;\n" - - // Step 4: Starting from the entry point, march the ray through the volume - // and sample it - "dataPos = dataPos + t_hit.x * geomDir; \n" - "for (float t = t_hit.x; t < t_hit.y; t += dt) {\n" - // data fetching from the red channel of volume texture - "vec4 sample; \n" - "if (channel == 1){ \n" - "sample = texture(volume, dataPos).rrrr; \n" - "}else if (channel == 2){ \n" - "sample = texture(volume, dataPos).gggg; \n" - "}else if (channel == 3){ \n" - "sample = texture(volume, dataPos).bbbb; \n" - "}else if (channel == 4){ \n" - "sample = texture(volume, dataPos).aaaa; \n" - "}else if (channel == 5){ \n" - "sample = texture(volume, dataPos); \n" - "}else{ \n" - "sample = texture(volume, dataPos); \n" - "sample.a = max(sample.r, max(sample.g,sample.b)) ; " - "}\n" - - "if(useBlend){ \n" - "vec4 sample_blend; \n" - "if (channel == 1){ \n" - "sample_blend = texture(blendVolume, dataPos).rrrr; \n" - "}else if (channel == 2){ \n" - "sample_blend = texture(blendVolume, dataPos).gggg; \n" - "}else if (channel == 3){ \n" - "sample_blend = texture(blendVolume, dataPos).bbbb; \n" - "}else if (channel == 4){ \n" - "sample_blend = texture(blendVolume, dataPos).aaaa; \n" - "}else if (channel == 5){ \n" - "sample_blend = texture(blendVolume, dataPos); \n" - "}else{ \n" - "sample_blend = texture(blendVolume, dataPos); \n" - "sample_blend.a = max(sample_blend.r, max(sample_blend.g,sample_blend.b)) ; " - "}\n" - - "sample = (vec4(1.0f - blendAlpha) * sample) + (vec4(blendAlpha) * sample_blend);\n" - "}\n" - - - //threshold based on alpha - "sample.a = (sample.a > threshold) ? sample.a : 0.0f ;\n" - - //transferfunction - "if(useLut) {\n" - "if(useMultiLut){\n" - "sample.r = texture(lut, vec2(sample.r,0.5)).r;" - "sample.g = texture(lut, vec2(sample.g,0.5)).g;" - "sample.b = texture(lut, vec2(sample.b,0.5)).b;" - "sample.a = max(sample.r, max(sample.g,sample.b)) ; " - "}else{\n" - "sample = texture(lut, vec2(sample.a,0.5));" - "}\n" - "}\n" - - //assume alpha is the highest channel and gamma correction - "sample.a = sample.a * multiplier; \n" ///needs changing - - - //blending (front to back) - "vFragColor.rgb += (1.0 - vFragColor.a) * sample.a * sample.rgb;\n" - "vFragColor.a += (1.0 - vFragColor.a) * sample.a;\n" - - //early exit if opacity is reached - "if (vFragColor.a >= 0.95) \n" - "break;\n" - - //advance point - "dataPos += geomDir * dt; \n" - "} \n" - - //remove fragments for correct depthbuffer - "if (vFragColor.a == 0.0f)" - "discard;" - "}\n"; + "#version 330 core\n" + "vec2 intersect_box(vec3 orig, vec3 dir, vec3 clip_min, vec3 clip_max) { \n" + "dir += vec3(0.0000001); \n" + "vec3 inv_dir = 1.0 / dir; \n" + "vec3 tmin_tmp = (clip_min - orig) * inv_dir; \n" + "vec3 tmax_tmp = (clip_max - orig) * inv_dir; \n" + "vec3 tmin = min(tmin_tmp, tmax_tmp); \n" + "vec3 tmax = max(tmin_tmp, tmax_tmp); \n" + "float t0 = max(tmin.x, max(tmin.y, tmin.z)); \n" + "float t1 = min(tmax.x, min(tmax.y, tmax.z)); \n" + "return vec2(t0, t1); \n" + "}\n" + + "layout(location = 0) out vec4 vFragColor; \n" // fragment shader output + "smooth in vec3 vUV; \n" // 3D texture coordinates form vertex shader interpolated by rasterizer + "uniform sampler3D volume;\n" // volume dataset + "uniform mat4 clipPlane; \n" + "uniform bool clipping;\n" + "uniform float threshold;\n" + "uniform float multiplier;\n" + "uniform vec3 camPos;\n" // camera position + "uniform vec3 step_size;\n" // ray step size + "const int MAX_SAMPLES = 3000;\n" // total samples for each ray march step + "uniform int channel;\n" + "uniform sampler2D lut;\n" // transferfunction + "uniform bool useLut;\n" + "uniform bool useMultiLut;\n" + "uniform sampler2D depth;\n" + "uniform vec2 viewport;\n" + "uniform mat4 P_inv; \n" + "uniform bool useBlend;\n" + "uniform sampler3D blendVolume;\n" // volume dataset + "uniform float blendAlpha;\n" + "uniform vec3 clip_min;\n" + "uniform vec3 clip_max;\n" + "void main()\n" + "{\n" + // get the 3D texture coordinates for lookup into the volume dataset + "vec3 dataPos = vUV; \n" + + // get the object space position by subracting 0.5 from the + // 3D texture coordinates. Then subtraact it from camera position + // and normalize to get the ray marching direction + "vec3 geomDir = normalize( dataPos - camPos); \n" + + // get the t values for the intersection with the box" + "vec2 t_hit = intersect_box(camPos, geomDir,clip_min,clip_max); \n" + + // We don't want to sample voxels behind the eye if it's + // inside the volume, so keep the starting point at or in front + // of the eye + "if(t_hit.x < 0.0f) t_hit.x= max(t_hit.x, 0.0); \n" + + // We not know if the ray was cast from the back or the front face. (Note: For now we also render the back face only) + // To ensure we update dataPos and t_hit to reflect a ray from entry point to exit + "dataPos = camPos + t_hit.x * geomDir;\n" + "t_hit.y = t_hit.y-t_hit.x; \n" + "t_hit.x = 0.0001f; \n" + + // get t for the clipping plane and overwrite the entry point + "if(clipping){ \n" + "vec4 p_in = clipPlane * vec4(dataPos + t_hit.x * geomDir, 1);\n" + "vec4 p_out = clipPlane * vec4(dataPos + t_hit.y * geomDir, 1);\n" + "if(p_in.y * p_out.y < 0.0f ){\n" + // both points lie on different sides of the plane + // we need to compute a new clippoint + "vec4 c_pos = clipPlane * vec4(dataPos, 1);\n" + "vec4 c_dir = clipPlane * vec4(geomDir, 0);\n" + "float t_clip = -c_pos.y / c_dir.y ;\n" + // update either entry or exit based on which is on the clipped side + "if (p_in.y > 0.0f){\n" + "t_hit.x = t_clip; \n" + "}else{\n" + "t_hit.y = t_clip; \n" + "}\n" + "}else{\n" + // both points lie on the same side of the plane. + // if one of them is on the wrong side they can be clipped + "if(p_in.y > 0.0f)\n" + "discard;\n" + "}\n" + "}\n" + + // Compute occlusion point in volume coordinates + "float d = texture(depth, vec2(gl_FragCoord.x/viewport.x,gl_FragCoord.y/viewport.y)).r; \n" + "vec4 d_ndc = vec4((gl_FragCoord.x / viewport.x - 0.5) * 2.0,(gl_FragCoord.y / viewport.y - 0.5) * 2.0, (d - 0.5) * 2.0, 1.0); \n" + "d_ndc = P_inv * d_ndc; \n " + "d_ndc = d_ndc / d_ndc.w; \n" + + // compute t_occ and check if it closer than the exit point + // The code below ocludes portion of the voxels at the center of the unit cube. + // Removing this lines fixes the issue, but it generates artifacts in the APPLE rendering. + // Do some research why the ray caster is occliding those specific voxels + /*"float t_occ = ((d_ndc.x + 0.5) - dataPos.x) / geomDir.x; \n" + "t_hit.y = min(t_hit.y, t_occ); \n"*/ + + // first value should always be lower by definition and this case should never occur. If it does discard the fragment. + "if (t_hit.x > t_hit.y) \n" + "discard; \n" + + // compute step size as the minimum of the stepsize + "float dt = min(step_size.x, min(step_size.y, step_size.z)) ;\n" + + // Step 4: Starting from the entry point, march the ray through the volume + // and sample it + "dataPos = dataPos + t_hit.x * geomDir; \n" + "for (float t = t_hit.x; t < t_hit.y; t += dt) {\n" + // data fetching from the red channel of volume texture + "vec4 sample; \n" + "if (channel == 1){ \n" + "sample = texture(volume, dataPos).rrrr; \n" + "}else if (channel == 2){ \n" + "sample = texture(volume, dataPos).gggg; \n" + "}else if (channel == 3){ \n" + "sample = texture(volume, dataPos).bbbb; \n" + "}else if (channel == 4){ \n" + "sample = texture(volume, dataPos).aaaa; \n" + "}else if (channel == 5){ \n" + "sample = texture(volume, dataPos); \n" + "}else{ \n" + "sample = texture(volume, dataPos); \n" + "sample.a = max(sample.r, max(sample.g,sample.b)) ; " + "}\n" + + "if(useBlend){ \n" + "vec4 sample_blend; \n" + "if (channel == 1){ \n" + "sample_blend = texture(blendVolume, dataPos).rrrr; \n" + "}else if (channel == 2){ \n" + "sample_blend = texture(blendVolume, dataPos).gggg; \n" + "}else if (channel == 3){ \n" + "sample_blend = texture(blendVolume, dataPos).bbbb; \n" + "}else if (channel == 4){ \n" + "sample_blend = texture(blendVolume, dataPos).aaaa; \n" + "}else if (channel == 5){ \n" + "sample_blend = texture(blendVolume, dataPos); \n" + "}else{ \n" + "sample_blend = texture(blendVolume, dataPos); \n" + "sample_blend.a = max(sample_blend.r, max(sample_blend.g,sample_blend.b)) ; " + "}\n" + + "sample = (vec4(1.0f - blendAlpha) * sample) + (vec4(blendAlpha) * sample_blend);\n" + "}\n" + + // threshold based on alpha + "sample.a = (sample.a > threshold) ? sample.a : 0.0f ;\n" + + // transferfunction + "if(useLut) {\n" + "if(useMultiLut){\n" + "sample.r = texture(lut, vec2(sample.r,0.5)).r;" + "sample.g = texture(lut, vec2(sample.g,0.5)).g;" + "sample.b = texture(lut, vec2(sample.b,0.5)).b;" + "sample.a = max(sample.r, max(sample.g,sample.b)) ; " + "}else{\n" + "sample = texture(lut, vec2(sample.a,0.5));" + "}\n" + "}\n" + + // assume alpha is the highest channel and gamma correction + "sample.a = sample.a * multiplier; \n" /// needs changing + + // blending (front to back) + "vFragColor.rgb += (1.0 - vFragColor.a) * sample.a * sample.rgb;\n" + "vFragColor.a += (1.0 - vFragColor.a) * sample.a;\n" + + // early exit if opacity is reached + "if (vFragColor.a >= 0.95) \n" + "break;\n" + + // advance point + "dataPos += geomDir * dt; \n" + "} \n" + + // remove fragments for correct depthbuffer + "if (vFragColor.a == 0.0f)" + "discard;" + "}\n"; } VolumeRaycastShader::~VolumeRaycastShader() { } -void VolumeRaycastShader::render(glm::mat4& MVP, glm::mat4& clipPlane, glm::vec3& camPos) +void VolumeRaycastShader::render(glm::mat4 &MVP, glm::mat4 &clipPlane, glm::vec3 &camPos) { if (m_use_blending) { @@ -292,7 +288,7 @@ void VolumeRaycastShader::initGL() bindProgram(); - //add attributes and uniforms + // add attributes and uniforms m_volume_uniform = glGetUniformLocation(m_programID, "volume"); m_MVP_uniform = glGetUniformLocation(m_programID, "MVP"); m_clipPlane_uniform = glGetUniformLocation(m_programID, "clipPlane"); @@ -318,7 +314,6 @@ void VolumeRaycastShader::initGL() m_clip_min_uniform = glGetUniformLocation(m_programID, "clip_min"); m_clip_max_uniform = glGetUniformLocation(m_programID, "clip_max"); - ////pass constant uniforms at initialization glUniform1i(m_volume_uniform, 0); glUniform1i(m_lut_uniform, 1); @@ -326,5 +321,4 @@ void VolumeRaycastShader::initGL() glUniform1i(m_blendVolume_uniform, 3); unbindProgram(); - } diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index eda44cf..8bf83a8 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -38,8 +38,8 @@ #include #endif -#include -#include +#include +#include #include "GLMLoader.h" #include #include @@ -49,44 +49,37 @@ #include "Model.h" #include "Texture.h" - -VRVolumeApp::VRVolumeApp() :m_mesh_model(nullptr), m_clip_max{ 1.0f }, m_clip_min{ 0.0f }, m_clip_ypr{ 0.0f }, m_clip_pos{ 0.0 }, m_wasd_pressed(0), -m_lookingGlass(false), m_isInitailized(false), m_speed(0.01f), m_movieAction(nullptr), m_moviename("movie.mp4"), m_noColor(0.0f), -m_ambient(0.2f, 0.2f, 0.2f, 1.0f), m_diffuse(0.5f, 0.5f, 0.5f, 1.0f), m_ui_view(nullptr), m_animated(false), m_numVolumes(0), m_selectedVolume(0), -m_multiplier(1.0f), m_threshold(0.0f), m_frame(0.0f), m_use_multi_transfer(false), m_clipping(false), m_show_menu(true), -m_window_properties(nullptr), m_animation_speed(1.0f), m_current_movie_state(MOVIE_STOP), m_app_mode(MANUAL), m_end_load(false) +VRVolumeApp::VRVolumeApp() : m_mesh_model(nullptr), m_clip_max{1.0f}, m_clip_min{0.0f}, m_clip_ypr{0.0f}, m_clip_pos{0.0}, m_wasd_pressed(0), + m_lookingGlass(false), m_isInitailized(false), m_speed(0.01f), m_movieAction(nullptr), m_moviename("movie.mp4"), m_noColor(0.0f), + m_ambient(0.2f, 0.2f, 0.2f, 1.0f), m_diffuse(0.5f, 0.5f, 0.5f, 1.0f), m_ui_view(nullptr), m_animated(false), m_numVolumes(0), m_selectedVolume(0), + m_multiplier(1.0f), m_threshold(0.0f), m_frame(0.0f), m_use_multi_transfer(false), m_clipping(false), m_show_menu(true), + m_window_properties(nullptr), m_animation_speed(1.0f), m_current_movie_state(MOVIE_STOP), m_app_mode(MANUAL), m_end_load(false) { m_renders.push_back(new VolumeSliceRenderer()); m_renders.push_back(new VolumeRaycastRenderer()); } - - VRVolumeApp::~VRVolumeApp() { - if (m_ui_view) - { - delete m_ui_view; - } - for (int i = 0; i < m_volumes.size(); i++) { - std::vector< Volume* > v = m_volumes[i]; + for (int i = 0; i < m_volumes.size(); i++) + { + std::vector v = m_volumes[i]; for (int j = 0; j < v.size(); j++) { delete v[j]; } - } m_volumes.clear(); + if (m_ui_view) + delete m_ui_view; delete m_window_properties; } - void VRVolumeApp::initialize() { - if (!m_isInitailized) { // std::cout << "initialize 1" << std::endl; @@ -96,7 +89,7 @@ void VRVolumeApp::initialize() if (!m_ui_view) { std::cout << "initialize UI " << std::endl; - m_ui_view = new UIView(*this); + m_ui_view = new UIView(*this); m_ui_view->init_ui(m_is2d, m_lookingGlass); } m_window_properties = new Window_Properties(); @@ -104,12 +97,10 @@ void VRVolumeApp::initialize() m_labels = new Labels(m_line_shader, m_simple_texture_shader); m_labels->set_parent_directory(get_directory_path()); - m_isInitailized = true; m_rendercount = 0; std::cout << "initialize end" << std::endl; } - } void VRVolumeApp::initialize_GL() @@ -119,7 +110,6 @@ void VRVolumeApp::initialize_GL() ren->initGL(); } - glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, glm::value_ptr(m_ambient)); @@ -132,24 +122,19 @@ void VRVolumeApp::initialize_GL() glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glClearColor(0.0, 0.0, 0.0, 1); - } - - void VRVolumeApp::load_mesh_model() { - for (std::string filename : m_models_filenames) { + for (std::string filename : m_models_filenames) + { m_mesh_model = GLMLoader::loadObjModel(filename); - if (m_texture) { m_mesh_model->setTexture(m_texture); } - - } m_models_filenames.clear(); } @@ -174,15 +159,14 @@ void VRVolumeApp::load_shaders() void VRVolumeApp::initialize_textures() { add_lodaded_textures(); - - for (int i = 0; i < m_volumes.size(); i++) + + for (int i = 0; i < m_volumes.size(); i++) { - std::vector< Volume* > vlm = m_volumes[i]; + std::vector vlm = m_volumes[i]; for (int j = 0; j < vlm.size(); j++) { vlm[j]->initGL(); } - } } @@ -197,7 +181,6 @@ void VRVolumeApp::update_trackBall_state() { get_trackball_camera().wasd_pressed(m_wasd_pressed); } - } void VRVolumeApp::update_animation(float fps) @@ -206,7 +189,7 @@ void VRVolumeApp::update_animation(float fps) { if (m_volumes.size()) { - //m_animation_speed = fps; + // m_animation_speed = fps; m_ui_view->update_animation(m_speed, m_volumes[m_selectedVolume].size() - 1); } } @@ -259,17 +242,17 @@ void VRVolumeApp::set_frame(float frame) m_frame = frame; } -glm::vec4& VRVolumeApp::get_no_color() +glm::vec4 &VRVolumeApp::get_no_color() { return m_noColor; } -glm::vec4& VRVolumeApp::get_ambient() +glm::vec4 &VRVolumeApp::get_ambient() { return m_ambient; } -glm::vec4& VRVolumeApp::get_diffuse() +glm::vec4 &VRVolumeApp::get_diffuse() { return m_diffuse; } @@ -309,7 +292,7 @@ void VRVolumeApp::set_threshold(float threshold) m_threshold = threshold; } -void VRVolumeApp::add_label(std::string& text, float x, float y, float z, float textPosZ, float size, int volume) +void VRVolumeApp::add_label(std::string &text, float x, float y, float z, float textPosZ, float size, int volume) { if (m_labels) { @@ -317,7 +300,7 @@ void VRVolumeApp::add_label(std::string& text, float x, float y, float z, float } } -void VRVolumeApp::set_description(int descriptionHeight, std::string& descriptionFilename) +void VRVolumeApp::set_description(int descriptionHeight, std::string &descriptionFilename) { m_descriptionHeight = descriptionHeight; m_descriptionFilename = descriptionFilename; @@ -325,17 +308,16 @@ void VRVolumeApp::set_description(int descriptionHeight, std::string& descriptio // std::cerr << m_description[0] << std::endl; } -void VRVolumeApp::set_mesh(int volumeId, std::string& fileName, std::string& shaderFilePath) +void VRVolumeApp::set_mesh(int volumeId, std::string &fileName, std::string &shaderFilePath) { m_models_volumeID.push_back(volumeId - 1); m_models_filenames.push_back(fileName); m_models_MV.push_back(glm::mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)); m_shader_file_path = shaderFilePath; - } -void VRVolumeApp::set_texture(std::string& fileNamePath) +void VRVolumeApp::set_texture(std::string &fileNamePath) { std::cerr << "Load texture " << fileNamePath << std::endl; m_texture = new Texture(GL_TEXTURE_2D, fileNamePath); @@ -344,7 +326,7 @@ void VRVolumeApp::set_texture(std::string& fileNamePath) void VRVolumeApp::init_num_volumes(int nVolumes) { m_numVolumes = nVolumes; - //m_data_labels.resize(m_numVolumes); + // m_data_labels.resize(m_numVolumes); m_volumes.resize(m_numVolumes); m_promises.resize(m_numVolumes); m_futures.resize(m_numVolumes); @@ -355,44 +337,42 @@ void VRVolumeApp::init_num_volumes(int nVolumes) m_ui_view->init_ui(m_is2d, m_lookingGlass); m_ui_view->update_ui(m_numVolumes); } - - } -void VRVolumeApp::add_data_label(std::string& label) +void VRVolumeApp::add_data_label(std::string &label) { m_ui_view->add_data_label(label); } -std::vector*>& VRVolumeApp::get_promise(int index) +std::vector *> &VRVolumeApp::get_promise(int index) { return m_promises[index - 1]; } -std::vector>* VRVolumeApp::get_future(int index) +std::vector> *VRVolumeApp::get_future(int index) { return m_futures[index - 1]; } -void VRVolumeApp::set_future(int index, std::vector>* futures) +void VRVolumeApp::set_future(int index, std::vector> *futures) { m_futures[index - 1] = futures; } -std::vector & VRVolumeApp::get_thread(int index) +std::vector &VRVolumeApp::get_thread(int index) { - return m_threads[index - 1]; + return m_threads[index - 1]; } void VRVolumeApp::init_volume_loading(int index, std::vector vals) { - std::vector & ths = m_threads[index - 1]; - std::vector*> v2 = m_promises[index - 1]; + std::vector &ths = m_threads[index - 1]; + std::vector *> v2 = m_promises[index - 1]; ths.emplace_back(new std::thread(&VRVolumeApp::load_volume, this, vals, v2.back())); } -void VRVolumeApp::set_character_state(std::string& eventName, int state) +void VRVolumeApp::set_character_state(std::string &eventName, int state) { size_t pos = eventName.find("Kbd"); size_t pos_ = eventName.find("_"); @@ -404,7 +384,7 @@ void VRVolumeApp::set_character_state(std::string& eventName, int state) if (keyStr.size() == 1) { int keyCode = keyStr[0]; - ImGuiIO& io = ImGui::GetIO(); + ImGuiIO &io = ImGui::GetIO(); if (state == 1) { io.KeysDown[keyCode] = true; @@ -445,35 +425,31 @@ void VRVolumeApp::set_character_state(std::string& eventName, int state) addTextToInputField(space);*/ } } - } - } - - } -void VRVolumeApp::set_directory_path(std::string& dir_path) +void VRVolumeApp::set_directory_path(std::string &dir_path) { m_directiort_path = dir_path; } -std::string& VRVolumeApp::get_directory_path() +std::string &VRVolumeApp::get_directory_path() { return m_directiort_path; } -void VRVolumeApp::set_loaded_file(std::string& dir_path) +void VRVolumeApp::set_loaded_file(std::string &dir_path) { m_current_file_loaded = dir_path; } -std::string& VRVolumeApp::get_loaded_file() +std::string &VRVolumeApp::get_loaded_file() { return m_current_file_loaded; } -std::vector< Volume* >& VRVolumeApp::get_volume(int volume) +std::vector &VRVolumeApp::get_volume(int volume) { return m_volumes[volume]; } @@ -484,23 +460,23 @@ void VRVolumeApp::intialize_ui() { m_ui_view->init_ui(m_is2d, m_lookingGlass); } - } - -void VRVolumeApp::load_volume(std::vector vals, std::promise* promise) +void VRVolumeApp::load_volume(std::vector vals, std::promise *promise) { if (vals.size() == 1 && helper::ends_with_string(vals[0], ".nrrd")) { #ifdef WITH_TEEM - Volume* volume = LoadNrrdAction(vals[0]).run(); - volume->set_volume_position({ 0.0, 0.0, 0.0 }); - volume->set_volume_scale({ 0.0, 0.0, 0.0 }); + Volume *volume = LoadNrrdAction(vals[0]).run(); + volume->set_volume_position({0.0, 0.0, 0.0}); + volume->set_volume_scale({0.0, 0.0, 0.0}); volume->set_volume_mv(glm::mat4()); - promise->set_value(volume);; + promise->set_value(volume); + ; #endif } - else { + else + { std::cerr << "Load volume " << vals[1] << std::endl; std::cerr << "Position " << vals[5] << " , " << vals[6] << " , " << vals[7] << std::endl; std::cerr << "Resolution " << vals[2] << " , " << vals[3] << " , " << vals[4] << std::endl; @@ -510,10 +486,10 @@ void VRVolumeApp::load_volume(std::vector vals, std::promiseset_volume_position({ stof(vals[5]), stof(vals[6]), stof(vals[7]) }); - volume->set_volume_scale({ 0.0, 0.0, 0.0 }); + volume->set_volume_position({stof(vals[5]), stof(vals[6]), stof(vals[7])}); + volume->set_volume_scale({0.0, 0.0, 0.0}); volume->set_volume_mv(glm::mat4()); if (vals.size() > 9) @@ -521,28 +497,28 @@ void VRVolumeApp::load_volume(std::vector vals, std::promiseset_render_channel(std::stoi(vals[9])); } - promise->set_value(volume);; + promise->set_value(volume); + ; std::cerr << "end load" << std::endl; } } - -void VRVolumeApp::load_nrrd_file(std::string& filename) +void VRVolumeApp::load_nrrd_file(std::string &filename) { std::vector vals; vals.push_back(filename); - std::vector*> v; - std::promise* pm = new std::promise(); + std::vector *> v; + std::promise *pm = new std::promise(); v.push_back(pm); m_promises.push_back(v); - std::vector>* fut = new std::vector>; + std::vector> *fut = new std::vector>; fut->push_back(pm->get_future()); m_futures.push_back(fut); - std::vector ths; - std::vector*> v2 = m_promises.back(); + std::vector ths; + std::vector *> v2 = m_promises.back(); ths.emplace_back(new std::thread(&VRVolumeApp::load_volume, this, vals, v2.back())); m_threads.push_back(ths); m_numVolumes = 1; @@ -551,11 +527,9 @@ void VRVolumeApp::load_nrrd_file(std::string& filename) { m_ui_view->update_ui(m_numVolumes); } - - } -void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) +void VRVolumeApp::render(const MinVR::VRGraphicsState &renderState) { m_trackball.set_app_mode(m_app_mode); if (m_app_mode == SIMULATION) @@ -569,9 +543,9 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) m_ui_view->set_clip_min(sim_state.min_clip); } } - - if (m_is2d) { + if (m_is2d) + { m_headpose = glm::make_mat4(renderState.getViewMatrix()); m_headpose = glm::inverse(m_headpose); } @@ -585,20 +559,22 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) m_depthTextures.push_back(new DepthTexture); } - //setup projection + // setup projection m_projection_mtrx = glm::make_mat4(renderState.getProjectionMatrix()); m_model_view = glm::make_mat4(renderState.getViewMatrix()); - //overwrite MV for 2D viewing + // overwrite MV for 2D viewing if (m_is2d) - m_model_view = m_trackball.getViewmatrix(); + m_model_view = m_trackball.get_view_matrix(); glMatrixMode(GL_PROJECTION); glLoadMatrixf(glm::value_ptr(m_projection_mtrx)); - //setup Modelview for volumes - for (int i = 0; i < m_volumes.size(); i++) { - for (int j = 0; j < m_volumes[i].size(); j++) { + // setup Modelview for volumes + for (int i = 0; i < m_volumes.size(); i++) + { + for (int j = 0; j < m_volumes[i].size(); j++) + { glm::mat4 tmp = m_model_view; tmp = tmp * m_object_pose; tmp = glm::scale(tmp, glm::vec3(m_ui_view->get_scale(), m_ui_view->get_scale(), m_ui_view->get_scale() * m_ui_view->get_z_scale())); @@ -608,12 +584,13 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) } } - //setup Modelview for meshes + // setup Modelview for meshes glm::mat4 volume_mv; if (m_mesh_model) { int i = 0; - if (m_volumes.size() > m_models_volumeID[i]) { + if (m_volumes.size() > m_models_volumeID[i]) + { volume_mv = m_volumes[0][m_models_volumeID[i]]->get_volume_mv(); volume_mv = glm::translate(volume_mv, glm::vec3(-0.5f, -0.5f, -0.5f * m_volumes[0][m_models_volumeID[i]]->get_volume_scale().x / (m_volumes[0][m_models_volumeID[i]]->get_volume_scale().z))); volume_mv = glm::scale(volume_mv, glm::vec3(m_volumes[0][m_models_volumeID[i]]->get_volume_scale().x, m_volumes[0][m_models_volumeID[i]]->get_volume_scale().y, m_volumes[0][m_models_volumeID[i]]->get_volume_scale().x)); @@ -622,26 +599,28 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) m_models_MV[i] = volume_mv; /*Original transformations of the model - DO NOT REMOVE YET*/ - //mesh_model->setPosition(glm::vec3(-0.5f, -0.5f, + // mesh_model->setPosition(glm::vec3(-0.5f, -0.5f, // -0.5f * m_volumes[m_models_volumeID[i]]->get_volume_scale().x / (m_volumes[m_models_volumeID[i]]->get_volume_scale().z))); - //mesh_model->setScale(glm::vec3(m_volumes[m_models_volumeID[i]]->get_volume_scale().x, m_volumes[m_models_volumeID[i]]->get_volume_scale().y, m_volumes[m_models_volumeID[i]]->get_volume_scale().x)); + // mesh_model->setScale(glm::vec3(m_volumes[m_models_volumeID[i]]->get_volume_scale().x, m_volumes[m_models_volumeID[i]]->get_volume_scale().y, m_volumes[m_models_volumeID[i]]->get_volume_scale().x)); } } /* SOriginal transformations of the volumes - DO NOT REMOVE YET */ - //for (int i = 0; i < m_models_displayLists.size(); i++) { + // for (int i = 0; i < m_models_displayLists.size(); i++) { // if (m_volumes.size() > m_models_volumeID[i]) { // m_models_MV[i] = m_volumes[m_models_volumeID[i]]->get_volume_mv(); // m_models_MV[i] = glm::translate(m_models_MV[i], glm::vec3(-0.5f, -0.5f, -0.5f * m_volumes[m_models_volumeID[i]]->get_volume_scale().x / (m_volumes[m_models_volumeID[i]]->get_volume_scale().z))); // m_models_MV[i] = glm::scale(m_models_MV[i], glm::vec3(m_volumes[m_models_volumeID[i]]->get_volume_scale().x, m_volumes[m_models_volumeID[i]]->get_volume_scale().y, m_volumes[m_models_volumeID[i]]->get_volume_scale().x)); // //m_models_MV[i] = glm::scale(m_models_MV[i], glm::vec3(10,10,10)); // } - //} + // } - if (m_clipping || m_ui_view->is_use_custom_clip_plane()) { + if (m_clipping || m_ui_view->is_use_custom_clip_plane()) + { glm::mat4 clipPlane = glm::inverse(m_controller_pose) * glm::inverse(m_model_view); - if (m_use_custom_clip_plane) { + if (m_use_custom_clip_plane) + { clipPlane = glm::eulerAngleYXZ(m_clip_ypr.x, m_clip_ypr.y, m_clip_ypr.z); clipPlane = glm::translate(clipPlane, m_clip_pos); clipPlane = clipPlane * glm::inverse(m_model_view); @@ -656,14 +635,14 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) ren->setClipping(false, nullptr); } - for (auto ren : m_renders) { + for (auto ren : m_renders) + { if (m_ui_view) { ren->setClipMinMax(m_ui_view->get_clip_min(), m_ui_view->get_clip_max()); } } - if (m_mesh_model) { m_simple_texture_shader.start(); @@ -672,7 +651,7 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) m_simple_texture_shader.stop(); } - //render labels + // render labels m_line_shader.start(); m_line_shader.setUniform("p", m_projection_mtrx); m_line_shader.setUniform("mv", volume_mv); @@ -686,19 +665,21 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) m_ui_view->render_3D(viewMatrix); }*/ - m_depthTextures[m_rendercount]->copyDepthbuffer(); - (static_cast (m_renders[1]))->setDepthTexture(m_depthTextures[m_rendercount]); + (static_cast(m_renders[1]))->setDepthTexture(m_depthTextures[m_rendercount]); - if (m_is2d ) { - m_ui_view->draw_tranfer_funciton_legend(); + if (m_is2d) + { + m_ui_view->draw_transfer_function_legend(); } - //drawTime - if (m_is2d && m_animated) { + // drawTime + if (m_is2d && m_animated) + { unsigned int active_volume = floor(m_frame); unsigned int active_volume2 = ceil(m_frame); - if (active_volume < m_volumes[0].size() && active_volume2 < m_volumes[0].size() && m_volumes[0][active_volume]->texture_initialized() && m_volumes[0][active_volume2]->texture_initialized()) { + if (active_volume < m_volumes[0].size() && active_volume2 < m_volumes[0].size() && m_volumes[0][active_volume]->texture_initialized() && m_volumes[0][active_volume2]->texture_initialized()) + { float alpha = m_frame - active_volume; time_t time = m_volumes[0][active_volume]->getTime() * (1 - alpha) + m_volumes[0][active_volume2]->getTime() * alpha; m_ui_view->set_volume_time_info(time); @@ -708,54 +689,34 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState& renderState) render_volume(renderState); render_ui(renderState); - - - glFlush(); m_rendercount++; - - - if (m_movieAction) { + if (m_movieAction) + { #ifndef _MSC_VER glFinish(); #endif std::cerr << "Add Frame" << std::endl; m_movieAction->addFrame(); - /*if (m_frame > m_volumes[m_selectedVolume].size() - 1 - (m_speed * m_animation_speed)) { - std::cerr << "Save Movie" << std::endl; -#ifdef _MSC_VER - m_movieAction->save(m_moviename); -#endif - delete m_movieAction; - m_movieAction = nullptr; - m_show_menu = true; - }*/ } - - } -void VRVolumeApp::render_labels(glm::mat4& volume_mv, const MinVR::VRGraphicsState& renderState) +void VRVolumeApp::render_labels(glm::mat4 &volume_mv, const MinVR::VRGraphicsState &renderState) { - //render labels + // render labels if (m_labels) { m_labels->drawLabels(volume_mv, m_projection_mtrx, m_headpose, m_ui_view->get_z_scale()); - } - - - /*if (m_is2d && !m_description.empty()) - FontHandler::getInstance()->renderMultiLineTextBox2D(m_description, 50, 950, 200, m_descriptionHeight);*/ } -void VRVolumeApp::render_mesh(const MinVR::VRGraphicsState& renderState) +void VRVolumeApp::render_mesh(const MinVR::VRGraphicsState &renderState) { /*Original render Mesh using Fixed pipeline - DO NOT REMOVE YET*/ - //Render meshes + // Render meshes /*for (int i = 0; i < m_models_displayLists.size(); i++) { if (m_volumes.size() > m_models_volumeID[i]) { glMatrixMode(GL_MODELVIEW); @@ -775,38 +736,35 @@ void VRVolumeApp::render_mesh(const MinVR::VRGraphicsState& renderState) } } -void VRVolumeApp::render_volume(const MinVR::VRGraphicsState& renderState) +void VRVolumeApp::render_volume(const MinVR::VRGraphicsState &renderState) { - //render volumes - // renderState->getProjectionMatrix(); - for (auto ren : m_renders) { + // render volumes + // renderState->getProjectionMatrix(); + for (auto ren : m_renders) + { ren->set_multiplier(m_ui_view->get_multiplier()); ren->set_threshold(m_ui_view->get_threshold()); ren->set_numSlices(m_ui_view->get_slices()); ren->useMultichannelColormap(m_use_multi_transfer); } - - for (int tfn = 0; tfn < m_ui_view->get_num_transfer_functions(); tfn++) { for (int vol = 0; vol < m_numVolumes; vol++) { m_animated ? animated_render(tfn, vol) : normal_render_volume(tfn, vol); - } } - - } void VRVolumeApp::normal_render_volume(int tfn, int vol) { if (m_ui_view && m_ui_view->is_transfer_function_enabled(tfn, vol)) { - std::vector > order; - for (int i = 0; i < m_volumes.size(); i++) { + std::vector> order; + for (int i = 0; i < m_volumes.size(); i++) + { glm::vec4 center = m_volumes[vol][i]->get_volume_mv() * glm::vec4(0, 0, 0, 1); float l = glm::length(center); order.push_back(std::make_pair(l, i)); @@ -815,7 +773,8 @@ void VRVolumeApp::normal_render_volume(int tfn, int vol) int renderMethod = m_ui_view->get_render_method(); bool useTranferFunction = m_ui_view->is_use_transfer_function_enabled(); - for (int i = order.size() - 1; i >= 0; i--) { + for (int i = order.size() - 1; i >= 0; i--) + { if (m_volumes[vol][order[i].second]->texture_initialized()) { if (m_ui_view->is_render_volume_enabled()) @@ -824,22 +783,19 @@ void VRVolumeApp::normal_render_volume(int tfn, int vol) GLint colorMap = m_ui_view->get_transfer_function_colormap(tfn); GLint colorMapMult = m_ui_view->get_multitransfer_function_colormap(tfn); m_renders[renderMethod]->render(m_volumes[vol][order[i].second], m_volumes[vol][order[i].second]->get_volume_mv(), m_projection_mtrx, m_volumes[vol][order[i].second]->get_volume_scale().x / m_volumes[vol][order[i].second]->get_volume_scale().z, - useTranferFunction ? (m_use_multi_transfer) ? colorMapMult : colorMap : -1, m_ui_view->get_render_channel()); + useTranferFunction ? (m_use_multi_transfer) ? colorMapMult : colorMap : -1, m_ui_view->get_render_channel()); } - } } } } - void VRVolumeApp::animated_render(int tfn, int vol) { unsigned int active_volume = floor(m_frame); unsigned int active_volume2 = ceil(m_frame); int render_method = m_ui_view->get_render_method(); bool use_tranferFunction = m_ui_view->is_use_transfer_function_enabled(); - //bool useMultitransferFunction = m_ui_view->isUseMultiTransfer(); size_t max_animation_length = 0; float global_min = std::numeric_limits::max(); @@ -875,9 +831,8 @@ void VRVolumeApp::animated_render(int tfn, int vol) } } - m_renders[render_method]->render(m_volumes[vol][active_volume], m_volumes[vol][active_volume]->get_volume_mv(), m_projection_mtrx, m_volumes[vol][active_volume]->get_volume_scale().x / m_volumes[vol][active_volume]->get_volume_scale().z, - lut, m_ui_view->get_render_channel()); + lut, m_ui_view->get_render_channel()); } } } @@ -885,16 +840,14 @@ void VRVolumeApp::animated_render(int tfn, int vol) if (dirty) { - m_ui_view->set_trns_fnct_min_max(global_min, global_max); + m_ui_view->set_transfer_function_min_max(global_min, global_max); } - - } -void VRVolumeApp::render_ui(const MinVR::VRGraphicsState& renderState) +void VRVolumeApp::render_ui(const MinVR::VRGraphicsState &renderState) { - //render menu - + // render menu + if (m_ui_view && m_window_properties) { m_window_properties->window_w = renderState.index().getValue("WindowWidth"); @@ -902,7 +855,6 @@ void VRVolumeApp::render_ui(const MinVR::VRGraphicsState& renderState) m_window_properties->framebuffer_w = renderState.index().getValue("FramebufferWidth"); m_window_properties->framebuffer_h = renderState.index().getValue("FramebufferHeight"); - if (!m_is2d) { glm::mat4 mvMatrix = glm::make_mat4(renderState.getViewMatrix()); @@ -913,10 +865,8 @@ void VRVolumeApp::render_ui(const MinVR::VRGraphicsState& renderState) m_ui_view->render_2D(*m_window_properties); } } - } - void VRVolumeApp::update_frame_state() { glMatrixMode(GL_MODELVIEW); @@ -942,12 +892,8 @@ void VRVolumeApp::update_3D_ui() m_ui_view->update_3D_ui_frame(); } } - } - - - void VRVolumeApp::update_2D_ui() { if (m_show_menu && m_ui_view) @@ -962,10 +908,10 @@ void VRVolumeApp::update_2D_ui() void VRVolumeApp::add_lodaded_textures() { bool allready = true; - for (auto& fut : m_futures) + for (auto &fut : m_futures) { - std::vector >* _ft = fut; - for (auto& f : *_ft) + std::vector> *_ft = fut; + for (auto &f : *_ft) { #ifdef _MSC_VER allready = allready & f._Is_ready(); @@ -973,47 +919,41 @@ void VRVolumeApp::add_lodaded_textures() allready = allready & (f.wait_for(std::chrono::seconds(0)) == std::future_status::ready); #endif } - } if (allready) { for (int i = 0; i < m_futures.size(); i++) { - std::vector >* _ft = m_futures[i]; + std::vector> *_ft = m_futures[i]; int counter = 0; - for (auto& value : *_ft) + for (auto &value : *_ft) { - Volume* vlm = value.get(); + Volume *vlm = value.get(); m_volumes[i].push_back(vlm); m_threads[i][counter]->join(); delete m_threads[i][counter]; delete m_promises[i][counter]; counter++; } - - } - m_threads.clear(); m_promises.clear(); m_futures.clear(); - - } } void VRVolumeApp::clear_data() { - for (int i = 0; i < m_volumes.size(); i++) { - std::vector< Volume* > v = m_volumes[i]; + for (int i = 0; i < m_volumes.size(); i++) + { + std::vector v = m_volumes[i]; for (int j = 0; j < v.size(); j++) { delete v[i]; } - } m_volumes.clear(); m_description.clear(); @@ -1021,7 +961,6 @@ void VRVolumeApp::clear_data() { m_labels->clear(); } - m_models_filenames.clear(); m_models_displayLists.clear(); @@ -1030,7 +969,6 @@ void VRVolumeApp::clear_data() m_models_MV.clear(); } - bool VRVolumeApp::data_is_multi_channel() { bool is_multi_channel = false; @@ -1040,18 +978,17 @@ bool VRVolumeApp::data_is_multi_channel() for (int i = 0; i < m_volumes.size(); i++) { if (m_volumes.size() > 0 && m_volumes[i][0]->get_channels() > 1 && - (renderchannel == 0 || renderchannel == 5 || renderchannel == 6)) + (renderchannel == 0 || renderchannel == 5 || renderchannel == 6)) { is_multi_channel |= true; } } } - return is_multi_channel; } -void VRVolumeApp::get_min_max(const float frame, float& min, float& max) +void VRVolumeApp::get_min_max(const float frame, float &min, float &max) { unsigned int active_volume = floor(frame); unsigned int active_volume2 = ceil(frame); @@ -1085,15 +1022,13 @@ void VRVolumeApp::set_num_volumes(int nVolumes) m_numVolumes = nVolumes; } -void VRVolumeApp::mouse_pos_event(glm::vec2& mPos) +void VRVolumeApp::mouse_pos_event(glm::vec2 &mPos) { get_trackball_camera().mouse_move(mPos.x, mPos.y); if (m_ui_view) { m_ui_view->set_cursor_pos(mPos); } - - } void VRVolumeApp::update_ui_events(float value) @@ -1102,7 +1037,6 @@ void VRVolumeApp::update_ui_events(float value) { m_ui_view->set_analog_value(value); } - } void VRVolumeApp::update_track_ball_event(float value) @@ -1116,7 +1050,6 @@ void VRVolumeApp::button_events_ui_handle(int button, int state) { m_ui_view->set_button_click(button, state); } - } void VRVolumeApp::button_event_trackBall_handle(int button, int state) @@ -1157,7 +1090,7 @@ void VRVolumeApp::enable_render_volume() } } -void VRVolumeApp::update_UI_pose_controller(glm::mat4& newPose) +void VRVolumeApp::update_UI_pose_controller(glm::mat4 &newPose) { if (m_ui_view) { @@ -1165,13 +1098,12 @@ void VRVolumeApp::update_UI_pose_controller(glm::mat4& newPose) } } -void VRVolumeApp::update_head_pose(glm::mat4& newPose) +void VRVolumeApp::update_head_pose(glm::mat4 &newPose) { if (m_is2d) { m_headpose = newPose; } - } void VRVolumeApp::update_fps(float fps) @@ -1192,9 +1124,10 @@ void VRVolumeApp::update_dynamic_slices() } } -void VRVolumeApp::do_grab(glm::mat4& newPose) +void VRVolumeApp::do_grab(glm::mat4 &newPose) { - if (m_grab) { + if (m_grab) + { // Update the paintingToRoom transform based upon the new transform // of the left hand relative to the last frame. m_object_pose = newPose * glm::inverse(m_controller_pose) * m_object_pose; @@ -1202,7 +1135,7 @@ void VRVolumeApp::do_grab(glm::mat4& newPose) m_controller_pose = newPose; } -ArcBallCamera& VRVolumeApp::get_trackball_camera() +ArcBallCamera &VRVolumeApp::get_trackball_camera() { return m_trackball; } @@ -1212,7 +1145,7 @@ void VRVolumeApp::set_animation_speed(float time) m_animation_speed = time; } -Simulation& VRVolumeApp::get_simulation() +Simulation &VRVolumeApp::get_simulation() { return *m_simulation; } @@ -1233,12 +1166,13 @@ std::string VRVolumeApp::get_movie_state_label() { return "Write Movie"; } - - return "STOP RECORD"; - + else + { + return "STOP RECORD"; + } } -MovieState VRVolumeApp::get_movie_state() +MOVIESTATE VRVolumeApp::get_movie_state() { return m_current_movie_state; } diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index 0ab64a0..d61908e 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -22,16 +22,14 @@ #include "UI/UIView.h" #include "loader/VRDataLoader.h" - #include #include #include "render/FontHandler.h" - -VolumeVisualizationApp::VolumeVisualizationApp(int argc, char** argv) : VRApp(argc, argv), m_vrVolumeApp(nullptr), m_num_frames(0) +VolumeVisualizationApp::VolumeVisualizationApp(int argc, char **argv) : VRApp(argc, argv), m_vrVolumeApp(nullptr), m_num_frames(0) { int argc_int = this->getLeftoverArgc(); - char** argv_int = this->getLeftoverArgv(); + char **argv_int = this->getLeftoverArgv(); m_vrVolumeApp = new VRVolumeApp(); std::string current_Path = std::string(argv_int[0]); @@ -40,24 +38,25 @@ VolumeVisualizationApp::VolumeVisualizationApp(int argc, char** argv) : VRApp(ar m_vrVolumeApp->set_directory_path(parent_Path); FontHandler::setParentPath(parent_Path); - if (argc_int >= 2) { - for (int i = 1; i < argc_int; i++) { - + if (argc_int >= 2) + { + for (int i = 1; i < argc_int; i++) + { if (std::string(argv_int[i]) == std::string("use2DUI")) { - //m_is2d = true; + // m_is2d = true; m_vrVolumeApp->set_is_2D(true); } if (std::string(argv_int[i]) == std::string("useHolo")) { - //m_lookingGlass = true; - //m_speed = 0.5; + // m_lookingGlass = true; + // m_speed = 0.5; m_vrVolumeApp->set_looking_glass(true); - } - else if (std::string(argv_int[i]) == std::string("convert")) { - //convert = true; + else if (std::string(argv_int[i]) == std::string("convert")) + { + // convert = true; m_vrVolumeApp->set_convert(true); } else if (helper::ends_with_string(std::string(argv_int[i]), ".txt")) @@ -65,7 +64,8 @@ VolumeVisualizationApp::VolumeVisualizationApp(int argc, char** argv) : VRApp(ar std::string fileName = argv_int[i]; VRDataLoader::load_txt_file(*m_vrVolumeApp, fileName); } - else if (helper::ends_with_string(std::string(argv_int[i]), ".nrrd")) { + else if (helper::ends_with_string(std::string(argv_int[i]), ".nrrd")) + { /* NRRD LOADING @@ -87,7 +87,7 @@ VolumeVisualizationApp::VolumeVisualizationApp(int argc, char** argv) : VRApp(ar threads.push_back(ths);*/ std::string nrrdFileName(argv_int[i]); m_vrVolumeApp->load_nrrd_file(nrrdFileName); - //m_vrVolumeApp->initialize(); + // m_vrVolumeApp->initialize(); } } } @@ -96,7 +96,6 @@ VolumeVisualizationApp::VolumeVisualizationApp(int argc, char** argv) : VRApp(ar m_light_pos[1] = 4.0; m_light_pos[2] = 0.0; m_light_pos[3] = 1.0; - } VolumeVisualizationApp::~VolumeVisualizationApp() @@ -105,8 +104,7 @@ VolumeVisualizationApp::~VolumeVisualizationApp() delete m_vrVolumeApp; } - -void VolumeVisualizationApp::onCursorMove(const VRCursorEvent& event) +void VolumeVisualizationApp::onCursorMove(const VRCursorEvent &event) { if (event.getName() == "Mouse_Move") { @@ -116,54 +114,57 @@ void VolumeVisualizationApp::onCursorMove(const VRCursorEvent& event) glm::vec2 pos2d(event.getPos()[0], event.getPos()[1]); m_vrVolumeApp->mouse_pos_event(pos2d); } - - } } -#define count_Packages +#define count_Packages #ifdef count_Packages int last_received = 0; #endif count_Packages -void VolumeVisualizationApp::onAnalogChange(const VRAnalogEvent& event) { - if (m_vrVolumeApp && m_vrVolumeApp->is_show_menu() && m_vrVolumeApp->is_ui_event()) { - if (event.getName() == "HTC_Controller_Right_TrackPad0_Y" || event.getName() == "HTC_Controller_1_TrackPad0_Y" - || (event.getName() == "Wand_Joystick_Y_Update" && !(event.getValue() > -0.1 && event.getValue() < 0.1))) - //m_menu_handler->setAnalogValue(event.getValue()); +void VolumeVisualizationApp::onAnalogChange(const VRAnalogEvent &event) +{ + if (m_vrVolumeApp && m_vrVolumeApp->is_show_menu() && m_vrVolumeApp->is_ui_event()) + { + if (event.getName() == "HTC_Controller_Right_TrackPad0_Y" || event.getName() == "HTC_Controller_1_TrackPad0_Y" || (event.getName() == "Wand_Joystick_Y_Update" && !(event.getValue() > -0.1 && event.getValue() < 0.1))) + // m_menu_handler->setAnalogValue(event.getValue()); m_vrVolumeApp->update_ui_events(event.getValue()); - if (event.getName() == "MouseWheel_Spin") { + if (event.getName() == "MouseWheel_Spin") + { std::cerr << event.getValue() << std::endl; - //m_menu_handler->setAnalogValue(event.getValue() * 10); + // m_menu_handler->setAnalogValue(event.getValue() * 10); m_vrVolumeApp->update_ui_events(event.getValue() * 10); } } - else { - if (event.getName() == "MouseWheel_Spin") { + else + { + if (event.getName() == "MouseWheel_Spin") + { if (m_vrVolumeApp) { m_vrVolumeApp->update_track_ball_event(event.getValue() * 0.01); } - } - } - if (event.getName() == "PhotonLoopFinished") { + if (event.getName() == "PhotonLoopFinished") + { m_vrVolumeApp->update_3D_ui(); m_vrVolumeApp->update_2D_ui(); - if (last_received + 1 != event.getValue()) { + if (last_received + 1 != event.getValue()) + { std::cerr << "Problem with package , received " << event.getValue() << " expected " << last_received + 1 << std::endl; } last_received = event.getValue(); } } - -void VolumeVisualizationApp::onButtonDown(const VRButtonEvent& event) { - if (m_vrVolumeApp && m_vrVolumeApp->is_ui_event()) { +void VolumeVisualizationApp::onButtonDown(const VRButtonEvent &event) +{ + if (m_vrVolumeApp && m_vrVolumeApp->is_ui_event()) + { if (event.getName() == "MouseBtnLeft_Down") { m_vrVolumeApp->button_events_ui_handle(0, 1); @@ -197,10 +198,10 @@ void VolumeVisualizationApp::onButtonDown(const VRButtonEvent& event) { { m_vrVolumeApp->button_event_trackBall_handle(2, 1); } - } - if (m_vrVolumeApp && m_vrVolumeApp->is_show_menu() && m_vrVolumeApp->is_ui_event()) { + if (m_vrVolumeApp && m_vrVolumeApp->is_show_menu() && m_vrVolumeApp->is_ui_event()) + { if (event.getName() == "HTC_Controller_Right_Axis1Button_Down" || event.getName() == "HTC_Controller_1_Axis1Button_Down" || event.getName() == "B10_Down") { m_vrVolumeApp->button_events_ui_handle(0, 1); @@ -209,52 +210,52 @@ void VolumeVisualizationApp::onButtonDown(const VRButtonEvent& event) { { m_vrVolumeApp->button_events_ui_handle(2, 1); } - //else if (event.getName() == "HTC_Controller_Right_AButton_Down" || event.getName() == "HTC_Controller_1_AButton_Down") + // else if (event.getName() == "HTC_Controller_Right_AButton_Down" || event.getName() == "HTC_Controller_1_AButton_Down") else if (event.getName() == "HTC_Controller_Right_Axis0Button_Down" || event.getName() == "HTC_Controller_1_Axis0Button_Down" || event.getName() == "B08_Down") { m_vrVolumeApp->button_events_ui_handle(1, 1); } } - else { + else + { // This routine is called for all Button_Down events. Check event->getName() // to see exactly which button has been pressed down. - //std::cerr << "onButtonDown " << event.getName() << std::endl; + // std::cerr << "onButtonDown " << event.getName() << std::endl; if (event.getName() == "KbdEsc_Down") { exit(0); } else if (event.getName() == "HTC_Controller_Right_Axis1Button_Down" || event.getName() == "HTC_Controller_1_Axis1Button_Down" || event.getName() == "B10_Down") { - //m_grab = true; - //std::cerr << "Grab ON" << std::endl; + // m_grab = true; + // std::cerr << "Grab ON" << std::endl; if (m_vrVolumeApp) { m_vrVolumeApp->enable_grab(true); } - } - //else if (event.getName() == "HTC_Controller_Right_AButton_Down" || event.getName() == "HTC_Controller_1_AButton_Down") + // else if (event.getName() == "HTC_Controller_Right_AButton_Down" || event.getName() == "HTC_Controller_1_AButton_Down") else if (event.getName() == "HTC_Controller_Right_Axis0Button_Down" || event.getName() == "HTC_Controller_1_Axis0Button_Down" || event.getName() == "Wand_Right_Btn_Down") { - //m_clipping = true; + // m_clipping = true; if (m_vrVolumeApp) { m_vrVolumeApp->enable_clipping(true); } - //std::cerr << "Clipping ON" << std::endl; + // std::cerr << "Clipping ON" << std::endl; } else if (event.getName() == "HTC_Controller_Right_GripButton_Down" || event.getName() == "HTC_Controller_1_GripButton_Down" || event.getName() == "B08_Down") { - //m_show_menu = !m_show_menu; + // m_show_menu = !m_show_menu; if (m_vrVolumeApp) { m_vrVolumeApp->enable_ui_menu(); } - } } - if (!(m_vrVolumeApp && m_vrVolumeApp->is_show_menu() && m_vrVolumeApp->is_ui_event())) { + if (!(m_vrVolumeApp && m_vrVolumeApp->is_show_menu() && m_vrVolumeApp->is_ui_event())) + { if (event.getName() == "KbdW_Down") { m_vrVolumeApp->set_AWSD_keyBoard_event(W); @@ -279,14 +280,13 @@ void VolumeVisualizationApp::onButtonDown(const VRButtonEvent& event) { { m_vrVolumeApp->set_AWSD_keyBoard_event(E); } - - } } - -void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { - if (m_vrVolumeApp && m_vrVolumeApp->is_ui_event()) { +void VolumeVisualizationApp::onButtonUp(const VRButtonEvent &event) +{ + if (m_vrVolumeApp && m_vrVolumeApp->is_ui_event()) + { if (event.getName() == "MouseBtnMiddle_ScrollUp") { m_vrVolumeApp->update_ui_events(10); @@ -311,7 +311,6 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { { m_vrVolumeApp->button_event_trackBall_handle(2, 0); } - } if (event.getName() == "MouseBtnMiddle_ScrollDown") @@ -330,7 +329,6 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { m_vrVolumeApp->button_events_ui_handle(0, 0); m_vrVolumeApp->button_event_trackBall_handle(0, 0); } - } else if (event.getName() == "MouseBtnRight_Up") { @@ -340,9 +338,9 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { m_vrVolumeApp->button_events_ui_handle(1, 0); m_vrVolumeApp->button_event_trackBall_handle(1, 0); } - } - else if (event.getName() == "MouseBtnMiddle_Up") { + else if (event.getName() == "MouseBtnMiddle_Up") + { if (m_vrVolumeApp) { @@ -351,8 +349,8 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { } } - - if (m_vrVolumeApp && m_vrVolumeApp->is_show_menu()) { + if (m_vrVolumeApp && m_vrVolumeApp->is_show_menu()) + { if (event.getName() == "HTC_Controller_Right_Axis1Button_Up" || event.getName() == "HTC_Controller_1_Axis1Button_Up" || event.getName() == "B10_Up") { m_vrVolumeApp->button_events_ui_handle(0, 0); @@ -361,7 +359,7 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { { m_vrVolumeApp->button_events_ui_handle(2, 0); } - //else if (event.getName() == "HTC_Controller_Right_AButton_Down" || event.getName() == "HTC_Controller_1_AButton_Down") + // else if (event.getName() == "HTC_Controller_Right_AButton_Down" || event.getName() == "HTC_Controller_1_AButton_Down") else if (event.getName() == "HTC_Controller_Right_Axis0Button_Up" || event.getName() == "HTC_Controller_1_Axis0Button_Up" || event.getName() == "B08_Up") { m_vrVolumeApp->button_events_ui_handle(1, 0); @@ -369,7 +367,7 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { } // This routine is called for all Button_Up events. Check event->getName() // to see exactly which button has been released. - //std::cerr << "onButtonUp " << event.getName() << std::endl; + // std::cerr << "onButtonUp " << event.getName() << std::endl; if (event.getName() == "HTC_Controller_Right_Axis1Button_Up" || event.getName() == "HTC_Controller_1_Axis1Button_Up" || event.getName() == "B10_Up") { @@ -377,9 +375,8 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { { m_vrVolumeApp->enable_grab(false); } - } - //else if (event.getName() == "HTC_Controller_Right_AButton_Up" || event.getName() == "HTC_Controller_1_AButton_Up") + // else if (event.getName() == "HTC_Controller_Right_AButton_Up" || event.getName() == "HTC_Controller_1_AButton_Up") else if (event.getName() == "HTC_Controller_Right_Axis0Button_Up" || event.getName() == "HTC_Controller_1_Axis0Button_Up" || event.getName() == "Wand_Right_Btn_Up") { @@ -387,16 +384,15 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { { m_vrVolumeApp->enable_clipping(false); } - } - if (event.getName() == "KbdW_Up") { + if (event.getName() == "KbdW_Up") + { if (m_vrVolumeApp) { m_vrVolumeApp->unset_AWSD_keyBoard_event(W); } - } if (event.getName() == "KbdA_Up") { @@ -412,7 +408,8 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { m_vrVolumeApp->unset_AWSD_keyBoard_event(S); } } - if (event.getName() == "KbdD_Up") { + if (event.getName() == "KbdD_Up") + { if (m_vrVolumeApp) { m_vrVolumeApp->unset_AWSD_keyBoard_event(D); @@ -433,20 +430,18 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent& event) { } } - if (event.getName() == "KbdSpace_Up") { - //m_renderVolume = !m_renderVolume; + if (event.getName() == "KbdSpace_Up") + { + // m_renderVolume = !m_renderVolume; if (m_vrVolumeApp) { m_vrVolumeApp->enable_render_volume(); } } - - - } - -void VolumeVisualizationApp::onTrackerMove(const VRTrackerEvent& event) { +void VolumeVisualizationApp::onTrackerMove(const VRTrackerEvent &event) +{ if (event.getName() == "HTC_Controller_Right_Move" || event.getName() == "HTC_Controller_1_Move" || event.getName() == "Wand0_Move") { @@ -456,60 +451,51 @@ void VolumeVisualizationApp::onTrackerMove(const VRTrackerEvent& event) { glm::mat4 new_pose = glm::make_mat4(event.getTransform()); m_vrVolumeApp->update_UI_pose_controller(new_pose); } - } - - // This routine is called for all Tracker_Move events. Check event->getName() - // to see exactly which tracker has moved, and then access the tracker's new - // 4x4 transformation matrix with event->getTransform(). - if (event.getName() == "HTC_Controller_Right_Move" || event.getName() == "HTC_Controller_1_Move" || event.getName() == "Wand0_Move") { + // to see exactly which tracker has moved, and then access the tracker's new + // 4x4 transformation matrix with event->getTransform(). + if (event.getName() == "HTC_Controller_Right_Move" || event.getName() == "HTC_Controller_1_Move" || event.getName() == "Wand0_Move") + { glm::mat4 new_pose = glm::make_mat4(event.getTransform()); if (m_vrVolumeApp) { m_vrVolumeApp->do_grab(new_pose); } - } - else if (event.getName() == "HTC_HMD_1_Move") { + else if (event.getName() == "HTC_HMD_1_Move") + { glm::mat4 headPose = glm::make_mat4(event.getTransform()); if (m_vrVolumeApp) { m_vrVolumeApp->update_head_pose(headPose); } - //m_headpose = glm::inverse(m_headpose); + // m_headpose = glm::inverse(m_headpose); m_light_pos[0] = headPose[3][0]; m_light_pos[1] = headPose[3][1]; m_light_pos[2] = headPose[3][2]; } } - - -void VolumeVisualizationApp::onGenericEvent(const VRDataIndex& index) +void VolumeVisualizationApp::onGenericEvent(const VRDataIndex &index) { - if (index.getName() == "WindowClose") { + if (index.getName() == "WindowClose") + { shutdown(); } - if (index.getName() == "WindowSize") { - /* - some code to update projection matrix - */ - } - - if (index.getName() == "BufferSize") { - const std::vector* v = index.getValue("WindowSize"); - const float* f = &(v->front()); - std::cout << "new buffer size: " << GLint(f[0]) << ", " << GLint(f[1]) << std::endl; + if (index.getName() == "BufferSize") + { + const std::vector *v = index.getValue("WindowSize"); + const float *f = &(v->front()); glViewport(0, 0, GLint(f[0]), GLint(f[1])); } - } -void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& renderState) { +void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState &renderState) +{ // This routine is called once per graphics context at the start of the // rendering process. So, this is the place to initialize textures, // load models, or do other operations that you only want to do once per @@ -520,9 +506,6 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend std::chrono::duration delta_time = std::chrono::duration(nowTime - m_lastTime); float delta_time_to_milliseconds = std::chrono::duration_cast(delta_time).count(); float fps = 1000.0f / delta_time_to_milliseconds; - - std::chrono::duration time_lapse = std::chrono::duration(nowTime - last_Update_Time); - float time_lapse_to_seconds = std::chrono::duration_cast(time_lapse).count(); if (m_vrVolumeApp) { @@ -531,18 +514,17 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend } m_lastTime = nowTime; - - - - if (renderState.isInitialRenderCall()) { + if (renderState.isInitialRenderCall()) + { #ifndef __APPLE__ glewExperimental = GL_TRUE; GLenum err = glewInit(); - if (GLEW_OK != err) { + if (GLEW_OK != err) + { std::cout << "Error initializing GLEW." << std::endl; } -#endif +#endif std::cout << "init vizapp " << std::endl; if (m_vrVolumeApp) { @@ -565,26 +547,8 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend glClearColor(0.0, 0.0, 0.0, 1); std::cout << "init vizapp end" << std::endl; const float duration = 10.5f; - - - } - - - - //glMatrixMode(GL_MODELVIEW); - //glLoadIdentity(); - //glLightfv(GL_LIGHT0, GL_POSITION, m_light_pos); - - - - //_timeline.step(1.0 / 60.0); - //std::cout << target << std::endl; - //std::cout << _control_b.value().x<<" , "<< _control_b.value().y << " , " << _control_b.value().z << std::endl; - - - if (m_vrVolumeApp) { if (m_vrVolumeApp->pending_models_to_load()) @@ -596,25 +560,20 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState& rend m_vrVolumeApp->update_3D_ui(); m_vrVolumeApp->update_trackBall_state(); - - //if (time_lapse_to_seconds >= fps_Limit) if (true) { - //std::cout << "animate" << std::endl; m_vrVolumeApp->update_animation(delta_time.count()); last_Update_Time = nowTime; - } - - m_vrVolumeApp->set_render_count(0); + m_vrVolumeApp->set_render_count(0); } // std::cout << "init vizapp loop" << std::endl; } - -void VolumeVisualizationApp::onRenderGraphicsScene(const VRGraphicsState& renderState) { +void VolumeVisualizationApp::onRenderGraphicsScene(const VRGraphicsState &renderState) +{ // This routine is called once per eye. This is the place to actually // draw the scene... @@ -622,5 +581,4 @@ void VolumeVisualizationApp::onRenderGraphicsScene(const VRGraphicsState& render { m_vrVolumeApp->render(renderState); } - } diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index d76f11e..b85664b 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -420,6 +420,7 @@ endif() find_package(OpenCV CONFIG REQUIRED) +set_target_properties(${OpenCV_LIBS} PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE) if(OpenCV_FOUND) message(STATUS "OpenCV found ${_OpenCV_LIB_PATH}") message(STATUS "OpenCV found ${OpenCV_INSTALL_PATH}") From 0f54d4e8935c736ebdddce13fe08d6da0825f9f4 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Tue, 26 Apr 2022 13:36:37 -0400 Subject: [PATCH 16/23] address comments from PR review. Delete comments, unuse code, formatting files --- Resources/README.md | 2 +- include/interaction/ArcBallCamera.h | 4 +- include/interaction/PointOfInterests.h | 5 ++ include/render/VolumeRenderer.h | 77 +++++++++++++------------- src/UI/UIView.cpp | 16 +++--- src/vrapp/VolumeVisualizationApp.cpp | 14 ++--- 6 files changed, 57 insertions(+), 61 deletions(-) diff --git a/Resources/README.md b/Resources/README.md index 5f3e820..861c485 100644 --- a/Resources/README.md +++ b/Resources/README.md @@ -1,3 +1,3 @@ ### Resource folder -All the [Models - obj files ](https://en.wikipedia.org/wiki/Wavefront_.obj_file) used by applications must go on this folder. Make sure the .objs have both vertex and texture coordinates (normals are optional). \ No newline at end of file +All the [Models - obj files ](https://en.wikipedia.org/wiki/Wavefront_.obj_file) used by applications must go on this folder. Make sure the `.objs` have both vertex and texture coordinates (normals are optional). \ No newline at end of file diff --git a/include/interaction/ArcBallCamera.h b/include/interaction/ArcBallCamera.h index 7f2d4c7..de151a6 100644 --- a/include/interaction/ArcBallCamera.h +++ b/include/interaction/ArcBallCamera.h @@ -1,5 +1,5 @@ // ---------------------------------- -// Copyright � 2017, Brown University, Providence, RI. +// Copyright © 2017, Brown University, Providence, RI. // // All Rights Reserved // @@ -12,7 +12,7 @@ // See license.txt for further information. // // BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED �AS IS�, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// PROVIDED "AS IS", INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY // SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING // FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR diff --git a/include/interaction/PointOfInterests.h b/include/interaction/PointOfInterests.h index b76abd4..8eaab1d 100644 --- a/include/interaction/PointOfInterests.h +++ b/include/interaction/PointOfInterests.h @@ -25,6 +25,11 @@ public : up = other.up; }; + //The orbit camera is constrained to move around a centered point ("target"). + //The camera position is calculated as a linear combination between the center object + //and the radius of the virtual sphere that surrounds it. + //This is not equals to the view matrix eye position determined by the homogeneous coordinate (4th column) + glm::vec3 get_camera_position() { eye = (glm::normalize(eye)); diff --git a/include/render/VolumeRenderer.h b/include/render/VolumeRenderer.h index 9db1d96..d128974 100644 --- a/include/render/VolumeRenderer.h +++ b/include/render/VolumeRenderer.h @@ -1,25 +1,25 @@ // ---------------------------------- // Copyright © 2015, Brown University, Providence, RI. -// +// // All Rights Reserved -// -// Use of the software is provided under the terms of the GNU General Public License version 3 -// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided -// that this copyright notice appear in all copies and that the name of Brown University not be used in -// advertising or publicity pertaining to the use or distribution of the software without specific written +// +// Use of the software is provided under the terms of the GNU General Public License version 3 +// as published by the Free Software Foundation at http://www.gnu.org/licenses/gpl-3.0.html, provided +// that this copyright notice appear in all copies and that the name of Brown University not be used in +// advertising or publicity pertaining to the use or distribution of the software without specific written // prior permission from Brown University. -// +// // See license.txt for further information. -// -// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED “AS ISâ€, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY -// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING -// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION -// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS +// PROVIDED “AS ISâ€, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY +// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING +// FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, OR ANY OTHER LEGAL THEORY, ARISING OUT OF OR IN CONNECTION +// WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // ---------------------------------- -// +// ///\file VolumeRenderer.h ///\author Benjamin Knorlein ///\date 5/24/2019 @@ -33,36 +33,33 @@ #include "Volume.h" class VolumeRenderer - { - public: - VolumeRenderer(){}; - virtual ~VolumeRenderer(){}; +{ +public: + VolumeRenderer(){}; + virtual ~VolumeRenderer(){}; - virtual void initGL() = 0; - virtual void render(Volume* volume, const glm::mat4 &MV, glm::mat4 &P, float z_scale, GLint colorma, int renderChannel) = 0; + virtual void initGL() = 0; + virtual void render(Volume *volume, const glm::mat4 &MV, glm::mat4 &P, float z_scale, GLint colorma, int renderChannel) = 0; - virtual void set_threshold(float threshold) = 0; - virtual void set_multiplier(float multiplier) = 0; - virtual void set_numSlices(int slices) = 0; - - virtual void set_blending(bool useBlending, float alpha, Volume* volume) = 0; - virtual void useMultichannelColormap(bool useMulti) = 0; - - virtual void setClipMinMax(glm::vec3 min_clip, glm::vec3 max_clip) = 0; + virtual void set_threshold(float threshold) = 0; + virtual void set_multiplier(float multiplier) = 0; + virtual void set_numSlices(int slices) = 0; - void setClipping(bool isClipping, glm::mat4 * clipPlane) - { - m_clipping = isClipping; - if (m_clipping) - m_clipPlane = *clipPlane; - }; + virtual void set_blending(bool useBlending, float alpha, Volume *volume) = 0; + virtual void useMultichannelColormap(bool useMulti) = 0; - protected: - bool m_clipping; - glm::mat4 m_clipPlane; + virtual void setClipMinMax(glm::vec3 min_clip, glm::vec3 max_clip) = 0; - + void setClipping(bool isClipping, glm::mat4 *clipPlane) + { + m_clipping = isClipping; + if (m_clipping) + m_clipPlane = *clipPlane; }; +protected: + bool m_clipping; + glm::mat4 m_clipPlane; +}; #endif // VOLUMERENDER_H diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index 2fba745..9af1ab0 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -389,7 +389,9 @@ void UIView::draw_ui_callback() if (m_animated) { /* - frame by frame animation + TODO: + + Fix frame by frame animation unsigned int active_volume = floor(m_frame); unsigned int active_volume2 = ceil(m_frame); @@ -401,13 +403,9 @@ void UIView::draw_ui_callback() m_volumes[m_selectedVolume][active_volume2]->getTransferfunction(i), alpha, i); }*/ } - else - { - /* tfn_widget_multi[m_selectedVolume].setHistogram(m_volumes[m_selectedVolume][0]->getTransferfunction(i), i);*/ - } + } m_controller_app.set_multi_transfer(true); - // tfn_widget_multi[m_selectedTrnFnc].draw_histogram(); tfn_widget_multi[m_trnfnc_table_selection].draw_ui(); } else @@ -415,7 +413,9 @@ void UIView::draw_ui_callback() if (m_animated) { /* - frame by frame animation + TODO: + + Fix frame by frame animation unsigned int active_volume = floor(m_frame); unsigned int active_volume2 = ceil(m_frame); @@ -430,7 +430,7 @@ void UIView::draw_ui_callback() m_histogram.draw_histogram(); tfn_widget[m_trnfnc_table_selection].draw_ui(); - // tfn_widget[m_trnfnc_table_selection].setMinMax() + } } } diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index d61908e..56c72d7 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -210,7 +210,6 @@ void VolumeVisualizationApp::onButtonDown(const VRButtonEvent &event) { m_vrVolumeApp->button_events_ui_handle(2, 1); } - // else if (event.getName() == "HTC_Controller_Right_AButton_Down" || event.getName() == "HTC_Controller_1_AButton_Down") else if (event.getName() == "HTC_Controller_Right_Axis0Button_Down" || event.getName() == "HTC_Controller_1_Axis0Button_Down" || event.getName() == "B08_Down") { m_vrVolumeApp->button_events_ui_handle(1, 1); @@ -220,34 +219,31 @@ void VolumeVisualizationApp::onButtonDown(const VRButtonEvent &event) { // This routine is called for all Button_Down events. Check event->getName() // to see exactly which button has been pressed down. - // std::cerr << "onButtonDown " << event.getName() << std::endl; + if (event.getName() == "KbdEsc_Down") { exit(0); } else if (event.getName() == "HTC_Controller_Right_Axis1Button_Down" || event.getName() == "HTC_Controller_1_Axis1Button_Down" || event.getName() == "B10_Down") { - // m_grab = true; - // std::cerr << "Grab ON" << std::endl; if (m_vrVolumeApp) { m_vrVolumeApp->enable_grab(true); } } - // else if (event.getName() == "HTC_Controller_Right_AButton_Down" || event.getName() == "HTC_Controller_1_AButton_Down") else if (event.getName() == "HTC_Controller_Right_Axis0Button_Down" || event.getName() == "HTC_Controller_1_Axis0Button_Down" || event.getName() == "Wand_Right_Btn_Down") { - // m_clipping = true; + if (m_vrVolumeApp) { m_vrVolumeApp->enable_clipping(true); } - // std::cerr << "Clipping ON" << std::endl; + } else if (event.getName() == "HTC_Controller_Right_GripButton_Down" || event.getName() == "HTC_Controller_1_GripButton_Down" || event.getName() == "B08_Down") { - // m_show_menu = !m_show_menu; + if (m_vrVolumeApp) { m_vrVolumeApp->enable_ui_menu(); @@ -367,7 +363,6 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent &event) } // This routine is called for all Button_Up events. Check event->getName() // to see exactly which button has been released. - // std::cerr << "onButtonUp " << event.getName() << std::endl; if (event.getName() == "HTC_Controller_Right_Axis1Button_Up" || event.getName() == "HTC_Controller_1_Axis1Button_Up" || event.getName() == "B10_Up") { @@ -376,7 +371,6 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent &event) m_vrVolumeApp->enable_grab(false); } } - // else if (event.getName() == "HTC_Controller_Right_AButton_Up" || event.getName() == "HTC_Controller_1_AButton_Up") else if (event.getName() == "HTC_Controller_Right_Axis0Button_Up" || event.getName() == "HTC_Controller_1_Axis0Button_Up" || event.getName() == "Wand_Right_Btn_Up") { From 695d9c32fe401f9c500e7617b9d53ab2e0891ad4 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Thu, 28 Apr 2022 14:39:29 -0400 Subject: [PATCH 17/23] remove unsed code. rename variables. add comments. --- include/UI/UIView.h | 6 +-- .../interaction/{Labels.h => LabelManager.h} | 16 +++---- include/interaction/PointOfInterests.h | 6 +-- include/interaction/Simulation.h | 17 +++++-- include/render/VolumeRaycastRenderer.h | 4 +- include/render/VolumeRenderer.h | 11 ++--- include/render/VolumeSliceRenderer.h | 4 +- include/vrapp/VRVolumeApp.h | 12 +++-- libs/Model/Model.cpp | 2 +- libs/UIHelpers/transfer_function_widget.cpp | 6 +-- shaders/lines_shader.vert | 8 ++-- shaders/shader.frag | 15 +++--- shaders/shader.vert | 16 +++---- src/UI/UIView.cpp | 18 ++++---- .../{Labels.cpp => LabelManager.cpp} | 36 ++++++++------- src/interaction/Simulation.cpp | 34 +++++++------- src/vrapp/VRVolumeApp.cpp | 46 ++++++++----------- src/vrapp/VolumeVisualizationApp.cpp | 21 +++------ superbuild/CMakeLists.txt | 4 +- 19 files changed, 138 insertions(+), 144 deletions(-) rename include/interaction/{Labels.h => LabelManager.h} (84%) rename src/interaction/{Labels.cpp => LabelManager.cpp} (78%) diff --git a/include/UI/UIView.h b/include/UI/UIView.h index d1befa6..1bf2c37 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -160,13 +160,13 @@ class UIView void open_save_modal_dialog(std::string &id, bool &window_state, std::function save_function, std::string &extension); - void add_trans_function(); + void add_transfer_function(); - void save_trans_functions(std::ofstream &saveFile); + void save_transfer_functions(std::ofstream &saveFile); void save_user_session(std::ofstream &saveFile); - void load_trans_functions(std::ifstream &loadPath); + void load_transfer_functions(std::ifstream &loadPath); void load_user_session(std::string filePath); diff --git a/include/interaction/Labels.h b/include/interaction/LabelManager.h similarity index 84% rename from include/interaction/Labels.h rename to include/interaction/LabelManager.h index 75ae2ad..52a5cf5 100644 --- a/include/interaction/Labels.h +++ b/include/interaction/LabelManager.h @@ -36,7 +36,7 @@ class Texture; class VRVolumeApp; class ShaderProgram; -struct LabelBillboard +struct BillboardLabel { unsigned int line_vba; Texture *label_texture; @@ -44,15 +44,15 @@ struct LabelBillboard glm::vec3 position; }; -class Labels +class LabelManager { public: - Labels(ShaderProgram &lines_shader, ShaderProgram &plane_shader); - ~Labels(); + LabelManager(ShaderProgram &lines_shader, ShaderProgram &plane_shader); + ~LabelManager(); - void add(std::string texture, float x, float y, float z, float textPosZ, float size, int volume); - void drawLabels(glm::mat4 MV, glm::mat4 projection_matrix, glm::mat4 &headpose, float z_scale); - void drawLines(); + void add_label(std::string texture, float x, float y, float z, float textPosZ, float size, int volume); + void draw_labels(glm::mat4 MV, glm::mat4 projection_matrix, glm::mat4 &headpose, float z_scale); + void draw_lines(); void clear(); void set_parent_directory(std::string &directory); @@ -60,7 +60,7 @@ class Labels private: unsigned int create_line_vba(glm::vec3 &start, glm::vec3 &end); - std::vector m_billboard_labels; + std::vector m_billboard_labels; std::vector m_text; std::vector m_position; diff --git a/include/interaction/PointOfInterests.h b/include/interaction/PointOfInterests.h index 8eaab1d..21c1ae6 100644 --- a/include/interaction/PointOfInterests.h +++ b/include/interaction/PointOfInterests.h @@ -1,5 +1,5 @@ -#ifndef PointOfInterest_H -#define PointOfInterest_H +#ifndef POINTOFINTEREST_H +#define POINTOFINTEREST_H #include #include @@ -28,7 +28,7 @@ public : //The orbit camera is constrained to move around a centered point ("target"). //The camera position is calculated as a linear combination between the center object //and the radius of the virtual sphere that surrounds it. - //This is not equals to the view matrix eye position determined by the homogeneous coordinate (4th column) + //This is not equal to the view matrix eye position determined by the homogeneous coordinate (4th column) glm::vec3 get_camera_position() { diff --git a/include/interaction/Simulation.h b/include/interaction/Simulation.h index f519033..62fe9f6 100644 --- a/include/interaction/Simulation.h +++ b/include/interaction/Simulation.h @@ -14,6 +14,15 @@ enum ANIMATION_STATE PAUSE }; +/* + SimulationState represents a frame in the simulation/animation + where the camera is set on a postion P, pointing on direction of a target T, + and min/max are set on a X-Y value. + the animation change SimulationStates by interpolating between the mentioned values. +*/ + +#define SIMULATION_TIME_STEP 30.0 + struct SimulationState { SimulationState(){}; @@ -40,15 +49,15 @@ class Simulation void add_simulation_state(SimulationState &simulationState); - void create_animations(); + void create_simulation_time_frames(); void update_simulation(); void set_animation_state(); ANIMATION_STATE get_animation_state(); std::string get_camera_animation_state(); - float get_camera_animation_duration(); - void set_camera_animation_duration(float duration); + float get_simulation_duration(); + void set_simulation_duration(float duration); const std::list &get_simulation_states(); @@ -64,7 +73,7 @@ class Simulation void update_time_step(); ch::Timeline m_timeline; - float m_animation_duration; + float m_simulation_duration; std::list m_simulation_states; diff --git a/include/render/VolumeRaycastRenderer.h b/include/render/VolumeRaycastRenderer.h index 1024d70..1d5d65a 100644 --- a/include/render/VolumeRaycastRenderer.h +++ b/include/render/VolumeRaycastRenderer.h @@ -67,14 +67,14 @@ class VolumeRaycastRenderer : public VolumeRenderer virtual void set_blending(bool useBlending, float alpha, Volume* volume) override; virtual void useMultichannelColormap(bool useMulti); - virtual void set_numSlices(int slices) override; + virtual void set_num_slices(int slices) override; void setDepthTexture(DepthTexture* depth_texture) { shader.setDepthTexture(depth_texture); } - virtual void setClipMinMax(glm::vec3 min_clip, glm::vec3 max_clip); + virtual void set_clip_min_max(glm::vec3 min_clip, glm::vec3 max_clip); private: void setChannel(Volume* volume); diff --git a/include/render/VolumeRenderer.h b/include/render/VolumeRenderer.h index d128974..311af21 100644 --- a/include/render/VolumeRenderer.h +++ b/include/render/VolumeRenderer.h @@ -24,7 +24,6 @@ ///\author Benjamin Knorlein ///\date 5/24/2019 -#pragma once #ifndef VOLUMERENDER_H #define VOLUMERENDER_H @@ -43,23 +42,23 @@ class VolumeRenderer virtual void set_threshold(float threshold) = 0; virtual void set_multiplier(float multiplier) = 0; - virtual void set_numSlices(int slices) = 0; + virtual void set_num_slices(int slices) = 0; virtual void set_blending(bool useBlending, float alpha, Volume *volume) = 0; virtual void useMultichannelColormap(bool useMulti) = 0; - virtual void setClipMinMax(glm::vec3 min_clip, glm::vec3 max_clip) = 0; + virtual void set_clip_min_max(glm::vec3 min_clip, glm::vec3 max_clip) = 0; - void setClipping(bool isClipping, glm::mat4 *clipPlane) + void set_clipping_plane(bool isClipping, glm::mat4 *clipPlane) { m_clipping = isClipping; if (m_clipping) - m_clipPlane = *clipPlane; + m_clip_plane = *clipPlane; }; protected: bool m_clipping; - glm::mat4 m_clipPlane; + glm::mat4 m_clip_plane; }; #endif // VOLUMERENDER_H diff --git a/include/render/VolumeSliceRenderer.h b/include/render/VolumeSliceRenderer.h index 8c9991f..c8e79f2 100644 --- a/include/render/VolumeSliceRenderer.h +++ b/include/render/VolumeSliceRenderer.h @@ -66,7 +66,7 @@ class VolumeSliceRenderer : public VolumeRenderer virtual void set_threshold(float threshold) override; virtual void set_multiplier(float multiplier) override; - virtual void set_numSlices(int slices) override; + virtual void set_num_slices(int slices) override; virtual void useMultichannelColormap(bool useMulti); virtual void set_blending(bool useBlending, float alpha, Volume* volume) override @@ -74,7 +74,7 @@ class VolumeSliceRenderer : public VolumeRenderer //unsupported for now } - virtual void setClipMinMax(glm::vec3 min_clip, glm::vec3 max_clip); + virtual void set_clip_min_max(glm::vec3 min_clip, glm::vec3 max_clip); private: //function to get the max (abs) dimension of the given vertex v diff --git a/include/vrapp/VRVolumeApp.h b/include/vrapp/VRVolumeApp.h index 06c9fc4..0c7b3f2 100644 --- a/include/vrapp/VRVolumeApp.h +++ b/include/vrapp/VRVolumeApp.h @@ -22,7 +22,7 @@ class Window_Properties; class Model; class Texture; class Simulation; -class Labels; +class LabelManager; enum MOVIESTATE { @@ -172,7 +172,11 @@ class VRVolumeApp ArcBallCamera& get_trackball_camera(); - void set_animation_speed(float time); + /* + increase/decrease the step size of the volume animation by a `scale` factor. + It is a step unit, not related to any time unit. + */ + void set_volume_animation_scale_factor(float scale); Simulation& get_simulation(); @@ -210,7 +214,7 @@ class VRVolumeApp std::vector < std::vector< Volume* >> m_volumes; std::vector m_description; - Labels* m_labels; + LabelManager* m_labels; std::vector m_models_filenames; std::vector m_models_displayLists; std::vector m_models_position; @@ -239,7 +243,7 @@ class VRVolumeApp bool m_animated; float m_threshold; int m_descriptionHeight; - float m_animation_speed; + float m_volume_animation_scale_factor; float m_frame; float m_speed; diff --git a/libs/Model/Model.cpp b/libs/Model/Model.cpp index ed9e3df..e3a0a79 100644 --- a/libs/Model/Model.cpp +++ b/libs/Model/Model.cpp @@ -36,7 +36,7 @@ void Model::setTexture(Texture *val) void Model::render(ShaderProgram &shaderProgram) { - shaderProgram.setUniform("mv", m_model_view_mtrx); + shaderProgram.setUniform("model_view_matrix", m_model_view_mtrx); assert(m_Obj_Model && "NO MODEL TO RENDER"); // bind texture diff --git a/libs/UIHelpers/transfer_function_widget.cpp b/libs/UIHelpers/transfer_function_widget.cpp index 5dce27b..809bf58 100644 --- a/libs/UIHelpers/transfer_function_widget.cpp +++ b/libs/UIHelpers/transfer_function_widget.cpp @@ -441,10 +441,10 @@ void TransferFunctionWidget::draw_legend(float legend_pos_x, float legend_pos_y, ImGui::Begin("##legend", &show_legend, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); ImGuiIO &io = ImGui::GetIO(); ImTextureID my_tex_id = io.Fonts->TexID; - float my_tex_w = (float)io.Fonts->TexWidth; - float my_tex_h = (float)io.Fonts->TexHeight; + float texture_width = (float)io.Fonts->TexWidth; + float texture_height = (float)io.Fonts->TexHeight; std::string max_str = std::to_string(m_min_max_val[1]); - float offset = 0.008 * (my_tex_w * max_str.size()); + float offset = 0.008 * (texture_width * max_str.size()); ImGui::Image(reinterpret_cast(colormap_img), ImVec2(legend_width, 16)); ImGui::Text("%.0f", m_min_max_val[0]); ImGui::SameLine((legend_width / 2)); diff --git a/shaders/lines_shader.vert b/shaders/lines_shader.vert index d2b0d0c..16d434f 100644 --- a/shaders/lines_shader.vert +++ b/shaders/lines_shader.vert @@ -1,10 +1,10 @@ #version 410 -layout (location = 0 )in vec3 vp; -uniform mat4 mv; -uniform mat4 p; +layout (location = 0 )in vec3 vertex_position; +uniform mat4 model_view_matrix; +uniform mat4 projection_matrixp; void main () { - gl_Position = p * mv * vec4(vp,1); + gl_Position = projection_matrix * model_view_matrix * vec4(vertex_position,1); } \ No newline at end of file diff --git a/shaders/shader.frag b/shaders/shader.frag index 76423ff..a1aa6b9 100644 --- a/shaders/shader.frag +++ b/shaders/shader.frag @@ -1,17 +1,14 @@ #version 330 -const vec4 lightPos = vec4(0.0, 2.0, 2.0, 1.0); -const vec4 color = vec4(0.5, 0.5, 0.5, 1.0); +in vec4 vertex_pos; +in vec2 text_coord; -in vec4 pos; -in vec2 TexCoord; - -out vec4 fragColor; -uniform sampler2D myTextureSampler; +out vec4 frag_color; +uniform sampler2D texture_sampler; void main() { - fragColor = vec4(texture( myTextureSampler, TexCoord )); - if(fragColor.a < 0.1) + frag_color = vec4(texture( texture_sampler, text_coord )); + if(frag_color.a < 0.1) { discard; } diff --git a/shaders/shader.vert b/shaders/shader.vert index 7aa0336..e8408e6 100644 --- a/shaders/shader.vert +++ b/shaders/shader.vert @@ -4,19 +4,17 @@ layout(location = 0) in vec3 position; layout(location = 1) in vec3 normal; layout(location = 2) in vec2 uv; -uniform mat4 p; +uniform mat4 projection_matrix; uniform mat4 v; uniform mat4 m; -uniform mat4 mv; +uniform mat4 model_view_matrix; -out vec4 pos; -//out vec4 norm; -out vec2 TexCoord; +out vec4 vertex_pos; +out vec2 text_coord; void main() { - pos = mv * vec4(position, 1.0); - //norm = normalize(mv * vec4(normal, 0.0)); - TexCoord = uv; + vertex_pos = model_view_matrix * vec4(position, 1.0); + text_coord = uv; - gl_Position = p * pos; + gl_Position = p * vertex_pos; } \ No newline at end of file diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index 9af1ab0..5b3467a 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -297,7 +297,7 @@ void UIView::draw_ui_callback() if (m_use_transferfunction) { std::string extension = ".fnc"; - auto save_funtion = std::bind(&UIView::save_trans_functions, this, std::placeholders::_1); + auto save_funtion = std::bind(&UIView::save_transfer_functions, this, std::placeholders::_1); open_save_modal_dialog(save_Trnf_window_id, m_save_trnfct_open, save_funtion, extension); } else @@ -461,7 +461,7 @@ void UIView::draw_ui_callback() { m_animation_speed = 1.0f; } - m_controller_app.set_animation_speed(m_animation_speed); + m_controller_app.set_volume_animation_scale_factor(m_animation_speed); } #if (!defined(__APPLE__)) @@ -763,7 +763,7 @@ void UIView::draw_ui_callback() ImGui::InputText("##textanimationtime", &m_animation_duration_to_string, ImGuiInputTextFlags_CharsDecimal); if (ImGui::Button("Ok")) { - m_controller_app.get_simulation().set_camera_animation_duration(std::stof(m_animation_duration_to_string)); + m_controller_app.get_simulation().set_simulation_duration(std::stof(m_animation_duration_to_string)); m_animation_duration_to_string.clear(); m_camera_animation_duration_open = false; ImGui::CloseCurrentPopup(); @@ -857,7 +857,7 @@ void UIView::draw_ui_callback() m_tfns.clear(); std::string filePath = fileDialogLoadTrnsFnc.selected_path; std::ifstream fileToLoad(filePath); - load_trans_functions(fileToLoad); + load_transfer_functions(fileToLoad); m_trnfnc_table_selection = 0; m_current_load_modal = LOAD_NONE; } @@ -1306,11 +1306,11 @@ void UIView::open_save_modal_dialog(std::string &id, bool &window_state, } } -void UIView::add_trans_function() +void UIView::add_transfer_function() { } -void UIView::save_trans_functions(std::ofstream &saveFile) +void UIView::save_transfer_functions(std::ofstream &saveFile) { std::string pointsLine; if (saveFile.is_open()) @@ -1389,14 +1389,14 @@ void UIView::save_user_session(std::ofstream &savefile) { savefile << "Trnfncs" << "\n"; - save_trans_functions(savefile); + save_transfer_functions(savefile); } savefile.close(); } } -void UIView::load_trans_functions(std::ifstream &loadFile) +void UIView::load_transfer_functions(std::ifstream &loadFile) { std::string line; @@ -1564,7 +1564,7 @@ void UIView::load_user_session(std::string filePath) } else if (tag == "Trnfncs") { - load_trans_functions(loadFile); + load_transfer_functions(loadFile); } else if (tag == "POI") { diff --git a/src/interaction/Labels.cpp b/src/interaction/LabelManager.cpp similarity index 78% rename from src/interaction/Labels.cpp rename to src/interaction/LabelManager.cpp index 0f6eefc..2537f5f 100644 --- a/src/interaction/Labels.cpp +++ b/src/interaction/LabelManager.cpp @@ -23,6 +23,8 @@ ///\file Labels.cpp ///\author Benjamin Knorlein ///\date 6/25/2019 +///\author Camilo Diaz +///\date 4/28/2022 #pragma once @@ -46,7 +48,7 @@ #include #endif -#include "../../include/interaction/Labels.h" +#include "../../include/interaction/LabelManager.h" #include #include #include "../../include/render/FontHandler.h" @@ -54,11 +56,11 @@ #include #include -Labels::Labels(ShaderProgram &lines_shader, ShaderProgram &plane_shader) : m_init_plane_model(false), m_lines_shader_program(lines_shader), m_plane_shader_program(plane_shader), m_plane_model(nullptr) +LabelManager::LabelManager(ShaderProgram &lines_shader, ShaderProgram &plane_shader) : m_init_plane_model(false), m_lines_shader_program(lines_shader), m_plane_shader_program(plane_shader), m_plane_model(nullptr) { } -Labels::~Labels() +LabelManager::~LabelManager() { clear(); std::map::iterator it; @@ -69,7 +71,7 @@ Labels::~Labels() delete m_plane_model; } -void Labels::clear() +void LabelManager::clear() { m_text.clear(); m_position.clear(); @@ -78,12 +80,12 @@ void Labels::clear() m_volume.clear(); } -void Labels::set_parent_directory(std::string &directory) +void LabelManager::set_parent_directory(std::string &directory) { m_parent_directory = directory; } -unsigned int Labels::create_line_vba(glm::vec3 &start, glm::vec3 &end) +unsigned int LabelManager::create_line_vba(glm::vec3 &start, glm::vec3 &end) { unsigned int vba; unsigned int vbo; @@ -110,7 +112,7 @@ unsigned int Labels::create_line_vba(glm::vec3 &start, glm::vec3 &end) return vba; } -void Labels::add(std::string texture_path, float x, float y, float z, float textPosZ, float size, int volume) +void LabelManager::add_label(std::string texture_path, float x, float y, float z, float textPosZ, float size, int volume) { if (!m_init_plane_model) { @@ -126,7 +128,7 @@ void Labels::add(std::string texture_path, float x, float y, float z, float text m_texture_cache[texture_path] = texture; } - LabelBillboard billboard; + BillboardLabel billboard; glm::vec3 line_start(x, y, z); glm::vec3 line_end(x, y, textPosZ + 200); unsigned int line_vba = create_line_vba(line_start, line_end); @@ -142,7 +144,7 @@ void Labels::add(std::string texture_path, float x, float y, float z, float text m_volume.push_back(volume); } -void Labels::drawLabels(glm::mat4 volume_mv, glm::mat4 projection_matrix, glm::mat4 &headpose, float z_scale) +void LabelManager::draw_labels(glm::mat4 volume_mv, glm::mat4 projection_matrix, glm::mat4 &headpose, float z_scale) { for (int i = 0; i < m_billboard_labels.size(); i++) { @@ -164,23 +166,23 @@ void Labels::drawLabels(glm::mat4 volume_mv, glm::mat4 projection_matrix, glm::m dir.z = 0; dir = normalize(dir); float angle = 180.0f / M_PI * atan2(dir.x, dir.y); - glm::mat4 label_mv; + glm::mat4 label_model_view_matrix; - label_mv = glm::translate(volume_mv, m_billboard_labels[i].position); - label_mv = glm::scale(label_mv, glm::vec3(50.0f, 50.0f, 100.0f)); - label_mv = glm::rotate(label_mv, glm::radians(180.0f - angle), glm::vec3(0.0f, 0.0f, 1.0f)); - label_mv = glm::rotate(label_mv, glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f)); - // label_mv = glm::scale(label_mv, glm::vec3(1.0f, 1.0f / z_scale, 1.0f)); + label_model_view_matrix = glm::translate(volume_mv, m_billboard_labels[i].position); + label_model_view_matrix = glm::scale(label_model_view_matrix, glm::vec3(50.0f, 50.0f, 100.0f)); + label_model_view_matrix = glm::rotate(label_model_view_matrix, glm::radians(180.0f - angle), glm::vec3(0.0f, 0.0f, 1.0f)); + label_model_view_matrix = glm::rotate(label_model_view_matrix, glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f)); + m_plane_shader_program.start(); m_plane_shader_program.setUniform("p", projection_matrix); - m_plane_model->setMVMatrix(label_mv); + m_plane_model->setMVMatrix(label_model_view_matrix); m_billboard_labels[i].label_model->setTexture(m_billboard_labels[i].label_texture); m_billboard_labels[i].label_model->render(m_plane_shader_program); m_plane_shader_program.stop(); } } -void Labels::drawLines() +void LabelManager::draw_lines() { for (size_t i = 0; i < m_lines_vba.size(); ++i) diff --git a/src/interaction/Simulation.cpp b/src/interaction/Simulation.cpp index d9a62e1..8179bb2 100644 --- a/src/interaction/Simulation.cpp +++ b/src/interaction/Simulation.cpp @@ -1,14 +1,14 @@ #include "../include/interaction/Simulation.h" #include "../include/vrapp/VRVolumeApp.h" -Simulation::Simulation(VRVolumeApp &controller_app, float time) : m_animation_duration(time), m_controller_app(controller_app), +Simulation::Simulation(VRVolumeApp &controller_app, float time) : m_simulation_duration(time), m_controller_app(controller_app), animation_button_label("ANIMATE"), m_animation_state(STOP) { } void Simulation::add_simulation_state(SimulationState &simulationState) { - float time = m_simulation_states.size() * m_animation_duration; + float time = m_simulation_states.size() * m_simulation_duration; int mins = (int)time / 60; int seconds = (int)time % 60; @@ -17,7 +17,7 @@ void Simulation::add_simulation_state(SimulationState &simulationState) m_simulation_states.push_back(simulationState); } -void Simulation::create_animations() +void Simulation::create_simulation_time_frames() { if (m_simulation_states.size() > 1) { @@ -29,14 +29,14 @@ void Simulation::create_animations() ch::Sequence sequence_clip_max(first_position.max_clip); ch::Sequence sequence_clip_min(first_position.min_clip); - for (auto iterator = std::next(m_simulation_states.begin()); iterator != m_simulation_states.end(); iterator++) + for (auto iterator = std::next(m_simulation_states.begin()); iterator != m_simulation_states.end(); ++iterator) { - sequence_eye.then(iterator->poi.eye, m_animation_duration); - sequence_target.then(iterator->poi.target, m_animation_duration); - sequence_up.then(iterator->poi.up, m_animation_duration); - sequence_radius.then(iterator->poi.radius, m_animation_duration); - sequence_clip_max.then(iterator->max_clip, m_animation_duration); - sequence_clip_min.then(iterator->min_clip, m_animation_duration); + sequence_eye.then(iterator->poi.eye, m_simulation_duration); + sequence_target.then(iterator->poi.target, m_simulation_duration); + sequence_up.then(iterator->poi.up, m_simulation_duration); + sequence_radius.then(iterator->poi.radius, m_simulation_duration); + sequence_clip_max.then(iterator->max_clip, m_simulation_duration); + sequence_clip_min.then(iterator->min_clip, m_simulation_duration); } auto group = std::make_shared(); @@ -72,14 +72,14 @@ void Simulation::update_simulation() void Simulation::update_time_step() { - m_timeline.step(1.0 / 30.0); + m_timeline.step(1.0 / SIMULATION_TIME_STEP); } void Simulation::set_animation_state() { if (m_animation_state == STOP) { - create_animations(); + create_simulation_time_frames(); m_controller_app.set_app_mode(SIMULATION); m_animation_state = PLAYING; animation_button_label = "PAUSE"; @@ -129,14 +129,14 @@ std::string Simulation::get_camera_animation_state() return animation_button_label; } -float Simulation::get_camera_animation_duration() +float Simulation::get_simulation_duration() { - return m_animation_duration; + return m_simulation_duration; } -void Simulation::set_camera_animation_duration(float duration) +void Simulation::set_simulation_duration(float duration) { - m_animation_duration = duration; + m_simulation_duration = duration; } const std::list &Simulation::get_simulation_states() @@ -179,5 +179,5 @@ void Simulation::remove_simulation_state(unsigned int index) float Simulation::get_animation_duration() { - return m_animation_duration; + return m_simulation_duration; } diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index 8bf83a8..f4a98a2 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -53,7 +53,7 @@ VRVolumeApp::VRVolumeApp() : m_mesh_model(nullptr), m_clip_max{1.0f}, m_clip_min m_lookingGlass(false), m_isInitailized(false), m_speed(0.01f), m_movieAction(nullptr), m_moviename("movie.mp4"), m_noColor(0.0f), m_ambient(0.2f, 0.2f, 0.2f, 1.0f), m_diffuse(0.5f, 0.5f, 0.5f, 1.0f), m_ui_view(nullptr), m_animated(false), m_numVolumes(0), m_selectedVolume(0), m_multiplier(1.0f), m_threshold(0.0f), m_frame(0.0f), m_use_multi_transfer(false), m_clipping(false), m_show_menu(true), - m_window_properties(nullptr), m_animation_speed(1.0f), m_current_movie_state(MOVIE_STOP), m_app_mode(MANUAL), m_end_load(false) + m_window_properties(nullptr), m_volume_animation_scale_factor(1.0f), m_current_movie_state(MOVIE_STOP), m_app_mode(MANUAL), m_end_load(false) { m_renders.push_back(new VolumeSliceRenderer()); m_renders.push_back(new VolumeRaycastRenderer()); @@ -146,14 +146,14 @@ void VRVolumeApp::load_shaders() std::string vertexShaderFolderPath = m_shader_file_path + OS_SLASH + std::string("shader.vert"); std::string fragmentShaderFolderPath = m_shader_file_path + OS_SLASH + std::string("shader.frag"); m_simple_texture_shader.LoadShaders(vertexShaderFolderPath.c_str(), fragmentShaderFolderPath.c_str()); - m_simple_texture_shader.addUniform("p"); - m_simple_texture_shader.addUniform("mv"); + m_simple_texture_shader.addUniform("projection_matrix"); + m_simple_texture_shader.addUniform("model_view_matrix"); std::string linesVertexShaderFolderPath = m_shader_file_path + OS_SLASH + std::string("lines_shader.vert"); std::string linesFragmentShaderFolderPath = m_shader_file_path + OS_SLASH + std::string("lines_shader.frag"); m_line_shader.LoadShaders(linesVertexShaderFolderPath.c_str(), linesFragmentShaderFolderPath.c_str()); - m_line_shader.addUniform("p"); - m_line_shader.addUniform("mv"); + m_line_shader.addUniform("projection_matrix"); + m_line_shader.addUniform("model_view_matrix"); } void VRVolumeApp::initialize_textures() @@ -189,7 +189,7 @@ void VRVolumeApp::update_animation(float fps) { if (m_volumes.size()) { - // m_animation_speed = fps; + // m_volume_animation_multiplier = fps; m_ui_view->update_animation(m_speed, m_volumes[m_selectedVolume].size() - 1); } } @@ -529,7 +529,7 @@ void VRVolumeApp::load_nrrd_file(std::string &filename) } } -void VRVolumeApp::render(const MinVR::VRGraphicsState &renderState) +void VRVolumeApp::render(const MinVR::VRGraphicsState &render_state) { m_trackball.set_app_mode(m_app_mode); if (m_app_mode == SIMULATION) @@ -546,7 +546,7 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState &renderState) if (m_is2d) { - m_headpose = glm::make_mat4(renderState.getViewMatrix()); + m_headpose = glm::make_mat4(render_state.getViewMatrix()); m_headpose = glm::inverse(m_headpose); } @@ -554,14 +554,14 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState &renderState) glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - if (renderState.isInitialRenderCall()) + if (render_state.isInitialRenderCall()) { m_depthTextures.push_back(new DepthTexture); } // setup projection - m_projection_mtrx = glm::make_mat4(renderState.getProjectionMatrix()); - m_model_view = glm::make_mat4(renderState.getViewMatrix()); + m_projection_mtrx = glm::make_mat4(render_state.getProjectionMatrix()); + m_model_view = glm::make_mat4(render_state.getViewMatrix()); // overwrite MV for 2D viewing if (m_is2d) @@ -646,24 +646,18 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState &renderState) if (m_mesh_model) { m_simple_texture_shader.start(); - m_simple_texture_shader.setUniform("p", m_projection_mtrx); + m_simple_texture_shader.setUniform("projection_matrix", m_projection_mtrx); m_mesh_model->render(m_simple_texture_shader); m_simple_texture_shader.stop(); } // render labels m_line_shader.start(); - m_line_shader.setUniform("p", m_projection_mtrx); - m_line_shader.setUniform("mv", volume_mv); - render_labels(volume_mv, renderState); + m_line_shader.setUniform("projection_matrix", m_projection_mtrx); + m_line_shader.setUniform("model_view_matrix", volume_mv); + render_labels(volume_mv, render_state); m_line_shader.stop(); - /*if (m_ui_view && !m_is2d) - { - - glm::mat4 viewMatrix = glm::make_mat4(renderState.getViewMatrix()); - m_ui_view->render_3D(viewMatrix); - }*/ m_depthTextures[m_rendercount]->copyDepthbuffer(); (static_cast(m_renders[1]))->setDepthTexture(m_depthTextures[m_rendercount]); @@ -686,9 +680,9 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState &renderState) } } - render_volume(renderState); + render_volume(render_state); - render_ui(renderState); + render_ui(render_state); glFlush(); @@ -874,7 +868,7 @@ void VRVolumeApp::update_frame_state() glLightfv(GL_LIGHT0, GL_POSITION, m_light_pos); if (m_animated && !m_ui_view->is_stopped()) { - m_frame += (m_speed * m_animation_speed); + m_frame += (m_speed * m_volume_animation_scale_factor); if (m_frame > m_volumes[m_selectedVolume].size() - 1) { m_frame = 0.0; @@ -1140,9 +1134,9 @@ ArcBallCamera &VRVolumeApp::get_trackball_camera() return m_trackball; } -void VRVolumeApp::set_animation_speed(float time) +void VRVolumeApp::set_volume_animation_scale_factor(float scale) { - m_animation_speed = time; + m_volume_animation_scale_factor = scale; } Simulation &VRVolumeApp::get_simulation() diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index 56c72d7..dc7e2ed 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -219,7 +219,7 @@ void VolumeVisualizationApp::onButtonDown(const VRButtonEvent &event) { // This routine is called for all Button_Down events. Check event->getName() // to see exactly which button has been pressed down. - + if (event.getName() == "KbdEsc_Down") { exit(0); @@ -233,17 +233,15 @@ void VolumeVisualizationApp::onButtonDown(const VRButtonEvent &event) } else if (event.getName() == "HTC_Controller_Right_Axis0Button_Down" || event.getName() == "HTC_Controller_1_Axis0Button_Down" || event.getName() == "Wand_Right_Btn_Down") { - + if (m_vrVolumeApp) { m_vrVolumeApp->enable_clipping(true); } - - } else if (event.getName() == "HTC_Controller_Right_GripButton_Down" || event.getName() == "HTC_Controller_1_GripButton_Down" || event.getName() == "B08_Down") { - + if (m_vrVolumeApp) { m_vrVolumeApp->enable_ui_menu(); @@ -426,7 +424,6 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent &event) if (event.getName() == "KbdSpace_Up") { - // m_renderVolume = !m_renderVolume; if (m_vrVolumeApp) { m_vrVolumeApp->enable_render_volume(); @@ -466,7 +463,7 @@ void VolumeVisualizationApp::onTrackerMove(const VRTrackerEvent &event) { m_vrVolumeApp->update_head_pose(headPose); } - // m_headpose = glm::inverse(m_headpose); + m_light_pos[0] = headPose[3][0]; m_light_pos[1] = headPose[3][1]; m_light_pos[2] = headPose[3][2]; @@ -540,7 +537,6 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState &rend glDepthFunc(GL_LEQUAL); glClearColor(0.0, 0.0, 0.0, 1); std::cout << "init vizapp end" << std::endl; - const float duration = 10.5f; } if (m_vrVolumeApp) @@ -554,16 +550,11 @@ void VolumeVisualizationApp::onRenderGraphicsContext(const VRGraphicsState &rend m_vrVolumeApp->update_3D_ui(); m_vrVolumeApp->update_trackBall_state(); - if (true) - { - m_vrVolumeApp->update_animation(delta_time.count()); - last_Update_Time = nowTime; - } + m_vrVolumeApp->update_animation(delta_time.count()); + last_Update_Time = nowTime; m_vrVolumeApp->set_render_count(0); } - - // std::cout << "init vizapp loop" << std::endl; } void VolumeVisualizationApp::onRenderGraphicsScene(const VRGraphicsState &renderState) diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index b85664b..fabd261 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -566,7 +566,7 @@ endif() ${CMAKE_CURRENT_BINARY_DIR}/../libs/glm.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/render/FrameBufferObject.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/render/DepthTexture.cpp - ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/Labels.cpp + ${CMAKE_CURRENT_BINARY_DIR}/../src/interaction/LabelManager.cpp ${CMAKE_CURRENT_BINARY_DIR}/../src/render/FontHandler.cpp ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/transfer_function_widget.cpp ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/transfer_function_multichannel_widget.cpp @@ -594,7 +594,7 @@ set(header_files ${CMAKE_CURRENT_BINARY_DIR}/../libs/glm.h ${CMAKE_CURRENT_BINARY_DIR}/../include/render/FrameBufferObject.h ${CMAKE_CURRENT_BINARY_DIR}/../include/render/DepthTexture.h - ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/Labels.h + ${CMAKE_CURRENT_BINARY_DIR}/../include/interaction/LabelManager.h ${CMAKE_CURRENT_BINARY_DIR}/../include/render/FontHandler.h ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/transfer_function_widget.h ${CMAKE_CURRENT_BINARY_DIR}/../libs/UIHelpers/transfer_function_multichannel_widget.h From 9ac936888149f91b244acfcc410bdbd09afb07ec Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Mon, 2 May 2022 11:52:19 -0400 Subject: [PATCH 18/23] rename variable. remove unused code --- include/UI/UIView.h | 4 ++-- src/UI/UIView.cpp | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/UI/UIView.h b/include/UI/UIView.h index 1bf2c37..1e11747 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -273,8 +273,8 @@ class UIView std::string m_color_map_directory; - float m_animation_speed; - std::string m_animation_duration_to_string; + float m_animation_step; + std::string m_string_animation_duration; bool m_camera_animation_duration_open; diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index 5b3467a..d310dd2 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -28,7 +28,7 @@ UIView::UIView(VRVolumeApp &controllerApp) : m_controller_app(controllerApp), m_ m_current_load_modal(LOAD_NONE), m_file_extension_filter(".txt"), m_non_trns_functions_selected_modal(false), m_ui_background(false), m_column_selection_state(0), m_compute_new_histogram(true), m_histogram_point_1(0.0), m_histogram_point_2(1.1), m_stopped(false), m_color_map_directory("colormaps"), m_show_menu(true), m_camera_poi_table_selection(0), - m_camera_name_window_open(false), m_camera_button_action(BUTTON_ACTION::NONE), m_num_animation_frames(0), m_animation_speed(1.0f), + m_camera_name_window_open(false), m_camera_button_action(BUTTON_ACTION::NONE), m_num_animation_frames(0), m_animation_step(1.0f), m_camera_animation_duration_open(false), m_show_clock(false), m_clock_width(250), m_clock_height(200), m_time_info(""), m_day_info(""), m_time_frame_edited(false), m_show_movie_saved_pop_up(false) { @@ -452,16 +452,16 @@ void UIView::draw_ui_callback() m_stopped = !m_stopped; } ImGui::SameLine(); - int value = int(m_animation_speed * 100.0 + .5); + int value = int(m_animation_step * 100.0 + .5); std::string speed_text = ">>X " + std::to_string(value / 100); if (ImGui::Button(speed_text.c_str(), ImVec2(80, 0))) { - m_animation_speed += 0.5; - if (m_animation_speed > 4.0f) + m_animation_step += 0.5; + if (m_animation_step > 4.0f) { - m_animation_speed = 1.0f; + m_animation_step = 1.0f; } - m_controller_app.set_volume_animation_scale_factor(m_animation_speed); + m_controller_app.set_volume_animation_scale_factor(m_animation_step); } #if (!defined(__APPLE__)) @@ -654,7 +654,7 @@ void UIView::draw_ui_callback() if (ImGui::Button(str_animation_duration.c_str())) { m_camera_animation_duration_open = true; - m_animation_duration_to_string = std::string(str_animation_duration); + m_string_animation_duration = str_animation_duration; } #if (!defined(__APPLE__)) @@ -760,18 +760,18 @@ void UIView::draw_ui_callback() if (ImGui::BeginPopupModal("Animation Time", &m_camera_animation_duration_open)) { ImGui::Text("Camera Name"); - ImGui::InputText("##textanimationtime", &m_animation_duration_to_string, ImGuiInputTextFlags_CharsDecimal); + ImGui::InputText("##textanimationtime", &m_string_animation_duration, ImGuiInputTextFlags_CharsDecimal); if (ImGui::Button("Ok")) { - m_controller_app.get_simulation().set_simulation_duration(std::stof(m_animation_duration_to_string)); - m_animation_duration_to_string.clear(); + m_controller_app.get_simulation().set_simulation_duration(std::stof(m_string_animation_duration)); + m_string_animation_duration.clear(); m_camera_animation_duration_open = false; ImGui::CloseCurrentPopup(); } if (ImGui::Button("Cancel")) { m_camera_animation_duration_open = false; - m_animation_duration_to_string.clear(); + m_string_animation_duration.clear(); ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); @@ -1229,7 +1229,7 @@ void UIView::add_character(char c) ImGui::ClearActiveID(); if ((c >= '0' && c <= '9') || (c == '.')) { - m_animation_duration_to_string += c; + m_string_animation_duration += c; } } } @@ -1262,10 +1262,10 @@ void UIView::remove_character() if (m_camera_animation_duration_open) { - if (!m_animation_duration_to_string.empty()) + if (!m_string_animation_duration.empty()) { ImGui::ClearActiveID(); - m_animation_duration_to_string.pop_back(); + m_string_animation_duration.pop_back(); } } } From 638372866dcfbbdd012956f1cc1692f9c93d4920 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Fri, 6 May 2022 18:08:20 -0400 Subject: [PATCH 19/23] rename variables. format files --- include/render/VolumeRenderer.h | 3 +++ src/vrapp/VRVolumeApp.cpp | 1 - src/vrapp/VolumeVisualizationApp.cpp | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/render/VolumeRenderer.h b/include/render/VolumeRenderer.h index 311af21..a351444 100644 --- a/include/render/VolumeRenderer.h +++ b/include/render/VolumeRenderer.h @@ -53,7 +53,10 @@ class VolumeRenderer { m_clipping = isClipping; if (m_clipping) + { m_clip_plane = *clipPlane; + } + }; protected: diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index f4a98a2..7f1a94b 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -189,7 +189,6 @@ void VRVolumeApp::update_animation(float fps) { if (m_volumes.size()) { - // m_volume_animation_multiplier = fps; m_ui_view->update_animation(m_speed, m_volumes[m_selectedVolume].size() - 1); } } diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index dc7e2ed..ea7824e 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -352,8 +352,7 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent &event) else if (event.getName() == "HTC_Controller_Right_GripButton_Up" || event.getName() == "HTC_Controller_1_GripButton_Up" || event.getName() == "Wand_Right_Btn_Up") { m_vrVolumeApp->button_events_ui_handle(2, 0); - } - // else if (event.getName() == "HTC_Controller_Right_AButton_Down" || event.getName() == "HTC_Controller_1_AButton_Down") + } else if (event.getName() == "HTC_Controller_Right_Axis0Button_Up" || event.getName() == "HTC_Controller_1_Axis0Button_Up" || event.getName() == "B08_Up") { m_vrVolumeApp->button_events_ui_handle(1, 0); From 2d02f28b008d19216ba0b675725ce5186d6a07c2 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Fri, 6 May 2022 18:18:35 -0400 Subject: [PATCH 20/23] renamed uiview member variable --- include/UI/UIView.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/UI/UIView.h b/include/UI/UIView.h index 1e11747..405e54a 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -231,7 +231,7 @@ class UIView bool m_transfer_function_options_window; - bool m_save_trnfct_open; + bool m_save_transfer_function_open; bool m_save_session_dialog_open; From 5a63ded2e968499b67c337562e700743550d57fc Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Mon, 9 May 2022 16:12:45 -0400 Subject: [PATCH 21/23] remove commented code. add notes on code. --- include/render/VolumeRenderer.h | 2 - libs/Model/Model.cpp | 1 + libs/Texture/Texture.cpp | 6 +-- libs/UIHelpers/transfer_function_widget.cpp | 4 +- src/UI/UIView.cpp | 42 +++++++-------------- src/interaction/ArcBallCamera.cpp | 2 +- src/render/VolumeRaycastShader.cpp | 2 + src/vrapp/VRVolumeApp.cpp | 22 +++-------- src/vrapp/VolumeVisualizationApp.cpp | 41 +++++++++----------- superbuild/CMakeLists.txt | 1 + 10 files changed, 46 insertions(+), 77 deletions(-) diff --git a/include/render/VolumeRenderer.h b/include/render/VolumeRenderer.h index a351444..60ff3f6 100644 --- a/include/render/VolumeRenderer.h +++ b/include/render/VolumeRenderer.h @@ -24,7 +24,6 @@ ///\author Benjamin Knorlein ///\date 5/24/2019 - #ifndef VOLUMERENDER_H #define VOLUMERENDER_H @@ -56,7 +55,6 @@ class VolumeRenderer { m_clip_plane = *clipPlane; } - }; protected: diff --git a/libs/Model/Model.cpp b/libs/Model/Model.cpp index e3a0a79..0838d4c 100644 --- a/libs/Model/Model.cpp +++ b/libs/Model/Model.cpp @@ -40,6 +40,7 @@ void Model::render(ShaderProgram &shaderProgram) assert(m_Obj_Model && "NO MODEL TO RENDER"); // bind texture + // Always load texture id 0. The model doesnt support multi texturing. m_texture->Bind(0); // render geometry diff --git a/libs/Texture/Texture.cpp b/libs/Texture/Texture.cpp index 7abcb3e..535d142 100644 --- a/libs/Texture/Texture.cpp +++ b/libs/Texture/Texture.cpp @@ -127,17 +127,15 @@ int Texture::LoadTexture(const std::string &fileName, if (data) { if (bbp == 3) - { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, *data); + { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, *data); } else if (bbp == 4) { - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, *data); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, *data); } - // glGenerateMipmap(GL_TEXTURE_2D); + } else { diff --git a/libs/UIHelpers/transfer_function_widget.cpp b/libs/UIHelpers/transfer_function_widget.cpp index 809bf58..e4ea24c 100644 --- a/libs/UIHelpers/transfer_function_widget.cpp +++ b/libs/UIHelpers/transfer_function_widget.cpp @@ -69,14 +69,12 @@ TransferFunctionWidget::TransferFunctionWidget() load_embedded_preset(blue_gold, sizeof(blue_gold), "Blue Gold"); load_embedded_preset(ice_fire, sizeof(ice_fire), "Ice Fire"); load_embedded_preset(nic_edge, sizeof(nic_edge), "nic Edge"); - // load_embedded_preset(Algae, sizeof(Algae), "Algae"); - + // Initialize the colormap alpha channel w/ a linear ramp update_colormap(); for (int i = 0; i < 256; i++) { - // current_histogram.push_back(static_cast (rand()) / static_cast (RAND_MAX)); current_histogram.push_back(0); } diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index d310dd2..8adc284 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -23,7 +23,7 @@ UIView::UIView(VRVolumeApp &controllerApp) : m_controller_app(controllerApp), m_ m_z_scale(0.16f), m_scale{1.0f}, m_slices(256), m_dynamic_slices(false), m_renderVolume(true), m_selectedTrnFnc(0), m_animated(false), m_ui_frame_controller(0.0f), m_menu_handler(nullptr), m_initialized(false), m_use_transferfunction(false), m_clip_max(1.0), m_clip_min(0.0), m_clip_ypr(0.0), m_clip_pos(0.0), m_useCustomClipPlane(false), m_rendermethod(1), m_renderchannel(0), - m_trnfnc_table_selection(-1), m_transfer_function_options_window(false), m_save_trnfct_open(false), m_trnfnct_counter(1), m_file_dialog_open(false), + m_trnfnc_table_selection(-1), m_transfer_function_options_window(false), m_save_transfer_function_open(false), m_trnfnct_counter(1), m_file_dialog_open(false), m_file_load_trnsf(false), m_file_dialog_save_dir(false), m_save_session_dialog_open(false), m_current_save_modal(SAVE_NONE), m_current_load_modal(LOAD_NONE), m_file_extension_filter(".txt"), m_non_trns_functions_selected_modal(false), m_ui_background(false), m_column_selection_state(0), m_compute_new_histogram(true), m_histogram_point_1(0.0), @@ -181,7 +181,7 @@ void UIView::draw_ui_callback() ImGui::SameLine(); if (ImGui::SmallButton("Save Functions")) { - m_save_trnfct_open = true; + m_save_transfer_function_open = true; m_non_trns_functions_selected_modal = !m_use_transferfunction; }; @@ -290,7 +290,7 @@ void UIView::draw_ui_callback() open_save_modal_dialog(save_user_session_window_id, m_save_session_dialog_open, save_funtion, extension); } - if (m_save_trnfct_open) + if (m_save_transfer_function_open) { m_current_save_modal = SAVE_TRFR_FNC; std::string save_Trnf_window_id = "Save Transfer Functions"; @@ -298,7 +298,7 @@ void UIView::draw_ui_callback() { std::string extension = ".fnc"; auto save_funtion = std::bind(&UIView::save_transfer_functions, this, std::placeholders::_1); - open_save_modal_dialog(save_Trnf_window_id, m_save_trnfct_open, save_funtion, extension); + open_save_modal_dialog(save_Trnf_window_id, m_save_transfer_function_open, save_funtion, extension); } else { @@ -311,7 +311,7 @@ void UIView::draw_ui_callback() if (ImGui::Button("Close")) { m_non_trns_functions_selected_modal = false; - m_save_trnfct_open = false; + m_save_transfer_function_open = false; ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); @@ -415,7 +415,7 @@ void UIView::draw_ui_callback() /* TODO: - Fix frame by frame animation + The base code to fix frame by frame animation unsigned int active_volume = floor(m_frame); unsigned int active_volume2 = ceil(m_frame); @@ -796,10 +796,10 @@ void UIView::draw_ui_callback() else if (helper::ends_with_string(fileDialog.selected_fn, ".nrrd")) { std::vector vals; - /* vals.push_back(fileDialog.GetSelected().string()); + vals.push_back(fileDialog.GetSelected().string()); promises.push_back(new std::promise); futures.push_back(promises.back()->get_future()); - threads.push_back(new std::thread(&VolumeVisualizationApp::loadVolume, this, vals, promises.back()));*/ + threads.push_back(new std::thread(&VolumeVisualizationApp::loadVolume, this, vals, promises.back())); } #endif } @@ -814,7 +814,7 @@ void UIView::draw_ui_callback() m_save_session_dialog_open = false; break; case SAVE_TRFR_FNC: - m_save_trnfct_open = false; + m_save_transfer_function_open = false; break; default: break; @@ -836,7 +836,7 @@ void UIView::draw_ui_callback() m_save_session_dialog_open = true; break; case SAVE_TRFR_FNC: - m_save_trnfct_open = true; + m_save_transfer_function_open = true; break; default: break; @@ -918,7 +918,6 @@ void UIView::init_ui(bool is2D, bool lookingGlass) if (!m_initialized) { - // fileDialog.SetTitle("load data"); #ifdef WITH_NRRD fileDialog.SetTypeFilters({".txt", ".nrrd"}); #elseif @@ -1212,7 +1211,7 @@ void UIView::add_character(char c) ImGui::ClearActiveID(); m_copy_trnfnct_name += c; } - if (m_save_trnfct_open || m_save_session_dialog_open) + if (m_save_transfer_function_open || m_save_session_dialog_open) { ImGui::ClearActiveID(); m_save_file_name += c; @@ -1244,7 +1243,7 @@ void UIView::remove_character() } } - if (m_save_trnfct_open || m_save_session_dialog_open) + if (m_save_transfer_function_open || m_save_session_dialog_open) { if (!m_save_file_name.empty()) { @@ -1318,22 +1317,9 @@ void UIView::save_transfer_functions(std::ofstream &saveFile) saveFile << "numFunction " << std::to_string(m_tfns.size()) << "\n"; for (int i = 0; i < m_tfns.size(); i++) { - // savefile << m_tfns[i].ID + ","; + saveFile << "FuncName " + std::to_string(i + 1) + " " + m_tfns[i].Name + " " + std::to_string(tfn_widget[i].get_colormap_gpu()) + "\n"; - /* for (int j = 0; j < tfn_widget_multi[i].alpha_control_pts.size(); j++) - { - if (j != tfn_widget_multi[i].alpha_control_pts.size()-1) - { - savefile << std::to_string(tfn_widget_multi[i].alpha_control_pts[j][0].x) +","+ std::to_string(tfn_widget_multi[i].alpha_control_pts[j][0].y) + - std::to_string(tfn_widget_multi[i].alpha_control_pts[j][1].x) + "," + std::to_string(tfn_widget_multi[i].alpha_control_pts[j][1].y); - } - else - { - savefile << std::to_string(tfn_widget_multi[i].alpha_control_pts[j][0].x) + "," + std::to_string(tfn_widget_multi[i].alpha_control_pts[j][0].y )+ - std::to_string(tfn_widget_multi[i].alpha_control_pts[j][1].x) + "," + std::to_string(tfn_widget_multi[i].alpha_control_pts[j][1].y) +";"; - } - - }*/ + saveFile << "FuncPoints " << std::to_string(i + 1) << " "; for (int j = 0; j < tfn_widget[i].alpha_control_pts.size(); j++) { diff --git a/src/interaction/ArcBallCamera.cpp b/src/interaction/ArcBallCamera.cpp index 7ace944..ee818d5 100644 --- a/src/interaction/ArcBallCamera.cpp +++ b/src/interaction/ArcBallCamera.cpp @@ -1,5 +1,5 @@ // ---------------------------------- -// Copyright � 2017, Brown University, Providence, RI. +// Copyright © 2017, Brown University, Providence, RI. // // All Rights Reserved // diff --git a/src/render/VolumeRaycastShader.cpp b/src/render/VolumeRaycastShader.cpp index 3e670e7..a101e40 100644 --- a/src/render/VolumeRaycastShader.cpp +++ b/src/render/VolumeRaycastShader.cpp @@ -111,6 +111,8 @@ VolumeRaycastShader::VolumeRaycastShader() : m_use_blending{false}, m_blend_volu // To ensure we update dataPos and t_hit to reflect a ray from entry point to exit "dataPos = camPos + t_hit.x * geomDir;\n" "t_hit.y = t_hit.y-t_hit.x; \n" + + // slightly move the ray to not collide with viewport culling front plane. "t_hit.x = 0.0001f; \n" // get t for the clipping plane and overwrite the entry point diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index 7f1a94b..58c8b11 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -82,10 +82,10 @@ void VRVolumeApp::initialize() if (!m_isInitailized) { - // std::cout << "initialize 1" << std::endl; + m_object_pose = glm::mat4(1.0f); initialize_GL(); - // std::cout << "initialize 2" << std::endl; + if (!m_ui_view) { std::cout << "initialize UI " << std::endl; @@ -325,7 +325,6 @@ void VRVolumeApp::set_texture(std::string &fileNamePath) void VRVolumeApp::init_num_volumes(int nVolumes) { m_numVolumes = nVolumes; - // m_data_labels.resize(m_numVolumes); m_volumes.resize(m_numVolumes); m_promises.resize(m_numVolumes); m_futures.resize(m_numVolumes); @@ -604,16 +603,6 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState &render_state) } } - /* SOriginal transformations of the volumes - DO NOT REMOVE YET */ - // for (int i = 0; i < m_models_displayLists.size(); i++) { - // if (m_volumes.size() > m_models_volumeID[i]) { - // m_models_MV[i] = m_volumes[m_models_volumeID[i]]->get_volume_mv(); - // m_models_MV[i] = glm::translate(m_models_MV[i], glm::vec3(-0.5f, -0.5f, -0.5f * m_volumes[m_models_volumeID[i]]->get_volume_scale().x / (m_volumes[m_models_volumeID[i]]->get_volume_scale().z))); - // m_models_MV[i] = glm::scale(m_models_MV[i], glm::vec3(m_volumes[m_models_volumeID[i]]->get_volume_scale().x, m_volumes[m_models_volumeID[i]]->get_volume_scale().y, m_volumes[m_models_volumeID[i]]->get_volume_scale().x)); - // //m_models_MV[i] = glm::scale(m_models_MV[i], glm::vec3(10,10,10)); - // } - // } - if (m_clipping || m_ui_view->is_use_custom_clip_plane()) { glm::mat4 clipPlane = glm::inverse(m_controller_pose) * glm::inverse(m_model_view); @@ -657,7 +646,6 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState &render_state) render_labels(volume_mv, render_state); m_line_shader.stop(); - m_depthTextures[m_rendercount]->copyDepthbuffer(); (static_cast(m_renders[1]))->setDepthTexture(m_depthTextures[m_rendercount]); @@ -731,8 +719,7 @@ void VRVolumeApp::render_mesh(const MinVR::VRGraphicsState &renderState) void VRVolumeApp::render_volume(const MinVR::VRGraphicsState &renderState) { - // render volumes - // renderState->getProjectionMatrix(); + for (auto ren : m_renders) { ren->set_multiplier(m_ui_view->get_multiplier()); @@ -970,6 +957,9 @@ bool VRVolumeApp::data_is_multi_channel() int renderchannel = m_ui_view->get_render_channel(); for (int i = 0; i < m_volumes.size(); i++) { + // renderchannel[0] = "based on data" + // renderchannel[5] = "rgba" + // renderchannel[6] = "rgba with alpha as max rgb"; if (m_volumes.size() > 0 && m_volumes[i][0]->get_channels() > 1 && (renderchannel == 0 || renderchannel == 5 || renderchannel == 6)) { diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index ea7824e..7f3378e 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -45,18 +45,15 @@ VolumeVisualizationApp::VolumeVisualizationApp(int argc, char **argv) : VRApp(ar if (std::string(argv_int[i]) == std::string("use2DUI")) { - // m_is2d = true; + m_vrVolumeApp->set_is_2D(true); } if (std::string(argv_int[i]) == std::string("useHolo")) { - // m_lookingGlass = true; - // m_speed = 0.5; m_vrVolumeApp->set_looking_glass(true); } else if (std::string(argv_int[i]) == std::string("convert")) { - // convert = true; m_vrVolumeApp->set_convert(true); } else if (helper::ends_with_string(std::string(argv_int[i]), ".txt")) @@ -67,27 +64,27 @@ VolumeVisualizationApp::VolumeVisualizationApp(int argc, char **argv) : VRApp(ar else if (helper::ends_with_string(std::string(argv_int[i]), ".nrrd")) { - /* - NRRD LOADING - std::vector vals; - vals.push_back(std::string(argv_int[i])); - std::vector*> v; - std::promise* pm = new std::promise(); + NRRD LOADING + std::vector + vals; + vals.push_back(std::string(argv_int[i])); + std::vector *> v; + std::promise *pm = new std::promise(); - v.push_back(pm); - promises.push_back(v); + v.push_back(pm); + promises.push_back(v); - std::vector>* fut = new std::vector>; - fut->push_back(pm->get_future()); - futures.push_back(fut); + std::vector> *fut = new std::vector>; + fut->push_back(pm->get_future()); + futures.push_back(fut); - std::vector ths; - std::vector*> v2= promises.back(); - ths.emplace_back(new std::thread(&VolumeVisualizationApp::loadVolume, this, vals, v2.back())); - threads.push_back(ths);*/ + std::vector ths; + std::vector *> v2 = promises.back(); + ths.emplace_back(new std::thread(&VolumeVisualizationApp::loadVolume, this, vals, v2.back())); + threads.push_back(ths); std::string nrrdFileName(argv_int[i]); m_vrVolumeApp->load_nrrd_file(nrrdFileName); - // m_vrVolumeApp->initialize(); + m_vrVolumeApp->initialize(); } } } @@ -127,12 +124,10 @@ void VolumeVisualizationApp::onAnalogChange(const VRAnalogEvent &event) if (m_vrVolumeApp && m_vrVolumeApp->is_show_menu() && m_vrVolumeApp->is_ui_event()) { if (event.getName() == "HTC_Controller_Right_TrackPad0_Y" || event.getName() == "HTC_Controller_1_TrackPad0_Y" || (event.getName() == "Wand_Joystick_Y_Update" && !(event.getValue() > -0.1 && event.getValue() < 0.1))) - // m_menu_handler->setAnalogValue(event.getValue()); m_vrVolumeApp->update_ui_events(event.getValue()); if (event.getName() == "MouseWheel_Spin") { std::cerr << event.getValue() << std::endl; - // m_menu_handler->setAnalogValue(event.getValue() * 10); m_vrVolumeApp->update_ui_events(event.getValue() * 10); } } @@ -352,7 +347,7 @@ void VolumeVisualizationApp::onButtonUp(const VRButtonEvent &event) else if (event.getName() == "HTC_Controller_Right_GripButton_Up" || event.getName() == "HTC_Controller_1_GripButton_Up" || event.getName() == "Wand_Right_Btn_Up") { m_vrVolumeApp->button_events_ui_handle(2, 0); - } + } else if (event.getName() == "HTC_Controller_Right_Axis0Button_Up" || event.getName() == "HTC_Controller_1_Axis0Button_Up" || event.getName() == "B08_Up") { m_vrVolumeApp->button_events_ui_handle(1, 0); diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index fabd261..8dbb2a5 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -586,6 +586,7 @@ set(header_files ${CMAKE_CURRENT_BINARY_DIR}/../include/loader/LoadDataAction.h ${CMAKE_CURRENT_BINARY_DIR}/../include/render/Shader.h ${CMAKE_CURRENT_BINARY_DIR}/../include/render/Volume.h + ${CMAKE_CURRENT_BINARY_DIR}/../include/render/VolumeRenderer.h ${CMAKE_CURRENT_BINARY_DIR}/../include/render/VolumeSliceRenderer.h ${CMAKE_CURRENT_BINARY_DIR}/../include/render/VolumeSliceShader.h ${CMAKE_CURRENT_BINARY_DIR}/../include/render/VolumeRaycastRenderer.h From f197c5fa066f9f2cc9d5b5ae2e3f4f6761c19da5 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Mon, 9 May 2022 17:53:22 -0400 Subject: [PATCH 22/23] remove uncommented code. reformatted files --- .../transfer_function_widget.cpp | 503 +++++++++--------- src/interaction/ArcBallCamera.cpp | 2 +- src/vrapp/VRVolumeApp.cpp | 27 - src/vrapp/VolumeVisualizationApp.cpp | 2 - 4 files changed, 267 insertions(+), 267 deletions(-) diff --git a/libs/transferfunction/transfer_function_widget.cpp b/libs/transferfunction/transfer_function_widget.cpp index 67d7aff..8ccc853 100644 --- a/libs/transferfunction/transfer_function_widget.cpp +++ b/libs/transferfunction/transfer_function_widget.cpp @@ -16,10 +16,12 @@ template T clamp(T x, T min, T max) { - if (x < min) { + if (x < min) + { return min; } - if (x > max) { + if (x > max) + { return max; } return x; @@ -73,14 +75,14 @@ TransferFunctionWidget::vec2f::operator ImVec2() const TransferFunctionWidget::TransferFunctionWidget() { // Load up the embedded colormaps as the default options - load_embedded_preset(cool_warm_extended, sizeof(cool_warm_extended), "Cool Warm Extended"); - load_embedded_preset(paraview_cool_warm, sizeof(paraview_cool_warm), "ParaView Cool Warm"); + load_embedded_preset(cool_warm_extended, sizeof(cool_warm_extended), "Cool Warm Extended"); + load_embedded_preset(paraview_cool_warm, sizeof(paraview_cool_warm), "ParaView Cool Warm"); load_embedded_preset(rainbow, sizeof(rainbow), "Rainbow"); load_embedded_preset(matplotlib_plasma, sizeof(matplotlib_plasma), "Matplotlib Plasma"); load_embedded_preset(matplotlib_virdis, sizeof(matplotlib_virdis), "Matplotlib Virdis"); load_embedded_preset(samsel_linear_green, sizeof(samsel_linear_green), "Samsel Linear Green"); load_embedded_preset(samsel_linear_ygb_1211g, sizeof(samsel_linear_ygb_1211g), "Samsel Linear YGB 1211G"); - load_embedded_preset(blackbody, sizeof(blackbody), "Black Body"); + load_embedded_preset(blackbody, sizeof(blackbody), "Black Body"); load_embedded_preset(jet, sizeof(jet), "Jet"); load_embedded_preset(blue_gold, sizeof(blue_gold), "Blue Gold"); load_embedded_preset(ice_fire, sizeof(ice_fire), "Ice Fire"); @@ -89,12 +91,11 @@ TransferFunctionWidget::TransferFunctionWidget() // Initialize the colormap alpha channel w/ a linear ramp update_colormap(); - for (int i = 0; i < 255; i++) - current_histogram.push_back(static_cast (rand()) / static_cast (RAND_MAX)); + for (int i = 0; i < 255; i++) + current_histogram.push_back(static_cast(rand()) / static_cast(RAND_MAX)); - - m_min_max_val[0] = 0.0f; - m_min_max_val[1] = 1.0f; + m_min_max_val[0] = 0.0f; + m_min_max_val[1] = 1.0f; } void TransferFunctionWidget::add_colormap(const Colormap &map) @@ -114,9 +115,12 @@ void TransferFunctionWidget::draw_ui() "Left click to add a point, right click remove. " "Left click + drag to move points."); - if (ImGui::BeginCombo("Colormap", colormaps[selected_colormap].name.c_str())) { - for (size_t i = 0; i < colormaps.size(); ++i) { - if (ImGui::Selectable(colormaps[i].name.c_str(), selected_colormap == i)) { + if (ImGui::BeginCombo("Colormap", colormaps[selected_colormap].name.c_str())) + { + for (size_t i = 0; i < colormaps.size(); ++i) + { + if (ImGui::Selectable(colormaps[i].name.c_str(), selected_colormap == i)) + { selected_colormap = i; update_colormap(); } @@ -142,83 +146,106 @@ void TransferFunctionWidget::draw_ui() draw_list->AddRect(canvas_pos, canvas_pos + canvas_size, ImColor(180, 180, 180, 255)); ImGui::InvisibleButton("tfn_canvas", canvas_size); - if (ImGui::IsItemHovered() || selected_point != (size_t)-1) { - + if (ImGui::IsItemHovered() || selected_point != (size_t)-1) + { + vec2f mouse_pos = (vec2f(io.MousePos) - view_offset) / view_scale; mouse_pos.x = clamp(mouse_pos.x, 0.f, 1.f); mouse_pos.y = clamp(mouse_pos.y, 0.f, 1.f); - //bool requires_sorting = false; - - if (io.MouseDown[0]) { - if (selected_point != (size_t)-1) { - alpha_control_pts[selected_point] = mouse_pos; - - //make sure point does not cross - + // bool requires_sorting = false; + + if (io.MouseDown[0]) + { + if (selected_point != (size_t)-1) + { + alpha_control_pts[selected_point] = mouse_pos; + + // make sure point does not cross + // Keep the first and last control points at the edges - if (selected_point == 0) { + if (selected_point == 0) + { alpha_control_pts[selected_point].x = 0.f; - } else if (selected_point == alpha_control_pts.size() - 1) { + } + else if (selected_point == alpha_control_pts.size() - 1) + { alpha_control_pts[selected_point].x = 1.f; } - //make sure the other points do not cross - else + // make sure the other points do not cross + else { - alpha_control_pts[selected_point].x = (alpha_control_pts[selected_point].x < alpha_control_pts[selected_point - 1].x) - ? alpha_control_pts[selected_point - 1].x + 0.01 : alpha_control_pts[selected_point].x; - alpha_control_pts[selected_point].x = (alpha_control_pts[selected_point].x > alpha_control_pts[selected_point + 1].x) - ? alpha_control_pts[selected_point + 1].x - 0.01 : alpha_control_pts[selected_point].x; + alpha_control_pts[selected_point].x = (alpha_control_pts[selected_point].x < alpha_control_pts[selected_point - 1].x) + ? alpha_control_pts[selected_point - 1].x + 0.01 + : alpha_control_pts[selected_point].x; + alpha_control_pts[selected_point].x = (alpha_control_pts[selected_point].x > alpha_control_pts[selected_point + 1].x) + ? alpha_control_pts[selected_point + 1].x - 0.01 + : alpha_control_pts[selected_point].x; } - } else { + } + else + { // See if we're selecting a point or adding one - if (io.MousePos.x - canvas_pos.x <= point_radius) { + if (io.MousePos.x - canvas_pos.x <= point_radius) + { selected_point = 0; - } else if (io.MousePos.x - canvas_pos.x >= canvas_size.x - point_radius) { + } + else if (io.MousePos.x - canvas_pos.x >= canvas_size.x - point_radius) + { selected_point = alpha_control_pts.size() - 1; - } else { + } + else + { auto fnd = std::find_if( - alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f &p) { + alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f &p) + { const vec2f pt_pos = p * view_scale + view_offset; float dist = (pt_pos - vec2f(io.MousePos)).length(); - return dist <= point_radius; - }); + return dist <= point_radius; }); // No nearby point, we're adding a new one - if (fnd == alpha_control_pts.end()) { + if (fnd == alpha_control_pts.end()) + { alpha_control_pts.push_back(mouse_pos); - // Keep alpha control points ordered by x coordinate, update - // selected point index to match - std::sort(alpha_control_pts.begin(), - alpha_control_pts.end(), - [](const vec2f& a, const vec2f& b) { return a.x < b.x; }); - if (selected_point != 0 && selected_point != alpha_control_pts.size() - 1) { - fnd = std::find_if( - alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f& p) { + // Keep alpha control points ordered by x coordinate, update + // selected point index to match + std::sort(alpha_control_pts.begin(), + alpha_control_pts.end(), + [](const vec2f &a, const vec2f &b) + { return a.x < b.x; }); + if (selected_point != 0 && selected_point != alpha_control_pts.size() - 1) + { + fnd = std::find_if( + alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f &p) + { const vec2f pt_pos = p * view_scale + view_offset; float dist = (pt_pos - vec2f(io.MousePos)).length(); - return dist <= point_radius; - }); - } + return dist <= point_radius; }); + } } - selected_point = std::distance(alpha_control_pts.begin(), fnd); + selected_point = std::distance(alpha_control_pts.begin(), fnd); } } update_colormap(); - } else if (ImGui::IsMouseClicked(1)) { + } + else if (ImGui::IsMouseClicked(1)) + { selected_point = -1; // Find and remove the point auto fnd = std::find_if( - alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f &p) { + alpha_control_pts.begin(), alpha_control_pts.end(), [&](const vec2f &p) + { const vec2f pt_pos = p * view_scale + view_offset; float dist = (pt_pos - vec2f(io.MousePos)).length(); - return dist <= point_radius; - }); + return dist <= point_radius; }); // We also want to prevent erasing the first and last points if (fnd != alpha_control_pts.end() && fnd != alpha_control_pts.begin() && - fnd != alpha_control_pts.end() - 1) { + fnd != alpha_control_pts.end() - 1) + { alpha_control_pts.erase(fnd); } update_colormap(); - } else { + } + else + { selected_point = -1; } } @@ -226,55 +253,61 @@ void TransferFunctionWidget::draw_ui() // Draw the alpha control points, and build the points for the polyline // which connects them std::vector polyline_pts; - for (const auto &pt : alpha_control_pts) { + for (const auto &pt : alpha_control_pts) + { const vec2f pt_pos = pt * view_scale + view_offset; polyline_pts.push_back(pt_pos); draw_list->AddCircleFilled(pt_pos, point_radius, 0xFFFFFFFF); } - //Code to Draw histogram in the UI - /*for (int i = 0; i < current_histogram.size(); i++) { - // vec2f lp = vec2f( ((float) i) / current_histogram.size(), 0.0f); - // vec2f hp = vec2f( ((float) i + 1.0f) / current_histogram.size(), current_histogram[i]); - // draw_list->AddRectFilled(lp * view_scale + view_offset, hp * view_scale + view_offset, 0x77777777); - //} - */ + // Code to Draw histogram in the UI + /*for (int i = 0; i < current_histogram.size(); i++) { + // vec2f lp = vec2f( ((float) i) / current_histogram.size(), 0.0f); + // vec2f hp = vec2f( ((float) i + 1.0f) / current_histogram.size(), current_histogram[i]); + // draw_list->AddRectFilled(lp * view_scale + view_offset, hp * view_scale + view_offset, 0x77777777); + //} + */ draw_list->AddPolyline(polyline_pts.data(), polyline_pts.size(), 0xFFFFFFFF, false, 2.f); draw_list->PopClipRect(); - //Add Label tick marks - int nbTicks = 5; - vec2f tick_pos = ImGui::GetCursorScreenPos(); - tick_pos.y -= ImGui::GetStyle().ItemSpacing.y; - vec2f tick_size = ImGui::GetContentRegionAvail(); - tick_size.y = 5; - draw_list->PushClipRect(tick_pos, ImVec2(tick_pos.x + tick_size.x, tick_pos.y + tick_size.y)); - - for (int i = 0; i < nbTicks; i++) { - float percentage = float(i) / (nbTicks - 1); - - draw_list->AddLine(ImVec2(tick_pos.x + percentage*(tick_size.x -1), tick_size.y), - ImVec2(tick_pos.x + percentage * (tick_size.x - 1), tick_pos.y + tick_size.y), ImColor(255, 255, 255, 255), 1); - } - draw_list->PopClipRect(); - - //Add Label text - const float ItemSpacing = ImGui::GetStyle().ItemSpacing.x; - for (int i = 0; i < nbTicks; i++) { - float percentage = float(i) / (nbTicks - 1); - float val = (m_min_max_val[1] - m_min_max_val[0]) * percentage + m_min_max_val[0]; - std::stringstream text; - text << std::fixed << std::setprecision(4) << val; - if (i == 0) { - } - else if (i == nbTicks - 1) { - ImGui::SameLine(ImGui::GetWindowWidth() - ItemSpacing - ImGui::CalcTextSize(text.str().c_str()).x); - } - else { - ImGui::SameLine((ImGui::GetWindowWidth()) * percentage - ImGui::CalcTextSize(text.str().c_str()).x * 0.5); - } - ImGui::Text(text.str().c_str()); - } + // Add Label tick marks + int nbTicks = 5; + vec2f tick_pos = ImGui::GetCursorScreenPos(); + tick_pos.y -= ImGui::GetStyle().ItemSpacing.y; + vec2f tick_size = ImGui::GetContentRegionAvail(); + tick_size.y = 5; + draw_list->PushClipRect(tick_pos, ImVec2(tick_pos.x + tick_size.x, tick_pos.y + tick_size.y)); + + for (int i = 0; i < nbTicks; i++) + { + float percentage = float(i) / (nbTicks - 1); + + draw_list->AddLine(ImVec2(tick_pos.x + percentage * (tick_size.x - 1), tick_size.y), + ImVec2(tick_pos.x + percentage * (tick_size.x - 1), tick_pos.y + tick_size.y), ImColor(255, 255, 255, 255), 1); + } + draw_list->PopClipRect(); + + // Add Label text + const float ItemSpacing = ImGui::GetStyle().ItemSpacing.x; + for (int i = 0; i < nbTicks; i++) + { + float percentage = float(i) / (nbTicks - 1); + float val = (m_min_max_val[1] - m_min_max_val[0]) * percentage + m_min_max_val[0]; + std::stringstream text; + text << std::fixed << std::setprecision(4) << val; + if (i == 0) + { + } + else if (i == nbTicks - 1) + { + ImGui::SameLine(ImGui::GetWindowWidth() - ItemSpacing - ImGui::CalcTextSize(text.str().c_str()).x); + } + else + { + ImGui::SameLine((ImGui::GetWindowWidth()) * percentage - ImGui::CalcTextSize(text.str().c_str()).x * 0.5); + } + ImGui::Text(text.str().c_str()); + } } bool TransferFunctionWidget::changed() const @@ -290,7 +323,8 @@ std::vector TransferFunctionWidget::get_colormap() std::vector TransferFunctionWidget::get_colormapf() { std::vector colormapf(current_colormap.size(), 0.f); - for (size_t i = 0; i < current_colormap.size(); ++i) { + for (size_t i = 0; i < current_colormap.size(); ++i) + { colormapf[i] = current_colormap[i] / 255.f; } return colormapf; @@ -298,31 +332,31 @@ std::vector TransferFunctionWidget::get_colormapf() void TransferFunctionWidget::setHistogram(const std::vector &hist) { - current_histogram = hist; + current_histogram = hist; } -void TransferFunctionWidget::setMinMax(const float min, const float max) { - m_min_max_val[0] = min; - m_min_max_val[1] = max; +void TransferFunctionWidget::setMinMax(const float min, const float max) +{ + m_min_max_val[0] = min; + m_min_max_val[1] = max; } - -void TransferFunctionWidget::setBlendedHistogram(const std::vector& hist1, const std::vector& hist2, float alpha) +void TransferFunctionWidget::setBlendedHistogram(const std::vector &hist1, const std::vector &hist2, float alpha) { - if (hist1.size() != hist2.size()) - return; + if (hist1.size() != hist2.size()) + return; - current_histogram.clear(); - for (int i = 0; i < hist1.size(); i++) - current_histogram.push_back(hist1[i] * alpha + hist2[i] * (1.0f - alpha)); + current_histogram.clear(); + for (int i = 0; i < hist1.size(); i++) + current_histogram.push_back(hist1[i] * alpha + hist2[i] * (1.0f - alpha)); } - void TransferFunctionWidget::get_colormapf(std::vector &color, std::vector &opacity) { color.resize((current_colormap.size() / 4) * 3); opacity.resize(current_colormap.size() / 4); - for (size_t i = 0; i < current_colormap.size() / 4; ++i) { + for (size_t i = 0; i < current_colormap.size() / 4; ++i) + { color[i * 3] = current_colormap[i * 4] / 255.f; color[i * 3 + 1] = current_colormap[i * 4 + 1] / 255.f; color[i * 3 + 2] = current_colormap[i * 4 + 2] / 255.f; @@ -330,141 +364,132 @@ void TransferFunctionWidget::get_colormapf(std::vector &color, std::vecto } } -void TransferFunctionWidget::drawLegend() { - /*GLint viewport[4]; - GLfloat projection[16]; - GLfloat modelview[16]; - - int min [2] = { 50 , 100 }; - int max [2] = { 400 , 120 }; - - - glGetIntegerv(GL_VIEWPORT, &viewport[0]); - glGetFloatv(GL_PROJECTION_MATRIX, &projection[0]); - glGetFloatv(GL_MODELVIEW_MATRIX, &modelview[0]); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, viewport[2], 0, viewport[3], -1, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glDisable(GL_LIGHTING); - glEnable(GL_TEXTURE_2D); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glBindTexture(GL_TEXTURE_2D, colormap_img); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glBegin(GL_QUADS); - glTexCoord2f(0, 1); - glVertex3f(min[0], max[1], 0); - glTexCoord2f(1, 1); - glVertex3f(max[0], max[1], 0); - glTexCoord2f(1, 0); - glVertex3f(max[0], 0.5f * (min[1] + max[1]), 0); - glTexCoord2f(0, 0); - glVertex3f(min[0], 0.5f * (min[1] + max[1]), 0); - glEnd(); - glDisable(GL_BLEND); - glBindTexture(GL_TEXTURE_2D, 0); - - glBindTexture(GL_TEXTURE_2D, colormap_img); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glBegin(GL_QUADS); - glTexCoord2f(0, 1); - glVertex3f(min[0], 0.5f * (min[1] + max[1]), 0); - glTexCoord2f(1, 1); - glVertex3f(max[0], 0.5f * (min[1] + max[1]), 0); - glTexCoord2f(1, 0); - glVertex3f(max[0], min[1], 0); - glTexCoord2f(0, 0); - glVertex3f(min[0], min[1], 0); - glEnd(); - glDisable(GL_TEXTURE_2D); - - glBindTexture(GL_TEXTURE_2D, 0); - - - - //Add Label tick marks - int nbTicks = 4; - float diff = (max[0] - min[0])/nbTicks; - for (int i = 0; i <= nbTicks; i++) { - float pos_x = min[0] + i * diff; - glBegin(GL_LINES); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glVertex3f(pos_x, min[1], 0); - glVertex3f(pos_x, min[1] - 5, 0); - glEnd(); - - float percentage = float(i) / (nbTicks); - float val = (m_min_max_val[1] - m_min_max_val[0]) * percentage + m_min_max_val[0]; - std::stringstream text; - text << std::fixed << std::setprecision(4) << val; - - FontHandler::getInstance()->renderTextBox(text.str(), pos_x - 100 , min[1] - 15, 0, 200.0, 10, TextAlignment::CENTER); - } - - glEnable(GL_LIGHTING); - - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(projection); - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(modelview); +void TransferFunctionWidget::drawLegend() +{ + /*GLint viewport[4]; + GLfloat projection[16]; + GLfloat modelview[16]; + + int min [2] = { 50 , 100 }; + int max [2] = { 400 , 120 }; + + + glGetIntegerv(GL_VIEWPORT, &viewport[0]); + glGetFloatv(GL_PROJECTION_MATRIX, &projection[0]); + glGetFloatv(GL_MODELVIEW_MATRIX, &modelview[0]); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, viewport[2], 0, viewport[3], -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glBindTexture(GL_TEXTURE_2D, colormap_img); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0, 1); + glVertex3f(min[0], max[1], 0); + glTexCoord2f(1, 1); + glVertex3f(max[0], max[1], 0); + glTexCoord2f(1, 0); + glVertex3f(max[0], 0.5f * (min[1] + max[1]), 0); + glTexCoord2f(0, 0); + glVertex3f(min[0], 0.5f * (min[1] + max[1]), 0); + glEnd(); + glDisable(GL_BLEND); + glBindTexture(GL_TEXTURE_2D, 0); + + glBindTexture(GL_TEXTURE_2D, colormap_img); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0, 1); + glVertex3f(min[0], 0.5f * (min[1] + max[1]), 0); + glTexCoord2f(1, 1); + glVertex3f(max[0], 0.5f * (min[1] + max[1]), 0); + glTexCoord2f(1, 0); + glVertex3f(max[0], min[1], 0); + glTexCoord2f(0, 0); + glVertex3f(min[0], min[1], 0); + glEnd(); + glDisable(GL_TEXTURE_2D); + + glBindTexture(GL_TEXTURE_2D, 0); + + + + //Add Label tick marks + int nbTicks = 4; + float diff = (max[0] - min[0])/nbTicks; + for (int i = 0; i <= nbTicks; i++) { + float pos_x = min[0] + i * diff; + glBegin(GL_LINES); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glVertex3f(pos_x, min[1], 0); + glVertex3f(pos_x, min[1] - 5, 0); + glEnd(); + + float percentage = float(i) / (nbTicks); + float val = (m_min_max_val[1] - m_min_max_val[0]) * percentage + m_min_max_val[0]; + std::stringstream text; + text << std::fixed << std::setprecision(4) << val; + + FontHandler::getInstance()->renderTextBox(text.str(), pos_x - 100 , min[1] - 15, 0, 200.0, 10, TextAlignment::CENTER); + } -*/ + glEnable(GL_LIGHTING); + glMatrixMode(GL_PROJECTION); + glLoadMatrixf(projection); + glMatrixMode(GL_MODELVIEW); + glLoadMatrixf(modelview); + +*/ } void TransferFunctionWidget::draw_histogram() { - //update_gpu_image(); - - - const ImGuiIO& io = ImGui::GetIO(); + // update_gpu_image(); - ImGui::Text("Histogram"); - - vec2f canvas_size = ImGui::GetContentRegionAvail(); - // Note: If you're not using OpenGL for rendering your UI, the setup for - // displaying the colormap texture in the UI will need to be updated. - ImGui::Image(reinterpret_cast(colormap_img), ImVec2(canvas_size.x, 16)); - vec2f canvas_pos = ImGui::GetCursorScreenPos(); - canvas_size.y -= 80; - - const float point_radius = 20.f; - - ImDrawList* draw_list = ImGui::GetWindowDrawList(); - draw_list->PushClipRect(canvas_pos, canvas_pos + canvas_size); + const ImGuiIO &io = ImGui::GetIO(); - const vec2f view_scale(canvas_size.x, -canvas_size.y); - const vec2f view_offset(canvas_pos.x, canvas_pos.y + canvas_size.y); + ImGui::Text("Histogram"); - draw_list->AddRect(canvas_pos, canvas_pos + canvas_size, ImColor(180, 180, 180, 255)); + vec2f canvas_size = ImGui::GetContentRegionAvail(); + // Note: If you're not using OpenGL for rendering your UI, the setup for + // displaying the colormap texture in the UI will need to be updated. + ImGui::Image(reinterpret_cast(colormap_img), ImVec2(canvas_size.x, 16)); + vec2f canvas_pos = ImGui::GetCursorScreenPos(); + canvas_size.y -= 80; - //ImGui::InvisibleButton("tfn_canvas", canvas_size); - + const float point_radius = 20.f; - // Draw the alpha control points, and build the points for the polyline - // which connects them - + ImDrawList *draw_list = ImGui::GetWindowDrawList(); + draw_list->PushClipRect(canvas_pos, canvas_pos + canvas_size); - //Code to Draw histogram in the UI - for (int i = 0; i < current_histogram.size(); i++) { - vec2f lp = vec2f(((float)i) / current_histogram.size(), 0.0f); - vec2f hp = vec2f(((float)i + 1.0f) / current_histogram.size(), current_histogram[i]); - draw_list->AddRectFilled(lp * view_scale + view_offset, hp * view_scale + view_offset, 0x77777777); - } + const vec2f view_scale(canvas_size.x, -canvas_size.y); + const vec2f view_offset(canvas_pos.x, canvas_pos.y + canvas_size.y); + draw_list->AddRect(canvas_pos, canvas_pos + canvas_size, ImColor(180, 180, 180, 255)); - draw_list->PopClipRect(); + // ImGui::InvisibleButton("tfn_canvas", canvas_size); - + // Draw the alpha control points, and build the points for the polyline + // which connects them - + // Code to Draw histogram in the UI + for (int i = 0; i < current_histogram.size(); i++) + { + vec2f lp = vec2f(((float)i) / current_histogram.size(), 0.0f); + vec2f hp = vec2f(((float)i + 1.0f) / current_histogram.size(), current_histogram[i]); + draw_list->AddRectFilled(lp * view_scale + view_offset, hp * view_scale + view_offset, 0x77777777); + } - + draw_list->PopClipRect(); } void TransferFunctionWidget::update_gpu_image() @@ -472,7 +497,8 @@ void TransferFunctionWidget::update_gpu_image() GLint prev_tex_2d = 0; glGetIntegerv(GL_TEXTURE_BINDING_2D, &prev_tex_2d); - if (colormap_img == (GLuint)-1) { + if (colormap_img == (GLuint)-1) + { glGenTextures(1, &colormap_img); glBindTexture(GL_TEXTURE_2D, colormap_img); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -480,7 +506,8 @@ void TransferFunctionWidget::update_gpu_image() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } - if (colormap_changed) { + if (colormap_changed) + { glBindTexture(GL_TEXTURE_2D, colormap_img); glTexImage2D(GL_TEXTURE_2D, 0, @@ -492,7 +519,8 @@ void TransferFunctionWidget::update_gpu_image() GL_UNSIGNED_BYTE, current_colormap.data()); } - if (prev_tex_2d != 0) { + if (prev_tex_2d != 0) + { glBindTexture(GL_TEXTURE_2D, prev_tex_2d); } } @@ -506,16 +534,18 @@ void TransferFunctionWidget::update_colormap() auto a_it = alpha_control_pts.begin(); const size_t npixels = current_colormap.size() / 4; - for (size_t i = 0; i < npixels; ++i) { + for (size_t i = 0; i < npixels; ++i) + { float x = static_cast(i) / npixels; auto high = a_it + 1; - if (x > high->x) { + if (x > high->x) + { ++a_it; ++high; } float t = (x - a_it->x) / (high->x - a_it->x); float alpha = (1.f - t) * a_it->y + t * high->y; - current_colormap[i * 4 + 3] = static_cast(clamp(alpha * 255.f, 0.f, 255.f)); + current_colormap[i * 4 + 3] = static_cast(clamp(alpha * 255.f, 0.f, 255.f)); } } @@ -529,4 +559,3 @@ void TransferFunctionWidget::load_embedded_preset(const uint8_t *buf, stbi_image_free(img_data); colormaps.emplace_back(name, img); } - diff --git a/src/interaction/ArcBallCamera.cpp b/src/interaction/ArcBallCamera.cpp index ee818d5..b623cb2 100644 --- a/src/interaction/ArcBallCamera.cpp +++ b/src/interaction/ArcBallCamera.cpp @@ -12,7 +12,7 @@ // See license.txt for further information. // // BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE WHICH IS -// PROVIDED �AS IS�, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// PROVIDED "AS IS", INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR ANY // SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR FOR ANY DAMAGES WHATSOEVER RESULTING // FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index 58c8b11..ad6762a 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -399,13 +399,6 @@ void VRVolumeApp::set_character_state(std::string &eventName, int state) m_ui_view->add_character(keyStr[0]); } } - /* if (std::isalpha(keyStr[0], loc) || isdigit(keyStr[0])) - { - if (m_ui_view) - { - m_ui_view->set_chracter(keyStr[0]); - } - }*/ } else { @@ -414,13 +407,10 @@ void VRVolumeApp::set_character_state(std::string &eventName, int state) if (keyStr == "Backspace" || keyStr == "Del") { m_ui_view->remove_character(); - //_keyBoardInputText->deleteCharacters(_keyBoardInputText->getTextSize() - 1, 1); } else if (keyStr == "Space") { m_ui_view->add_character(32); - /*std::string space(" "); - addTextToInputField(space);*/ } } } @@ -595,11 +585,6 @@ void VRVolumeApp::render(const MinVR::VRGraphicsState &render_state) m_mesh_model->setMVMatrix(volume_mv); m_models_MV[i] = volume_mv; - - /*Original transformations of the model - DO NOT REMOVE YET*/ - // mesh_model->setPosition(glm::vec3(-0.5f, -0.5f, - // -0.5f * m_volumes[m_models_volumeID[i]]->get_volume_scale().x / (m_volumes[m_models_volumeID[i]]->get_volume_scale().z))); - // mesh_model->setScale(glm::vec3(m_volumes[m_models_volumeID[i]]->get_volume_scale().x, m_volumes[m_models_volumeID[i]]->get_volume_scale().y, m_volumes[m_models_volumeID[i]]->get_volume_scale().x)); } } @@ -696,18 +681,6 @@ void VRVolumeApp::render_labels(glm::mat4 &volume_mv, const MinVR::VRGraphicsSta void VRVolumeApp::render_mesh(const MinVR::VRGraphicsState &renderState) { - /*Original render Mesh using Fixed pipeline - DO NOT REMOVE YET*/ - // Render meshes - /*for (int i = 0; i < m_models_displayLists.size(); i++) { - if (m_volumes.size() > m_models_volumeID[i]) { - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadMatrixf(glm::value_ptr(m_models_MV[i])); - glColor3f(1.0f, 1.0f, 1.0f); - glCallList(m_models_displayLists[i]); - glPopMatrix(); - } - }*/ if (m_mesh_model) { m_simple_texture_shader.start(); diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index 7f3378e..b67164d 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -45,7 +45,6 @@ VolumeVisualizationApp::VolumeVisualizationApp(int argc, char **argv) : VRApp(ar if (std::string(argv_int[i]) == std::string("use2DUI")) { - m_vrVolumeApp->set_is_2D(true); } if (std::string(argv_int[i]) == std::string("useHolo")) @@ -127,7 +126,6 @@ void VolumeVisualizationApp::onAnalogChange(const VRAnalogEvent &event) m_vrVolumeApp->update_ui_events(event.getValue()); if (event.getName() == "MouseWheel_Spin") { - std::cerr << event.getValue() << std::endl; m_vrVolumeApp->update_ui_events(event.getValue() * 10); } } From 621bf99f438878c3841651dc52a0624ea6f4d476 Mon Sep 17 00:00:00 2001 From: Kmilo9999 Date: Tue, 10 May 2022 12:04:19 -0400 Subject: [PATCH 23/23] remove commeted code. --- include/UI/UIView.h | 2 +- libs/UIHelpers/transfer_function_widget.cpp | 2 +- src/UI/UIView.cpp | 7 +++---- src/vrapp/VRVolumeApp.cpp | 3 +-- src/vrapp/VolumeVisualizationApp.cpp | 6 +++--- superbuild/CMakeLists.txt | 3 --- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/UI/UIView.h b/include/UI/UIView.h index 405e54a..3051162 100644 --- a/include/UI/UIView.h +++ b/include/UI/UIView.h @@ -21,7 +21,7 @@ enum SAVE_MODAL { SAVE_NONE, SAVE_SESSION, - SAVE_TRFR_FNC + SAVE_TRANSFER_FUNCTION }; enum LOAD_MODAL { diff --git a/libs/UIHelpers/transfer_function_widget.cpp b/libs/UIHelpers/transfer_function_widget.cpp index e4ea24c..9c53f5c 100644 --- a/libs/UIHelpers/transfer_function_widget.cpp +++ b/libs/UIHelpers/transfer_function_widget.cpp @@ -462,7 +462,7 @@ void TransferFunctionWidget::draw_histogram() vec2f canvas_size = ImGui::GetContentRegionAvail(); // Note: If you're not using OpenGL for rendering your UI, the setup for // displaying the colormap texture in the UI will need to be updated. - // ImGui::Image(reinterpret_cast(colormap_img), ImVec2(canvas_size.x, 16)); + // TODO(#45) ImGui::Image(reinterpret_cast(colormap_img), ImVec2(canvas_size.x, 16)); vec2f canvas_pos = ImGui::GetCursorScreenPos(); canvas_size.y -= 250; diff --git a/src/UI/UIView.cpp b/src/UI/UIView.cpp index 8adc284..aea6f02 100644 --- a/src/UI/UIView.cpp +++ b/src/UI/UIView.cpp @@ -292,7 +292,7 @@ void UIView::draw_ui_callback() if (m_save_transfer_function_open) { - m_current_save_modal = SAVE_TRFR_FNC; + m_current_save_modal = SAVE_TRANSFER_FUNCTION; std::string save_Trnf_window_id = "Save Transfer Functions"; if (m_use_transferfunction) { @@ -813,7 +813,7 @@ void UIView::draw_ui_callback() case SAVE_SESSION: m_save_session_dialog_open = false; break; - case SAVE_TRFR_FNC: + case SAVE_TRANSFER_FUNCTION: m_save_transfer_function_open = false; break; default: @@ -835,7 +835,7 @@ void UIView::draw_ui_callback() case SAVE_SESSION: m_save_session_dialog_open = true; break; - case SAVE_TRFR_FNC: + case SAVE_TRANSFER_FUNCTION: m_save_transfer_function_open = true; break; default: @@ -1031,7 +1031,6 @@ int UIView::get_num_transfer_functions() bool UIView::is_transfer_function_enabled(int tfn, int vol) { - // return m_selected_volume_TrFn[tfn][vol]; return m_tfns[tfn].volumes[vol]; } diff --git a/src/vrapp/VRVolumeApp.cpp b/src/vrapp/VRVolumeApp.cpp index ad6762a..5a7559f 100644 --- a/src/vrapp/VRVolumeApp.cpp +++ b/src/vrapp/VRVolumeApp.cpp @@ -303,8 +303,7 @@ void VRVolumeApp::set_description(int descriptionHeight, std::string &descriptio { m_descriptionHeight = descriptionHeight; m_descriptionFilename = descriptionFilename; - m_description = LoadDescriptionAction(m_descriptionFilename).run(); - // std::cerr << m_description[0] << std::endl; + m_description = LoadDescriptionAction(m_descriptionFilename).run(); } void VRVolumeApp::set_mesh(int volumeId, std::string &fileName, std::string &shaderFilePath) diff --git a/src/vrapp/VolumeVisualizationApp.cpp b/src/vrapp/VolumeVisualizationApp.cpp index b67164d..365c008 100644 --- a/src/vrapp/VolumeVisualizationApp.cpp +++ b/src/vrapp/VolumeVisualizationApp.cpp @@ -63,9 +63,9 @@ VolumeVisualizationApp::VolumeVisualizationApp(int argc, char **argv) : VRApp(ar else if (helper::ends_with_string(std::string(argv_int[i]), ".nrrd")) { - NRRD LOADING - std::vector - vals; + // NRRD LOADING + std::vector + vals; vals.push_back(std::string(argv_int[i])); std::vector *> v; std::promise *pm = new std::promise(); diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index 8dbb2a5..5e1f566 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -110,7 +110,6 @@ endif (WIN32) #Choreograph # Configure external project -#IF(NOT EXISTS ${CMAKE_SOURCE_DIR}/Choreograph/Choreograph) execute_process( COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} @@ -129,8 +128,6 @@ execute_process( COMMAND ${CMAKE_COMMAND} ) -#ENDIF() - find_package(Choreograph REQUIRED) if(Choreograph_FOUND) message(STATUS "Choreograph found")