-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAverage.cpp
117 lines (104 loc) · 2.85 KB
/
Average.cpp
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
/**
* @file Average.h
* @author Dan R. Lipsa
* @date 9 June 2010
*
* Implementation for the Average class
*
*/
#include "Average.h"
#include "Debug.h"
#include "DerivedData.h"
#include "ObjectPosition.h"
#include "OpenGLUtils.h"
#include "Settings.h"
#include "Simulation.h"
#include "ViewSettings.h"
Average::Average (
ViewNumber::Enum viewNumber, boost::shared_ptr<Settings> settings,
boost::shared_ptr<const SimulationGroup> simulationGroup,
boost::shared_ptr<DerivedData>* dd) :
AverageInterface (viewNumber), Base (settings, simulationGroup, dd),
m_currentTimeWindow (0)
{
}
void Average::AverageInit ()
{
m_currentTimeWindow = 0;
}
void Average::forAllSubsteps (Operation op, size_t currentTime)
{
size_t stepSize = getStepSize (currentTime);
for (size_t i = 0; i < stepSize; ++i)
(this->*op) (currentTime, i);
}
void Average::executeOperation (
size_t currentTime, Operation op, TimeOperation timeOp,
bool atEnd, size_t timeWindow)
{
if (atEnd)
{
do
{
forAllSubsteps (op, currentTime);
currentTime = timeOp (currentTime, 1);
--m_currentTimeWindow;
}
while (m_currentTimeWindow >= timeWindow);
++m_currentTimeWindow;
}
else
forAllSubsteps (op, currentTime);
}
void Average::AverageStep (int timeDifference, size_t timeWindow)
{
if (timeDifference == 0)
return;
if (abs (timeDifference) > 1)
{
AverageInitStep (timeWindow);
return;
}
Operation firstOp, secondOp;
size_t currentTime = GetSettings ().GetViewTime (GetViewNumber ());
if (timeDifference < 0)
{
++currentTime;
firstOp = &Average::removeStep;
secondOp = &Average::addStep;
}
else
{
firstOp = &Average::addStep;
secondOp = &Average::removeStep;
}
executeOperation (
currentTime, firstOp, std::minus<float> (),
timeDifference < 0, timeWindow);
if (m_currentTimeWindow >= timeWindow && currentTime >= timeWindow)
executeOperation (currentTime - m_currentTimeWindow,
secondOp, std::plus<float> (),
timeDifference > 0, timeWindow);
else
m_currentTimeWindow += timeDifference;
WarnOnOpenGLError ("AverageStep");
}
G3D::Vector3 Average::GetTranslation (size_t timeStep) const
{
const Simulation& simulation = GetSimulation ();
G3D::AABox bb = simulation.GetBoundingBox ();
G3D::Vector3 center = bb.center ();
const ObjectPosition current =
GetObjectPositions ()->GetAverageAroundPosition (timeStep);
G3D::Vector3 t = center - current.m_rotationCenter;
return t;
}
G3D::Vector3 Average::GetTranslation () const
{
const ViewSettings& vs = GetViewSettings ();
return GetTranslation (vs.GetTime ());
}
ViewNumber::Enum Average::GetViewNumber () const
{
return AverageInterface::GetViewNumber ();
}