Overte C++ Documentation
FilterTask.h
1 //
2 // FilterTask.h
3 // render/src/render
4 //
5 // Created by Sam Gateau on 2/2/16.
6 // Copyright 2016 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_render_FilterTask_h
13 #define hifi_render_FilterTask_h
14 
15 #include "Engine.h"
16 #include "ViewFrustum.h"
17 
18 namespace render {
19 
20  class MultiFilterItemsConfig : public Job::Config {
21  Q_OBJECT
22  Q_PROPERTY(int numItems READ getNumItems)
23  public:
24  int numItems{ 0 };
25  int getNumItems() { return numItems; }
26  };
27 
28  // Filter inbound of items into multiple buckets defined from the job's Filter array
29  template <int NUM_FILTERS>
30  class MultiFilterItems {
31  public:
32  using ItemFilterArray = std::array<ItemFilter, NUM_FILTERS>;
33  using ItemBoundsArray = VaryingArray<ItemBounds, NUM_FILTERS>;
34  using Config = MultiFilterItemsConfig;
35  using JobModel = Job::ModelIO<MultiFilterItems, ItemBounds, ItemBoundsArray, Config>;
36 
37  MultiFilterItems() {}
38  MultiFilterItems(const ItemFilterArray& filters) :
39  _filters(filters) {}
40 
41  ItemFilterArray _filters;
42 
43  void configure(const Config& config) {}
44  void run(const RenderContextPointer& renderContext, const ItemBounds& inItems, ItemBoundsArray& outItems) {
45  auto& scene = renderContext->_scene;
46 
47  // Clear previous values
48  for (size_t i = 0; i < NUM_FILTERS; i++) {
49  outItems[i].template edit<ItemBounds>().clear();
50  }
51 
52  // For each item, filter it into one bucket
53  for (auto itemBound : inItems) {
54  auto& item = scene->getItem(itemBound.id);
55  auto itemKey = item.getKey();
56  for (size_t i = 0; i < NUM_FILTERS; i++) {
57  if (_filters[i].test(itemKey)) {
58  outItems[i].template edit<ItemBounds>().emplace_back(itemBound);
59  }
60  }
61  }
62  }
63  };
64 
65  // Filter the items belonging to the job's keep layer
66  class FilterLayeredItems {
67  public:
68  using Outputs = render::VaryingSet2<ItemBounds, ItemBounds>;
69  using JobModel = Job::ModelIO<FilterLayeredItems, ItemBounds, Outputs>;
70 
71  FilterLayeredItems(int keepLayer) :
72  _keepLayer(keepLayer) {}
73 
74  int _keepLayer;
75 
76  void run(const RenderContextPointer& renderContext, const ItemBounds& inItems, Outputs& outputs);
77  };
78 
79  // SliceItems job config defining the slice range
80  class SliceItemsConfig : public Job::Config {
81  Q_OBJECT
82  Q_PROPERTY(int rangeOffset MEMBER rangeOffset)
83  Q_PROPERTY(int rangeLength MEMBER rangeLength)
84  Q_PROPERTY(int numItems READ getNumItems NOTIFY dirty())
85  int numItems { 0 };
86  public:
87  int rangeOffset{ -1 };
88  int rangeLength{ 1 };
89  int getNumItems() { return numItems; }
90  void setNumItems(int n) { numItems = n; emit dirty(); }
91  signals:
92  void dirty();
93  };
94 
95  // Keep items in the job slice (defined from config)
96  class SliceItems {
97  public:
98  using Config = SliceItemsConfig;
99  using JobModel = Job::ModelIO<SliceItems, ItemBounds, ItemBounds, Config>;
100 
101  SliceItems() {}
102  int _rangeOffset{ -1 };
103  int _rangeLength{ 1 };
104 
105  void configure(const Config& config) {
106  _rangeOffset = config.rangeOffset;
107  _rangeLength = config.rangeLength;
108  }
109 
110  void run(const RenderContextPointer& renderContext, const ItemBounds& inItems, ItemBounds& outItems);
111  };
112 
113  // Keep items belonging to the job selection
114  class SelectItems {
115  public:
116  using Inputs = VaryingSet3<ItemBounds, ItemBounds, std::string>;
117  using Outputs = ItemBounds;
118  using JobModel = Job::ModelIO<SelectItems, Inputs, Outputs>;
119 
120  std::string _name;
121  SelectItems() {}
122  SelectItems(const Selection::Name& name) : _name(name) {}
123 
124  void run(const RenderContextPointer& renderContext, const Inputs& inputs, ItemBounds& outItems);
125  };
126 
127  // Same as SelectItems but reorder the output to match the selection order
128  class SelectSortItems {
129  public:
130  using JobModel = Job::ModelIO<SelectSortItems, ItemBounds, ItemBounds>;
131 
132  std::string _name;
133  SelectSortItems(const Selection::Name& name) : _name(name) {}
134 
135  void run(const RenderContextPointer& renderContext, const ItemBounds& inItems, ItemBounds& outItems);
136  };
137 
138  // From meta-Items, generate the sub-items
139  class MetaToSubItems {
140  public:
141  using JobModel = Job::ModelIO<MetaToSubItems, ItemBounds, ItemIDs>;
142 
143  MetaToSubItems() {}
144 
145  void run(const RenderContextPointer& renderContext, const ItemBounds& inItems, ItemIDs& outItems);
146  };
147 
148  // From item IDs build item bounds
149  class IDsToBounds {
150  public:
151  using JobModel = Job::ModelIO<IDsToBounds, ItemIDs, ItemBounds>;
152 
153  IDsToBounds(bool disableAABBs = false) : _disableAABBs(disableAABBs) {}
154 
155  void run(const RenderContextPointer& renderContext, const ItemIDs& inItems, ItemBounds& outItems);
156 
157  private:
158  bool _disableAABBs{ false };
159  };
160 
161 }
162 
163 #endif // hifi_render_FilterTask_h;