GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Pipeline.hpp
Go to the documentation of this file.
1 /* ************************************************************************************************************* */
2 /* */
3 /* GLIP-LIB */
4 /* OpenGL Image Processing LIBrary */
5 /* */
6 /* Author : R. Kerviche */
7 /* LICENSE : MIT License */
8 /* Website : glip-lib.net */
9 /* */
10 /* File : Pipeline.hpp */
11 /* Original Date : August 15th 2011 */
12 /* */
13 /* Description : Pipeline object */
14 /* */
15 /* ************************************************************************************************************* */
16 
24 #ifndef __GLIPLIB_PIPELINE__
25 #define __GLIPLIB_PIPELINE__
26 
27  // Includes
28  #include <ctime>
29  #include <algorithm>
30  #include <map>
31  #include <limits>
32  #include "Core/LibTools.hpp"
33  #include "Core/Component.hpp"
34  #include "Core/Filter.hpp"
35 
36  namespace Glip
37  {
38  namespace CoreGL
39  {
40  // Prototypes
41  class HdlTexture;
42  class __HdlTextureFormat_OnlyData;
43  class HdlFBO;
44  class ShaderSource;
45  class HdlShader;
46  class HdlProgram;
47  }
48 
49  namespace CorePipeline
50  {
51  // Prototypes
52  class PipelineLayout;
53  class Pipeline;
54 
55  // Constants
56  #define ELEMENT_NOT_ASSOCIATED (-2)
57 
58  // Objects
63  class GLIP_API AbstractPipelineLayout : virtual public AbstractComponentLayout
64  {
65  public :
68  {
70  THIS_PIPELINE = -1,
72  FILTER = 0,
74  PIPELINE = 1
75  };
76 
81  struct Connection // Connection goes from idOut::portOut to idIn::portIn
82  {
84  int idIn;
86  int portIn;
88  int idOut;
90  int portOut;
91  };
92 
93  private :
94  // Data
95  typedef std::vector<AbstractComponentLayout*> ComponentList;
96  std::vector<Connection> connections;
97  ComponentList elementsLayout;
98  std::vector<ComponentKind> elementsKind;
99  std::vector<std::string> elementsName;
100  std::vector<int> elementsID;
101 
102  // Friends
103  friend class PipelineLayout;
104 
105  protected :
106  // Tools
107  AbstractPipelineLayout(const std::string& type);
108  void setElementID(int i, int ID);
109  std::vector<Connection> getConnectionDestinations(int id, int p);
110  Connection getConnectionSource(int id, int p);
111 
112  // Friends
113  friend class Pipeline;
114 
115  public :
116  // Tools
118  virtual ~AbstractPipelineLayout(void);
119 
120  void checkElement(int i) const;
121  int getNumElements(void) const;
122  int getNumConnections(void) const;
123  void getInfoElements(int& numFilters, int& numPipelines, int& numUniformVariables);
124  int getElementIndex(const std::string& name) const;
125  bool doesElementExist(const std::string& name) const;
126  bool doesElementExist(const std::vector<std::string>& path) const;
127  ComponentKind getElementKind(int i) const;
128  const std::string& getElementName(int i) const;
129  int getElementID(int i) const;
130  int getElementID(const std::string& name) const;
131  AbstractComponentLayout& componentLayout(int i) const;
132  AbstractComponentLayout& componentLayout(const std::string& name) const;
133 
134  AbstractFilterLayout& filterLayout(int i) const;
135  AbstractFilterLayout& filterLayout(const std::string& name) const;
136  AbstractPipelineLayout& pipelineLayout(int i) const;
137  AbstractPipelineLayout& pipelineLayout(const std::string& name) const;
138  AbstractPipelineLayout& pipelineLayout(const std::vector<std::string>& path); // Cannot be const as it can return itself.
139 
140  Connection getConnection(int i) const;
141  bool check(bool exception = true);
142  };
143 
145 
185  class GLIP_API PipelineLayout : virtual public ComponentLayout, virtual public AbstractPipelineLayout
186  {
187  public :
188  // Tools
189  PipelineLayout(const std::string& type);
191  int add(const AbstractFilterLayout& filterLayout, const std::string& name);
192  int add(const AbstractPipelineLayout& pipelineLayout, const std::string& name);
193  int addInput(const std::string& name);
194  int addOutput(const std::string& name);
195 
196  void connect(int filterOut, int portOut, int filterIn, int portIn);
197  void connect(const std::string& filterOut, const std::string& portOut, const std::string& filterIn, const std::string& portIn);
198  void connectToInput(int port, int filterIn, int portIn);
199  void connectToInput(const std::string& port, const std::string& filterIn, const std::string& portIn);
200  void connectToOutput(int filterOut, int portOut, int port);
201  void connectToOutput(const std::string& filterOut, const std::string& portOut, const std::string& port);
202  void autoConnect(void);
203  };
204 
261  class GLIP_API Pipeline : public AbstractPipelineLayout, public Component
262  {
263  public :
266  {
270  Reset
271  };
272 
273  private :
274  struct ActionHub
275  {
276  std::vector<int> inputBufferIdx; // The index of the buffer providing the argument k.
277  std::vector<int> inputArgumentIdx; // The index of the output providing the argument k.
278  int bufferIdx; // The index of the buffer to use for output.
279  int filterIdx; // The index of the filter.
280  };
281 
282  struct OutputHub
283  {
284  int bufferIdx; // The index of the targeted buffer holding the input.
285  int outputIdx; // The index of the output for this buffer which has to be used.
286  };
287 
288  struct BufferFormatsCell
289  {
290  std::vector<HdlTextureFormat> formats; // Format of the FBO.
291  std::vector<int> outputCounts; // Number of output textures for the current FBO.
292 
293  int size(void) const;
294  void append(const HdlAbstractTextureFormat& fmt, int count);
295  };
296 
297  struct BuffersCell
298  {
299  std::vector<HdlFBO*> buffersList;
300 
301  BuffersCell(const BufferFormatsCell& bufferFormats);
302  ~BuffersCell(void);
303  };
304 
305  // Data
306  std::vector<HdlTexture*> inputsList;
307  BufferFormatsCell bufferFormats;
308  std::map<int, BuffersCell*> cells;
309  BuffersCell* currentCell;
310  std::vector<Filter*> filtersList;
311  std::vector<ActionHub> actionsList;
312  std::vector<OutputHub> outputsList;
313  std::map<int, int> filtersGlobalIDsList;
314 
315  bool firstRun,
316  broken,
317  perfsMonitoring;
318  GLuint queryObject;
319  std::vector<double> perfs;
320  double totalPerf;
321 
322  // Tools
323  Pipeline(const AbstractPipelineLayout& p, const std::string& name, bool fake);
324  void cleanInput(void);
325  void build(int& currentIdx, std::vector<Filter*>& filters, std::map<int, int>& filtersGlobalID, std::vector<Connection>& connections, AbstractPipelineLayout& originalLayout);
326  void allocateBuffers(std::vector<Connection>& connections);
327 
328  protected :
329  // Tools
330  void process(void);
331 
332  public :
333  // Tools
334  Pipeline(const AbstractPipelineLayout& p, const std::string& name);
335  ~Pipeline(void);
336 
337  int getNumActions(void) const;
338  int getSize(bool askDriver = false);
339 
340  Pipeline& operator<<(HdlTexture& texture);
341  Pipeline& operator<<(Pipeline& pipeline);
342  Pipeline& operator<<(ActionType a);
343  HdlTexture& out(int id = 0, int cellID=0);
344  HdlTexture& out(const std::string& portName, int cellID=0);
345  Filter& operator[](int filterID);
346  bool wentThroughFirstRun(void) const;
347  bool isBroken(void) const;
348 
349  int createBuffersCell(void);
350  int getNumBuffersCells(void) const;
351  bool isBuffersCellValid(int cellID) const;
352  int getCurrentCellID(void) const;
353  std::vector<int> getCellIDs(void) const;
354  void changeTargetBuffersCell(int cellID);
355  void removeBuffersCell(int cellID);
356 
357  void enablePerfsMonitoring(void);
358  void disablePerfsMonitoring(void);
359  double getTiming(int filterID);
360  double getTiming(int action, std::string& filterName);
361  double getTotalTiming(void);
362  };
363  }
364  }
365 
366 
367 #endif
Layout of a component template.
Definition: Component.hpp:89
Specific defines for the API structure.
int idOut
The ID of the element emitting the connection.
Definition: Pipeline.hpp:88
Filter object.
Object describing connetion betwen elements in a pipeline.
Definition: Pipeline.hpp:81
Filter layout (Read Only).
Definition: Filter.hpp:59
Pipeline layout (Read Only).
Definition: Pipeline.hpp:63
int idIn
The ID of the element receiving the connection.
Definition: Pipeline.hpp:84
Definition: Component.hpp:32
ComponentKind
Flags describing the component kind.
Definition: Pipeline.hpp:67
Components of pipelines.
To start process.
Definition: Pipeline.hpp:268
int portIn
The ID of the port of the element receiving the connection.
Definition: Pipeline.hpp:86
Element of a pipeline.
Definition: Component.hpp:110
int portOut
The ID of the port of the element emitting the connection.
Definition: Pipeline.hpp:90
Pipeline layout.
Definition: Pipeline.hpp:185
Pipeline object.
Definition: Pipeline.hpp:261
Layout of a component template (Read Only)
Definition: Component.hpp:51
ActionType
Actions enumeration.
Definition: Pipeline.hpp:265