00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMPSTATISTICS_KM_RECTANGLE_H
00009 #define IMPSTATISTICS_KM_RECTANGLE_H
00010
00011 #include <cstdlib>
00012 #include <fstream>
00013 #include <iomanip>
00014 #include <climits>
00015 #include <ctime>
00016 #include <string>
00017 #include <vector>
00018 #include "statistics_config.h"
00019 #include "KMData.h"
00020 #include <IMP/base_types.h>
00021 IMPSTATISTICS_BEGIN_NAMESPACE
00022
00023 #ifndef IMP_DOXYGEN
00024
00025
00026
00027
00028
00029 IMPSTATISTICSEXPORT double km_distance2(const KMPoint &p,const KMPoint &q);
00030
00031
00032
00033
00034 bool km_is_equal(const KMPoint &p,const KMPoint &q);
00035
00036
00037
00038
00039
00040 class KMRectangle {
00041 public:
00042 KMRectangle(){}
00043
00044
00045
00046
00047 KMRectangle(int dim) {
00048 lo_.clear();hi_.clear();
00049 lo_.insert(lo_.end(),dim,0);
00050 hi_.insert(hi_.end(),dim,0);
00051 }
00052 KMRectangle(const KMPoint &l,const KMPoint &h):lo_(l),hi_(h){}
00053
00054
00055
00056
00057 bool is_inside(const KMPoint &p);
00058
00059 KMRectangle expand(double x);
00060 int get_dim(){return lo_.size();}
00061 KMPoint *get_point(int i) {
00062 IMP_INTERNAL_CHECK(i==0 || i==1,"wrong index");
00063 if (i==0) return &lo_;
00064 return &hi_;
00065 }
00066 const KMPoint *get_point(int i) const {
00067 IMP_INTERNAL_CHECK(i==0 || i==1,"wrong index");
00068 if (i==0) return &lo_;
00069 return &hi_;
00070 }
00071
00072 KMPoint sample();
00073 double max_length() const {
00074 double max_length = hi_[0]-lo_[0];
00075 for (unsigned int i=1;i<lo_.size(); i++) {
00076 double length = hi_[i]-lo_[i];
00077 if (length > max_length) {
00078 max_length = length;
00079 }
00080 }
00081 return max_length;
00082 }
00083 KMPoint find_closest_vertex(const KMPoint &p){
00084 IMP_INTERNAL_CHECK(p.size() == (unsigned int)get_dim(),
00085 "KMRectangle::find_closest_vertex the"
00086 <<" input point is of the wrong dimension" << p.size() << " != "
00087 << get_dim()<<std::endl);
00088 KMPoint closest_vertex;
00089 for(int d=0;d<get_dim();d++) {
00090 if (p[d]>hi_[d]) {
00091 closest_vertex.push_back(hi_[d]);
00092 }
00093 else if (p[d]<lo_[d]) {
00094 closest_vertex.push_back(lo_[d]);
00095 }
00096 else {
00097 if ((p[d]-lo_[d]) < (hi_[d]-p[d])) {
00098 closest_vertex.push_back(lo_[d]);
00099 }
00100 else {
00101 closest_vertex.push_back(hi_[d]);
00102 }
00103 }
00104 }
00105 return closest_vertex;
00106 }
00107 protected:
00108 KMPoint lo_;
00109 KMPoint hi_;
00110 };
00111
00112 #endif
00113
00114 IMPSTATISTICS_END_NAMESPACE
00115 #endif