trase
Geometry.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 GEOMETRY_H_
37 #define GEOMETRY_H_
38 
39 #include <memory>
40 #include <vector>
41 
42 #include "frontend/Data.hpp"
43 #include "frontend/Drawable.hpp"
44 #include "frontend/Transform.hpp"
45 #include "util/BBox.hpp"
46 #include "util/Colors.hpp"
47 #include "util/Exception.hpp"
48 
49 namespace trase {
50 
51 // forward declare to be able to store a pointer in Axis
52 class Axis;
53 
54 class Geometry : public Drawable {
55 protected:
57  std::vector<DataWithAesthetic> m_data;
58 
60  std::string m_label;
61 
64 
67 
70 
73 
74 public:
75  explicit Geometry(Axis *parent);
76 
85  void add_frame(const DataWithAesthetic &data, float time);
86 
87  float get_time(const int i) const { return m_times[i]; }
88 
89  const DataWithAesthetic &get_data(const int i) const { return m_data[i]; }
90  DataWithAesthetic &get_data(const int i) { return m_data[i]; }
91  size_t data_size() const { return m_data.size(); }
92 
99  void set_transform(const Transform &transform) { m_transform = transform; }
100 
106  void set_label(const std::string &label) { m_label = label; }
107 
108  const std::string &get_label() const { return m_label; }
109  const Colormap &get_colormap() const { return *m_colormap; }
110 
111 #ifdef TRASE_BACKEND_GL
112  virtual void dispatch_legend(BackendGL &figure, float time,
113  const bfloat2_t &box) = 0;
114 #endif
115  virtual void dispatch_legend(BackendSVG &file, float time,
116  const bfloat2_t &box) = 0;
117  virtual void dispatch_legend(BackendSVG &file, const bfloat2_t &box) = 0;
118 
119  template <typename AnimatedBackend> void draw(AnimatedBackend &backend);
120  template <typename Backend> void draw(Backend &backend, float time);
121  template <typename AnimatedBackend>
122  void draw_legend(AnimatedBackend &backend, const bfloat2_t &box);
123  template <typename Backend>
124  void draw_legend(Backend &backend, float time, const bfloat2_t &box);
125 };
126 
127 } // namespace trase
128 
129 #define TRASE_DISPATCH_LEGEND(backend_type) \
130  void dispatch_legend(backend_type &backend, float time, \
131  const bfloat2_t &box) override { \
132  draw_legend(backend, time, box); \
133  }
134 
135 #define TRASE_ANIMATED_DISPATCH_LEGEND(backend_type) \
136  void dispatch_legend(backend_type &backend, const bfloat2_t &box) override { \
137  draw_legend(backend, box); \
138  }
139 
140 #define TRASE_DISPATCH_LEGEND_SVG \
141  TRASE_DISPATCH_LEGEND(BackendSVG) \
142  TRASE_ANIMATED_DISPATCH_LEGEND(BackendSVG)
143 
144 #ifdef TRASE_BACKEND_GL
145 #define TRASE_DISPATCH_LEGEND_GL TRASE_DISPATCH_LEGEND(BackendGL)
146 #else
147 #define TRASE_DISPATCH_LEGEND_GL
148 #endif
149 
150 #define TRASE_GEOMETRY_DISPATCH_BACKENDS \
151  TRASE_DISPATCH_SVG \
152  TRASE_DISPATCH_GL \
153  TRASE_DISPATCH_LEGEND_SVG \
154  TRASE_DISPATCH_LEGEND_GL
155 
156 #include "frontend/Geometry.tcc"
157 
158 #endif // PLOT1D_H_
void add_frame(const DataWithAesthetic &data, float time)
Adds a new data frame to this plot.
Definition: Geometry.cpp:47
std::vector< float > m_times
the animation frame times (see add_frame_time())
Definition: Drawable.hpp:117
a base class for all the backends that support drawing a single frame
Definition: Backend.hpp:50
Contains the minimum and maximum extents of a hypercube in D dimensional space.
Definition: BBox.hpp:54
An 2D axis that can contain zero or more Geometry objects.
Definition: Axis.hpp:85
a linear segmented colormap
Definition: Colors.hpp:119
std::shared_ptr< Figure > figure(std::array< float, 2 > pixels={ {800.0, 600.0}})
create a new Figure
Definition: Figure.hpp:125
Combination of the RawData class and Aesthetics, this class points to a RawData object, and contains a mapping from aesthetics to RawData column numbers.
Definition: Data.hpp:243
Transform m_transform
transform
Definition: Geometry.hpp:69
const Colormap * m_colormap
colormap
Definition: Geometry.hpp:63
std::string m_label
label
Definition: Geometry.hpp:60
holds a std::function that maps between two DataWithAesthetic classes
Definition: Transform.hpp:68
Base class for drawable objects in a figure.
Definition: Drawable.hpp:99
void set_label(const std::string &label)
Set the label.
Definition: Geometry.hpp:106
Contains classes and functions for handling data and aesthetics.
Definition: BackendGL.hpp:55
std::vector< DataWithAesthetic > m_data
dataset
Definition: Geometry.hpp:57
Limits m_limits
min/max limits of m_data across all frames
Definition: Geometry.hpp:66
a base class for all the backends that support animation over time
Definition: Backend.hpp:62
Definition: Geometry.hpp:54
Definition: BackendSVG.hpp:73
Axis * m_axis
parent axis
Definition: Geometry.hpp:72
void set_transform(const Transform &transform)
Sets the transform.
Definition: Geometry.hpp:99
Definition: Backend.cpp:39