Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef ESBTL_XYZ_UTILS_H
00036 #define ESBTL_XYZ_UTILS_H
00037
00038 #include <cmath>
00039 #include <math.h>
00040 #include <limits>
00041 #include <ESBTL/constants.h>
00042 #include <boost/iterator/zip_iterator.hpp>
00043 #include <boost/tuple/tuple.hpp>
00044
00045 namespace ESBTL{
00046
00050 class Point_3{
00051 public:
00052 Point_3(double x,double y,double z):x_(x),y_(y),z_(z){}
00053 Point_3():x_(0),y_(0),z_(0){}
00054
00055 DECLARE_AND_ACCESS(x,double)
00056 DECLARE_AND_ACCESS(y,double)
00057 DECLARE_AND_ACCESS(z,double)
00058 };
00059
00066 template <class NT>
00067 inline NT square(const NT& n){return n*n;}
00068
00069
00078 template <class Point1,class Point2>
00079 inline double squared_distance(const Point1& p1,const Point2& p2){
00080 return square(p1.x()-p2.x())+square(p1.y()-p2.y())+square(p1.z()-p2.z());
00081 }
00082
00083
00094 template <class Iterator>
00095 double rms_no_align(Iterator begin1,Iterator end1,Iterator begin2,Iterator end2){
00096 typedef boost::tuple<Iterator,Iterator> It_tuple;
00097 typedef boost::zip_iterator<It_tuple> Zip_iterator;
00098 double nb=0;
00099 double sum_sqd=0;
00100 for (Zip_iterator it=boost::make_zip_iterator(boost::make_tuple(begin1,begin1));it!=boost::make_zip_iterator(boost::make_tuple(end1,end2));++it){
00101 sum_sqd+=squared_distance(boost::get<0>(*it),boost::get<1>(*it));
00102 nb+=1;
00103 }
00104 return sqrt(sum_sqd/nb);
00105 }
00106
00115 template <class Point_3,class Iterator>
00116 std::pair<Point_3,Point_3>
00117 bounding_box(Iterator begin,Iterator end){
00118 double xmin=std::numeric_limits<double>::max(),ymin=std::numeric_limits<double>::max(),zmin=std::numeric_limits<double>::max();
00119 double xmax=std::numeric_limits<double>::min(),ymax=std::numeric_limits<double>::min(),zmax=std::numeric_limits<double>::min();
00120 for (Iterator it=begin;it!=end;++it){
00121 if (it->x() < xmin) xmin=it->x();
00122 if (it->x() > xmax) xmax=it->x();
00123 if (it->y() < ymin) ymin=it->y();
00124 if (it->y() > ymax) ymax=it->y();
00125 if (it->z() < zmin) zmin=it->z();
00126 if (it->z() > zmax) zmax=it->z();
00127 }
00128 return std::make_pair(Point_3(xmin,ymin,zmin),Point_3(xmax,ymax,zmax));
00129 }
00130
00139 template <class Point_3,class Iterator>
00140 inline
00141 std::pair<Point_3,double>
00142 bounding_cube(Iterator begin,Iterator end){
00143 std::pair<Point_3,Point_3> bbox=bounding_box<Point_3>(begin,end);
00144 double edge_length=bbox.second.x()-bbox.first.x();
00145 if (edge_length < bbox.second.y()-bbox.first.y()) edge_length=bbox.second.y()-bbox.first.y();
00146 if (edge_length < bbox.second.z()-bbox.first.z()) edge_length=bbox.second.z()-bbox.first.z();
00147
00148 return std::make_pair( bbox.first,nextafter(edge_length,std::numeric_limits<double>::max()) );
00149 }
00150
00151 }
00152
00153
00154 #endif //ESBTL_XYZ_UTILS_H