// Copyright (c) 1998 ETH Zurich (Switzerland). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under // the terms of the Q Public License version 1.0. // See the file LICENSE.QPL distributed with CGAL. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $Source$ // $Revision$ $Date$ // $Name$ // // Author(s) : Gabriele Neyer #ifndef __R_tree_key_H__ #define __R_tree_key_H__ #include #include #include CGAL_BEGIN_NAMESPACE // a 1 dimensional key which is an interval class R_tree_key_1 { int min(int a, int b) const { return (a y.xmin)) return false; if ((xmax < y.xmax)) return false; return true; } bool compare(const R_tree_key_1 & y) const{ return intersect(y); } bool intersect( const R_tree_key_1& y) const { if ((xmax <= y.xmin) || (y.xmax <= xmin)) { return false; } return true; } double cost() const { return (xmax - xmin); } void intersection(const R_tree_key_1 & p, const R_tree_key_1 & q){ if(p.intersect(q)) { xmin = max(p.xmin, q.xmin); xmax = min(p.xmax, q.xmax); } } // compute the distance between the centers of the keys double center_dist( const R_tree_key_1& q) const { double x=xmin + 0.5*(xmax-xmin); double qx=q.xmin + 0.5*(q.xmax-q.xmin); double dist = (x-qx)*(x-qx); return dist; } void read(char **s) { int sint=(int)sizeof(int); char *from_int=new char[sint]; int i,r=0; for (i=0; i y.xmin) || (ymin > y.ymin)) return false; if ((xmax < y.xmax) || (ymax < y.ymax)) return false; return true; } bool compare(const R_tree_key_2 & y) const{ return intersect(y); } bool intersect( const R_tree_key_2& y) const { if ((xmax <= y.xmin) || (y.xmax <= xmin)) { return false; } if ((ymax <= y.ymin) || (y.ymax <= ymin)) { return false; } return true; } double cost() const { return (xmax - xmin) * (ymax - ymin); } void intersection( const R_tree_key_2 & p, const R_tree_key_2 & q){ if(p.intersect(q)) { xmin = max(p.xmin, q.xmin); xmax = min(p.xmax, q.xmax); ymin = max(p.ymin, q.ymin); ymax = min(p.ymax, q.ymax); } } // compute the distance between the centers of the keys double center_dist( const R_tree_key_2& q) const { double x=xmin + 0.5*(xmax-xmin); double y=ymin + 0.5*(ymax-ymin); double qx=q.xmin + 0.5*(q.xmax-q.xmin); double qy=q.ymin + 0.5*(q.ymax-q.ymin); double dist = (x-qx)*(x-qx) + (y-qy)*(y-qy); return dist; } void read(char **s) { int sint=(int)sizeof(int); char *from_int=new char[sint]; int i,r=0; for (i=0; i y.xmin) || (ymin > y.ymin)) return false; if ((xmax < y.xmax) || (ymax < y.ymax)) return false; if ((zmax < y.zmax) || (zmax < y.zmax)) return false; return true; } bool compare(const R_tree_key_3 & y) const{ return intersect(y); } bool intersect( const R_tree_key_3& y) const { if ((xmax <= y.xmin) || (y.xmax <= xmin)) { return false; } if ((ymax <= y.ymin) || (y.ymax <= ymin)) { return false; } if ((zmax <= y.zmin) || (y.zmax <= zmin)) { return false; } return true; } double cost() const { return (xmax - xmin) * (ymax - ymin)* (zmax - zmin); } void intersection( const R_tree_key_3 & p, const R_tree_key_3 & q){ if(p.intersect(q)) { xmin = max(p.xmin, q.xmin); xmax = min(p.xmax, q.xmax); ymin = max(p.ymin, q.ymin); ymax = min(p.ymax, q.ymax); zmin = max(p.zmin, q.zmin); zmax = min(p.zmax, q.zmax); } } // compute the distance between the centers of the keys double center_dist( const R_tree_key_3& q) const { double x=xmin + 0.5*(xmax-xmin); double y=ymin + 0.5*(ymax-ymin); double z=zmin + 0.5*(zmax-zmin); double qx=q.xmin + 0.5*(q.xmax-q.xmin); double qy=q.ymin + 0.5*(q.ymax-q.ymin); double qz=q.zmin + 0.5*(q.zmax-q.zmin); double dist = (x-qx)*(x-qx) + (y-qy)*(y-qy) + (z-qz)*(z-qz); return dist; } void read(char **s) { int sint=(int)sizeof(int); char *from_int=new char[sint]; int i,r=0; for (i=0; i y.xmin) || (ymin > y.ymin)) return false; if ((xmax < y.xmax) || (ymax < y.ymax)) return false; if ((zmax < y.zmax) || (zmax < y.zmax)) return false; if ((wmax < y.wmax) || (wmax < y.wmax)) return false; return true; } bool compare(const R_tree_key_4 & y) const{ return intersect(y); } bool intersect( const R_tree_key_4& y) const { if ((xmax <= y.xmin) || (y.xmax <= xmin)) { return false; } if ((ymax <= y.ymin) || (y.ymax <= ymin)) { return false; } if ((zmax <= y.zmin) || (y.zmax <= zmin)) { return false; } if ((wmax <= y.wmin) || (y.wmax <= wmin)) { return false; } return true; } double cost() const { return (xmax - xmin) * (ymax - ymin)* (zmax - zmin)* (wmax - wmin); } void intersection( const R_tree_key_4 & p, const R_tree_key_4 & q){ if(p.intersect(q)) { xmin = max(p.xmin, q.xmin); xmax = min(p.xmax, q.xmax); ymin = max(p.ymin, q.ymin); ymax = min(p.ymax, q.ymax); zmin = max(p.zmin, q.zmin); zmax = min(p.zmax, q.zmax); zmin = max(p.wmin, q.wmin); zmax = min(p.wmax, q.wmax); } } // compute the distance between the centers of the keys double center_dist( const R_tree_key_4& q) const { double x=xmin + 0.5*(xmax-xmin); double y=ymin + 0.5*(ymax-ymin); double z=zmin + 0.5*(zmax-zmin); double w=wmin + 0.5*(wmax-wmin); double qx=q.xmin + 0.5*(q.xmax-q.xmin); double qy=q.ymin + 0.5*(q.ymax-q.ymin); double qz=q.zmin + 0.5*(q.zmax-q.zmin); double qw=q.wmin + 0.5*(q.wmax-q.wmin); double dist = (x-qx)*(x-qx) + (y-qy)*(y-qy) + (z-qz)*(z-qz) + (w-qw)*(w-qw); return dist; } void read(char **s) { int sint=(int)sizeof(int); char *from_int=new char[sint]; int i,r=0; for (i=0; i class X_Compare_1{ typedef typename Container::Key Key; typedef typename Key::compare_1 comp_1; comp_1 ccc1; public: bool operator()(const Container &p, const Container &q) { return ccc1(p.key,q.key); } }; template class X_Compare_2{ typedef typename Container::Key Key; typedef typename Key::compare_2 comp_2; comp_2 ccc2; public: bool operator()(const Container &p, const Container &q) { return ccc2(p.key,q.key); } }; template class X_Compare_3{ typedef typename Container::Key Key; typedef typename Key::compare_3 comp_3; comp_3 ccc3; public: bool operator()(const Container &p, const Container &q) { return ccc3(p.key,q.key); } }; template class X_Compare_4{ typedef typename Container::Key Key; typedef typename Key::compare_4 comp_4; comp_4 ccc4; public: bool operator()(const Container &p, const Container &q) { return ccc4(p.key,q.key); } }; // return true if sort axis exists template class sort_axis_key_1_dim { public: typedef typename Container::Key Key; typedef typename Key::compare_1 comp_1; typedef X_Compare_1 compare_1; compare_1 cc1; bool operator()(int split_axis, Container *first, Container *last) { if(split_axis==0) { std::stable_sort(first,last,cc1); return true; } else return false; return false; } }; // return true if sort axis exists template class sort_axis_key_2_dim { public: typedef typename Container::Key Key; typedef typename Key::compare_1 comp_1; typedef typename Key::compare_2 comp_2; typedef X_Compare_1 compare_1; typedef X_Compare_2 compare_2; compare_1 cc1; compare_2 cc2; bool operator()(int split_axis, Container *first, Container *last) { if(split_axis==0) { std::stable_sort(first,last,cc1); return true; } else if(split_axis==1) { std::stable_sort(first,last,cc2); return true; } else return false; return false; } }; // return true if sort axis exists template class sort_axis_key_3_dim { public: typedef typename Container::Key Key; typedef typename Key::compare_1 comp_1; typedef typename Key::compare_2 comp_2; typedef typename Key::compare_3 comp_3; typedef X_Compare_1 compare_1; typedef X_Compare_2 compare_2; typedef X_Compare_3 compare_3; compare_1 cc1; compare_2 cc2; compare_3 cc3; bool operator()(int split_axis, Container *first, Container *last) { if(split_axis==0) { std::stable_sort(first,last,cc1); return true; } else if(split_axis==1) { std::stable_sort(first,last,cc2); return true; } else if(split_axis==2) { std::stable_sort(first,last,cc3); return true; } else return false; return false; } }; // return true if sort axis exists template class sort_axis_key_4_dim { public: typedef typename Container::Key Key; typedef typename Key::compare_1 comp_1; typedef typename Key::compare_2 comp_2; typedef typename Key::compare_3 comp_3; typedef typename Key::compare_4 comp_4; typedef X_Compare_1 compare_1; typedef X_Compare_2 compare_2; typedef X_Compare_3 compare_3; typedef X_Compare_4 compare_4; compare_1 cc1; compare_2 cc2; compare_3 cc3; compare_4 cc4; bool operator()(int split_axis, Container *first, Container *last) { if(split_axis==0) { std::stable_sort(first,last,cc1); return true; } else if(split_axis==1) { std::stable_sort(first,last,cc2); return true; } else if(split_axis==2) { std::stable_sort(first,last,cc3); return true; } else if(split_axis==3) { std::stable_sort(first,last,cc4); return true; } else return false; return false; } }; CGAL_END_NAMESPACE #endif