From 4abf7f9003d85547f4eebb5528f22c95ffb677e1 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Thu, 5 Dec 2024 17:51:57 -0800 Subject: [PATCH] Split marker_tracking (#154) Summary: Pull Request resolved: https://github.com/facebookincubator/momentum/pull/154 Reviewed By: cdtwigg Differential Revision: D66831016 --- pymomentum/cmake/build_variables.bzl | 14 + .../marker_tracking_pybind.cpp | 239 +----------------- 2 files changed, 20 insertions(+), 233 deletions(-) diff --git a/pymomentum/cmake/build_variables.bzl b/pymomentum/cmake/build_variables.bzl index b9e32e92..27ba344a 100644 --- a/pymomentum/cmake/build_variables.bzl +++ b/pymomentum/cmake/build_variables.bzl @@ -74,3 +74,17 @@ skel_state_public_headers = [ skel_state_sources = [ "skel_state/skel_state_pybind.cpp", ] + +marker_tracking_public_headers = [ +] + +marker_tracking_sources = [ + "marker_tracking/marker_tracking_pybind.cpp", +] + +marker_tracking_extensions_public_headers = [ +] + +marker_tracking_extensions_sources = [ + "marker_tracking_extensions/marker_tracking_extensions_pybind.cpp", +] diff --git a/pymomentum/marker_tracking/marker_tracking_pybind.cpp b/pymomentum/marker_tracking/marker_tracking_pybind.cpp index 5cc8bf80..80a5add8 100644 --- a/pymomentum/marker_tracking/marker_tracking_pybind.cpp +++ b/pymomentum/marker_tracking/marker_tracking_pybind.cpp @@ -1,9 +1,5 @@ // (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. -#include // @manual=fbsource//arvr/projects/kuiper_belt/projects/marker_tracking:analysis_utils -#include // @manual=fbsource//arvr/projects/kuiper_belt/projects/marker_tracking:self_collision_detector -#include // @manual=fbsource//arvr/projects/kuiper_belt/projects/marker_tracking:validate_c3d - #include #include #include @@ -13,12 +9,13 @@ #include #include #include + #include namespace py = pybind11; // Python bindings for marker tracking APIs defined under: -// //arvr/projects/kuiper_belt/projects/marker_tracking +// //arvr/libraries/momentum/marker_tracking // @dep=fbsource//arvr/libraries/dispenso:dispenso @@ -29,180 +26,6 @@ PYBIND11_MODULE(marker_tracking, m) { pybind11::module_::import( "pymomentum.geometry"); // @dep=fbcode//pymomentum:geometry - // Bindings for APIs and types defined in - // marker_tracking/analysis_utils/marker_error_utils.h - // (https://pybind11.readthedocs.io/en/latest/classes.html#creating-bindings-for-a-custom-type) - auto markerErrorReport = py::class_( - m, - "MarkerErrorReport", - "Represents a report generated from computed marker errors"); - - py::class_( - markerErrorReport, - "LocatorEntry", - "a struct within MarkerErrorReport, called LocatorEntry") - .def(py::init<>()) - .def_readwrite( - "locator_name", - &marker_tracking::MarkerErrorReport::LocatorEntry::locatorName) - .def_readwrite( - "frames_error", - &marker_tracking::MarkerErrorReport::LocatorEntry::framesError) - .def_readwrite( - "has_data", - &marker_tracking::MarkerErrorReport::LocatorEntry::hasData) - .def_readwrite( - "average_error", - &marker_tracking::MarkerErrorReport::LocatorEntry::averageError); - - py::class_( - markerErrorReport, - "OcclusionInfo", - "a struct within MarkerErrorReport, called OcclusionInfo") - .def(py::init<>()) - .def_readwrite( - "frame_id", - &marker_tracking::MarkerErrorReport::OcclusionInfo::frameId) - .def_readwrite( - "locator_names", - &marker_tracking::MarkerErrorReport::OcclusionInfo::locatorNames); - - markerErrorReport.def(py::init<>()) - .def_readwrite( - "unused_locators", - &marker_tracking::MarkerErrorReport::unusedLocators, - "Locators that are not used") - .def_readwrite( - "unused_markers", - &marker_tracking::MarkerErrorReport::unusedMarkers, - "Markers that are not used") - .def_readwrite( - "entries", - &marker_tracking::MarkerErrorReport::entries, - "vector") - .def_readwrite( - "occluded", - &marker_tracking::MarkerErrorReport::occluded, - "vector"); - - // (see find_segment_collisions) - m.def( - "generate_marker_error_report_on_files", - [](const std::string& markerFile, const std::string& motionGlbFile) - -> marker_tracking::MarkerErrorReport { - return marker_tracking::generateMarkerErrorReportOnFiles( - markerFile, motionGlbFile); - }, - py::arg("marker_file"), - py::arg("motion_glb_file")); - - // Bindings for APIs and types defined in - // marker_tracking/metrics/self_collision_detector.h - auto bodySegmentCollisionResult = py::class_< - marker_tracking::BodySegmentCollisionResult>( - m, - "BodySegmentCollisionResult", - "Represents a body part segment collision result e.g. left hand collides with right hand."); - - bodySegmentCollisionResult.def(py::init<>()) - .def_readonly( - "first_segment", - &marker_tracking::BodySegmentCollisionResult::firstSegment, - "Name of the first body segment") - .def_readonly( - "second_segment", - &marker_tracking::BodySegmentCollisionResult::secondSegment, - "Name of the second body segment") - .def_readonly( - "num_contacts", - &marker_tracking::BodySegmentCollisionResult::numContacts, - "Number of contacts between two body segments") - .def_readonly( - "max_penetration_depth", - &marker_tracking::BodySegmentCollisionResult::maxPenetrationDepth, - "Max penetration depth from detected contacts"); - ; - - auto frameCollisionResult = py::class_( - m, - "FrameCollisionResult", - "Represents the body part segment collision pairs in one frame"); - - frameCollisionResult.def(py::init<>()) - .def_readonly( - "segment_collision_results", - &marker_tracking::FrameCollisionResult::segmentCollisionResults, - "List of all body part segment collisions at the current frame"); - - auto motionSequenceCollisionResult = - py::class_( - m, - "MotionSequenceCollisionResult", - "Represents collision results for a motion sequence."); - - motionSequenceCollisionResult.def(py::init<>()) - .def_readonly( - "sequence_name", - &marker_tracking::MotionSequenceCollisionResult::sequenceName, - "Name of the sequence file") - .def_readonly( - "body_segment_root_names", - &marker_tracking::MotionSequenceCollisionResult::bodySegmentRootNames, - "List of body part segment names used for collision detection") - .def_readonly( - "frame_collision_results", - &marker_tracking::MotionSequenceCollisionResult:: - frameCollisionResults, - "Collision results for all frames in the mocap sequence"); - - py::list bodySegmentRootNameList; - for (const std::string& s : marker_tracking::kBodySegmentRootNames) { - bodySegmentRootNameList.append(s); - } - m.attr("body_segment_roots_default") = bodySegmentRootNameList; - m.def( - "create_body_segments_to_vertices_mapping", - &marker_tracking::createBodySegmentsToVerticesMapping); - m.def( - "find_segment_collisions", - [](const momentum::Character& character, - Eigen::Ref jointParams, - const std::unordered_map>& - bodySegmentToVertices, - const size_t maxContacts) { - return marker_tracking::findSegmentCollisions( - character, jointParams, bodySegmentToVertices, maxContacts); - }, - py::arg("character"), - py::arg("joint_params"), - py::arg("body_segment_to_vertices"), - py::arg("max_contacts")); - - m.def( - "find_collision", - [](const momentum::Mesh& mesh1, - const momentum::Mesh& mesh2, - const size_t maxContacts) { - return marker_tracking::findCollision(mesh1, mesh2, maxContacts); - }, - py::arg("mesh_1"), - py::arg("mesh_2"), - py::arg("max_contacts")); - - m.def( - "create_body_segment_mesh", - [](const momentum::Mesh& originalMesh, - const std::vector& vertexIds, - const std::vector& newVertices) { - return marker_tracking::createBodySegmentMesh( - originalMesh, vertexIds, newVertices); - }, - py::arg("original_mesh"), - py::arg("vertices_ids"), - py::arg("pose_vertices")); - - m.def("detect_self_collisions", &marker_tracking::detectSelfCollisions); - // Bindings for types defined in marker_tracking/marker_tracker.h auto baseConfig = py::class_( m, "BaseConfig", "Represents base config class"); @@ -217,7 +40,7 @@ PYBIND11_MODULE(marker_tracking, m) { .def_readwrite( "min_vis_percent", &marker_tracking::BaseConfig::minVisPercent, - "Minimum percetange of visible markers to be used") + "Minimum percentage of visible markers to be used") .def_readwrite( "loss_alpha", &marker_tracking::BaseConfig::lossAlpha, @@ -339,7 +162,7 @@ PYBIND11_MODULE(marker_tracking, m) { .def_readwrite( "parameters", &marker_tracking::ModelOptions::parameters, - "Path of parameter trasform model file e.g. blueman.model") + "Path of parameter transform model file e.g. blueman.model") .def_readwrite( "locators", &marker_tracking::ModelOptions::locators, @@ -444,7 +267,7 @@ PYBIND11_MODULE(marker_tracking, m) { const marker_tracking::RefineConfig& refineConfig) { // python and cpp have the motion matrix transposed from each other. // Let's do that on the way in and out here so it's consistent for both - // lanangues. + // languages. Eigen::MatrixXf inputMotion(motion.transpose()); // If input identity is not empty, it means the motion is stripped of @@ -452,7 +275,7 @@ PYBIND11_MODULE(marker_tracking, m) { // If the input identity is empty, we assume the identity fields already // exist in the motion matrix. if (identity.size() > 0) { - marker_tracking::ParameterSet idParamSet = + momentum::ParameterSet idParamSet = character.parameterTransform.getScalingParameters(); marker_tracking::fillIdentity(idParamSet, identity, inputMotion); } @@ -466,54 +289,4 @@ PYBIND11_MODULE(marker_tracking, m) { py::arg("motion"), py::arg("marker_data"), py::arg("refine_config")); - - auto markerActorStats = py::class_( - m, - "markerActorStats", - "Class to collect stats from a single actor of a marker file"); - - markerActorStats.def(py::init<>()) - .def_readonly( - "actor_name", - &marker_tracking::MarkerActorStats::actorName, - "Name of a given actor in the marker file") - .def_readonly( - "num_frames", - &marker_tracking::MarkerActorStats::numFrames, - "Number of frames characterizing the marker sequence of the given actor") - .def_readonly( - "fps", - &marker_tracking::MarkerActorStats::fps, - "FPS characterizing the marker sequence of the given actor") - .def_readonly( - "marker_names", - &marker_tracking::MarkerActorStats::markerNames, - "List of all the marker names") - .def_readonly( - "min_count_markers", - &marker_tracking::MarkerActorStats::minCountMarkers, - "Minimum amount of non-occluded markers across the motion sequence") - .def_readonly( - "max_count_markers", - &marker_tracking::MarkerActorStats::maxCountMarkers, - "Maximum amount of non-occluded markers across the motion sequence") - .def_readonly( - "mean_count_markers", - &marker_tracking::MarkerActorStats::meanCountMarkers, - "Average amount of non-occluded markers across the motion sequence"); - - auto markerFileStats = py::class_( - m, "markerFileStats", "Class to extract stats from an input marker file"); - - markerFileStats.def(py::init<>()) - .def_readonly( - "num_actors", - &marker_tracking::MarkerFileStats::numActors, - "Name of actors in the input marker file") - .def_readonly( - "marker_actor_stats", - &marker_tracking::MarkerFileStats::markerActorStats, - "List of the stats related to all actors in the marker file"); - - m.def("stats_from_marker_file", &marker_tracking::statsFromMarkerFile); }