Skip to content

Commit

Permalink
updated code organization, started working on opengl 3d visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
rxdu committed Nov 2, 2024
1 parent 318a070 commit c39c283
Show file tree
Hide file tree
Showing 38 changed files with 277 additions and 47 deletions.
Binary file added docs/opengl/opengl_coordinate_frames.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/opengl/orthographic_projection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/opengl/perspective_projection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/app/panels/main_docking_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ MainDockingPanel::MainDockingPanel(std::string name) : Panel(name) {
this->SetNoTitleBar(true);
this->SetNoBackground(true);

gl_scene_widget_.SetNoMove(true);
gl_scene_widget_.SetWindowNoTabBar();
gl_widget_.SetNoMove(true);
gl_widget_.SetWindowNoTabBar();
}

void MainDockingPanel::Draw() {
Expand All @@ -42,7 +42,7 @@ void MainDockingPanel::Draw() {

ImGui::DockBuilderDockWindow(config_panel_.GetName().c_str(),
config_panel_node_);
ImGui::DockBuilderDockWindow(gl_scene_widget_.GetName().c_str(),
ImGui::DockBuilderDockWindow(gl_widget_.GetName().c_str(),
gl_scene_widget_node_);
ImGui::DockBuilderDockWindow(console_panel_.GetName().c_str(),
console_panel_node_);
Expand All @@ -57,7 +57,7 @@ void MainDockingPanel::Draw() {
// draw child panels
if (config_panel_.IsVisible()) config_panel_.Draw();
if (console_panel_.IsVisible()) console_panel_.Draw();
if (gl_scene_widget_.IsVisible()) gl_scene_widget_.Draw();
if (gl_widget_.IsVisible()) gl_widget_.Draw();

End();
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/panels/main_docking_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class MainDockingPanel : public Panel {
void ChangeDebugPanelVisibility(bool visible);

private:

bool layout_initialized_ = false;
ImGuiID dockspace_id_;

Expand All @@ -37,7 +36,7 @@ class MainDockingPanel : public Panel {

ConfigPanel config_panel_{"Config"};
ConsolePanel console_panel_{"Console"};
GlSceneWidget gl_scene_widget_{"Scene"};
GlWidget gl_widget_{"Scene"};
};
} // namespace quickviz

Expand Down
10 changes: 6 additions & 4 deletions src/imview/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ add_library(imview
src/component/shader.cpp
src/component/shader_program.cpp
src/component/frame_buffer.cpp
# opengl primitives
src/primitive/grid.cpp
# data buffer
src/buffer/buffer_registry.cpp
src/buffer/scrolling_plot_buffer.cpp
src/component/buffer/buffer_registry.cpp
src/component/buffer/scrolling_plot_buffer.cpp
# event handling
src/event/event_dispatcher.cpp
src/event/async_event_dispatcher.cpp
src/component/event/event_dispatcher.cpp
src/component/event/async_event_dispatcher.cpp
)
target_link_libraries(imview PUBLIC imcore
PkgConfig::Cairo PkgConfig::Fontconfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <unordered_map>
#include <stdexcept>

#include "imview/buffer/buffer_interface.hpp"
#include "imview/component/buffer/buffer_interface.hpp"

namespace quickviz {
class BufferRegistry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <atomic>
#include <condition_variable>

#include "imview/buffer/buffer_interface.hpp"
#include "imview/component/buffer/buffer_interface.hpp"

namespace quickviz {
template <typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#include <vector>
#include <iostream>

#include "imview/buffer/buffer_interface.hpp"
#include "imview/component/buffer/buffer_interface.hpp"

namespace quickviz {
template <typename T = uint8_t, std::size_t N = 1024>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <queue>
#include <atomic>

#include "imview/event/event.hpp"
#include "imview/event/thread_safe_queue.hpp"
#include "imview/component/event/event.hpp"
#include "imview/component/event/thread_safe_queue.hpp"

namespace quickviz {
class AsyncEventDispatcher {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef QUICKVIZ_EVENT_ASYNC_EMITTER_HPP
#define QUICKVIZ_EVENT_ASYNC_EMITTER_HPP

#include "imview/event/async_event_dispatcher.hpp"
#include "imview/component/event/async_event_dispatcher.hpp"

namespace quickviz {
class AsyncEventEmitter {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <functional>
#include <unordered_map>

#include "imview/event/event.hpp"
#include "imview/component/event/event.hpp"

namespace quickviz {
class EventDispatcher {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef QUICKVIZ_EVENT_EMITTER_HPP
#define QUICKVIZ_EVENT_EMITTER_HPP

#include "imview/event/event_dispatcher.hpp"
#include "imview/component/event/event_dispatcher.hpp"

namespace quickviz {
class EventEmitter {
Expand Down
3 changes: 2 additions & 1 deletion src/imview/include/imview/component/shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Shader {
};

public:
Shader(const char* source_code, Type type);
Shader(const std::string& source_file, Type type);
~Shader();

Expand All @@ -36,7 +37,7 @@ class Shader {
uint32_t GetShaderID() const { return shader_id_; }

private:
std::string LoadSourceFile(const std::string& file_path);
void CreateShader();

std::string source_file_;
Type type_;
Expand Down
41 changes: 41 additions & 0 deletions src/imview/include/imview/primitive/grid.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* @file grid.hpp
* @date 11/2/24
* @brief
*
* @copyright Copyright (c) 2024 Ruixiang Du (rdu)
*/

#ifndef QUICKVIZ_GRID_HPP
#define QUICKVIZ_GRID_HPP

#include <glm/glm.hpp>

#include <vector>

#include "imview/component/shader_program.hpp"

namespace quickviz {
class Grid {
public:
Grid(float grid_size = 10.0f, float spacing = 1.0f,
glm::vec3 color = glm::vec3(0.5f, 0.5f, 0.5f));
~Grid();

void Initialize();
void Draw(const glm::mat4& projection, const glm::mat4& view);

private:
void GenerateGrid();

float grid_size_;
float spacing_;
glm::vec3 color_;
uint32_t vao_;
uint32_t vbo_;
std::vector<glm::vec3> vertices_;
ShaderProgram shader_;
};
} // namespace quickviz

#endif // QUICKVIZ_GRID_HPP
1 change: 1 addition & 0 deletions src/imview/include/imview/viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Viewer : public Window {
void Show();

protected:
void SetupOpenGL();
void ClearBackground();
void CreateNewImGuiFrame();
void RenderImGuiFrame();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <functional>

#include "imview/panel.hpp"
#include "imview/buffer/buffer_registry.hpp"
#include "imview/component/buffer/buffer_registry.hpp"

#include "glad/glad.h"

Expand Down
4 changes: 2 additions & 2 deletions src/imview/include/imview/widget/rt_line_plot_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <unordered_map>

#include "imview/panel.hpp"
#include "imview/buffer/buffer_registry.hpp"
#include "imview/buffer/scrolling_plot_buffer.hpp"
#include "imview/component/buffer/buffer_registry.hpp"
#include "imview/component/buffer/scrolling_plot_buffer.hpp"

namespace quickviz {
class RtLinePlotWidget : public Panel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <stdexcept>

#include "imview/buffer/buffer_registry.hpp"
#include "imview/component/buffer/buffer_registry.hpp"

namespace quickviz {
BufferRegistry& BufferRegistry::GetInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Copyright (c) 2021 Ruixiang Du (rdu)
*/

#include "imview/buffer/scrolling_plot_buffer.hpp"
#include "imview/component/buffer/scrolling_plot_buffer.hpp"

#include <cmath>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright Copyright (c) 2024 Ruixiang Du (rdu)
*/

#include "imview/event/async_event_dispatcher.hpp"
#include "imview/component/event/async_event_dispatcher.hpp"

namespace quickviz {
AsyncEventDispatcher& AsyncEventDispatcher::GetInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright Copyright (c) 2024 Ruixiang Du (rdu)
*/

#include "imview/event/event_dispatcher.hpp"
#include "imview/component/event/event_dispatcher.hpp"

namespace quickviz {
EventDispatcher& EventDispatcher::GetInstance() {
Expand Down
26 changes: 20 additions & 6 deletions src/imview/src/component/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,29 @@ std::string LoadShaderSource(const std::string& file_path) {
}
} // namespace

Shader::Shader(const char* source_code, Type type)
: source_code_(source_code), type_(type) {
if (source_code == nullptr) {
std::cout << "ERROR::SHADER::INVALID_SOURCE_CODE" << std::endl;
}
CreateShader();
}

Shader::Shader(const std::string& source_file, Shader::Type type)
: source_file_(source_file), type_(type) {
source_code_ = LoadShaderSource(source_file_);

CreateShader();
}

Shader::~Shader() { glDeleteShader(shader_id_); }

void Shader::CreateShader() {
if (source_code_.empty()) {
std::cout << "ERROR::SHADER::INVALID_SOURCE_FILE" << std::endl;
throw std::invalid_argument("Invalid shader source file");
}

if (type_ == Shader::Type::kVertex)
shader_id_ = glCreateShader(GL_VERTEX_SHADER);
else if (type_ == Shader::Type::kFragment)
Expand All @@ -43,8 +63,6 @@ Shader::Shader(const std::string& source_file, Shader::Type type)
glShaderSource(shader_id_, 1, &code, NULL);
}

Shader::~Shader() { glDeleteShader(shader_id_); }

void Shader::Print() const {
std::cout << "Shader source file: " << source_file_ << std::endl;
std::cout << "Shader type: " << static_cast<int>(type_) << std::endl;
Expand All @@ -68,8 +86,4 @@ bool Shader::Compile() {
}
return success;
}

std::string Shader::LoadSourceFile(const std::string& file_path) {
return std::string();
}
} // namespace quickviz
Loading

0 comments on commit c39c283

Please sign in to comment.