Skip to content

Commit ac1029e

Browse files
authored
Minimal support of RigidMass widget (sofa-framework#223)
1 parent 9c846be commit ac1029e

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

SofaImGui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ set(HEADER_FILES
106106
${SOFAIMGUI_SOURCE_DIR}/widgets/DisplayFlagsWidget.h
107107
${SOFAIMGUI_SOURCE_DIR}/widgets/LinearSpringWidget.h
108108
${SOFAIMGUI_SOURCE_DIR}/widgets/MaterialWidget.h
109+
${SOFAIMGUI_SOURCE_DIR}/widgets/RigidMass.h
109110
${SOFAIMGUI_SOURCE_DIR}/widgets/ScalarWidget.h
110111
${SOFAIMGUI_SOURCE_DIR}/windows/Performances.h
111112
${SOFAIMGUI_SOURCE_DIR}/windows/Log.h

SofaImGui/src/SofaImGui/ImGuiDataWidget.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <SofaImGui/widgets/DisplayFlagsWidget.h>
3131
#include <SofaImGui/widgets/LinearSpringWidget.h>
3232
#include <SofaImGui/widgets/MaterialWidget.h>
33+
#include <SofaImGui/widgets/RigidMass.h>
3334

3435
namespace sofaimgui
3536
{
@@ -722,6 +723,36 @@ void DataWidget<sofa::type::vector<sofa::type::Material>>::showWidget(MyData& da
722723
showMaterialListWidget(data);
723724
}
724725

726+
/***********************************************************************************************************************
727+
* RigidMass
728+
**********************************************************************************************************************/
729+
730+
template<>
731+
void DataWidget<sofa::defaulttype::Rigid3Mass>::showWidget(MyData& data)
732+
{
733+
const auto& rigidMass = data.getValue();
734+
showRigidMass(rigidMass);
735+
}
736+
737+
template<>
738+
void DataWidget<sofa::defaulttype::Rigid2Mass>::showWidget(MyData& data)
739+
{
740+
const auto& rigidMass = data.getValue();
741+
showRigidMass(rigidMass);
742+
}
743+
744+
template<>
745+
void DataWidget<sofa::type::vector<sofa::defaulttype::Rigid3Mass>>::showWidget(MyData& data)
746+
{
747+
showRigidMasses(data);
748+
}
749+
750+
template<>
751+
void DataWidget<sofa::type::vector<sofa::defaulttype::Rigid2Mass>>::showWidget(MyData& data)
752+
{
753+
showRigidMasses(data);
754+
}
755+
725756
/***********************************************************************************************************************
726757
* Factory
727758
**********************************************************************************************************************/
@@ -808,4 +839,9 @@ const bool dw_springvecf = DataWidgetFactory::Add<sofa::type::vector<sofa::compo
808839

809840
const bool dw_material = DataWidgetFactory::Add<sofa::type::Material>();
810841
const bool dw_vector_material = DataWidgetFactory::Add<sofa::type::vector<sofa::type::Material>>();
842+
843+
const bool dw_rigid2mass = DataWidgetFactory::Add<sofa::defaulttype::Rigid2Mass>();
844+
const bool dw_vector_rigid2mass = DataWidgetFactory::Add<sofa::type::vector<sofa::defaulttype::Rigid2Mass>>();
845+
const bool dw_rigid3mass = DataWidgetFactory::Add<sofa::defaulttype::Rigid3Mass>();
846+
const bool dw_vector_rigid3mass = DataWidgetFactory::Add<sofa::type::vector<sofa::defaulttype::Rigid3Mass>>();
811847
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 <sofa/core/objectmodel/Data.h>
24+
#include <imgui.h>
25+
26+
namespace sofaimgui
27+
{
28+
29+
template<sofa::Size N, typename real>
30+
inline void showRigidMass(const sofa::defaulttype::RigidMass<N,real>& rigidMass)
31+
{
32+
ImGui::Text("Mass: %f", rigidMass.mass);
33+
ImGui::Text("Volume: %f", rigidMass.volume);
34+
35+
std::stringstream ss;
36+
ss << rigidMass.inertiaMatrix;
37+
ImGui::Text("Inertia Matrix: %s", ss.str().c_str());
38+
}
39+
40+
template<sofa::Size N, typename real>
41+
inline void showRigidMasses(const sofa::Data<sofa::type::vector<sofa::defaulttype::RigidMass<N, real>>>& data)
42+
{
43+
static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_NoHostExtendX;
44+
ImGui::Text("%d elements", data.getValue().size());
45+
if (ImGui::BeginTable((data.getName() + data.getOwner()->getPathName()).c_str(), 4, flags))
46+
{
47+
ImGui::TableSetupColumn("");
48+
ImGui::TableSetupColumn("Mass");
49+
ImGui::TableSetupColumn("Volume");
50+
ImGui::TableSetupColumn("Inertia Matrix");
51+
52+
ImGui::TableHeadersRow();
53+
54+
unsigned int counter {};
55+
for (const auto& rigidMass : *sofa::helper::getReadAccessor(data))
56+
{
57+
ImGui::TableNextRow();
58+
ImGui::TableNextColumn();
59+
ImGui::Text("%d", counter++);
60+
ImGui::TableNextColumn();
61+
ImGui::Text("%f", rigidMass.mass);
62+
ImGui::TableNextColumn();
63+
ImGui::Text("%f", rigidMass.volume);
64+
65+
ImGui::TableNextColumn();
66+
std::stringstream ss;
67+
ss << rigidMass.inertiaMatrix;
68+
ImGui::Text("Inertia Matrix: %s", ss.str().c_str());
69+
}
70+
ImGui::EndTable();
71+
}
72+
}
73+
74+
}

0 commit comments

Comments
 (0)