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
2ed9834e
Commit
2ed9834e
authored
7 years ago
by
Alexis Iakovenko
Browse files
Options
Downloads
Patches
Plain Diff
Prepare structure for mean and variance computation
parent
4062294a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Assets/Gesture/Gesture.cs
+22
-91
22 additions, 91 deletions
Assets/Gesture/Gesture.cs
Assets/Replay/Replay.cs
+1
-1
1 addition, 1 deletion
Assets/Replay/Replay.cs
with
23 additions
and
92 deletions
Assets/Gesture/Gesture.cs
+
22
−
91
View file @
2ed9834e
...
...
@@ -5,6 +5,8 @@ using System.IO;
public
class
Gesture
{
public
enum
GestureType
{
Normal
,
Mean
,
Variance
};
static
string
directoryPath
=
"Assets/Record/Recorded/"
;
public
List
<
GestureState
>
states
;
string
name
;
...
...
@@ -14,116 +16,45 @@ public class Gesture
states
=
new
List
<
GestureState
>
();
}
public
Gesture
(
string
name
)
public
Gesture
(
string
name
,
GestureType
type
=
GestureType
.
Normal
)
{
this
.
name
=
name
;
Load
();
//VerifyNormalization ();
Normalize
();
//VerifyNormalization ();
if
(
type
==
GestureType
.
Normal
)
Load
();
else
if
(
type
==
GestureType
.
Mean
)
ComputeMean
();
else
if
(
type
==
GestureType
.
Variance
)
ComputeVariance
();
}
public
void
Normalize
()
void
ComputeMean
()
{
//set 0 as origin/centroid
//find mean position
Vector3
meanPosition
=
new
Vector3
(
0
,
0
,
0
);
foreach
(
GestureState
state
in
states
)
meanPosition
+=
state
.
position
;
meanPosition
/=
states
.
Count
;
//subtract mean position to all positions
foreach
(
GestureState
state
in
states
)
state
.
position
-=
meanPosition
;
//have furthest point have distance 1
//find furthest point length
float
furthestDistance
=
0
;
foreach
(
GestureState
state
in
states
)
{
float
length
=
state
.
position
.
magnitude
;
if
(
length
>
furthestDistance
)
furthestDistance
=
length
;
}
//divide length to all points
foreach
(
GestureState
state
in
states
)
state
.
position
/=
furthestDistance
;
//time normalization: have 100 points.
int
pointNumber
=
100
;
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
++)
//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
))
{
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
)
if
(!
gesturePath
.
Equals
(
path
+
"mean.txt"
)
&&
!
gesturePath
.
Equals
(
path
+
"variance.txt"
))
{
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
;
}
Gesture
gesture
=
new
Gesture
(
gesturePath
);
gesture
.
Load
();
gesturesToMean
.
Add
(
gesture
);
}
normalizedState
.
position
=
normalizedPosition
;
normalizedState
.
rotation
=
normalizedRotation
;
normalizedState
.
timestamp
=
normalizedTimestamp
;
normalizedStates
.
Add
(
normalizedState
);
normalizedTimestamp
+=
timestampStep
;
//Debug.Log ("i: " + i + ", state id: " + stateID + " of " + states.Count);
//Debug.Log ("currentstate T: " + currentState.timestamp + ", pos: " + currentState.position);
//Debug.Log ("normstate T: " + normalizedState.timestamp + ", pos: " + normalizedState.position);
}
states
=
normalizedStates
;
//
Debug.Log ("Time normalization done\n");
//
compute the mean
}
public
void
VerifyNormalization
()
void
ComputeVariance
()
{
Vector3
meanPosition
=
new
Vector3
(
0
,
0
,
0
);
foreach
(
GestureState
state
in
states
)
meanPosition
+=
state
.
position
;
meanPosition
/=
states
.
Count
;
Debug
.
Log
(
"[VerifyNormalization] mean position: "
+
meanPosition
);
float
furthestDistance
=
-
1
;
foreach
(
GestureState
state
in
states
)
{
float
length
=
state
.
position
.
sqrMagnitude
;
if
(
length
>
furthestDistance
)
furthestDistance
=
length
;
}
Debug
.
Log
(
"[VerifyNormalization] furthestDistance: "
+
furthestDistance
);
}
public
void
Load
()
public
void
Load
()
{
states
=
GestureLoader
.
Load
(
FullPath
());
}
private
string
FullPath
()
private
string
FullPath
()
{
return
directoryPath
+
name
+
".txt"
;
}
...
...
This diff is collapsed.
Click to expand it.
Assets/Replay/Replay.cs
+
1
−
1
View file @
2ed9834e
...
...
@@ -46,7 +46,7 @@ public class Replay: MonoBehaviour
public
void
UpdateSelectedGesture
(
int
id
)
{
gestureToReplay
=
new
Gesture
(
replays
[
id
]
+
"/0"
);
gestureToReplay
=
new
Gesture
(
replays
[
id
]
,
Gesture
.
GestureType
.
Mean
);
currentFrame
=
0
;
ApplyCurrentFrameToModel
();
}
...
...
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