43 const OpenSim::Model& sourceModel)
const final
49 if (not modelFilesystemLocation) {
55 if (get_destination_mesh_file().
empty()) {
59 not std::filesystem::exists(destinationMeshPath)) {
61 messages.emplace_back(
63 std::format(
"{}: : Cannot find `destination_mesh_file` on filesystem", destinationMeshPath.string())
68 const auto* sourceMesh = FindComponent<OpenSim::Mesh>(sourceModel, get_source_mesh_component_path());
70 messages.emplace_back(
72 std::format(
"{}: Cannot find Mesh 'source_mesh_component_path' in the source model (or it isn't a Mesh).", get_source_mesh_component_path())
82 const OpenSim::Model& sourceModel,
83 OpenSim::Model& resultModel)
const final
89 const std::optional<std::filesystem::path> modelFilesystemLocation =
TryFindInputFile(resultModel);
90 OSC_ASSERT_ALWAYS(modelFilesystemLocation &&
"The source model has no filesystem location");
96 const auto* sourceMesh = FindComponent<OpenSim::Geometry>(resultModel, get_source_mesh_component_path());
97 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");
98 OSC_ASSERT_ALWAYS(sourceMesh &&
"could not find `source_mesh_component_path` in the model");
104 const SimTK::Transform t = cache.lookupTPSAffineTransformWithoutScaling(commonParams.tpsInputs);
105 const SimTK::Vec3 newScaleFactors =
106 (commonParams.tpsInputs.destinationLandmarksPrescale/commonParams.tpsInputs.sourceLandmarksPrescale) * sourceMesh->get_scale_factors();
109 auto* destinationMesh = FindComponentMut<OpenSim::Geometry>(resultModel, get_source_mesh_component_path());
110 OSC_ASSERT_ALWAYS(destinationMesh &&
"could not find `source_mesh_component_path` in the result model");
111 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");
112 const std::string existingMeshName = destinationMesh->getName();
114 auto* oldParentFrame = FindComponentMut<OpenSim::PhysicalFrame>(resultModel, destinationMesh->getFrame().getAbsolutePath());
122 auto* newFrame =
new OpenSim::PhysicalOffsetFrame{*oldParentFrame, t.invert()};
123 newFrame->updSocket(
"parent").setConnecteePath(oldParentFrame->getAbsolutePathString());
124 resultModel.addComponent(newFrame);
126 auto newMesh = std::make_unique<OpenSim::Mesh>();
127 newMesh->setName(existingMeshName);
128 newMesh->set_scale_factors(newScaleFactors);
129 newMesh->set_mesh_file(destinationMeshPath.string());
130 newMesh->updSocket(
"frame").setConnecteePath(newFrame->getAbsolutePathString());
131 resultModel.addComponent(newMesh.release());