1 #define BIORBD_API_EXPORTS
2 #include "ModelReader.h"
6 #include "BiorbdModel.h"
7 #include "Utils/Error.h"
8 #include "Utils/IfStream.h"
9 #include "Utils/String.h"
10 #include "Utils/Equation.h"
11 #include "Utils/Vector.h"
12 #include "Utils/Vector3d.h"
13 #include "Utils/Rotation.h"
14 #include "Utils/Range.h"
15 #include "Utils/SpatialVector.h"
16 #include "RigidBody/GeneralizedCoordinates.h"
17 #include "RigidBody/Mesh.h"
18 #include "RigidBody/SegmentCharacteristics.h"
19 #include "RigidBody/IMU.h"
20 #include "RigidBody/MeshFace.h"
21 #include "RigidBody/NodeSegment.h"
23 #ifdef MODULE_ACTUATORS
24 #include "Actuators/ActuatorConstant.h"
25 #include "Actuators/ActuatorLinear.h"
26 #include "Actuators/ActuatorGauss3p.h"
27 #include "Actuators/ActuatorGauss6p.h"
28 #endif // MODULE_ACTUATORS
31 #include "Muscles/Muscle.h"
32 #include "Muscles/Geometry.h"
33 #include "Muscles/MuscleGroup.h"
34 #include "Muscles/ViaPoint.h"
35 #include "Muscles/WrappingCylinder.h"
36 #include "Muscles/FatigueParameters.h"
37 #include "Muscles/State.h"
38 #include "Muscles/Characteristics.h"
39 #include "Muscles/ViaPoint.h"
40 #include "Muscles/PathModifiers.h"
41 #endif // MODULE_MUSCLES
58 +
" could not be open");
75 std::map<biorbd::utils::Equation, double> variable;
79 unsigned int version(
static_cast<unsigned int>(atoi(main_tag.c_str())));
81 "Version " + main_tag +
" is not implemented yet");
83 #ifdef MODULE_ACTUATORS
84 bool hasActuators =
false;
85 #endif // MODULE_ACTUATORS
89 while(file.
read(main_tag)){
96 if (!main_tag.
tolower().compare(
"segment")){
101 bool RTinMatrix(
true);
105 double mass = 0.00000001;
106 RigidBodyDynamics::Math::Matrix3d inertia(RigidBodyDynamics::Math::Matrix3d::Identity());
111 int segmentByFile(-1);
113 std::vector<biorbd::utils::Range> QRanges;
114 std::vector<biorbd::utils::Range> QDotRanges;
115 std::vector<biorbd::utils::Range> QDDotRanges;
116 bool isRangeQSet(
false);
117 bool isRangeQDotSet(
false);
118 bool isRangeQDDotSet(
false);
119 while(file.
read(property_tag) && property_tag.
tolower().compare(
"endsegment")){
120 if (!property_tag.
tolower().compare(
"parent")){
122 file.
read(parent_str);
123 if (parent_str.
tolower().compare(
"root"))
126 else if (!property_tag.
tolower().compare(
"translations")){
128 !isRangeQSet,
"Translations must appear before the rangesq tag");
130 !isRangeQDotSet,
"Translations must appear before the rangesqdot tag");
132 !isRangeQDDotSet,
"Translations must appear before the rangesqddot tag");
135 else if (!property_tag.
tolower().compare(
"rotations")){
137 !isRangeQSet,
"Rotations must appear before the rangesq tag");
139 !isRangeQDotSet,
"Rotations must appear before the rangesqdot tag");
141 !isRangeQDDotSet,
"Rotations must appear before the rangesqddot tag");
144 else if (!property_tag.
tolower().compare(
"ranges") ||
145 !property_tag.
tolower().compare(
"rangesq")){
148 if (rot.compare(
"q")){
150 rotLength = rot.length();
152 for (
size_t i=0; i<trans.length() + rotLength; ++i){
160 else if (!property_tag.
tolower().compare(
"rangesqdot")){
163 if (rot.compare(
"q")){
165 rotLength = rot.length();
167 for (
size_t i=0; i<trans.length() + rotLength; ++i){
170 QDotRanges.push_back(
173 isRangeQDotSet =
true;
175 else if (!property_tag.
tolower().compare(
"rangesqddot")){
178 if (rot.compare(
"q")){
180 rotLength = rot.length();
182 for (
size_t i=0; i<trans.length() + rotLength; ++i){
185 QDDotRanges.push_back(
188 isRangeQDDotSet =
true;
190 else if (!property_tag.
tolower().compare(
"mass"))
191 file.
read(mass, variable);
192 else if (!property_tag.
tolower().compare(
"inertia")){
193 for (
unsigned int i=0; i<3;++i){
194 for (
unsigned int j=0; j<3; ++j){
195 file.
read(inertia(i,j), variable);
199 else if (!property_tag.
tolower().compare(
"rtinmatrix")){
201 file.
read(RTinMatrix);
203 else if (!property_tag.
tolower().compare(
"rt")){
206 for (
unsigned int i=0; i<3;++i){
207 for (
unsigned int j=0; j<4; ++j){
209 file.
read(RT_R(j, i), variable);
211 file.
read(RT_T(i), variable);
221 for (
unsigned int i=0; i<3; ++i)
226 for (
unsigned int i=0; i<3; ++i)
229 RT_R = RT.
rot().transpose();
236 else if (!property_tag.
tolower().compare(
"com"))
237 for (
unsigned int i=0; i<3; ++i)
238 file.
read(com(i), variable);
239 else if (!property_tag.
tolower().compare(
"forceplate") || !property_tag.
tolower().compare(
"externalforceindex"))
241 else if (!property_tag.
tolower().compare(
"mesh")){
242 if (segmentByFile==-1)
244 else if (segmentByFile == 1)
247 for (
unsigned int i=0; i<3; ++i)
248 file.
read(tp(i), variable);
251 else if (!property_tag.
tolower().compare(
"patch")){
252 if (segmentByFile==-1)
254 else if (segmentByFile == 1)
257 for (
unsigned int i=0; i<3; ++i)
261 else if (!property_tag.
tolower().compare(
"meshfile")){
262 if (segmentByFile==-1)
264 else if (segmentByFile == 0)
267 file.
read(filePathInString);
269 if (!filePath.
extension().compare(
"bioMesh"))
271 else if (!filePath.
extension().compare(
"ply"))
273 else if (!filePath.
extension().compare(
"obj"))
275 #ifdef MODULE_VTP_FILES_READER
276 else if (!filePath.
extension().compare(
"vtp"))
285 if (rot.compare(
"q")){
287 rotLength = rot.length();
289 for (
size_t i=0; i<trans.length() + rotLength; ++i){
294 if (!isRangeQDotSet){
296 if (rot.compare(
"q")){
298 rotLength = rot.length();
300 for (
size_t i=0; i<trans.length() + rotLength; ++i){
301 QDotRanges.push_back(
305 if (!isRangeQDDotSet){
307 if (rot.compare(
"q")){
309 rotLength = rot.length();
311 for (
size_t i=0; i<trans.length() + rotLength; ++i){
312 QDDotRanges.push_back(
316 RigidBodyDynamics::Math::SpatialTransform RT(RT_R, RT_T);
318 model->
AddSegment(name, parent_str, trans, rot, QRanges, QDotRanges, QDDotRanges, characteristics, RT, PF);
320 else if (!main_tag.
tolower().compare(
"gravity")){
322 for (
unsigned int i=0; i<3; ++i)
323 file.
read(gravity(i), variable);
324 model->gravity = gravity;
326 else if (!main_tag.
tolower().compare(
"variables")){
328 while(file.
read(var) && var.
tolower().compare(
"endvariables")){
329 if (!var(0).compare(
"$")){
333 variable[var] = value;
337 else if (!main_tag.
tolower().compare(
"marker")){
340 unsigned int parent_int = 0;
343 bool technical =
true;
344 bool anatomical =
false;
346 while(file.
read(property_tag) && property_tag.
tolower().compare(
"endmarker"))
347 if (!property_tag.
tolower().compare(
"parent")){
349 file.
read(parent_str);
350 parent_int = model->GetBodyId(parent_str.c_str());
354 else if (!property_tag.
tolower().compare(
"position"))
355 for (
unsigned int i=0; i<3; ++i)
356 file.
read(pos(i), variable);
357 else if (!property_tag.
tolower().compare(
"technical"))
358 file.
read(technical);
359 else if (!property_tag.
tolower().compare(
"anatomical"))
360 file.
read(anatomical);
361 else if (!property_tag.
tolower().compare(
"axestoremove"))
362 file.
read(axesToRemove);
364 model->
addMarker(pos, name, parent_str, technical, anatomical, axesToRemove,
static_cast<int>(parent_int));
366 else if (!main_tag.
tolower().compare(
"mimu") && version >= 4){
369 else if (!main_tag.
tolower().compare(
"imu") || !main_tag.
tolower().compare(
"mimu") || !main_tag.
tolower().compare(
"customrt")){
374 bool RTinMatrix(
true);
378 bool technical =
true;
379 bool anatomical =
false;
380 bool firstTag =
true;
381 bool fromMarkers(
false);
384 std::vector<biorbd::utils::String> firstAxisMarkerNames(2);
386 std::vector<biorbd::utils::String> secondAxisMarkerNames(2);
388 while(file.
read(property_tag) && !(!property_tag.
tolower().compare(
"endimu")
389 || !property_tag.
tolower().compare(
"endmimu")
390 || !property_tag.
tolower().compare(
"endcustomrt"))){
391 if (!property_tag.
tolower().compare(
"parent")){
393 file.
read(parent_str);
397 else if (!property_tag.
tolower().compare(
"frommarkers")){
405 else if (!property_tag.
tolower().compare(
"technical"))
406 file.
read(technical);
407 else if (!property_tag.
tolower().compare(
"anatomical"))
408 file.
read(anatomical);
411 if (!property_tag.
tolower().compare(
"originmarkername")){
412 file.
read(originMarkerName);
414 else if (!property_tag.
tolower().compare(
"firstaxis")){
415 file.
read(firstAxis);
417 else if (!property_tag.
tolower().compare(
"firstaxismarkernames")){
418 for (
unsigned int i = 0; i<2; ++i){
419 file.
read(firstAxisMarkerNames[i]);
422 else if (!property_tag.
tolower().compare(
"secondaxis")){
423 file.
read(secondAxis);
425 else if (!property_tag.
tolower().compare(
"secondaxismarkernames")){
426 for (
unsigned int i = 0; i<2; ++i){
427 file.
read(secondAxisMarkerNames[i]);
430 else if (!property_tag.
tolower().compare(
"recalculate")){
431 file.
read(axisToRecalculate);
435 if (!property_tag.
tolower().compare(
"rtinmatrix")){
437 file.
read(RTinMatrix);
439 else if (!property_tag.
tolower().compare(
"rt")){
441 for (
unsigned int i=0; i<4;++i)
442 for (
unsigned int j=0; j<4;++j)
443 file.
read(RT(i,j), variable);
450 for (
unsigned int i=0; i<3; ++i)
455 for (
unsigned int i=0; i<3; ++i)
464 std::vector<biorbd::rigidbody::NodeSegment> allMarkerOnSegment(model->
marker(parent_str));
466 bool isOrigin(
false), isAxis1Beg(
false), isAxis1End(
false), isAxis2Beg(
false), isAxis2End(
false);
467 for (
auto mark : allMarkerOnSegment){
468 if (!mark.biorbd::utils::Node::name().compare(originMarkerName)){
472 if (!mark.biorbd::utils::Node::name().compare(firstAxisMarkerNames[0])){
476 if (!mark.biorbd::utils::Node::name().compare(firstAxisMarkerNames[1])){
480 if (!mark.biorbd::utils::Node::name().compare(secondAxisMarkerNames[0])){
484 if (!mark.biorbd::utils::Node::name().compare(secondAxisMarkerNames[1])){
489 if (! (isAxis1Beg && isAxis1End && isAxis2Beg && isAxis2End)){
490 biorbd::utils::Error::raise(
"All the axes name and origin for the IMU " + name +
" must be set and correspond to marker names previously defined on the same parent");
492 if (!(!axisToRecalculate.
tolower().compare(
"firstaxis") || !axisToRecalculate.
tolower().compare(
"secondaxis"))){
495 axisToRecalculate = !axisToRecalculate.
tolower().compare(
"firstaxis") ? firstAxis : secondAxis;
499 {axis1Beg, axis1End},
500 {axis2Beg, axis2End},
501 {firstAxis, secondAxis}, axisToRecalculate);
505 if (!main_tag.
tolower().compare(
"customrt")){
509 model->
addIMU(RT, technical, anatomical);
512 else if (!main_tag.
tolower().compare(
"contact")){
515 unsigned int parent_int = 0;
521 while(file.
read(property_tag) && property_tag.
tolower().compare(
"endcontact")){
522 if (!property_tag.
tolower().compare(
"parent")){
524 file.
read(parent_str);
525 parent_int = model->GetBodyId(parent_str.c_str());
529 else if (!property_tag.
tolower().compare(
"position"))
530 for (
unsigned int i=0; i<3; ++i)
531 file.
read(pos(i), variable);
532 else if (!property_tag.
tolower().compare(
"normal"))
533 for (
unsigned int i=0; i<3; ++i)
534 file.
read(norm(i), variable);
535 else if (!property_tag.
tolower().compare(
"axis"))
537 else if (!property_tag.
tolower().compare(
"acceleration"))
538 file.
read(acc, variable);
541 #ifndef BIORBD_USE_CASADI_MATH
546 else if (version >= 2){
551 else if (!main_tag.
tolower().compare(
"loopconstraint")){
553 unsigned int id_predecessor = 0;
554 unsigned int id_successor = 0;
560 bool enableStabilization(
false);
561 double stabilizationParam(-1);
562 while(file.
read(property_tag) && property_tag.
tolower().compare(
"endloopconstraint")){
563 if (!property_tag.
tolower().compare(
"predecessor")){
565 file.
read(predecessor_str);
566 id_predecessor = model->GetBodyId(predecessor_str.c_str());
570 if (!property_tag.
tolower().compare(
"successor")){
572 file.
read(successor_str);
573 id_successor = model->GetBodyId(successor_str.c_str());
576 }
else if (!property_tag.
tolower().compare(
"rtpredecessor")){
581 for (
unsigned int i=0; i<3; ++i)
586 for (
unsigned int i=0; i<3; ++i)
589 }
else if (!property_tag.
tolower().compare(
"rtsuccessor")){
594 for (
unsigned int i=0; i<3; ++i)
599 for (
unsigned int i=0; i<3; ++i)
602 }
else if (!property_tag.
tolower().compare(
"axis"))
603 for (
unsigned int i=0; i<axis.size(); ++i)
604 file.
read(axis(i), variable);
605 else if (!property_tag.
tolower().compare(
"stabilizationparameter"))
606 file.
read(stabilizationParam, variable);
608 if (stabilizationParam > 0)
609 enableStabilization =
true;
610 name =
"Loop_" + predecessor_str +
"_" + successor_str;
611 model->
AddLoopConstraint(id_predecessor, id_successor, X_predecessor, X_successor,
612 axis, name, enableStabilization, stabilizationParam);
614 else if (!main_tag.
tolower().compare(
"actuator")) {
615 #ifdef MODULE_ACTUATORS
620 unsigned int parent_int = model->GetBodyId(name.c_str());
626 unsigned int dofIdx(INT_MAX);
bool isDofSet =
false;
628 int int_direction = 0;
629 double Tmax(-1);
bool isTmaxSet =
false;
630 double T0(-1);
bool isT0Set =
false;
631 double slope(-1);
bool isSlopeSet =
false;
632 double wmax(-1);
bool iswmaxSet =
false;
633 double wc(-1);
bool iswcSet =
false;
634 double amin(-1);
bool isaminSet =
false;
635 double wr(-1);
bool iswrSet =
false;
636 double w1(-1);
bool isw1Set =
false;
637 double r(-1);
bool isrSet =
false;
638 double qopt(-1);
bool isqoptSet =
false;
639 double facteur6p(-1);
bool isFacteur6pSet =
false;
640 double r2(-1);
bool isr2Set =
false;
641 double qopt2(-1);
bool isqopt2Set =
false;
644 while(file.
read(property_tag) && property_tag.
tolower().compare(
"endactuator")){
645 if (!property_tag.
tolower().compare(
"type")){
649 else if (!property_tag.
tolower().compare(
"dof")){
655 else if (!property_tag.
tolower().compare(
"direction")){
656 file.
read(str_direction);
658 !str_direction.
tolower().compare(
"negative"),
659 "Direction should be \"positive\" or \"negative\"");
660 if (!str_direction.
tolower().compare(
"positive"))
664 isDirectionSet =
true;
666 else if (!property_tag.
tolower().compare(
"tmax")){
667 file.
read(Tmax, variable);
670 else if (!property_tag.
tolower().compare(
"t0")){
671 file.
read(T0, variable);
674 else if (!property_tag.
tolower().compare(
"pente") || !property_tag.
tolower().compare(
"slope")){
675 file.
read(slope, variable);
678 else if (!property_tag.
tolower().compare(
"wmax")){
679 file.
read(wmax, variable);
682 else if (!property_tag.
tolower().compare(
"wc")){
683 file.
read(wc, variable);
686 else if (!property_tag.
tolower().compare(
"amin")){
687 file.
read(amin, variable);
690 else if (!property_tag.
tolower().compare(
"wr")){
691 file.
read(wr, variable);
694 else if (!property_tag.
tolower().compare(
"w1")){
695 file.
read(w1, variable);
698 else if (!property_tag.
tolower().compare(
"r")){
699 file.
read(r, variable);
702 else if (!property_tag.
tolower().compare(
"qopt")){
703 file.
read(qopt, variable);
706 else if (!property_tag.
tolower().compare(
"facteur")){
707 file.
read(facteur6p, variable);
708 isFacteur6pSet =
true;
710 else if (!property_tag.
tolower().compare(
"r2")){
711 file.
read(r2, variable);
714 else if (!property_tag.
tolower().compare(
"qopt2")){
715 file.
read(qopt2, variable);
723 if (!type.
tolower().compare(
"gauss3p")){
725 iswrSet && isw1Set && isrSet && isqoptSet,
726 "Make sure all parameters are defined");
727 actuator =
new biorbd::actuator::ActuatorGauss3p(int_direction,Tmax,T0,wmax,wc,amin,wr,w1,r,qopt,dofIdx,name);
729 else if (!type.
tolower().compare(
"constant")){
731 "Make sure all parameters are defined");
734 else if (!type.
tolower().compare(
"linear")){
736 "Make sure all parameters are defined");
739 else if (!type.
tolower().compare(
"gauss6p")){
741 iswrSet && isw1Set && isrSet && isqoptSet && isFacteur6pSet && isr2Set && isqopt2Set,
742 "Make sure all parameters are defined");
743 actuator =
new biorbd::actuator::ActuatorGauss6p(int_direction,Tmax,T0,wmax,wc,amin,wr,w1,r,qopt,facteur6p, r2, qopt2, dofIdx,name);
752 model->addActuator(*actuator);
754 #else // MODULE_ACTUATORS
756 #endif // MODULE_ACTUATORS
757 }
else if (!main_tag.
tolower().compare(
"musclegroup")){
758 #ifdef MODULE_MUSCLES
765 while(file.
read(property_tag) && property_tag.
tolower().compare(
"endmusclegroup")){
766 if (!property_tag.
tolower().compare(
"originparent")){
768 file.
read(origin_parent_str);
769 unsigned int idx = model->GetBodyId(origin_parent_str.c_str());
773 else if (!property_tag.
tolower().compare(
"insertionparent")){
775 file.
read(insert_parent_str);
776 unsigned int idx = model->GetBodyId(insert_parent_str.c_str());
781 model->addMuscleGroup(name, origin_parent_str, insert_parent_str);
782 #else // MODULE_MUSCLES
784 #endif // MODULE_MUSCLES
786 else if (!main_tag.
tolower().compare(
"muscle")){
787 #ifdef MODULE_MUSCLES
791 biorbd::muscles::MUSCLE_TYPE type(biorbd::muscles::MUSCLE_TYPE::NO_MUSCLE_TYPE);
792 biorbd::muscles::STATE_TYPE stateType(biorbd::muscles::STATE_TYPE::NO_STATE_TYPE);
793 biorbd::muscles::STATE_FATIGUE_TYPE dynamicFatigueType(biorbd::muscles::STATE_FATIGUE_TYPE::NO_FATIGUE_STATE_TYPE);
798 double optimalLength(0);
800 double tendonSlackLength(0);
802 double maxExcitation(1);
803 double maxActivation(1);
808 while(file.
read(property_tag) && property_tag.
tolower().compare(
"endmuscle")){
809 if (!property_tag.
tolower().compare(
"musclegroup")){
811 file.
read(muscleGroup);
812 idxGroup = model->getGroupId(muscleGroup);
816 else if (!property_tag.
tolower().compare(
"type")){
819 if (!tp_type.
tolower().compare(
"idealizedactuator"))
820 type = biorbd::muscles::MUSCLE_TYPE::IDEALIZED_ACTUATOR;
821 else if (!tp_type.
tolower().compare(
"hill"))
822 type = biorbd::muscles::MUSCLE_TYPE::HILL;
823 else if (!tp_type.
tolower().compare(
"hillthelen") || !tp_type.
tolower().compare(
"thelen"))
824 type = biorbd::muscles::MUSCLE_TYPE::HILL_THELEN;
825 else if (!tp_type.
tolower().compare(
"hillthelenfatigable") || !tp_type.
tolower().compare(
"thelenfatigable"))
826 type = biorbd::muscles::MUSCLE_TYPE::HILL_THELEN_FATIGABLE;
830 else if (!property_tag.
tolower().compare(
"statetype")){
833 if (!tp_state.
tolower().compare(
"buchanan"))
834 stateType = biorbd::muscles::STATE_TYPE::BUCHANAN;
835 else if (!tp_state.
tolower().compare(
"degroote"))
836 stateType = biorbd::muscles::STATE_TYPE::DE_GROOTE;
840 else if (!property_tag.
tolower().compare(
"originposition"))
841 for (
unsigned int i=0; i<3; ++i)
842 file.
read(origin_pos(i), variable);
843 else if (!property_tag.
tolower().compare(
"insertionposition"))
844 for (
unsigned int i=0; i<3; ++i)
845 file.
read(insert_pos(i), variable);
846 else if (!property_tag.
tolower().compare(
"optimallength"))
847 file.
read(optimalLength, variable);
848 else if (!property_tag.
tolower().compare(
"tendonslacklength"))
849 file.
read(tendonSlackLength, variable);
850 else if (!property_tag.
tolower().compare(
"pennationangle"))
851 file.
read(pennAngle, variable);
852 else if (!property_tag.
tolower().compare(
"maximalforce"))
853 file.
read(maxForce, variable);
854 else if (!property_tag.
tolower().compare(
"maximalexcitation"))
855 file.
read(maxExcitation, variable);
856 else if (!property_tag.
tolower().compare(
"pcsa"))
857 file.
read(PCSA, variable);
858 else if (!property_tag.
tolower().compare(
"fatigueparameters")){
859 while(file.
read(subproperty_tag) && subproperty_tag.
tolower().compare(
"endfatigueparameters")){
860 if (!subproperty_tag.
tolower().compare(
"type")){
862 file.
read(tp_fatigue_type);
863 if (!tp_fatigue_type.
tolower().compare(
"simple"))
864 dynamicFatigueType = biorbd::muscles::STATE_FATIGUE_TYPE::SIMPLE_STATE_FATIGUE;
865 else if (!tp_fatigue_type.
tolower().compare(
"xia"))
866 dynamicFatigueType = biorbd::muscles::STATE_FATIGUE_TYPE::DYNAMIC_XIA;
872 if (!subproperty_tag.
tolower().compare(
"fatiguerate"))
874 else if (!subproperty_tag.
tolower().compare(
"recoveryrate"))
876 else if (!subproperty_tag.
tolower().compare(
"developfactor"))
878 else if (!subproperty_tag.
tolower().compare(
"recoveryfactor"))
886 biorbd::utils::Vector3d(origin_pos, name +
"_origin", model->muscleGroup(
static_cast<unsigned int>(idxGroup)).origin()),
887 biorbd::utils::Vector3d(insert_pos, name +
"_insertion", model->muscleGroup(
static_cast<unsigned int>(idxGroup)).insertion()));
890 model->muscleGroup(
static_cast<unsigned int>(idxGroup)).addMuscle(name,type,geo,characteristics,
biorbd::muscles::PathModifiers(),stateType,dynamicFatigueType);
891 #else // MODULE_MUSCLES
893 #endif // MODULE_MUSCLES
895 else if (!main_tag.
tolower().compare(
"viapoint")){
896 #ifdef MODULE_MUSCLES
904 int iMuscleGroup(-1);
909 while(file.
read(property_tag) && property_tag.
tolower().compare(
"endviapoint")){
910 if (!property_tag.
tolower().compare(
"parent")){
913 unsigned int idx = model->GetBodyId(parent.c_str());
917 else if (!property_tag.
tolower().compare(
"muscle"))
919 else if (!property_tag.
tolower().compare(
"musclegroup"))
920 file.
read(musclegroup);
921 else if (!property_tag.
tolower().compare(
"position"))
922 for (
unsigned int i=0; i<3; ++i)
923 file.
read(position(i), variable);
925 iMuscleGroup = model->getGroupId(musclegroup);
927 iMuscle = model->muscleGroup(
static_cast<unsigned int>(iMuscleGroup)).muscleID(muscle);
931 model->muscleGroup(
static_cast<unsigned int>(iMuscleGroup))
932 .muscle(
static_cast<unsigned int>(iMuscle)).addPathObject(position);
933 #else // MODULE_MUSCLES
935 #endif // MODULE_MUSCLES
937 else if (!main_tag.
tolower().compare(
"wrap")){
938 #ifdef MODULE_MUSCLES
945 int iMuscleGroup(-1);
954 while(file.
read(property_tag) && property_tag.
tolower().compare(
"endwrapping")){
955 if (!property_tag.
tolower().compare(
"parent")){
958 unsigned int idx = model->GetBodyId(parent.c_str());
962 else if (!property_tag.
tolower().compare(
"rt")){
963 for (
unsigned int i=0; i<4;++i)
964 for (
unsigned int j=0; j<4; ++j)
965 file.
read(RT(i,j), variable);
967 else if (!property_tag.
tolower().compare(
"muscle"))
969 else if (!property_tag.
tolower().compare(
"musclegroup"))
970 file.
read(musclegroup);
971 else if (!property_tag.
tolower().compare(
"diameter"))
972 file.
read(dia, variable);
973 else if (!property_tag.
tolower().compare(
"length"))
974 file.
read(length, variable);
975 else if (!property_tag.
tolower().compare(
"wrappingside"))
982 iMuscleGroup = model->getGroupId(musclegroup);
984 iMuscle = model->muscleGroup(
static_cast<unsigned int>(iMuscleGroup)).muscleID(muscle);
987 model->muscleGroup(
static_cast<unsigned int>(iMuscleGroup)).muscle(
static_cast<unsigned int>(iMuscle)).addPathObject(cylinder);
988 #else // MODULE_MUSCLES
990 #endif // MODULE_MUSCLES
993 }
catch (std::runtime_error message) {
996 if (name.compare(
""))
997 error_message +=
"Element: " + main_tag +
", named: " + name +
"\n";
998 if (property_tag.compare(
"") && property_tag.find_first_of(
"end") != 0)
999 error_message +=
"Property: " + property_tag +
"\n";
1000 if (subproperty_tag.compare(
"") && subproperty_tag.find_first_of(
"end") != 0)
1001 error_message +=
"Subproperty: " + subproperty_tag +
"\n";
1005 #ifdef MODULE_ACTUATORS
1007 model->closeActuator();
1008 #endif // MODULE_ACTUATORS
1013 std::vector<std::vector<biorbd::utils::Vector3d>>
1032 unsigned int version(
static_cast<unsigned int>(atoi(tp.c_str())));
1037 unsigned int nbMark(
static_cast<unsigned int>(atoi(tp.c_str())));
1041 unsigned int nbIntervals(
static_cast<unsigned int>(atoi(tp.c_str())));
1043 std::vector<std::vector<biorbd::utils::Vector3d>> markers;
1044 std::vector<biorbd::utils::Vector3d> position;
1046 for (
unsigned int j=0; j<nbMark; j++){
1047 while (tp.compare(
"Marker")){
1048 bool check = file.
read(tp);
1052 unsigned int noMarker;
1053 file.
read(noMarker);
1054 for (
unsigned int i=0; i<=nbIntervals; i++){
1056 for (
unsigned int j=0; j<3; ++j)
1058 position.push_back(mark);
1060 markers.push_back(position);
1072 std::vector<biorbd::rigidbody::GeneralizedCoordinates>
1091 unsigned int version(
static_cast<unsigned int>(atoi(tp.c_str())));
1096 unsigned int NDDL(
static_cast<unsigned int>(atoi(tp.c_str())));
1100 unsigned int nbIntervals(
static_cast<unsigned int>(atoi(tp.c_str())));
1102 std::vector<biorbd::rigidbody::GeneralizedCoordinates> kinematics;
1104 for (
unsigned int j=0; j<nbIntervals+1; j++){
1105 while (tp.compare(
"T")){
1106 bool check = file.
read(tp);
1113 for (
unsigned int i=0; i<NDDL; i++)
1114 file.
read(position(i));
1116 kinematics.push_back(position);
1127 std::vector<biorbd::utils::Vector>
1146 unsigned int version(
static_cast<unsigned int>(atoi(tp.c_str())));
1151 unsigned int nMus(
static_cast<unsigned int>(atoi(tp.c_str())));
1155 unsigned int nbIntervals(
static_cast<unsigned int>(atoi(tp.c_str())));
1157 std::vector<biorbd::utils::Vector> activations;
1159 for (
unsigned int j=0; j<nbIntervals+1; j++){
1160 while (tp.compare(
"T")){
1161 bool check = file.
read(tp);
1168 for (
unsigned int i=0; i<nMus; i++)
1169 file.
read(activation_tp(i));
1171 activations.push_back(activation_tp);
1182 std::vector<biorbd::utils::Vector>
1201 unsigned int version(
static_cast<unsigned int>(atoi(tp.c_str())));
1206 unsigned int nGeneralizedTorque(
static_cast<unsigned int>(atoi(tp.c_str())));
1210 unsigned int nbIntervals(
static_cast<unsigned int>(atoi(tp.c_str())));
1212 std::vector<biorbd::utils::Vector> torque;
1214 for (
unsigned int j=0; j<nbIntervals+1; j++){
1215 while (tp.compare(
"T")){
1216 bool check = file.
read(tp);
1226 for (
unsigned int i=0; i<nGeneralizedTorque; i++)
1227 file.
read(torque_tp(i));
1229 torque.push_back(torque_tp);
1240 std::vector<biorbd::utils::Vector>
1259 unsigned int version(
static_cast<unsigned int>(atoi(tp.c_str())));
1264 unsigned int NGRF(
static_cast<unsigned int>(atoi(tp.c_str())));
1268 unsigned int nbIntervals(
static_cast<unsigned int>(atoi(tp.c_str())));
1270 std::vector<biorbd::utils::Vector> grf;
1272 for (
unsigned int j=0; j<nbIntervals+1; j++){
1273 while (tp.compare(
"T")){
1274 bool check = file.
read(tp);
1284 for (
unsigned int i=0; i<NGRF; i++)
1285 file.
read(grf_tp(i));
1287 grf.push_back(grf_tp);
1300 std::vector<std::vector<unsigned int>>& frame,
1301 std::vector<unsigned int>& frequency,
1302 std::vector<std::vector<biorbd::utils::Vector3d>>& force,
1303 std::vector<std::vector<biorbd::utils::Vector3d>>& moment,
1304 std::vector<std::vector<biorbd::utils::Vector3d>>& cop) {
1327 std::vector<unsigned int> frame1pf;
1328 std::vector<biorbd::utils::Vector3d> force1fp;
1329 std::vector<biorbd::utils::Vector3d> moment1fp;
1330 std::vector<biorbd::utils::Vector3d> cop1fp;
1334 unsigned int frequency1pf(
static_cast<unsigned int>(atoi(tp.c_str())));
1337 for (
unsigned int i=0; i<4; ++i)
1344 if (!tp.compare(
"")){
1350 std::stringstream ss( tp );
1352 std::vector<double> data;
1354 while (getline( ss, field,
',' )){
1357 std::stringstream fs( field );
1362 data.push_back( f );
1368 frame1pf.push_back(
static_cast<unsigned int>(data[0]));
1373 for (
unsigned int i=0; i<3; ++i){
1374 cop_tp[i] = data[i+2]/1000;
1375 for_tp[i] = data[i+5];
1376 M_tp[i] = data[i+8]/1000;
1378 cop1fp.push_back(cop_tp);
1379 force1fp.push_back(for_tp);
1380 moment1fp.push_back(M_tp);
1383 frame.push_back(frame1pf);
1384 frequency.push_back(frequency1pf);
1385 force.push_back(force1fp);
1386 moment.push_back(moment1fp);
1387 cop.push_back(cop1fp);
1391 std::vector<std::vector<biorbd::utils::SpatialVector>>
1394 std::vector<std::vector<unsigned int>> frame;
1395 std::vector<unsigned int> frequency;
1396 std::vector<std::vector<biorbd::utils::Vector3d>> force;
1397 std::vector<std::vector<biorbd::utils::Vector3d>> moment;
1398 std::vector<std::vector<biorbd::utils::Vector3d>> cop;
1399 readViconForceFile(path, frame, frequency, force, moment, cop);
1402 std::vector<std::vector<biorbd::utils::SpatialVector>> st;
1403 for (
unsigned int j=0; j<force.size(); ++j){
1404 std::vector<biorbd::utils::SpatialVector> tp;
1405 for (
unsigned int i=0; i<force[j].size(); ++i){
1415 std::vector<std::vector<biorbd::utils::Vector3d>>
1417 std::vector<biorbd::utils::String>& markOrder,
1435 for (
unsigned int i=0; i<3; ++i)
1438 std::vector<unsigned int> idx_init;
1439 std::vector<unsigned int> idx_end;
1441 while (idx_tp < t.length()) {
1442 idx_tp = t.find(
":", idx_tp+1);
1443 idx_init.push_back(
static_cast<unsigned int>(idx_tp));
1444 idx_end.push_back(
static_cast<unsigned int>(t.find(
",", idx_tp+1)));
1447 std::vector<biorbd::utils::String> MarkersInFile;
1448 for (
unsigned int i=0; i<idx_init.size()-1; ++i){
1450 for (
unsigned int j=*(idx_init.begin()+i)+1; j<*(idx_end.begin()+i); ++j)
1451 tp.push_back(t.at(j));
1452 MarkersInFile.push_back(tp);
1458 ordre =
new int[3*MarkersInFile.size()];
1459 for (
int i=0; i<static_cast<int>(3*MarkersInFile.size()); ++i)
1461 for (
int i=0; i<static_cast<int>(markOrder.size()); ++i){
1466 if (!m1.compare(m2)){
1468 ordre[3*cmp+1] = 3*i+1;
1469 ordre[3*cmp+2] = 3*i+2;
1476 if (cmp>=MarkersInFile.size())
1482 for (
unsigned int i=0; i<4; ++i)
1486 unsigned int jumps(1);
1487 unsigned int nbFrames(0);
1488 if (nFramesToGet != -1){
1503 for (
unsigned int i=0; i<7; ++i)
1506 &&
static_cast<unsigned int>(nFramesToGet)<=nbFrames,
1507 "nNode should not be 0, 1 or greater "
1508 "than number of frame");
1509 jumps = nbFrames/
static_cast<unsigned int>(nFramesToGet)+1;
1513 std::vector<std::vector<biorbd::utils::Vector3d>> data;
1515 unsigned int cmpFrames(1);
1518 static_cast<unsigned int>(3*markOrder.size()));
1521 std::stringstream ss( t );
1523 unsigned int cmp = 0;
1524 while (getline( ss, field,
',' )){
1527 std::stringstream fs( field );
1530 if (cmp>1 && cmp<3*MarkersInFile.size()+2){
1531 int idx = ordre[cmp-2];
1533 data_tp(
static_cast<unsigned int>(idx)) = f;
1538 std::vector<biorbd::utils::Vector3d> data_tp2;
1539 for (
unsigned int i=0; i<static_cast<unsigned int>(data_tp.size())/3; ++i){
1541 data_tp2.push_back(node);
1544 data.push_back(data_tp2);
1545 for (
unsigned int i=0; i<jumps; ++i){
1546 if (cmpFrames != nbFrames){
1585 unsigned int version(
static_cast<unsigned int>(atoi(tp.c_str())));
1590 unsigned int nPoints(
static_cast<unsigned int>(atoi(tp.c_str())));
1592 unsigned int nFaces(
static_cast<unsigned int>(atoi(tp.c_str())));
1597 for (
unsigned int iPoints=0; iPoints < nPoints; ++iPoints){
1599 for (
unsigned int i=0; i<3; ++i)
1600 file.
read(nodeTp(i));
1603 for (
unsigned int i=0; i<3; ++i){
1609 for (
unsigned int iPoints=0; iPoints < nFaces; ++iPoints){
1611 unsigned int nVertices;
1612 file.
read(nVertices);
1615 for (
unsigned int i=0; i<nVertices; ++i)
1616 file.
read(patchTp(i));
1645 unsigned int nVertex(
static_cast<unsigned int>(atoi(tp.c_str())));
1651 unsigned int nFaces(
static_cast<unsigned int>(atoi(tp.c_str())));
1661 for (
unsigned int iPoints=0; iPoints < nVertex; ++iPoints){
1663 for (
unsigned int i=0; i<3; ++i)
1664 file.
read(nodeTp(i));
1667 for (
int i=0; i<nVertexProperties-3; ++i){
1673 for (
unsigned int iPoints=0; iPoints < nFaces; ++iPoints){
1675 unsigned int nVertices;
1676 file.
read(nVertices);
1679 for (
unsigned int i=0; i<nVertices; ++i)
1680 file.
read(patchTp(i));
1683 for (
int i=0; i<nFacesProperties-1; ++i)
1724 if (!text.compare(
"v")) {
1726 for (
unsigned int i=0; i<3; ++i)
1727 file.
read(vertex(i));
1730 else if (!text.compare(
"f")) {
1733 for (
unsigned int i=0; i<3; ++i) {
1735 size_t idxSlash = text.find(
"/");
1737 patch(i) = (std::stoi(text.substr (0,idxSlash)) - 1);
1752 #ifdef MODULE_VTP_FILES_READER
1753 #include "tinyxml.h"
1766 TiXmlDocument doc(filepath);
1768 TiXmlHandle hDoc(&doc);
1773 TiXmlHandle polydata =
1774 hDoc.ChildElement(
"VTKFile", 0)
1775 .ChildElement(
"PolyData", 0)
1776 .ChildElement(
"Piece", 0);
1777 int numberOfPoints, NumberOfPolys;
1778 polydata.ToElement()->QueryIntAttribute(
"NumberOfPoints", &numberOfPoints);
1779 polydata.ToElement()->QueryIntAttribute(
"NumberOfPolys", &NumberOfPolys);
1786 polydata.ChildElement(
"Points", 0)
1787 .ChildElement(
"DataArray", 0).Element()->GetText());
1788 std::stringstream ss( points );
1789 for (
int i = 0; i < numberOfPoints; ++i){
1792 getline( ss, field,
' ' );
1793 std::stringstream fs( field );
1797 getline( ss, field,
' ' );
1798 std::stringstream fs( field );
1802 getline( ss, field,
' ' );
1803 std::stringstream fs( field );
1813 polydata.ChildElement(
"Polys", 0)
1814 .ChildElement(
"DataArray", 0).Element()->GetText());
1815 std::stringstream ss( polys );
1816 for (
int i = 0; i < NumberOfPolys; ++i){
1817 int vertex1, vertex2, vertex3;
1819 getline( ss, field,
' ' );
1820 std::stringstream fs( field );
1824 getline( ss, field,
' ' );
1825 std::stringstream fs( field );
1829 getline( ss, field,
' ' );
1830 std::stringstream fs( field );
1833 mesh.
addFace({vertex1, vertex2, vertex3});
1839 #endif // MODULE_VTP_FILES_READER
1842 std::vector<std::vector<biorbd::utils::Vector3d>>
1861 for (
unsigned int i=0; i<3; ++i)
1864 std::vector<unsigned int> idx_init;
1865 std::vector<unsigned int> idx_end;
1867 while (idx_tp < t.length()) {
1868 idx_tp = t.find(
":", idx_tp+1);
1869 idx_init.push_back(
static_cast<unsigned int>(idx_tp));
1870 idx_end.push_back(
static_cast<unsigned int>(t.find(
",", idx_tp+1)));
1873 std::vector<biorbd::utils::String> MarkersInFile;
1874 for (
unsigned int i=0; i<idx_init.size()-1; ++i){
1876 for (
unsigned int j=*(idx_init.begin()+i)+1; j<*(idx_end.begin()+i); ++j)
1877 tp.push_back(t.at(j));
1878 MarkersInFile.push_back(tp);
1884 return readViconMarkerFile(path, MarkersInFile, nFramesToGet);