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 $
|
2007-05-16 17:12:40 +02:00
|
|
|
Revision 1.29 2006/12/06 00:08:21 cignoni
|
|
|
|
Removed Oldstyle uberZ access to FF adjacency
|
|
|
|
|
2006-12-06 01:08:21 +01:00
|
|
|
Revision 1.28 2006/11/09 17:28:42 cignoni
|
|
|
|
Corrected Detach; added FFCorrectness; Corrected ComplexSize, Dissemination of a lot of assert()
|
|
|
|
|
2006-11-09 18:28:42 +01:00
|
|
|
Revision 1.27 2006/05/03 21:38:57 cignoni
|
|
|
|
Added possibility of not updating the topology during a SwapEdge
|
|
|
|
|
2006-05-03 23:38:57 +02:00
|
|
|
Revision 1.26 2005/12/19 13:47:26 corsini
|
|
|
|
Rewrite SwapEdge to fix problems with borders
|
|
|
|
|
2005-12-19 14:47:26 +01:00
|
|
|
Revision 1.25 2005/12/16 11:01:26 corsini
|
|
|
|
Remove trivial warnings
|
|
|
|
|
2005-12-16 12:01:26 +01:00
|
|
|
Revision 1.24 2005/12/16 10:47:48 corsini
|
|
|
|
Add further comment to FlipEdge
|
|
|
|
|
2005-12-16 11:47:48 +01:00
|
|
|
Revision 1.23 2005/12/16 10:43:23 corsini
|
|
|
|
Fix one bug
|
|
|
|
|
2005-12-16 11:43:23 +01:00
|
|
|
Revision 1.22 2005/12/16 10:29:10 corsini
|
|
|
|
Add CheckOrientation
|
|
|
|
Reimplement SwapEdge function
|
|
|
|
|
2005-12-16 11:29:10 +01:00
|
|
|
Revision 1.21 2005/12/01 23:54:59 cignoni
|
|
|
|
Removed excess ';' from end of template functions, for gcc compiling
|
|
|
|
|
2005-12-02 00:54:59 +01:00
|
|
|
Revision 1.20 2005/11/23 13:04:26 ganovelli
|
|
|
|
changed IsBOrder
|
|
|
|
|
2005-11-23 14:04:26 +01:00
|
|
|
Revision 1.19 2005/11/10 15:49:32 cignoni
|
|
|
|
Made IsManifold Constant
|
|
|
|
|
2005-11-10 16:49:32 +01:00
|
|
|
Revision 1.18 2005/10/13 08:34:19 cignoni
|
|
|
|
Removed reference to IsBorder() member of face and substituted with the face templated function version.
|
|
|
|
|
2005-10-13 10:34:19 +02:00
|
|
|
Revision 1.17 2005/04/11 09:17:24 pietroni
|
|
|
|
Changed detach to FFdetach , compiled tested in manifold cases
|
|
|
|
|
2005-04-11 11:17:24 +02:00
|
|
|
Revision 1.16 2005/03/18 16:35:53 fiorin
|
|
|
|
minor changes to comply gcc compiler
|
|
|
|
|
2005-03-18 17:35:53 +01:00
|
|
|
Revision 1.15 2004/10/22 13:41:06 fiorin
|
|
|
|
Added CheckFlipEdge and FlipEdge
|
|
|
|
|
2004-10-22 15:41:06 +02:00
|
|
|
Revision 1.14 2004/10/18 17:15:45 ganovelli
|
|
|
|
minor change
|
|
|
|
|
2004-10-18 19:15:45 +02:00
|
|
|
Revision 1.13 2004/08/06 01:47:57 pietroni
|
|
|
|
corrected errors on vfappend
|
|
|
|
|
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
|
|
|
{
|
2006-11-09 18:28:42 +01:00
|
|
|
assert(f.cFFp(j) != 0); // never try to use this on uncomputed topology
|
2004-03-10 01:50:41 +01:00
|
|
|
if(FaceType::HasFFAdjacency())
|
2005-11-10 16:49:32 +01:00
|
|
|
return ( f.cFFp(j) == &f || &f == f.cFFp(j)->cFFp(f.cFFi(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())
|
2005-10-13 10:34:19 +02:00
|
|
|
return f.cFFp(j)==&f;
|
|
|
|
//return f.IsBorder(j);
|
|
|
|
|
|
|
|
assert(0);
|
|
|
|
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;
|
2005-10-13 10:34:19 +02:00
|
|
|
if( IsBorder(f,0) ) ++t;
|
|
|
|
if( IsBorder(f,1) ) ++t;
|
|
|
|
if( IsBorder(f,2) ) ++t;
|
2004-03-10 01:50:41 +01:00
|
|
|
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>
|
2006-11-09 18:28:42 +01:00
|
|
|
inline int ComplexSize(FaceType & f, const int e)
|
2004-03-10 01:50:41 +01:00
|
|
|
{
|
2006-11-09 18:28:42 +01:00
|
|
|
if(FaceType::HasFFAdjacency())
|
2004-05-10 17:20:49 +02:00
|
|
|
{
|
2006-11-09 18:28:42 +01:00
|
|
|
if(face::IsBorder<FaceType>(f,e)) return 1;
|
|
|
|
if(face::IsManifold<FaceType>(f,e)) return 2;
|
|
|
|
|
|
|
|
// Non manifold case
|
|
|
|
Pos< FaceType > fpos(&f,e);
|
|
|
|
int cnt=0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
fpos.NextF();
|
|
|
|
assert(!fpos.IsBorder());
|
|
|
|
assert(!fpos.IsManifold());
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
while(fpos.f!=&f);
|
|
|
|
assert (cnt>2);
|
|
|
|
return cnt;
|
|
|
|
}
|
2004-03-10 01:50:41 +01:00
|
|
|
assert(0);
|
2004-03-08 06:25:48 +01:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2006-11-09 18:28:42 +01:00
|
|
|
|
|
|
|
/** This function check the FF topology correctness for an edge of a face.
|
|
|
|
It's possible to use it also in non-two manifold situation.
|
|
|
|
The function cannot be applicated if the adjacencies among faces aren't defined.
|
|
|
|
@param f the face to be checked
|
|
|
|
@param e Index of the edge to be checked
|
2004-03-08 06:25:48 +01:00
|
|
|
*/
|
2006-11-09 18:28:42 +01:00
|
|
|
template <class FaceType>
|
|
|
|
bool FFCorrectness(FaceType & f, const int e)
|
|
|
|
{
|
|
|
|
if(f.FFp(e)==0) return false; // Not computed or inconsistent topology
|
|
|
|
|
|
|
|
if(f.FFp(e)==&f) // Border
|
|
|
|
{
|
|
|
|
if(f.FFi(e)==e) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(f.FFp(e)->FFp(f.FFi(e))==&f) // plain two manifold
|
|
|
|
{
|
|
|
|
if(f.FFp(e)->FFi(f.FFi(e))==e) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Non Manifold Case
|
|
|
|
// all the faces must be connected in a loop.
|
|
|
|
|
|
|
|
Pos< FaceType > curFace(&f,e); // Build the half edge
|
|
|
|
int cnt=0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(curFace.IsManifold()) return false;
|
|
|
|
if(curFace.IsBorder()) return false;
|
|
|
|
curFace.NextF();
|
|
|
|
cnt++;
|
|
|
|
assert(cnt<100);
|
|
|
|
}
|
|
|
|
while ( curFace.f != &f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 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 defined.
|
|
|
|
@param f the face to be detached
|
|
|
|
@param e Index of the edge to be detached
|
|
|
|
*/
|
|
|
|
|
2004-03-10 01:50:41 +01:00
|
|
|
template <class FaceType>
|
2005-04-11 11:17:24 +02:00
|
|
|
void FFDetach(FaceType & f, const int e)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2006-11-09 18:28:42 +01:00
|
|
|
assert(FFCorrectness(f,e));
|
|
|
|
assert(!IsBorder<FaceType>(f,e)); // Never try to detach a border edge!
|
|
|
|
int complexity;
|
|
|
|
assert(complexity=ComplexSize(f,e));
|
|
|
|
|
|
|
|
Pos< FaceType > FirstFace(&f,e); // Build the half edge
|
|
|
|
Pos< FaceType > LastFace(&f,e); // Build the half edge
|
|
|
|
FirstFace.NextF();
|
|
|
|
LastFace.NextF();
|
2004-03-08 06:25:48 +01:00
|
|
|
int cnt=0;
|
2006-11-09 18:28:42 +01:00
|
|
|
|
|
|
|
///then in case of non manifold face continue to advance LastFace
|
|
|
|
// until I find it become the one that
|
|
|
|
///preceed the face I want to erase
|
2005-04-11 11:17:24 +02:00
|
|
|
|
2006-11-09 18:28:42 +01:00
|
|
|
while ( LastFace.f->FFp(LastFace.z) != &f)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2006-11-09 18:28:42 +01:00
|
|
|
assert(ComplexSize(*LastFace.f,LastFace.z)==complexity);
|
|
|
|
assert(!LastFace.IsManifold()); // We enter in this loop only if we are on a non manifold edge
|
|
|
|
assert(!LastFace.IsBorder());
|
|
|
|
LastFace.NextF();
|
2004-03-08 06:25:48 +01:00
|
|
|
cnt++;
|
2006-11-09 18:28:42 +01:00
|
|
|
assert(cnt<100);
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
2005-04-11 11:17:24 +02:00
|
|
|
|
2006-11-09 18:28:42 +01:00
|
|
|
assert(LastFace.f->FFp(LastFace.z)==&f);
|
|
|
|
assert(f.FFp(e)== FirstFace.f);
|
2004-03-08 06:25:48 +01:00
|
|
|
|
2006-11-09 18:28:42 +01:00
|
|
|
// Now we link the last one to the first one, skipping the face to be detached;
|
|
|
|
LastFace.f->FFp(LastFace.z) = FirstFace.f;
|
|
|
|
LastFace.f->FFi(LastFace.z) = FirstFace.z;
|
|
|
|
assert(ComplexSize(*LastFace.f,LastFace.z)==complexity-1);
|
|
|
|
|
|
|
|
// At the end selfconnect the chosen edge to make a border.
|
|
|
|
f.FFp(e) = &f;
|
2005-04-11 11:17:24 +02:00
|
|
|
f.FFi(e) = e;
|
2006-11-09 18:28:42 +01:00
|
|
|
assert(ComplexSize(f,e)==1);
|
2004-03-08 06:25:48 +01:00
|
|
|
|
2006-11-09 18:28:42 +01:00
|
|
|
assert(FFCorrectness(*LastFace.f,LastFace.z));
|
|
|
|
assert(FFCorrectness(f,e));
|
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
|
|
|
|
2005-12-16 11:29:10 +01:00
|
|
|
/**
|
|
|
|
* Check if the given face is oriented as the one adjacent to the specified edge.
|
|
|
|
* @param f Face to check the orientation
|
|
|
|
* @param z Index of the edge
|
|
|
|
*/
|
|
|
|
template <class FaceType>
|
|
|
|
bool CheckOrientation(FaceType &f, int z)
|
2004-03-08 06:25:48 +01:00
|
|
|
{
|
2005-12-16 11:29:10 +01:00
|
|
|
if (IsBorder(f, z))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FaceType *g = f.FFp(z);
|
|
|
|
int gi = f.FFi(z);
|
|
|
|
if (f.V0(z) == g->V1(gi))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2004-03-08 06:25:48 +01:00
|
|
|
|
2005-12-16 11:29:10 +01:00
|
|
|
/**
|
|
|
|
* This function change the orientation of the face by inverting the index of two vertex.
|
|
|
|
* @param z Index of the edge
|
|
|
|
*/
|
|
|
|
template <class FaceType>
|
2006-05-03 23:38:57 +02:00
|
|
|
void SwapEdge(FaceType &f, const int z) { SwapEdge<FaceType,true>(f,z); }
|
|
|
|
|
|
|
|
template <class FaceType, bool UpdateTopology>
|
2005-12-16 11:29:10 +01:00
|
|
|
void SwapEdge(FaceType &f, const int z)
|
|
|
|
{
|
2005-12-19 14:47:26 +01:00
|
|
|
// swap V0(z) with V1(z)
|
2007-05-16 17:12:40 +02:00
|
|
|
std::swap(f.V0(z), f.V1(z));
|
2005-12-16 11:29:10 +01:00
|
|
|
|
2006-05-03 23:38:57 +02:00
|
|
|
if(f.HasFFAdjacency() && UpdateTopology)
|
2005-12-16 11:29:10 +01:00
|
|
|
{
|
2005-12-19 14:47:26 +01:00
|
|
|
// store information to preserve topology
|
|
|
|
int z1 = (z+1)%3;
|
|
|
|
int z2 = (z+2)%3;
|
|
|
|
FaceType *g1p = f.FFp(z1);
|
|
|
|
FaceType *g2p = f.FFp(z2);
|
|
|
|
int g1i = f.FFi(z1);
|
|
|
|
int g2i = f.FFi(z2);
|
|
|
|
|
2005-12-16 11:29:10 +01:00
|
|
|
// g0 face topology is not affected by the swap
|
2004-03-08 06:25:48 +01:00
|
|
|
|
2005-12-16 11:43:23 +01:00
|
|
|
if (g1p != &f)
|
2005-12-19 14:47:26 +01:00
|
|
|
{
|
|
|
|
g1p->FFi(g1i) = z2;
|
|
|
|
f.FFi(z2) = g1i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.FFi(z2) = z2;
|
|
|
|
}
|
2005-12-16 11:29:10 +01:00
|
|
|
|
2005-12-16 11:43:23 +01:00
|
|
|
if (g2p != &f)
|
2005-12-19 14:47:26 +01:00
|
|
|
{
|
|
|
|
g2p->FFi(g2i) = z1;
|
|
|
|
f.FFi(z1) = g2i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.FFi(z1) = z1;
|
|
|
|
}
|
2005-12-16 11:29:10 +01:00
|
|
|
|
|
|
|
// finalize swap
|
2005-12-19 14:47:26 +01:00
|
|
|
f.FFp(z1) = g2p;
|
|
|
|
f.FFp(z2) = g1p;
|
2005-12-16 11:29:10 +01:00
|
|
|
}
|
2004-03-08 06:25:48 +01:00
|
|
|
}
|
|
|
|
|
2004-10-22 15:41:06 +02:00
|
|
|
/*!
|
|
|
|
* Check if the z-th edge of the face f can be flipped.
|
|
|
|
* \param f pointer to the face
|
|
|
|
* \param z the edge index
|
|
|
|
*/
|
|
|
|
template <class FaceType>
|
|
|
|
static bool CheckFlipEdge(FaceType &f, int z)
|
|
|
|
{
|
|
|
|
if (z<0 || z>2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// boundary edges cannot be flipped
|
|
|
|
if (face::IsBorder(f, z))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
FaceType *g = f.FFp(z);
|
|
|
|
int w = f.FFi(z);
|
|
|
|
|
|
|
|
// check if the vertices of the edge are the same
|
|
|
|
if (g->V(w)!=f.V1(z) || g->V1(w)!=f.V(z) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// check if the flipped edge is already present in the mesh
|
|
|
|
typedef typename FaceType::VertexType VertexType;
|
|
|
|
VertexType *f_v2 = f.V2(z);
|
|
|
|
VertexType *g_v2 = g->V2(w);
|
|
|
|
if (f_v2 == g_v2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
vcg::face::Pos< FaceType > pos(&f, (z+2)%3, f.V2(z));
|
|
|
|
do
|
|
|
|
{
|
|
|
|
pos.NextE();
|
|
|
|
if (g_v2==pos.f->V1(pos.z))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
while (&f!=pos.f);
|
|
|
|
|
|
|
|
return true;
|
2005-12-02 00:54:59 +01:00
|
|
|
}
|
2004-10-22 15:41:06 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Flip the z-th edge of the face f.
|
|
|
|
* Check for topological correctness first using <CODE>CheckFlipFace()</CODE>.
|
|
|
|
* \param f pointer to the face
|
|
|
|
* \param z the edge index
|
2005-12-16 11:47:48 +01:00
|
|
|
*
|
|
|
|
* Note: For <em>edge flip</em> we intend the swap of the diagonal of the rectangle
|
|
|
|
* formed by the face \a f and the face adjacent to the specified edge.
|
2004-10-22 15:41:06 +02:00
|
|
|
*/
|
|
|
|
template <class FaceType>
|
|
|
|
static void FlipEdge(FaceType &f, const int z)
|
|
|
|
{
|
|
|
|
assert(z>=0);
|
|
|
|
assert(z<3);
|
2005-11-23 14:04:26 +01:00
|
|
|
assert( !IsBorder(f,z) );
|
2004-10-22 15:41:06 +02:00
|
|
|
assert( face::IsManifold<FaceType>(f, z));
|
|
|
|
|
|
|
|
FaceType *g = f.FFp(z);
|
|
|
|
int w = f.FFi(z);
|
|
|
|
|
|
|
|
assert( g->V(w) == f.V1(z) );
|
|
|
|
assert( g->V1(w)== f.V(z) );
|
|
|
|
assert( g->V2(w)!= f.V(z) );
|
|
|
|
assert( g->V2(w)!= f.V1(z) );
|
|
|
|
assert( g->V2(w)!= f.V2(z) );
|
|
|
|
|
|
|
|
f.V1(z) = g->V2(w);
|
|
|
|
g->V1(w) = f.V2(z);
|
|
|
|
|
|
|
|
f.FFp(z) = g->FFp1(w);
|
|
|
|
f.FFi(z) = g->FFi((w+1)%3);
|
|
|
|
g->FFp(w) = f.FFp1(z);
|
|
|
|
g->FFi(w) = f.FFi((z+1)%3);
|
|
|
|
f.FFp1(z) = g;
|
|
|
|
f.FFi((z+1)%3) = (w+1)%3;
|
|
|
|
g->FFp1(w) = &f;
|
|
|
|
g->FFi((w+1)%3) = (z+1)%3;
|
|
|
|
|
|
|
|
if(f.FFp(z)==g)
|
|
|
|
{
|
|
|
|
f.FFp(z) = &f;
|
|
|
|
f.FFi(z) = z;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-06 01:08:21 +01:00
|
|
|
f.FFp(z)->FFp( f.FFi(z) ) = &f;
|
|
|
|
f.FFp(z)->FFi( f.FFi(z) ) = z;
|
2004-10-22 15:41:06 +02:00
|
|
|
}
|
|
|
|
if(g->FFp(w)==&f)
|
|
|
|
{
|
|
|
|
g->FFp(w)=g;
|
|
|
|
g->FFi(w)=w;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-06 01:08:21 +01:00
|
|
|
g->FFp(w)->FFp( g->FFi(w) ) = g;
|
|
|
|
g->FFp(w)->FFi( g->FFi(w) ) = w;
|
2004-10-22 15:41:06 +02:00
|
|
|
}
|
2005-12-02 00:54:59 +01:00
|
|
|
}
|
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)
|
|
|
|
{
|
2005-03-18 17:35:53 +01:00
|
|
|
typename FaceType::VerteType *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
|
|
|
|
|