-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandMangoLaw.cpp
More file actions
148 lines (141 loc) · 5.31 KB
/
HandMangoLaw.cpp
File metadata and controls
148 lines (141 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "stdafx.h"
#include "HandMotionLawsCustom.h"
#include "lagrange_interp_1d.hpp"
//------------------------------------------------------------------------------
namespace NewHand
{
namespace
{
void MangoInputFile (const tstring &filename,
std::vector<double> &angles,
std::vector<double> &frames)
{
std::ifstream fin (filename, std::ios_base::in);
// --------------------------------
if ( fin.is_open () )
{
size_t mii;
if ( fin >> mii )
{ angles.reserve (mii); }
else
{ throw std::exception ("ifstream: input error."); }
double angle = 0.;
while ( fin >> angle )
{ angles.push_back (angle); }
// --------------------------------
size_t m = angles.size ();
frames.resize (m);
// --------------------------------
for ( size_t i = 1U; i < m; ++i )
{ frames[i] = i; }
// --------------------------------
}
else
{ throw std::exception ("ifstream: input error."); }
}
void MangoOutputFile (const tstring &filename,
MotionLaws::VectorDoublesIterator first, size_t n)
{
std::ofstream fout (filename + tstring (_T ("-out.txt")),
std::ofstream::out);
//------------------------------------------------------
auto iter = first;
for ( size_t i = 0U; i < n; ++i )
{ fout << *iter << std::endl;
++iter;
}
}
};
namespace MotionLaws
{
MangoAcceleration::MangoAcceleration (const tstring &filename, bool out) :
filename (filename), out (out)
{ MangoInputFile (filename, angles, frames); }
//------------------------------------------------------
MangoDeceleration::MangoDeceleration (const tstring &filename, bool out) :
filename (filename), out (out)
{ MangoInputFile (filename, angles, frames); }
//------------------------------------------------------
//------------------------------------------------------
void MangoAcceleration::generate (VectorDoublesIterator first, size_t frames_count,
double left_border, double right_border) const
{
VectorDoublesIterator iter = first;
// --------------------------------
size_t n = frames_count;
size_t m = angles.size ();
double a = left_border,
b = right_border;
// --------------------------------
// std::vector<double> new_frames (n);
// double n_frame = 1.;
// for ( auto &frame : new_frames )
// { frame = n_frame * m / n; n_frame += 1.; }
// // --------------------------------
// double* new_angles = lagrange_value_1d (static_cast<int> (m), frames.data (), angles.data (),
// static_cast<int> (n), new_frames.data ());
// --------------------------------
double norm_sum = 0.;
for ( size_t i = 0U; i < n; ++i )
{
double d = angles[size_t (i * m / n)];
norm_sum += d;
*iter = d;
++iter;
}
// --------------------------------
// delete[] new_angles;
// --------------------------------
iter = first;
for ( size_t i = 0U; i < n; ++i )
{ /* apply the normalization */
*iter = *iter * (b - n * a) / norm_sum + a;
++iter;
}
// --------------------------------
if ( out ) MangoOutputFile (filename, first, n);
}
//------------------------------------------------------
void MangoDeceleration::generate (VectorDoublesIterator first, size_t frames_count,
double left_border, double right_border,
double max_velosity) const
{
VectorDoublesIterator iter = first;
size_t n = frames_count;
size_t m = angles.size ();
double a = left_border,
b = right_border,
v = max_velosity;
//------------------------------------------------------
// std::vector<double> new_frames (n);
// size_t n_frame = 1U;
// for ( auto &frame : new_frames )
// { frame = size_t (n_frame * m / n); n_frame += 1.; }
// --------------------------------
// double* new_angles = lagrange_value_1d (static_cast<int> (10), frames.data (), angles.data (),
// static_cast<int> (3), new_frames.data ());
//------------------------------------------------------
double norm_sum = 0.;
for ( size_t i = 0U; i < n; ++i )
{
double d = angles[size_t (i * m / n)]; // new_angles[i];
norm_sum += d;
*iter = d;
++iter;
}
//------------------------------------------------------
// delete[] new_angles;
//------------------------------------------------------
iter = first;
for ( size_t i = 0U; i < n; ++i )
{ /* apply normalization */
*iter = *iter * (b - n * a) / norm_sum + a;
if ( *iter > v ) *iter = v;
++iter;
}
//------------------------------------------------------
if ( out ) MangoOutputFile (filename, first, n);
}
};
//------------------------------------------------------
};