21size_t markerCount(
const std::vector<std::vector<Marker>>& frames) {
22 size_t maxCountMarkers = 0;
23 for (
const auto& fr : frames) {
24 const size_t markerCount =
25 std::count_if(fr.begin(), fr.end(), [](
const Marker& marker) { return !marker.occluded; });
26 maxCountMarkers = std::max(markerCount, maxCountMarkers);
28 return maxCountMarkers;
33 const std::string& filename,
35 std::span<const std::string> validMarkerNames) {
36 const std::string ext = filesystem::path(filename).extension().string();
39 return loadC3d(filename, up, validMarkerNames);
40 }
else if (ext ==
".trc") {
42 }
else if (ext ==
".glb") {
44 }
else if (ext ==
".fbx") {
47 MT_LOGE(
"{} Unknown marker file type {}", __func__, filename);
51 MT_LOGE(
"{}: Unknown error in {}", __func__, filename);
57 const std::string& filename,
59 std::span<const std::string> validMarkerNames) {
60 const std::vector<MarkerSequence> markerSequences =
loadMarkers(filename, up, validMarkerNames);
65 return {markerSequences.at(subjectID)};
70 std::span<const std::byte> bytes,
71 const std::string& format,
73 std::span<const std::string> validMarkerNames) {
75 if (format ==
".trc") {
77 }
else if (format ==
".glb") {
79 }
else if (format ==
".fbx") {
81 }
else if (format ==
".c3d") {
82#ifdef MOMENTUM_WITH_EZC3D_ISTREAM
83 return loadC3d(bytes, up, validMarkerNames);
86 MT_LOGE(
"{}: in-memory c3d loading is not supported", __func__);
90 MT_LOGE(
"{}: Unknown marker format '{}' for {}-byte buffer", __func__, format, bytes.size());
94 MT_LOGE(
"{}: Unknown error reading {} buffer", __func__, format);
100 std::span<const std::byte> bytes,
101 const std::string& format,
103 std::span<const std::string> validMarkerNames) {
104 const std::vector<MarkerSequence> markerSequences =
110 return {markerSequences.at(subjectID)};
115 if (markerSequences.empty()) {
127 const size_t numActors = markerSequences.size();
128 std::vector<size_t> maxMarkers(numActors, 0);
130 for (
size_t iActor = 0; iActor < numActors; ++iActor) {
131 maxMarkers.at(iActor) = markerCount(markerSequences[iActor].frames);
136 if (numActors == 1) {
143 for (
size_t iActor = 0; iActor < numActors; ++iActor) {
144 const size_t count = maxMarkers.at(iActor);
145 auto actorName = markerSequences[iActor].name;
146 std::transform(actorName.begin(), actorName.end(), actorName.begin(), [](
unsigned char c) {
147 return std::tolower(c);
149 if (count > maxCount && !actorName.empty() && actorName !=
"unlabeled") {
156 return static_cast<int>(actorID);
std::vector< MarkerSequence > loadC3d(const std::string &filename, UpVector up, std::span< const std::string > validMarkerNames)
Loads all the subjects from a C3D file into a vector of MarkerSequences.
UpVector
This enumeration is used to define the primary up vector directions for various coordinate systems an...
std::vector< MarkerSequence > loadMarkers(const std::string &filename, UpVector up, std::span< const std::string > validMarkerNames)
Loads all actor sequences from a marker file (c3d, trc, glb) and converts the positions to the target...
MarkerSequence loadTrc(std::istream &stream, UpVector up)
Loads marker data from a TRC input stream into a MarkerSequence.
int findMainSubjectIndex(std::span< const MarkerSequence > markerSequences)
Finds the "main subject" from a vector of MarkerSequences.
MarkerSequence loadMarkerSequence(const filesystem::path &filename)
Load a marker sequence from a glTF file.
MarkerSequence loadFbxMarkerSequence(const filesystem::path &filename, bool stripNamespaces)
Loads a MarkerSequence from an FBX file.
std::optional< MarkerSequence > loadMarkersForMainSubject(const std::string &filename, UpVector up, std::span< const std::string > validMarkerNames)
Loads the main subject's marker data from a marker file (c3d, trc, glb) and converts the positions to...
A single motion capture marker observation (position, occlusion, confidence).