removed tetra complex...bootstrapping tetra in trimesh:

base done
foreach done
Allocator done
Append done

quality selection topology WIP
clean todo
This commit is contained in:
T.Alderighi 2018-05-04 18:12:02 +02:00
parent b662f747a0
commit 67a80722d5
17 changed files with 435 additions and 3865 deletions

View File

@ -116,6 +116,11 @@ public:
typedef typename MeshType::FaceIterator FaceIterator;
typedef typename MeshType::ConstFaceIterator ConstFaceIterator;
typedef typename MeshType::FaceContainer FaceContainer;
typedef typename MeshType::TetraType TetraType;
typedef typename MeshType::TetraPointer TetraPointer;
typedef typename MeshType::TetraIterator TetraIterator;
typedef typename MeshType::ConstTetraIterator ConstTetraIterator;
typedef typename vcg::Box3<ScalarType> Box3Type;
typedef GridStaticPtr<FaceType, ScalarType > TriMeshGrid;
@ -191,6 +196,13 @@ public:
{
(*ei).V(k) = &*mp[ (*ei).V(k) ];
}
for (TetraIterator ti = m.tetra.begin(); ti != m.tetra.end(); ++ti)
if (!(*ti).IsD())
for (k = 0; k < 4; ++k)
if (mp.find((typename MeshType::VertexPointer)(*ti).V(k)) != mp.end())
(*ti).V(k) = &*mp[ (*ti).V(k) ];
if(RemoveDegenerateFlag) RemoveDegenerateFace(m);
if(RemoveDegenerateFlag && m.en>0) {
RemoveDegenerateEdge(m);

View File

@ -51,6 +51,9 @@ public:
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator;
typedef typename MeshType::TetraType TetraType;
typedef typename MeshType::TetraPointer TetraPointer;
typedef typename MeshType::TetraIterator TetraIterator;
/// \brief Reset all the mesh flags (vertexes edge faces) setting everithing to zero (the default value for flags)
@ -65,8 +68,12 @@ public:
if(HasPerFaceFlags(m) )
for(FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
(*fi).Flags() = 0;
if(HasPerTetraFlags(m) )
for(TetraIterator ti=m.tetra.begin(); ti!=m.tetra.end(); ++ti)
(*ti).Flags() = 0;
}
static void VertexClear(MeshType &m, unsigned int FlagMask = 0xffffffff)
{
RequirePerVertexFlags(m);
@ -91,6 +98,14 @@ public:
if(!(*fi).IsD()) (*fi).Flags() &= andMask ;
}
static void TetraClear(MeshType &m, unsigned int FlagMask = 0xffffffff)
{
RequirePerTetraFlags(m);
int andMask = ~FlagMask;
for(TetraIterator ti=m.tetra.begin(); ti!=m.tetra.end(); ++ti)
if(!(*ti).IsD()) (*ti).Flags() &= andMask ;
}
static void VertexSet(MeshType &m, unsigned int FlagMask)
{
RequirePerVertexFlags(m);
@ -112,6 +127,13 @@ public:
if(!(*fi).IsD()) (*fi).Flags() |= FlagMask ;
}
static void TetraSet(MeshType &m, unsigned int FlagMask)
{
RequirePerTetraFlags(m);
for(TetraIterator ti=m.tetra.begin(); ti!=m.tetra.end(); ++ti)
if(!(*ti).IsD()) (*ti).Flags() |= FlagMask ;
}
static void VertexClearV(MeshType &m) { VertexClear(m,VertexType::VISITED);}
@ -134,9 +156,13 @@ public:
static void FaceSetV(MeshType &m) { FaceSet(m,FaceType::VISITED);}
static void FaceSetB(MeshType &m) { FaceSet(m,FaceType::BORDER);}
static void FaceSetF(MeshType &m) { FaceSet(m,FaceType::FAUX012);}
static void TetraClearV(MeshType &m) { TetraClear(m, TetraType::VISITED); }
static void TetraClearS(MeshType &m) { TetraClear(m, TetraType::SELECTED); }
static void TetraClearB(MeshType &m) { TetraClear(m, TetraType::BORDER0123); }
static void TetraSetV(MeshType &m) { TetraSet(m, TetraType::VISITED); }
static void TetraSetS(MeshType &m) { TetraSet(m, TetraType::SELECTED); }
static void TetraSetB(MeshType &m) { TetraSet(m, TetraType::BORDER0123); }
/// \brief Compute the border flags for the faces using the Face-Face Topology.
/**
\warning Obviously it assumes that the topology has been correctly computed (see: UpdateTopology::FaceFace )
*/
@ -153,6 +179,23 @@ public:
}
}
/// \brief Compute the border flags for the tetras using the Tetra-Tetra Topology.
/**
\warning Obviously it assumes that the topology has been correctly computed (see: UpdateTopology::FaceFace )
*/
static void TetraBorderFromTT(MeshType &m)
{
RequirePerTetraFlags(m);
RequireTTAdjacency(m);
for(TetraIterator ti=m.tetra.begin(); ti!=m.tetra.end(); ++ti)
if(!(*ti).IsD())
for(int j = 0; j < 4; ++j)
{
if (tetrahedron::IsBorder(*fi,j)) (*ti).SetB(j);
else (*ti).ClearB(j);
}
}
static void FaceBorderFromVF(MeshType &m)
{

View File

@ -55,6 +55,11 @@ public:
typedef typename MeshType::FaceIterator FaceIterator;
typedef typename MeshType::VertexType::QualityType VertexQualityType;
typedef typename MeshType::FaceType::QualityType FaceQualityType;
typedef typename MeshType::TetraType TetraType;
typedef typename MeshType::TetraPointer TetraPointer;
typedef typename MeshType::TetraIterator TetraIterator;
typedef typename MeshType::TetraType::QualityType TetraQualityType;
/** Assign to each vertex of the mesh a constant quality value. Useful for initialization.
@ -136,6 +141,21 @@ static void FaceArea(MeshType &m)
(*fi).Q()=FaceQualityType(vcg::DoubleArea(*fi)/ScalarType(2.0));
}
static void TetraConstant(MeshType & m, const TetraQualityType q)
{
tri::RequirePerTetraQuality(m);
ForEachTetra(m, [&q] (MeshType::TetraType & t) {
t.Q() = q;
});
}
static void TetraVolume(MeshType & m)
{
tri::RequirePerTetraQuality(m);
ForEachTetra(m, [] (MeshType::TetraType & t) {
t.Q() = TetraQualityType(vcg::Tetra::ComputeVolume(t));
});
}
static void VertexFromFace( MeshType &m, bool areaWeighted=true)
{
tri::RequirePerFaceQuality(m);

View File

@ -37,6 +37,8 @@ class SelectionStack
typedef typename ComputeMeshType::template PerVertexAttributeHandle< bool > vsHandle;
typedef typename ComputeMeshType::template PerEdgeAttributeHandle< bool > esHandle;
typedef typename ComputeMeshType::template PerFaceAttributeHandle< bool > fsHandle;
typedef typename ComputeMeshType::template PerTetraAttributeHandle< bool > tsHandle;
public:
SelectionStack(ComputeMeshType &m)
@ -47,8 +49,9 @@ public:
bool push()
{
vsHandle vsH = Allocator<ComputeMeshType>::template AddPerVertexAttribute< bool >(*_m);
esHandle esH = Allocator<ComputeMeshType>::template AddPerEdgeAttribute< bool >(*_m);
esHandle esH = Allocator<ComputeMeshType>::template AddPerEdgeAttribute< bool > (*_m);
fsHandle fsH = Allocator<ComputeMeshType>::template AddPerFaceAttribute< bool > (*_m);
fsHandle tsH = Allocator<ComputeMeshType>::template AddPerTetraAttribute< bool > (*_m);
typename ComputeMeshType::VertexIterator vi;
for(vi = _m->vert.begin(); vi != _m->vert.end(); ++vi)
if( !(*vi).IsD() ) vsH[*vi] = (*vi).IsS() ;
@ -61,9 +64,14 @@ public:
for(fi = _m->face.begin(); fi != _m->face.end(); ++fi)
if( !(*fi).IsD() ) fsH[*fi] = (*fi).IsS() ;
typename ComputeMeshType::TetraIterator ti;
for(ti = _m->tetra.begin(); ti != _m->tetra.end(); ++ti)
if( !(*ti).IsD() ) tsH[*ti] = (*ti).IsS() ;
vsV.push_back(vsH);
esV.push_back(esH);
fsV.push_back(fsH);
tsV.push_back(tsH);
return true;
}
@ -89,6 +97,8 @@ public:
vsHandle vsH = vsV.back();
esHandle esH = esV.back();
fsHandle fsH = fsV.back();
tsHandle tsH = tsV.back();
if(! (Allocator<ComputeMeshType>::template IsValidHandle(*_m, vsH))) return false;
for(auto vi = _m->vert.begin(); vi != _m->vert.end(); ++vi)
@ -122,12 +132,25 @@ public:
}
}
for (auto ti = _m->tetra.begin(); ti != _m.tetra.end(); ++ti)
if (!(*ti).IsD())
{
if (fsH[*ti]) {
if (!andFlag) (*ti).SetS();
} else {
if (!orFlag) (*ti).ClearS();
}
}
Allocator<ComputeMeshType>::template DeletePerVertexAttribute<bool>(*_m,vsH);
Allocator<ComputeMeshType>::template DeletePerEdgeAttribute<bool>(*_m,esH);
Allocator<ComputeMeshType>::template DeletePerFaceAttribute<bool>(*_m,fsH);
Allocator<ComputeMeshType>::template DeletePerTetraAttribute<bool>(*_m,tsH);
vsV.pop_back();
esV.pop_back();
fsV.pop_back();
tsV.pop_back();
return true;
}
@ -136,6 +159,8 @@ private:
std::vector<vsHandle> vsV;
std::vector<esHandle> esV;
std::vector<fsHandle> fsV;
std::vector<fsHandle> tsV;
};
/// \ingroup trimesh
@ -161,6 +186,10 @@ typedef typename MeshType::EdgeIterator EdgeIterator;
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator;
typedef typename MeshType::TetraType TetraType;
typedef typename MeshType::TetraPointer TetraPointer;
typedef typename MeshType::TetraIterator TetraIterator;
typedef typename vcg::Box3<ScalarType> Box3Type;
/// \brief This function select all the vertices.
@ -186,6 +215,16 @@ static size_t FaceAll(MeshType &m)
return m.fn;
}
/// \brief This function select all the tetras.
static size_t TetraAll (MeshType & m)
{
ForEachTetra(m, [] (MeshType::TetraType & t) {
t.SetS();
});
return m.tn;
}
/// \brief This function clear the selection flag for all the vertices.
static size_t VertexClear(MeshType &m)
{
@ -210,12 +249,23 @@ static size_t FaceClear(MeshType &m)
return 0;
}
/// \brief This function clears the selection flag for all the tetras.
static size_t TetraClear (MeshType & m)
{
ForEachTetra(m, [] (MeshType::TetraType & t) {
t.ClearS();
});
return 0;
}
/// \brief This function clears the selection flag for all the elements of a mesh (vertices, edges, and faces).
static void Clear(MeshType &m)
{
VertexClear(m);
EdgeClear(m);
FaceClear(m);
TetraClear(m);
}
/// \brief This function returns the number of selected faces.
@ -245,6 +295,17 @@ static size_t VertexCount(MeshType &m)
return selCnt;
}
/// \brief This function returns the number of selected tetras.
static size_t TetraCount (MeshType & m)
{
size_t selCnt = 0;
ForEachTetra(m, [&selCnt] (MeshType::TetraType & t) {
if (t.IsS())
++selCnt;
});
return selCnt;
}
/// \brief This function inverts the selection flag for all the faces.
static size_t FaceInvert(MeshType &m)
{
@ -293,6 +354,24 @@ static size_t VertexInvert(MeshType &m)
return selCnt;
}
/// \brief This function inverts the selection flag for all the tetras.
static size_t TetraInvert (MeshType & m)
{
size_t selCnt = 0;
ForEachTetra(m, [&selCnt] (MeshType::TetraType & t) {
if (t.IsS())
t.ClearS();
else
{
t.SetS();
++selCnt;
}
});
return selCnt;
}
/// \brief Select all the vertices that are touched by at least a single selected faces
static size_t VertexFromFaceLoose(MeshType &m, bool preserveSelection=false)
{

View File

@ -48,15 +48,97 @@ typedef typename MeshType::EdgeIterator EdgeIterator;
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator;
typedef typename MeshType::TetraType TetraType;
typedef typename MeshType::TetraPointer TetraPointer;
typedef typename MeshType::TetraIterator TetraIterator;
/// \headerfile topology.h vcg/complex/algorithms/update/topology.h
/// \brief Auxiliary data structure for computing tetra tetra adjacency information.
/**
* It identifies a face, storing three vertex pointers and a tetra pointer where it belongs.
*/
class PFace
{
public:
VertexPointer v[3]; //three ordered vertex pointers, identify a face
TetraPointer t; //the pointer to the tetra where this face belongs
int z; //index in [0..3] of the face in the tetra
bool isBorder;
PFace () {}
PFace (TetraPointer tp, const int nz) { this->Set(tp, nz); }
void Set (TetraPointer tp /*the tetra pointer*/, const int nz /*the face index*/)
{
assert (tp != 0);
assert (nz >= 0 && nz < 4);
v[0] = tp->cV(Tetra::VofF(nz, 0));
v[1] = tp->cV(Tetra::VofF(nz, 1));
v[2] = tp->cV(Tetra::VofF(nz, 2));
assert(v[0] != v[1] && v[1] != v[2]); //no degenerate faces
if (v[0] > v[1])
std::swap(v[0], v[1]);
if (v[1] > v[2])
std::swap(v[1], v[2]);
if (v[0] > v[1])
std::swap(v[0], v[1]);
t = tp;
z = nz;
}
inline bool operator < (const PFace & pf) const
{
if (v[0] < pf.v[0])
return true;
else
{
if (v[0] > pf.v[0]) return false;
if (v[1] < pf.v[1])
return true;
else
{
if (v[1] > pf.v[1]) return false;
return (v[2] < pf.v[2]);
}
}
}
inline bool operator == (const PFace & pf) const
{
return v[0] == pf.v[0] && v[1] == pf.v[1] && v[2] == pf.v[2];
}
};
static void FillFaceVector (MeshType & m, std::vector<PFace> & fvec)
{
ForEachTetra(m, [&fvec] (MeshType::TetraType & t) {
for (int i = 0; i < 4; ++i)
fvec.push_back(PFace(&t, i));
});
}
static void FillUniqueFaceVector (MeshType & m, std::vector<PFace> & fvec)
{
FillFaceVector(m, fvec);
std::sort(fvec.begin(), fvec.end());
typename std::vector<PFace>::iterator newEnd = std::unique(fvec.begin(), fvec.end());
}
/// \brief 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:
@ -219,6 +301,60 @@ static void AllocateEdge(MeshType &m)
}
/// \brief Clear the tetra-tetra topological relation, setting each involved pointer to null.
/// useful when you passed a mesh with tt adjacency to an algorithm that does not use it and chould have messed it
static void ClearTetraTetra (MeshType & m)
{
RequireTTAdjacency(m);
ForEachTetra(m, [] (MeshType::TetraType & t) {
for (int i = 0; i < 4; ++i)
{
t.TTp(i) = NULL;
t.TTi(i) = -1;
}
});
}
/// \brief Updates the Tetra-Tetra topological relation by allowing to retrieve for each tetra what other tetras share their faces.
static void TetraTetra (MeshType & m)
{
RequireTTAdjacency(m);
if (m.tn == 0) return;
std::vector<PFace> fvec;
FillFaceVector(m, fvec);
std::sort(fvec.begin(), fvec.end());
int nf = 0;
typename std::vector<PFace>::iterator pback, pfront;
pback = fvec.begin();
pfront = fvec.begin();
do
{
if (pfront == fvec.end() || !(*pfront == *pback))
{
typename std::vector<PFace>::iterator q, q_next;
for (q = pback; q < pfront - 1; ++q)
{
assert((*q).z >= 0);
q_next = q;
++q_next;
assert((*q_next).z >= 0 && (*q_next).z < 4);
(*q).t->TTp(q->z) = (*q_next).t;
(*q).t->TTi(q->z) = (*q_next).z;
}
(*q).t->TTp(q->z) = pback->t;
(*q).t->TTi(q->z) = pback->z;
pback = pfront;
++nf;
}
if (pfront == fvec.end()) break;
++pfront;
} while (true);
}
/// \brief Clear the Face-Face topological relation setting each involved pointer to null.
/// useful when you passed a mesh with ff adjacency to an algorithm that does not use it and could have messed it.
static void ClearFaceFace(MeshType &m)
@ -280,6 +416,30 @@ static void FaceFace(MeshType &m)
} while(true);
}
/// \brief Update the vertex-tetra topological relation.
static void VertexTetra(MeshType & m)
{
RequireVTAdjacency(m);
ForEachVertex(m, [] (MeshType::VertexType & v) {
v.VTp() = NULL;
v.VTi() = 0;
});
ForEachTetra(m, [] (MeshType::TetraType & t) {
//this works like this: the first iteration defines the end of the chain
//then it backwards chains everything
for (int i = 0; i < 4; ++i)
{
t.VTp(i) = t.V(i)->VTp();
t.VTi(i) = t.V(i)->VTi();
t.V(i)->VTp() = &t;
t.V(i)->VTi() = i;
}
});
}
/// \brief Update the Vertex-Face topological relation.
/**
The function allows to retrieve for each vertex the list of faces sharing this vertex.

View File

@ -1131,10 +1131,10 @@ public:
if(HasEFAdjacency(m))
// if (m.edge[i].cEEp(0)!=0)
{
m.edge[ pu.remap[i] ].EFp(0) = m.edge[i].cEFp(0);
m.edge[ pu.remap[i] ].EFi(0) = m.edge[i].cEFi(0);
m.edge[ pu.remap[i] ].EFp(1) = m.edge[i].cEFp(1);
m.edge[ pu.remap[i] ].EFi(1) = m.edge[i].cEFi(1);
m.edge[ pu.remap[i] ].EFp() = m.edge[i].cEFp();
m.edge[ pu.remap[i] ].EFi() = m.edge[i].cEFi();
m.edge[ pu.remap[i] ].EFp() = m.edge[i].cEFp();
m.edge[ pu.remap[i] ].EFi() = m.edge[i].cEFi();
}
}
@ -1170,8 +1170,8 @@ public:
pu.Update((*ei).VEp(i));
if(HasEEAdjacency(m))
pu.Update((*ei).EEp(i));
if(HasEFAdjacency(m))
pu.Update((*ei).EFp(i));
// if(HasEFAdjacency(m))
// pu.Update((*ei).EFp());
}
}
@ -1322,7 +1322,7 @@ public:
size_t pos = 0;
for (size_t i = 0; i < m.tetra.size(); ++i)
{
if (!m.tetra.IsD())
if (!m.tetra[i].IsD())
{
if (pos != i)
{
@ -1341,7 +1341,7 @@ public:
m.tetra[pos].VTi(j) = m.tetra[i].VTi(j);
}
else
m.tetra[pos].VTClear();
m.tetra[pos].VTClear(j);
}
//import TT adj
if (HasTTAdjacency(m))
@ -1397,7 +1397,7 @@ public:
for (int i = 0; i < 4; ++i)
if ((*ti).IsVTInitialized(i) && (*ti).VTp(i) != 0)
{
size_t oldIndex = (*ti).VTp(i) - fbase;
size_t oldIndex = (*ti).VTp(i) - tbase;
assert(tbase <= (*ti).VTp(i) && oldIndex < pu.remap.size());
(*ti).VTp(i) = tbase + pu.remap[oldIndex];
}

View File

@ -193,7 +193,6 @@ public:
{
// Tetra to Tetra Adj
if(HasTTAdjacency(ml) && HasTTAdjacency(mr)){
assert(tl.TN() == tr.TN());
for( int vi = 0; vi < 4; ++vi ){
size_t idx = remap.tetra[Index(mr,tr.cTTp(vi))];
if(idx != Remap::InvalidIndex()){
@ -307,7 +306,7 @@ static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false,
for (TetraIteratorRight ti = mr.tetra.begin(); ti != mr.tetra.end(); ++ti)
if (!(*ti).IsD() && (!selected || (*ti).IsS())) {
size_t idx = Index(mr, *ti);
assert (remap.tetra[ind] == Remap::InvalidIndex());
assert (remap.tetra[idx] == Remap::InvalidIndex());
TetraIteratorLeft tp = Allocator<MeshLeft>::AddTetras(ml, 1);
(*tp).ImportData(*ti);
remap.tetra[idx] = Index(ml, *tp);

View File

@ -641,10 +641,10 @@ template < class TetraType> bool TetraVectorHasPerTetraQuality(const std::vector
template < class TetraType> bool TetraVectorHasVTAdjacency (const std::vector<TetraType> &) { return TetraType::HasVTAdjacency(); }
template < class TetraType> bool TetraVectorHasTTAdjacency (const std::vector<TetraType> &) { return TetraType::HasTTAdjacency(); }
template < class TriMeshType> bool HasPerTetraFlags (const TriMeshType &m) { return tri::FaceVectorHasPerTetraFlags (m.face); }
template < class TriMeshType> bool HasPerTetraColor (const TriMeshType &m) { return tri::FaceVectorHasPerTetraColor (m.face); }
template < class TriMeshType> bool HasPerTetraMark (const TriMeshType &m) { return tri::FaceVectorHasPerTetraMark (m.face); }
template < class TriMeshType> bool HasPerTetraQuality (const TriMeshType &m) { return tri::FaceVectorHasPerTetraQuality (m.face); }
template < class TriMeshType> bool HasPerTetraFlags (const TriMeshType &m) { return tri::TetraVectorHasPerTetraFlags (m.tetra); }
template < class TriMeshType> bool HasPerTetraColor (const TriMeshType &m) { return tri::TetraVectorHasPerTetraColor (m.tetra); }
template < class TriMeshType> bool HasPerTetraMark (const TriMeshType &m) { return tri::TetraVectorHasPerTetraMark (m.tetra); }
template < class TriMeshType> bool HasPerTetraQuality (const TriMeshType &m) { return tri::TetraVectorHasPerTetraQuality (m.tetra); }
template < class TriMeshType> bool HasFFAdjacency (const TriMeshType &m) { return tri::FaceVectorHasFFAdjacency (m.face); }
template < class TriMeshType> bool HasEEAdjacency (const TriMeshType &m) { return tri::EdgeVectorHasEEAdjacency (m.edge); }

View File

@ -190,7 +190,7 @@ inline void ForEachTetra(MeshType &m, std::function<void (typename MeshType::Tet
{
if(m.tn == (int) m.tetra.size())
{
for(auto ti = m.tetra.begin(); ti! = m.tetra.end(); ++ti) {
for(auto ti = m.tetra.begin(); ti != m.tetra.end(); ++ti) {
action(*ti);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,456 +0,0 @@
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004-2016 \/)\/ *
* 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. *
* *
****************************************************************************/
#ifndef __VCGLIB_TETRAAPPEND
#define __VCGLIB_TETRAAPPEND
#ifndef __VCG_TETRA_MESH
#error "This file should not be included alone. It is automatically included by complex.h"
#endif
namespace vcg {
namespace tetra {
/** \ingroup trimesh */
/*! \brief Class to safely duplicate and append (portion of) meshes.
Adding elements to a mesh, like faces and vertices can involve the reallocation of the vectors of the involved elements.
This class provide the only safe methods to add elements of a mesh to another one.
\sa \ref allocation
*/
template<class MeshLeft, class ConstMeshRight>
class Append
{
public:
typedef typename MeshLeft::ScalarType ScalarLeft;
typedef typename MeshLeft::CoordType CoordLeft;
typedef typename MeshLeft::VertexType VertexLeft;
typedef typename MeshLeft::EdgeType EdgeLeft;
typedef typename MeshLeft::FaceType FaceLeft;
typedef typename MeshLeft::TetraType TetraLeft;
// typedef typename MeshLeft::HEdgeType HEdgeLeft;
typedef typename MeshLeft::VertexPointer VertexPointerLeft;
typedef typename MeshLeft::VertexIterator VertexIteratorLeft;
typedef typename MeshLeft::EdgeIterator EdgeIteratorLeft;
// typedef typename MeshLeft::HEdgeIterator HEdgeIteratorLeft;
typedef typename MeshLeft::FaceIterator FaceIteratorLeft;
typedef typename MeshLeft::TetraIterator TetraIteratorLeft;
typedef typename MeshLeft::TetraPointer TetraPointerLeft;
typedef typename ConstMeshRight::ScalarType ScalarRight;
typedef typename ConstMeshRight::CoordType CoordRight;
typedef typename ConstMeshRight::VertexType VertexRight;
typedef typename ConstMeshRight::EdgeType EdgeRight;
// typedef typename ConstMeshRight::HEdgeType HEdgeRight;
typedef typename ConstMeshRight::FaceType FaceRight;
typedef typename ConstMeshRight::VertexPointer VertexPointerRight;
typedef typename ConstMeshRight::VertexIterator VertexIteratorRight;
typedef typename ConstMeshRight::EdgeIterator EdgeIteratorRight;
// typedef typename ConstMeshRight::HEdgeIterator HEdgeIteratorRight;
typedef typename ConstMeshRight::FaceIterator FaceIteratorRight;
typedef typename ConstMeshRight::FacePointer FacePointerRight;
typedef typename ConstMeshRight::TetraType TetraTypeRight;
typedef typename ConstMeshRight::TetraPointer TetraPointerRight;
typedef typename ConstMeshRight::TetraIterator TetraIteratorRight;
struct Remap{
static size_t InvalidIndex() { return std::numeric_limits<size_t>::max(); }
std::vector<size_t> vert,face,edge, /*hedge,*/ tetra;
};
static void ImportVertexAdj(MeshLeft &ml, ConstMeshRight &mr, VertexLeft &vl, VertexRight &vr, Remap &remap ){
// Vertex to Edge Adj
if(HasVEAdjacency(ml) && HasVEAdjacency(mr) && vr.cVEp() != 0){
size_t i = Index(mr,vr.cVEp());
vl.VEp() = (i>ml.edge.size())? 0 : &ml.edge[remap.edge[i]];
vl.VEi() = vr.VEi();
}
// Vertex to Face Adj
if(HasPerVertexVFAdjacency(ml) && HasPerVertexVFAdjacency(mr) && vr.cVFp() != 0 ){
size_t i = Index(mr,vr.cVFp());
vl.VFp() = (i>ml.face.size())? 0 :&ml.face[remap.face[i]];
vl.VFi() = vr.VFi();
}
if (HasPerVertexVTAdjacency(ml) && HasPerVertexVTAdjacency(mr) && vr.cVTp() != 0) {
size_t i = Index(mr, vr.cVTp());
vl.VTp() = (i > ml.tetra.size()) ? 0 : &ml.tetra[remap.tetra[i]];
vl.VTi() = vt.VTi();
}
// // Vertex to HEdge Adj
// if(HasVHAdjacency(ml) && HasVHAdjacency(mr) && vr.cVHp() != 0){
// vl.VHp() = &ml.hedge[remap.hedge[Index(mr,vr.cVHp())]];
// vl.VHi() = vr.VHi();
// }
}
static void ImportEdgeAdj(MeshLeft &ml, ConstMeshRight &mr, EdgeLeft &el, const EdgeRight &er, Remap &remap)
{
// Edge to Edge Adj
if(HasEEAdjacency(ml) && HasEEAdjacency(mr))
for(unsigned int vi = 0; vi < 2; ++vi)
{
size_t idx = Index(mr,er.cEEp(vi));
el.EEp(vi) = (idx>ml.edge.size())? 0 : &ml.edge[remap.edge[idx]];
el.EEi(vi) = er.cEEi(vi);
}
// Edge to Face Adj
if(HasEFAdjacency(ml) && HasEFAdjacency(mr)){
size_t idx = Index(mr,er.cEFp());
el.EFp() = (idx>ml.face.size())? 0 :&ml.face[remap.face[idx]];
el.EFi() = er.cEFi();
}
// // Edge to HEdge Adj
// if(HasEHAdjacency(ml) && HasEHAdjacency(mr))
// el.EHp() = &ml.hedge[remap.hedge[Index(mr,er.cEHp())]];
}
static void ImportFaceAdj(MeshLeft &ml, ConstMeshRight &mr, FaceLeft &fl, const FaceRight &fr, Remap &remap )
{
// Face to Edge Adj
if(HasFEAdjacency(ml) && HasFEAdjacency(mr)){
assert(fl.VN() == fr.VN());
for( int vi = 0; vi < fl.VN(); ++vi ){
size_t idx = remap.edge[Index(mr,fr.cFEp(vi))];
if(idx!=Remap::InvalidIndex())
fl.FEp(vi) = &ml.edge[idx];
}
}
// Face to Face Adj
if(HasFFAdjacency(ml) && HasFFAdjacency(mr)){
assert(fl.VN() == fr.VN());
for( int vi = 0; vi < fl.VN(); ++vi ){
size_t idx = remap.face[Index(mr,fr.cFFp(vi))];
if(idx!=Remap::InvalidIndex()){
fl.FFp(vi) = &ml.face[idx];
fl.FFi(vi) = fr.cFFi(vi);
}
}
}
// // Face to HEedge Adj
// if(HasFHAdjacency(ml) && HasFHAdjacency(mr))
// fl.FHp() = &ml.hedge[remap.hedge[Index(mr,fr.cFHp())]];
}
static void ImportTetraAdj(MeshLeft & ml, ConstMeshRight & mr, TetraLeft & tl, const TetraTypeRight &tr, Remap &remap )
{
// TT Adj
if(HasTTAdjacency(ml) && HasTTAdjacency(mr)){
for( int vi = 0; vi < 4; ++vi ){
size_t idx = remap.tetra[Index(mr,tr.cTTp(vi))];
if(idx!=Remap::InvalidIndex()){
tl.TTp(vi) = &ml.tetra[idx];
tl.TTi(vi) = fr.cTTi(vi);
}
}
}
// // Face to HEedge Adj
// if(HasFHAdjacency(ml) && HasFHAdjacency(mr))
// fl.FHp() = &ml.hedge[remap.hedge[Index(mr,fr.cFHp())]];
}
// static void ImportHEdgeAdj(MeshLeft &ml, ConstMeshRight &mr, HEdgeLeft &hl, const HEdgeRight &hr, Remap &remap, bool /*sel*/ ){
// // HEdge to Vertex Adj
// if(HasHVAdjacency(ml) && HasHVAdjacency(mr))
// hl.HVp() = &ml.vert[remap.vert[Index(mr,hr.cHVp())]];
// // HEdge to Edge Adj
// if(HasHEAdjacency(ml) && HasHEAdjacency(mr)){
// size_t idx = Index(mr,hr.cHEp()) ;
// hl.HEp() = (idx>ml.edge.size())? 0 : &ml.edge[remap.edge[idx]];
// }
// // HEdge to Face Adj
// if(HasHFAdjacency(ml) && HasHFAdjacency(mr)){
// size_t idx = Index(mr,hr.cHFp());
// hl.HFp() = (idx>ml.face.size())? 0 :&ml.face[remap.face[idx]];
// }
// // HEdge to Opposite HEdge Adj
// if(HasHOppAdjacency(ml) && HasHOppAdjacency(mr))
// hl.HOp() = &ml.hedge[remap.hedge[Index(mr,hr.cHOp())]];
// // HEdge to Next HEdge Adj
// if(HasHNextAdjacency(ml) && HasHNextAdjacency(mr))
// hl.HNp() = &ml.hedge[remap.hedge[Index(mr,hr.cHNp())]];
// // HEdge to Next HEdge Adj
// if(HasHPrevAdjacency(ml) && HasHPrevAdjacency(mr))
// hl.HPp() = &ml.hedge[remap.hedge[Index(mr,hr.cHPp())]];
// }
// Append Right Mesh to the Left Mesh
// Append::Mesh(ml, mr) is equivalent to ml += mr.
// Note MeshRigth could be costant...
/*! \brief %Append the second mesh to the first one.
The first mesh is not destroyed and no attempt of avoid duplication of already present elements is done.
If requested only the selected elements are appended to the first one.
The second mesh is not changed at all (it could be constant) with the exception of the selection (see below note).
\note If the the selection of the vertexes is not consistent with the face selection
the append could build faces referencing non existent vertices
so it is mandatory that the selection of the vertices reflects the loose selection
from edges and faces (e.g. if a face is selected then all its vertices must be selected).
\note Attributes. This function will copy only those attributes that are present in both meshes.
Two attributes in different meshes are considered the same iff they have the same
name and the same type. This may be deceiving because they could in fact have
different semantic, but this is up to the developer.
If the left mesh has attributes that are not in the right mesh, their values for the elements
of the right mesh will be uninitialized
*/
//TODO:
static void Mesh(MeshLeft& ml, ConstMeshRight& mr, const bool selected = false, const bool adjFlag = false)
{
// Note that if the the selection of the vertexes is not consistent with the face selection
// the append could build faces referencing non existent vertices
// so it is mandatory that the selection of the vertices reflects the loose selection
// from edges and faces (e.g. if a face is selected all its vertices must be selected).
// note the use of the parameter for preserving existing vertex selection.
if(selected)
{
assert(adjFlag == false || ml.IsEmpty()); // It is rather meaningless to partially copy adj relations.
tri::UpdateSelection<ConstMeshRight>::VertexFromEdgeLoose(mr,true);
tri::UpdateSelection<ConstMeshRight>::VertexFromFaceLoose(mr,true);
}
// phase 1. allocate on ml vert,edge,face, hedge to accomodat those of mr
// and build the remapping for all
Remap remap;
// vertex
remap.vert.resize(mr.vert.size(), Remap::InvalidIndex());
VertexIteratorLeft vp;
size_t svn = UpdateSelection<ConstMeshRight>::VertexCount(mr);
if(selected)
vp=Allocator<MeshLeft>::AddVertices(ml,int(svn));
else
vp=Allocator<MeshLeft>::AddVertices(ml,mr.vn);
for(VertexIteratorRight vi=mr.vert.begin(); vi!=mr.vert.end(); ++vi)
{
if(!(*vi).IsD() && (!selected || (*vi).IsS()))
{
size_t ind=Index(mr,*vi);
remap.vert[ind]=int(Index(ml,*vp));
++vp;
}
}
// edge
remap.edge.resize(mr.edge.size(), Remap::InvalidIndex());
EdgeIteratorLeft ep;
size_t sen = UpdateSelection<ConstMeshRight>::EdgeCount(mr);
if(selected) ep=Allocator<MeshLeft>::AddEdges(ml,sen);
else ep=Allocator<MeshLeft>::AddEdges(ml,mr.en);
for(EdgeIteratorRight ei=mr.edge.begin(); ei!=mr.edge.end(); ++ei)
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
size_t ind=Index(mr,*ei);
remap.edge[ind]=int(Index(ml,*ep));
++ep;
}
// face
remap.face.resize(mr.face.size(), Remap::InvalidIndex());
FaceIteratorLeft fp;
size_t sfn = UpdateSelection<ConstMeshRight>::FaceCount(mr);
if(selected) fp=Allocator<MeshLeft>::AddFaces(ml,sfn);
else fp=Allocator<MeshLeft>::AddFaces(ml,mr.fn);
for(FaceIteratorRight fi=mr.face.begin(); fi!=mr.face.end(); ++fi)
if(!(*fi).IsD() && (!selected || (*fi).IsS())){
size_t ind=Index(mr,*fi);
remap.face[ind]=int(Index(ml,*fp));
++fp;
}
// hedge
remap.hedge.resize(mr.hedge.size(),Remap::InvalidIndex());
for(HEdgeIteratorRight hi=mr.hedge.begin(); hi!=mr.hedge.end(); ++hi)
if(!(*hi).IsD() && (!selected || (*hi).IsS())){
size_t ind=Index(mr,*hi);
assert(remap.hedge[ind]==Remap::InvalidIndex());
HEdgeIteratorLeft hp = Allocator<MeshLeft>::AddHEdges(ml,1);
(*hp).ImportData(*(hi));
remap.hedge[ind]=Index(ml,*hp);
}
// phase 2.
// copy data from ml to its corresponding elements in ml and adjacencies
// vertex
for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi)
if( !(*vi).IsD() && (!selected || (*vi).IsS())){
ml.vert[remap.vert[Index(mr,*vi)]].ImportData(*vi);
if(adjFlag) ImportVertexAdj(ml,mr,ml.vert[remap.vert[Index(mr,*vi)]],*vi,remap);
}
// edge
for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei)
if(!(*ei).IsD() && (!selected || (*ei).IsS())){
ml.edge[remap.edge[Index(mr,*ei)]].ImportData(*ei);
// Edge to Vertex Adj
EdgeLeft &el = ml.edge[remap.edge[Index(mr,*ei)]];
if(HasEVAdjacency(ml) && HasEVAdjacency(mr)){
el.V(0) = &ml.vert[remap.vert[Index(mr,ei->cV(0))]];
el.V(1) = &ml.vert[remap.vert[Index(mr,ei->cV(1))]];
}
if(adjFlag) ImportEdgeAdj(ml,mr,el,*ei,remap);
}
// face
const size_t textureOffset = ml.textures.size();
bool WTFlag = HasPerWedgeTexCoord(mr) && (textureOffset>0);
for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi)
if(!(*fi).IsD() && (!selected || (*fi).IsS()))
{
FaceLeft &fl = ml.face[remap.face[Index(mr,*fi)]];
fl.Alloc(fi->VN());
if(HasFVAdjacency(ml) && HasFVAdjacency(mr)){
for(int i = 0; i < fl.VN(); ++i)
fl.V(i) = &ml.vert[remap.vert[Index(mr,fi->cV(i))]];
}
fl.ImportData(*fi);
if(WTFlag)
for(int i = 0; i < fl.VN(); ++i)
fl.WT(i).n() += short(textureOffset);
if(adjFlag) ImportFaceAdj(ml,mr,ml.face[remap.face[Index(mr,*fi)]],*fi,remap);
}
// hedge
for(HEdgeIteratorRight hi=mr.hedge.begin();hi!=mr.hedge.end();++hi)
if(!(*hi).IsD() && (!selected || (*hi).IsS())){
ml.hedge[remap.hedge[Index(mr,*hi)]].ImportData(*hi);
ImportHEdgeAdj(ml,mr,ml.hedge[remap.hedge[Index(mr,*hi)]],*hi,remap,selected);
}
// phase 3.
// take care of other per mesh data: textures, attributes
// At the end concatenate the vector with texture names.
ml.textures.insert(ml.textures.end(),mr.textures.begin(),mr.textures.end());
// Attributes. Copy only those attributes that are present in both meshes
// Two attributes in different meshes are considered the same if they have the same
// name and the same type. This may be deceiving because they could in fact have
// different semantic, but this is up to the developer.
// If the left mesh has attributes that are not in the right mesh, their values for the elements
// of the right mesh will be uninitialized
unsigned int id_r;
typename std::set< PointerToAttribute >::iterator al, ar;
// per vertex attributes
for(al = ml.vert_attr.begin(); al != ml.vert_attr.end(); ++al)
if(!(*al)._name.empty()){
ar = mr.vert_attr.find(*al);
if(ar!= mr.vert_attr.end()){
id_r = 0;
for(VertexIteratorRight vi=mr.vert.begin();vi!=mr.vert.end();++vi,++id_r)
if( !(*vi).IsD() && (!selected || (*vi).IsS()))
memcpy((*al)._handle->At(remap.vert[Index(mr,*vi)]),(*ar)._handle->At(id_r),
(*al)._handle->SizeOf());
}
}
// per edge attributes
for(al = ml.edge_attr.begin(); al != ml.edge_attr.end(); ++al)
if(!(*al)._name.empty()){
ar = mr.edge_attr.find(*al);
if(ar!= mr.edge_attr.end()){
id_r = 0;
for(EdgeIteratorRight ei=mr.edge.begin();ei!=mr.edge.end();++ei,++id_r)
if( !(*ei).IsD() && (!selected || (*ei).IsS()))
memcpy((*al)._handle->At(remap.edge[Index(mr,*ei)]),(*ar)._handle->At(id_r),
(*al)._handle->SizeOf());
}
}
// per face attributes
for(al = ml.face_attr.begin(); al != ml.face_attr.end(); ++al)
if(!(*al)._name.empty()){
ar = mr.face_attr.find(*al);
if(ar!= mr.face_attr.end()){
id_r = 0;
for(FaceIteratorRight fi=mr.face.begin();fi!=mr.face.end();++fi,++id_r)
if( !(*fi).IsD() && (!selected || (*fi).IsS()))
memcpy((*al)._handle->At(remap.face[Index(mr,*fi)]),(*ar)._handle->At(id_r),
(*al)._handle->SizeOf());
}
}
// per mesh attributes
// if both ml and mr have an attribute with the same name, no action is done
// if mr has an attribute that is NOT present in ml, the attribute is added to ml
//for(ar = mr.mesh_attr.begin(); ar != mr.mesh_attr.end(); ++ar)
// if(!(*ar)._name.empty()){
// al = ml.mesh_attr.find(*ar);
// if(al== ml.mesh_attr.end())
// //...
// }
}
/*! \brief Copy the second mesh over the first one.
The first mesh is destroyed. If requested only the selected elements are copied.
*/
static void MeshCopy(MeshLeft& ml, ConstMeshRight& mr, bool selected=false, const bool adjFlag = false)
{
ml.Clear();
Mesh(ml,mr,selected,adjFlag);
ml.bbox.Import(mr.bbox);
}
/*! \brief %Append only the selected elements of second mesh to the first one.
It is just a wrap of the main Append::Mesh()
*/
static void Selected(MeshLeft& ml, ConstMeshRight& mr)
{
Mesh(ml,mr,true);
}
}; // end of class Append
} // End Namespace tri
} // End Namespace vcg
#endif

File diff suppressed because it is too large Load Diff

View File

@ -81,8 +81,8 @@ public:
static bool HasQuality() { return false; }
static bool HasQuality3() { return false; }
bool IsQualityEnabled() const { return T::TetraType::HasQuality(); }
bool IsQuality3Enabled() const { return T::TetraType::HasQuality3(); }
inline bool IsQualityEnabled() const { return T::TetraType::HasQuality(); }
inline bool IsQuality3Enabled() const { return T::TetraType::HasQuality3(); }
//Empty flags
int &Flags() { static int dummyflags(0); assert(0); return dummyflags; }
@ -103,10 +103,10 @@ public:
//Empty Adjacency
typedef int VFAdjType;
typename T::TetraPointer & VTp( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; }
typename T::TetraPointer & VTp ( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; }
typename T::TetraPointer const cVTp( const int ) const { static typename T::TetraPointer const tp=0; assert(0); return tp; }
typename T::TetraPointer & TTp( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; }
typename T::TetraPointer & TTp ( const int ) { static typename T::TetraPointer tp=0; assert(0); return tp; }
typename T::TetraPointer const cTTp( const int ) const { static typename T::TetraPointer const tp=0; assert(0); return tp; }
char & VTi( const int j ) { static char z=0; assert(0); return z; }
@ -122,8 +122,8 @@ public:
}
}
static bool HasVTAdjacency() { return false; }
static bool HasTTAdjacency() { return false; }
static bool HasVTAdjacency() { return false; }
static bool HasTTAdjacency() { return false; }
static bool HasTTAdjacencyOcc() { return false; }
static bool HasVTAdjacencyOcc() { return false; }
@ -154,20 +154,39 @@ public:
v[1]=0;
v[2]=0;
v[3]=0;
/******* vertex and faces indices scheme*********
*
* /2\`
* / \ `
* / \ `
* / \ _ 3`
* / _ \ '
* / _ \ '
* /0___________1\'
*
*/
findices[0][0] = 0; findices[0][1] = 1; findices[0][2] = 2;
findices[1][0] = 0; findices[1][1] = 3; findices[1][2] = 1;
findices[2][0] = 0; findices[2][1] = 2; findices[2][2] = 3;
findices[3][0] = 1; findices[3][1] = 3; findices[3][2] = 2;
}
typedef typename T::VertexType::CoordType CoordType;
typedef typename T::VertexType::ScalarType ScalarType;
typedef typename T::VertexType::CoordType CoordType;
typedef typename T::VertexType::ScalarType ScalarType;
inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<4); return v[j]; }
inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<4); return v[j]; }
inline typename T::VertexType * const cV( const int j ) const { assert(j>=0 && j<4); return v[j]; }
inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<4); return v[j]; }
inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<4); return v[j]; }
inline typename T::VertexType * const cV( const int j ) const { assert(j>=0 && j<4); return v[j]; }
// Shortcut per accedere ai punti delle facce
inline typename CoordType & P( const int j ) { assert(j>=0 && j<4); return v[j]->P(); }
inline const typename CoordType & P( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); }
inline const typename CoordType &cP( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); }
inline typename size_t const cFtoVi (const int f, const int j) const { assert(f >= 0 && f < 4); assert(j >= 0 && j < 3); return findices[f][j]; }
/** Return the pointer to the ((j+1)%3)-th vertex of the face.
// Shortcut for tetra points
inline typename CoordType & P( const int j ) { assert(j>=0 && j<4); return v[j]->P(); }
inline const typename CoordType & P( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); }
inline const typename CoordType &cP( const int j ) const { assert(j>=0 && j<4); return v[j]->cP(); }
/** Return the pointer to the ((j+1)%4)-th vertex of the tetra.
@param j Index of the face vertex.
*/
inline typename T::VertexType * & V0( const int j ) { return V(j);}
@ -184,18 +203,18 @@ public:
inline const typename T::VertexType * const & cV3( const int j ) const { return cV((j+3)%4);}
/// Shortcut to get vertex values
inline typename CoordType & P0( const int j ) { return V(j)->P();}
inline typename CoordType & P1( const int j ) { return V((j+1)%4)->P();}
inline typename CoordType & P2( const int j ) { return V((j+2)%4)->P();}
inline typename CoordType & P3( const int j ) { return V((j+3)%4)->P();}
inline const typename CoordType & P0( const int j ) const { return V(j)->P();}
inline const typename CoordType & P1( const int j ) const { return V((j+1)%4)->P();}
inline const typename CoordType & P2( const int j ) const { return V((j+2)%4)->P();}
inline const typename CoordType & P3( const int j ) const { return V((j+3)%4)->P();}
inline const typename CoordType & cP0( const int j ) const { return cV(j)->P();}
inline const typename CoordType & cP1( const int j ) const { return cV((j+1)%4)->P();}
inline const typename CoordType & cP2( const int j ) const { return cV((j+2)%4)->P();}
inline const typename CoordType & cP3( const int j ) const { return cV((j+3)%4)->P();}
inline typename CoordType &P0 (const int j) { return V(j)->P(); }
inline typename CoordType &P2 (const int j) { return V((j + 2) % 4)->P(); }
inline typename CoordType &P3 (const int j) { return V((j + 3) % 4)->P(); }
inline typename CoordType &P1 (const int j) { return V((j + 1) % 4)->P(); }
inline const typename CoordType &P0 (const int j) const { return V(j)->P(); }
inline const typename CoordType &P1 (const int j) const { return V((j + 1) % 4)->P(); }
inline const typename CoordType &P2 (const int j) const { return V((j + 2) % 4)->P(); }
inline const typename CoordType &P3 (const int j) const { return V((j + 3) % 4)->P(); }
inline const typename CoordType &cP0(const int j) const { return cV(j)->P(); }
inline const typename CoordType &cP1(const int j) const { return cV((j + 1) % 4)->P(); }
inline const typename CoordType &cP2(const int j) const { return cV((j + 2) % 4)->P(); }
inline const typename CoordType &cP3(const int j) const { return cV((j + 3) % 4)->P(); }
static bool HasVertexRef() { return true; }
static bool HasTVAdjacency() { return true; }
@ -207,6 +226,7 @@ public:
private:
typename T::VertexType *v[4];
size_t findices[4][3];
};

View File

@ -21,48 +21,28 @@
* *
****************************************************************************/
#ifndef __VCG_TETRA_MESH_H
#define __VCG_TETRA_MESH_H
#define __VCG_TETRA_MESH
#define __VCG_MESH
#ifndef _VCG_TETRA_TOPOLOGY
#define _VCG_TETRA_TOPOLOGY
#include <cassert>
#include <cstring>
#include <string>
#include <ctime>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iostream>
#include <stdexcept>
#include <limits>
#include <iterator>
#include <typeindex>
#include <wrap/callback.h>
#include <vcg/complex/exception.h>
#include <vcg/container/simple_temporary_data.h>
#include <vcg/complex/used_types.h>
#include <vcg/complex/tetrahedron/base.h>
#include <vcg/complex/tetrahedron/allocate.h>
#include <vcg/simplex/face/pos.h>
#include <vcg/simplex/face/topology.h>
#include <vcg/simplex/edge/pos.h>
#include <vcg/simplex/edge/topology.h>
#include <vcg/simplex/tetrahedron/pos.h>
#include <vcg/complex/foreach.h>
#include <vcg/complex/algorithms/update/flag.h>
#include <vcg/complex/algorithms/update/selection.h>
#include <vcg/complex/algorithms/update/topology.h>
#include <vcg/complex/algorithms/update/normal.h>
#include <vcg/complex/algorithms/update/bounding.h>
#include <vcg/complex/algorithms/mesh_assert.h>
#include <vcg/complex/append.h>
namespace vcg {
namespace tetrahedron {
/** \addtogroup tetrahedron */
/*@{*/
#undef __VCG_TETRA_MESH
#undef __VCG_MESH
/** Return a boolean that indicate if the j-th face of the tetra is a border.
@param j Index of the face
@return true if j is an face of border, false otherwise
*/
template <class TetraType>
inline bool IsBorder(TetraType const & t, const int j )
{
if(TetraType::HasTTAdjacency())
return t.cTTp(j)==&t;
assert(0);
return true;
}
#endif
}
}
#endif

View File

@ -98,8 +98,16 @@ public:
typename TT::TetraPointer &VTp() { static typename TT::TetraPointer tp = 0; assert(0); return tp; }
typename TT::TetraPointer cVTp() const { static typename TT::TetraPointer tp = 0; assert(0); return tp; }
int &VTi() { static int z = 0; return z; }
int &VTi() { static int z = 0; assert(0); return z; }
int cVTi() const { static int z = 0; assert(0); return z; }
static bool HasVTAdjacency() { return false; }
bool IsVTInitialized() const {return static_cast<const typename TT::VertexType *>(this)->cVTi()!=-1;}
void VTClear() {
if(IsVTInitialized()) {
static_cast<typename TT::VertexPointer>(this)->VTp()=0;
static_cast<typename TT::VertexPointer>(this)->VTi()=-1;
}
}
typename TT::FacePointer &VFp() { static typename TT::FacePointer fp=0; assert(0); return fp; }
typename TT::FacePointer cVFp() const { static typename TT::FacePointer fp=0; assert(0); return fp; }
@ -589,6 +597,7 @@ public:
typename T::TetraPointer &VTp() { return _tp; }
typename T::TetraPointer cVTp() const { return _tp; }
int &VTi() {return _zp; }
int cVTi() const { return _zp; }
static bool HasVTAdjacency() { return true; }
static void Name( std::vector< std::string > & name ) { name.push_back( std::string("VTAdj") ); T::Name(name); }

View File

@ -298,6 +298,27 @@ static int FofEE(const int &indexE0,const int &indexE1)
return edgesface[indexE0][indexE1];
}
// compute the barycenter
template<class TetraType>
static Point3<typename TetraType::ScalarType> Barycenter(const TetraType & t)
{
return ((t.cP(0)+t.cP(1)+t.cP(2)+t.cP(3))/(TetraType::ScalarType) 4.0);
}
// compute and return the volume of a tetrahedron
template<class TetraType>
static typename TetraType::ScalarType ComputeVolume( const TetraType & t){
return (typename TetraType::ScalarType)((( t.cP(2)-t.cP(0))^(t.cP(1)-t.cP(0) ))*(t.cP(3)-t.cP(0))/6.0);
}
/// Returns the normal to the face face of the tetrahedron t
template<class TetraType>
static Point3<typename TetraType::ScalarType> Normal( const TetraType &t,const int & face)
{
return(((t.cP(Tetra::VofF(face,1))-t.cP(Tetra::VofF(face,0)))^(t.cP(Tetra::VofF(face,2))-t.cP(Tetra::VofF(face,0)))).Normalize());
}
};
/**
@ -488,25 +509,7 @@ ScalarType ComputeAspectRatio()
}; //end Class
// compute the barycenter
template<class ScalarType>
Point3<ScalarType> Barycenter(const Tetra3<ScalarType> &t)
{
return ((t.cP(0)+t.cP(1)+t.cP(2)+t.cP(3))/(ScalarType) 4.0);
}
// compute and return the volume of a tetrahedron
template<class TetraType>
typename TetraType::ScalarType ComputeVolume( const TetraType & t){
return (typename TetraType::ScalarType)((( t.cP(2)-t.cP(0))^(t.cP(1)-t.cP(0) ))*(t.cP(3)-t.cP(0))/6.0);
}
/// Returns the normal to the face face of the tetrahedron t
template<class TetraType>
Point3<typename TetraType::ScalarType> Normal( const TetraType &t,const int &face)
{
return(((t.cP(Tetra::VofF(face,1))-t.cP(Tetra::VofF(face,0)))^(t.cP(Tetra::VofF(face,2))-t.cP(Tetra::VofF(face,0)))).Normalize());
}
/*@}*/
} // end namespace

View File

@ -403,6 +403,7 @@ public:
vv[2]=indices[fp->cV(2)];
vv[3]=indices[fp->cV(3)];
fwrite(&c,1,1,fpout);
fwrite(vv,sizeof(int),4,fpout);
@ -432,6 +433,7 @@ public:
}
else // ***** ASCII *****
{
fprintf(fpout,"%d " , 4);
fprintf(fpout,"%d %d %d %d ",
indices[fp->cV(0)], indices[fp->cV(1)], indices[fp->cV(2)], indices[fp->cV(3)]);