@ -41,9 +41,54 @@ namespace Implementation {
template < class Vertex , std : : size_t vertexSize = Vertex : : Size > class Clean {
template < class Vertex , std : : size_t vertexSize = Vertex : : Size > class Clean {
public :
public :
inline Clean ( std : : vector < UnsignedInt > & indices , std : : vector < Vertex > & vertices ) : indices ( indices ) , vertices ( vertices ) { }
Clean ( std : : vector < UnsignedInt > & indices , std : : vector < Vertex > & vertices ) : indices ( indices ) , vertices ( vertices ) { }
void operator ( ) ( typename Vertex : : Type epsilon = Math : : TypeTraits < typename Vertex : : Type > : : epsilon ( ) ) {
void operator ( ) ( typename Vertex : : Type epsilon = Math : : TypeTraits < typename Vertex : : Type > : : epsilon ( ) ) ;
private :
class IndexHash {
public :
std : : size_t operator ( ) ( const Math : : Vector < vertexSize , std : : size_t > & data ) const {
return * reinterpret_cast < const std : : size_t * > ( Utility : : MurmurHash2 ( ) ( reinterpret_cast < const char * > ( & data ) , sizeof ( data ) ) . byteArray ( ) ) ;
}
} ;
struct HashedVertex {
UnsignedInt oldIndex , newIndex ;
HashedVertex ( UnsignedInt oldIndex , UnsignedInt newIndex ) : oldIndex ( oldIndex ) , newIndex ( newIndex ) { }
} ;
std : : vector < UnsignedInt > & indices ;
std : : vector < Vertex > & vertices ;
} ;
}
/**
@ brief % Clean the mesh
@ tparam Vertex Vertex data type
@ tparam vertexSize How many initial vertex fields are important ( for
example , when dealing with perspective in 3 D space , only first three
fields of otherwise 4 D vertex are important )
@ param [ in , out ] indices Index array to operate on
@ param [ in , out ] vertices Vertex array to operate on
@ param [ in ] epsilon Epsilon value , vertices nearer than this distance will
be melt together .
Removes duplicate vertices from the mesh .
@ todo Different ( no cycle ) implementation for integral vertices
@ todo Interpolate vertices , not collapse them to first in the cell
@ todo Ability to specify other attributes for interpolation
*/
template < class Vertex , std : : size_t vertexSize = Vertex : : Size > inline void clean ( std : : vector < UnsignedInt > & indices , std : : vector < Vertex > & vertices , typename Vertex : : Type epsilon = Math : : TypeTraits < typename Vertex : : Type > : : epsilon ( ) ) {
Implementation : : Clean < Vertex , vertexSize > ( indices , vertices ) ( epsilon ) ;
}
namespace Implementation {
template < class Vertex , std : : size_t vertexSize > void Clean < Vertex , vertexSize > : : operator ( ) ( typename Vertex : : Type epsilon ) {
if ( indices . empty ( ) ) return ;
if ( indices . empty ( ) ) return ;
/* Get mesh bounds */
/* Get mesh bounds */
@ -105,47 +150,8 @@ template<class Vertex, std::size_t vertexSize = Vertex::Size> class Clean {
moved [ moving ] = epsilon / 2 ;
moved [ moving ] = epsilon / 2 ;
}
}
}
}
}
private :
class IndexHash {
public :
inline std : : size_t operator ( ) ( const Math : : Vector < vertexSize , std : : size_t > & data ) const {
return * reinterpret_cast < const std : : size_t * > ( Utility : : MurmurHash2 ( ) ( reinterpret_cast < const char * > ( & data ) , sizeof ( data ) ) . byteArray ( ) ) ;
}
} ;
struct HashedVertex {
UnsignedInt oldIndex , newIndex ;
HashedVertex ( UnsignedInt oldIndex , UnsignedInt newIndex ) : oldIndex ( oldIndex ) , newIndex ( newIndex ) { }
} ;
std : : vector < UnsignedInt > & indices ;
std : : vector < Vertex > & vertices ;
} ;
}
}
/**
@ brief % Clean the mesh
@ tparam Vertex Vertex data type
@ tparam vertexSize How many initial vertex fields are important ( for
example , when dealing with perspective in 3 D space , only first three
fields of otherwise 4 D vertex are important )
@ param [ in , out ] indices Index array to operate on
@ param [ in , out ] vertices Vertex array to operate on
@ param [ in ] epsilon Epsilon value , vertices nearer than this distance will
be melt together .
Removes duplicate vertices from the mesh .
@ todo Different ( no cycle ) implementation for integral vertices
@ todo Interpolate vertices , not collapse them to first in the cell
@ todo Ability to specify other attributes for interpolation
*/
template < class Vertex , std : : size_t vertexSize = Vertex : : Size > inline void clean ( std : : vector < UnsignedInt > & indices , std : : vector < Vertex > & vertices , typename Vertex : : Type epsilon = Math : : TypeTraits < typename Vertex : : Type > : : epsilon ( ) ) {
Implementation : : Clean < Vertex , vertexSize > ( indices , vertices ) ( epsilon ) ;
}
}
} }
} }