PICCANTE  0.4
The hottest HDR imaging library!
std_util.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_UTIL_STD_UTIL_HPP
19 #define PIC_UTIL_STD_UTIL_HPP
20 
21 #include <vector>
22 
23 namespace pic {
24 
31 template<class T>
32 inline void filterInliers(std::vector< T > &vec, std::vector< unsigned int > &inliers, std::vector< T > &vecOut)
33 {
34  vecOut.clear();
35 
36  if(!inliers.empty()) {
37  for(unsigned int i = 0; i < inliers.size(); i++) {
38  vecOut.push_back(vec[inliers[i]]);
39  }
40  } else {
41  vecOut.assign(vec.begin(), vec.end());
42  }
43 }
44 
49 template<class T>
50 inline void stdVectorClear(std::vector<T *> &vec)
51 {
52  for(unsigned int i = 0; i < vec.size(); i++) {
53  T *tmp = vec[i];
54 
55  if(tmp != NULL) {
56  delete tmp;
57  }
58 
59  vec[i] = NULL;
60  }
61 
62  vec.clear();
63 }
64 
65 
70 template<class T>
71 inline void stdVectorArrayClear(std::vector<T *> &vec)
72 {
73  for(unsigned int i = 0; i < vec.size(); i++) {
74  T *tmp = vec[i];
75 
76  if(tmp != NULL) {
77  delete[] tmp;
78  }
79  }
80 
81  vec.clear();
82 }
83 
89 template<class T>
90 inline void setToANullVector(std::vector< T* > &vec, unsigned int n)
91 {
92  if(!vec.empty()) {
93  return;
94  }
95 
96  for(unsigned int i = 0; i < n; i++) {
97  vec.push_back(NULL);
98  }
99 }
100 
106 template<class T>
107 inline T* releasePtr(T *data)
108 {
109  if(data != NULL) {
110  delete data;
111  data = NULL;
112  }
113 
114  return data;
115 }
116 
122 template<class T>
123 inline T* delete_s(T *data)
124 {
125  if(data != NULL) {
126  delete data;
127  data = NULL;
128  }
129  return data;
130 }
131 
137 template<class T>
138 inline T* delete_vec_s(T *data)
139 {
140  if(data != NULL) {
141  delete[] data;
142  data = NULL;
143  }
144  return data;
145 }
146 
147 
148 } // end namespace pic
149 
150 #endif // PIC_UTIL_STD_UTIL_HPP
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
void setToANullVector(std::vector< T * > &vec, unsigned int n)
setToANullVector
Definition: std_util.hpp:90
T * delete_vec_s(T *data)
delete_vec_s
Definition: std_util.hpp:138
void stdVectorArrayClear(std::vector< T *> &vec)
stdVectorArrayClear
Definition: std_util.hpp:71
void filterInliers(std::vector< T > &vec, std::vector< unsigned int > &inliers, std::vector< T > &vecOut)
filterInliers
Definition: std_util.hpp:32
Definition: bilateral_separation.hpp:25
T * releasePtr(T *data)
release
Definition: std_util.hpp:107
void stdVectorClear(std::vector< T *> &vec)
stdVectorClear
Definition: std_util.hpp:50