FAST  3.2.0
Framework for Heterogeneous Medical Image Computing and Visualization
SegmentationPyramidRenderer.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <deque>
5 #include <thread>
6 #include <FAST/Data/Color.hpp>
7 
8 namespace fast {
9 
10 class ImagePyramid;
11 
12 /*
13 template <class T>
14 class UniqueQueue {
15  public:
16  T next_and_pop() {
17  std::lock_guard<std::mutex> lock(m_mutex);
18  T item = m_queue.back();
19  m_queue.pop_back();
20  m_indices.erase(item);
21  return item;
22  }
23  void add(T item) {
24  std::lock_guard<std::mutex> lock(m_mutex);
25  //std::cout << "Adding item " << item << std::endl;
26  if(m_indices.count(item) > 0) {
27  // To avoid duplicates
28  auto it = m_queue.begin();
29  if(m_indices[item] < m_queue.size()) {
30  //std::cout << "Duplicate, erasing.. " << m_indices[item] << " " << m_queue.size() << std::endl;
31  std::advance(it, m_indices[item]);
32  m_queue.erase(it);
33  // Update indices of items after the deleted item
34  for(;it != m_queue.end(); ++it) // TODO find a more efficient way to do this
35  m_indices[*it]--;
36  //std::cout << "New size: " << m_queue.size() << std::endl;
37  } else {
38  std::cout << "error.." << std::endl;
39  }
40  }
41  m_queue.push_back(item);
42  m_indices[item] = m_queue.size() - 1;
43  }
44  bool empty() {
45  return m_queue.empty();
46  }
47  std::size_t size() {
48  return m_queue.size();
49  }
50  void clear() {
51  std::lock_guard<std::mutex> lock(m_mutex);
52  m_queue.clear();
53  m_indices.clear();
54  }
55  std::mutex& getMutex() {
56  return m_mutex;
57  }
58  private:
59  std::list<T> m_queue;
60  std::unordered_map<T, std::size_t> m_indices;
61  std::mutex m_mutex;
62 };*/
63 
64 
65 class FAST_EXPORT SegmentationPyramidRenderer : public Renderer {
67  public:
68  void loadAttributes() override;
69  ~SegmentationPyramidRenderer() override;
70  void clearPyramid();
71  void setOpacity(float opacity);
72  void stopPipeline() override;
73  private:
75  void draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, float zNear, float zFar, bool mode2D);
76 
77  std::unordered_map<std::string, uint> mTexturesToRender;
78  std::unordered_map<uint, std::shared_ptr<ImagePyramid>> mImageUsed;
79  std::unordered_map<std::string, uint> mVAO;
80  std::unordered_map<std::string, uint> mVBO;
81  std::unordered_map<std::string, uint> mEBO;
82 
83  // Queue of tiles to be loaded
84  std::list<std::string> m_tileQueue; // LIFO queue of unique items
85  // Buffer to process queue
86  std::unique_ptr<std::thread> m_bufferThread;
87  // Condition variable to wait if queue is empty
88  std::condition_variable m_queueEmptyCondition;
89  std::mutex m_tileQueueMutex;
90  bool m_stop = false;
91  std::unordered_set<std::string> m_loaded;
92 
93  int m_currentLevel = -1;
94 
95  cl::Kernel mKernel;
96 
97  std::shared_ptr<ImagePyramid> m_input;
98 
99  bool mColorsModified;
100  bool mFillAreaModified;
101 
102  std::unordered_map<int, Color> mLabelColors;
103  std::unordered_map<int, bool> mLabelFillArea;
104  bool mFillArea;
105  int mBorderRadius = 1;
106  float mOpacity = 0.5;
107  cl::Buffer mColorBuffer, mFillAreaBuffer;
108  std::atomic<uint64_t> m_memoryUsage;
109  std::mutex m_texturesToRenderMutex;
110 
111  void drawTextures(Matrix4f &perspectiveMatrix, Matrix4f &viewingMatrix, bool mode2D);
112 };
113 
114 }
fast::Renderer
Definition: Renderer.hpp:14
fast
Definition: AffineTransformation.hpp:7
fast::SegmentationPyramidRenderer
Definition: SegmentationPyramidRenderer.hpp:65
FAST_OBJECT
#define FAST_OBJECT(className)
Definition: Object.hpp:9
Renderer.hpp
Color.hpp