2004-05-07 11:29:50 +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. *
|
|
|
|
* *
|
2004-05-07 11:35:09 +02:00
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
History
|
|
|
|
|
|
|
|
$Log: not supported by cvs2svn $
|
2008-02-15 13:51:59 +01:00
|
|
|
Revision 1.12 2007/05/31 09:39:55 cignoni
|
|
|
|
Small gcc compiling issues
|
|
|
|
|
2007-05-31 11:39:56 +02:00
|
|
|
Revision 1.11 2006/07/06 12:30:32 ganovelli
|
|
|
|
misleading comment removed
|
|
|
|
|
2006-07-06 14:30:32 +02:00
|
|
|
Revision 1.10 2005/12/14 17:14:13 pietroni
|
|
|
|
added assert on deleted flag condition
|
|
|
|
|
2005-12-14 18:14:13 +01:00
|
|
|
Revision 1.9 2005/02/08 14:38:05 turini
|
|
|
|
Warnings Correction
|
|
|
|
|
2005-02-08 15:38:05 +01:00
|
|
|
Revision 1.8 2004/05/17 08:26:28 turini
|
|
|
|
Changed : Parameters Order As In vcg::tetra::SubSet.
|
|
|
|
|
2004-05-17 10:26:28 +02:00
|
|
|
Revision 1.7 2004/05/17 07:58:16 turini
|
|
|
|
Minor Changes To Compile Even Without using namespace std.
|
|
|
|
|
2004-05-17 09:58:16 +02:00
|
|
|
Revision 1.6 2004/05/14 11:43:17 turini
|
|
|
|
Changed mesh ClearFlag call.
|
|
|
|
|
2004-05-14 13:43:17 +02:00
|
|
|
Revision 1.5 2004/05/13 09:59:20 turini
|
|
|
|
Added typedef typename in InsertedV
|
|
|
|
|
2004-05-13 11:59:20 +02:00
|
|
|
Revision 1.4 2004/05/07 10:06:46 turini
|
|
|
|
include Plane3 removed.
|
|
|
|
|
2004-05-07 12:06:46 +02:00
|
|
|
Revision 1.3 2004/05/07 09:35:09 turini
|
|
|
|
Added History Info
|
2004-05-07 11:35:09 +02:00
|
|
|
|
2004-05-07 11:29:50 +02:00
|
|
|
****************************************************************************/
|
2004-05-07 11:27:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef __VCGLIB_TRISUBSET
|
|
|
|
#define __VCGLIB_TRISUBSET
|
|
|
|
|
2004-05-14 13:43:17 +02:00
|
|
|
#include <vcg/complex/trimesh/update/flag.h>
|
2004-05-07 11:27:07 +02:00
|
|
|
|
|
|
|
namespace vcg {
|
|
|
|
namespace tri {
|
|
|
|
|
|
|
|
|
|
|
|
template <class I_MESH_TYPE>
|
|
|
|
struct InsertedV
|
|
|
|
{
|
2004-05-13 11:59:20 +02:00
|
|
|
typedef I_MESH_TYPE IMeshType;
|
|
|
|
typedef typename IMeshType::VertexPointer VertexPointer;
|
|
|
|
typedef typename IMeshType::FacePointer FacePointer;
|
|
|
|
|
|
|
|
InsertedV(VertexPointer _v, FacePointer _f, int _z)
|
|
|
|
: v(_v), f(_f), z(_z)
|
2004-05-07 11:27:07 +02:00
|
|
|
{}
|
|
|
|
|
2004-05-13 11:59:20 +02:00
|
|
|
VertexPointer v;
|
|
|
|
FacePointer f;
|
2004-05-07 11:27:07 +02:00
|
|
|
int z;
|
|
|
|
|
2008-08-19 13:03:39 +02:00
|
|
|
const bool operator < (const InsertedV & o) const
|
2004-05-07 11:27:07 +02:00
|
|
|
{
|
|
|
|
return (v<o.v);
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool operator ==(const InsertedV & o)
|
|
|
|
{
|
|
|
|
return (v==o.v);
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool operator !=(const InsertedV & o)
|
|
|
|
{
|
|
|
|
return (v!=o.v);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This function build a nesh from a subset of faces of another.
|
|
|
|
// @param : subSet, stl vector of face poitners.
|
|
|
|
// m, output mesh mesh.
|
2005-12-14 18:14:13 +01:00
|
|
|
|
|
|
|
|
2004-05-07 11:27:07 +02:00
|
|
|
template <class S_MESH_TYPE, class STL_CONT>
|
2004-05-17 10:26:28 +02:00
|
|
|
void SubSet(S_MESH_TYPE & m, STL_CONT & subSet)
|
2004-05-07 11:27:07 +02:00
|
|
|
{
|
2004-05-17 09:58:16 +02:00
|
|
|
std::vector< InsertedV<S_MESH_TYPE> > newVertices;
|
2009-03-17 17:39:23 +01:00
|
|
|
typename STL_CONT::const_iterator pfi;
|
2007-05-31 11:39:56 +02:00
|
|
|
typename S_MESH_TYPE::VertexIterator vi;
|
2008-02-15 13:51:59 +01:00
|
|
|
typename S_MESH_TYPE::FaceIterator fi;
|
|
|
|
typedef typename S_MESH_TYPE::VertexType S_VertexType;
|
2007-05-31 11:39:56 +02:00
|
|
|
std::vector<typename S_MESH_TYPE::VertexPointer> redirect;
|
2008-02-15 13:51:59 +01:00
|
|
|
|
2004-05-07 11:27:07 +02:00
|
|
|
|
2008-02-15 13:51:59 +01:00
|
|
|
fi = vcg::tri::Allocator<S_MESH_TYPE>::AddFaces(m,subSet.size());
|
2004-05-07 11:27:07 +02:00
|
|
|
for(pfi=subSet.begin(); pfi!=subSet.end(); ++pfi)
|
2005-12-14 18:14:13 +01:00
|
|
|
{
|
|
|
|
assert(!(*pfi)->IsD());
|
2008-02-15 13:51:59 +01:00
|
|
|
(*fi).ImportLocal(**pfi);
|
2008-11-12 17:03:24 +01:00
|
|
|
for(int ii = 0 ; ii < (*fi).VN(); ++ii)
|
|
|
|
(*fi).V(ii) = (S_VertexType*)(void*)(*pfi)->V(ii);
|
2008-02-15 13:51:59 +01:00
|
|
|
++fi;
|
2005-12-14 18:14:13 +01:00
|
|
|
}
|
2004-05-07 11:27:07 +02:00
|
|
|
|
2008-02-15 13:51:59 +01:00
|
|
|
|
2004-05-07 11:27:07 +02:00
|
|
|
for(fi=m.face.begin(); fi!=m.face.end(); ++fi)
|
2008-11-12 17:03:24 +01:00
|
|
|
for(int ii = 0 ; ii < (*fi).VN(); ++ii)
|
|
|
|
newVertices.push_back(InsertedV<S_MESH_TYPE>((*fi).V(ii), &(*fi),ii));
|
2004-05-07 11:27:07 +02:00
|
|
|
|
|
|
|
sort(newVertices.begin(), newVertices.end());
|
|
|
|
|
2007-05-31 11:39:56 +02:00
|
|
|
typename std::vector< InsertedV<S_MESH_TYPE> >::iterator curr, next;
|
2004-05-07 11:27:07 +02:00
|
|
|
int pos=0;
|
|
|
|
curr=next=newVertices.begin();
|
|
|
|
while(next!=newVertices.end())
|
|
|
|
{
|
|
|
|
if((*curr)!=(*next))
|
|
|
|
pos++;
|
2007-05-31 11:39:56 +02:00
|
|
|
(*next).f->V((*next).z)=(typename S_MESH_TYPE::VertexPointer)pos;
|
2004-05-07 11:27:07 +02:00
|
|
|
curr=next;
|
|
|
|
next++;
|
|
|
|
}
|
|
|
|
|
2007-05-31 11:39:56 +02:00
|
|
|
typename std::vector< InsertedV<S_MESH_TYPE> >::iterator newE=unique(newVertices.begin(), newVertices.end());
|
2008-08-19 11:09:44 +02:00
|
|
|
|
|
|
|
vi = vcg::tri::Allocator<S_MESH_TYPE>::AddVertices(m,newE-newVertices.begin());
|
2008-11-12 17:03:24 +01:00
|
|
|
for(curr=newVertices.begin(); curr!=newE; ++curr,++vi)
|
|
|
|
(*vi).ImportLocal(*((*curr).v));
|
|
|
|
|
|
|
|
for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
|
|
|
|
redirect.push_back(&(*vi));
|
|
|
|
|
|
|
|
for(fi=m.face.begin(); fi!=m.face.end(); ++fi)
|
|
|
|
{
|
|
|
|
for(int ii = 0 ; ii < (*fi).VN(); ++ii)
|
|
|
|
(*fi).V(ii)=redirect[(size_t)(*fi).V(ii)];
|
|
|
|
}
|
|
|
|
m.vn=(int)m.vert.size();
|
|
|
|
m.fn=(int)m.face.size();
|
2004-05-07 11:27:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // End Namespace TriMesh
|
|
|
|
} // End Namespace vcg
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|