2004-03-04 01:53:24 +01: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 $
|
2005-11-10 16:36:42 +01:00
|
|
|
Revision 1.15 2004/10/20 07:33:10 cignoni
|
|
|
|
removed FaceBorderFlags (already present in update/flags.h)
|
|
|
|
|
2004-10-20 09:33:10 +02:00
|
|
|
Revision 1.14 2004/10/18 17:10:22 ganovelli
|
|
|
|
added ::FaceBorderFLags
|
|
|
|
|
2004-10-18 19:10:22 +02:00
|
|
|
Revision 1.13 2004/10/01 15:58:00 ponchio
|
|
|
|
Added include <vector>
|
|
|
|
|
2004-10-01 17:58:00 +02:00
|
|
|
Revision 1.12 2004/09/09 13:02:12 ponchio
|
|
|
|
Linux compatible path in #include
|
|
|
|
|
2004-09-09 15:02:12 +02:00
|
|
|
Revision 1.11 2004/08/07 16:18:20 pietroni
|
|
|
|
addet testFFTopology and testVFTopology functions used to test the rispective topology....
|
|
|
|
|
2004-08-07 18:18:20 +02:00
|
|
|
Revision 1.10 2004/07/15 11:35:08 ganovelli
|
|
|
|
Vfb to VFp
|
|
|
|
|
2004-07-15 13:35:08 +02:00
|
|
|
Revision 1.9 2004/07/15 00:13:39 cignoni
|
|
|
|
Better doxigen documentation
|
|
|
|
|
2004-07-15 02:16:37 +02:00
|
|
|
Revision 1.8 2004/06/02 16:42:44 ganovelli
|
|
|
|
typename for gcc compilation
|
|
|
|
|
2004-06-02 18:42:44 +02:00
|
|
|
Revision 1.7 2004/06/02 16:28:22 ganovelli
|
|
|
|
minor changes (swap =>> math::Swap)
|
|
|
|
|
2004-06-02 18:28:22 +02:00
|
|
|
Revision 1.6 2004/05/10 15:23:43 cignoni
|
|
|
|
Changed a FV -> VF in VertexFace topology computation
|
|
|
|
|
2004-05-10 17:23:43 +02:00
|
|
|
Revision 1.5 2004/05/06 15:24:38 pietroni
|
|
|
|
changed names to topology functions
|
|
|
|
|
2004-05-06 17:24:38 +02:00
|
|
|
Revision 1.4 2004/03/31 14:44:43 cignoni
|
|
|
|
Added Vertex-Face Topology
|
|
|
|
|
2004-03-31 16:44:43 +02:00
|
|
|
Revision 1.3 2004/03/12 15:22:19 cignoni
|
|
|
|
Written some documentation and added to the trimes doxygen module
|
|
|
|
|
2004-03-12 16:22:28 +01:00
|
|
|
Revision 1.2 2004/03/05 21:49:21 cignoni
|
|
|
|
First working version for face face
|
|
|
|
|
2004-03-05 22:49:21 +01:00
|
|
|
Revision 1.1 2004/03/04 00:53:24 cignoni
|
|
|
|
Initial commit
|
|
|
|
|
2004-03-04 01:53:24 +01:00
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __VCG_TRI_UPDATE_TOPOLOGY
|
|
|
|
#define __VCG_TRI_UPDATE_TOPOLOGY
|
2004-03-05 22:49:21 +01:00
|
|
|
#include <algorithm>
|
2004-10-01 17:58:00 +02:00
|
|
|
#include <vector>
|
2004-09-09 15:02:12 +02:00
|
|
|
#include <vcg/simplex/face/pos.h>
|
2004-03-04 01:53:24 +01:00
|
|
|
namespace vcg {
|
|
|
|
namespace tri {
|
2004-03-12 16:22:28 +01:00
|
|
|
/** \addtogroup trimesh */
|
|
|
|
/*@{*/
|
2004-07-15 02:16:37 +02:00
|
|
|
/** Generation of per-vertex and per-face topological information.
|
|
|
|
**/
|
2004-03-04 01:53:24 +01: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;
|
|
|
|
typedef typename MeshType::FaceType FaceType;
|
|
|
|
typedef typename MeshType::FacePointer FacePointer;
|
|
|
|
typedef typename MeshType::FaceIterator FaceIterator;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Auxiliairy data structure for computing face face adjacency information.
|
|
|
|
// It identifies and edge storing two vertex pointer and a face pointer where it belong.
|
|
|
|
class PEdge
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2004-03-05 22:49:21 +01:00
|
|
|
VertexPointer v[2]; // the two Vertex pointer are ordered!
|
|
|
|
FacePointer f; // the face where this edge belong
|
2004-03-04 01:53:24 +01:00
|
|
|
int z; // index in [0..2] of the edge of the face
|
|
|
|
|
|
|
|
PEdge() {}
|
|
|
|
|
2004-03-05 22:49:21 +01:00
|
|
|
void Set( FacePointer pf, const int nz )
|
2004-03-04 01:53:24 +01:00
|
|
|
{
|
|
|
|
assert(pf!=0);
|
|
|
|
assert(nz>=0);
|
|
|
|
assert(nz<3);
|
|
|
|
|
|
|
|
v[0] = pf->V(nz);
|
|
|
|
v[1] = pf->V((nz+1)%3);
|
2005-11-10 16:36:42 +01:00
|
|
|
assert(v[0] != v[1]); // The face pointed by 'f' is Degenerate (two coincident vertexes)
|
2004-03-04 01:53:24 +01:00
|
|
|
|
2004-06-02 18:28:22 +02:00
|
|
|
if( v[0] > v[1] ) math::Swap(v[0],v[1]);
|
2004-03-04 01:53:24 +01:00
|
|
|
f = pf;
|
|
|
|
z = nz;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator < ( const PEdge & pe ) const
|
|
|
|
{
|
|
|
|
if( v[0]<pe.v[0] ) return true;
|
|
|
|
else if( v[0]>pe.v[0] ) return false;
|
|
|
|
else return v[1] < pe.v[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator <= ( const PEdge & pe ) const
|
|
|
|
{
|
|
|
|
if( v[0]<pe.v[0] ) return true;
|
|
|
|
else if( v[0]>pe.v[0] ) return false;
|
|
|
|
else return v[1] <= pe.v[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator > ( const PEdge & pe ) const
|
|
|
|
{
|
|
|
|
if( v[0]>pe.v[0] ) return true;
|
|
|
|
else if( v[0]<pe.v[0] ) return false;
|
|
|
|
else return v[1] > pe.v[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator >= ( const PEdge & pe ) const
|
|
|
|
{
|
|
|
|
if( v[0]>pe.v[0] ) return true;
|
|
|
|
else if( v[0]<pe.v[0] ) return false;
|
|
|
|
else return v[1] >= pe.v[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator == ( const PEdge & pe ) const
|
|
|
|
{
|
|
|
|
return v[0]==pe.v[0] && v[1]==pe.v[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator != ( const PEdge & pe ) const
|
|
|
|
{
|
|
|
|
return v[0]!=pe.v[0] || v[1]!=pe.v[1];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-07-15 02:16:37 +02:00
|
|
|
/** Update the Face-Face topological relation by allowing to retrieve for each face what other faces shares their edges.
|
|
|
|
*/
|
2004-03-05 22:49:21 +01:00
|
|
|
static void FaceFace(MeshType &m)
|
2004-03-04 01:53:24 +01:00
|
|
|
{
|
2004-03-05 22:49:21 +01:00
|
|
|
if(!m.HasFFTopology()) return;
|
2004-03-04 01:53:24 +01:00
|
|
|
|
2004-06-02 18:28:22 +02:00
|
|
|
std::vector<PEdge> e;
|
2004-03-31 16:44:43 +02:00
|
|
|
FaceIterator pf;
|
2004-06-02 18:42:44 +02:00
|
|
|
typename std::vector<PEdge>::iterator p;
|
2004-03-31 16:44:43 +02:00
|
|
|
|
|
|
|
if( m.fn == 0 ) return;
|
|
|
|
|
|
|
|
e.resize(m.fn*3); // Alloco il vettore ausiliario
|
|
|
|
p = e.begin();
|
|
|
|
for(pf=m.face.begin();pf!=m.face.end();++pf) // Lo riempio con i dati delle facce
|
|
|
|
if( ! (*pf).IsD() )
|
|
|
|
for(int j=0;j<3;++j)
|
|
|
|
{
|
|
|
|
(*p).Set(&(*pf),j);
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
assert(p==e.end());
|
|
|
|
sort(e.begin(), e.end()); // Lo ordino per vertici
|
|
|
|
|
|
|
|
int ne = 0; // Numero di edge reali
|
|
|
|
|
2004-06-02 18:42:44 +02:00
|
|
|
typename std::vector<PEdge>::iterator pe,ps;
|
2004-03-31 16:44:43 +02:00
|
|
|
for(ps = e.begin(),pe=e.begin();pe<=e.end();++pe) // Scansione vettore ausiliario
|
|
|
|
{
|
|
|
|
if( pe==e.end() || *pe != *ps ) // Trovo blocco di edge uguali
|
2004-03-04 01:53:24 +01:00
|
|
|
{
|
2004-06-02 18:42:44 +02:00
|
|
|
typename std::vector<PEdge>::iterator q,q_next;
|
2004-03-31 16:44:43 +02:00
|
|
|
for (q=ps;q<pe-1;++q) // Scansione facce associate
|
2004-03-04 01:53:24 +01:00
|
|
|
{
|
|
|
|
assert((*q).z>=0);
|
|
|
|
assert((*q).z< 3);
|
2004-03-31 16:44:43 +02:00
|
|
|
q_next = q;
|
|
|
|
++q_next;
|
|
|
|
assert((*q_next).z>=0);
|
|
|
|
assert((*q_next).z< 3);
|
2004-05-06 17:24:38 +02:00
|
|
|
(*q).f->FFp(q->z) = (*q_next).f; // Collegamento in lista delle facce
|
|
|
|
(*q).f->FFi(q->z) = (*q_next).z;
|
2004-03-04 01:53:24 +01:00
|
|
|
}
|
2004-03-31 16:44:43 +02:00
|
|
|
assert((*q).z>=0);
|
|
|
|
assert((*q).z< 3);
|
2004-05-06 17:24:38 +02:00
|
|
|
(*q).f->FFp((*q).z) = ps->f;
|
|
|
|
(*q).f->FFi((*q).z) = ps->z;
|
2004-03-31 16:44:43 +02:00
|
|
|
ps = pe;
|
|
|
|
++ne; // Aggiorno il numero di edge
|
2004-03-04 01:53:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-18 19:10:22 +02:00
|
|
|
|
2004-07-15 02:16:37 +02:00
|
|
|
/** Update the Vertex-Face topological relation by allowing to retrieve for each vertex the list of faces sharing this vertex..
|
|
|
|
*/
|
2004-03-31 16:44:43 +02:00
|
|
|
static void VertexFace(MeshType &m)
|
|
|
|
{
|
|
|
|
if(!m.HasVFTopology()) return;
|
2004-03-04 01:53:24 +01:00
|
|
|
|
2004-03-31 16:44:43 +02:00
|
|
|
VertexIterator vi;
|
|
|
|
FaceIterator fi;
|
|
|
|
|
|
|
|
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
|
|
|
{
|
2004-07-15 13:35:08 +02:00
|
|
|
(*vi).VFp() = 0;
|
2004-05-06 17:24:38 +02:00
|
|
|
(*vi).VFi() = 0;
|
2004-03-31 16:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
|
|
|
if( ! (*fi).IsD() )
|
|
|
|
{
|
|
|
|
for(int j=0;j<3;++j)
|
|
|
|
{
|
2004-07-15 13:35:08 +02:00
|
|
|
(*fi).VFp(j) = (*fi).V(j)->VFp();
|
2004-05-10 17:23:43 +02:00
|
|
|
(*fi).VFi(j) = (*fi).V(j)->VFi();
|
2004-07-15 13:35:08 +02:00
|
|
|
(*fi).V(j)->VFp() = &(*fi);
|
2004-05-06 17:24:38 +02:00
|
|
|
(*fi).V(j)->VFi() = j;
|
2004-03-31 16:44:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-07 18:18:20 +02:00
|
|
|
|
|
|
|
///test correctness of VFtopology
|
|
|
|
static void TestVertexFace(MeshType &m)
|
|
|
|
{
|
|
|
|
if(!m.HasVFTopology()) return;
|
|
|
|
|
|
|
|
VertexIterator vi;
|
|
|
|
vcg::face::VFIterator<FaceType> VFi;
|
|
|
|
|
|
|
|
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
|
|
|
{
|
|
|
|
if (!vi->IsD())
|
|
|
|
{
|
|
|
|
//the vertex must be linked to one face
|
|
|
|
assert(vi->VFp()!=0);
|
|
|
|
VFi.f=vi->VFp();
|
|
|
|
VFi.z=vi->VFi();
|
|
|
|
while (!VFi.End())
|
|
|
|
{
|
|
|
|
assert(!VFi.F()->IsD());
|
|
|
|
assert((VFi.F()->V(VFi.I()))==&(*vi));
|
|
|
|
VFi++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///test correctness of FFtopology
|
|
|
|
static void TestFaceFace(MeshType &m)
|
|
|
|
{
|
|
|
|
if(!m.HasFFTopology()) return;
|
|
|
|
|
|
|
|
FaceIterator Fi;
|
2004-03-31 16:44:43 +02:00
|
|
|
|
2004-08-07 18:18:20 +02:00
|
|
|
for(Fi=m.face.begin();Fi!=m.face.end();++Fi)
|
|
|
|
{
|
|
|
|
if (!Fi->IsD())
|
|
|
|
{
|
|
|
|
for (int i=0;i<3;i++)
|
|
|
|
{
|
|
|
|
FaceType *f=Fi->FFp(i);
|
|
|
|
int e=Fi->FFi(i);
|
|
|
|
//invariant property of fftopology
|
|
|
|
assert(f->FFp(e)=&(*Fi));
|
|
|
|
//control if the vertex are the same
|
|
|
|
assert(((f->V(e)==Fi->V(i))&&(f->V((e+1)%3)==Fi->V((i+1)%3)))||
|
|
|
|
((f->V(e)==Fi->V((i+1)%3))&&(f->V((e+1)%3)==Fi->V(i))));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-03-04 01:53:24 +01:00
|
|
|
|
|
|
|
}; // end class
|
|
|
|
|
2004-03-12 16:22:28 +01:00
|
|
|
/*@}*/
|
2004-03-04 01:53:24 +01:00
|
|
|
} // End namespace
|
|
|
|
} // End namespace
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|