Skip to content

Commit 2905295

Browse files
alxbilgerhugtalbot
andauthored
Introduce widget for bounding box (#270)
Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
1 parent 729c21e commit 2905295

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

SofaImGui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ set(HEADER_FILES
9595
${SOFAIMGUI_SOURCE_DIR}/ImGuiGUI.h
9696
${SOFAIMGUI_SOURCE_DIR}/ImGuiGUIEngine.h
9797
${SOFAIMGUI_SOURCE_DIR}/UIStrings.h
98+
${SOFAIMGUI_SOURCE_DIR}/widgets/BoundingBoxWidget.h
9899
${SOFAIMGUI_SOURCE_DIR}/widgets/BoolWidget.h
99100
${SOFAIMGUI_SOURCE_DIR}/widgets/DisplayFlagsWidget.h
100101
${SOFAIMGUI_SOURCE_DIR}/widgets/LinearSpringWidget.h

SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <SofaImGui/widgets/MaterialWidget.h>
3333
#include <SofaImGui/widgets/RigidMass.h>
3434
#include <SofaImGui/widgets/VecVectorWidget.h>
35+
#include <SofaImGui/widgets/BoundingBoxWidget.h>
3536
#include <SofaImGui/widgets/BoolWidget.h>
3637

3738
namespace sofaimgui
@@ -651,6 +652,16 @@ void DataWidget<sofa::type::vector<sofa::defaulttype::Rigid2Mass>>::showWidget(M
651652
showRigidMasses(data);
652653
}
653654

655+
/***********************************************************************************************************************
656+
* Bounding Box
657+
**********************************************************************************************************************/
658+
659+
template<>
660+
void DataWidget<sofa::type::BoundingBox>::showWidget(MyData& data)
661+
{
662+
showBoundingBoxWidget(data);
663+
}
664+
654665
/***********************************************************************************************************************
655666
* Factory
656667
**********************************************************************************************************************/
@@ -742,4 +753,6 @@ const bool dw_rigid2mass = DataWidgetFactory::Add<sofa::defaulttype::Rigid2Mass>
742753
const bool dw_vector_rigid2mass = DataWidgetFactory::Add<sofa::type::vector<sofa::defaulttype::Rigid2Mass>>();
743754
const bool dw_rigid3mass = DataWidgetFactory::Add<sofa::defaulttype::Rigid3Mass>();
744755
const bool dw_vector_rigid3mass = DataWidgetFactory::Add<sofa::type::vector<sofa::defaulttype::Rigid3Mass>>();
756+
757+
const bool dw_boundingbox = DataWidgetFactory::Add<sofa::type::BoundingBox>();
745758
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU General Public License as published by the Free *
7+
* Software Foundation; either version 2 of the License, or (at your option) *
8+
* any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
13+
* more details. *
14+
* *
15+
* You should have received a copy of the GNU General Public License along *
16+
* with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Authors: The SOFA Team and external contributors (see Authors.txt) *
19+
* *
20+
* Contact information: contact@sofa-framework.org *
21+
******************************************************************************/
22+
#pragma once
23+
#include <imgui.h>
24+
#include <sofa/core/objectmodel/Data.h>
25+
#include <sofa/type/BoundingBox.h>
26+
27+
namespace sofaimgui
28+
{
29+
30+
inline void showBoundingBoxWidget(sofa::Data<sofa::type::BoundingBox>& data)
31+
{
32+
const auto box = data.getValue();
33+
34+
static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX;
35+
36+
if (ImGui::BeginTable("bbox_table", 4, flags))
37+
{
38+
ImGui::TableSetupColumn("");
39+
ImGui::TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch);
40+
ImGui::TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch);
41+
ImGui::TableSetupColumn("Z", ImGuiTableColumnFlags_WidthStretch);
42+
43+
ImGui::TableHeadersRow();
44+
45+
// Second row: ["min", min.x, min.y, min.z]
46+
ImGui::TableNextRow();
47+
ImGui::TableSetColumnIndex(0); ImGui::Text("min");
48+
ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", box.minBBox().x());
49+
ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", box.minBBox().y());
50+
ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", box.minBBox().z());
51+
52+
// Third row: ["max", max.x, max.y, max.z]
53+
ImGui::TableNextRow();
54+
ImGui::TableSetColumnIndex(0); ImGui::Text("max");
55+
ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", box.maxBBox().x());
56+
ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", box.maxBBox().y());
57+
ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", box.maxBBox().z());
58+
59+
ImGui::EndTable();
60+
}
61+
}
62+
63+
}

0 commit comments

Comments
 (0)