43 const OpenSim::Model& sourceModel)
const final
49 if (not modelFilesystemLocation) {
55 if (get_destination_mesh_file().
empty()) {
58 else if (
const auto destinationMeshPath = modelFilesystemLocation->parent_path() / get_destination_mesh_file();
59 not std::filesystem::exists(destinationMeshPath)) {
61 std::stringstream msg;
62 msg << destinationMeshPath.string() <<
": Cannot find `destination_mesh_file` on filesystem";
67 const auto* sourceMesh = FindComponent<OpenSim::Mesh>(sourceModel, get_source_mesh_component_path());
69 std::stringstream msg;
70 msg << get_landmarks_frame() <<
": Cannot find Mesh 'source_mesh_component_path' in the source model (or it isn't a Mesh).";
80 const OpenSim::Model& sourceModel,
81 OpenSim::Model& resultModel)
const final
87 const std::optional<std::filesystem::path> modelFilesystemLocation =
TryFindInputFile(resultModel);
88 OSC_ASSERT_ALWAYS(modelFilesystemLocation &&
"The source model has no filesystem location");
91 const std::filesystem::path destinationMeshPath = modelFilesystemLocation->parent_path() / get_destination_mesh_file();
94 const auto* sourceMesh = FindComponent<OpenSim::Geometry>(resultModel, get_source_mesh_component_path());
95 OSC_ASSERT_ALWAYS((
dynamic_cast<const OpenSim::Mesh*
>(sourceMesh) or
dynamic_cast<const InMemoryMesh*
>(sourceMesh)) &&
"'source_mesh_component_path' exists in the model but isn't mesh-like");
96 OSC_ASSERT_ALWAYS(sourceMesh &&
"could not find `source_mesh_component_path` in the model");
102 const SimTK::Transform t = cache.lookupTPSAffineTransformWithoutScaling(commonParams.tpsInputs);
103 const SimTK::Vec3 newScaleFactors =
104 (commonParams.tpsInputs.destinationLandmarksPrescale/commonParams.tpsInputs.sourceLandmarksPrescale) * sourceMesh->get_scale_factors();
107 auto* destinationMesh = FindComponentMut<OpenSim::Geometry>(resultModel, get_source_mesh_component_path());
108 OSC_ASSERT_ALWAYS(destinationMesh &&
"could not find `source_mesh_component_path` in the result model");
109 OSC_ASSERT_ALWAYS((
dynamic_cast<const OpenSim::Mesh*
>(destinationMesh) or
dynamic_cast<const InMemoryMesh*
>(destinationMesh)) &&
"'source_mesh_component_path' exists in the model but isn't mesh-like");
110 const std::string existingMeshName = destinationMesh->getName();
112 auto* oldParentFrame = FindComponentMut<OpenSim::PhysicalFrame>(resultModel, destinationMesh->getFrame().getAbsolutePath());
120 auto* newFrame =
new OpenSim::PhysicalOffsetFrame{*oldParentFrame, t.invert()};
121 newFrame->updSocket(
"parent").setConnecteePath(oldParentFrame->getAbsolutePathString());
122 resultModel.addComponent(newFrame);
124 auto newMesh = std::make_unique<OpenSim::Mesh>();
125 newMesh->setName(existingMeshName);
126 newMesh->set_scale_factors(newScaleFactors);
127 newMesh->set_mesh_file(destinationMeshPath.string());
128 newMesh->updSocket(
"frame").setConnecteePath(newFrame->getAbsolutePathString());
129 resultModel.addComponent(newMesh.release());