1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004-2016 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef __VCGLIB_MESH_ASSERT
#define __VCGLIB_MESH_ASSERT
namespace vcg {
namespace tri {
/**
* \brief For checking the adequacy of a mesh to a given algorithm.
*
* While the many RequireXXX functions allow to check the static correctness of a mesh and
* have a O(1) complexity, in many cases we need to run more complex checks to be sure that
* the subsequent algorithm can run without issues.
* Typical cases are the fact that there are no unreferenced vertices (NoUnreferencedVertex)
* or a given adjacency is correctly initialized (and not only statically present as a type component).
*
* Naming Notes:
* - First two letters of the function name code the required adjacency involved
* - The exception text completes the sentence "This exception is thronw when/because...
*
*/
template <class MeshType>
class MeshAssert
{
public:
typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::VertexIterator VertexIterator;
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::FaceIterator FaceIterator;
typedef typename MeshType::CoordType CoordType;
typedef typename MeshType::ScalarType ScalarType;
/// \brief Throw vcg::MissingPreconditionException if FF adjacency is not initialized
static void FFAdjacencyIsInitialized(MeshType &m)
{
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
{
if(!fi->IsD())
for(int i=0;i<fi->VN();++i)
{
if(fi->FFp(i)==0)
throw vcg::MissingPreconditionException("FF adjacency is not initialized");
}
}
}
/// \brief Throw vcg::MissingPreconditionException if VF adjacency is not initialized
static void VFAdjacencyIsInitialized(MeshType &m)
{
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) if(!vi->IsD())
{
if(vi->VFp() == nullptr)
throw vcg::MissingPreconditionException("VF adjacency is not initialized");
}
}
/// \brief Throw vcg::MissingPreconditionException if EE adjacency is not initialized
static void EEAdjacencyIsInitialized(MeshType &m)
{
for(auto ei=m.edge.begin();ei!=m.edge.end();++ei) if(!ei->IsD())
{
if(ei->EEp(0)==0)
throw vcg::MissingPreconditionException("EE adjacency is not initialized");
}
}
/// \brief Throw vcg::MissingPreconditionException if According to EE adjacency, the edge mesh is not 1-manifold (e.g there are more than 2 edges on a vertex)
static void EEOneManifold(MeshType &m)
{
EEAdjacencyIsInitialized(m);
for(auto ei=m.edge.begin();ei!=m.edge.end();++ei) if(!ei->IsD())
{
if(! edge::IsEdgeManifold(*ei,0) )
throw vcg::MissingPreconditionException("According to EE adjacency, the edge mesh is not 1-manifold (e.g there are more than 2 edges on a vertex)");
}
}
/// \brief Throw vcg::MissingPreconditionException if Vertex Normals are not unit lenght
static void VertexNormalNormalized(MeshType &m)
{
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) if(!vi->IsD())
{
if(fabs(vi->cN().Norm()-1.0)>0.000001)
throw vcg::MissingPreconditionException("Vertex Normal are not normalized");
}
}
/// \brief Throw vcg::MissingPreconditionException if There are unreferenced vertices
static void NoUnreferencedVertex(MeshType &m)
{
UpdateFlags<MeshType>::VertexClearV(m);
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!fi->IsD())
{
for(int i=0;i<fi->VN();++i) fi->V(i)->SetV();
}
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!vi->IsD())
{
if(!vi->IsV())
throw vcg::MissingPreconditionException("There are unreferenced vertices");
}
}
/// \brief Throw vcg::MissingPreconditionException if There are faces with more than three vertices
static void OnlyTriFace(MeshType &m)
{
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!fi->IsD())
{
if(fi->VN()!=3)
throw vcg::MissingPreconditionException("There are faces with more than three vertices");
}
}
/// \brief Throw vcg::MissingPreconditionException if There are non quadrilateral faces
static void OnlyQuadFace(MeshType &m)
{
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!fi->IsD())
{
if(fi->VN()!=4)
throw vcg::MissingPreconditionException("There are non quadrilateral faces");
}
}
/// \brief Throw vcg::MissingPreconditionException if The mesh is not composed only by edges (no faces needed or allowed)
static void OnlyEdgeMesh(MeshType &m)
{
if(m.FN()>0)
throw vcg::MissingPreconditionException("The mesh is not composed only by edges (no faces needed or allowed)");
}
/// \brief Throw vcg::MissingPreconditionException if According to FF adjacency, the mesh is not two manifold (e.g. there are more than two faces on an edge)
static void FFTwoManifoldEdge(MeshType & m)
{
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!fi->IsD())
{
for(int i=0;i<fi->VN();++i){
if(!face::IsManifold(*fi,i))
throw vcg::MissingPreconditionException("According to FF adjacency, the mesh is not two manifold (e.g. there are more than two faces on an edge)");
}
}
}
};
} // end namespace tri
} // end namespace vcg
#endif // __VCGLIB_MESH_ASSERT
|