00001 // -*- c-basic-offset: 4 -*- 00026 #include "CalculateOptimalScale.h" 00027 00028 #include <panotools/PanoToolsInterface.h> 00029 00030 00031 namespace HuginBase { 00032 00034 double CalculateOptimalScale::calcOptimalScale(PanoramaData& panorama) 00035 { 00036 if (panorama.getNrOfImages() == 0) 00037 return 1; 00038 00039 PanoramaOptions opt = panorama.getOptions(); 00040 double scale = 0; 00041 00042 for (unsigned i = 0; i < panorama.getNrOfImages(); i++) { 00043 double s = calcOptimalPanoScale(panorama.getSrcImage(i), opt); 00044 if (scale < s) { 00045 scale = s; 00046 } 00047 } 00048 00049 return scale; 00050 } 00051 00052 00056 double CalculateOptimalScale::calcOptimalPanoScale(const SrcPanoImage & src, 00057 const PanoramaOptions & dest) 00058 { 00059 // calculate the input pixel per output pixel ratio at the panorama center. 00060 00061 PTools::Transform transf; 00062 SrcPanoImage timg = src; 00063 timg.setRoll(0); 00064 timg.setPitch(0); 00065 timg.setYaw(0); 00066 timg.setX(0); 00067 timg.setY(0); 00068 timg.setZ(0); 00069 transf.createTransform(timg, dest); 00070 hugin_utils::FDiff2D imgp1; 00071 hugin_utils::FDiff2D imgp2; 00072 00073 transf.transform(imgp1, hugin_utils::FDiff2D(0, 0)); 00074 transf.transform(imgp2, hugin_utils::FDiff2D(1, 1)); 00075 double dist = hugin_utils::norm(imgp2-imgp1); 00076 00077 return dist / sqrt(2.0); 00078 00079 /* 00080 // calculate average pixel density of each image 00081 // and use the highest one to calculate the width 00082 double density=0; 00083 double w = imgSize.x; 00084 switch (imgProj) { 00085 case Lens::RECTILINEAR: 00086 density = 1/RAD_TO_DEG(atan(2*tan(DEG_TO_RAD(v)/2)/w)); 00087 break; 00088 case Lens::CIRCULAR_FISHEYE: 00089 case Lens::FULL_FRAME_FISHEYE: 00090 // if we assume the linear fisheye model: r = f * theta 00091 // then we get the same pixel density as for cylindrical and equirect 00092 case Lens::EQUIRECTANGULAR: 00093 case Lens::PANORAMIC: 00094 density = w / v; 00095 break; 00096 } 00097 // TODO: use density properly based on the output projection. 00098 double width = roundi(density * opt.getHFOV()); 00099 */ 00100 } 00101 00102 00103 } //namespace