RegistrationStatistics.h
上传用户:kellyonhid
上传日期:2013-10-12
资源大小:932k
文件大小:4k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. //###############################################################
  2. // RegistationStatistics.h
  3. // Laurent MEUNIER
  4. // $date
  5. // 
  6. // structure for registration quality related features 
  7. // computed in ICP.h
  8. //###############################################################
  9. #ifndef REGISTRATION_STATISTICS_H
  10. #define REGISTRATION_STATISTICS_H
  11. extern void fitPnt3Plane(const vector<Pnt3>&,Pnt3&,float&,Pnt3&);
  12. class RegistrationStatistics {
  13.  public:
  14.   enum {
  15. PERCENTAGE_OVERLAPPING      = 1,
  16. AVG_MOTION                  = 2,
  17. CONDITION_NUMBER            = 3,
  18. PAIR_STABILITY              = 4,
  19. RMS_POINT_TO_PLANE_ERROR    = 5,
  20. RMS_POINT_TO_POINT_ERROR    = 6
  21.   };
  22.   bool discarded;
  23.   float percentageOverlapping;
  24.   float percentageKept;
  25.   float avgConfidence;
  26.   float avgMotion;
  27.   float conditionNumber;
  28.   float RMSPointToPointError;
  29.   float AVGPointToPointError;
  30.   float pointToPointDeviation;
  31.   float RMSPointToPlaneError;  
  32.   float AVGPointToPlaneError;
  33.   float pointToPlaneDeviation;
  34.   float mainDirProjections[8];
  35.   // init everything
  36.   RegistrationStatistics() {
  37.     discarded = false;
  38.     percentageOverlapping = 0.0;
  39.     percentageKept = 0.0;
  40.     avgConfidence = 0.0;
  41.     
  42.     avgMotion = 0.0;
  43.     conditionNumber = 0.0;
  44.     
  45.     RMSPointToPointError = 0.0;
  46.     AVGPointToPointError = 0.0;
  47.     pointToPointDeviation = 0.0;
  48.     RMSPointToPlaneError = 0.0;  
  49.     AVGPointToPlaneError = 0.0;
  50.     pointToPlaneDeviation = 0.0;    
  51.     
  52.     for(int i = 0; i < 8; i++) 
  53.       mainDirProjections[i] = 0.0;
  54.   }
  55.   bool test(RegistrationStatistics t) {
  56.     return (
  57. (percentageOverlapping > t.percentageOverlapping) &&
  58. (percentageKept > t.percentageKept) &&
  59. (avgMotion < t.avgMotion) &&
  60. (RMSPointToPlaneError < t.RMSPointToPlaneError) &&
  61. (RMSPointToPointError < t.RMSPointToPointError)
  62. );
  63.   }
  64.   float getResult(int resultType) {
  65.     switch(resultType) {
  66.     case PERCENTAGE_OVERLAPPING : return percentageOverlapping;
  67.     case PAIR_STABILITY : return percentageKept;
  68.     case AVG_MOTION : return -avgMotion;
  69.     case CONDITION_NUMBER : return -conditionNumber;
  70.     case RMS_POINT_TO_PLANE_ERROR : return -RMSPointToPlaneError;
  71.     case RMS_POINT_TO_POINT_ERROR : return -RMSPointToPointError;
  72.     }
  73.     return 0;
  74.   }
  75.   // print everything
  76.   void print() {
  77.     if(discarded) {
  78.       cout << "this pairing was discarded (overlapping area is to small)n";
  79.       return;
  80.     }
  81.     cout << "overlapping = " << percentageOverlapping << "%n";
  82.     cout << "kept = " << percentageKept << "%n";
  83.     cout << "avg confidence = " << avgConfidence << "n";
  84.     cout << "avg motion = " << avgMotion << "mmn";
  85.     cout << "condition number = " << conditionNumber << "n";
  86.     cout << "point to point: avg = " << AVGPointToPointError 
  87.          << "mm, rms = " << RMSPointToPointError 
  88.          << "mm,  deviation = " << pointToPointDeviation << "mmn";
  89.     cout << "point to plane: avg = " << AVGPointToPlaneError 
  90.  << "mm, rms = " << RMSPointToPlaneError 
  91.          << "mm,  deviation = " << pointToPlaneDeviation << "mmn";
  92.  
  93.     char str1[80], str2[80], str3[80];
  94.     sprintf(str1, "projections: %9.3f %9.3f %9.3fn", mainDirProjections[3], mainDirProjections[2], mainDirProjections[1]);
  95.     sprintf(str2, "             %9.3f           %9.3fn", mainDirProjections[4], mainDirProjections[0]);
  96.     sprintf(str3, "             %9.3f %9.3f %9.3fn", mainDirProjections[5], mainDirProjections[6], mainDirProjections[7]);    
  97.     cout << str1 << str2 << str3 << "n" << flush;   
  98.   }
  99.   static void computeMainDirections(vector<Pnt3> pts, Pnt3 *directions, Pnt3 &centroid) {
  100.     Pnt3 norm;
  101.     float d;
  102.     fitPnt3Plane(pts, norm, d, centroid);
  103.     Pnt3 u = cross(norm, Pnt3(1, 0, 0));
  104.     norm.normalize();
  105.     float lu = u.norm();
  106.     if(lu == 0.0)
  107.       u = cross(norm, Pnt3(0, 1, 0));      
  108.     u.normalize();
  109.     Pnt3 v = cross(norm, u);
  110.     v.normalize();
  111.     directions[0] = u;
  112.     directions[1] = (u + v).normalize();   
  113.     directions[2] = v;       
  114.     directions[3] = (u*(-1) + v).normalize();   
  115.     directions[4] = u*(-1);   
  116.     directions[5] = (u*(-1) + v*(-1)).normalize();   
  117.     directions[6] = v*(-1);   
  118.     directions[7] = (u + v*(-1)).normalize();
  119.   }
  120.   static float projection(vector<Pnt3> pts, Pnt3 centroid, Pnt3 direction) {
  121.     float sum = 0;
  122.     for(int i = 0; i < pts.size(); i++) {
  123.       float d = dot(pts[i]-centroid, direction);
  124.       sum += (d>0)?d:0.0;
  125.     }
  126.     return sum / pts.size();
  127.   }
  128. };
  129. #endif