trase
Transform.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 TRANSFORM_H_
37 #define TRANSFORM_H_
38 
39 #include <functional>
40 
41 #include "frontend/Data.hpp"
42 #include "util/BBox.hpp"
43 
44 namespace trase {
45 
47 struct Identity {
48  DataWithAesthetic operator()(const DataWithAesthetic &data) const {
49  return data;
50  }
51 };
52 
56 class BinX {
57  int m_number_of_bins{-1};
58  bbox<float, 1> m_span;
59 
60 public:
61  BinX() = default;
62  explicit BinX(int number_of_bins);
63  explicit BinX(int number_of_bins, float min, float max);
64  DataWithAesthetic operator()(const DataWithAesthetic &data);
65 };
66 
68 class Transform {
69  std::function<DataWithAesthetic(const DataWithAesthetic &)> m_transform;
70 
71 public:
73  Transform() : m_transform(Identity()) {}
74 
78  template <typename T>
79  explicit Transform(const T &transform) : m_transform(transform) {}
80 
83  return m_transform(data);
84  }
85 };
86 
87 } // namespace trase
88 
89 #endif // TRANSFORM_H_
DataWithAesthetic operator()(const DataWithAesthetic &data)
perform mapping on data, return result
Definition: Transform.hpp:82
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(const T &transform)
construct a Transform wrapping the given transform function T.
Definition: Transform.hpp:79
holds a std::function that maps between two DataWithAesthetic classes
Definition: Transform.hpp:68
Contains classes and functions for handling data and aesthetics.
bin x coordinates
Definition: Transform.hpp:56
Identity transform, just pass through...
Definition: Transform.hpp:47
Transform()
construct an identity transform
Definition: Transform.hpp:73
Definition: Backend.cpp:39