texture.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) 2004                                                \/)\/    *
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 
00025 #ifndef __VCG_TRI_UPDATE_TEXTURE
00026 #define __VCG_TRI_UPDATE_TEXTURE
00027 
00028 //#include <vcg/space/plane.h>
00029 
00030 namespace vcg {
00031 namespace tri {
00032 
00034 
00036 
00038 template <class ComputeMeshType>
00039 class UpdateTexture
00040 {
00041 
00042 public:
00043 typedef ComputeMeshType MeshType; 
00044 typedef typename MeshType::ScalarType     ScalarType;
00045 typedef typename MeshType::VertexType     VertexType;
00046 typedef typename MeshType::VertexPointer  VertexPointer;
00047 typedef typename MeshType::VertexIterator VertexIterator;
00048 typedef typename MeshType::FaceType       FaceType;
00049 typedef typename MeshType::FacePointer    FacePointer;
00050 typedef typename MeshType::FaceIterator   FaceIterator;
00051 
00052 static void WedgeTexFromPlane(ComputeMeshType &m, const Point3<ScalarType> &uVec, const Point3<ScalarType> &vVec, bool aspectRatio, ScalarType sideGutter=0.0)
00053 {
00054         Box2f bb;
00055 
00056         FaceIterator fi;
00057         for(fi=m.face.begin();fi!=m.face.end();++fi)
00058                 if(!(*fi).IsD()) 
00059                 {
00060                         for(int i=0;i<3;++i)
00061                         {
00062                                 (*fi).WT(i).U()= (*fi).V(i)->cP() * uVec;
00063                                 (*fi).WT(i).V()= (*fi).V(i)->cP() * vVec;
00064                                 bb.Add((*fi).WT(i).P());
00065                         }
00066                 }       
00067 
00068         ScalarType wideU =  bb.max[0]- bb.min[0];
00069         ScalarType wideV =  bb.max[1]- bb.min[1];
00070 
00071         if (sideGutter>0.0)
00072         {
00073                 ScalarType deltaGutter = std::min(wideU, wideV) * min(sideGutter, (ScalarType)0.5);
00074 
00075                 bb.max[0] += deltaGutter;
00076                 bb.min[0] -= deltaGutter;
00077                 bb.max[1] += deltaGutter;
00078                 bb.min[1] -= deltaGutter;
00079 
00080                 wideU = bb.max[0] - bb.min[0];
00081                 wideV = bb.max[1] - bb.min[1];
00082         }
00083 
00084         if (aspectRatio) {
00085                 wideU = std::max(wideU, wideV);
00086                 wideV = wideU;
00087         }
00088 
00089         for (fi = m.face.begin(); fi != m.face.end(); ++fi)
00090         if (!(*fi).IsD())
00091         {
00092                 for (int i = 0; i<3; ++i)
00093                 {
00094                         (*fi).WT(i).U() = ((*fi).WT(i).U() - bb.min[0]) / wideU;
00095                         (*fi).WT(i).V() = ((*fi).WT(i).V() - bb.min[1]) / wideV;
00096                 }
00097         }
00098 }
00099 
00100 static void WedgeTexFromCamera(ComputeMeshType &m, Plane3<ScalarType> &pl)
00101 {
00102         
00103 }
00104 
00105 static void WedgeTexFromVertexTex(ComputeMeshType &m)
00106 {
00107   for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
00108           if(!(*fi).IsD())
00109               {
00110                for(int i=0;i<3;++i)
00111                {
00112                  (*fi).WT(i).U() = (*fi).V(i)->T().U();
00113                  (*fi).WT(i).V() = (*fi).V(i)->T().V();
00114                }
00115               }
00116 }
00117 
00118 
00122 static void WedgeTexRemoveNull(ComputeMeshType &m, const std::string &texturename)
00123 {
00124         bool found=false;
00125         
00126         FaceIterator fi;
00127         // first loop lets check that there are -1 indexed textured face
00128         for(fi=m.face.begin();fi!=m.face.end();++fi)
00129                 if(!(*fi).IsD()) if((*fi).WT(0).N()==-1) found = true;
00130         
00131         if(!found) return;
00132         m.textures.push_back(texturename);
00133         
00134         int nullId=m.textures.size()-1;
00135         
00136         for(fi=m.face.begin();fi!=m.face.end();++fi)
00137                 if(!(*fi).IsD()) if((*fi).WT(0).N()==-1)                
00138                 {
00139                         (*fi).WT(0).N() = nullId;
00140                         (*fi).WT(1).N() = nullId;
00141                         (*fi).WT(2).N() = nullId;                       
00142                 }                                                                                       
00143                         
00144 }
00145 
00146 }; // end class
00147 
00148 }       // End namespace
00149 }       // End namespace
00150 
00151 
00152 #endif


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