/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2012 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : include/ICLAlgorithms/SQFitter.h ** ** Module : ICLAlgorithms ** ** Authors: Christian Groszewski ** ** ** ** ** ** Commercial License ** ** ICL can be used commercially, please refer to our website ** ** www.iclcv.org for more details. ** ** ** ** GNU General Public License Usage ** ** Alternatively, this file may be used under the terms of the ** ** GNU General Public License version 3.0 as published by the ** ** Free Software Foundation and appearing in the file LICENSE.GPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the GNU General Public License ** ** version 3.0 requirements will be met: ** ** http://www.gnu.org/copyleft/gpl.html. ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** *********************************************************************/ #ifndef ICL_SQFITTER_H_ #define ICL_SQFITTER_H_ #include #include #include #include namespace icl{ /** * Implementation of automatic fitting of a superquadric to given pointcloud. * Internally Levenberg-Marquardt algorithm is used. */ class SQFitter{ private: ///internal datastorage class Data; Data *m_data; ///Superquadric static SuperQuadric sq; ///min value of matrix /** * @param m matrix * @return min value of matrix */ double min(const DynMatrix &m); ///max value of matrix /** * @param m matrix * @return max value of matrix */ double max(const DynMatrix &m); ///mean of matrix /** * @param m matrix * @return meanvalue */ double mean(const DynMatrix &m); ///sorts rotationmatrix with given eigenvalues /** * @param w eigenvalues of R * @param R rotationmatrix * @return sorted rotationmatrix */ DynMatrix sort_eig(DynMatrix &w, DynMatrix &R); ///computes initial values for optimization /** * @params x points for xdim * @params y points for ydim * @params z points for zdim */ DynMatrix initial_estimate(const DynMatrix &x, const DynMatrix &y, const DynMatrix &z); ///computes Euler angles from a given rotation matrix /** * @param R rotationmatrix * @return colvector of Euler angles */ DynMatrix euler_from_rot_matrix(DynMatrix &R); public: ///Constructor /** * @param data points to fit, rowwise */ SQFitter(const DynMatrix *data); ///Destructor ~SQFitter(); ///fits superquadric to given data /** * @param params initial params, can be all zero, order is x,y,z,e1,e2,a1,a2,a3,rx,ry,rz * @param thresh max error * @param maxiter maximum nuber of iteration to do * @param autoinit automacally initializes params if true */ void fit(DynMatrix ¶ms, const double thresh=0.01, const int maxiter=100, bool autoinit = true); ///evaluates errorfunction of superquadric for x,y,z,e1,e2,a1,a2,a3,rx,ry,rz /** * @param xyz points to fit * @param params params to evaluate the errorfunction of superquadric on, order is x,y,z,e1,e2,a1,a2,a3,rx,ry,rz * @return the error for each point to fit */ static DynMatrix *func_real(const DynMatrix &xyz, DynMatrix ¶ms); ///forward differences approximating the jacobian matrix of the errorfunction of superquadric /** * Can be used in combination with every function given in this class. * @param xyz points to fit, rowwise * @param params new values for params, order is x,y,z,e1,e2,a1,a2,a3,rx,ry,rz * @return jacobian Matrix evaluated at given points rowwise */ static DynMatrix* jacobian(const DynMatrix &xyz, DynMatrix ¶ms); ///evaluates errorfunction of superquadric for new params x,y,z /** * @param xyz points to fit, rowwise * @param params new params x,y,z * @return Matrix of error */ static DynMatrix *func_XYZ(const DynMatrix &xyz, DynMatrix ¶ms); ///evaluates errorfunction of superquadric for new params rx,ry,rz /** * @param xyz points to fit, rowwise * @param params new params rx,ry,rz * @return Matrix of error */ static DynMatrix *func_R(const DynMatrix &xyz, DynMatrix ¶ms); ///evaluates errorfunction of superquadric for new params e1,e2 /** * @param xyz points to fit, rowwise * @param params new params e1,e2 * @return Matrix of error */ static DynMatrix *func_E(const DynMatrix &xyz, DynMatrix ¶ms); ///evaluates errorfunction of superquadric for new params a1,a2,a3 /** * @param xyz points to fit, rowwise * @param params new params a1,a2,a3 * @return Matrix of error */ static DynMatrix *func_A(const DynMatrix &xyz, DynMatrix ¶ms); ///evaluates errorfunction of superquadric for new params e1,e2,a1,a2,a3 /** * @param xyz points to fit, rowwise * @param params new params e1,e2,a1,a2,a3 * @return Matrix of error */ static DynMatrix *func_EA(const DynMatrix &xyz, DynMatrix ¶ms); }; } #endif /* ICL_SQFITTER_H_ */