Skip to content

Commit 79e05a2

Browse files
committed
viewer: implement GPU-based picker
1 parent 797b59e commit 79e05a2

23 files changed

+548
-270
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ VERBOSE("Info: %s", str); // General logging
6363
6464
### Common Typedefs
6565
```cpp
66-
typedef uint32_t IDX; // Array indices
6766
typedef SEACAVE::Point3f Point3f; // 3D points
6867
typedef SEACAVE::String String; // String type
69-
#define NO_ID ((IDX)-1) // Invalid index
68+
#define NO_ID ((uint32_t)-1) // Invalid index
7069
```
7170
Most of OpenMVS code uses custom point and matrix types derived from OpenCV types, e.g., `SEACAVE::Point3f`, `SEACAVE::Matrix4f`. Hoewever, some components use Eigen3 types, e.g. `SEACAVE::AABB3d` and `SEACAVE::Ray3d` classes. There custom types support convertion operation to and from Eigen3 types.
7271

apps/Viewer/ArcballControls.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ void ArcballControls::panCamera(const Eigen::Vector2d& delta) {
241241
}
242242

243243
void ArcballControls::zoomCamera(double delta) {
244-
const double speed = MAXF(0.001, 0.15 * (camera.GetTarget() - camera.GetPosition()).norm() * zoomSensitivity);
244+
const double distance = MINF(camera.GetSceneDistance()*0.3, (camera.GetPosition() - camera.GetTarget()).norm());
245+
const double speed = MAXF(0.001, 0.15 * distance * zoomSensitivity);
245246
zoom(delta * speed);
246247
}
247248

apps/Viewer/BufferObjects.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,31 @@ void VBO::SetSubData(const void* data, size_t size, size_t offset) {
9292
GL_CHECK(glBufferSubData(target, offset, size, data));
9393
}
9494

95+
// Readback implementations
96+
template<typename T>
97+
void VBO::GetData(T* out, size_t count) {
98+
ASSERT(count > 0);
99+
Bind();
100+
GL_CHECK(glGetBufferSubData(target, 0, count * sizeof(T), out));
101+
}
102+
103+
template<typename T>
104+
void VBO::GetData(std::vector<T>& out) {
105+
GetData(out.data(), out.size());
106+
}
107+
108+
template<typename T>
109+
void VBO::GetSubData(T* out, size_t count, size_t offset) {
110+
Bind();
111+
GL_CHECK(glGetBufferSubData(target, offset * sizeof(T), count * sizeof(T), out));
112+
}
113+
114+
template<typename T>
115+
void VBO::GetSubData(std::vector<T>& out, size_t offset) {
116+
if (out.empty()) return;
117+
GetSubData(out.data(), out.size(), offset);
118+
}
119+
95120
// Explicit template instantiations
96121
template void VBO::SetData<float>(const std::vector<float>&, GLenum);
97122
template void VBO::SetData<uint32_t>(const std::vector<uint32_t>&, GLenum);
@@ -107,6 +132,21 @@ template void VBO::SetSubData<float>(const float*, size_t, size_t);
107132
template void VBO::SetSubData<uint32_t>(const uint32_t*, size_t, size_t);
108133
template void VBO::SetSubData<uint8_t>(const uint8_t*, size_t, size_t);
109134

135+
// Explicit template instantiations for readback
136+
template void VBO::GetData<float>(float*, size_t);
137+
template void VBO::GetData<uint32_t>(uint32_t*, size_t);
138+
template void VBO::GetData<uint8_t>(uint8_t*, size_t);
139+
template void VBO::GetData<float>(std::vector<float>&);
140+
template void VBO::GetData<uint32_t>(std::vector<uint32_t>&);
141+
template void VBO::GetData<uint8_t>(std::vector<uint8_t>&);
142+
143+
template void VBO::GetSubData<float>(float*, size_t, size_t);
144+
template void VBO::GetSubData<uint32_t>(uint32_t*, size_t, size_t);
145+
template void VBO::GetSubData<uint8_t>(uint8_t*, size_t, size_t);
146+
template void VBO::GetSubData<float>(std::vector<float>&, size_t);
147+
template void VBO::GetSubData<uint32_t>(std::vector<uint32_t>&, size_t);
148+
template void VBO::GetSubData<uint8_t>(std::vector<uint8_t>&, size_t);
149+
110150
// VAO Implementation
111151
VAO::VAO() {
112152
GL_CHECK(glGenVertexArrays(1, &id));

apps/Viewer/BufferObjects.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ class VBO {
8282

8383
void SetSubData(const void* data, size_t size, size_t offset);
8484

85+
// Read back buffer data
86+
template<typename T>
87+
void GetData(T* out, size_t count);
88+
89+
template<typename T>
90+
void GetData(std::vector<T>& out);
91+
92+
template<typename T>
93+
void GetSubData(T* out, size_t count, size_t offset);
94+
95+
template<typename T>
96+
void GetSubData(std::vector<T>& out, size_t offset);
97+
8598
GLuint GetID() const { return id; }
8699
};
87100

apps/Viewer/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ else()
4141
FILE(GLOB LIBRARY_FILES_C "*.cpp")
4242
endif()
4343
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")
44-
FILE(GLOB SHADERS_LIBRARY_FILES "Shaders/*.*")
44+
FILE(GLOB SHADERS_LIBRARY_FILES "shaders/*.*")
4545
SOURCE_GROUP("Shaders" FILES ${SHADERS_LIBRARY_FILES})
4646

47-
cxx_executable_with_flags(${VIEWER_NAME} "Apps" "${cxx_default}" "MVS;glad::glad;${GLFW_STATIC_LIBRARIES};${glfw3_LIBRARY};${GLFW3_LIBRARY};glfw;imgui::imgui" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
47+
cxx_executable_with_flags(${VIEWER_NAME} "Apps" "${cxx_default}" "MVS;glad::glad;${GLFW_STATIC_LIBRARIES};${glfw3_LIBRARY};${GLFW3_LIBRARY};glfw;imgui::imgui" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H} ${SHADERS_LIBRARY_FILES})
4848

4949
# Build the Viewer as a GUI application on platforms that support it so
5050
# launching from the desktop does not open or attach a console/terminal.

apps/Viewer/OpenGLDebug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ inline bool CheckOpenGLError(const char* function, const char* file, int line) {
116116
if (error == GL_NO_ERROR)
117117
return true; // No error, everything is fine
118118
DEBUG("OpenGL Error: %s (0x%X)\n Function: %s\n File: %s:%d", errorString.c_str(), error, function, file, line);
119+
ASSERT("OpenGL error detected!" == NULL);
119120
return false;
120121
}
121122

0 commit comments

Comments
 (0)