PICCANTE  0.4
The hottest HDR imaging library!
superpixels_oracle.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_ALGORITHMS_SUPERPIXELS_ORACLE_HPP
19 #define PIC_ALGORITHMS_SUPERPIXELS_ORACLE_HPP
20 
21 #include <vector>
22 #include <set>
23 
24 #include "../algorithms/quadtree.hpp"
25 
26 namespace pic {
27 
32 {
33 protected:
34 
35  int *buffer;
36  int width, height;
37  std::vector<int> unique;
38 
40 
44  void init()
45  {
46  int size = width * height;
47 
48  std::set<int> keys;
49 
50  for(int i = 0; i < size; i++) {
51  keys.insert(buffer[i]);
52  }
53 
54  unique.insert(unique.begin(), keys.begin(), keys.end());
55 
56  int bmin[2], bmax[2];
57  bmin[0] = 0;
58  bmin[1] = 0;
59 
60  bmax[0] = width;
61  bmax[1] = height;
62 
63  int tmp_max_level = width > height ? height : width;
64  int max_level = int(ceilf(logf(float(tmp_max_level)) / logf(2.0f)));
65 
66  printf("Max Level: %d\n", max_level);
67  root = new Quadtree(bmax, bmin);
68 
69  for(int i = 0; i < height; i++) {
70  int pos[2];
71  int ind = i * width;
72  pos[1] = i;
73 
74  for(int j = 0; j < width; j++) {
75  pos[0] = j;
76  root->insert(pos, buffer[ind + j], max_level);
77  }
78  }
79  }
80 
81 public:
82 
90  {
91  if((buffer == NULL) || (width < 1) || (height < 1)) {
92  return;
93  }
94 
95  this->buffer = buffer;
96  this->width = width;
97  this->height = height;
98  init();
99  }
100 
102  {
103  delete root;
104  }
105 
113  void query(float x, float y, float r, std::set<int> &out)
114  {
115  root->find(x, y, r, out);
116  }
117 };
118 
119 } // end namespace pic
120 
121 #endif /* PIC_ALGORITHMS_SUPERPIXELS_ORACLE_HPP */
122 
The SuperPixelsOracle class.
Definition: superpixels_oracle.hpp:31
The Quadtree class.
Definition: quadtree.hpp:28
void query(float x, float y, float r, std::set< int > &out)
query
Definition: superpixels_oracle.hpp:113
int * buffer
Definition: superpixels_oracle.hpp:35
SuperPixelsOracle(int *buffer, int width, int height)
SuperPixelsOracle.
Definition: superpixels_oracle.hpp:89
~SuperPixelsOracle()
Definition: superpixels_oracle.hpp:101
int width
Definition: superpixels_oracle.hpp:36
Quadtree * root
Definition: superpixels_oracle.hpp:39
void find(float x, float y, float radius, std::set< int > &out)
find
Definition: quadtree.hpp:228
int height
Definition: superpixels_oracle.hpp:36
void insert(int *pos, int value, int MAX_OCTREE_LEVEL, int level=0)
insert
Definition: quadtree.hpp:198
std::vector< int > unique
Definition: superpixels_oracle.hpp:37
Definition: bilateral_separation.hpp:25
void init()
init
Definition: superpixels_oracle.hpp:44