Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
parameter_transform_io.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
9
12#include "momentum/common/log.h"
18
19#include <re2/re2.h>
20
21#include <fstream>
22
23namespace momentum {
24
25namespace {
26
28
29// Section name constants to avoid typos
30constexpr const char* kParameterTransformSection = "ParameterTransform";
31constexpr const char* kParameterSetsSection = "ParameterSets";
32constexpr const char* kPoseConstraintsSection = "PoseConstraints";
33constexpr const char* kParameterLimitsSection = "Limits";
34
35bool isKnownSection(const std::string& sectionName) {
36 return sectionName == kParameterTransformSection || sectionName == kParameterSetsSection ||
37 sectionName == kPoseConstraintsSection || sectionName == kParameterLimitsSection;
38}
39
40std::unordered_map<std::string, SectionContent> loadMomentumModelCommon(std::istream& input) {
41 if (!input) {
42 MT_LOGW("Unable to read parameter transform data.");
43 return {};
44 }
45
46 std::unordered_map<std::string, SectionContent> result;
47 std::string sectionName;
48 std::string sectionContent;
49 size_t sectionStartLine = 0;
50 size_t linesNotInSectionCount = 0;
51 constexpr size_t kMaxLinesNotInSectionWarnings = 5;
52
53 std::string line;
54 size_t lineNumber = 0;
55 while (GetLineCrossPlatform(input, line)) {
56 ++lineNumber;
57 line = trim(line.substr(0, line.find_first_of('#')));
58 if (line.empty()) {
59 // Skip leading comments
60 continue;
61 }
62
63 if (line == "Momentum Model Definition V1.0") {
64 break;
65 }
66
68 "Invalid model definition file; expected 'Momentum Model Definition V1.0', got {}", line);
69 }
70
71 while (GetLineCrossPlatform(input, line)) {
72 ++lineNumber;
73 // erase all comments
74 line = trim(line.substr(0, line.find_first_of('#')));
75
76 // skip empty lines or comment lines
77 if (line.empty()) {
78 continue;
79 }
80
81 // look for new section
82 static const re2::RE2 reg(R"(\‍[(\w+)\‍])");
83 std::string newSectionName;
84 if (re2::RE2::FullMatch(line, reg, &newSectionName)) {
85 // new section, store old section
86 if (!sectionName.empty() && !sectionContent.empty()) {
87 if (isKnownSection(sectionName)) {
88 result[sectionName].addSegment(sectionContent, sectionStartLine);
89 }
90 }
91
92 // Check if this is a known section type
93 if (!isKnownSection(newSectionName)) {
94 MT_LOGW("Unexpected section found at line {}: [{}]", lineNumber, newSectionName);
95 }
96
97 // start new section
98 sectionName = newSectionName;
99 sectionContent.clear();
100 sectionStartLine = lineNumber + 1; // Content starts on the next line after section header
101 } else if (!sectionName.empty()) {
102 // Only accumulate content for known sections
103 if (isKnownSection(sectionName)) {
104 sectionContent += line + "\n";
105 }
106 } else {
107 // Line is not in a section and is not a comment
108 if (linesNotInSectionCount < kMaxLinesNotInSectionWarnings) {
109 MT_LOGW("Line {} is not in a section and is not a comment: {}", lineNumber, line);
110 ++linesNotInSectionCount;
111 if (linesNotInSectionCount == kMaxLinesNotInSectionWarnings) {
112 MT_LOGW("Suppressing further warnings about lines not in sections");
113 }
114 }
115 }
116 }
117
118 // store last section
119 if (!sectionName.empty() && !sectionContent.empty()) {
120 if (isKnownSection(sectionName)) {
121 result[sectionName].addSegment(sectionContent, sectionStartLine);
122 }
123 }
124
125 return result;
126}
127
128std::tuple<ParameterTransform, ParameterLimits> loadModelDefinitionFromStream(
129 std::istream& instream,
130 const Skeleton& skeleton) {
131 MT_THROW_IF(!instream, "Unable to read parameter transform data.");
132
133 const auto sections = loadMomentumModelCommon(instream);
134
135 std::tuple<ParameterTransform, ParameterLimits> res;
136 ParameterTransform& pt = std::get<0>(res);
137 ParameterLimits& pl = std::get<1>(res);
138
139 const auto ptIt = sections.find(kParameterTransformSection);
140 if (ptIt == sections.end()) {
141 pt = parseParameterTransform(momentum::io_detail::SectionContent{}, skeleton);
142 } else {
143 pt = parseParameterTransform(ptIt->second, skeleton);
144 }
145
146 const auto psIt = sections.find(kParameterSetsSection);
147 if (psIt != sections.end()) {
148 pt.parameterSets = parseParameterSets(psIt->second, pt);
149 }
150
151 const auto pcIt = sections.find(kPoseConstraintsSection);
152 if (pcIt != sections.end()) {
153 pt.poseConstraints = parsePoseConstraints(pcIt->second, pt);
154 }
155
156 const auto plIt = sections.find(kParameterLimitsSection);
157 if (plIt != sections.end()) {
158 pl = parseParameterLimits(plIt->second, skeleton, pt);
159 }
160
161 return res;
162}
163
164void parseParameter(
165 std::vector<Eigen::Triplet<float>>& triplets,
167 const std::vector<std::string>& pTokens,
168 const Skeleton& skeleton,
169 size_t jointIndex,
170 size_t attributeIndex,
171 const std::string& line) {
172 // split the parameter names
173 const auto dtokens = tokenize(pTokens[1], "+");
174 for (const auto& dtoken : dtokens) {
175 // tokenize each subtoken
176 const auto stokens = tokenize(dtoken, "*");
177
178 if (stokens.size() != 2) {
179 if (stokens.size() != 1) {
180 continue;
181 }
182
183 // additional weight
184 const Eigen::Index pindex = jointIndex * kParametersPerJoint + attributeIndex;
185 const float weight = gsl::narrow_cast<float>(std::stod(stokens[0]));
186 pt.offsets(pindex) = weight;
187 continue;
188 }
189
190 // first should be the weight
191 const float weight = gsl::narrow_cast<float>(std::stod(stokens[0]));
192
193 const std::string& parameterName = trim(stokens[1]);
194 size_t parameterIndex = kInvalidIndex;
195 for (size_t d = 0; d < pt.name.size(); d++) {
196 if (pt.name[d] == parameterName) {
197 parameterIndex = static_cast<int>(d);
198 break;
199 }
200 }
201
202 // check if the first token is actually a joint name as well
203 const size_t refJointIndex =
204 skeleton.getJointIdByName(parameterName.substr(0, parameterName.find_first_of('.')));
205 size_t refJointParameter = kInvalidIndex;
206 if (refJointIndex != kInvalidIndex) {
207 const std::string jpString = parameterName.substr(parameterName.find_first_of('.') + 1);
208 for (size_t l = 0; l < kParametersPerJoint; l++) {
209 if (jpString == kJointParameterNames[l]) {
210 refJointParameter = l;
211 break;
212 }
213 }
214 }
215
216 if (parameterIndex == kInvalidIndex && refJointIndex == kInvalidIndex) {
217 // no reference transform, so create new parameter
218 parameterIndex = static_cast<int>(pt.name.size());
219 pt.name.push_back(parameterName);
220
221 // add triplet
222 triplets.emplace_back(
223 static_cast<int>(jointIndex * kParametersPerJoint + attributeIndex),
224 static_cast<int>(parameterIndex),
225 weight);
226 } else if (
227 parameterIndex == kInvalidIndex && refJointIndex != kInvalidIndex &&
228 refJointParameter != kInvalidIndex) {
229 // we actually reference a joint that is in the list earlier, copy over all parameters
230 // defining this joint and multiply them
231 const size_t refJointId = refJointIndex * kParametersPerJoint + refJointParameter;
232 for (size_t tr = 0; tr < triplets.size(); tr++) {
233 const auto& t = triplets[tr];
234 if (static_cast<size_t>(t.row()) == refJointId) {
235 triplets.emplace_back(
236 static_cast<int>(jointIndex * kParametersPerJoint + attributeIndex),
237 static_cast<int>(t.col()),
238 t.value() * weight);
239 }
240 }
241 } else if (parameterIndex != kInvalidIndex) {
242 // add triplet
243 triplets.emplace_back(
244 static_cast<int>(jointIndex * kParametersPerJoint + attributeIndex),
245 static_cast<int>(parameterIndex),
246 weight);
247 } else {
248 MT_THROW("Could not parse channel expression : {}", line);
249 }
250 }
251}
252
253} // namespace
254
255std::unordered_map<std::string, std::string> loadMomentumModel(const filesystem::path& filename) {
256 if (filename.empty()) {
257 return {};
258 }
259
260 std::ifstream infile(filename);
261 MT_THROW_IF(!infile.is_open(), "Cannot find file {}", filename.string());
262 const auto sections = loadMomentumModelCommon(infile);
263
264 std::unordered_map<std::string, std::string> result;
265 for (const auto& [sectionName, content] : sections) {
266 result[sectionName] = content.toString();
267 }
268 return result;
269}
270
271std::unordered_map<std::string, std::string> loadMomentumModelFromBuffer(
272 std::span<const std::byte> buffer) {
273 if (buffer.empty()) {
274 return {};
275 }
276
277 ispanstream inputStream(buffer);
278 const auto sections = loadMomentumModelCommon(inputStream);
279
280 std::unordered_map<std::string, std::string> result;
281 for (const auto& [sectionName, content] : sections) {
282 result[sectionName] = content.toString();
283 }
284 return result;
285}
286
287// Internal overload that accepts SectionContent
289 const SectionContent& content,
290 const Skeleton& skeleton) {
292 pt.activeJointParams.setConstant(skeleton.joints.size() * kParametersPerJoint, false);
293 pt.offsets.setZero(skeleton.joints.size() * kParametersPerJoint);
294
295 // triplet list
296 std::vector<Eigen::Triplet<float>> triplets;
297
298 auto iterator = content.begin();
299 std::string line;
300 while (iterator.getline(line)) {
301 const size_t lineIndex = iterator.currentLine();
302
303 // erase all comments
304 line = line.substr(0, line.find_first_of('#'));
305
306 // Skip empty lines
307 if (trim(line).empty()) {
308 continue;
309 }
310
311 // ------------------------------------------------
312 // parse parameter vector
313 // ------------------------------------------------
314 const auto pTokens = tokenize(line, "=");
315 if (pTokens.size() != 2) {
316 MT_LOGW(
317 "Ignoring invalid line under [ParameterTransform] section at line {}: {}",
318 lineIndex,
319 line);
320 continue;
321 }
322
323 // split pToken[0] into joint name and attribute name
324 const auto aTokens = tokenize(pTokens[0], ".");
326 aTokens.size() != 2, "Unknown joint name in expression at line {}: {}", lineIndex, line);
327
328 // get the right joint to modify
329 const size_t jointIndex = skeleton.getJointIdByName(trim(aTokens[0]));
331 jointIndex == kInvalidIndex,
332 "Unknown joint name in expression at line {}: {}",
333 lineIndex,
334 line);
335
336 // the first pToken is the name of the joint and it's attribute type
337 size_t attributeIndex = kInvalidIndex;
338 const auto trimName = trim(aTokens[1]);
339 for (size_t j = 0; j < kParametersPerJoint; j++) {
340 if (trimName == kJointParameterNames[j]) {
341 attributeIndex = j;
342 break;
343 }
344 }
345
346 // if we didn't find a right name exit with an error
348 attributeIndex == kInvalidIndex,
349 "Unknown channel name in expression at line {}: {}",
350 lineIndex,
351 line);
352
353 // enable the attribute in the skeleton if we have a parameter controlling it
354 pt.activeJointParams[jointIndex * kParametersPerJoint + attributeIndex] = true;
355
356 // split the parameter names
357 parseParameter(triplets, pt, pTokens, skeleton, jointIndex, attributeIndex, line);
358 }
359
360 // resize the Transform matrix to the correct size
361 pt.transform.resize(
362 static_cast<int>(skeleton.joints.size()) * kParametersPerJoint,
363 static_cast<int>(pt.name.size()));
364
365 // finish parameter setup by creating sparse matrix
366 triplets.erase(
367 std::remove_if(
368 std::begin(triplets),
369 std::end(triplets),
370 [](const Eigen::Triplet<float>& t) { return t.value() == 0.0f; }),
371 std::end(triplets));
372
373 pt.transform.setFromTriplets(triplets.begin(), triplets.end());
374
375 return pt;
376}
377
378// Public API wrapper for backward compatibility
380parseParameterTransform(const std::string& data, const Skeleton& skeleton, size_t lineOffset) {
381 SectionContent content;
382 if (!data.empty()) {
383 content.addSegment(data, lineOffset);
384 }
385 return parseParameterTransform(content, skeleton);
386}
387
388// Internal overload that accepts SectionContent
390 ParameterSets result;
391
392 auto iterator = content.begin();
393 std::string line;
394 while (iterator.getline(line)) {
395 const size_t lineIndex = iterator.currentLine();
396
397 // erase all comments
398 line = line.substr(0, line.find_first_of('#'));
399
400 // Skip empty lines
401 if (trim(line).empty()) {
402 continue;
403 }
404
405 // Skip if not parameterset definitions
406 if (line.find("parameterset") != 0) {
407 MT_LOGW(
408 "Ignoring invalid line under [ParameterSets] section at line {}: {}", lineIndex, line);
409 continue;
410 }
411
412 // parse parameterset
413 const auto pTokens = tokenize(line, " \t\r\n");
415 pTokens.size() < 2,
416 "Could not parse parameterset line in parameter configuration at line {}: {}",
417 lineIndex,
418 line);
419
420 ParameterSet ps;
421 for (size_t i = 2; i < pTokens.size(); i++) {
422 const std::string& parameterName = trim(pTokens[i]);
423 size_t parameterIndex = kInvalidIndex;
424 for (size_t d = 0; d < pt.name.size(); d++) {
425 if (pt.name[d] == parameterName) {
426 parameterIndex = d;
427 break;
428 }
429 }
430
432 parameterIndex == kInvalidIndex,
433 "Could not parse parameterset line in parameter configuration at line {}: {}. Found unknown parameter name {}.",
434 lineIndex,
435 line,
436 parameterName);
437
438 ps.set(parameterIndex, true);
439 }
440
441 result[pTokens[1]] = ps;
442 }
443
444 return result;
445}
446
447// Public API wrapper for backward compatibility
449parseParameterSets(const std::string& data, const ParameterTransform& pt, size_t lineOffset) {
450 SectionContent content;
451 if (!data.empty()) {
452 content.addSegment(data, lineOffset);
453 }
454 return parseParameterSets(content, pt);
455}
456
457// Internal overload that accepts SectionContent
459 PoseConstraints result;
460
461 auto iterator = content.begin();
462 std::string line;
463 while (iterator.getline(line)) {
464 const size_t lineIndex = iterator.currentLine();
465
466 // erase all comments
467 line = line.substr(0, line.find_first_of('#'));
468
469 // Skip empty lines
470 if (trim(line).empty()) {
471 continue;
472 }
473
474 // Skip if not poseconstraints definitions
475 if (line.find("poseconstraints") != 0) {
476 MT_LOGW(
477 "Ignoring invalid line under [PoseConstraints] section at line {}: {}", lineIndex, line);
478 continue;
479 }
480
481 // parse parameterset
482 const auto pTokens = tokenize(line, " \t\r\n");
484 pTokens.size() < 2,
485 "Could not parse 'poseconstraints' line in parameter configuration at line {}: {}",
486 lineIndex,
487 line);
488
490 for (size_t i = 2; i < pTokens.size(); i++) {
491 const std::string& item = trim(pTokens[i]);
492
493 const auto cTokens = tokenize(item, "=");
494 if (cTokens.size() != 2) {
495 continue;
496 }
497
498 size_t parameterIndex = kInvalidIndex;
499 for (size_t d = 0; d < pt.name.size(); d++) {
500 if (pt.name[d] == cTokens[0]) {
501 parameterIndex = d;
502 break;
503 }
504 }
505
507 parameterIndex == kInvalidIndex,
508 "Could not parse 'poseconstraints' line in parameter configuration at line {}: {}",
509 lineIndex,
510 line);
511
512 ps.parameterIdValue.emplace_back(parameterIndex, std::stof(cTokens[1]));
513 }
514
515 result[pTokens[1]] = ps;
516 }
517
518 return result;
519}
520
521// Public API wrapper for backward compatibility
523parsePoseConstraints(const std::string& data, const ParameterTransform& pt, size_t lineOffset) {
524 SectionContent content;
525 if (!data.empty()) {
526 content.addSegment(data, lineOffset);
527 }
528 return parsePoseConstraints(content, pt);
529}
530
531std::tuple<ParameterTransform, ParameterLimits> loadModelDefinition(
532 const filesystem::path& filename,
533 const Skeleton& skeleton) {
534 std::ifstream infile(filename);
536 !infile.is_open(),
537 "Unable to open parameter transform file '{}' for reading.",
538 filename.string());
539
540 return loadModelDefinitionFromStream(infile, skeleton);
541}
542
543std::tuple<ParameterTransform, ParameterLimits> loadModelDefinition(
544 std::span<const std::byte> rawData,
545 const Skeleton& skeleton) {
546 if (rawData.empty()) {
547 return {};
548 }
549
550 ispanstream inputStream(rawData);
551
552 MT_THROW_IF(!inputStream, "Unable to read parameter transform data.");
553
554 return loadModelDefinitionFromStream(inputStream, skeleton);
555}
556
558 const ParameterTransform& parameterTransform,
559 const Skeleton& skeleton) {
560 std::ostringstream oss;
561
562 // Write each joint parameter definition
563 for (size_t iJoint = 0; iJoint < skeleton.joints.size(); ++iJoint) {
564 const auto& joint = skeleton.joints[iJoint];
565
566 for (size_t iParam = 0; iParam < kParametersPerJoint; ++iParam) {
567 const size_t jointParamIndex = iJoint * kParametersPerJoint + iParam;
568
569 // Skip inactive joint parameters
570 if (!parameterTransform.activeJointParams[jointParamIndex]) {
571 continue;
572 }
573
574 // Write joint parameter name
575 oss << joint.name << "." << kJointParameterNames[iParam] << " = ";
576
577 // Collect all model parameters that influence this joint parameter
578 std::vector<std::pair<size_t, float>> influences;
579 for (Eigen::Index iModelParam = 0; iModelParam < parameterTransform.transform.cols();
580 ++iModelParam) {
581 const float weight = parameterTransform.transform.coeff(jointParamIndex, iModelParam);
582 if (weight != 0.0f) {
583 influences.emplace_back(iModelParam, weight);
584 }
585 }
586
587 // Write the offset if it exists
588 const float offset = parameterTransform.offsets[jointParamIndex];
589 bool needsPlus = false;
590
591 if (!influences.empty()) {
592 bool firstTerm = true;
593 for (const auto& [modelParamIndex, weight] : influences) {
595 modelParamIndex >= parameterTransform.name.size(),
596 "Model parameter index {} is out of bounds (name size: {})",
597 modelParamIndex,
598 parameterTransform.name.size());
599 if (!firstTerm) {
600 oss << " + ";
601 }
602 oss << weight << "*" << parameterTransform.name.at(modelParamIndex);
603 firstTerm = false;
604 needsPlus = true;
605 }
606 }
607
608 if (offset != 0.0f) {
609 if (needsPlus) {
610 oss << " + ";
611 }
612 oss << offset;
613 }
614
615 oss << "\n";
616 }
617 }
618
619 return oss.str();
620}
621
622std::string writeParameterSets(const ParameterSets& parameterSets) {
623 std::ostringstream oss;
624
625 for (const auto& [name, paramSet] : parameterSets) {
626 oss << "parameterset " << name;
627
628 // Write all active parameters in the set
629 for (size_t i = 0; i < paramSet.size(); ++i) {
630 if (paramSet.test(i)) {
631 // We need the parameter name, but we don't have access to parameterTransform here
632 // This is a limitation - we'll need to pass it in
633 oss << " param_" << i;
634 }
635 }
636 oss << "\n";
637 }
638
639 return oss.str();
640}
641
642std::string writePoseConstraints(const PoseConstraints& poseConstraints) {
643 std::ostringstream oss;
644
645 for (const auto& [name, constraint] : poseConstraints) {
646 oss << "poseconstraints " << name;
647
648 // Write all parameter=value pairs
649 for (const auto& [paramIndex, value] : constraint.parameterIdValue) {
650 // We need the parameter name, but we don't have access to parameterTransform here
651 oss << " param_" << paramIndex << "=" << value;
652 }
653 oss << "\n";
654 }
655
656 return oss.str();
657}
658
660 const Skeleton& skeleton,
661 const ParameterTransform& parameterTransform,
662 const ParameterLimits& parameterLimits) {
663 std::ostringstream oss;
664
665 // Write header
666 oss << "Momentum Model Definition V1.0\n\n";
667
668 // Write ParameterTransform section
669 if (!parameterTransform.name.empty()) {
670 oss << "[ParameterTransform]\n";
671 oss << writeParameterTransform(parameterTransform, skeleton);
672 oss << "\n";
673 }
674
675 // Write ParameterSets section
676 if (!parameterTransform.parameterSets.empty()) {
677 oss << "[ParameterSets]\n";
678 for (const auto& [name, paramSet] : parameterTransform.parameterSets) {
679 oss << "parameterset " << name;
680
681 // Write all active parameters in the set
682 for (size_t i = 0; i < paramSet.size() && i < parameterTransform.name.size(); ++i) {
683 if (paramSet.test(i)) {
684 oss << " " << parameterTransform.name[i];
685 }
686 }
687 oss << "\n";
688 }
689 oss << "\n";
690 }
691
692 // Write PoseConstraints section
693 if (!parameterTransform.poseConstraints.empty()) {
694 oss << "[PoseConstraints]\n";
695 for (const auto& [name, constraint] : parameterTransform.poseConstraints) {
696 oss << "poseconstraints " << name;
697
698 // Write all parameter=value pairs
699 for (const auto& [paramIndex, value] : constraint.parameterIdValue) {
700 if (paramIndex < parameterTransform.name.size()) {
701 oss << " " << parameterTransform.name.at(paramIndex) << "=" << value;
702 }
703 }
704 oss << "\n";
705 }
706 oss << "\n";
707 }
708
709 // Write ParameterLimits section using existing function
710 if (!parameterLimits.empty()) {
711 oss << "[" << kParameterLimitsSection << "]\n";
712 oss << writeParameterLimits(parameterLimits, skeleton, parameterTransform);
713 }
714
715 return oss.str();
716}
717
718} // namespace momentum
Holds all segments of a section and provides line-aware iteration This is used internally to track li...
Definition utility.h:25
void addSegment(std::string_view content, size_t startLine)
Definition utility.h:27
LineIterator begin() const
Definition utility.h:54
Holds all segments of a section and provides line-aware iteration This is used internally to track li...
Definition utility.h:25
#define MT_THROW(...)
Throws a std::runtime_error with a formatted message.
Definition exception.h:31
#define MT_THROW_IF(Condition,...)
Conditionally throws a std::runtime_error with a formatted message if the condition is true.
Definition exception.h:55
#define MT_LOGW(...)
Definition log.h:180
SkeletonT< float > Skeleton
Definition fwd.h:263
StringType trim(const StringType &text, const char *whiteChars)
Returns a copy of the string with leading and trailing characters in whiteChars removed.
Definition string.cpp:16
ParameterLimits parseParameterLimits(const io_detail::SectionContent &content, const Skeleton &skeleton, const ParameterTransform &parameterTransform)
std::unordered_map< std::string, std::string > loadMomentumModel(const filesystem::path &filename)
std::unordered_map< std::string, ParameterSet > ParameterSets
std::string writeParameterTransform(const ParameterTransform &parameterTransform, const Skeleton &skeleton)
std::unordered_map< std::string, std::string > loadMomentumModelFromBuffer(std::span< const std::byte > buffer)
std::vector< ParameterLimit > ParameterLimits
std::string writeParameterSets(const ParameterSets &parameterSets)
constexpr std::array< const char *, kParametersPerJoint > kJointParameterNames
Definition types.h:24
ParameterTransformT< float > ParameterTransform
Definition fwd.h:244
std::string writePoseConstraints(const PoseConstraints &poseConstraints)
ParameterTransform parseParameterTransform(const SectionContent &content, const Skeleton &skeleton)
std::istream & GetLineCrossPlatform(std::istream &is, std::string &line)
Reads a line from the input stream, handling line endings for different platforms.
std::tuple< ParameterTransform, ParameterLimits > loadModelDefinition(const filesystem::path &filename, const Skeleton &skeleton)
constexpr size_t kParametersPerJoint
Definition types.h:21
std::vector< std::string > tokenize(const std::string &inputString, const std::string &delimiters, const bool trim)
Tokenizes a string using the specified single-byte delimiter characters.
Definition string.cpp:42
ParameterSets parseParameterSets(const SectionContent &content, const ParameterTransform &pt)
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
Definition types.h:182
std::string writeParameterLimits(const ParameterLimits &parameterLimits, const Skeleton &skeleton, const ParameterTransform &parameterTransform)
std::unordered_map< std::string, PoseConstraint > PoseConstraints
PoseConstraints parsePoseConstraints(const SectionContent &content, const ParameterTransform &pt)
std::bitset< kMaxModelParams > ParameterSet
Bitset for model parameter enablement.
Definition types.h:430
std::string writeModelDefinition(const Skeleton &skeleton, const ParameterTransform &parameterTransform, const ParameterLimits &parameterLimits)
Write complete model definition file.
VectorX< bool > activeJointParams
The list of joint parameters that are actually active and influenced from the transform.
PoseConstraints poseConstraints
A set of predefined poses.
std::vector< std::string > name
The list of model parameter names.
ParameterSets parameterSets
Convenience grouping of model parameters.
SparseRowMatrix< T > transform
The sparse mapping matrix that maps model parameters to joint parameters.
std::vector< std::pair< size_t, float > > parameterIdValue
A vector of tuples of type: (model parameter index, parameter value).
size_t getJointIdByName(std::string_view name) const
Returns the index of a joint with the given name, or kInvalidIndex if not found.
Definition skeleton.cpp:25
JointList joints
The list of joints in this skeleton, ordered such that every joint's parent appears earlier in the li...
Definition skeleton.h:25
istream that takes a span of const bytes as input.