diff --git a/src/OpenSimCreator/CMakeLists.txt b/src/OpenSimCreator/CMakeLists.txt index f65cc349ce..8806f8aafe 100644 --- a/src/OpenSimCreator/CMakeLists.txt +++ b/src/OpenSimCreator/CMakeLists.txt @@ -208,8 +208,8 @@ add_library(OpenSimCreator STATIC Graphics/OpenSimDecorationOptions.h Graphics/ModelRendererParams.cpp Graphics/ModelRendererParams.h - Graphics/MuscleColoringStyle.cpp - Graphics/MuscleColoringStyle.h + Graphics/MuscleColorSource.cpp + Graphics/MuscleColorSource.h Graphics/MuscleDecorationStyle.cpp Graphics/MuscleDecorationStyle.h Graphics/MuscleSizingStyle.cpp diff --git a/src/OpenSimCreator/Graphics/MuscleColorSource.cpp b/src/OpenSimCreator/Graphics/MuscleColorSource.cpp new file mode 100644 index 0000000000..bea3d3d7d5 --- /dev/null +++ b/src/OpenSimCreator/Graphics/MuscleColorSource.cpp @@ -0,0 +1,69 @@ +#include "MuscleColorSource.h" + +#include +#include + +#include +#include +#include + +using namespace osc; + +namespace +{ + constexpr auto c_Metadata = std::to_array( + { + MuscleColorSourceMetadata + { + "opensim_appearance", + "OpenSim (Appearance Property)", + MuscleColorSource::OpenSimAppearanceProperty, + }, + MuscleColorSourceMetadata + { + "opensim", + "OpenSim", + MuscleColorSource::OpenSim, + }, + MuscleColorSourceMetadata + { + "activation", + "Activation", + MuscleColorSource::Activation, + }, + MuscleColorSourceMetadata + { + "excitation", + "Excitation", + MuscleColorSource::Excitation, + }, + MuscleColorSourceMetadata + { + "force", + "Force", + MuscleColorSource::Force, + }, + MuscleColorSourceMetadata + { + "fiber_length", + "Fiber Length", + MuscleColorSource::FiberLength, + }, + }); + static_assert(c_Metadata.size() == num_options()); +} + +std::span osc::GetAllPossibleMuscleColoringSourcesMetadata() +{ + return c_Metadata; +} + +const MuscleColorSourceMetadata& osc::GetMuscleColoringStyleMetadata(MuscleColorSource s) +{ + return GetAllPossibleMuscleColoringSourcesMetadata()[GetIndexOf(s)]; +} + +ptrdiff_t osc::GetIndexOf(MuscleColorSource s) +{ + return static_cast(s); +} diff --git a/src/OpenSimCreator/Graphics/MuscleColoringStyle.h b/src/OpenSimCreator/Graphics/MuscleColorSource.h similarity index 50% rename from src/OpenSimCreator/Graphics/MuscleColoringStyle.h rename to src/OpenSimCreator/Graphics/MuscleColorSource.h index 8c2dc054d5..da29c5ad99 100644 --- a/src/OpenSimCreator/Graphics/MuscleColoringStyle.h +++ b/src/OpenSimCreator/Graphics/MuscleColorSource.h @@ -7,7 +7,7 @@ namespace osc { - enum class MuscleColoringStyle { + enum class MuscleColorSource { OpenSimAppearanceProperty, OpenSim, Activation, @@ -19,12 +19,12 @@ namespace osc Default = OpenSim, }; - struct MuscleColoringStyleMetadata final { + struct MuscleColorSourceMetadata final { CStringView id; CStringView label; - MuscleColoringStyle value; + MuscleColorSource value; }; - std::span GetAllMuscleColoringStyleMetadata(); - const MuscleColoringStyleMetadata& GetMuscleColoringStyleMetadata(MuscleColoringStyle); - ptrdiff_t GetIndexOf(MuscleColoringStyle); + std::span GetAllPossibleMuscleColoringSourcesMetadata(); + const MuscleColorSourceMetadata& GetMuscleColoringStyleMetadata(MuscleColorSource); + ptrdiff_t GetIndexOf(MuscleColorSource); } diff --git a/src/OpenSimCreator/Graphics/MuscleColoringStyle.cpp b/src/OpenSimCreator/Graphics/MuscleColoringStyle.cpp deleted file mode 100644 index 8292beff03..0000000000 --- a/src/OpenSimCreator/Graphics/MuscleColoringStyle.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "MuscleColoringStyle.h" - -#include -#include - -#include -#include -#include - -using namespace osc; - -namespace -{ - constexpr auto c_Metadata = std::to_array( - { - MuscleColoringStyleMetadata - { - "opensim_appearance", - "OpenSim (Appearance Property)", - MuscleColoringStyle::OpenSimAppearanceProperty, - }, - MuscleColoringStyleMetadata - { - "opensim", - "OpenSim", - MuscleColoringStyle::OpenSim, - }, - MuscleColoringStyleMetadata - { - "activation", - "Activation", - MuscleColoringStyle::Activation, - }, - MuscleColoringStyleMetadata - { - "excitation", - "Excitation", - MuscleColoringStyle::Excitation, - }, - MuscleColoringStyleMetadata - { - "force", - "Force", - MuscleColoringStyle::Force, - }, - MuscleColoringStyleMetadata - { - "fiber_length", - "Fiber Length", - MuscleColoringStyle::FiberLength, - }, - }); - static_assert(c_Metadata.size() == num_options()); -} - -std::span osc::GetAllMuscleColoringStyleMetadata() -{ - return c_Metadata; -} - -const MuscleColoringStyleMetadata& osc::GetMuscleColoringStyleMetadata(MuscleColoringStyle s) -{ - return GetAllMuscleColoringStyleMetadata()[GetIndexOf(s)]; -} - -ptrdiff_t osc::GetIndexOf(MuscleColoringStyle s) -{ - return static_cast(s); -} diff --git a/src/OpenSimCreator/Graphics/OpenSimDecorationGenerator.cpp b/src/OpenSimCreator/Graphics/OpenSimDecorationGenerator.cpp index 1b24ff957e..01ab453485 100644 --- a/src/OpenSimCreator/Graphics/OpenSimDecorationGenerator.cpp +++ b/src/OpenSimCreator/Graphics/OpenSimDecorationGenerator.cpp @@ -83,16 +83,16 @@ namespace float GetMuscleColorFactor( const OpenSim::Muscle& musc, const SimTK::State& st, - MuscleColoringStyle s) + MuscleColorSource s) { switch (s) { - case MuscleColoringStyle::Activation: + case MuscleColorSource::Activation: return static_cast(musc.getActivation(st)); - case MuscleColoringStyle::Excitation: + case MuscleColorSource::Excitation: return static_cast(musc.getExcitation(st)); - case MuscleColoringStyle::Force: + case MuscleColorSource::Force: return static_cast(musc.getActuation(st)) / static_cast(musc.getMaxIsometricForce()); - case MuscleColoringStyle::FiberLength: + case MuscleColorSource::FiberLength: { const auto nfl = static_cast(musc.getNormalizedFiberLength(st)); // 1.0f == ideal length float fl = nfl - 1.0f; @@ -120,7 +120,7 @@ namespace Color CalcOSCMuscleColor( const OpenSim::Muscle& musc, const SimTK::State& st, - MuscleColoringStyle s) + MuscleColorSource s) { const Color zeroColor = {50.0f / 255.0f, 50.0f / 255.0f, 166.0f / 255.0f, 1.0f}; const Color fullColor = {255.0f / 255.0f, 25.0f / 255.0f, 25.0f / 255.0f, 1.0f}; @@ -134,12 +134,12 @@ namespace Color GetMuscleColor( const OpenSim::Muscle& musc, const SimTK::State& st, - MuscleColoringStyle s) + MuscleColorSource s) { switch (s) { - case MuscleColoringStyle::OpenSimAppearanceProperty: + case MuscleColorSource::OpenSimAppearanceProperty: return GetGeometryPathDefaultColor(musc.getGeometryPath()); - case MuscleColoringStyle::OpenSim: + case MuscleColorSource::OpenSim: return GetGeometryPathColor(musc.getGeometryPath(), st); default: return CalcOSCMuscleColor(musc, st, s); @@ -710,7 +710,7 @@ namespace const Color fiberColor = GetMuscleColor( muscle, rs.getState(), - rs.getOptions().getMuscleColoringStyle() + rs.getOptions().getMuscleColorSource() ); const Color tendonColor = {204.0f/255.0f, 203.0f/255.0f, 200.0f/255.0f}; @@ -967,7 +967,7 @@ namespace const Color color = GetMuscleColor( musc, rs.getState(), - rs.getOptions().getMuscleColoringStyle() + rs.getOptions().getMuscleColorSource() ); EmitPointBasedLine(rs, musc, points, radius, color); diff --git a/src/OpenSimCreator/Graphics/OpenSimDecorationOptions.cpp b/src/OpenSimCreator/Graphics/OpenSimDecorationOptions.cpp index 6718af8629..626f293ff4 100644 --- a/src/OpenSimCreator/Graphics/OpenSimDecorationOptions.cpp +++ b/src/OpenSimCreator/Graphics/OpenSimDecorationOptions.cpp @@ -15,7 +15,7 @@ namespace rgs = std::ranges; osc::OpenSimDecorationOptions::OpenSimDecorationOptions() : m_MuscleDecorationStyle{MuscleDecorationStyle::Default}, - m_MuscleColoringStyle{MuscleColoringStyle::Default}, + m_MuscleColorSource{MuscleColorSource::Default}, m_MuscleSizingStyle{MuscleSizingStyle::Default}, m_Flags{OpenSimDecorationOptionFlags::Default} {} @@ -30,14 +30,14 @@ void osc::OpenSimDecorationOptions::setMuscleDecorationStyle(MuscleDecorationSty m_MuscleDecorationStyle = s; } -MuscleColoringStyle osc::OpenSimDecorationOptions::getMuscleColoringStyle() const +MuscleColorSource osc::OpenSimDecorationOptions::getMuscleColorSource() const { - return m_MuscleColoringStyle; + return m_MuscleColorSource; } -void osc::OpenSimDecorationOptions::setMuscleColoringStyle(MuscleColoringStyle s) +void osc::OpenSimDecorationOptions::setMuscleColorSource(MuscleColorSource s) { - m_MuscleColoringStyle = s; + m_MuscleColorSource = s; } MuscleSizingStyle osc::OpenSimDecorationOptions::getMuscleSizingStyle() const @@ -188,7 +188,7 @@ void osc::OpenSimDecorationOptions::setShouldShowPointForces(bool v) void osc::OpenSimDecorationOptions::forEachOptionAsAppSettingValue(const std::function& callback) const { callback("muscle_decoration_style", GetMuscleDecorationStyleMetadata(m_MuscleDecorationStyle).id); - callback("muscle_coloring_style", GetMuscleColoringStyleMetadata(m_MuscleColoringStyle).id); + callback("muscle_coloring_style", GetMuscleColoringStyleMetadata(m_MuscleColorSource).id); callback("muscle_sizing_style", GetMuscleSizingStyleMetadata(m_MuscleSizingStyle).id); for (size_t i = 0; i < num_flags(); ++i) { const auto& meta = GetIthOptionMetadata(i); @@ -223,10 +223,10 @@ void osc::OpenSimDecorationOptions::tryUpdFromValues( if (auto* appVal = lookup("muscle_coloring_style"); appVal->type() == VariantType::String) { - const auto metadata = GetAllMuscleColoringStyleMetadata(); + const auto metadata = GetAllPossibleMuscleColoringSourcesMetadata(); const auto it = rgs::find(metadata, to(*appVal), [](const auto& m) { return m.id; }); if (it != metadata.end()) { - m_MuscleColoringStyle = it->value; + m_MuscleColorSource = it->value; } } diff --git a/src/OpenSimCreator/Graphics/OpenSimDecorationOptions.h b/src/OpenSimCreator/Graphics/OpenSimDecorationOptions.h index d60bb2994c..01b3cd6080 100644 --- a/src/OpenSimCreator/Graphics/OpenSimDecorationOptions.h +++ b/src/OpenSimCreator/Graphics/OpenSimDecorationOptions.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -26,8 +26,8 @@ namespace osc MuscleDecorationStyle getMuscleDecorationStyle() const; void setMuscleDecorationStyle(MuscleDecorationStyle); - MuscleColoringStyle getMuscleColoringStyle() const; - void setMuscleColoringStyle(MuscleColoringStyle); + MuscleColorSource getMuscleColorSource() const; + void setMuscleColorSource(MuscleColorSource); MuscleSizingStyle getMuscleSizingStyle() const; void setMuscleSizingStyle(MuscleSizingStyle); @@ -79,7 +79,7 @@ namespace osc private: MuscleDecorationStyle m_MuscleDecorationStyle; - MuscleColoringStyle m_MuscleColoringStyle; + MuscleColorSource m_MuscleColorSource; MuscleSizingStyle m_MuscleSizingStyle; OpenSimDecorationOptionFlags m_Flags; }; diff --git a/src/OpenSimCreator/UI/PreviewExperimentalData/PreviewExperimentalDataTab.cpp b/src/OpenSimCreator/UI/PreviewExperimentalData/PreviewExperimentalDataTab.cpp index d2b0a50441..e05f65986a 100644 --- a/src/OpenSimCreator/UI/PreviewExperimentalData/PreviewExperimentalDataTab.cpp +++ b/src/OpenSimCreator/UI/PreviewExperimentalData/PreviewExperimentalDataTab.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include diff --git a/src/OpenSimCreator/UI/Shared/BasicWidgets.cpp b/src/OpenSimCreator/UI/Shared/BasicWidgets.cpp index 5fe8c3fb08..c1d3ce6e59 100644 --- a/src/OpenSimCreator/UI/Shared/BasicWidgets.cpp +++ b/src/OpenSimCreator/UI/Shared/BasicWidgets.cpp @@ -949,15 +949,15 @@ bool osc::DrawMuscleSizingOptionsRadioButtons(OpenSimDecorationOptions& opts) return edited; } -bool osc::DrawMuscleColoringOptionsRadioButtons(OpenSimDecorationOptions& opts) +bool osc::DrawMuscleColorSourceOptionsRadioButtons(OpenSimDecorationOptions& opts) { - const MuscleColoringStyle currentStyle = opts.getMuscleColoringStyle(); + const MuscleColorSource currentStyle = opts.getMuscleColorSource(); bool edited = false; - for (const auto& metadata : GetAllMuscleColoringStyleMetadata()) + for (const auto& metadata : GetAllPossibleMuscleColoringSourcesMetadata()) { if (ui::draw_radio_button(metadata.label, metadata.value == currentStyle)) { - opts.setMuscleColoringStyle(metadata.value); + opts.setMuscleColorSource(metadata.value); edited = true; } } @@ -982,8 +982,8 @@ bool osc::DrawMuscleDecorationOptionsEditor(OpenSimDecorationOptions& opts) ui::draw_dummy({0.0f, 0.25f*ui::get_text_line_height()}); ui::push_id(id++); - ui::draw_text_disabled("Coloring"); - edited = DrawMuscleColoringOptionsRadioButtons(opts) || edited; + ui::draw_text_disabled("Color Source"); + edited = DrawMuscleColorSourceOptionsRadioButtons(opts) || edited; ui::pop_id(); return edited; diff --git a/src/OpenSimCreator/UI/Shared/BasicWidgets.h b/src/OpenSimCreator/UI/Shared/BasicWidgets.h index ceb30915a2..85d7552fdb 100644 --- a/src/OpenSimCreator/UI/Shared/BasicWidgets.h +++ b/src/OpenSimCreator/UI/Shared/BasicWidgets.h @@ -223,7 +223,7 @@ namespace osc // basic wigetized parts of the 3D viewer bool DrawMuscleRenderingOptionsRadioButtions(OpenSimDecorationOptions&); bool DrawMuscleSizingOptionsRadioButtons(OpenSimDecorationOptions&); - bool DrawMuscleColoringOptionsRadioButtons(OpenSimDecorationOptions&); + bool DrawMuscleColorSourceOptionsRadioButtons(OpenSimDecorationOptions&); bool DrawMuscleDecorationOptionsEditor(OpenSimDecorationOptions&); bool DrawRenderingOptionsEditor(CustomRenderingOptions&); bool DrawOverlayOptionsEditor(OverlayDecorationOptions&); diff --git a/tests/TestOpenSimCreator/Graphics/TestOpenSimDecorationGenerator.cpp b/tests/TestOpenSimCreator/Graphics/TestOpenSimDecorationGenerator.cpp index 1f50154a88..7931ca38e5 100644 --- a/tests/TestOpenSimCreator/Graphics/TestOpenSimDecorationGenerator.cpp +++ b/tests/TestOpenSimCreator/Graphics/TestOpenSimDecorationGenerator.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -38,7 +38,7 @@ TEST(OpenSimDecorationGenerator, GenerateDecorationsWithOpenSimMuscleColoringGen SimTK::State& state = model.initializeState(); OpenSimDecorationOptions opts; - opts.setMuscleColoringStyle(MuscleColoringStyle::OpenSimAppearanceProperty); + opts.setMuscleColorSource(MuscleColorSource::OpenSimAppearanceProperty); SceneCache meshCache; bool passedTest = false;