Skip to content

Commit

Permalink
Threading through some new SubjectOnDisk values to help with aggregat…
Browse files Browse the repository at this point in the history
…e statistics
  • Loading branch information
keenon committed Sep 27, 2024
1 parent deb01b1 commit 46eaef0
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 0 deletions.
133 changes: 133 additions & 0 deletions dart/biomechanics/SubjectOnDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,84 @@ MissingGRFReason missingGRFReasonFromProto(proto::MissingGRFReason reason)
return notMissingGRF;
}

BasicTrialType basicTrialTypeFromProto(proto::BasicTrialType type)
{
switch (type)
{
case proto::BasicTrialType::treadmill:
return treadmill;
case proto::BasicTrialType::overground:
return overground;
case proto::BasicTrialType::staticTrial:
return staticTrial;
case proto::BasicTrialType::other:
return other;
case proto::BasicTrialType_INT_MIN_SENTINEL_DO_NOT_USE_:
return other;
break;
case proto::BasicTrialType_INT_MAX_SENTINEL_DO_NOT_USE_:
return other;
break;
}
return other;
}

proto::BasicTrialType basicTrialTypeToProto(BasicTrialType type)
{
switch (type)
{
case treadmill:
return proto::BasicTrialType::treadmill;
case overground:
return proto::BasicTrialType::overground;
case staticTrial:
return proto::BasicTrialType::staticTrial;
case other:
return proto::BasicTrialType::other;
}
return proto::BasicTrialType::other;
}

DetectedTrialFeature detectedTrialFeatureFromProto(
proto::DetectedTrialFeature feature)
{
switch (feature)
{
case proto::DetectedTrialFeature::walking:
return walking;
case proto::DetectedTrialFeature::running:
return running;
case proto::DetectedTrialFeature::unevenTerrain:
return unevenTerrain;
case proto::DetectedTrialFeature::flatTerrain:
return flatTerrain;
case proto::DetectedTrialFeature_INT_MIN_SENTINEL_DO_NOT_USE_:
return walking;
break;
case proto::DetectedTrialFeature_INT_MAX_SENTINEL_DO_NOT_USE_:
return walking;
break;
}
return walking;
}

proto::DetectedTrialFeature detectedTrialFeatureToProto(
DetectedTrialFeature feature)
{
switch (feature)
{
case walking:
return proto::DetectedTrialFeature::walking;
case running:
return proto::DetectedTrialFeature::running;
case unevenTerrain:
return proto::DetectedTrialFeature::unevenTerrain;
case flatTerrain:
return proto::DetectedTrialFeature::flatTerrain;
}
return proto::DetectedTrialFeature::walking;
}

SubjectOnDisk::SubjectOnDisk(const std::string& path)
: mPath(path), mLoadedAllFrames(false)
{
Expand Down Expand Up @@ -3193,6 +3271,17 @@ void SubjectOnDiskTrial::setMissingGRFReason(
mMissingGRFReason = missingGRFReason;
}

std::vector<bool> SubjectOnDiskTrial::getHasManualGRFAnnotation()
{
return mHasManualGRFAnnotation;
}

void SubjectOnDiskTrial::setHasManualGRFAnnotation(
std::vector<bool> hasManualGRFAnnotation)
{
mHasManualGRFAnnotation = hasManualGRFAnnotation;
}

void SubjectOnDiskTrial::setCustomValues(
std::vector<Eigen::MatrixXs> customValues)
{
Expand Down Expand Up @@ -3250,6 +3339,27 @@ std::vector<ForcePlate> SubjectOnDiskTrial::getForcePlates()
return mForcePlates;
}

void SubjectOnDiskTrial::setBasicTrialType(BasicTrialType type)
{
mBasicTrialType = type;
}

BasicTrialType SubjectOnDiskTrial::getBasicTrialType()
{
return mBasicTrialType;
}

void SubjectOnDiskTrial::setDetectedTrialFeatures(
std::vector<DetectedTrialFeature> features)
{
mDetectedTrialFeatures = features;
}

std::vector<DetectedTrialFeature> SubjectOnDiskTrial::getDetectedTrialFeatures()
{
return mDetectedTrialFeatures;
}

std::shared_ptr<SubjectOnDiskTrialPass> SubjectOnDiskTrial::addPass()
{
mTrialPasses.push_back(std::make_shared<SubjectOnDiskTrialPass>());
Expand Down Expand Up @@ -3305,6 +3415,19 @@ void SubjectOnDiskTrial::read(const proto::SubjectOnDiskTrialHeader& proto)
mMissingGRFReason.push_back(
missingGRFReasonFromProto(proto.missing_grf_reason(i)));
}
mHasManualGRFAnnotation.clear();
for (int i = 0; i < proto.has_manual_grf_annotation_size(); i++)
{
mHasManualGRFAnnotation.push_back(proto.has_manual_grf_annotation(i));
}

mBasicTrialType = basicTrialTypeFromProto(proto.trial_type());
mDetectedTrialFeatures.clear();
for (int i = 0; i < proto.detected_trial_feature_size(); i++)
{
mDetectedTrialFeatures.push_back(
detectedTrialFeatureFromProto(proto.detected_trial_feature(i)));
}

// ///////////////////////////////////////////////////////////////////////////
// // Raw sensor observations, which are shared across processing passes
Expand Down Expand Up @@ -3378,6 +3501,16 @@ void SubjectOnDiskTrial::write(proto::SubjectOnDiskTrialHeader* proto)
proto->add_missing_grf_reason(
missingGRFReasonToProto(mMissingGRFReason[i]));
}
for (int i = 0; i < mHasManualGRFAnnotation.size(); i++)
{
proto->add_has_manual_grf_annotation(mHasManualGRFAnnotation[i]);
}
proto->set_trial_type(basicTrialTypeToProto(mBasicTrialType));
for (int i = 0; i < mDetectedTrialFeatures.size(); i++)
{
proto->add_detected_trial_feature(
detectedTrialFeatureToProto(mDetectedTrialFeatures[i]));
}

// ///////////////////////////////////////////////////////////////////////////
// // Raw sensor observations, which are shared across processing passes
Expand Down
10 changes: 10 additions & 0 deletions dart/biomechanics/SubjectOnDisk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ class SubjectOnDiskTrial
void setOriginalTrialEndTime(s_t endTime);
std::vector<MissingGRFReason> getMissingGRFReason();
void setMissingGRFReason(std::vector<MissingGRFReason> missingGRFReason);
std::vector<bool> getHasManualGRFAnnotation();
void setHasManualGRFAnnotation(std::vector<bool> hasManualGRFAnnotation);
void setCustomValues(std::vector<Eigen::MatrixXs> customValues);
void setMarkerNamesGuessed(bool markersGuessed);
std::vector<std::map<std::string, Eigen::Vector3s>> getMarkerObservations();
Expand All @@ -361,6 +363,10 @@ class SubjectOnDiskTrial
void setExoTorques(std::map<int, Eigen::VectorXs> exoTorques);
void setForcePlates(std::vector<ForcePlate> forcePlates);
std::vector<ForcePlate> getForcePlates();
void setBasicTrialType(BasicTrialType type);
BasicTrialType getBasicTrialType();
void setDetectedTrialFeatures(std::vector<DetectedTrialFeature> features);
std::vector<DetectedTrialFeature> getDetectedTrialFeatures();
std::shared_ptr<SubjectOnDiskTrialPass> addPass();
std::vector<std::shared_ptr<SubjectOnDiskTrialPass>> getPasses();
void read(const proto::SubjectOnDiskTrialHeader& proto);
Expand All @@ -373,6 +379,7 @@ class SubjectOnDiskTrial
std::vector<std::string> mTrialTags;
std::vector<std::shared_ptr<SubjectOnDiskTrialPass>> mTrialPasses;
std::vector<MissingGRFReason> mMissingGRFReason;
std::vector<bool> mHasManualGRFAnnotation;
// This is true if we guessed the marker names, and false if we got them from
// the uploaded user's file, which implies that they got them from human
// observations.
Expand All @@ -385,6 +392,9 @@ class SubjectOnDiskTrial
s_t mOriginalTrialStartTime;
s_t mOriginalTrialEndTime;

BasicTrialType mBasicTrialType;
std::vector<DetectedTrialFeature> mDetectedTrialFeatures;

///////////////////////////////////////////////////////////////////////////
// Recovered proto summaries, for incremental loading of Frames
///////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 16 additions & 0 deletions dart/biomechanics/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ enum MissingGRFReason
extendedToNearestPeakForce
};

enum BasicTrialType
{
treadmill,
overground,
staticTrial,
other
};

enum DetectedTrialFeature
{
walking,
running,
unevenTerrain,
flatTerrain
};

enum MissingGRFStatus
{
no = 0, // no will cast to `false`
Expand Down
19 changes: 19 additions & 0 deletions dart/proto/SubjectOnDisk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ enum ProcessingPassType {
accMinimizingFilter = 3;
};

enum BasicTrialType {
treadmill = 0;
overground = 1;
staticTrial = 2;
other = 3;
};

enum DetectedTrialFeature {
walking = 0;
running = 1;
unevenTerrain = 2;
flatTerrain = 3;
}

// Many of the ML tasks we want to support from SubjectOnDisk data include
// effectively predicting the results of a downstream processing task from
// an upstream processing task. Trivially, that's predicting physics from
Expand Down Expand Up @@ -79,6 +93,7 @@ message SubjectOnDiskTrialHeader {
// memory, but we really want to know this information when randomly picking
// frames from the subject to sample.
repeated MissingGRFReason missing_GRF_reason = 2;
repeated bool has_manual_GRF_annotation = 16;
// This is how many frames are in this trial
int32 trial_length = 3;
// This is the timestep used in this trial (assumed constant throughout the trial)
Expand All @@ -102,6 +117,10 @@ message SubjectOnDiskTrialHeader {
int32 original_trial_end_frame = 13;
float original_trial_start_time = 14;
float original_trial_end_time = 15;
// This is the type of trial we're dealing with
BasicTrialType trial_type = 17;
// This is the detected features of this trial
repeated DetectedTrialFeature detected_trial_feature = 18;
}

message SubjectOnDiskPass {
Expand Down
70 changes: 70 additions & 0 deletions python/_nimblephysics/biomechanics/SubjectOnDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,51 @@ void SubjectOnDisk(py::module& m)
"This is the pass where we apply an acceleration minimizing "
"filter to the kinematics and dynamics.");

auto basicTrialType
= ::py::enum_<dart::biomechanics::BasicTrialType>(m, "BasicTrialType")
.value(
"TREADMILL",
dart::biomechanics::BasicTrialType::treadmill,
"This is a trial where the subject is walking or "
"running on a treadmill.")
.value(
"OVERGROUND",
dart::biomechanics::BasicTrialType::overground,
"This is a trial where the subject is walking or "
"running overground.")
.value(
"STATIC_TRIAL",
dart::biomechanics::BasicTrialType::staticTrial,
"This is a trial where the subject is standing "
"still.")
.value(
"OTHER",
dart::biomechanics::BasicTrialType::other,
"This is a trial that doesn't fit into any of the "
"other categories.");

auto detectedTrialFeature
= ::py::enum_<dart::biomechanics::DetectedTrialFeature>(
m, "DetectedTrialFeature")
.value(
"WALKING",
dart::biomechanics::DetectedTrialFeature::walking,
"This is a trial where the subject is walking.")
.value(
"RUNNING",
dart::biomechanics::DetectedTrialFeature::running,
"This is a trial where the subject is running.")
.value(
"UNEVEN_TERRAIN",
dart::biomechanics::DetectedTrialFeature::unevenTerrain,
"This is a trial where the subject is walking or "
"running on uneven terrain.")
.value(
"FLAT_TERRAIN",
dart::biomechanics::DetectedTrialFeature::flatTerrain,
"This is a trial where the subject is walking or "
"running on flat terrain.");

auto framePass
= ::py::class_<
dart::biomechanics::FramePass,
Expand Down Expand Up @@ -891,6 +936,15 @@ Note that these are specified in the local body frame, acting on the body at its
.def(
"getMissingGRFReason",
&dart::biomechanics::SubjectOnDiskTrial::getMissingGRFReason)
.def(
"setHasManualGRFAnnotation",
&dart::biomechanics::SubjectOnDiskTrial::
setHasManualGRFAnnotation,
::py::arg("hasManualGRFAnnotation"))
.def(
"getHasManualGRFAnnotation",
&dart::biomechanics::SubjectOnDiskTrial::
getHasManualGRFAnnotation)
.def(
"setCustomValues",
&dart::biomechanics::SubjectOnDiskTrial::setCustomValues,
Expand Down Expand Up @@ -929,6 +983,22 @@ Note that these are specified in the local body frame, acting on the body at its
.def(
"getForcePlates",
&dart::biomechanics::SubjectOnDiskTrial::getForcePlates)
.def(
"setBasicTrialType",
&dart::biomechanics::SubjectOnDiskTrial::setBasicTrialType,
::py::arg("type"))
.def(
"getBasicTrialType",
&dart::biomechanics::SubjectOnDiskTrial::getBasicTrialType)
.def(
"setDetectedTrialFeatures",
&dart::biomechanics::SubjectOnDiskTrial::
setDetectedTrialFeatures,
::py::arg("features"))
.def(
"getDetectedTrialFeatures",
&dart::biomechanics::SubjectOnDiskTrial::
getDetectedTrialFeatures)
.def(
"addPass",
&dart::biomechanics::SubjectOnDiskTrial::addPass,
Expand Down

0 comments on commit 46eaef0

Please sign in to comment.