Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
embodiment-learning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SoftwareProjectVR17
embodiment-learning
Commits
893170e5
Commit
893170e5
authored
7 years ago
by
Alexis Iakovenko
Browse files
Options
Downloads
Patches
Plain Diff
Compute mean for replay
parent
2ed9834e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assets/Gesture/Gesture.cs
+92
-12
92 additions, 12 deletions
Assets/Gesture/Gesture.cs
with
92 additions
and
12 deletions
Assets/Gesture/Gesture.cs
+
92
−
12
View file @
893170e5
...
...
@@ -18,10 +18,9 @@ public class Gesture
public
Gesture
(
string
name
,
GestureType
type
=
GestureType
.
Normal
)
{
states
=
new
List
<
GestureState
>
();
this
.
name
=
name
;
if
(
type
==
GestureType
.
Normal
)
Load
();
else
if
(
type
==
GestureType
.
Mean
)
if
(
type
==
GestureType
.
Mean
)
ComputeMean
();
else
if
(
type
==
GestureType
.
Variance
)
ComputeVariance
();
...
...
@@ -29,34 +28,115 @@ public class Gesture
void
ComputeMean
()
{
//Debug.Log ("[Gesture:ComputeMean] Start computing mean ");
//find and load gestures to compare for the mean
List
<
Gesture
>
gesturesToMean
=
new
List
<
Gesture
>
();
string
path
=
"Assets/Record/Recorded/"
+
name
+
"/"
;
foreach
(
string
gesturePath
in
Directory
.
GetDirectories
(
path
))
//Debug.Log ("[Gesture:ComputeMean] path " + path);
foreach
(
string
gesturePath
in
Directory
.
GetFiles
(
path
))
{
if
(!
gesturePath
.
Equals
(
path
+
"mean.txt"
)
&&
!
gesturePath
.
Equals
(
path
+
"variance.txt"
))
//Debug.Log ("[Gesture:ComputeMean] gesturePath " + gesturePath);
if
(
gesturePath
.
Substring
(
gesturePath
.
Length
-
4
).
Equals
(
".txt"
)
&&
!
gesturePath
.
Equals
(
path
+
"mean.txt"
)
&&
!
gesturePath
.
Equals
(
path
+
"variance.txt"
))
{
Gesture
gesture
=
new
Gesture
(
gesturePath
);
gesture
.
Load
();
Gesture
gesture
=
new
Gesture
(
name
);
gesture
.
Load
(
gesturePath
);
gesturesToMean
.
Add
(
gesture
);
}
}
//compute the mean
if
(
gesturesToMean
.
Count
==
0
)
return
;
//find mean time and normalize towards it
int
meanTime
=
0
;
foreach
(
Gesture
gesture
in
gesturesToMean
)
meanTime
+=
gesture
.
states
.
Count
;
meanTime
/=
gesturesToMean
.
Count
;
foreach
(
Gesture
gesture
in
gesturesToMean
)
gesture
.
NormalizeTime
(
meanTime
);
//for each frame, compute position and rotation mean
for
(
int
i
=
0
;
i
<
meanTime
;
i
++)
{
Vector3
positionMean
=
new
Vector3
(
0
,
0
,
0
);
Vector4
rotationMean
=
new
Vector4
(
0
,
0
,
0
,
0
);
float
timestampMean
=
0.0f
;
foreach
(
Gesture
gesture
in
gesturesToMean
)
{
timestampMean
+=
gesture
.
states
[
i
].
timestamp
;
positionMean
+=
gesture
.
states
[
i
].
position
;
rotationMean
+=
gesture
.
states
[
i
].
rotation
;
}
timestampMean
/=
gesturesToMean
.
Count
;
positionMean
/=
gesturesToMean
.
Count
;
rotationMean
/=
gesturesToMean
.
Count
;
GestureState
stateMean
=
new
GestureState
();
stateMean
.
position
=
positionMean
;
stateMean
.
rotation
=
rotationMean
;
stateMean
.
timestamp
=
timestampMean
;
states
.
Add
(
stateMean
);
}
Debug
.
Log
(
"[Gesture:ComputeMean] Finished computing mean "
+
meanTime
);
}
void
ComputeVariance
()
{
}
public
void
Load
(
)
public
void
NormalizeTime
(
int
pointNumber
)
{
states
=
GestureLoader
.
Load
(
FullPath
());
if
(
pointNumber
==
states
.
Count
)
return
;
float
timeNormalizationFactor
=
pointNumber
*
1.0f
/
states
.
Count
;
//Debug.Log ("Time normalization, factor: " + timeNormalizationFactor);
List
<
GestureState
>
normalizedStates
=
new
List
<
GestureState
>();
float
timestampStep
=
(
states
[
states
.
Count
-
1
].
timestamp
-
states
[
0
].
timestamp
)
/
(
states
.
Count
-
1
);
float
normalizedTimestamp
=
states
[
0
].
timestamp
;
for
(
int
i
=
0
;
i
<
pointNumber
;
i
++)
{
GestureState
normalizedState
=
new
GestureState
();
int
stateID
=
(
int
)
Mathf
.
Floor
(
i
/
timeNormalizationFactor
);
GestureState
currentState
=
states
[
stateID
];
Vector3
normalizedPosition
=
states
[
stateID
].
position
;
Vector3
normalizedRotation
=
states
[
stateID
].
rotation
;
if
(
stateID
>
0
&&
stateID
<
states
.
Count
-
1
)
{
GestureState
nextState
=
states
[
stateID
+
1
];
float
smallTimestamp
=
(
normalizedTimestamp
-
currentState
.
timestamp
);
if
(
smallTimestamp
!=
0
)
{
float
smallFactor
=
(
nextState
.
timestamp
-
currentState
.
timestamp
)
/
smallTimestamp
;
Vector3
positionToNextState
=
nextState
.
position
-
currentState
.
position
;
normalizedPosition
=
currentState
.
position
+
positionToNextState
*
smallFactor
;
Vector4
rotationToNextState
=
nextState
.
rotation
-
currentState
.
rotation
;
normalizedRotation
=
currentState
.
rotation
+
rotationToNextState
*
smallFactor
;
}
}
normalizedState
.
position
=
normalizedPosition
;
normalizedState
.
rotation
=
normalizedRotation
;
normalizedState
.
timestamp
=
normalizedTimestamp
;
normalizedStates
.
Add
(
normalizedState
);
normalizedTimestamp
+=
timestampStep
;
}
states
=
normalizedStates
;
}
p
rivate
string
FullP
ath
(
)
p
ublic
void
Load
(
string
p
ath
)
{
return
directoryPath
+
name
+
".txt"
;
states
=
GestureLoader
.
Load
(
path
)
;
}
public
override
string
ToString
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment