export_field.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 #ifndef __VCGLIB_EXPORTERFIELD
00024 #define __VCGLIB_EXPORTERFIELD
00025 
00026 #include <vcg/complex/algorithms/parametrization/tangent_field_operators.h>
00027 
00028 namespace vcg {
00029 namespace tri {
00030 namespace io {
00031 
00035 template <class MeshType>
00036 class ExporterFIELD
00037 {
00038     typedef typename MeshType::ScalarType ScalarType;
00039     typedef typename MeshType::FaceType FaceType;
00040     typedef typename MeshType::VertexType VertexType;
00041     typedef typename MeshType::CoordType CoordType;
00042 
00043 public:
00044     
00047     static void SaveFaceFIELD(MeshType &mesh,
00048                               const char *path)
00049     {
00050         
00051         FILE *f = fopen(path,"wt");
00052         //if (!f)return false;
00053 //            char word[512]; word[0]=0;
00054 //            fscanf(f,"%s",word);
00055 //            char c=0;
00056 //            if (word[0]=='#') {
00057 //                // skip comment line
00058 //                while (fscanf(f,"%c",&c)!=EOF) if (c=='\n') break;
00059 //            }
00060 //            else
00061 //            {
00062 //                return false;
00063 //            }
00064             int nf = mesh.fn;//-1;
00065             fprintf(f,"# frame generated with VCG \n");
00066             fprintf(f,"target frame \n");
00067             fprintf(f,"%d\n",nf);
00068 //            
00069 //            if( per_vertex && !HasPerVertexCurvatureDir(mesh)) throw vcg::MissingComponentException("PerVertexCurvatureDir");
00070 //            if(!per_vertex && !HasPerFaceCurvatureDir(mesh))   throw vcg::MissingComponentException("PerFaceCurvatureDir");
00071             if (!HasPerFaceCurvatureDir(mesh))
00072                 throw vcg::MissingComponentException("PerFaceCurvatureDir");
00073             
00074             fprintf(f,"k1        k2      k1v_x   k1v_y   k1v_z   k2v_x   k2v_y   k2v_z\n");
00075 
00076             for (int i=0; i<nf; i++){
00077                 vcg::Point3<float> u;
00078                 u.Import(mesh.face[i].PD1());
00079                 vcg::Point3<float> v;
00080                 v.Import(mesh.face[i].PD2());
00081                 
00082                 fprintf(f,"1 1 %f %f %f %f %f %f\n",
00083                         (u.X()),(u.Y()),(u.Z()),
00084                         (v.X()),(v.Y()),(v.Z()));
00085             }
00086         fclose(f);
00087     }
00088 
00089     
00093     static void Save4ROSY(MeshType &mesh,
00094                         const char *path)
00095     {
00096         FILE *f = fopen(path,"wt");
00097         fprintf(f,"%d\n",mesh.vn);
00098         fprintf(f,"4\n");
00099         for (unsigned int i=0;i<mesh.vert.size();i++)
00100         {
00101             float dirX=(float)mesh.vert[i].PD1().X();
00102             float dirY=(float)mesh.vert[i].PD1().Y();
00103             float dirZ=(float)mesh.vert[i].PD1().Z();
00104             fprintf(f,"%f %f %f \n",dirX,dirY,dirZ);
00105 
00106         }
00107         fclose(f);
00108     }
00109 
00110     //Save a 4 rosy format file as pair of angles
00111     static void Save2AngleFace(MeshType &mesh,
00112                               const char *path)
00113     {
00114         FILE *f = fopen(path,"wt");
00115         fprintf(f,"#%d param_field\n",mesh.fn);
00116         for (unsigned int i=0;i<mesh.face.size();i++)
00117         {
00118             ScalarType alpha1,alpha2;
00119             CoordType PD1Test=mesh.face[i].PD1();
00120             CoordType PD2Test=mesh.face[i].PD2();
00121             vcg::tri::CrossField<MeshType>::CrossFieldToAngles(mesh.face[i],alpha1,alpha2,1);
00122             fprintf(f,"%d %f %f \n",i,alpha1,alpha2);
00123         }
00124         fclose(f);
00125     }
00126 
00127 }; // end class
00128 
00129 
00130 
00131 } // end namespace tri
00132 } // end namespace io
00133 } // end namespace vcg
00134 
00135 #endif
00136 


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