Permalink
Browse files

**In Region constructor, precompute edges

  • Loading branch information...
nutanong committed Jun 6, 2011
1 parent 4aa2c9e commit 6d141a8f51599fc783d46c43785c48531a33078c
Showing with 25 additions and 11 deletions.
  1. +7 −4 src/rtree/RTree.cc
  2. +18 −7 src/spatialindex/Region.cc
View
@@ -606,7 +606,7 @@ double SpatialIndex::RTree::RTree::hausdorff(ISpatialIndex& query, uint64_t& id1
{
double retDist;
RTree *queryRTreePtr = dynamic_cast<RTree*>(&query);
-
+ //std::cout << "============" << std::endl;
//std::cout << *queryRTreePtr << std::endl;
if (mode==0) {
retDist = this->hausdorff2(query, id1, id2, v);
@@ -619,11 +619,14 @@ double SpatialIndex::RTree::RTree::hausdorff(ISpatialIndex& query, uint64_t& id1
} else if (mode==2) {
double max = std::numeric_limits<double>::min();
- //Region r = Region(2);
+ Region r = Region(2);
+
int counter = 0;
for (int i=this->m_vec_pMBR.size()-1; i>=0; i--) {
- //this->m_vec_pMBR[i]->getMBR(r);
- max = this->m_vec_pMBR[i]->getHausDistLB(queryRTreePtr->m_vec_pMBR,max,counter);
+ this->m_vec_pMBR[i]->getMBR(r);
+ //max = this->m_vec_pMBR[i]->getHausDistLB(queryRTreePtr->m_vec_pMBR,max,counter);
+ max = std::max(max,r.getHausDistLB(queryRTreePtr->m_vec_pMBR,max,counter));
+
}
v.incNumDistCals(counter);
View
@@ -56,6 +56,11 @@ Region::Region(const Point& low, const Point& high)
Region::Region(const Region& r)
{
initialize(r.m_pLow, r.m_pHigh, r.m_dimension);
+ for (int i=0; i < 4; i++) {
+ Region *pR = new Region(2);
+ this->getEdge(i,*pR);
+ this->m_vec_pEdge.push_back(pR);
+ }
}
void Region::initialize(const double* pLow, const double* pHigh, uint32_t dimension)
@@ -93,11 +98,8 @@ void Region::initialize(const double* pLow, const double* pHigh, uint32_t dimens
memcpy(m_pLow, pLow, m_dimension * sizeof(double));
memcpy(m_pHigh, pHigh, m_dimension * sizeof(double));
- for (int i=0; i < 4; i++) {
- Region *pR = new Region(2);
- this->getEdge(i,*pR);
- this->m_vec_pEdge.push_back(pR);
- }
+
+
}
void Region::initialize(uint32_t dimension)
@@ -260,6 +262,13 @@ uint32_t Region::getDimension() const
void Region::getMBR(Region& out) const
{
out = *this;
+
+ out.m_vec_pEdge.clear();
+ for (int i=0; i < 4; i++) {
+ Region *pR = new Region(2);
+ out.getEdge(i,*pR);
+ out.m_vec_pEdge.push_back(pR);
+ }
}
double Region::getArea() const
@@ -626,15 +635,17 @@ double Region::getHausDistLB(const std::vector<const Region*> vec_pMBR, double m
//);
//}
- //Region edge1 = Region(2);
+ max = max*max;
+ Region edge1 = Region(2);
for (int i=0; i<4; i++) {
- //this->getEdge(i,edge1);
+ this->getEdge(i,edge1);
double min = std::numeric_limits<double>::max();
for (int j=0; j< vec_pMBR.size(); j++) {
min = std::min(min,this->m_vec_pEdge.at(i)->getMinimumDistanceSq(*(vec_pMBR[j])));
+ //min = std::min(min,edge1.getMinimumDistanceSq(*(vec_pMBR[j])));
counter++;
if (min < max) break;
}

0 comments on commit 6d141a8

Please sign in to comment.