Blender
V2.93
source
blender
depsgraph
intern
debug
deg_time_average.h
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or
3
* modify it under the terms of the GNU General Public License
4
* as published by the Free Software Foundation; either version 2
5
* of the License, or (at your option) any later version.
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software Foundation,
14
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
*
16
* The Original Code is Copyright (C) 2013 Blender Foundation.
17
* All rights reserved.
18
*/
19
24
#pragma once
25
26
namespace
blender
{
27
namespace
deg
{
28
29
// Utility class which takes care of calculating average of time series, such as
30
// FPS counters.
31
template
<
int
MaxSamples>
class
AveragedTimeSampler
{
32
public
:
33
AveragedTimeSampler
() :
num_samples_
(0),
next_sample_index_
(0)
34
{
35
}
36
37
void
add_sample
(
double
value)
38
{
39
samples_
[
next_sample_index_
] = value;
40
41
// Move to the next index, keeping wrapping at the end of array into account.
42
++
next_sample_index_
;
43
if
(
next_sample_index_
== MaxSamples) {
44
next_sample_index_
= 0;
45
}
46
47
// Update number of stored samples.
48
if
(
num_samples_
!= MaxSamples) {
49
++
num_samples_
;
50
}
51
}
52
53
double
get_averaged
()
const
54
{
55
double
sum
= 0.0;
56
for
(
int
i = 0; i <
num_samples_
; ++i) {
57
sum
+=
samples_
[i];
58
}
59
return
sum
/
num_samples_
;
60
}
61
62
protected
:
63
double
samples_
[MaxSamples];
64
65
// Number of samples which are actually stored in the array.
66
int
num_samples_
;
67
68
// Index in the samples_ array under which next sample will be stored.
69
int
next_sample_index_
;
70
};
71
72
}
// namespace deg
73
}
// namespace blender
sum
static T sum(const btAlignedObjectArray< T > &items)
Definition:
btSoftBodyHelpers.cpp:94
blender::deg::AveragedTimeSampler
Definition:
deg_time_average.h:31
blender::deg::AveragedTimeSampler::AveragedTimeSampler
AveragedTimeSampler()
Definition:
deg_time_average.h:33
blender::deg::AveragedTimeSampler::add_sample
void add_sample(double value)
Definition:
deg_time_average.h:37
blender::deg::AveragedTimeSampler::samples_
double samples_[MaxSamples]
Definition:
deg_time_average.h:63
blender::deg::AveragedTimeSampler::num_samples_
int num_samples_
Definition:
deg_time_average.h:66
blender::deg::AveragedTimeSampler::next_sample_index_
int next_sample_index_
Definition:
deg_time_average.h:69
blender::deg::AveragedTimeSampler::get_averaged
double get_averaged() const
Definition:
deg_time_average.h:53
blender::deg
Definition:
deg_builder.cc:53
blender
Definition:
BKE_attribute_access.hh:30
Generated on Tue Jan 31 2023 14:37:24 for Blender by
doxygen
1.9.1