Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some SubjectOnDisk fields and a binding for unwrapEulerAngles #222

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 187 additions & 0 deletions dart/biomechanics/SubjectOnDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,118 @@ 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;
}

DataQuality dataQualityFromProto(proto::DataQuality quality)
{
switch (quality)
{
case proto::DataQuality::pilotData:
return pilotData;
case proto::DataQuality::experimentalData:
return experimentalData;
case proto::DataQuality::internetData:
return internetData;
case proto::DataQuality_INT_MIN_SENTINEL_DO_NOT_USE_:
return internetData;
break;
case proto::DataQuality_INT_MAX_SENTINEL_DO_NOT_USE_:
return internetData;
break;
}
return internetData;
}

proto::DataQuality dataQualityToProto(DataQuality quality)
{
switch (quality)
{
case pilotData:
return proto::DataQuality::pilotData;
case experimentalData:
return proto::DataQuality::experimentalData;
case internetData:
return proto::DataQuality::internetData;
}
return proto::DataQuality::pilotData;
}

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 @@ -1490,6 +1602,12 @@ std::vector<MissingGRFReason> SubjectOnDisk::getMissingGRF(int trial)
return mHeader->mTrials[trial]->mMissingGRFReason;
}

/// This returns the user supplied enum of type 'DataQuality'
DataQuality SubjectOnDisk::getQuality()
{
return mHeader->getQuality();
}

int SubjectOnDisk::getNumProcessingPasses()
{
return mHeader->mPasses.size();
Expand Down Expand Up @@ -3193,6 +3311,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 +3379,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 +3455,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 +3541,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 Expand Up @@ -3547,6 +3720,17 @@ SubjectOnDiskHeader& SubjectOnDiskHeader::setNotes(const std::string& notes)
return *this;
}

SubjectOnDiskHeader& SubjectOnDiskHeader::setQuality(DataQuality quality)
{
mDataQuality = quality;
return *this;
}

DataQuality SubjectOnDiskHeader::getQuality()
{
return mDataQuality;
}

std::shared_ptr<SubjectOnDiskPassHeader>
SubjectOnDiskHeader::addProcessingPass()
{
Expand Down Expand Up @@ -3782,6 +3966,7 @@ void SubjectOnDiskHeader::write(dart::proto::SubjectOnDiskHeader* header)
{
header->add_exo_dof_index(index);
}
header->set_data_quality(dataQualityToProto(mDataQuality));

if (!header->IsInitialized())
{
Expand Down Expand Up @@ -3926,6 +4111,8 @@ void SubjectOnDiskHeader::read(const dart::proto::SubjectOnDiskHeader& proto)
{
mExoDofIndices.push_back(proto.exo_dof_index(i));
}

mDataQuality = dataQualityFromProto(proto.data_quality());
}

void SubjectOnDiskHeader::writeSensorsFrame(
Expand Down
18 changes: 18 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 Expand Up @@ -453,6 +463,8 @@ class SubjectOnDiskHeader
SubjectOnDiskHeader& setSubjectTags(std::vector<std::string> subjectTags);
SubjectOnDiskHeader& setHref(const std::string& sourceHref);
SubjectOnDiskHeader& setNotes(const std::string& notes);
SubjectOnDiskHeader& setQuality(DataQuality quality);
DataQuality getQuality();
std::shared_ptr<SubjectOnDiskPassHeader> addProcessingPass();
std::vector<std::shared_ptr<SubjectOnDiskPassHeader>> getProcessingPasses();
std::shared_ptr<SubjectOnDiskTrial> addTrial();
Expand Down Expand Up @@ -512,6 +524,9 @@ class SubjectOnDiskHeader
// This is exoskeleton data
std::vector<int> mExoDofIndices;

// This is the user supplied quality of the data
DataQuality mDataQuality;

friend class SubjectOnDisk;
friend struct Frame;
friend struct FramePass;
Expand Down Expand Up @@ -627,6 +642,9 @@ class SubjectOnDisk
/// include `notMissingGRF`.
std::vector<MissingGRFReason> getMissingGRF(int trial);

/// This returns the user supplied enum of type 'DataQuality'
DataQuality getQuality();

int getNumProcessingPasses();

ProcessingPassType getProcessingPassType(int processingPass);
Expand Down
23 changes: 23 additions & 0 deletions dart/biomechanics/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ enum MissingGRFReason
extendedToNearestPeakForce
};

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

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

enum DataQuality
{
pilotData,
experimentalData,
internetData
};

enum MissingGRFStatus
{
no = 0, // no will cast to `false`
Expand Down
Loading
Loading