Blue Brain BioExplorer
AnimationParameters.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
5  * scientific data from visualization
6  *
7  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License version 3.0 as published
11  * by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
25 #include "AbstractParameters.h"
26 #include <list>
27 
28 SERIALIZATION_ACCESS(AnimationParameters)
29 
30 namespace core
31 {
33 {
34 public:
36 
38  void print() final;
39 
41  void reset();
42 
44  void setFrame(uint32_t value) { _updateValue(_current, _adjustedCurrent(value)); }
45  uint32_t getFrame() const { return _current; }
47  void setDelta(const int32_t delta);
48  int32_t getDelta() const { return _delta; }
49  void setNumFrames(const uint32_t numFrames, const bool triggerCallback = true)
50  {
51  _updateValue(_numFrames, numFrames, triggerCallback);
52  _updateValue(_current, std::min(_current, _numFrames), triggerCallback);
53  }
54  uint32_t getNumFrames() const { return _numFrames; }
56  void setDt(const double dt, const bool triggerCallback = true) { _updateValue(_dt, dt, triggerCallback); }
57  double getDt() const { return _dt; }
59  void setUnit(const std::string& unit, const bool triggerCallback = true)
60  {
61  _updateValue(_unit, unit, triggerCallback);
62  }
63  using IsReadyCallback = std::function<bool()>;
64 
70  void setIsReadyCallback(const IsReadyCallback& callback) { _isReadyCallback = callback; }
71 
74  {
75  if (_isReadyCallback)
76  {
77  reset();
78  _isReadyCallback = nullptr;
79  }
80  }
81 
82  bool hasIsReadyCallback() const { return !!_isReadyCallback; }
84  void update();
85 
87  void jumpFrames(int frames);
88 
89  void togglePlayback() { _playing = !_playing; }
90  bool isPlaying() const { return _playing; }
91 
92 private:
93  uint32_t _adjustedCurrent(const uint32_t newCurrent) const { return _numFrames == 0 ? 0 : newCurrent % _numFrames; }
94 
95  bool _canUpdateFrame() const;
96 
97  uint32_t _numFrames{0};
98  uint32_t _current{0};
99  int32_t _delta{1};
100  bool _playing{false};
101  double _dt{0};
102  std::string _unit;
103 
104  IsReadyCallback _isReadyCallback;
105 
107 };
108 } // namespace core
#define SERIALIZATION_FRIEND(type)
Definition: Macros.h:32
#define SERIALIZATION_ACCESS(type)
Definition: Macros.h:25
std::function< bool()> IsReadyCallback
void setIsReadyCallback(const IsReadyCallback &callback)
void setDelta(const int32_t delta)
void setUnit(const std::string &unit, const bool triggerCallback=true)
void setDt(const double dt, const bool triggerCallback=true)
void setFrame(uint32_t value)
void setNumFrames(const uint32_t numFrames, const bool triggerCallback=true)
void _updateValue(T &member, const T &newValue, const bool triggerCallback=true)
Definition: BaseObject.h:87