param.h
Go to the documentation of this file.
00001 
00059 /*
00060  * param.h
00061  *
00062  *  Created on: 11.06.2012
00063  *      Author: josh
00064  */
00065 
00066 #ifndef PARAM_H_
00067 #define PARAM_H_
00068 
00069 #define FAK( x ) ((x+2)*(x+1)/2)
00070 #define ROUND_UP_POW2( x ) (x<=2?2:(x<=4?4:(x<=8?8:(x<=16?16:(x<=32?32:(x<=64?64:(x<128?128:x)))))))
00071 
00076 template<int Degree>
00077 struct Param {
00078 #ifdef MIN_EIGEN_VECTOR
00079   typedef Eigen::Matrix<float, FAK(Degree), 1>    VectorU;
00080   typedef Eigen::Matrix<float, FAK(Degree), FAK(Degree)>    MatrixU;
00081 #else
00082   typedef Eigen::Matrix<float, (ROUND_UP_POW2( FAK(Degree) )), 1>    VectorU;
00083   typedef Eigen::Matrix<float, (ROUND_UP_POW2( FAK(Degree) )), (ROUND_UP_POW2( FAK(Degree) ))>    MatrixU;
00084 #endif
00085 
00086   enum {NUM=FAK(Degree)};       
00087 
00088   MatrixU model_;               
00089   VectorU z_;                   
00090 #ifdef USE_MIN_MAX_RECHECK_
00091   float v_min_,v_max_;          
00092 #endif
00093   int occopied;                 
00094 
00096   Param() {
00097     z_.fill(0);
00098     model_.fill(0);
00099   }
00100 
00102   inline void operator=(const Eigen::Vector3f &p) {
00103     if(pcl_isfinite(p(2))) {
00104 
00105 #ifdef USE_MIN_MAX_RECHECK_
00106       v_min_=v_max_=p(2);
00107 #endif
00108 
00109       for(int i=0; i<=Degree; i++)
00110         for(int j=0; j<=i; j++)
00111           z_(i*(i+1)/2+j) = std::pow(p(0),j)*std::pow(p(1),i-j);
00112 
00113       model_ = z_*z_.transpose();
00114       z_ *= p(2);
00115     }
00116     else {
00117 #ifdef USE_MIN_MAX_RECHECK_
00118       v_min_=v_max_=0.f;
00119 #endif
00120       z_.fill(0);
00121       model_.fill(0);
00122     }
00123   }
00124 
00126   inline void operator+=(const Param<Degree> &p) {
00127     model_+=p.model_;
00128     z_+=p.z_;
00129 #ifdef USE_MIN_MAX_RECHECK_
00130     if((p.v_min_!=0.f && p.v_min_<v_min_)||v_min_==0.f) v_min_=p.v_min_;
00131     if(p.v_max_>v_max_||v_max_==0.f) v_max_=p.v_max_;
00132 #endif
00133   }
00134 
00135   inline float x() const {return model_(0,2)/model_(0,0);}      
00136   inline float y() const {return model_(0,1)/model_(0,0);}      
00137   inline float z() const {return z_(0)/model_(0,0);}            
00138 };
00139 
00140 #ifdef QPPF_SPECIALIZATION_2
00141 
00145 template< >
00146 struct Param<2> {
00147 #ifdef MIN_EIGEN_VECTOR
00148   typedef Eigen::Matrix<float, FAK(6), 1>    VectorU;
00149   typedef Eigen::Matrix<float, FAK(2), FAK(2)>    MatrixU;
00150 #else
00151   typedef Eigen::Matrix<float, (ROUND_UP_POW2( FAK(2) )), 1>    VectorU;
00152   typedef Eigen::Matrix<float, (ROUND_UP_POW2( FAK(2) )), (ROUND_UP_POW2( FAK(2) ))>    MatrixU;
00153 #endif
00154 
00155   enum {NUM=FAK(2)};
00156 
00157   MatrixU model_;        
00158   VectorU z_;              
00159 #ifdef USE_MIN_MAX_RECHECK_
00160   float v_min_,v_max_;
00161 #endif
00162   int occopied;             
00163 
00165   Param(): model_(MatrixU::Zero()) ,z_(VectorU::Zero()){
00166     //for(int i=0; i<model_.rows(); i++)
00167     //{z_(i)=0; for(int j=0; j<model_.cols(); j++) model_(i,j)=0;}
00168   }
00169 
00171   inline void operator=(const Eigen::Vector3f &p) {
00172     if(pcl_isfinite(p(2))) {
00173 
00174 #ifdef USE_MIN_MAX_RECHECK_
00175       v_min_=v_max_=p(2);
00176 #endif
00177       float x=p(0);
00178       float x2=x*x;
00179       float y=p(1);
00180       float y2=y*y;
00181 
00182 #if 0
00183       z_(0) = 1;
00184       z_(1) = x;
00185       z_(2) = x2;
00186       z_(3) = y;
00187       z_(4) = y2;
00188       z_(5) = x*y;
00189 
00190       model_ = z_*z_.transpose();
00191       z_ *= p(2);
00192 
00193 #else
00194 
00195       z_(0) = p(2);
00196       z_(1) = p(2)*x;
00197       z_(2) = p(2)*x2;
00198       z_(3) = p(2)*y;
00199       z_(4) = p(2)*y2;
00200 #ifndef DONT_USE_6TH
00201       z_(5) = p(2)*x*y;
00202 #endif
00203 
00204       for(int i=0; i<6; i++) {
00205         float m=1;
00206         switch(i) {
00207           case 1: m=x;break;
00208           case 2: m=x2;break;
00209           case 3: m=y;break;
00210           case 4: m=y2;break;
00211 #ifndef DONT_USE_6TH
00212           case 5: m=x*y;break;
00213 #else
00214           case 5: m=0.f;break;
00215 #endif
00216         }
00217         model_(i,0)=m;
00218         model_(i,1)=x*m;
00219         model_(i,2)=x2*m;
00220         model_(i,3)=y*m;
00221         model_(i,4)=y2*m;
00222 #ifndef DONT_USE_6TH
00223         model_(i,5)=x*y*m;
00224 #endif
00225       }
00226 #endif
00227     }
00228     else {
00229 #ifdef USE_MIN_MAX_RECHECK_
00230       v_min_=v_max_=0.f;
00231 #endif
00232       z_.fill(0.f);
00233       model_.fill(0.f);
00234 //      z_(0)=z_(1)=z_(2)=z_(3)=z_(4)=z_(5)=0.f;
00235 //      for(int i=0; i<6; i++) for(int j=0; j<6; j++)
00236 //        model_(i,j)=0.f;
00237     }
00238   }
00239 
00241   inline void operator+=(const Param<2> &p) {
00242     model_+=p.model_;
00243     z_+=p.z_;
00244 #ifdef USE_MIN_MAX_RECHECK_
00245     if((p.v_min_!=0.f && p.v_min_<v_min_)||v_min_==0.f) v_min_=p.v_min_;
00246     if(p.v_max_>v_max_||v_max_==0.f) v_max_=p.v_max_;
00247 #endif
00248   }
00249 
00250   inline float x() const {return model_(0,1)/model_(0,0);}
00251   inline float y() const {return model_(0,3)/model_(0,0);}
00252   inline float z() const {return z_(0)/model_(0,0);}
00253 };
00254 #endif
00255 
00262 template<int Degree>
00263 struct ParamC {
00264   Param<Degree> *data;
00265   unsigned int w,h;
00266 
00267   ParamC(const ParamC &p):w(p.w),h(p.h) {
00268     data=new Param<Degree>[w*h];
00269     for(size_t i=0; i<w*h; i++)
00270       data[i]=p.data[i];
00271   }
00272 
00273   ParamC(unsigned int w, unsigned int h):w(w),h(h) {
00274     data=new Param<Degree>[w*h];
00275   }
00276 
00277   ~ParamC() {
00278     delete [] data;
00279   }
00280 };
00281 
00282 #endif /* PARAM_H_ */


cob_3d_segmentation
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:03:03