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 #ifndef __VCGLIB_MESH_ASSERT 00024 #define __VCGLIB_MESH_ASSERT 00025 00026 #include <vcg/complex/complex.h> 00027 00028 namespace vcg { 00029 namespace tri { 00040 template <class MeshType> 00041 class MeshAssert 00042 { 00043 public: 00044 typedef typename MeshType::VertexType VertexType; 00045 typedef typename MeshType::VertexIterator VertexIterator; 00046 typedef typename MeshType::FaceType FaceType; 00047 typedef typename MeshType::FaceIterator FaceIterator; 00048 typedef typename MeshType::CoordType CoordType; 00049 typedef typename MeshType::ScalarType ScalarType; 00050 00051 static void FFAdjacencyIsInitialized(MeshType &m) 00052 { 00053 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) 00054 { 00055 if(!fi->IsD()) 00056 for(int i=0;i<fi->VN();++i) 00057 { 00058 if(fi->FFp(i)==0) 00059 throw vcg::MissingPreconditionException("FF adjacency is not initialized"); 00060 } 00061 } 00062 } 00063 00064 static void VFAdjacencyIsInitialized(MeshType &m) 00065 { 00066 for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) if(!vi->IsD()) 00067 { 00068 if(vi->VFp().IsNull()) 00069 throw vcg::MissingPreconditionException("VF adjacency is not initialized"); 00070 } 00071 } 00072 00073 static void NoUnreferencedVertex(MeshType &m) 00074 { 00075 tri::UpdateFlags<MeshType>::VertexClearV(m); 00076 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!fi->IsD()) 00077 { 00078 for(int i=0;i<fi->VN();++i) fi->V(i)->SetV(); 00079 } 00080 00081 for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) 00082 if(!vi->IsD()) 00083 { 00084 if(!vi->IsV()) 00085 throw vcg::MissingPreconditionException("There are unreferenced vertices"); 00086 } 00087 } 00088 00089 static void OnlyTriFace(MeshType &m) 00090 { 00091 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!fi->IsD()) 00092 { 00093 if(fi->VN()!=3) 00094 throw vcg::MissingPreconditionException("There are faces with more than three vertices"); 00095 } 00096 } 00097 00098 static void OnlyQuadFace(MeshType &m) 00099 { 00100 for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!fi->IsD()) 00101 { 00102 if(fi->VN()!=4) 00103 throw vcg::MissingPreconditionException("There are non quadrilateral faces"); 00104 } 00105 } 00106 00107 }; 00108 00109 } // end namespace tri 00110 } // end namespace vcg 00111 #endif // __VCGLIB_MESH_ASSERT