00001
00002
00003 #ifndef _FDETECT_DETECTION_RESULT_HPP_
00004 #define _FDETECT_DETECTION_RESULT_HPP_
00005
00006 #include <boost/serialization/shared_ptr.hpp>
00007 #include <boost/serialization/vector.hpp>
00008 #include <boost/shared_ptr.hpp>
00009
00010 #include "fdetect/InterestFeature.hpp"
00011
00012 namespace jafar {
00013 namespace fdetect {
00022 class DetectionResult {
00023 struct Shared;
00024 public:
00028 DetectionResult();
00032 DetectionResult(const DetectionResult&);
00037 DetectionResult& operator=(const DetectionResult&);
00038 ~DetectionResult();
00039 public:
00040 unsigned int id;
00041
00042 typedef vInterestFeatures_it iterator;
00043 typedef vInterestFeatures_cit const_iterator;
00047 unsigned int countInterestFeatures() const;
00048 unsigned int size() const { return countInterestFeatures(); }
00053 InterestFeature* operator[](int p);
00058 const InterestFeature* operator[](int p) const;
00062 vInterestFeatures_it beginFeatures();
00063 iterator begin() { return beginFeatures(); }
00067 vInterestFeatures_cit beginFeatures() const;
00068 const_iterator begin() const { return beginFeatures(); }
00072 vInterestFeatures_it endFeatures();
00073 iterator end() { return endFeatures(); }
00077 vInterestFeatures_cit endFeatures() const;
00078 const_iterator end() const { return endFeatures(); }
00085 void addFeature(InterestFeature* ife);
00086 void push_back(InterestFeature* ife) { addFeature(ife); }
00090 vInterestFeatures_it eraseFeature(vInterestFeatures_it it);
00091 iterator erase(iterator it) { return eraseFeature(it); }
00092 vInterestFeatures& getFeatures() const;
00093 DetectionResult filter(double threshold);
00094
00095 friend std::ostream& operator <<(std::ostream& s, const DetectionResult& p_);
00096 friend std::ostream& operator <<(std::ostream& s, const DetectionResult::Shared& p_);
00097
00098 private:
00099 void unref();
00100 Shared* m_shared;
00102 friend class boost::serialization::access;
00103 template<class Archive>
00104 void serialize(Archive &ar, const unsigned int version);
00105 };
00106 }
00107
00108 namespace fdetect_v2 {
00117 template< typename InterestFeatureT >
00118 class DetectionResult {
00119 public:
00121 typedef std::vector< InterestFeatureT* > vInterestFeatures;
00122 typedef typename std::vector< InterestFeatureT* >::iterator iterator;
00123 typedef typename std::vector< InterestFeatureT* >::const_iterator const_iterator;
00124 typedef typename std::vector< InterestFeatureT* >::reverse_iterator
00125 reverse_iterator;
00126 typedef typename std::vector< InterestFeatureT* >::const_reverse_iterator
00127 const_reverse_iterator;
00128
00132 DetectionResult() : id(-1), m_shared(new vInterestFeatures()) { }
00137 DetectionResult(const DetectionResult& dr) : id(dr.id), m_shared(dr.m_shared) {}
00139 ~DetectionResult() {}
00141 unsigned int id;
00142
00146 unsigned int countInterestFeatures() const
00147 {
00148 return m_shared->size();
00149 }
00150 unsigned int size() const
00151 {
00152 return m_shared->size();
00153 }
00158 InterestFeatureT* operator[](int p)
00159 {
00160 return m_shared->at(p);
00161 }
00166 const InterestFeatureT* operator[](int p) const
00167 {
00168 return m_shared->at(p);
00169 }
00173 iterator begin()
00174 {
00175 return m_shared->begin();
00176 }
00180 const_iterator begin() const
00181 {
00182 return m_shared->begin();
00183 }
00187 reverse_iterator rbegin()
00188 {
00189 return m_shared->rbegin();
00190 }
00194 const_reverse_iterator rbegin() const
00195 {
00196 return m_shared->rbegin();
00197 }
00201 iterator end()
00202 {
00203 return m_shared->end();
00204 }
00208 const_iterator end() const
00209 {
00210 return m_shared->end();
00211 }
00219 void push_back(InterestFeatureT* ife)
00220 {
00221 ife->setIndex(m_shared->size());
00222 m_shared->push_back(ife);
00223 }
00229 iterator erase(iterator it)
00230 {
00231 return m_shared->erase(it);
00232 }
00238 iterator erase(iterator first, iterator last)
00239 {
00240 return m_shared->erase(first, last);
00241 }
00246 iterator erase(InterestFeatureT* ife)
00247 {
00248 iterator it = m_shared->begin() + ife->index();
00249 return m_shared->erase(it);
00250 }
00252 template <class InputIterator>
00253 void insert (InputIterator first, InputIterator last )
00254 {
00255 m_shared->insert(m_shared->end(), first, last);
00256 }
00261 void clean_indices()
00262 {
00263
00264 for(unsigned int i = 0; i < size(); i++)
00265 m_shared->operator[](i)->setIndex(i);
00266 }
00271 void clear()
00272 {
00273 m_shared->clear();
00274 id = -1;
00275 }
00279 void clone(DetectionResult& dr)
00280 {
00281 dr.clear();
00282 for(const_iterator fit = this->begin(); fit != this->end(); ++fit)
00283 dr.push_back(new InterestFeatureT(*(*fit)));
00284 }
00285
00289 vInterestFeatures& get() const
00290 {
00291 return *m_shared;
00292 }
00297 DetectionResult filter(double threshold = 3.0)
00298 {
00299 DetectionResult result;
00300 for(iterator it = begin(); it != end(); ++it)
00301 if ((*it)->quality() >= threshold)
00302 result.push_back(*it);
00303 return result;
00304 }
00309 friend std::ostream& operator <<(std::ostream& s, const fdetect_v2::DetectionResult<InterestFeatureT>& p_)
00310 {
00311 for(const_iterator it = p_.m_shared->begin(); it != p_.m_shared->end(); ++it)
00312 s << *(*it);
00313 s << "refcount " << p_.m_shared.use_count();
00314 return s;
00315 }
00316
00317 private:
00318 boost::shared_ptr< vInterestFeatures > m_shared;
00320 friend class boost::serialization::access;
00321 template<class Archive>
00322 void serialize(Archive &ar, const unsigned int version)
00323 {
00324 ar & id;
00325 ar & *m_shared;
00326 }
00327 };
00328
00329 }
00330
00331 }
00332
00333 #endif