Skip to content

Commit 7d06417

Browse files
committed
Fix behavior with totally new mechanism
1 parent d04b18d commit 7d06417

File tree

2 files changed

+62
-19
lines changed

2 files changed

+62
-19
lines changed

src/InfinyToolkit/CenterLineForceField.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ private :
113113
std::vector<int> m_distribution;
114114

115115
Real m_startTimeWave = 1.0;
116+
int centerDone = -4;
117+
int centerStart = 0;
118+
int centerCurrent = 0;
119+
Real nextStart = 0.0;
120+
121+
Real length = 4.0_sreal;
122+
//Real current
116123

117124
}; // definition of the CenterLineForceField class
118125

src/InfinyToolkit/CenterLineForceField.inl

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void CenterLineForceField<DataTypes>::init()
9090

9191
m_startTime = std::chrono::system_clock::now();
9292
sofa::core::objectmodel::BaseObject::d_componentState.setValue(sofa::core::objectmodel::ComponentState::Valid);
93+
nextStart = d_pace.getValue() / length;
9394
}
9495

9596

@@ -177,44 +178,79 @@ void CenterLineForceField<DataTypes>::doUpdate()
177178
pacePercent = std::fmod(time, pace) / pace;
178179
//std::cout << "std::fmod(time, pace): " << std::fmod(time, pace) << std::endl;
179180
//std::cout << "std::fmod(time, pace)/2*pace: " << std::fmod(time, pace)/(2*pace) << std::endl;
180-
//std::cout << "pacePercent: " << pacePercent << std::endl;
181+
//std::cout << "time: " << time << " | pace: " << pace << " | pacePercent: " << pacePercent << std::endl;
181182

182-
183-
184-
//Real factorForce = (pacePercent >= 0.5) ? 1 - pacePercent : pacePercent;
185-
186-
//msg_info() << "Time: " << time << " -> pacePercent: " << pacePercent << " -> " << factorForce;
187-
188-
189-
190-
// const Real force = d_force.getValue() * factorForce;
191-
//const bool uniformF = d_uniformForce.getValue();
183+
if (time >= nextStart) // at every pace/2 we start moving a new center and stop previous one
184+
{
185+
centerStart++;
186+
centerDone++;
187+
188+
//if (centerCurrent == 4)
189+
{
190+
/* centerDone++;
191+
centerCurrent = 0;*/
192+
std::cout << "Center " << centerDone << " done at time " << time << std::endl;
193+
}
194+
195+
//centerDone++;
196+
std::cout << "Center " << centerStart << " started at time " << time << std::endl;
197+
198+
nextStart += pace / length;
199+
}
192200

193201
// G ---- X -- X0
194202

195-
const Real amplitude = 1.0;
203+
const Real amplitude = 0.8;
196204
const Real frequency = pace;
197205

198-
199-
200206
//std::cout << "oscillation: " << oscillation << std::endl;
201-
207+
//std::cout << "centerStart: " << centerStart << " | " << centerDone << " / " << _centers.size() << " centers done." << std::endl;
202208
for (size_t i = 0; i < inX.size(); ++i)
203209
{
204210
int centerId = m_distribution[i];
205211

212+
213+
if (centerId > centerStart || centerId <= centerDone )
214+
{
215+
outX[i] = inX[i];
216+
continue;
217+
}
218+
206219
const Coord& center = m_centersOrdered[centerId];
207220
const Coord& p0 = inX[i];
208221
Coord dir = center - p0;
209222

210-
Real omega = centerId * i;//2.0 * M_PI * frequency;
211-
omega = omega/ m_distribution.size();
212-
Real oscillation = amplitude * std::cos(pacePercent * 2.0 * M_PI + omega);
213-
oscillation = 1.0_sreal - (oscillation + 1.0_sreal) / 2.0_sreal; // normalize between 0 and 1
223+
//Real omega = centerId * i;//2.0 * M_PI * frequency;
224+
//Real omega = Real(centerId) / Real(_centers.size()) * M_PI * 12;
225+
Real omega = centerId * 2.0 * M_PI / length;
226+
Real oscillation = amplitude * std::cos(pacePercent * 2.0 * M_PI - omega);
227+
oscillation = amplitude - (oscillation + amplitude) / 2.0_sreal; // normalize between 0 and 0.9
228+
229+
// cos: [-1; 1] 1 -1 1
230+
// [0; 2] 2 0 2
231+
// [0; 1] 1 0 1
232+
// [1; 0] 0 1 0
233+
234+
// 0.9 -0.9 0.9
235+
// 1.8 0 1.8
236+
// 0.9 0 0.9
237+
// 0 0.9 0
214238

215239
outX[i] = p0 + dir * oscillation;
216240
}
217241

242+
243+
244+
if (centerDone >= int(m_centersOrdered.size()) && pacePercent >= 0.99)
245+
{
246+
std::cout << "centerDone " << centerDone << " | " << m_centersOrdered.size() << std::endl;
247+
248+
centerDone = -4;
249+
centerStart = 0;
250+
nextStart = time + pace / length;
251+
}
252+
253+
218254
}
219255

220256
template<class DataTypes>

0 commit comments

Comments
 (0)