-
Notifications
You must be signed in to change notification settings - Fork 0
/
BodyAlongTime.h
167 lines (142 loc) · 3.67 KB
/
BodyAlongTime.h
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* @file BodyAlongTime.h
* @author Dan R. Lipsa
* @date 15 May 2010
* @ingroup data model
* @brief A bubble path
*/
#ifndef __BODY_ALONG_TIME_H__
#define __BODY_ALONG_TIME_H__
#include "StripIterator.h"
#include "Enums.h"
class Body;
class Simulation;
/**
* @brief A bubble path
*/
class BodyAlongTime
{
public:
typedef vector<boost::shared_ptr<Body> > Bodies;
typedef vector<size_t> Wraps;
typedef vector<G3D::Vector3int16> Translations;
public:
BodyAlongTime (size_t timeSteps);
size_t GetId () const;
const boost::shared_ptr<Body>& GetBody (size_t timeStep) const
{
return m_bodyAlongTime[timeStep];
}
void SetBody (size_t timeStep, const boost::shared_ptr<Body>& body);
size_t GetTimeBegin () const
{
return m_timeBegin;
}
size_t GetTimeEnd () const
{
return m_timeEnd;
}
/**
* Calculates when from one time step to another a body is wrapped around
* the original domain. A body wraps around when it moves a distance longer
* than 1/2 of min all sides of the original domain
*/
void CalculateBodyWraps (const Simulation& simulation);
StripIterator GetStripIterator (const Simulation& simulation) const
{
return StripIterator (*this, simulation);
}
size_t GetWrapSize () const
{
return m_wraps.size ();
}
size_t GetWrap (size_t i) const
{
return m_wraps[i];
}
G3D::Vector3int16 GetTranslation (size_t currentWrap) const
{
return m_translations[currentWrap];
}
string ToString () const;
void AssertDeadBubblesStayDead () const;
public:
friend ostream& operator<< (
ostream& ostr, const BodyAlongTime& bodyAlongTime);
private:
Bodies m_bodyAlongTime;
/**
* A bubble can appear after time 0 and disappear before time n.
* I assume bubble IDs are not reused. :-) That is, once a bubble has
* dissapeared, it cannot appear again.
* A bubble exists between m_timeBeing <= time < m_timeEnd.
*/
size_t m_timeBegin;
size_t m_timeEnd;
/**
* List of times (indexes in Bodies vector) where a body wraps
* around the torus original domain. The wrap is between index and
* index + 1. If there are no wraps this vector has 0 length.
*/
Wraps m_wraps;
/**
* Translation between step index and step index + 1.
* @see Wraps
*/
Translations m_translations;
};
/**
* @brief A map between the bubble ID and the bubble path
*/
class BodiesAlongTime
{
public:
typedef map <size_t, boost::shared_ptr<BodyAlongTime> > BodyMap;
public:
BodiesAlongTime ();
size_t GetBodyCount ()
{
return m_bodyMap.size ();
}
void AllocateBodyAlongTime (size_t bodyId, size_t timeSteps);
void CacheBody (
boost::shared_ptr<Body> body, size_t timeStep, size_t timeSteps);
BodyMap& GetBodyMap ()
{
return m_bodyMap;
}
const BodyMap& GetBodyMap () const
{
return m_bodyMap;
}
BodyAlongTime& GetBodyAlongTime (size_t id)
{
return getBodyAlongTime (id);
}
const BodyAlongTime& GetBodyAlongTime (size_t id) const
{
return getBodyAlongTime (id);
}
string ToString () const;
void AssertDeadBubblesStayDead () const;
private:
BodyAlongTime& getBodyAlongTime (size_t id) const;
private:
/**
* Map between the original index of the body and the body along time
*/
BodyMap m_bodyMap;
};
inline ostream& operator<< (ostream& ostr, const BodyAlongTime& bat)
{
return ostr << bat.ToString ();
}
inline ostream& operator<< (
ostream& ostr, const BodiesAlongTime& bodiesAlongTime)
{
return ostr << bodiesAlongTime.ToString ();
}
#endif //__BODY_ALONG_TIME_H__
// Local Variables:
// mode: c++
// End: