Skip to content

Commit 5e7d569

Browse files
committed
- added Timing class
1 parent 930f401 commit 5e7d569

18 files changed

+329
-68
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- added Timing class
12
- removed Boost dependency
23
- update to Eigen 3.2.9
34
- added support for x86 compilation (thanks to Josef Kohout)

Demos/BarDemo/main.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <iostream>
1010
#include "Demos/Visualization/Visualization.h"
1111
#include "Demos/Utils/Utilities.h"
12+
#include "Demos/Utils/Timing.h"
1213

1314
// Enable memory leak detection
1415
#if defined(_DEBUG) && !defined(EIGEN_ALIGN)
@@ -94,6 +95,8 @@ int main( int argc, char **argv )
9495

9596
cleanup ();
9697

98+
Timing::printAverageTimes();
99+
97100
return 0;
98101
}
99102

@@ -123,6 +126,8 @@ void cleanup()
123126

124127
void reset()
125128
{
129+
Timing::printAverageTimes();
130+
Timing::reset();
126131
model.reset();
127132
sim.reset();
128133
TimeManager::getCurrent()->setTime(0.0);
@@ -224,12 +229,12 @@ void render ()
224229
// Draw simulation model
225230
renderTetModels();
226231

227-
float red[4] = { 0.8f, 0.0f, 0.0f, 1 };
232+
float red[4] = { 0.8f, 0.0f, 0.0f, 1 };
228233
const ParticleData &pd = model.getParticles();
229-
for (unsigned int j = 0; j < selectedParticles.size(); j++)
230-
{
231-
MiniGL::drawSphere(pd.getPosition(selectedParticles[j]), 0.08f, red);
232-
}
234+
for (unsigned int j = 0; j < selectedParticles.size(); j++)
235+
{
236+
MiniGL::drawSphere(pd.getPosition(selectedParticles[j]), 0.08f, red);
237+
}
233238

234239
MiniGL::drawTime( TimeManager::getCurrent ()->getTime ());
235240
}

Demos/ClothDemo/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <iostream>
1010
#include "Demos/Visualization/Visualization.h"
1111
#include "Demos/Utils/Utilities.h"
12+
#include "Demos/Utils/Timing.h"
1213

1314
// Enable memory leak detection
1415
#if defined(_DEBUG) && !defined(EIGEN_ALIGN)
@@ -118,6 +119,8 @@ int main( int argc, char **argv )
118119

119120
cleanup ();
120121

122+
Timing::printAverageTimes();
123+
121124
return 0;
122125
}
123126

@@ -147,6 +150,9 @@ void cleanup()
147150

148151
void reset()
149152
{
153+
Timing::printAverageTimes();
154+
Timing::reset();
155+
150156
model.reset();
151157
sim.reset();
152158
TimeManager::getCurrent()->setTime(0.0);

Demos/CouplingDemos/RigidBodyClothCouplingDemo.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Demos/Visualization/Visualization.h"
1212
#include "Demos/Utils/OBJLoader.h"
1313
#include "Demos/Utils/Utilities.h"
14+
#include "Demos/Utils/Timing.h"
1415

1516
#define _USE_MATH_DEFINES
1617
#include "math.h"
@@ -179,6 +180,9 @@ void cleanup()
179180

180181
void reset()
181182
{
183+
Timing::printAverageTimes();
184+
Timing::reset();
185+
182186
model.reset();
183187
sim.reset();
184188
TimeManager::getCurrent()->setTime(0.0);
@@ -211,8 +215,8 @@ void mouseMove(int x, int y)
211215

212216
void selection(const Eigen::Vector2i &start, const Eigen::Vector2i &end)
213217
{
214-
std::vector<unsigned int> hits;
215-
218+
std::vector<unsigned int> hits;
219+
216220
selectedParticles.clear();
217221
ParticleData &pd = model.getParticles();
218222
Selection::selectRect(start, end, &pd.getPosition(0), &pd.getPosition(pd.size() - 1), selectedParticles);
@@ -221,18 +225,18 @@ void selection(const Eigen::Vector2i &start, const Eigen::Vector2i &end)
221225
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
222226
std::vector<Vector3r, Eigen::aligned_allocator<Vector3r> > x;
223227
x.resize(rb.size());
224-
for (unsigned int i = 0; i < rb.size(); i++)
225-
{
226-
x[i] = rb[i]->getPosition();
227-
}
228+
for (unsigned int i = 0; i < rb.size(); i++)
229+
{
230+
x[i] = rb[i]->getPosition();
231+
}
228232

229-
Selection::selectRect(start, end, &x[0], &x[rb.size() - 1], selectedBodies);
233+
Selection::selectRect(start, end, &x[0], &x[rb.size() - 1], selectedBodies);
230234
if ((selectedBodies.size() > 0) || (selectedParticles.size() > 0))
231-
MiniGL::setMouseMoveFunc(GLUT_MIDDLE_BUTTON, mouseMove);
232-
else
233-
MiniGL::setMouseMoveFunc(-1, NULL);
235+
MiniGL::setMouseMoveFunc(GLUT_MIDDLE_BUTTON, mouseMove);
236+
else
237+
MiniGL::setMouseMoveFunc(-1, NULL);
234238

235-
MiniGL::unproject(end[0], end[1], oldMousePos);
239+
MiniGL::unproject(end[0], end[1], oldMousePos);
236240
}
237241

238242
void timeStep ()
@@ -366,11 +370,11 @@ void renderTriangleModels()
366370
if (shaderTex)
367371
shaderTex->end();
368372

369-
float red[4] = { 0.8f, 0.0, 0.0, 1 };
370-
for (unsigned int j = 0; j < selectedParticles.size(); j++)
371-
{
372-
MiniGL::drawSphere(pd.getPosition(selectedParticles[j]), 0.08f, red);
373-
}
373+
float red[4] = { 0.8f, 0.0, 0.0, 1 };
374+
for (unsigned int j = 0; j < selectedParticles.size(); j++)
375+
{
376+
MiniGL::drawSphere(pd.getPosition(selectedParticles[j]), 0.08f, red);
377+
}
374378
}
375379

376380

Demos/DistanceFieldDemos/ClothCollisionDemo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Demos/Utils/Utilities.h"
1313
#include "Demos/Simulation/DistanceFieldCollisionDetection.h"
1414
#include "Demos/Utils/OBJLoader.h"
15+
#include "Demos/Utils/Timing.h"
1516

1617
// Enable memory leak detection
1718
#if defined(_DEBUG) && !defined(EIGEN_ALIGN)
@@ -141,6 +142,8 @@ int main( int argc, char **argv )
141142
glutMainLoop ();
142143

143144
cleanup ();
145+
146+
Timing::printAverageTimes();
144147

145148
return 0;
146149
}
@@ -187,6 +190,9 @@ void cleanup()
187190

188191
void reset()
189192
{
193+
Timing::printAverageTimes();
194+
Timing::reset();
195+
190196
model.reset();
191197
sim.reset();
192198
TimeManager::getCurrent()->setTime(0.0);

Demos/DistanceFieldDemos/DeformableCollisionDemo.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Demos/Utils/Utilities.h"
1212
#include "Demos/Simulation/DistanceFieldCollisionDetection.h"
1313
#include "Demos/Utils/OBJLoader.h"
14+
#include "Demos/Utils/Timing.h"
1415

1516
// Enable memory leak detection
1617
#if defined(_DEBUG) && !defined(EIGEN_ALIGN)
@@ -117,6 +118,8 @@ int main( int argc, char **argv )
117118

118119
cleanup ();
119120

121+
Timing::printAverageTimes();
122+
120123
return 0;
121124
}
122125

@@ -146,6 +149,8 @@ void cleanup()
146149

147150
void reset()
148151
{
152+
Timing::printAverageTimes();
153+
Timing::reset();
149154
model.reset();
150155
sim.reset();
151156
TimeManager::getCurrent()->setTime(0.0);
@@ -321,12 +326,12 @@ void render ()
321326
// Draw simulation model
322327
renderModels();
323328

324-
float red[4] = { 0.8f, 0.0f, 0.0f, 1 };
329+
float red[4] = { 0.8f, 0.0f, 0.0f, 1 };
325330
const ParticleData &pd = model.getParticles();
326-
for (unsigned int j = 0; j < selectedParticles.size(); j++)
327-
{
328-
MiniGL::drawSphere(pd.getPosition(selectedParticles[j]), 0.08f, red);
329-
}
331+
for (unsigned int j = 0; j < selectedParticles.size(); j++)
332+
{
333+
MiniGL::drawSphere(pd.getPosition(selectedParticles[j]), 0.08f, red);
334+
}
330335

331336
if (renderContacts)
332337
{

Demos/DistanceFieldDemos/RigidBodyCollisionDemo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Demos/Visualization/Visualization.h"
1212
#include "Demos/Utils/Utilities.h"
1313
#include "Demos/Simulation/DistanceFieldCollisionDetection.h"
14+
#include "Demos/Utils/Timing.h"
1415

1516
#define _USE_MATH_DEFINES
1617
#include "math.h"
@@ -95,6 +96,8 @@ int main( int argc, char **argv )
9596
glutMainLoop ();
9697

9798
cleanup ();
99+
100+
Timing::printAverageTimes();
98101

99102
return 0;
100103
}
@@ -141,6 +144,9 @@ void cleanup()
141144

142145
void reset()
143146
{
147+
Timing::printAverageTimes();
148+
Timing::reset();
149+
144150
model.reset();
145151
sim.reset();
146152
TimeManager::getCurrent()->setTime(0.0);

Demos/FluidDemo/TimeStepFluidModel.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "PositionBasedDynamics/PositionBasedFluids.h"
44
#include "PositionBasedDynamics/TimeIntegration.h"
55
#include "PositionBasedDynamics/SPHKernels.h"
6+
#include "Demos/Utils/Timing.h"
67

78
using namespace PBD;
89
using namespace std;
@@ -17,6 +18,7 @@ TimeStepFluidModel::~TimeStepFluidModel(void)
1718

1819
void TimeStepFluidModel::step(FluidModel &model)
1920
{
21+
START_TIMING("simulation step");
2022
TimeManager *tm = TimeManager::getCurrent ();
2123
const Real h = tm->getTimeStepSize();
2224
ParticleData &pd = model.getParticles();
@@ -36,10 +38,14 @@ void TimeStepFluidModel::step(FluidModel &model)
3638
}
3739

3840
// Perform neighborhood search
41+
START_TIMING("neighborhood search");
3942
model.getNeighborhoodSearch()->neighborhoodSearch(&model.getParticles().getPosition(0), model.numBoundaryParticles(), &model.getBoundaryX(0));
43+
STOP_TIMING_AVG;
4044

4145
// Solve density constraint
46+
START_TIMING("constraint projection");
4247
constraintProjection(model);
48+
STOP_TIMING_AVG;
4349

4450
// Update velocities
4551
for (unsigned int i = 0; i < pd.size(); i++)
@@ -56,6 +62,7 @@ void TimeStepFluidModel::step(FluidModel &model)
5662
// Compute new time
5763
tm->setTime (tm->getTime () + h);
5864
model.getNeighborhoodSearch()->update();
65+
STOP_TIMING_AVG;
5966
}
6067

6168

Demos/FluidDemo/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "TimeStepFluidModel.h"
1010
#include <iostream>
1111
#include "Demos/Utils/Utilities.h"
12+
#include "Demos/Utils/Timing.h"
1213

1314
// Enable memory leak detection
1415
#if defined(_DEBUG) && !defined(EIGEN_ALIGN)
@@ -98,6 +99,8 @@ int main( int argc, char **argv )
9899
glutMainLoop ();
99100

100101
cleanup ();
102+
103+
Timing::printAverageTimes();
101104

102105
return 0;
103106
}
@@ -111,6 +114,9 @@ void cleanup()
111114

112115
void reset()
113116
{
117+
Timing::printAverageTimes();
118+
Timing::reset();
119+
114120
model.reset();
115121
simulation.reset();
116122
TimeManager::getCurrent()->setTime(0.0);

Demos/GenericConstraintsDemos/GenericParticleConstraintsDemo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Demos/Simulation/TimeStepController.h"
1010
#include "Demos/Visualization/Visualization.h"
1111
#include "Demos/Utils/Utilities.h"
12+
#include "Demos/Utils/Timing.h"
1213

1314
// Enable memory leak detection
1415
#if defined(_DEBUG) && !defined(EIGEN_ALIGN)
@@ -84,6 +85,8 @@ int main( int argc, char **argv )
8485

8586
cleanup ();
8687

88+
Timing::printAverageTimes();
89+
8790
return 0;
8891
}
8992

@@ -113,6 +116,9 @@ void cleanup()
113116

114117
void reset()
115118
{
119+
Timing::printAverageTimes();
120+
Timing::reset();
121+
116122
model.reset();
117123
simulation.reset();
118124
TimeManager::getCurrent()->setTime(0.0);

Demos/PositionBasedElasticRodsDemo/PositionBasedElasticRodsDemo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "PositionBasedElasticRodsConstraints.h"
99
#include "PositionBasedElasticRodsTSC.h"
1010
#include <iostream>
11+
#include "Demos/Utils/Timing.h"
1112

1213
#define _USE_MATH_DEFINES
1314
#include "math.h"
@@ -92,6 +93,8 @@ int main( int argc, char **argv )
9293
glutMainLoop ();
9394

9495
cleanup ();
96+
97+
Timing::printAverageTimes();
9598

9699
return 0;
97100
}
@@ -103,6 +106,9 @@ void cleanup()
103106

104107
void reset()
105108
{
109+
Timing::printAverageTimes();
110+
Timing::reset();
111+
106112
model.reset();
107113
sim.reset();
108114
TimeManager::getCurrent()->setTime(0.0);

0 commit comments

Comments
 (0)