From 2bc858be6a38b50938011e8ea34fa797ee563417 Mon Sep 17 00:00:00 2001
From: Patrick Nossol <patrick.nossol@vr.rwth-aachen.de>
Date: Tue, 11 Apr 2023 13:25:20 +0200
Subject: [PATCH] split the looong preprocess recording method into submethods

---
 Source/MoCapPlugin/Private/MCController.cpp | 92 +++++++++++++++------
 Source/MoCapPlugin/Public/MCController.h    |  9 ++
 2 files changed, 75 insertions(+), 26 deletions(-)

diff --git a/Source/MoCapPlugin/Private/MCController.cpp b/Source/MoCapPlugin/Private/MCController.cpp
index da7b0f6..7af1cdb 100644
--- a/Source/MoCapPlugin/Private/MCController.cpp
+++ b/Source/MoCapPlugin/Private/MCController.cpp
@@ -300,12 +300,8 @@ void AMCController::ScaleAnimDataInterval(int start, int end, float DeltaTime, L
 
 }
 
-bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltingPoint) {
-
+void AMCController::TranslateJsonToAnimData() {
 	UMCAnimInstance* AI = AnimSaveState.Pawn->GetAnimInstance();
-
-	//----translate json data to AnimSaveState.AnimData----
-
 	FTimespan LastStamp;
 	FTimespan NextFrame;
 	int CurrentMarker = 0;
@@ -378,14 +374,9 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 
 	}
 
-	//If the animation is empty, continue
-	if (AnimSaveState.AnimData.Num() <= 1) {
-		return false;
-	}
-
-	//----process the anim data----
+}
 
-	//---Sensor turned off -> interpolate
+void AMCController::InterpolateOutages() {
 	for (int i = 0; i < AnimSaveState.AnimData.Num(); i++) {
 
 		FProcessedAnimData& AnimData = AnimSaveState.AnimData[i];
@@ -461,7 +452,7 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 
 				}
 
-				
+
 
 			}
 
@@ -469,7 +460,9 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 
 	}
 
-	//---Smoothing of legs---
+}
+
+void AMCController::LegHipSmoothing() {
 	int smoothTimes = LegSmoothTimes;
 	for (int l = 0; l < smoothTimes; l++) {
 
@@ -482,7 +475,7 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 				continue;
 			}
 
-			TArray<EBodyPart> BodyParts = { EBodyPart::LowerBody/*, EBodyPart::LowerLegL, EBodyPart::LowerLegR*/};
+			TArray<EBodyPart> BodyParts = { EBodyPart::LowerBody/*, EBodyPart::LowerLegL, EBodyPart::LowerLegR*/ };
 			for (EBodyPart BodyPart : BodyParts) {
 
 				FVector PosRes;
@@ -537,9 +530,10 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 
 		}
 	}
-	
-	//---find halting points and scale them up---
-	
+
+}
+
+void AMCController::ScaleHaltingAreas(float StartHaltingPoint, float EndHaltingPoint) {
 	//end point
 	if (EndHaltingPoint > 0.f) {
 
@@ -669,8 +663,9 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 
 	}
 
-	//---shift whole body so that it is centered around the green foot indicators---
+}
 
+void AMCController::CenterBodyOnFootIndicators() {
 	int amount = 0;
 	int start = 0;
 
@@ -712,8 +707,9 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 
 	}
 
-	//---Shift Hip To Reducing Center---
-	
+}
+
+void AMCController::HipHandling() {
 	FVector HipReducingCenterAbsolute = HipReducingCenter + 0.5f * (LeftFootPlane->GetActorLocation() + RightFootPlane->GetActorLocation());
 
 	if (HipShiftToReducingCenter) {
@@ -809,7 +805,9 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 
 	}
 
-	//---Controlling Chest Position---
+}
+
+void AMCController::ChestHandling() {
 	if (ChestControlFactor > 0.f) {
 
 		FVector AvgChestPos;
@@ -871,10 +869,11 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 		}
 	}
 
-	//---adjust feet position so that they are located at the green foot indicators---
+}
 
-	amount = 0;
-	start = 0;
+void AMCController::FeetPositions() {
+	int amount = 0;
+	int start = 0;
 
 	for (int i = 0; i < AnimSaveState.AnimData.Num() && LockFeet && LeftFootPlane && RightFootPlane; i++) {
 
@@ -992,7 +991,9 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 
 	}
 
-	//---return to default pose at start and end---
+}
+
+void AMCController::TakeDefaultPose() {
 	FSensorData DefaultPose;
 	if (ReturnToDefaultPose) {
 
@@ -1085,6 +1086,45 @@ bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltin
 		}
 	}
 
+}
+
+bool AMCController::PreprocessRecording(float StartHaltingPoint, float EndHaltingPoint) {
+
+	//----translate json data to AnimSaveState.AnimData----
+	TranslateJsonToAnimData();
+	
+	//If the animation is empty, continue
+	if (AnimSaveState.AnimData.Num() <= 1) {
+		return false;
+	}
+
+	//--------process the anim data-----------
+	
+	//---Sensor turned off -> interpolate
+	InterpolateOutages();
+
+	//---Smoothing of legs---
+	LegHipSmoothing();
+
+	//---find halting points and scale them up---
+	ScaleHaltingAreas(StartHaltingPoint, EndHaltingPoint);
+
+	//---shift whole body so that it is centered around the green foot indicators---
+	CenterBodyOnFootIndicators();
+	
+	//---Shift Hip To Reducing Center---
+	HipHandling();
+
+	//---Controlling Chest Position---
+	ChestHandling();
+
+	//---adjust feet position so that they are located at the green foot indicators---
+	FeetPositions();
+
+	//---return to default pose at start and end---
+	TakeDefaultPose();
+
+
 	AnimSaveState.NextFrame = FTimespan();
 
 	return true;
diff --git a/Source/MoCapPlugin/Public/MCController.h b/Source/MoCapPlugin/Public/MCController.h
index e0225dd..3c863c6 100644
--- a/Source/MoCapPlugin/Public/MCController.h
+++ b/Source/MoCapPlugin/Public/MCController.h
@@ -102,6 +102,15 @@ protected:
 	void SaveToAnimMode();
 
 	void ScaleAnimDataInterval(int start, int end, float DeltaTime, LinearTransformType LinearTransType, float EasingExponent);
+	void TranslateJsonToAnimData();
+	void InterpolateOutages();
+	void LegHipSmoothing();
+	void ScaleHaltingAreas(float StartHaltingPoint, float EndHaltingPoint);
+	void CenterBodyOnFootIndicators();
+	void HipHandling();
+	void ChestHandling();
+	void FeetPositions();
+	void TakeDefaultPose();
 	bool PreprocessRecording(float StartHaltingPoint, float EndHaltingPoint);
 	void InputNextFrame();
 
-- 
GitLab