|
| 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