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 IO_FAN_TESSELLATOR_H 00024 #define IO_FAN_TESSELLATOR_H 00025 00026 namespace vcg { 00027 namespace tri { 00028 namespace io { 00029 00030 /* 00031 * A face polygon composed of more than three vertices is triangulated 00032 * according to the following schema: 00033 * v5 00034 * / \ 00035 * / \ 00036 * / \ 00037 * v1------v4 00038 * |\ / 00039 * | \ / 00040 * | \ / 00041 * v2---v3 00042 * 00043 * As shown above, the 5 vertices polygon (v1,v2,v3,v4,v5) 00044 * has been split into the triangles (v1,v2,v3), (v1,v3,v4) e (v1,v4,v5). 00045 * This way vertex v1 becomes the common vertex of all newly generated 00046 * triangles, and this may lead to the creation of very thin triangles. 00047 * 00048 * This function is intended as a trivial fallback when glutessellator is not available. 00049 * it assumes just ONE outline 00050 */ 00051 template < class PointType> 00052 void FanTessellator(const std::vector< std::vector<PointType> > & outlines, std::vector<int> & indices) 00053 { 00054 indices.clear(); 00055 if(outlines.empty()) return; 00056 const std::vector<PointType> &points=outlines[0]; 00057 00058 for(size_t i=0;i<points.size()-2;++i) 00059 { 00060 indices.push_back(0); 00061 indices.push_back(i+1); 00062 indices.push_back(i+2); 00063 } 00064 } 00065 00066 } // end Namespace tri 00067 } // end Namespace io 00068 } // end Namespace vcg 00069 00070 00071 #endif // IO_FAN_TESSELLATOR_H