nurbs_solve_eigen.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2012-, Open Perception, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder(s) nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * 
00035  *
00036  */
00037 
00038 #include <iostream>
00039 #include <stdexcept>
00040 
00041 #include <pcl/surface/on_nurbs/nurbs_solve.h>
00042 
00043 using namespace std;
00044 using namespace pcl;
00045 using namespace on_nurbs;
00046 
00047 void
00048 NurbsSolve::assign (unsigned rows, unsigned cols, unsigned dims)
00049 {
00050   m_Keig = Eigen::MatrixXd::Zero (rows, cols);
00051   m_xeig = Eigen::MatrixXd::Zero (cols, dims);
00052   m_feig = Eigen::MatrixXd::Zero (rows, dims);
00053 }
00054 
00055 void
00056 NurbsSolve::K (unsigned i, unsigned j, double v)
00057 {
00058   m_Keig (i, j) = v;
00059 }
00060 void
00061 NurbsSolve::x (unsigned i, unsigned j, double v)
00062 {
00063   m_xeig (i, j) = v;
00064 }
00065 void
00066 NurbsSolve::f (unsigned i, unsigned j, double v)
00067 {
00068   m_feig (i, j) = v;
00069 }
00070 
00071 double
00072 NurbsSolve::K (unsigned i, unsigned j)
00073 {
00074   return m_Keig (i, j);
00075 }
00076 double
00077 NurbsSolve::x (unsigned i, unsigned j)
00078 {
00079   return m_xeig (i, j);
00080 }
00081 double
00082 NurbsSolve::f (unsigned i, unsigned j)
00083 {
00084   return m_feig (i, j);
00085 }
00086 
00087 void
00088 NurbsSolve::resize (unsigned rows)
00089 {
00090   m_feig.conservativeResize (rows, m_feig.cols ());
00091   m_Keig.conservativeResize (rows, m_Keig.cols ());
00092 }
00093 
00094 void
00095 NurbsSolve::printK ()
00096 {
00097   for (unsigned r = 0; r < m_Keig.rows (); r++)
00098   {
00099     for (unsigned c = 0; c < m_Keig.cols (); c++)
00100     {
00101       printf (" %f", m_Keig (r, c));
00102     }
00103     printf ("\n");
00104   }
00105 }
00106 
00107 void
00108 NurbsSolve::printX ()
00109 {
00110   for (unsigned r = 0; r < m_xeig.rows (); r++)
00111   {
00112     for (unsigned c = 0; c < m_xeig.cols (); c++)
00113     {
00114       printf (" %f", m_xeig (r, c));
00115     }
00116     printf ("\n");
00117   }
00118 }
00119 
00120 void
00121 NurbsSolve::printF ()
00122 {
00123   for (unsigned r = 0; r < m_feig.rows (); r++)
00124   {
00125     for (unsigned c = 0; c < m_feig.cols (); c++)
00126     {
00127       printf (" %f", m_feig (r, c));
00128     }
00129     printf ("\n");
00130   }
00131 }
00132 
00133 bool
00134 NurbsSolve::solve ()
00135 {
00136   //  m_xeig = m_Keig.colPivHouseholderQr().solve(m_feig);
00137   //  Eigen::MatrixXd x = A.householderQr().solve(b);
00138   m_xeig = m_Keig.jacobiSvd (Eigen::ComputeThinU | Eigen::ComputeThinV).solve (m_feig);
00139 
00140   return true;
00141 }
00142 
00143 Eigen::MatrixXd
00144 NurbsSolve::diff ()
00145 {
00146   Eigen::MatrixXd f (m_Keig * m_xeig);
00147   return (f - m_feig);
00148 }
00149 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:09