Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SofaImGui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ set(HEADER_FILES
${SOFAIMGUI_SOURCE_DIR}/ImGuiGUI.h
${SOFAIMGUI_SOURCE_DIR}/ImGuiGUIEngine.h
${SOFAIMGUI_SOURCE_DIR}/UIStrings.h
${SOFAIMGUI_SOURCE_DIR}/widgets/BoundingBoxWidget.h
${SOFAIMGUI_SOURCE_DIR}/widgets/DisplayFlagsWidget.h
${SOFAIMGUI_SOURCE_DIR}/widgets/LinearSpringWidget.h
${SOFAIMGUI_SOURCE_DIR}/widgets/MaterialWidget.h
Expand Down
13 changes: 13 additions & 0 deletions SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <SofaImGui/widgets/MaterialWidget.h>
#include <SofaImGui/widgets/RigidMass.h>
#include <SofaImGui/widgets/VecVectorWidget.h>
#include <SofaImGui/widgets/BoundingBoxWidget.h>

namespace sofaimgui
{
Expand Down Expand Up @@ -659,6 +660,16 @@ void DataWidget<sofa::type::vector<sofa::defaulttype::Rigid2Mass>>::showWidget(M
showRigidMasses(data);
}

/***********************************************************************************************************************
* Bounding Box
**********************************************************************************************************************/

template<>
void DataWidget<sofa::type::BoundingBox>::showWidget(MyData& data)
{
showBoundingBoxWidget(data);
}

/***********************************************************************************************************************
* Factory
**********************************************************************************************************************/
Expand Down Expand Up @@ -750,4 +761,6 @@ const bool dw_rigid2mass = DataWidgetFactory::Add<sofa::defaulttype::Rigid2Mass>
const bool dw_vector_rigid2mass = DataWidgetFactory::Add<sofa::type::vector<sofa::defaulttype::Rigid2Mass>>();
const bool dw_rigid3mass = DataWidgetFactory::Add<sofa::defaulttype::Rigid3Mass>();
const bool dw_vector_rigid3mass = DataWidgetFactory::Add<sofa::type::vector<sofa::defaulttype::Rigid3Mass>>();

const bool dw_boundingbox = DataWidgetFactory::Add<sofa::type::BoundingBox>();
}
63 changes: 63 additions & 0 deletions SofaImGui/src/SofaImGui/widgets/BoundingBoxWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; either version 2 of the License, or (at your option) *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once
#include <imgui.h>
#include <sofa/core/objectmodel/Data.h>
#include <sofa/type/BoundingBox.h>

namespace sofaimgui
{

inline void showBoundingBoxWidget(sofa::Data<sofa::type::BoundingBox>& data)
{
const auto box = data.getValue();

static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX;

if (ImGui::BeginTable("bbox_table", 4, flags))
{
ImGui::TableSetupColumn("");
ImGui::TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Z", ImGuiTableColumnFlags_WidthStretch);

ImGui::TableHeadersRow();

// Second row: ["min", min.x, min.y, min.z]
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::Text("min");
ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", box.minBBox().x());
ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", box.minBBox().y());
ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", box.minBBox().z());

// Third row: ["max", max.x, max.y, max.z]
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::Text("max");
ImGui::TableSetColumnIndex(1); ImGui::Text("%.2f", box.maxBBox().x());
ImGui::TableSetColumnIndex(2); ImGui::Text("%.2f", box.maxBBox().y());
ImGui::TableSetColumnIndex(3); ImGui::Text("%.2f", box.maxBBox().z());

ImGui::EndTable();
}
}

}
Loading