QuadTree.cpp
Go to the documentation of this file.
00001 //#include <pano_core/QuadTree.h>
00002 //#include <pano_core/feature_utils.h>
00003 //#include <list>
00004 //
00005 //using namespace cv;
00006 //using namespace std;
00007 //namespace pano{
00008 //typedef std::list<int> Idxs;
00009 //typedef cv::Rect_<float> RectF;
00010 //
00011 //struct QuadTreeNode
00012 //{
00013 //private:
00014 //  friend class QuadTree;
00015 //
00016 //  typedef Idxs::const_iterator Idxs_cit;
00017 //  typedef Idxs::iterator Idxs_it;
00018 //
00019 //  const std::vector<cv::Point2f> * mother_;
00020 //  cv::Rect_<float> region_;
00021 //  cv::Point2f center_;
00022 //  cv::Ptr<QuadTreeNode> q1_, q2_, q3_, q4_;
00023 //  Idxs idxs_;
00024 //  bool empty_;
00025 //  QuadTreeNode() :
00026 //    mother_(0),empty_(true)
00027 //  {
00028 //  }
00029 //  QuadTreeNode(const std::vector<cv::Point2f> * mother, const RectF& region) :
00030 //    mother_(mother), region_(region), center_(getCenter(region)),empty_(true)
00031 //  {
00032 //
00033 //  }
00034 //  QuadTreeNode(const std::vector<cv::Point2f> * mother, const Idxs& idxs, const RectF& region) :
00035 //    mother_(mother), region_(region), center_(getCenter(region)), idxs_(idxs),empty_(true)
00036 //  {
00037 //    propigatePoints();
00038 //  }
00039 //
00040 //  float dist(const cv::Point2f& p) const
00041 //  {
00042 //    Point2f dv = center_ - p;
00043 //    return sqrt(dv.dot(dv));
00044 //  }
00045 //
00046 //  bool empty() const {return empty_;}
00047 //
00048 //  void radiusSearch(_RadiusPoint<Point2f> rp, vector<int>& result) const
00049 //  {
00050 //    RectF p_region(region_.tl() - Point2f(rp.r, rp.r), Size(region_.width + rp.r, region_.height + rp.r));
00051 //    if (!p_region.contains(rp.pt2))
00052 //      return;
00053 //
00054 //    Idxs_cit it = idxs_.begin();
00055 //    while (idxs_.end() != it)
00056 //    {
00057 //      int i = *it;
00058 //      if (rp.cp((*mother_)[i]))
00059 //      {
00060 //        result.push_back(i);
00061 //      }
00062 //      ++it;
00063 //    }
00064 //
00065 //    if(!q1_.empty())
00066 //    q1_->radiusSearch(rp, result);
00067 //    if(!q2_.empty())
00068 //    q2_->radiusSearch(rp, result);
00069 //    if(!q3_.empty())
00070 //    q3_->radiusSearch(rp, result);
00071 //    if(!q4_.empty())
00072 //    q4_->radiusSearch(rp, result);
00073 //
00074 //  }
00075 //
00076 //  void newChildren()
00077 //  {
00078 //    q1_ = new QuadTreeNode(mother_, getRegion(1));
00079 //    q2_ = new QuadTreeNode(mother_, getRegion(2));
00080 //    q3_ = new QuadTreeNode(mother_, getRegion(3));
00081 //    q4_ = new QuadTreeNode(mother_, getRegion(4));
00082 //  }
00083 //  void propigatePoints()
00084 //  {
00085 //    empty_ = false;
00086 //
00087 //    if (idxs_.size() <= 4)
00088 //      return;
00089 //
00090 //    newChildren();
00091 //
00092 //    while (idxs_.size())
00093 //    {
00094 //      QuadTreeNode * node = closest((*mother_)[idxs_.back()]);
00095 //      node->idxs_.push_back(idxs_.back());
00096 //      idxs_.pop_back();
00097 //    }
00098 //
00099 //    q1_->propigatePoints();
00100 //    q2_->propigatePoints();
00101 //    q3_->propigatePoints();
00102 //    q4_->propigatePoints();
00103 //
00104 //  }
00105 //
00106 //  QuadTreeNode * closest(const Point2f& p)
00107 //  {
00108 //    float d1 = q1_->dist(p), d2 = q2_->dist(p), d3 = q3_->dist(p), d4 = q4_->dist(p);
00109 //    //float min12 = min(d1, d2);
00110 //    float min34 = min(d3, d4);
00111 //    if (d1 < min(d2, min34))
00112 //    {
00113 //      return &(*q1_);
00114 //    }
00115 //    if (d2 < min34)
00116 //    {
00117 //      return &(*q2_);
00118 //    }
00119 //    if (d3 < d4)
00120 //    {
00121 //      return &(*q3_);
00122 //    }
00123 //    return &(*q4_);
00124 //  }
00125 //
00126 //  RectF getRegion(int q)
00127 //  {
00128 //    RectF r(center_.x, center_.y, region_.width / 2, region_.height / 2);
00129 //    switch (q)
00130 //    {
00131 //      case 1:
00132 //        r.y -= r.height;
00133 //        break;
00134 //      case 2:
00135 //        r.x -= r.width;
00136 //        r.y -= r.height;
00137 //        break;
00138 //      case 3:
00139 //        r.x -= r.width;
00140 //        break;
00141 //      case 4:
00142 //        //r.x = center_.x
00143 //        //r.y = center_.y
00144 //        break;
00145 //    }
00146 //    return r;
00147 //  }
00148 //
00149 //  static cv::Point2f getCenter(const RectF region)
00150 //  {
00151 //    return cv::Point2f(region.x + region.width / 2, region.y + region.height / 2);
00152 //  }
00153 //};
00154 //
00155 //
00156 //QuadTree::QuadTree():root_(0)
00157 //
00158 //{
00159 //
00160 //}
00161 //QuadTree::~QuadTree(){
00162 //  delete root_;
00163 //}
00164 //QuadTree::QuadTree(const QuadTree& rhs) :
00165 //   root_(0)
00166 // {
00167 //   addPoints(rhs.points_, rhs.size_);
00168 // }
00169 // void QuadTree::operator=(const QuadTree& rhs)
00170 // {
00171 //   addPoints(rhs.points_, rhs.size_);
00172 // }
00173 //
00174 //void QuadTree::addPoints(const std::vector<cv::Point2f>& points, cv::Size size)
00175 //{
00176 //
00177 //  size_ = size;
00178 //  points_ = points;
00179 //  std::list<int> idxs;
00180 //  for (int i = 0; i < (int)points_.size(); i++)
00181 //  {
00182 //    idxs.push_back(i);
00183 //  }
00184 //
00185 //  delete root_;
00186 //  root_ = new QuadTreeNode(&points_, idxs, RectF(0, 0, size.width, size.height));
00187 //
00188 //}
00189 //void QuadTree::radiusSearch(const cv::Point2f& pt, float radius, std::vector<int>& result) const
00190 //{
00191 //  _RadiusPoint<Point2f> rp( radius, pt);
00192 //  result.clear();
00193 //  if(root_ == 0)return;
00194 //
00195 //  result.reserve(20);
00196 //  root_->radiusSearch(rp, result);
00197 //}
00198 //void QuadTree::radiusSearch(const vector< cv::Point2f >& pts, float radius, std::vector<vector<int> >& result) const
00199 //{
00200 //
00201 //  result.clear();
00202 //  if(root_ == 0)return;
00203 //
00204 //  result.resize(pts.size());
00205 //  for(size_t i = 0; i <  pts.size(); ++i){
00206 //    radiusSearch(pts[i],radius,result[i]);
00207 //  }
00208 //}
00209 //}


pano_core
Author(s): Ethan Rublee
autogenerated on Wed Aug 26 2015 16:34:01