2004-03-10 01:50:41 +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
|
|
|
|
|
2004-03-18 17:00:10 +01:00
|
|
|
$Log: not supported by cvs2svn $
|
2004-08-06 03:47:57 +02:00
|
|
|
Revision 1.12 2004/08/05 22:27:00 pietroni
|
|
|
|
added VFAppend funtion
|
|
|
|
|
2004-08-06 00:27:00 +02:00
|
|
|
Revision 1.10 2004/07/27 09:49:23 cignoni
|
|
|
|
Removed warning about postfix incremnet of VFIterator
|
|
|
|
|
|
|
|
Revision 1.9 2004/07/15 12:03:07 ganovelli
|
|
|
|
minor changes
|
|
|
|
|
|
|
|
Revision 1.8 2004/07/15 11:26:48 ganovelli
|
|
|
|
VFDetach corrected
|
|
|
|
|
|
|
|
Revision 1.7 2004/05/12 12:23:23 cignoni
|
|
|
|
Conformed C++ syntax to GCC requirements
|
|
|
|
|
2004-05-12 14:23:23 +02:00
|
|
|
Revision 1.6 2004/05/11 16:03:18 ganovelli
|
|
|
|
changed from "thi" to "&f" in Vfdetach
|
|
|
|
|
2004-05-11 18:03:18 +02:00
|
|
|
Revision 1.5 2004/05/10 15:20:49 cignoni
|
|
|
|
Updated names of POS and adj functions to the new standards for many functions
|
|
|
|
|
2004-05-10 17:20:49 +02:00
|
|
|
Revision 1.4 2004/03/18 16:00:10 cignoni
|
|
|
|
minor changes
|
|
|
|
|
2004-03-10 01:50:41 +01:00
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _VCG_FACE_TOPOLOGY
|
|
|
|
#define _VCG_FACE_TOPOLOGY
|
2004-05-10 17:20:49 +02:00
|
|
|
#include <vcg/simplex/face/pos.h>
|
2004-03-10 01:50:41 +01:00
|
|
|
namespace vcg {
|
2004-03-11 10:02:35 +01:00
|
|
|
namespace face {
|
|
|
|
/** \addtogroup face */
|
|
|
|
/*@{*/
|
2004-03-08 06:25:48 +01:00
|
|
|
|
|
|
|
/** Return a boolean that indicate if the face is complex.
|
|
|
|
@param j Index of the edge
|
|
|
|
@return true se la faccia e' manifold, false altrimenti
|
|
|
|
*/
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class FaceType>
|
|
|
|
inline bool IsManifold( FaceType const & f, const int j )
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-03-10 01:50:41 +01:00
|
|
|
if(FaceType::HasFFAdjacency())
|
2004-05-10 17:20:49 +02:00
|
|
|
return ( f.FFp(j) == &f || &f == f.FFp(j)->FFp(f.FFi(j)) );
|
2004-03-10 01:50:41 +01:00
|
|
|
else
|
|
|
|
return true;
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Return a boolean that indicate if the j-th edge of the face is a border.
|
|
|
|
@param j Index of the edge
|
|
|
|
@return true if j is an edge of border, false otherwise
|
|
|
|
*/
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class FaceType>
|
|
|
|
inline bool IsBorder(FaceType const & f, const int j )
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-03-10 01:50:41 +01:00
|
|
|
if(FaceType::HasFFAdjacency())
|
2004-05-10 17:20:49 +02:00
|
|
|
return f.FFp(j) == &f ;
|
2004-03-10 01:50:41 +01:00
|
|
|
else
|
|
|
|
return true;
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-18 17:00:10 +01:00
|
|
|
/// Count border edges of the face
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class FaceType>
|
|
|
|
inline int BorderCount(FaceType const & f)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-03-10 01:50:41 +01:00
|
|
|
if(FaceType::HasFFAdjacency())
|
|
|
|
{
|
|
|
|
int t = 0;
|
|
|
|
if( f.IsBorder(0) ) ++t;
|
|
|
|
if( f.IsBorder(1) ) ++t;
|
|
|
|
if( f.IsBorder(2) ) ++t;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
else return 3;
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-18 17:00:10 +01:00
|
|
|
/// Counts the number of incident faces in a complex edge
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class FaceType>
|
|
|
|
inline int ComplexSize(FaceType const & f, const int e)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-03-10 01:50:41 +01:00
|
|
|
if(FaceType::HasFFAdjacency())
|
|
|
|
{
|
2004-05-10 17:20:49 +02:00
|
|
|
Pos< FaceType > fpos(&f,e);
|
2004-03-10 01:50:41 +01:00
|
|
|
int cnt=0;
|
2004-05-10 17:20:49 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
fpos.NextF();
|
2004-03-08 06:25:48 +01:00
|
|
|
++cnt;
|
|
|
|
}
|
2004-05-10 17:20:49 +02:00
|
|
|
while(fpos.f=&f);
|
2004-03-08 06:25:48 +01:00
|
|
|
return cnt;
|
2004-03-10 01:50:41 +01:00
|
|
|
}
|
|
|
|
assert(0);
|
2004-03-08 06:25:48 +01:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Funzione di detach che scollega una faccia da un ciclo
|
|
|
|
(eventualmente costituito da due soli elementi) incidente su un edge*/
|
|
|
|
/** This function detach the face from the adjacent face via the edge e. It's possible to use it also in non-two manifold situation.
|
|
|
|
The function cannot be applicated if the adjacencies among faces aren't define.
|
|
|
|
@param e Index of the edge
|
|
|
|
*/
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class FaceType>
|
|
|
|
void Detach(FaceType & f, const int e)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
|
|
|
assert(!IsBorder(e));
|
2004-05-10 17:20:49 +02:00
|
|
|
Pos< FaceType > EPB(&f,e); // la faccia dall'altra parte
|
2004-03-08 06:25:48 +01:00
|
|
|
EPB.NextF();
|
|
|
|
int cnt=0;
|
2004-05-10 17:20:49 +02:00
|
|
|
while ( EPB.f->FFp(EPB.z) != &f)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
|
|
|
assert(!IsManifold(e)); // Si entra in questo loop solo se siamo in una situazione non manifold.
|
|
|
|
assert(!EPB.f->IsBorder(EPB.z));
|
|
|
|
EPB.NextF();
|
|
|
|
cnt++;
|
|
|
|
}
|
2004-05-10 17:20:49 +02:00
|
|
|
assert(EPB.f->FFp(EPB.z)==&f);
|
2004-03-08 06:25:48 +01:00
|
|
|
|
2004-05-10 17:20:49 +02:00
|
|
|
EPB.f->FFp(EPB.z) = F(e);
|
|
|
|
EPB.f->FFi(EPB.z) = Z(e);
|
2004-03-08 06:25:48 +01:00
|
|
|
|
2004-05-10 17:20:49 +02:00
|
|
|
F(e) = &f;
|
2004-03-08 06:25:48 +01:00
|
|
|
Z(e) = e;
|
|
|
|
|
|
|
|
EPB.f->SetM();
|
2004-05-10 17:20:49 +02:00
|
|
|
f.SetM();
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** This function attach the face (via the edge z1) to another face (via the edge z2). It's possible to use it also in non-two manifold situation.
|
|
|
|
The function cannot be applicated if the adjacencies among faces aren't define.
|
|
|
|
@param z1 Index of the edge
|
|
|
|
@param f2 Pointer to the face
|
|
|
|
@param z2 The edge of the face f2
|
|
|
|
*/
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class FaceType>
|
2004-05-10 17:20:49 +02:00
|
|
|
void Attach(FaceType * &f, int z1, FaceType *&f2, int z2)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-05-10 17:20:49 +02:00
|
|
|
//typedef FEdgePosB< FACE_TYPE > ETYPE;
|
|
|
|
Pos< FaceType > EPB(f2,z2);
|
|
|
|
Pos< FaceType > TEPB;
|
2004-03-08 06:25:48 +01:00
|
|
|
TEPB = EPB;
|
|
|
|
EPB.NextF();
|
|
|
|
while( EPB.f != f2) //Alla fine del ciclo TEPB contiene la faccia che precede f2
|
|
|
|
{
|
|
|
|
TEPB = EPB;
|
|
|
|
EPB.NextF();
|
|
|
|
}
|
|
|
|
//Salvo i dati di f1 prima di sovrascrivere
|
2004-08-06 00:27:00 +02:00
|
|
|
FaceType *f1prec = f.FFp(z1);
|
|
|
|
int z1prec = f.FFi(z1);
|
2004-03-08 06:25:48 +01:00
|
|
|
//Aggiorno f1
|
2004-05-10 17:20:49 +02:00
|
|
|
f->FFp(z1) = TEPB.f->FFp(TEPB.z);
|
|
|
|
f->FFi(z1) = TEPB.f->FFi(TEPB.z);
|
2004-03-08 06:25:48 +01:00
|
|
|
//Aggiorno la faccia che precede f2
|
2004-05-10 17:20:49 +02:00
|
|
|
TEPB.f->FFp(TEPB.z) = f1prec;
|
|
|
|
TEPB.f->FFi(TEPB.z) = z1prec;
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class FaceType>
|
2004-05-10 17:20:49 +02:00
|
|
|
void AssertAdj(FaceType & f)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-05-10 17:20:49 +02:00
|
|
|
assert(f.FFp(0)->FFp(f.FFi(0))==&f);
|
|
|
|
assert(f.FFp(1)->FFp(f.FFi(1))==&f);
|
|
|
|
assert(f.FFp(2)->FFp(f.FFi(2))==&f);
|
2004-03-08 06:25:48 +01:00
|
|
|
|
2004-05-10 17:20:49 +02:00
|
|
|
assert(f.FFp(0)->FFi(f.FFi(0))==0);
|
|
|
|
assert(f.FFp(1)->FFi(f.FFi(1))==1);
|
|
|
|
assert(f.FFp(2)->FFi(f.FFi(2))==2);
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
2004-03-10 01:50:41 +01:00
|
|
|
// Funzione di supporto usata da swap?
|
|
|
|
//template <class FaceType>
|
|
|
|
//inline void Nexts( *&f, int &z )
|
|
|
|
//{
|
|
|
|
// int t;
|
|
|
|
// t = z;
|
|
|
|
// z = (*f).Z(z);
|
|
|
|
// f = (*f).F(t);
|
|
|
|
//}
|
2004-03-08 06:25:48 +01:00
|
|
|
|
|
|
|
/** This function change the orientation of the face. Inverting the index of two vertex
|
|
|
|
@param z Index of the edge
|
|
|
|
*/
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class SwapFaceType>
|
|
|
|
void Swap (SwapFaceType &f, const int z )
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
|
|
|
int i;
|
2004-05-10 17:20:49 +02:00
|
|
|
SwapFaceType *tmp, *prec;
|
2004-03-08 06:25:48 +01:00
|
|
|
int t, precz;
|
|
|
|
|
2004-03-10 01:50:41 +01:00
|
|
|
swap ( f.V((z )%3),f.V((z+1)%3));
|
2004-03-08 06:25:48 +01:00
|
|
|
|
2004-03-10 01:50:41 +01:00
|
|
|
if(f.HasFFAdjacency() )
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-05-10 17:20:49 +02:00
|
|
|
// TODO!!!
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Stacca la faccia corrente dalla catena di facce incidenti sul vertice z,
|
|
|
|
// NOTA funziona SOLO per la topologia VF!!!
|
|
|
|
// usata nelle classi di collapse
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class FaceType>
|
2004-08-06 00:27:00 +02:00
|
|
|
void VFDetach(FaceType & f, int z)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-08-06 00:27:00 +02:00
|
|
|
if(f.V(z)->VFp()==&f ) //if it is the first face detach from the begin
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-08-06 00:27:00 +02:00
|
|
|
int fz = f.V(z)->VFi();
|
|
|
|
f.V(z)->VFp() = f.VFp(fz);
|
|
|
|
f.V(z)->VFi() = f.VFi(fz);
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
2004-08-06 00:27:00 +02:00
|
|
|
else // scan the list of faces in order to finde the current face f to be detached
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-08-06 00:27:00 +02:00
|
|
|
VFIterator<FaceType> x(f.V(z)->VFp(),f.V(z)->VFi());
|
|
|
|
VFIterator<FaceType> y;
|
|
|
|
|
|
|
|
for(;;)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-08-06 00:27:00 +02:00
|
|
|
y = x;
|
|
|
|
++x;
|
|
|
|
assert(x.f!=0);
|
|
|
|
if(x.f==&f) // found!
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2004-08-06 00:27:00 +02:00
|
|
|
y.f->VFp(y.z) = f.VFp(z);
|
|
|
|
y.f->VFi(y.z) = f.VFi(z);
|
2004-03-08 06:25:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-04 22:50:12 +02:00
|
|
|
/// Append a face in VF list of vertex f->V(z)
|
|
|
|
template <class FaceType>
|
|
|
|
void VFAppend(FaceType* & f, int z)
|
|
|
|
{
|
|
|
|
FaceType::VertexType *v=f->V(z);
|
2004-08-06 03:47:57 +02:00
|
|
|
if (v->VFp()!=0)
|
|
|
|
{
|
|
|
|
FaceType *f0=v->VFp();
|
|
|
|
int z0=v->VFi();
|
|
|
|
//append
|
|
|
|
f->VFp(z)=f0;
|
|
|
|
f->VFi(z)=z0;
|
|
|
|
}
|
2004-08-04 22:50:12 +02:00
|
|
|
v->VFp()=f;
|
|
|
|
v->VFi()=z;
|
|
|
|
}
|
|
|
|
|
2004-03-11 10:02:35 +01:00
|
|
|
/*@}*/
|
2004-03-08 06:25:48 +01:00
|
|
|
} // end namespace
|
2004-03-10 01:50:41 +01:00
|
|
|
} // end namespace
|
2004-03-08 06:25:48 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|