trase
Figure.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2018, University of Oxford.
3 All rights reserved.
4 
5 University of Oxford means the Chancellor, Masters and Scholars of the
6 University of Oxford, having an administrative office at Wellington
7 Square, Oxford OX1 2JD, UK.
8 
9 This file is part of trase.
10 
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright notice, this
14  list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18 * Neither the name of the copyright holder nor the names of its
19  contributors may be used to endorse or promote products derived from
20  this software without specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
35 
36 #ifndef FIGURE_H_
37 #define FIGURE_H_
38 
39 #include <array>
40 #include <memory>
41 #include <unordered_map>
42 
43 #include "frontend/Axis.hpp"
44 #include "frontend/Drawable.hpp"
45 
46 namespace trase {
47 
52 class Figure : public Drawable {
54  int m_id;
55 
57  vint2_t m_axis_layout;
58 
60  std::unordered_map<vint2_t, std::shared_ptr<Axis>, vint2_hash, vint2_equal>
61  m_axis_subplots;
62 
64  static int m_num_windows;
65 
66 public:
70  explicit Figure(const std::array<float, 2> &pixels);
71 
72  virtual ~Figure() = default;
73 
74  TRASE_DISPATCH_BACKENDS
75 
79  std::shared_ptr<Axis> axis();
80 
84  std::shared_ptr<Axis> axis(int i, int j);
85 
94  template <typename Backend> void show(Backend &backend);
95 
99  template <typename AnimatedBackend> void draw(AnimatedBackend &backend);
100 
105  template <typename Backend> void draw(Backend &backend, float time);
106 
107 private:
113  std::shared_ptr<Axis> update_layout(const vint2_t &new_position);
114 
115  template <typename Backend> void render_interactive_frame(Backend &backend);
116 #ifdef __EMSCRIPTEN__
117  template <typename Backend> static void emscripten_callback(void *data);
118 #endif
119 };
120 
125 inline std::shared_ptr<Figure> figure(std::array<float, 2> pixels = {
126  {800.0, 600.0}}) {
127  return std::make_shared<Figure>(pixels);
128 }
129 
130 } // namespace trase
131 
132 #include "frontend/Figure.tcc"
133 
134 #endif // FIGURE_H_
a base class for all the backends that support drawing a single frame
Definition: Backend.hpp:50
void draw(AnimatedBackend &backend)
Draw the Figure using the AnimatedBackend provided.
The primary Drawable for each figure.
Definition: Figure.hpp:52
std::shared_ptr< Figure > figure(std::array< float, 2 > pixels={ {800.0, 600.0}})
create a new Figure
Definition: Figure.hpp:125
Figure(const std::array< float, 2 > &pixels)
create a new figure with the given number of pixels
Definition: Figure.cpp:46
Base class for drawable objects in a figure.
Definition: Drawable.hpp:99
An N-dimensional vector class.
Definition: Vector.hpp:59
a base class for all the backends that support animation over time
Definition: Backend.hpp:62
void show(Backend &backend)
Draw the Figure using the Backend provided.
TRASE_DISPATCH_BACKENDS std::shared_ptr< Axis > axis()
Create a new axis at position (0,0) and return a shared pointer to it If the axis already exists retu...
Definition: Figure.cpp:101
hash function for an STL map of 2d int vectors
Definition: Vector.hpp:642
Definition: Backend.cpp:39
equality function for an STL map of 2d int vectors
Definition: Vector.hpp:650
const bfloat2_t & pixels() const
returns this objects drawable area in raw pixels
Definition: Drawable.hpp:156