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