trimesh_texture.cpp
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-2012                                           \/)\/    *
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 #include <QtOpenGL/QtOpenGL>
00024 
00025 #include<vcg/complex/complex.h>
00026 
00027 // input output
00028 #include <wrap/io_trimesh/import_ply.h>
00029 #include <wrap/io_trimesh/export_ply.h>
00030 
00031 #include<vcg/complex/algorithms/update/topology.h>
00032 #include<vcg/complex/algorithms/outline_support.h>
00033 
00034 #include<vcg/simplex/face/pos.h>
00035 
00036 #include <vcg/space/outline2_packer.h>
00037 #include <wrap/qt/outline2_rasterizer.h>
00038 
00039 #include <vcg/space/rasterized_outline2_packer.h>
00040 #include <wrap/qt/Outline2ToQImage.h>
00041 
00042 using namespace vcg;
00043 
00044 class MyEdge;
00045 class MyFace;
00046 class MyVertex;
00047 struct MyUsedTypes : public UsedTypes<  Use<MyVertex>::AsVertexType, Use<MyFace>::AsFaceType>{};
00048 
00049 class MyVertex  : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::BitFlags  >{};
00050 class MyFace    : public Face  < MyUsedTypes, face::VertexRef, face::FFAdj, face::WedgeTexCoord2f, face::Mark, face::BitFlags > {};
00051 class MyMesh : public tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace > >{};
00052 
00053 
00054 int main(int ,char ** )
00055 {
00056   MyMesh m,tm;
00057   tri::io::ImporterPLY<MyMesh>::Open(m,"../../meshes/bunny10k_textured.ply");
00058 
00059   tri::Allocator<MyMesh>::AddVertices(tm,m.fn*3);
00060   tri::Allocator<MyMesh>::AddFaces(tm,m.fn);
00061 
00062   for(size_t i=0;i<m.fn;++i)
00063   {
00064     for(int j=0;j<3;++j)
00065     {
00066       tm.face[i].V(j)=&tm.vert[i*3+j];
00067       tm.vert[i*3+j].P()[0] = m.face[i].WT(j).U();
00068       tm.vert[i*3+j].P()[1] = m.face[i].WT(j).V();
00069       tm.vert[i*3+j].P()[2] = 0;
00070     }
00071   }
00072   tri::Clean<MyMesh>::RemoveDuplicateVertex(tm);
00073   std::vector<std::pair<int,MyMesh::FacePointer> > fpVec;
00074   tri::UpdateTopology<MyMesh>::FaceFace(tm);
00075   tri::Clean<MyMesh>::ConnectedComponents(tm,fpVec);
00076   printf("Mesh has %lu texture components\n",fpVec.size());
00077   tri::io::ExporterPLY<MyMesh>::Save(tm,"out.ply");
00078   std::vector< std::vector<Point2f> > outline2Vec;
00079 
00080   for(size_t i=0; i<fpVec.size();++i)
00081   {
00082     tri::UpdateSelection<MyMesh>::FaceClear(tm);
00083     fpVec[i].second->SetS();
00084     tri::UpdateSelection<MyMesh>::FaceConnectedFF(tm);
00085     tri::UpdateSelection<MyMesh>::VertexClear(tm);
00086     tri::UpdateSelection<MyMesh>::VertexFromFaceLoose(tm);
00087 
00088     MyMesh comp;
00089     tri::Append<MyMesh,MyMesh>::Mesh(comp, tm, true);
00090 
00091     std::vector< std::vector<Point3f> > outline3Vec;
00092     tri::OutlineUtil<float>::ConvertMeshBoundaryToOutline3Vec(comp, outline3Vec);
00093     std::vector< std::vector<Point2f> > compOutline2Vec;
00094     tri::OutlineUtil<float>::ConvertOutline3VecToOutline2Vec(outline3Vec,compOutline2Vec);
00095     int largestInd=tri::OutlineUtil<float>::LargestOutline2(compOutline2Vec);
00096     if(tri::OutlineUtil<float>::Outline2Area(compOutline2Vec[largestInd])<0)
00097       tri::OutlineUtil<float>::ReverseOutline2(compOutline2Vec[largestInd]);
00098 
00099     outline2Vec.push_back(compOutline2Vec[largestInd]);
00100   }
00101 
00102   printf("Mesh has %lu texture components\n",outline2Vec.size());
00103 
00104   Outline2Dumper::Param pp;
00105   Similarity2f sim;
00106   sim.sca=1024.0f;
00107   std::vector<Similarity2f> trVec(outline2Vec.size(),sim);
00108   printf("Mesh has %lu texture components\n",outline2Vec.size());
00109   Outline2Dumper::dumpOutline2VecPNG("PrePack.png",outline2Vec,trVec,pp);
00110 
00111   const Point2i containerSize(1024,1024);
00112   Point2f finalSize(1024,1024);
00113   PolyPacker<float>::PackAsAxisAlignedRect(outline2Vec,containerSize,trVec,finalSize);
00114 
00115   Outline2Dumper::dumpOutline2VecPNG("PostPack.png",outline2Vec,trVec,pp);
00116 
00117   RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters packingParam;
00118 
00119   packingParam.costFunction  = RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Parameters::LowestHorizon;
00120   packingParam.doubleHorizon = true;
00121   packingParam.cellSize = 4;
00122   packingParam.rotationNum = 16; //number of rasterizations in 90°
00123 
00124   RasterizedOutline2Packer<float, QtOutline2Rasterizer>::Pack(outline2Vec,containerSize,trVec,packingParam);
00125   Outline2Dumper::dumpOutline2VecPNG("PostPackRR.png",outline2Vec,trVec,pp);
00126 
00127 
00128   return 0;
00129 }
00130 


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