vcglib/vcg/complex/edgemesh/update/topology.h

197 lines
5.2 KiB
C
Raw Normal View History

2004-04-29 01:33:24 +02:00
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004 \/)\/ *
* 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. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
2004-10-28 02:56:44 +02:00
Revision 1.2 2004/05/10 14:42:17 ganovelli
nimor changes
2004-04-29 01:33:24 +02:00
****************************************************************************/
2004-05-10 16:42:17 +02:00
#ifndef __VCG_EDGE_UPDATE_TOPOLOGY
#define __VCG_EDGE_UPDATE_TOPOLOGY
2004-04-29 01:33:24 +02:00
#include <algorithm>
namespace vcg {
2004-05-10 16:42:17 +02:00
namespace edge {
2004-10-28 02:56:44 +02:00
/** \addtogroup edgemesh */
2004-04-29 01:33:24 +02:00
/*@{*/
template <class UpdateMeshType>
class UpdateTopology
{
public:
typedef UpdateMeshType MeshType;
typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::VertexIterator VertexIterator;
2004-05-10 16:42:17 +02:00
typedef typename MeshType::EdgeType EdgeType;
typedef typename MeshType::EdgePointer EdgePointer;
typedef typename MeshType::EdgeIterator EdgeIterator;
2004-04-29 01:33:24 +02:00
/// Auxiliairy data structure for computing face face adjacency information.
// It identifies and edge storing two vertex pointer and a face pointer where it belong.
2004-05-10 16:42:17 +02:00
class PVertex
2004-04-29 01:33:24 +02:00
{
public:
2004-05-10 16:42:17 +02:00
VertexPointer v; // the two Vertex pointer are ordered!
EdgePointer e; // the edge where this vertex belong
2004-04-29 01:33:24 +02:00
int z; // index in [0..2] of the edge of the face
2004-05-10 16:42:17 +02:00
PVertex() {}
2004-04-29 01:33:24 +02:00
2004-05-10 16:42:17 +02:00
void Set( EdgePointer pe, const int nz )
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
assert(pe!=0);
2004-04-29 01:33:24 +02:00
assert(nz>=0);
2004-05-10 16:42:17 +02:00
assert(nz<2);
2004-04-29 01:33:24 +02:00
2004-05-10 16:42:17 +02:00
v= pe->V(nz);
e = pe;
2004-04-29 01:33:24 +02:00
z = nz;
}
2004-05-10 16:42:17 +02:00
inline bool operator < ( const PVertex & pe ) const
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
return ( v<pe.v );
2004-04-29 01:33:24 +02:00
}
2004-05-10 16:42:17 +02:00
inline bool operator <= ( const PVertex & pe ) const
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
return ( v<=pe.v );
2004-04-29 01:33:24 +02:00
}
2004-05-10 16:42:17 +02:00
inline bool operator > ( const PVertex & pe ) const
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
return ( v>pe.v );
2004-04-29 01:33:24 +02:00
}
2004-05-10 16:42:17 +02:00
inline bool operator >= ( const PVertex & pe ) const
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
return( v>pe.v );
2004-04-29 01:33:24 +02:00
}
2004-05-10 16:42:17 +02:00
inline bool operator == ( const PVertex & pe ) const
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
return (v==pe.v);
2004-04-29 01:33:24 +02:00
}
2004-05-10 16:42:17 +02:00
inline bool operator != ( const PVertex & pe ) const
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
return (v!=pe.v || v!=pe.v);
2004-04-29 01:33:24 +02:00
}
};
2004-05-10 16:42:17 +02:00
static void EdgeEdge(MeshType &m)
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
if(!m.HasEETopology()) return;
2004-04-29 01:33:24 +02:00
2004-05-10 16:42:17 +02:00
vector<PVertex> v;
EdgeIterator pf;
vector<PVertex>::iterator p;
2004-04-29 01:33:24 +02:00
2004-05-10 16:42:17 +02:00
if( m.en == 0 ) return;
2004-04-29 01:33:24 +02:00
2004-05-10 16:42:17 +02:00
v.resize(m.en*2); // Alloco il vettore ausiliario
p = v.begin();
for(pf=m.edges.begin();pf!=m.edges.end();++pf) // Lo riempio con i dati delle facce
2004-04-29 01:33:24 +02:00
if( ! (*pf).IsD() )
2004-05-10 16:42:17 +02:00
for(int j=0;j<2;++j)
2004-04-29 01:33:24 +02:00
{
(*p).Set(&(*pf),j);
++p;
}
2004-05-10 16:42:17 +02:00
assert(p==v.end());
sort(v.begin(), v.end()); // Lo ordino per vertici
2004-04-29 01:33:24 +02:00
int ne = 0; // Numero di edge reali
2004-05-10 16:42:17 +02:00
vector<PVertex>::iterator pe,ps;
for(ps = v.begin(),pe=v.begin();pe<=v.end();++pe) // Scansione vettore ausiliario
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
if( pe==v.end() || *pe != *ps ) // Trovo blocco di edge uguali
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
vector<PVertex>::iterator q,q_next;
for (q=ps;q<pe-1;++q) // Scansione edge associati
2004-04-29 01:33:24 +02:00
{
assert((*q).z>=0);
2004-05-10 16:42:17 +02:00
assert((*q).z< 2);
2004-04-29 01:33:24 +02:00
q_next = q;
++q_next;
assert((*q_next).z>=0);
2004-05-10 16:42:17 +02:00
assert((*q_next).z< 2);
(*q).e->EEp(q->z) = (*q_next).e; // Collegamento in lista delle facce
(*q).e->EEi(q->z) = (*q_next).z;
2004-04-29 01:33:24 +02:00
}
assert((*q).z>=0);
assert((*q).z< 3);
2004-05-10 16:42:17 +02:00
(*q).e->EEp((*q).z) = ps->e;
(*q).e->EEi((*q).z) = ps->z;
2004-04-29 01:33:24 +02:00
ps = pe;
++ne; // Aggiorno il numero di edge
}
}
}
2004-05-10 16:42:17 +02:00
static void VertexEdge(MeshType &m)
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
if(!m.HasVETopology()) return;
2004-04-29 01:33:24 +02:00
VertexIterator vi;
2004-05-10 16:42:17 +02:00
EdgeIterator ei;
2004-04-29 01:33:24 +02:00
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
{
2004-05-10 16:42:17 +02:00
(*vi).Ep() = 0;
(*vi).Ei() = 0;
2004-04-29 01:33:24 +02:00
}
2004-05-10 16:42:17 +02:00
for(ei=m.edges.begin();ei!=m.edges.end();++ei)
if( ! (*ei).IsD() )
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
for(int j=0;j<2;++j)
2004-04-29 01:33:24 +02:00
{
2004-05-10 16:42:17 +02:00
(*ei).Ev(j) = (*ei).V(j)->Ep();
(*ei).Zv(j) = (*ei).V(j)->Ei();
(*ei).V(j)->Ep() = &(*fi);
(*ei).V(j)->Ei() = j;
2004-04-29 01:33:24 +02:00
}
}
}
}; // end class
/*@}*/
} // End namespace
} // End namespace
#endif