added edgemeshconnectedcomponent and relative iterator
This commit is contained in:
parent
ddeab96232
commit
90077c02dc
|
|
@ -37,6 +37,68 @@
|
|||
namespace vcg {
|
||||
namespace tri{
|
||||
|
||||
template <class ConnectedEdgeMeshType>
|
||||
class EdgeConnectedComponentIterator
|
||||
{
|
||||
public:
|
||||
typedef ConnectedEdgeMeshType MeshType;
|
||||
typedef typename MeshType::VertexType VertexType;
|
||||
typedef typename MeshType::VertexPointer VertexPointer;
|
||||
typedef typename MeshType::VertexIterator VertexIterator;
|
||||
typedef typename MeshType::ScalarType ScalarType;
|
||||
typedef typename MeshType::EdgeType EdgeType;
|
||||
typedef typename MeshType::EdgePointer EdgePointer;
|
||||
typedef typename MeshType::EdgeIterator EdgeIterator;
|
||||
typedef typename MeshType::ConstEdgeIterator ConstEdgeIterator;
|
||||
typedef typename MeshType::EdgeContainer EdgeContainer;
|
||||
|
||||
public:
|
||||
void operator ++()
|
||||
{
|
||||
EdgePointer ep = se.top();
|
||||
se.pop();
|
||||
for(int i = 0; i < 2; ++i)
|
||||
{
|
||||
edge::VEIterator<EdgeType> vei(ep->V(i));
|
||||
while (!vei.End())
|
||||
{
|
||||
if (!tri::IsMarked(*mp, vei.E()))
|
||||
{
|
||||
tri::Mark(*mp, vei.E());
|
||||
se.push(vei.E());
|
||||
}
|
||||
++vei;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void start(MeshType &m, EdgePointer e)
|
||||
{
|
||||
tri::RequirePerEdgeMark(m);
|
||||
mp=&m;
|
||||
|
||||
while(!se.empty())
|
||||
se.pop();
|
||||
|
||||
UnMarkAll(m);
|
||||
|
||||
tri::Mark(m, e);
|
||||
se.push(e);
|
||||
}
|
||||
|
||||
bool completed() {
|
||||
return se.empty();
|
||||
}
|
||||
|
||||
EdgePointer operator *()
|
||||
{
|
||||
return se.top();
|
||||
}
|
||||
private:
|
||||
std::stack<EdgePointer> se;
|
||||
MeshType *mp;
|
||||
};
|
||||
|
||||
template <class ConnectedMeshType>
|
||||
class ConnectedComponentIterator
|
||||
{
|
||||
|
|
@ -1119,6 +1181,47 @@ public:
|
|||
return int(CCV.size());
|
||||
}
|
||||
|
||||
static int edgeMeshConnectedComponents(MeshType & poly, std::vector<std::pair<int, typename MeshType::EdgePointer> > &eCC)
|
||||
{
|
||||
typedef typename MeshType::EdgePointer EdgePointer;
|
||||
tri::UpdateTopology<MeshType>::VertexEdge(poly);
|
||||
tri::UpdateFlags<MeshType>::EdgeClear(poly);
|
||||
eCC.clear();
|
||||
std::stack<EdgePointer> stack;
|
||||
|
||||
for (auto ei = poly.edge.begin(); ei != poly.edge.end(); ++ei)
|
||||
if (!ei->IsD() && !ei->IsV())
|
||||
{
|
||||
ei->SetV();
|
||||
|
||||
std::pair<int, EdgePointer> cc(1, &*ei);
|
||||
|
||||
stack.push(&*ei);
|
||||
while (!stack.empty())
|
||||
{
|
||||
EdgePointer ep = stack.top();
|
||||
stack.pop();
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
edge::VEIterator<typename MeshType::EdgeType> vei(ep->V(i));
|
||||
while (!vei.End())
|
||||
{
|
||||
if (!vei.E()->IsV())
|
||||
{
|
||||
vei.E()->SetV();
|
||||
stack.push(vei.E());
|
||||
cc.first += 1;
|
||||
}
|
||||
++vei;
|
||||
}
|
||||
}
|
||||
}
|
||||
eCC.push_back(cc);
|
||||
}
|
||||
return int(eCC.size());
|
||||
}
|
||||
|
||||
static void ComputeValence( MeshType &m, typename MeshType::PerVertexIntHandle &h)
|
||||
{
|
||||
for(VertexIterator vi=m.vert.begin(); vi!= m.vert.end();++vi)
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ namespace tri {
|
|||
typedef CONTE EdgeContainer;
|
||||
typedef typename CONTE::value_type EdgeType;
|
||||
typedef typename TYPESPOOL::EdgePointer EdgePointer;
|
||||
typedef const typename TYPESPOOL::EdgePointer ConstEdgePointer;
|
||||
typedef typename CONTE::iterator EdgeIterator;
|
||||
typedef typename CONTE::const_iterator ConstEdgeIterator;
|
||||
|
||||
|
|
@ -124,7 +125,8 @@ namespace tri {
|
|||
struct MeshTypeHolder< T, CONT, AllTypes::AEdgeType>: public T{
|
||||
typedef CONT EdgeContainer;
|
||||
typedef typename EdgeContainer::value_type EdgeType;
|
||||
typedef typename EdgeContainer::value_type * EdgePointer;
|
||||
typedef EdgeType * EdgePointer;
|
||||
typedef const EdgeType * ConstEdgePointer;
|
||||
typedef typename EdgeContainer::iterator EdgeIterator;
|
||||
typedef typename EdgeContainer::const_iterator ConstEdgeIterator;
|
||||
};
|
||||
|
|
@ -188,6 +190,7 @@ class TriMesh
|
|||
// types for edge
|
||||
typedef typename TriMesh::EdgeType EdgeType;
|
||||
typedef typename TriMesh::EdgePointer EdgePointer;
|
||||
typedef typename TriMesh::ConstEdgePointer ConstEdgePointer;
|
||||
typedef typename TriMesh::EdgeIterator EdgeIterator;
|
||||
typedef typename TriMesh::ConstEdgeIterator ConstEdgeIterator;
|
||||
|
||||
|
|
@ -489,6 +492,15 @@ template <class MeshType> inline void InitVertexIMark(MeshType & m)
|
|||
if( !(*vi).IsD() && (*vi).IsRW() )
|
||||
(*vi).InitIMark();
|
||||
}
|
||||
/// Initialize the imark-system of the edges
|
||||
template <class MeshType> inline void InitEdgeIMark(MeshType & m)
|
||||
{
|
||||
typename MeshType::EdgeIterator ei;
|
||||
|
||||
for (ei = m.edge.begin(); ei != m.edge.end(); ++ei)
|
||||
if( !(*ei).IsD() && (*ei).IsRW() )
|
||||
(*ei).InitIMark();
|
||||
}
|
||||
|
||||
///initialize the imark-sysyem of the tetras
|
||||
template <class MeshType>
|
||||
|
|
@ -511,6 +523,11 @@ template <class MeshType> inline int & IMark(MeshType & m){return m.imark;}
|
|||
@param v Vertex pointer */
|
||||
template <class MeshType> inline bool IsMarked(MeshType & m, typename MeshType::ConstVertexPointer v ) { return v->cIMark() == m.imark; }
|
||||
|
||||
/** \brief Check if the edge incremental mark matches the one of the mesh.
|
||||
@param m the mesh containing the element
|
||||
@param e edge pointer */
|
||||
template <class MeshType> inline bool IsMarked(MeshType & m, typename MeshType::ConstEdgePointer e ) { return e->cIMark() == m.imark; }
|
||||
|
||||
/** \brief Check if the face incremental mark matches the one of the mesh.
|
||||
@param m the mesh containing the element
|
||||
@param f Face pointer */
|
||||
|
|
@ -527,6 +544,11 @@ inline bool IsMarked(MeshType &m, typename MeshType::ConstTetraPointer t) { retu
|
|||
@param v Vertex pointer */
|
||||
template <class MeshType> inline void Mark(MeshType & m, typename MeshType::VertexPointer v ) { v->IMark() = m.imark; }
|
||||
|
||||
/** \brief Set the edge incremental mark of the edge to the one of the mesh.
|
||||
@param m the mesh containing the element
|
||||
@param e edge pointer */
|
||||
template <class MeshType> inline void Mark(MeshType & m, typename MeshType::EdgePointer e ) { e->IMark() = m.imark; }
|
||||
|
||||
/** \brief Set the face incremental mark of the vertex to the one of the mesh.
|
||||
@param m the mesh containing the element
|
||||
@param f Vertex pointer */
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ public:
|
|||
inline int cIMark() const { assert(0); static int tmp=-1; return tmp;}
|
||||
inline int &IMark() { assert(0); static int tmp=-1; return tmp;}
|
||||
static bool HasMark() { return false; }
|
||||
inline bool IsMarkEnabled( ) const { return T::EdgeType::HasMark(); }
|
||||
|
||||
|
||||
typedef int FlagType;
|
||||
int &Flags() { static int dummyflags(0); assert(0); return dummyflags; }
|
||||
|
|
@ -170,9 +172,15 @@ public:
|
|||
static bool HasMarkOcc() { return true; }
|
||||
inline void InitIMark() { _imark = 0; }
|
||||
inline int & IMark() { return _imark;}
|
||||
inline const int & IMark() const {return _imark;}
|
||||
template < class LeftV>
|
||||
void ImportData(const LeftV & left ) { IMark() = left.IMark(); T::ImportData( left); }
|
||||
inline int cIMark() const { return _imark;}
|
||||
|
||||
template < class RightValueType>
|
||||
void ImportData(const RightValueType & rightE )
|
||||
{
|
||||
if(rightE.IsMarkEnabled())
|
||||
IMark() = rightE.cIMark();
|
||||
T::ImportData(rightE);
|
||||
}
|
||||
static void Name(std::vector<std::string> & name){name.push_back(std::string("Mark"));T::Name(name);}
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Reference in New Issue