Skip to content

Commit

Permalink
viewer: add option to crop scene to bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcseacave committed Dec 7, 2023
1 parent 6449134 commit 496c4a9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions apps/Viewer/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ bool Scene::Open(LPCTSTR fileName, LPCTSTR geometryFileName)
window.clbkCompilePointCloud = DELEGATEBINDCLASS(Window::ClbkCompilePointCloud, &Scene::CompilePointCloud, this);
window.clbkCompileMesh = DELEGATEBINDCLASS(Window::ClbkCompileMesh, &Scene::CompileMesh, this);
window.clbkTogleSceneBox = DELEGATEBINDCLASS(Window::ClbkTogleSceneBox, &Scene::TogleSceneBox, this);
window.clbkCropToBounds = DELEGATEBINDCLASS(Window::ClbkCropToBounds, &Scene::CropToBounds, this);
if (scene.IsBounded())
window.clbkCompileBounds = DELEGATEBINDCLASS(Window::ClbkCompileBounds, &Scene::CompileBounds, this);
if (!scene.IsEmpty())
Expand Down Expand Up @@ -511,6 +512,17 @@ void Scene::CompileBounds()
}
}

void Scene::CropToBounds()
{
if (!IsOpen())
return;
if (!scene.IsBounded())
return;
scene.pointcloud.RemovePointsOutside(scene.obb);
scene.mesh.RemoveFacesOutside(scene.obb);
Center();
}

void Scene::Draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Expand Down
1 change: 1 addition & 0 deletions apps/Viewer/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Scene
void CompilePointCloud();
void CompileMesh();
void CompileBounds();
void CropToBounds();

void Draw();
void Loop();
Expand Down
6 changes: 5 additions & 1 deletion apps/Viewer/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void Window::ReleaseClbk()
clbkCompileMesh.reset();
clbkCompileBounds.reset();
clbkTogleSceneBox.reset();
clbkCropToBounds.reset();
}

bool Window::Init(const cv::Size& _size, LPCTSTR name)
Expand Down Expand Up @@ -268,7 +269,10 @@ void Window::Key(int k, int /*scancode*/, int action, int mod)
break;
case GLFW_KEY_B:
if (action == GLFW_RELEASE) {
if (mod & GLFW_MOD_SHIFT) {
if (mod & GLFW_MOD_CONTROL) {
if (clbkCropToBounds != NULL)
clbkCropToBounds();
} else if (mod & GLFW_MOD_SHIFT) {
if (clbkTogleSceneBox != NULL)
clbkTogleSceneBox();
} else {
Expand Down
2 changes: 2 additions & 0 deletions apps/Viewer/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class Window
ClbkCompileBounds clbkCompileBounds;
typedef DELEGATE<void (void)> ClbkTogleSceneBox;
ClbkTogleSceneBox clbkTogleSceneBox;
typedef DELEGATE<void (void)> ClbkCropToBounds;
ClbkCropToBounds clbkCropToBounds;

typedef std::unordered_map<GLFWwindow*,Window*> WindowsMap;
static WindowsMap g_mapWindows;
Expand Down

0 comments on commit 496c4a9

Please sign in to comment.