2014-11-03 15:50:37 +01:00
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
2016-06-13 07:29:25 +02:00
* Copyright ( C ) 2004 - 2016 \ / ) \ / *
2014-11-03 15:50:37 +01:00
* Visual Computing Lab / \ / | *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved . *
* *
2016-06-13 07:29:25 +02:00
* This program is free software ; you can redistribute it and / or modify *
2014-11-03 15:50:37 +01:00
* 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 ) .
2017-03-21 23:18:22 +01:00
*
* 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...
*
2014-11-03 15:50:37 +01:00
*/
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 ;
2017-03-21 23:18:22 +01:00
/// \brief Throw vcg::MissingPreconditionException if FF adjacency is not initialized
2014-11-03 15:50:37 +01:00
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 " ) ;
}
}
}
2017-03-21 23:18:22 +01:00
/// \brief Throw vcg::MissingPreconditionException if VF adjacency is not initialized
2014-11-03 15:50:37 +01:00
static void VFAdjacencyIsInitialized ( MeshType & m )
{
for ( VertexIterator vi = m . vert . begin ( ) ; vi ! = m . vert . end ( ) ; + + vi ) if ( ! vi - > IsD ( ) )
{
if ( vi - > VFp ( ) . IsNull ( ) )
throw vcg : : MissingPreconditionException ( " VF adjacency is not initialized " ) ;
}
}
2017-03-21 23:18:22 +01:00
/// \brief Throw vcg::MissingPreconditionException if EE adjacency is not initialized
2017-03-13 15:41:16 +01:00
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 " ) ;
}
}
2017-03-21 23:18:22 +01:00
/// \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)
2017-03-13 15:41:16 +01:00
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 ) )
2017-03-21 23:18:22 +01:00
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) " ) ;
2017-03-13 15:41:16 +01:00
}
}
2017-03-21 23:18:22 +01:00
/// \brief Throw vcg::MissingPreconditionException if There are unreferenced vertices
2014-11-03 15:50:37 +01:00
static void NoUnreferencedVertex ( MeshType & m )
{
2017-03-21 23:18:22 +01:00
UpdateFlags < MeshType > : : VertexClearV ( m ) ;
2014-11-03 15:50:37 +01:00
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 " ) ;
}
}
2017-03-21 23:18:22 +01:00
/// \brief Throw vcg::MissingPreconditionException if There are faces with more than three vertices
2014-11-06 16:10:00 +01:00
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 " ) ;
}
}
2017-03-21 23:18:22 +01:00
/// \brief Throw vcg::MissingPreconditionException if There are non quadrilateral faces
2014-11-06 16:10:00 +01:00
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 " ) ;
}
}
2017-03-21 23:18:22 +01:00
/// \brief Throw vcg::MissingPreconditionException if The mesh is not composed only by edges (no faces needed or allowed)
2016-11-02 11:23:25 +01:00
static void OnlyEdgeMesh ( MeshType & m )
{
if ( m . FN ( ) > 0 )
2017-03-21 23:18:22 +01:00
throw vcg : : MissingPreconditionException ( " The mesh is not composed only by edges (no faces needed or allowed) " ) ;
2016-11-02 11:23:25 +01:00
}
2017-03-21 23:18:22 +01:00
/// \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)
2017-03-13 15:41:16 +01:00
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 ) )
2017-03-21 23:18:22 +01:00
throw vcg : : MissingPreconditionException ( " According to FF adjacency, the mesh is not two manifold (e.g. there are more than two faces on an edge) " ) ;
2017-03-13 15:41:16 +01:00
}
}
}
2016-11-02 11:23:25 +01:00
2014-11-03 15:50:37 +01:00
} ;
} // end namespace tri
} // end namespace vcg
# endif // __VCGLIB_MESH_ASSERT