Skip to content

Commit

Permalink
Rename 'Coloring' to 'Color Source' for muscles (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Oct 28, 2024
1 parent 328b3ea commit 84dbcf3
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 110 deletions.
4 changes: 2 additions & 2 deletions src/OpenSimCreator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions src/OpenSimCreator/Graphics/MuscleColorSource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "MuscleColorSource.h"

#include <oscar/Utils/CStringView.h>
#include <oscar/Utils/EnumHelpers.h>

#include <array>
#include <cstddef>
#include <span>

using namespace osc;

namespace
{
constexpr auto c_Metadata = std::to_array<MuscleColorSourceMetadata>(
{
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<MuscleColorSource>());
}

std::span<const MuscleColorSourceMetadata> osc::GetAllPossibleMuscleColoringSourcesMetadata()
{
return c_Metadata;
}

const MuscleColorSourceMetadata& osc::GetMuscleColoringStyleMetadata(MuscleColorSource s)
{
return GetAllPossibleMuscleColoringSourcesMetadata()[GetIndexOf(s)];
}

ptrdiff_t osc::GetIndexOf(MuscleColorSource s)
{
return static_cast<ptrdiff_t>(s);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace osc
{
enum class MuscleColoringStyle {
enum class MuscleColorSource {
OpenSimAppearanceProperty,
OpenSim,
Activation,
Expand All @@ -19,12 +19,12 @@ namespace osc
Default = OpenSim,
};

struct MuscleColoringStyleMetadata final {
struct MuscleColorSourceMetadata final {
CStringView id;
CStringView label;
MuscleColoringStyle value;
MuscleColorSource value;
};
std::span<const MuscleColoringStyleMetadata> GetAllMuscleColoringStyleMetadata();
const MuscleColoringStyleMetadata& GetMuscleColoringStyleMetadata(MuscleColoringStyle);
ptrdiff_t GetIndexOf(MuscleColoringStyle);
std::span<const MuscleColorSourceMetadata> GetAllPossibleMuscleColoringSourcesMetadata();
const MuscleColorSourceMetadata& GetMuscleColoringStyleMetadata(MuscleColorSource);
ptrdiff_t GetIndexOf(MuscleColorSource);
}
69 changes: 0 additions & 69 deletions src/OpenSimCreator/Graphics/MuscleColoringStyle.cpp

This file was deleted.

22 changes: 11 additions & 11 deletions src/OpenSimCreator/Graphics/OpenSimDecorationGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(musc.getActivation(st));
case MuscleColoringStyle::Excitation:
case MuscleColorSource::Excitation:
return static_cast<float>(musc.getExcitation(st));
case MuscleColoringStyle::Force:
case MuscleColorSource::Force:
return static_cast<float>(musc.getActuation(st)) / static_cast<float>(musc.getMaxIsometricForce());
case MuscleColoringStyle::FiberLength:
case MuscleColorSource::FiberLength:
{
const auto nfl = static_cast<float>(musc.getNormalizedFiberLength(st)); // 1.0f == ideal length
float fl = nfl - 1.0f;
Expand Down Expand Up @@ -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};
Expand All @@ -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);
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -967,7 +967,7 @@ namespace
const Color color = GetMuscleColor(
musc,
rs.getState(),
rs.getOptions().getMuscleColoringStyle()
rs.getOptions().getMuscleColorSource()
);

EmitPointBasedLine(rs, musc, points, radius, color);
Expand Down
16 changes: 8 additions & 8 deletions src/OpenSimCreator/Graphics/OpenSimDecorationOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
{}
Expand All @@ -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
Expand Down Expand Up @@ -188,7 +188,7 @@ void osc::OpenSimDecorationOptions::setShouldShowPointForces(bool v)
void osc::OpenSimDecorationOptions::forEachOptionAsAppSettingValue(const std::function<void(std::string_view, const Variant&)>& 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<OpenSimDecorationOptionFlags>(); ++i) {
const auto& meta = GetIthOptionMetadata(i);
Expand Down Expand Up @@ -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<std::string>(*appVal), [](const auto& m) { return m.id; });
if (it != metadata.end()) {
m_MuscleColoringStyle = it->value;
m_MuscleColorSource = it->value;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/OpenSimCreator/Graphics/OpenSimDecorationOptions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <OpenSimCreator/Graphics/MuscleColoringStyle.h>
#include <OpenSimCreator/Graphics/MuscleColorSource.h>
#include <OpenSimCreator/Graphics/MuscleDecorationStyle.h>
#include <OpenSimCreator/Graphics/MuscleSizingStyle.h>
#include <OpenSimCreator/Graphics/OpenSimDecorationOptionFlags.h>
Expand All @@ -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);
Expand Down Expand Up @@ -79,7 +79,7 @@ namespace osc

private:
MuscleDecorationStyle m_MuscleDecorationStyle;
MuscleColoringStyle m_MuscleColoringStyle;
MuscleColorSource m_MuscleColorSource;
MuscleSizingStyle m_MuscleSizingStyle;
OpenSimDecorationOptionFlags m_Flags;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <OpenSimCreator/Documents/Model/IModelStatePair.h>
#include <OpenSimCreator/Documents/Model/UndoableModelActions.h>
#include <OpenSimCreator/Documents/Model/UndoableModelStatePair.h>
#include <OpenSimCreator/Graphics/MuscleColoringStyle.h>
#include <OpenSimCreator/UI/Events/OpenComponentContextMenuEvent.h>
#include <OpenSimCreator/UI/Shared/BasicWidgets.h>
#include <OpenSimCreator/UI/Shared/ComponentContextMenu.h>
Expand Down
12 changes: 6 additions & 6 deletions src/OpenSimCreator/UI/Shared/BasicWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimCreator/UI/Shared/BasicWidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <OpenSim/Simulation/Model/Geometry.h>
#include <OpenSim/Simulation/Model/Ligament.h>
#include <OpenSim/Simulation/Model/Model.h>
#include <OpenSimCreator/Graphics/MuscleColoringStyle.h>
#include <OpenSimCreator/Graphics/MuscleColorSource.h>
#include <OpenSimCreator/Graphics/OpenSimDecorationOptions.h>
#include <OpenSimCreator/Platform/OpenSimCreatorApp.h>
#include <OpenSimCreator/Utils/OpenSimHelpers.h>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 84dbcf3

Please sign in to comment.