FotoSHOCK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
GraphNode.hpp
1 /*
2  * Copyright 2011, 2012 Lukas Jirkovsky
3  *
4  * This file is part of FotoSHOCKcore.
5  *
6  * FotoSHOCKcore is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * FotoSHOCKcore is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with FotoSHOCKcore. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef GRAPHNODE_H
20 #define GRAPHNODE_H
21 
22 #include "UpdateInfo.hpp"
23 #include "IO/ImageIO.hpp"
24 #include "ImageOperation.hpp"
25 
26 namespace FotoSHOCKcore{
27 
28 class GraphManager;
29 class Graph_private;
30 class ImageBufferBase;
31 class MipMap;
32 class RootLoadImage;
33 class RootCreateImage;
34 
36 
57 class GraphNode {
58  public:
59  friend class GraphManager;
60  friend class Graph_private;
61  friend class UpdateInfo;
62  friend class RootLoadImage;
63  friend class RootCreateImage;
64 
66 
74  ~GraphNode();
75 
77 
87  MipMap* getMipMap();
89 
102  ImageBufferBase* getBuffer(const int mipmapLevel = 0);
103 
105 
112  void saveBuffer(IO::SaveInfo info);
113 
115 
120  const float getElapsedTime() const;
121 
123 
128  const unsigned int id() const;
129 
131 
135  void recalculate();
136 
137 // /// Interrupt the currently running recalculation.
138 // /**
139 // * Interrupts the thread which recalculates the operations in the graph.
140 // * The thread is interrupted the next time it enters one of the predefined interruption points.
141 // */
142 // void interruptRecalculate();
143 //
144 // /// Wait for the recalculate thread to complete.
145 // void join();
146 
148 
157  void confirmOperation();
158 
160 
168  void enabled(bool enable);
170 
173  bool tryEnable();
174 
176 
181  const bool enabled() const;
182 
184 
187  ImageOperation* operation() const;
188 
190 
194 
196 
203  boost::shared_ptr<UpdateInfo> addROI(UpdateInfo updInfo);
207  boost::shared_ptr<UpdateInfo> addROI(ROIinfo ROI);
211  boost::shared_ptr<UpdateInfo> addROI(unsigned int x, unsigned int y, unsigned int sizeX, unsigned int sizeY, const int mipmapLevel);
213 
221  void deleteROI(boost::shared_ptr<UpdateInfo> ROI);
222 
224 
227  const std::vector<GraphNode*>& parents() const;
229 
232  const std::vector<GraphNode*>& children() const;
233  protected:
235 
243  GraphNode(unsigned int id, GraphManager* manager, ImageOperationDescriptor* operationDescr);
245 
251  bool checkInputs();
252  private:
254 
260  MipMap* m_buffer;
262 
268  bool m_cache;
270 
273  ImageOperationDescriptor* m_operationDescriptor;
275 
278  ImageOperation* m_operation;
279 
281 
284  const unsigned int m_nodeID;
285 
287 
292  Inputs m_inputs;
294 
299  Outputs m_outputs;
300 
302  float m_timeTaken;
304 
311  bool m_active;
313 
318  long m_stamp;
320  bool m_enabled;
321 
323  unsigned int m_distance;
324 
326  std::vector<GraphNode*> m_parents;
328  std::vector<GraphNode*> m_children;
329 
330  // TODO: add some checks (if the vector is empty etc)
332 
335  std::vector<GraphNode*>& parentsRW();
336  void setParents(std::vector<GraphNode*> parents);
337  void setParent(std::size_t position, GraphNode* parent);
338  void addParent(GraphNode* parent);
339 
340  // TODO: add some checks (if the vector is empty etc)
342 
345  std::vector<GraphNode*>& childrenRW();
346  void addChild(GraphNode* child);
347 
349 
352  void updateInputs();
353 
355 
359  std::vector<boost::shared_ptr<UpdateInfo> > m_updateInfo;
360 
362 
368  unsigned char m_visited;
369 
371  GraphManager* m_manager;
372 
374 
379  void checkROI(UpdateInfo& info);
380 
382 
385  void invalidateStamp();
386 
388 
396  bool runOperation();
398 
406  bool runOperation(UpdateInfo& info);
407 
409 
418  void createBuffer(unsigned int width, unsigned int height, PixelData format, unsigned int tileExtent, bool allocateTiles = true);
420 
428  void createBuffer(ImageBufferBase* buffer);
430 
435  void createBuffer(MipMap* buffer);
436 
438 
441  void setBuffer(MipMap* buffer);
442 
444  void cleanBuffer();
445 };
446 
447 }
448 
449 #endif