Overte C++ Documentation
Filter.h
1 //
2 // Created by Bradley Austin Davis 2015/10/09
3 // Copyright 2015 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #pragma once
10 #ifndef hifi_Controllers_Filter_h
11 #define hifi_Controllers_Filter_h
12 
13 #include <list>
14 #include <memory>
15 #include <numeric>
16 #include <map>
17 
18 #include <shared/Factory.h>
19 
20 #include <GLMHelpers.h>
21 
22 #include <QtCore/QEasingCurve>
23 
24 #include "../AxisValue.h"
25 #include "../Pose.h"
26 
27 class QJsonValue;
28 
29 namespace controller {
30 
31  // Encapsulates part of a filter chain
32  class Filter {
33  public:
34  using Pointer = std::shared_ptr<Filter>;
35  using List = std::list<Pointer>;
36  using Lambda = std::function<float(float)>;
37  using Factory = hifi::SimpleFactory<Filter, QString>;
38 
39  virtual ~Filter() = default;
40 
41  virtual AxisValue apply(AxisValue value) const = 0;
42  virtual Pose apply(Pose value) const = 0;
43 
44  // Factory features
45  virtual bool parseParameters(const QJsonValue& parameters) { return true; }
46 
47  static Pointer parse(const QJsonValue& json);
48  static void registerBuilder(const QString& name, Factory::Builder builder);
49  static Factory& getFactory() { return _factory; }
50 
51  static bool parseSingleFloatParameter(const QJsonValue& parameters, const QString& name, float& output);
52  static bool parseVec3Parameter(const QJsonValue& parameters, glm::vec3& output);
53  static bool parseQuatParameter(const QJsonValue& parameters, glm::quat& output);
54  static bool parseMat4Parameter(const QJsonValue& parameters, glm::mat4& output);
55  protected:
56  static Factory _factory;
57  };
58 }
59 
60 #define REGISTER_FILTER_CLASS(classEntry) \
61  private: \
62  using Registrar = Filter::Factory::Registrar<classEntry>; \
63  static Registrar _registrar;
64 
65 #define REGISTER_FILTER_CLASS_INSTANCE(classEntry, className) \
66  classEntry::Registrar classEntry::_registrar(className, Filter::getFactory());
67 
68 
69 #endif