lscm_parametrization.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2014                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 
00024 /* Optimizes given UV-mapping with
00025  * [Least Square Conformal Maps]
00026  * (minimizes angle distrotions).
00027  *
00028  * Needs:
00029  * (-) per-vertex texture coords
00030  * (-) some fixed boundary:
00031  *     Fixed vertices are the flagged ones.
00032  *     By default: (use fixedMask parameter to customize)
00033  *     BORDER or SELECTED verts are fixed.
00034  *
00035  * Example of usage:
00036  *    MyMesh m;
00037  *    vcg::tri::UpdateFlags< MyMesh >::VertexBorderFromNone( m );
00038  *    vcg::tri::OptimizeUV_LSCM( m );
00039  *
00040  */
00041 
00042 #ifndef __VCG_IGL_LEAST_SQUARES_CONFORMAL_MAPS
00043 #define __VCG_IGL_LEAST_SQUARES_CONFORMAL_MAPS
00044 
00045 #include <igl/lscm.h>
00046 #include <vcg/complex/algorithms/mesh_to_matrix.h>
00047 
00048 namespace vcg{
00049 namespace tri{
00050 
00051 template<class MeshType >
00052 void OptimizeUV_LSCM( MeshType& m ,
00053                       unsigned int fixedMask =
00054                         MeshType::VertexType::BORDER |
00055                         MeshType::VertexType::SELECTED
00056                      )
00057 {
00058 
00059     // check requirements
00060     vcg::tri::VertexVectorHasPerVertexTexCoord( m.vert );
00061     vcg::tri::VertexVectorHasPerVertexFlags( m.vert );
00062 
00063     Eigen::MatrixXd V;
00064     Eigen::MatrixXi F;
00065     Eigen::VectorXi b;
00066     Eigen::MatrixXd bc;
00067     Eigen::MatrixXd V_uv;
00068 
00069     vcg::tri::MeshToMatrix< MeshType >::GetTriMeshData( m, F, V );
00070 
00071     // build fixed points data
00072     int nFixed = 0;
00073     for (int i=0; i<(int)m.vert.size(); i++) {
00074         if (m.vert[i].Flags()&fixedMask) nFixed++;
00075     }
00076 
00077     // all fixed, nothing to do? get out to avoid crashes
00078     if (nFixed == m.vert.size()) return;
00079 
00080     b.resize(nFixed);
00081     bc.resize(nFixed,2);
00082     for (int i=0,k=0; i<(int)m.vert.size(); i++) {
00083         if (m.vert[i].Flags()&fixedMask)  {
00084             b(k) = i;
00085             bc(k,0) = m.vert[i].T().P()[0];
00086             bc(k,1) = m.vert[i].T().P()[1];
00087             k++;
00088         }
00089     }
00090 
00091     // apply Least Square Conformal Maps
00092     ::igl::lscm(V,F,b,bc,V_uv);
00093 
00094     // copy results back to mesh
00095     for (int i=0; i<(int)m.vert.size(); i++) {
00096         m.vert[i].T().P()[0] = V_uv(i,0);
00097         m.vert[i].T().P()[1] = V_uv(i,1);
00098     }
00099 }
00100 
00101 }} // namespaces
00102 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:32:50