99 std::map<utils::Equation, double> variable;
103 size_t version(
static_cast<size_t>(atoi(main_tag.c_str())));
105 (version == 1 || version == 2 || version == 3 || version == 4),
106 "Version " + main_tag +
" is not implemented yet");
108#ifdef MODULE_ACTUATORS
109 bool hasActuators =
false;
119 subproperty_tag =
"";
122 if (!main_tag.
tolower().compare(
"segment")) {
127 bool RTinMatrix(
true);
132 bool isInertiaSet(
false);
133 double mass = 0.00000001;
138 bool isMeshSet(
false);
139 int segmentByFile(-1);
140 std::vector<utils::Range> QRanges;
141 std::vector<utils::Range> QdotRanges;
142 std::vector<utils::Range> QddotRanges;
143 std::vector<utils::Scalar> jointDampings;
144 bool isRangeQSet(
false);
146 bool isRangeQdotSet(
false);
148 bool isRangeQddotSet(
false);
150 while (file.
read(property_tag) &&
151 property_tag.
tolower().compare(
"endsegment")) {
152 if (!property_tag.
tolower().compare(
"parent")) {
154 file.
read(parent_str);
155 if (parent_str.
tolower().compare(
"root")) {
157 model->GetBodyId(parent_str.c_str()),
158 "Wrong name in a segment");
160 }
else if (!property_tag.
tolower().compare(
"translations")) {
163 "Translations must appear before the rangesq tag");
166 "Translations must appear before the rangesqdot tag");
169 "Translations must appear before the rangesqddot tag");
171 }
else if (!property_tag.
tolower().compare(
"rotations")) {
173 !isRangeQSet,
"Rotations must appear before the rangesq tag");
176 "Rotations must appear before the rangesqdot tag");
179 "Rotations must appear before the rangesqddot tag");
182 !property_tag.
tolower().compare(
"ranges") ||
183 !property_tag.
tolower().compare(
"rangesq")) {
185 size_t rotLength = !rot.compare(
"q") ? 4 : rot.length();
186 for (
size_t i = 0; i < trans.length() + rotLength; ++i) {
192 }
else if (!property_tag.
tolower().compare(
"rangesqdot")) {
194 size_t rotLength = !rot.compare(
"q") ? 3 : rot.length();
195 for (
size_t i = 0; i < trans.length() + rotLength; ++i) {
200 isRangeQdotSet =
true;
201 }
else if (!property_tag.
tolower().compare(
"rangesqddot")) {
203 size_t rotLength = !rot.compare(
"q") ? 3 : rot.length();
204 for (
size_t i = 0; i < trans.length() + rotLength; ++i) {
209 isRangeQddotSet =
true;
210 }
else if (!property_tag.
tolower().compare(
"jointdampings")) {
211 size_t rotLength = !rot.compare(
"q") ? 3 : rot.length();
212 for (
size_t i = 0; i < trans.length() + rotLength; ++i) {
215 jointDampings.push_back(damping);
217 }
else if (!property_tag.
tolower().compare(
"mass")) {
218 file.
read(mass, variable);
220 !property_tag.
tolower().compare(
"inertia") ||
221 !property_tag.
tolower().compare(
"inertiamatrix")) {
224 "Inertia matrix cannot be set twice. Please note that "
225 "'Inertia', 'InertiaMatrix' and 'RadiiOfGyration' all set the "
229 }
else if (!property_tag.
tolower().compare(
"inertia_xxyyzz")) {
232 "Inertia matrix cannot be set twice. Please note that "
233 "'Inertia', 'InertiaMatrix' and 'RadiiOfGyration' all set the "
248 }
else if (!property_tag.
tolower().compare(
"rtinmatrix")) {
250 isRTset ==
false,
"RT should not appear before RTinMatrix");
251 file.
read(RTinMatrix);
252 }
else if (!property_tag.
tolower().compare(
"rt")) {
256 !property_tag.
tolower().compare(
"com") ||
257 !property_tag.
tolower().compare(
"centerofmass")) {
260 !property_tag.
tolower().compare(
"forceplate") ||
261 !property_tag.
tolower().compare(
"externalforceindex")) {
263 <<
"Please note that the 'externalforceindex' or 'forceplate' "
264 "tags were removed when the ExternalForceSet was "
266 <<
"Please consider removing these tag from your model file."
268 }
else if (!property_tag.
tolower().compare(
"mesh")) {
269 if (segmentByFile == -1) {
271 }
else if (segmentByFile == 1) {
278 }
else if (!property_tag.
tolower().compare(
"patch")) {
279 if (segmentByFile == -1) {
281 }
else if (segmentByFile == 1) {
285 for (
size_t i = 0; i < 3; ++i) {
289 }
else if (!property_tag.
tolower().compare(
"meshfile")) {
290 if (segmentByFile == -1) {
292 }
else if (segmentByFile == 0) {
296 file.
read(filePathInString);
297 utils::Path filePath(meshFolderPrefix + filePathInString);
299 if (!extension.compare(
"biomesh")) {
302 }
else if (!extension.compare(
"ply")) {
304 }
else if (!extension.compare(
"obj")) {
307#ifdef MODULE_VTP_FILES_READER
308 else if (!extension.compare(
"vtp")) {
312 else if (!extension.compare(
"stl")) {
316 filePath.
extension() +
" is an unrecognized mesh file");
319 }
else if (!property_tag.
tolower().compare(
"meshrt")) {
322 "mesh(es) or meshfile should be declared before meshrt");
326 }
else if (!property_tag.
tolower().compare(
"meshscale")) {
329 "mesh(es) or meshfile should be declared before meshscale");
333 }
else if (!property_tag.
tolower().compare(
"meshcolor")) {
341 if (rot.compare(
"q")) {
343 rotLength = rot.length();
347 for (
size_t i = 0; i < trans.length() + rotLength; ++i) {
348 if (!rot.compare(
"q") && i >= trans.length()) {
355 if (!isRangeQdotSet) {
357 if (rot.compare(
"q")) {
359 rotLength = rot.length();
363 for (
size_t i = 0; i < trans.length() + rotLength; ++i) {
364 QdotRanges.push_back(
utils::Range(-M_PI * 10, M_PI * 10));
367 if (!isRangeQddotSet) {
369 if (rot.compare(
"q")) {
371 rotLength = rot.length();
375 for (
size_t i = 0; i < trans.length() + rotLength; ++i) {
376 QddotRanges.push_back(
utils::Range(-M_PI * 100, M_PI * 100));
380 mass, com, inertia, mesh);
392 }
else if (!main_tag.
tolower().compare(
"mesh_folder_prefix")) {
393 file.
read(meshFolderPrefix);
394 }
else if (!main_tag.
tolower().compare(
"gravity")) {
397 model->gravity = gravity;
398 }
else if (!main_tag.
tolower().compare(
"variables")) {
400 while (file.
read(var) && var.
tolower().compare(
"endvariables")) {
401 if (!var(0).compare(
"$")) {
405 variable.find(var) == variable.end(),
406 "Variable already defined");
407 variable[var] = value;
410 }
else if (!main_tag.
tolower().compare(
"marker")) {
413 size_t parent_int = 0;
416 bool technical =
true;
417 bool anatomical =
false;
419 while (file.
read(property_tag) &&
420 property_tag.
tolower().compare(
"endmarker"))
421 if (!property_tag.
tolower().compare(
"parent")) {
423 file.
read(parent_str);
425 static_cast<size_t>(model->GetBodyId(parent_str.c_str()));
428 model->IsBodyId(
static_cast<unsigned int>(parent_int)),
429 "Wrong name in a segment");
430 }
else if (!property_tag.
tolower().compare(
"position")) {
432 }
else if (!property_tag.
tolower().compare(
"technical")) {
433 file.
read(technical);
434 }
else if (!property_tag.
tolower().compare(
"anatomical")) {
435 file.
read(anatomical);
436 }
else if (!property_tag.
tolower().compare(
"axestoremove")) {
437 file.
read(axesToRemove);
447 static_cast<int>(parent_int));
448 }
else if (!main_tag.
tolower().compare(
"mimu") && version >= 4) {
451 !main_tag.
tolower().compare(
"imu") ||
452 !main_tag.
tolower().compare(
"mimu") ||
453 !main_tag.
tolower().compare(
"customrt")) {
459 bool RTinMatrix(
true);
464 bool technical =
true;
465 bool anatomical =
false;
466 bool firstTag =
true;
467 bool fromMarkers(
false);
470 std::vector<utils::String> firstAxisMarkerNames(2);
472 std::vector<utils::String> secondAxisMarkerNames(2);
474 while (file.
read(property_tag) &&
475 !(!property_tag.
tolower().compare(
"endimu") ||
476 !property_tag.
tolower().compare(
"endmimu") ||
477 !property_tag.
tolower().compare(
"endcustomrt"))) {
478 if (!property_tag.
tolower().compare(
"parent")) {
480 file.
read(parent_str);
483 model->IsBodyId(model->GetBodyId(parent_str.c_str())),
484 "Wrong name in a segment");
485 }
else if (!property_tag.
tolower().compare(
"frommarkers")) {
488 "The tag 'fromMarkers' should appear first in the IMU " +
493 }
else if (!property_tag.
tolower().compare(
"technical")) {
494 file.
read(technical);
495 }
else if (!property_tag.
tolower().compare(
"anatomical")) {
496 file.
read(anatomical);
500 if (!property_tag.
tolower().compare(
"originmarkername")) {
501 file.
read(originMarkerName);
502 }
else if (!property_tag.
tolower().compare(
"firstaxis")) {
503 file.
read(firstAxis);
504 }
else if (!property_tag.
tolower().compare(
505 "firstaxismarkernames")) {
506 for (
size_t i = 0; i < 2; ++i) {
507 file.
read(firstAxisMarkerNames[i]);
509 }
else if (!property_tag.
tolower().compare(
"secondaxis")) {
510 file.
read(secondAxis);
511 }
else if (!property_tag.
tolower().compare(
512 "secondaxismarkernames")) {
513 for (
size_t i = 0; i < 2; ++i) {
514 file.
read(secondAxisMarkerNames[i]);
516 }
else if (!property_tag.
tolower().compare(
"recalculate")) {
517 file.
read(axisToRecalculate);
520 if (!property_tag.
tolower().compare(
"rtinmatrix")) {
522 isRTset ==
false,
"RT should not appear before RTinMatrix");
523 file.
read(RTinMatrix);
524 }
else if (!property_tag.
tolower().compare(
"rt")) {
531 std::vector<rigidbody::NodeSegment> allMarkerOnSegment(
534 bool isOrigin(
false), isAxis1Beg(
false), isAxis1End(
false),
535 isAxis2Beg(
false), isAxis2End(
false);
536 for (
auto mark : allMarkerOnSegment) {
537 if (!mark.utils::Node::name().compare(originMarkerName)) {
541 if (!mark.utils::Node::name().compare(firstAxisMarkerNames[0])) {
545 if (!mark.utils::Node::name().compare(firstAxisMarkerNames[1])) {
549 if (!mark.utils::Node::name().compare(secondAxisMarkerNames[0])) {
553 if (!mark.utils::Node::name().compare(secondAxisMarkerNames[1])) {
558 if (!(isAxis1Beg && isAxis1End && isAxis2Beg && isAxis2End &&
561 "All the axes name and origin for the " + rtType +
"(" + name +
562 ") must be set and correspond to marker names "
563 "previously defined on the same parent");
565 if (!(!axisToRecalculate.
tolower().compare(
"firstaxis") ||
566 !axisToRecalculate.
tolower().compare(
"secondaxis"))) {
568 "The 'recalculate' option for " + rtType +
"(" + name +
569 ") must be 'firstaxis' or 'secondaxis'");
571 axisToRecalculate = !axisToRecalculate.
tolower().compare(
"firstaxis")
577 {axis1Beg, axis1End},
578 {axis2Beg, axis2End},
579 {firstAxis, secondAxis},
584 if (!main_tag.
tolower().compare(
"customrt")) {
587 model->
addIMU(RT, technical, anatomical);
589 }
else if (!main_tag.
tolower().compare(
"contact")) {
593 size_t parent_int = 0;
597 while (file.
read(property_tag) &&
598 property_tag.
tolower().compare(
"endcontact")) {
599 if (!property_tag.
tolower().compare(
"parent")) {
601 file.
read(parentName);
603 static_cast<size_t>(model->GetBodyId(parentName.c_str()));
606 model->IsBodyId(
static_cast<unsigned int>(parent_int)),
607 "Wrong name in a segment");
608 }
else if (!property_tag.
tolower().compare(
"position")) {
610 }
else if (!property_tag.
tolower().compare(
"normal")) {
612 }
else if (!property_tag.
tolower().compare(
"axis")) {
617 model->
AddConstraint(parent_int, pos, norm, name, parentName);
618 }
else if (version >= 2) {
620 model->
AddConstraint(parent_int, pos, axis, name, parentName);
622 }
else if (!main_tag.
tolower().compare(
"loopconstraint")) {
624 size_t id_predecessor = 0;
625 size_t id_successor = 0;
631 bool enableStabilization(
false);
632 double stabilizationParam(-1);
633 while (file.
read(property_tag) &&
634 property_tag.
tolower().compare(
"endloopconstraint")) {
635 if (!property_tag.
tolower().compare(
"predecessor")) {
637 file.
read(predecessor_str);
639 static_cast<size_t>(model->GetBodyId(predecessor_str.c_str()));
642 model->IsBodyId(
static_cast<unsigned int>(id_predecessor)),
643 "Wrong name in a segment");
645 if (!property_tag.
tolower().compare(
"successor")) {
647 file.
read(successor_str);
649 static_cast<size_t>(model->GetBodyId(successor_str.c_str()));
652 model->IsBodyId(
static_cast<unsigned int>(id_successor)),
653 "Wrong name in a segment");
654 }
else if (!property_tag.
tolower().compare(
"rtpredecessor")) {
665 }
else if (!property_tag.
tolower().compare(
"rtsuccessor")) {
676 }
else if (!property_tag.
tolower().compare(
"axis"))
677 for (
size_t i = 0; i < static_cast<size_t>(axis.size()); ++i) {
678 file.
read(axis(
static_cast<unsigned int>(i)), variable);
680 else if (!property_tag.
tolower().compare(
"stabilizationparameter")) {
681 file.
read(stabilizationParam, variable);
684 if (stabilizationParam > 0) {
685 enableStabilization =
true;
687 name =
"Loop_" + predecessor_str +
"_" + successor_str;
697 }
else if (!main_tag.
tolower().compare(
"softcontact")) {
700 size_t parent_int = 0;
705 double stiffness(-1);
708 double muDynamic(-1);
709 double muViscous(-1);
711 while (file.
read(property_tag) &&
712 property_tag.
tolower().compare(
"endsoftcontact")) {
713 if (!property_tag.
tolower().compare(
"parent")) {
715 file.
read(parent_str);
717 static_cast<size_t>(model->GetBodyId(parent_str.c_str()));
720 model->IsBodyId(
static_cast<unsigned int>(parent_int)),
721 "Wrong name in a segment");
722 }
else if (!property_tag.
tolower().compare(
"type")) {
723 file.
read(contactType);
724 }
else if (!property_tag.
tolower().compare(
"position")) {
726 }
else if (!property_tag.
tolower().compare(
"radius")) {
727 file.
read(radius, variable);
728 }
else if (!property_tag.
tolower().compare(
"stiffness")) {
729 file.
read(stiffness, variable);
730 }
else if (!property_tag.
tolower().compare(
"damping")) {
731 file.
read(damping, variable);
732 }
else if (!property_tag.
tolower().compare(
"muStatic")) {
733 file.
read(muStatic, variable);
734 }
else if (!property_tag.
tolower().compare(
"muDynamic")) {
735 file.
read(muDynamic, variable);
736 }
else if (!property_tag.
tolower().compare(
"muViscous")) {
737 file.
read(muViscous, variable);
741 if (!contactType.
tolower().compare(
"sphere")) {
753 static_cast<int>(parent_int)));
757 }
else if (!main_tag.
tolower().compare(
"actuator")) {
758#ifdef MODULE_ACTUATORS
764 size_t parent_int =
static_cast<size_t>(model->GetBodyId(name.c_str()));
767 model->IsBodyId(
static_cast<unsigned int>(parent_int)),
768 "Wrong name in a segment");
772 bool isTypeSet =
false;
773 size_t dofIdx(INT_MAX);
774 bool isDofSet =
false;
776 bool isDirectionSet =
false;
777 int int_direction = 0;
779 bool isTmaxSet =
false;
781 bool isT0Set =
false;
783 bool isSlopeSet =
false;
785 bool iswmaxSet =
false;
787 bool iswcSet =
false;
789 bool isaminSet =
false;
791 bool iswrSet =
false;
793 bool isw1Set =
false;
797 bool isqoptSet =
false;
798 double facteur6p(-1);
799 bool isFacteur6pSet =
false;
801 bool isr2Set =
false;
803 bool isqopt2Set =
false;
805 bool isThetaSet =
false;
807 bool isLambdaSet =
false;
809 bool isOffsetSet =
false;
811 while (file.
read(property_tag) &&
812 property_tag.
tolower().compare(
"endactuator")) {
813 if (!property_tag.
tolower().compare(
"type")) {
816 }
else if (!property_tag.
tolower().compare(
"dof")) {
821 }
else if (!property_tag.
tolower().compare(
"direction")) {
822 file.
read(str_direction);
824 !str_direction.
tolower().compare(
"positive") ||
825 !str_direction.
tolower().compare(
"negative"),
826 "Direction should be \"positive\" or \"negative\"");
827 if (!str_direction.
tolower().compare(
"positive")) {
832 isDirectionSet =
true;
833 }
else if (!property_tag.
tolower().compare(
"tmax")) {
834 file.
read(Tmax, variable);
836 }
else if (!property_tag.
tolower().compare(
"t0")) {
837 file.
read(T0, variable);
840 !property_tag.
tolower().compare(
"pente") ||
841 !property_tag.
tolower().compare(
"slope")) {
842 file.
read(slope, variable);
844 }
else if (!property_tag.
tolower().compare(
"wmax")) {
845 file.
read(wmax, variable);
847 }
else if (!property_tag.
tolower().compare(
"wc")) {
848 file.
read(wc, variable);
850 }
else if (!property_tag.
tolower().compare(
"amin")) {
851 file.
read(amin, variable);
853 }
else if (!property_tag.
tolower().compare(
"wr")) {
854 file.
read(wr, variable);
856 }
else if (!property_tag.
tolower().compare(
"w1")) {
857 file.
read(w1, variable);
859 }
else if (!property_tag.
tolower().compare(
"r")) {
860 file.
read(r, variable);
862 }
else if (!property_tag.
tolower().compare(
"qopt")) {
863 file.
read(qopt, variable);
865 }
else if (!property_tag.
tolower().compare(
"facteur")) {
866 file.
read(facteur6p, variable);
867 isFacteur6pSet =
true;
868 }
else if (!property_tag.
tolower().compare(
"r2")) {
869 file.
read(r2, variable);
871 }
else if (!property_tag.
tolower().compare(
"qopt2")) {
872 file.
read(qopt2, variable);
874 }
else if (!property_tag.
tolower().compare(
"theta")) {
875 file.
read(theta, variable);
877 }
else if (!property_tag.
tolower().compare(
"lambda")) {
878 file.
read(lambda, variable);
880 }
else if (!property_tag.
tolower().compare(
"offset")) {
881 file.
read(offset, variable);
889 if (!type.
tolower().compare(
"gauss3p")) {
891 isDofSet && isDirectionSet && isTmaxSet && isT0Set && iswmaxSet &&
892 iswcSet && isaminSet && iswrSet && isw1Set && isrSet &&
894 "Make sure all parameters are defined");
908 }
else if (!type.
tolower().compare(
"constant")) {
910 isDofSet && isDirectionSet && isTmaxSet,
911 "Make sure all parameters are defined");
913 int_direction, Tmax, dofIdx, name);
914 }
else if (!type.
tolower().compare(
"linear")) {
916 isDofSet && isDirectionSet && isSlopeSet && isT0Set,
917 "Make sure all parameters are defined");
919 int_direction, T0, slope, dofIdx, name);
920 }
else if (!type.
tolower().compare(
"gauss6p")) {
922 isDofSet && isDirectionSet && isTmaxSet && isT0Set && iswmaxSet &&
923 iswcSet && isaminSet && iswrSet && isw1Set && isrSet &&
924 isqoptSet && isFacteur6pSet && isr2Set && isqopt2Set,
925 "Make sure all parameters are defined");
942 }
else if (!type.
tolower().compare(
"sigmoidgauss3p")) {
944 isDofSet && isThetaSet && isLambdaSet && isOffsetSet && isrSet &&
946 "Make sure all parameters are defined");
948 int_direction, theta, lambda, offset, r, qopt, dofIdx, name);
951 "Actuator do not correspond to an implemented one");
961 model->addActuator(*actuator);
965 "Biorbd was build without the module Internal forces but the model "
968 }
else if (!main_tag.
tolower().compare(
"musclegroup")) {
976 while (file.
read(property_tag) &&
977 property_tag.
tolower().compare(
"endmusclegroup")) {
978 if (!property_tag.
tolower().compare(
"originparent")) {
980 file.
read(origin_parent_str);
981 size_t idx =
static_cast<size_t>(
982 model->GetBodyId(origin_parent_str.c_str()));
985 model->IsBodyId(
static_cast<unsigned int>(idx)),
986 "Wrong origin parent name for a muscle");
987 }
else if (!property_tag.
tolower().compare(
"insertionparent")) {
989 file.
read(insert_parent_str);
990 size_t idx =
static_cast<size_t>(
991 model->GetBodyId(insert_parent_str.c_str()));
994 model->IsBodyId(
static_cast<unsigned int>(idx)),
995 "Wrong insertion parent name for a muscle");
998 model->addMuscleGroup(name, origin_parent_str, insert_parent_str);
1001 "Biorbd was build without the module Muscles but the model defines "
1004 }
else if (!main_tag.
tolower().compare(
"muscle")) {
1005#ifdef MODULE_MUSCLES
1009 internal_forces::muscles::MUSCLE_TYPE type(
1010 internal_forces::muscles::MUSCLE_TYPE::NO_MUSCLE_TYPE);
1011 internal_forces::muscles::STATE_TYPE stateType(
1012 internal_forces::muscles::STATE_TYPE::NO_STATE_TYPE);
1013 internal_forces::muscles::STATE_FATIGUE_TYPE dynamicFatigueType(
1014 internal_forces::muscles::STATE_FATIGUE_TYPE::
1015 NO_FATIGUE_STATE_TYPE);
1020 double optimalLength(0);
1022 double tendonSlackLength(0);
1023 double pennAngle(0);
1024 bool useDamping(
false);
1025 double maxExcitation(1);
1026 double maxActivation(1);
1028 double shapeFactor(0);
1029 double maxShorteningSpeed(10);
1033 while (file.
read(property_tag) &&
1034 property_tag.
tolower().compare(
"endmuscle")) {
1035 if (!property_tag.
tolower().compare(
"musclegroup")) {
1037 file.
read(muscleGroup);
1038 idxGroup = model->getMuscleGroupId(muscleGroup);
1041 }
else if (!property_tag.
tolower().compare(
"type")) {
1044 if (!tp_type.
tolower().compare(
"idealizedactuator")) {
1045 type = internal_forces::muscles::MUSCLE_TYPE::IDEALIZED_ACTUATOR;
1046 }
else if (!tp_type.
tolower().compare(
"hill")) {
1047 type = internal_forces::muscles::MUSCLE_TYPE::HILL;
1049 !tp_type.
tolower().compare(
"hilldegroote") ||
1050 !tp_type.
tolower().compare(
"degroote")) {
1051 type = internal_forces::muscles::MUSCLE_TYPE::HILL_DE_GROOTE;
1053 !tp_type.
tolower().compare(
"hillthelen") ||
1054 !tp_type.
tolower().compare(
"thelen")) {
1055 type = internal_forces::muscles::MUSCLE_TYPE::HILL_THELEN;
1057 !tp_type.
tolower().compare(
"hillthelenactive") ||
1058 !tp_type.
tolower().compare(
"thelenactive")) {
1059 type = internal_forces::muscles::MUSCLE_TYPE::HILL_THELEN_ACTIVE;
1061 !tp_type.
tolower().compare(
"hilldegrooteactive") ||
1062 !tp_type.
tolower().compare(
"degrooteactive")) {
1064 internal_forces::muscles::MUSCLE_TYPE::HILL_DE_GROOTE_ACTIVE;
1066 !tp_type.
tolower().compare(
"hillthelenfatigable") ||
1067 !tp_type.
tolower().compare(
"thelenfatigable")) {
1069 internal_forces::muscles::MUSCLE_TYPE::HILL_THELEN_FATIGABLE;
1071 !tp_type.
tolower().compare(
"hilldegrootefatigable") ||
1072 !tp_type.
tolower().compare(
"degrootefatigable")) {
1073 type = internal_forces::muscles::MUSCLE_TYPE::
1074 HILL_DE_GROOTE_FATIGABLE;
1078 }
else if (!property_tag.
tolower().compare(
"statetype")) {
1080 file.
read(tp_state);
1081 if (!tp_state.
tolower().compare(
"buchanan")) {
1082 stateType = internal_forces::muscles::STATE_TYPE::BUCHANAN;
1083 }
else if (!tp_state.
tolower().compare(
"degroote")) {
1084 stateType = internal_forces::muscles::STATE_TYPE::DE_GROOTE;
1087 property_tag +
" is not a valid muscle state type");
1089 }
else if (!property_tag.
tolower().compare(
"usedamping")) {
1090 file.
read(useDamping);
1091 }
else if (!property_tag.
tolower().compare(
"originposition")) {
1093 }
else if (!property_tag.
tolower().compare(
"insertionposition")) {
1095 }
else if (!property_tag.
tolower().compare(
"optimallength")) {
1096 file.
read(optimalLength, variable);
1097 }
else if (!property_tag.
tolower().compare(
"tendonslacklength")) {
1098 file.
read(tendonSlackLength, variable);
1099 }
else if (!property_tag.
tolower().compare(
"pennationangle")) {
1100 file.
read(pennAngle, variable);
1101 }
else if (!property_tag.
tolower().compare(
"maximalforce")) {
1102 file.
read(maxForce, variable);
1103 }
else if (!property_tag.
tolower().compare(
"maximalexcitation")) {
1104 file.
read(maxExcitation, variable);
1105 }
else if (!property_tag.
tolower().compare(
"pcsa")) {
1106 file.
read(PCSA, variable);
1107 }
else if (!property_tag.
tolower().compare(
"maxshorteningspeed")) {
1108 file.
read(maxShorteningSpeed, variable);
1109 }
else if (!property_tag.
tolower().compare(
"fatigueparameters")) {
1110 while (file.
read(subproperty_tag) &&
1111 subproperty_tag.
tolower().compare(
"endfatigueparameters")) {
1112 if (!subproperty_tag.
tolower().compare(
"type")) {
1114 file.
read(tp_fatigue_type);
1115 if (!tp_fatigue_type.
tolower().compare(
"simple")) {
1116 dynamicFatigueType = internal_forces::muscles::
1117 STATE_FATIGUE_TYPE::SIMPLE_STATE_FATIGUE;
1118 }
else if (!tp_fatigue_type.
tolower().compare(
"xia")) {
1119 dynamicFatigueType =
1120 internal_forces::muscles::STATE_FATIGUE_TYPE::DYNAMIC_XIA;
1124 " is not a value fatigue parameter type");
1129 if (!subproperty_tag.
tolower().compare(
"fatiguerate")) {
1131 }
else if (!subproperty_tag.
tolower().compare(
"recoveryrate")) {
1133 }
else if (!subproperty_tag.
tolower().compare(
1136 }
else if (!subproperty_tag.
tolower().compare(
1137 "recoveryfactor")) {
1142 }
else if (!property_tag.
tolower().compare(
"shapefactor")) {
1143 file.
read(shapeFactor);
1151 model->muscleGroup(
static_cast<size_t>(idxGroup)).origin()),
1154 name +
"_insertion",
1155 model->muscleGroup(
static_cast<size_t>(idxGroup)).insertion()));
1166 maxShorteningSpeed);
1167 model->muscleGroup(
static_cast<size_t>(idxGroup))
1175 dynamicFatigueType);
1176 if (stateType == internal_forces::muscles::STATE_TYPE::BUCHANAN &&
1178 auto &muscleGroup = model->muscleGroup(idxGroup);
1179 int nMuscInGroup(
static_cast<int>(muscleGroup.nbMuscles() - 1));
1180 auto &state = muscleGroup.muscle(nMuscInGroup).state();
1182 .shapeFactor(shapeFactor);
1186 "Biorbd was build without the module Muscles but the model defines "
1189 }
else if (!main_tag.
tolower().compare(
"ligament")) {
1190#ifdef MODULE_LIGAMENTS
1196 bool isTypeSet =
false;
1199 double ligamentSlackLength(std::numeric_limits<double>::quiet_NaN());
1200 double stiffness(std::numeric_limits<double>::quiet_NaN());
1202 double force(std::numeric_limits<double>::quiet_NaN());
1203 double dampingFactor(0);
1204 double maxShorteningSpeed(1);
1206 while (file.
read(property_tag) &&
1207 property_tag.
tolower().compare(
"endligament")) {
1208 if (!property_tag.
tolower().compare(
"type")) {
1211 }
else if (!property_tag.
tolower().compare(
"originposition")) {
1213 }
else if (!property_tag.
tolower().compare(
"insertionposition")) {
1215 }
else if (!property_tag.
tolower().compare(
"ligamentslacklength")) {
1216 file.
read(ligamentSlackLength, variable);
1217 }
else if (!property_tag.
tolower().compare(
"stiffness")) {
1218 file.
read(stiffness, variable);
1219 }
else if (!property_tag.
tolower().compare(
"epsilon")) {
1220 file.
read(epsilon, variable);
1221 }
else if (!property_tag.
tolower().compare(
"force")) {
1222 file.
read(force, variable);
1223 }
else if (!property_tag.
tolower().compare(
"origin")) {
1225 }
else if (!property_tag.
tolower().compare(
"insertion")) {
1226 file.
read(insertion);
1227 }
else if (!property_tag.
tolower().compare(
"dampingfactor")) {
1228 file.
read(dampingFactor, variable);
1229 }
else if (!property_tag.
tolower().compare(
"maxshorteningspeed")) {
1230 file.
read(maxShorteningSpeed, variable);
1235 std::shared_ptr<internal_forces::ligaments::Ligament> ligament;
1237 insertion !=
"" && origin !=
"",
1238 "Insertion and origin of the ligament need to be defined.");
1243 ligamentSlackLength, dampingFactor, maxShorteningSpeed);
1244 if (!type.
tolower().compare(
"constant")) {
1246 std::isnan(force) == 0 && std::isnan(ligamentSlackLength) == 0,
1247 "Make sure all parameters are defined");
1249 std::make_shared<internal_forces::ligaments::LigamentConstant>(
1250 force, name, geo, characteristics);
1251 }
else if (!type.
tolower().compare(
"linearspring")) {
1253 std::isnan(stiffness) == 0 &&
1254 std::isnan(ligamentSlackLength) == 0,
1255 "Make sure all parameters are defined");
1256 ligament = std::make_shared<
1258 stiffness, name, geo, characteristics);
1259 }
else if (!type.
tolower().compare(
"secondorderspring")) {
1261 std::isnan(stiffness) == 0 &&
1262 std::isnan(ligamentSlackLength) == 0,
1263 "Make sure all parameters are defined");
1264 ligament = std::make_shared<
1266 stiffness, epsilon, name, geo, characteristics);
1269 "Ligament type do not correspond to an implemented one");
1271 model->addLigament(*ligament);
1274 "Biorbd was build without the module Ligament but the model "
1275 "defines a ligament");
1277 }
else if (!main_tag.
tolower().compare(
"passivetorque")) {
1278#ifdef MODULE_PASSIVE_TORQUES
1281 size_t parent_int =
static_cast<size_t>(model->GetBodyId(name.c_str()));
1284 model->IsBodyId(
static_cast<unsigned int>(parent_int)),
1285 "Wrong name in a segment");
1288 bool isTypeSet =
false;
1289 size_t dofIdx(INT_MAX);
1290 bool isDofSet =
false;
1291 double Tconstant(std::numeric_limits<double>::quiet_NaN());
1292 double T0(std::numeric_limits<double>::quiet_NaN());
1293 double slope(std::numeric_limits<double>::quiet_NaN());
1294 double k1(std::numeric_limits<double>::quiet_NaN());
1295 double k2(std::numeric_limits<double>::quiet_NaN());
1296 double b1(std::numeric_limits<double>::quiet_NaN());
1297 double b2(std::numeric_limits<double>::quiet_NaN());
1298 double wMax(std::numeric_limits<double>::quiet_NaN());
1304 double isExponentialSet(0);
1306 while (file.
read(property_tag) &&
1307 property_tag.
tolower().compare(
"endpassivetorque")) {
1308 if (!property_tag.
tolower().compare(
"type")) {
1311 }
else if (!property_tag.
tolower().compare(
"dof")) {
1316 }
else if (!property_tag.
tolower().compare(
"torque")) {
1317 file.
read(Tconstant, variable);
1318 }
else if (!property_tag.
tolower().compare(
"t0")) {
1319 file.
read(T0, variable);
1321 !property_tag.
tolower().compare(
"pente") ||
1322 !property_tag.
tolower().compare(
"slope")) {
1323 file.
read(slope, variable);
1324 }
else if (!property_tag.
tolower().compare(
"k1")) {
1325 file.
read(k1, variable);
1326 isExponentialSet += 1;
1327 }
else if (!property_tag.
tolower().compare(
"k2")) {
1328 file.
read(k2, variable);
1329 isExponentialSet += 1;
1330 }
else if (!property_tag.
tolower().compare(
"b1")) {
1331 file.
read(b1, variable);
1332 isExponentialSet += 1;
1333 }
else if (!property_tag.
tolower().compare(
"b2")) {
1334 file.
read(b2, variable);
1335 isExponentialSet += 1;
1336 }
else if (!property_tag.
tolower().compare(
"wmax")) {
1337 file.
read(wMax, variable);
1338 isExponentialSet += 1;
1339 }
else if (!property_tag.
tolower().compare(
"qmid")) {
1340 file.
read(qMid, variable);
1341 }
else if (!property_tag.
tolower().compare(
"deltap")) {
1342 file.
read(deltaP, variable);
1343 }
else if (!property_tag.
tolower().compare(
"sv")) {
1344 file.
read(sV, variable);
1345 }
else if (!property_tag.
tolower().compare(
"taueq")) {
1346 file.
read(tauEq, variable);
1347 }
else if (!property_tag.
tolower().compare(
"pbeta")) {
1348 file.
read(pBeta, variable);
1353 isTypeSet != 0,
"PassiveTorque type must be defined");
1355 if (!type.
tolower().compare(
"constant")) {
1357 isDofSet && !std::isnan(Tconstant),
1358 "Make sure all parameters are defined");
1361 Tconstant, dofIdx, name);
1362 }
else if (!type.
tolower().compare(
"linear")) {
1364 isDofSet && !std::isnan(slope) && !std::isnan(T0),
1365 "Make sure all parameters are defined");
1368 T0, slope, dofIdx, name);
1369 }
else if (!type.
tolower().compare(
"exponential")) {
1371 isDofSet && isExponentialSet == 5,
1372 "Make sure all parameters are defined");
1389 "PassiveTorque do not correspond to an implemented one");
1391 model->addPassiveTorque(*passiveTorque);
1392 delete passiveTorque;
1395 "Biorbd was build without the module Passive torque but the model "
1396 "defines one passive torque");
1398 }
else if (!main_tag.
tolower().compare(
"viapoint")) {
1406 bool isMuscle =
false;
1407 bool isLigament =
false;
1408 int idxMuscleGroup(-1);
1409 int idxLigament(-1);
1415 while (file.
read(property_tag) &&
1416 property_tag.
tolower().compare(
"endviapoint")) {
1417 if (!property_tag.
tolower().compare(
"parent")) {
1420 size_t idx =
static_cast<size_t>(model->GetBodyId(parent.c_str()));
1423 model->IsBodyId(
static_cast<unsigned int>(idx)),
1424 "Wrong origin parent name for a muscle");
1425 }
else if (!property_tag.
tolower().compare(
"muscle")) {
1430 "Via point cannot be define either for ligament and muscle.");
1431 }
else if (!property_tag.
tolower().compare(
"musclegroup")) {
1432 file.
read(musclegroup);
1433 }
else if (!property_tag.
tolower().compare(
"ligament")) {
1434 file.
read(ligament);
1438 "Via point cannot be define either for ligament and muscle.");
1439 }
else if (!property_tag.
tolower().compare(
"position")) {
1446 idxMuscleGroup = model->getMuscleGroupId(musclegroup);
1448 idxMuscleGroup != -1,
"No muscle group was provided!");
1449 idxMuscle = model->muscleGroup(idxMuscleGroup).muscleID(muscle);
1451 model->muscleGroup(idxMuscleGroup)
1453 .addPathObject(position);
1454 }
else if (isLigament) {
1455 idxLigament = model->ligamentID(ligament);
1456 model->ligament(idxLigament).addPathObject(position);
1458 }
else if (!main_tag.
tolower().compare(
"wrapping")) {
1466 int idxMuscleGroup(-1);
1469 bool isMuscle =
false;
1470 bool isLigament =
false;
1471 int idxLigament(-1);
1474 bool isRTset(
false);
1475 bool RTinMatrix(
false);
1480 while (file.
read(property_tag) &&
1481 property_tag.
tolower().compare(
"endwrapping")) {
1482 if (!property_tag.
tolower().compare(
"parent")) {
1485 size_t idx =
static_cast<size_t>(model->GetBodyId(parent.c_str()));
1488 model->IsBodyId(
static_cast<unsigned int>(idx)),
1489 "Wrong origin parent name for a muscle");
1490 }
else if (!property_tag.
tolower().compare(
"rtinmatrix")) {
1492 isRTset ==
false,
"RT should not appear before RTinMatrix");
1493 file.
read(RTinMatrix);
1494 }
else if (!property_tag.
tolower().compare(
"rt")) {
1497 }
else if (!property_tag.
tolower().compare(
"type")) {
1498 file.
read(wrapType);
1499 }
else if (!property_tag.
tolower().compare(
"muscle")) {
1504 "Wrapping object cannot be define either for "
1505 "ligament and muscle.");
1506 }
else if (!property_tag.
tolower().compare(
"musclegroup")) {
1507 file.
read(musclegroup);
1508 }
else if (!property_tag.
tolower().compare(
"ligament")) {
1509 file.
read(ligament);
1513 "Wrapping object cannot be define either for "
1514 "ligament and muscle.");
1515 }
else if (!property_tag.
tolower().compare(
"radius")) {
1516 file.
read(radius, variable);
1517 }
else if (!property_tag.
tolower().compare(
"length")) {
1518 file.
read(length, variable);
1522 if (!wrapType.
tolower().compare(
"halfcylinder")) {
1524 radius > 0.0,
"Radius must be defined and positive");
1528 "Wrapping type must be defined (choices: 'halfcylinder')");
1531 RT, radius, length, name, parent);
1533 idxMuscleGroup = model->getMuscleGroupId(musclegroup);
1535 idxMuscleGroup != -1,
"No muscle group was provided!");
1536 idxMuscle = model->muscleGroup(idxMuscleGroup).muscleID(muscle);
1538 model->muscleGroup(idxMuscleGroup)
1540 .addPathObject(cylinder);
1541 }
else if (isLigament) {
1542 idxLigament = model->ligamentID(ligament);
1543 model->ligament(idxLigament).addPathObject(cylinder);
1547 }
catch (std::runtime_error message) {
1550 "\" failed with the following error:");
1551 error_message +=
"\n" +
utils::String(message.what()) +
"\n";
1552 if (name.compare(
"")) {
1553 error_message +=
"Element: " + main_tag +
", named: " + name +
"\n";
1555 if (property_tag.compare(
"") && property_tag.find_first_of(
"end") != 0) {
1556 error_message +=
"Property: " + property_tag +
"\n";
1558 if (subproperty_tag.compare(
"") &&
1559 subproperty_tag.find_first_of(
"end") != 0) {
1560 error_message +=
"Subproperty: " + subproperty_tag +
"\n";
1565#ifdef MODULE_ACTUATORS
1567 model->closeActuator();