Skip to content

Commit

Permalink
Start sketching out new model warping configuration design (#891 #889 #…
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jul 1, 2024
1 parent 0234941 commit 5cbd1ee
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/OpenSimCreator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ add_library(OpenSimCreator STATIC
Documents/ModelWarper/MaybePairedLandmark.h
Documents/ModelWarper/ModelWarpConfiguration.cpp
Documents/ModelWarper/ModelWarpConfiguration.h
Documents/ModelWarper/ModelWarperConfiguration.cpp
Documents/ModelWarper/ModelWarperConfiguration.h
Documents/ModelWarper/PointWarperFactories.cpp
Documents/ModelWarper/PointWarperFactories.h
Documents/ModelWarper/StationDefinedFrameWarperFactory.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "ModelWarperConfiguration.h"

#include <OpenSim/Common/Component.h>

#include <filesystem>

osc::mow::ModelWarperConfiguration::ModelWarperConfiguration()
{
constructProperties();
}

osc::mow::ModelWarperConfiguration::ModelWarperConfiguration(const std::filesystem::path& filePath) :
OpenSim::Component{filePath.string()}
{
constructProperties();
updateFromXMLDocument();
}

void osc::mow::ModelWarperConfiguration::constructProperties()
{
// TODO
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#pragma once

#include <OpenSim/Common/Component.h>

#include <filesystem>

namespace osc::mow
{
// abstract interface to a component that is capable of warping `n` other
// components (`StrategyTargets`) during a model warp
class ComponentWarpingStrategy : public OpenSim::Component {
protected:
ComponentWarpingStrategy() = default;
ComponentWarpingStrategy(const ComponentWarpingStrategy&) = default;
ComponentWarpingStrategy(ComponentWarpingStrategy&&) noexcept = default;
ComponentWarpingStrategy& operator=(const ComponentWarpingStrategy&) = default;
ComponentWarpingStrategy& operator=(ComponentWarpingStrategy&&) noexcept = default;
public:
~ComponentWarpingStrategy() noexcept override = default;

// StrategyTargets
private:
};

// abstract interface to a component that is capable of warping `n`
// `OpenSim::PhysicalOffsetFrame`s during a model warp
class OffsetFrameWarpingStrategy : public ComponentWarpingStrategy {};

// concrete implementation of an `OffsetFrameWarpingStrategy` in which
// only the `translation` property of the offset frame is warped but the
// rotation is left as-is
class ThinPlateSplineOnlyTranslationOffsetFrameWarpingStrategy final : public OffsetFrameWarpingStrategy {
public:
// PointSources
private:
};

// concrete implementation of an `OffsetFrameWarpingStrategy` in which the
// implementation should produce a halting error rather than continuing with
// the model warp
class ProduceErrorOffsetFrameWarpingStrategy final : public OffsetFrameWarpingStrategy {
};

// concrete implementation of an `OffsetFrameWarpingStrategy` in which the
// implementation should use a least-squares fit of the correspondences between
// source/destination landmarks (`PointsToFit`) to compute the resulting offset
// frame's `translation` and `rotation`
class LeastSquaresOffsetFrameWarpingStrategy final : public OffsetFrameWarpingStrategy {
public:
// PointsToFit
};

// abstract interface to a component that is capable of warping `n`
// `OpenSim::Station`s during a model warp
class StationWarpingStrategy : public OpenSim::Component {};

// concrete implementation of a `StationWarpingStrategy` that uses the Thin-Plate
// Spline (TPS) algorithm to fit correspondences between mesh landmarks (`MeshSources`)
class ThinPlateSplineStationWarpingStrategy final : public StationWarpingStrategy {
// MeshSources
};

// TODO:
// MuscleParameterWarpingStrategies
// MuscleParameterWarpingStrategy
// some_scaling_param
// IdentityMuscleParameterWarpingStrategy
//
// MeshWarpingStrategies
// ThinPlateSplineMeshWarpingStrategy
//
// WrapSurfaceWarpingStrategies
// WrapSurfaceWarpingStrategy
// LeastSquaresProjectionWrapSurfaceWarpingStrategy?

// top-level model warping configuration file
class ModelWarperConfiguration final : public OpenSim::Component {
OpenSim_DECLARE_CONCRETE_OBJECT(ModelWarperConfiguration, OpenSim::Component);
public:
// constructs a blank (default) configuration object
ModelWarperConfiguration();

// constructs a `ModelWarperConfiguration` by loading its properties from an XML file
// at the given filesystem location
explicit ModelWarperConfiguration(const std::filesystem::path& filePath);
private:
void constructProperties();
};
}
1 change: 1 addition & 0 deletions tests/TestOpenSimCreator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_executable(TestOpenSimCreator
Documents/Model/TestUndoableModelStatePair.cpp
Documents/ModelWarper/TestCachedModelWarper.cpp
Documents/ModelWarper/TestFrameWarperFactories.cpp
Documents/ModelWarper/TestModelWarperConfiguration.cpp
Documents/ModelWarper/TestPointWarperFactories.cpp
Documents/ModelWarper/TestWarpableModel.cpp
Documents/OutputExtractors/TestConstantOutputExtractor.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <OpenSimCreator/Documents/ModelWarper/ModelWarperConfiguration.h>

#include <TestOpenSimCreator/TestOpenSimCreatorConfig.h>

#include <gtest/gtest.h>

#include <filesystem>

using namespace osc;
using namespace osc::mow;

namespace
{
std::filesystem::path GetFixturePath(const std::filesystem::path& subpath)
{
return std::filesystem::weakly_canonical(std::filesystem::path{OSC_TESTING_RESOURCES_DIR} / subpath);
}
}

TEST(ModelWarperConfiguration, CanDefaultConstruct)
{
[[maybe_unused]] ModelWarperConfiguration configuration;
}

TEST(ModelWarperConfiguration, CanSaveDefaultConstructedToXMLFile)
{
ModelWarperConfiguration configuration;
configuration.print(R"(C:\Users\adamk\Desktop\somefile.xml)");
}

TEST(ModelWarperConfiguration, LoadingNonExistentFileThrows)
{
ASSERT_ANY_THROW({ [[maybe_unused]] ModelWarperConfiguration configuration{GetFixturePath("doesnt_exist")}; });
}

TEST(ModelWarperConfiguration, LoadingMalformedFileThrows)
{
ModelWarperConfiguration configuration{GetFixturePath("Document/ModelWarper/ModelWarperConfiguration/malformed.xml")};
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this isn't valid XML

0 comments on commit 5cbd1ee

Please sign in to comment.