Commit bb982acb authored by untereiner's avatar untereiner

adding bertram wavelets surface/volumes and sqrt3 lazy wavelet

parent 6a58a080
......@@ -443,8 +443,10 @@ void swapGen3To2(typename PFP::MAP& map, Dart d)
template <typename PFP>
void swapGen2To3(typename PFP::MAP& map, Dart d)
{
unsigned int n = map.edgeDegree(d);
//- a single 2-3 swap, followed by n − 3 3-2 swaps, or
// a single 4-4 swap, followed by n − 4 3-2 swaps.
//- a single 4-4 swap, followed by n − 4 3-2 swaps.
}
......
This diff is collapsed.
......@@ -99,34 +99,6 @@ inline double omega0(unsigned int n)
* Lazy Wavelet
*********************************************************************************/
template <typename PFP>
class Sqrt3InitVertexSynthesisFilter : public Filter
{
protected:
typename PFP::MAP& m_map ;
VertexAttribute<typename PFP::VEC3>& m_position ;
bool first;
public:
Sqrt3InitVertexSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p), first(true)
{}
void operator() ()
{
if(first)
{
TraversorV<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
m_map.incCurrentLevel() ;
m_position[d] = typename PFP::VEC3(0.0); // ou phi2(d)
m_map.decCurrentLevel() ;
}
first = false;
}
}
} ;
template <typename PFP>
class Sqrt3FaceSynthesisFilter : public Filter
{
......@@ -154,12 +126,19 @@ public:
p1 *= 1.0 / 3.0 ;
p2 *= 1.0 / 3.0 ;
m_map.incCurrentLevel() ;
m_position[m_map.phi2(d)] += p0 + p1 + p2 ;
if(m_map.isBoundaryFace(d))
{
Dart df = m_map.findBoundaryEdgeOfFace(d);
m_map.incCurrentLevel() ;
m_position[m_map.phi_1(m_map.phi2(df))] += p0 + p1 + p2 ;
}
else
{
m_map.incCurrentLevel() ;
m_position[m_map.phi2(d)] += p0 + p1 + p2 ;
}
m_map.decCurrentLevel() ;
}
}
} ;
......@@ -180,36 +159,70 @@ public:
TraversorV<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
typename PFP::VEC3 nf(0) ;
unsigned int degree = 0 ;
if(m_map.isBoundaryVertex(d))
{
Dart df = m_map.findBoundaryEdgeOfVertex(d);
m_map.incCurrentLevel() ;
Dart df = m_map.phi2(m_map.phi1(d));
if((m_map.getCurrentLevel()%2 == 0))
{
typename PFP::VEC3 np(0) ;
typename PFP::VEC3 nl(0) ;
typename PFP::VEC3 nr(0) ;
Traversor2VVaE<typename PFP::MAP> trav(m_map, df) ;
for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
{
++degree ;
nf += m_position[it] ;
typename PFP::VEC3 pi = m_position[df];
typename PFP::VEC3 pi_1 = m_position[m_map.phi_1(df)];
typename PFP::VEC3 pi1 = m_position[m_map.phi1(df)];
np += pi_1 * 4 + pi * 19 + pi1 * 4;
np /= 27;
nl += pi_1 * 10 + pi * 16 + pi1;
nl /= 27;
nr += pi_1 + pi * 16 + pi1 * 10;
nr /= 27;
m_map.incCurrentLevel() ;
m_position[df] = np;
m_position[m_map.phi_1(df)] = nl;
m_position[m_map.phi1(df)] = nr;
m_map.decCurrentLevel() ;
}
}
m_map.decCurrentLevel() ;
else
{
typename PFP::VEC3 nf(0) ;
unsigned int degree = 0 ;
float alpha = 1.0/9.0 * ( 4.0 - 2.0 * cos(2.0 * M_PI / degree));
float teta = 1 - (3 * alpha) / 2;
float sigma = (3 * alpha) / (2 * degree);
m_map.incCurrentLevel() ;
Dart df = m_map.phi2(m_map.phi1(d));
nf *= sigma;
Traversor2VVaE<typename PFP::MAP> trav(m_map, df) ;
for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
{
++degree ;
nf += m_position[it] ;
typename PFP::VEC3 vp = m_position[d] ;
vp *= teta ;
}
m_map.decCurrentLevel() ;
m_map.incCurrentLevel() ;
float alpha = 1.0/9.0 * ( 4.0 - 2.0 * cos(2.0 * M_PI / degree));
float teta = 1 - (3 * alpha) / 2;
float sigma = (3 * alpha) / (2 * degree);
m_position[df] = vp + nf;
nf *= sigma;
m_map.decCurrentLevel() ;
typename PFP::VEC3 vp = m_position[d] ;
vp *= teta ;
m_map.incCurrentLevel() ;
m_position[df] = vp + nf;
m_map.decCurrentLevel() ;
}
}
}
} ;
......
......@@ -56,6 +56,44 @@ public:
bool operator() (Dart d)
{
if(m_map.isBoundaryVertex(d))
{
Dart df = m_map.findBoundaryEdgeOfVertex(d);
if(m_map.getDartLevel(df) < m_map.getCurrentLevel())
{
if((m_map.getCurrentLevel()%2 == 0))
{
m_map.decCurrentLevel() ;
typename PFP::VEC3 np(0) ;
typename PFP::VEC3 nl(0) ;
typename PFP::VEC3 nr(0) ;
typename PFP::VEC3 pi = m_position[df];
typename PFP::VEC3 pi_1 = m_position[m_map.phi_1(df)];
typename PFP::VEC3 pi1 = m_position[m_map.phi1(df)];
np += pi_1 * 4 + pi * 19 + pi1 * 4;
np /= 27;
nl += pi_1 * 10 + pi * 16 + pi1;
nl /= 27;
nr += pi_1 + pi * 16 + pi1 * 10;
nr /= 27;
m_map.incCurrentLevel() ;
m_position[df] = np;
m_position[m_map.phi_1(df)] = nl;
m_position[m_map.phi1(df)] = nr;
return false;
}
}
}
m_map.decCurrentLevel() ;
typename PFP::VEC3 np(0) ;
......@@ -97,8 +135,8 @@ public:
m_map.decCurrentLevel() ;
Dart d1 = m_map.phi1(d1) ;
Dart d2 = m_map.phi1(d2) ;
Dart d1 = m_map.phi1(d0) ;
Dart d2 = m_map.phi1(d1) ;
typename PFP::VEC3 p0 = m_position[d0] ;
typename PFP::VEC3 p1 = m_position[d1] ;
......
......@@ -131,6 +131,11 @@ protected:
*/
void splitFace(Dart d, Dart e) ;
/**
*
*/
void flipBackEdge(Dart d);
/***************************************************
* SUBDIVISION *
***************************************************/
......@@ -151,6 +156,11 @@ public:
*/
unsigned int subdivideFace(Dart d, bool triQuad = true, bool OneLevelDifference = true);
/**
*
*/
unsigned int subdivideFaceSqrt3(Dart d);
/**
* coarsen the face of d from the next level
*/
......
......@@ -302,6 +302,27 @@ void Map2MR<PFP>::splitFace(Dart d, Dart e)
m_map.splitFace(d, e) ;
}
template <typename PFP>
void Map2MR<PFP>::flipBackEdge(Dart d)
{
Dart dprev = m_map.phi_1(d) ;
Dart dnext = m_map.phi_1(d) ;
Dart d2 = m_map.phi2(d);
Dart d2prev = m_map.phi_1(d2) ;
Dart d2next = m_map.phi_1(d2) ;
m_map.duplicateDart(d);
m_map.duplicateDart(dprev);
m_map.duplicateDart(dnext);
m_map.duplicateDart(d2);
m_map.duplicateDart(d2prev);
m_map.duplicateDart(d2next);
m_map.flipBackEdge(d) ;
}
template <typename PFP>
void Map2MR<PFP>::subdivideEdge(Dart d)
{
......@@ -369,7 +390,7 @@ unsigned int Map2MR<PFP>::subdivideFace(Dart d, bool triQuad, bool OneLevelDiffe
m_map.setCurrentLevel(fLevel + 1) ; // go to the next level to perform face subdivision
if(triQuad & degree == 3) // if subdividing a triangle
if(triQuad && degree == 3) // if subdividing a triangle
{
Dart dd = m_map.phi1(old) ;
Dart e = m_map.phi1(dd) ;
......@@ -468,6 +489,76 @@ void Map2MR<PFP>::coarsenFace(Dart d)
m_map.removeLevelBack() ;
}
template <typename PFP>
unsigned int Map2MR<PFP>::subdivideFaceSqrt3(Dart d)
{
assert(m_map.getDartLevel(d) <= m_map.getCurrentLevel() || !"subdivideFace : called with a dart inserted after current level") ;
//assert(!faceIsSubdivided(d) || !"Trying to subdivide an already subdivided face") ;
unsigned int fLevel = faceLevel(d) ;
Dart old = faceOldestDart(d) ;
m_map.pushLevel() ;
m_map.setCurrentLevel(fLevel) ; // go to the level of the face to subdivide its edges
if(m_map.getCurrentLevel() == m_map.getMaxLevel())
m_map.addLevelBack();
m_map.setCurrentLevel(fLevel + 1) ; // go to the next level to perform face subdivision
//if it is an even level (triadic refinement) and a boundary face
if((m_map.getCurrentLevel()%2 == 0) && m_map.isBoundaryFace(d))
{
// //find the boundary edge
// Dart df = m_map.findBoundaryEdgeOfFace(d);
// //trisection of the boundary edge
// cutEdge(df) ;
// splitFace(m_map.phi2(df), m_map.phi1(m_map.phi1(m_map.phi2(df)))) ;
// (*vertexVertexFunctor)(m_map.phi1(df) ;
//
// df = m_map.phi1(df);
// cutEdge(df) ;
// splitFace(m_map.phi2(df), m_map.phi1(m_map.phi1(m_map.phi2(df)))) ;
// //(*vertexVertexFunctor)(m_map.phi1(df)) ;
}
else
{
Dart d1 = m_map.phi1(old);
(*vertexVertexFunctor)(old) ;
splitFace(old, d1) ;
(*vertexVertexFunctor)(d1) ;
cutEdge(m_map.phi_1(old)) ;
Dart x = m_map.phi2(m_map.phi_1(old)) ;
Dart dd = m_map.phi1(m_map.phi1(m_map.phi1((x))));
while(dd != x)
{
(*vertexVertexFunctor)(dd) ;
Dart next = m_map.phi1(dd) ;
splitFace(dd, m_map.phi1(x)) ;
dd = next ;
}
Dart cd = m_map.phi2(x);
(*faceVertexFunctor)(cd) ;
Dart dit = cd;
do
{
Dart dit12 = m_map.phi2(m_map.phi1(dit));
dit = m_map.phi2(m_map.phi_1(dit));
if(faceLevel(dit12) == (fLevel + 1) && !m_map.isBoundaryEdge(dit12))
flipBackEdge(dit12);
}
while(dit != cd);
}
m_map.popLevel() ;
return fLevel ;
}
} // namespace Adaptive
} // namespace Primal
......
......@@ -79,6 +79,10 @@ public:
void analysis() ;
void synthesis() ;
//threshold
void filtering();
} ;
} // namespace Regular
......
......@@ -163,9 +163,14 @@ void Map2MR<PFP>::addNewLevelSqrt3(bool embedNewVertices)
if((m_map.getCurrentLevel()%2 == 0) && m_map.isBoundaryFace(dit))
{
//find the boundary edge
//Dart df = m_map.findBoundaryEdgeOfFace(dit);
Dart df = m_map.findBoundaryEdgeOfFace(dit);
//trisection of the boundary edge
m_map.cutEdge(df) ;
m_map.splitFace(m_map.phi2(df), m_map.phi1(m_map.phi1(m_map.phi2(df)))) ;
df = m_map.phi1(df);
m_map.cutEdge(df) ;
m_map.splitFace(m_map.phi2(df), m_map.phi1(m_map.phi1(m_map.phi2(df)))) ;
}
else
{
......@@ -199,7 +204,7 @@ void Map2MR<PFP>::addNewLevelSqrt3(bool embedNewVertices)
TraversorE<typename PFP::MAP> te(m_map) ;
for (Dart dit = te.begin(); dit != te.end(); dit = te.next())
{
if(m_map.getDartLevel(dit) < m_map.getCurrentLevel() && !m_map.isBoundaryEdge(dit))
if(!m_map.isBoundaryEdge(dit) && m_map.getDartLevel(dit) < m_map.getCurrentLevel())
m_map.flipEdge(dit);
}
......
......@@ -98,11 +98,10 @@ public:
typename PFP::VEC3 p = Algo::Geometry::faceCentroid<PFP>(m_map, d, m_position);
m_map.incCurrentLevel() ;
if(m_map.faceDegree(d) != 3)
{
Dart midF = m_map.phi2(m_map.phi1(d));
m_position[midF] = p ;
}
Dart midF = m_map.phi2(m_map.phi1(d));
m_position[midF] = p ;
m_map.decCurrentLevel() ;
}
......@@ -135,11 +134,36 @@ public:
Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
m_position[midV] = p ;
}
else
{
Dart midV = m_map.phi_1(m_map.phi2(d));
m_position[midV] = p;
}
m_map.decCurrentLevel() ;
}
}
} ;
template <typename PFP>
class LerpSqrt3VolumeSynthesisFilter : public Filter
{
protected:
typename PFP::MAP& m_map ;
VertexAttribute<typename PFP::VEC3>& m_position ;
public:
LerpSqrt3VolumeSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
{}
void operator() ()
{
TraversorW<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
typename PFP::VEC3 p = Algo::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
m_map.incCurrentLevel() ;
Dart midV = m_map.phi_1(m_map.phi2(d));
m_position[midV] = p;
m_map.decCurrentLevel() ;
}
......
......@@ -58,11 +58,6 @@ public:
typedef typename PFP::REAL REAL ;
protected:
enum SubdivideType
{
S_TRI,
S_QUAD
} ;
MAP& m_map;
bool shareVertexEmbeddings;
......@@ -74,33 +69,6 @@ protected:
public:
Map3MR(MAP& map);
private:
/*! @name Topological helping functions
*
*************************************************************************/
//@{
//!
/*!
*/
void swapEdges(Dart d, Dart e);
void splitSurfaceInVolume(std::vector<Dart>& vd, bool firstSideClosed = true, bool secondSideClosed = false);
Dart cutEdgeInVolume(Dart d);
void splitFaceInVolume(Dart d, Dart e);
void splitVolume(std::vector<Dart>& vd);
void saveRelationsAroundVertex(Dart d, std::vector<std::pair<Dart, Dart> >& vd);
void unsewAroundVertex(std::vector<std::pair<Dart, Dart> >& vd);
Dart cutEdge(Dart d) ;
void splitFace(Dart d, Dart e) ;
//@}
public:
/*! @name Cells informations
*
*************************************************************************/
......@@ -149,33 +117,58 @@ public:
bool volumeIsSubdivided(Dart d);
//@}
/*! @name Subdivision
*
*************************************************************************/
protected:
//@{
//! Subdivide the edge of d to the next level
/*! @param d Dart from the edge
*/
void subdivideEdge(Dart d) ;
//! Subdivide the edge of d to the next level
/*! @param d Dart frome the face
*/
void subdivideFace(Dart d, SubdivideType sType = S_QUAD) ;
// /*! @name Topological helping functions
// *
// *************************************************************************/
// //@{
// //!
// /*!
// */
// void swapEdges(Dart d, Dart e);
//
// void splitSurfaceInVolume(std::vector<Dart>& vd, bool firstSideClosed = true, bool secondSideClosed = false);
//
// Dart cutEdgeInVolume(Dart d);
//
// void splitFaceInVolume(Dart d, Dart e);
//
// void splitVolume(std::vector<Dart>& vd);
//
// void saveRelationsAroundVertex(Dart d, std::vector<std::pair<Dart, Dart> >& vd);
//
// void unsewAroundVertex(std::vector<std::pair<Dart, Dart> >& vd);
//
// Dart cutEdge(Dart d) ;
// void splitFace(Dart d, Dart e) ;
// //@}
//
// /*! @name Subdivision
// *
// *************************************************************************/
// //@{
// //! Subdivide the edge of d to the next level
// /*! @param d Dart from the edge
// */
// void subdivideEdge(Dart d) ;
//
// //! Subdivide the edge of d to the next level
// /*! @param d Dart frome the face
// */
// void subdivideFace(Dart d, bool triQuad) ;
public:
//! Subdivide the volume of d to hexahedral cells
/*! @param d Dart from the volume
*/
void subdivideVolume(Dart d) ;
//! Subdivide the volume of d to hexahedral cells
/*! @param d Dart from the volume
*/
void subdivideVolumeTetOcta(Dart d) ;
void subdivideVolumeTetOctaTemp(Dart d);
// //! Subdivide the volume of d to hexahedral cells
// /*! @param d Dart from the volume
// */
// unsigned int subdivideVolume(Dart d, bool triQuad = true, bool OneLevelDifference = true);
//
// //! Subdivide the volume of d to hexahedral cells
// /*! @param d Dart from the volume
// */
// void subdivideVolumeTetOcta(Dart d) ;
//
// void subdivideVolumeTetOctaTemp(Dart d);
//@}
/*! @name Vertices Attributes management
......
......@@ -70,6 +70,8 @@ protected:
public:
Map3MR(MAP& map);
~Map3MR();
private:
/*! @name Topological helping functions
*
......
......@@ -45,6 +45,19 @@ Map3MR<PFP>::Map3MR(typename PFP::MAP& map) :
}
template <typename PFP>
Map3MR<PFP>::~Map3MR()
{
unsigned int level = m_map.getCurrentLevel();
unsigned int maxL = m_map.getMaxLevel();
for(unsigned int i = maxL ; i > level ; --i)
m_map.removeLevelBack();
for(unsigned int i = 0 ; i < level ; ++i)
m_map.removeLevelFront();
}
/************************************************************************
* Topological helping functions *
......@@ -138,6 +151,7 @@ void Map3MR<PFP>::addNewLevelSqrt3(bool embedNewVertices)
Algo::Modelisation::Tetrahedralization::flip1To4<PFP>(m_map, dit);
}
/*
//
// 2-3 swap of all old interior faces
//
......@@ -150,7 +164,7 @@ void Map3MR<PFP>::addNewLevelSqrt3(bool embedNewVertices)
Algo::Modelisation::Tetrahedralization::swap2To3<PFP>(m_map, dit);
}
}
/*
//
// 1-3 flip of all boundary tetrahedra
//
......@@ -364,37 +378,26 @@ void Map3MR<PFP>::addNewLevelHexa(bool embedNewVertices)
m_map.duplicateDarts(m_map.getMaxLevel());
m_map.setCurrentLevel(m_map.getMaxLevel());
// if(!shareVertexEmbeddings)
// {
// //create the new level with the old one
// for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
// {
// unsigned int index = (*m_mrDarts[m_mrCurrentLevel])[i] ;
// (*m_embeddings[VERTEX])[index] = EMBNULL ; // set vertex embedding to EMBNULL if no sharing
// }
// }
//subdivision
//1. cut edges
TraversorE<typename PFP::MAP> travE(m_map);
for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
{
// if(!shareVertexEmbeddings)
// {
// if(getEmbedding<VERTEX>(d) == EMBNULL)
// embedNewCell<VERTEX>(d) ;
// if(getEmbedding<VERTEX>(phi1(d)) == EMBNULL)
// embedNewCell<VERTEX>(phi1(d)) ;
// }
if(!shareVertexEmbeddings && embedNewVertices)
{
if(m_map.template getEmbedding<VERTEX>(d) == EMBNULL)
m_map.template embedNewCell<VERTEX>(d) ;
if(m_map.template getEmbedding<VERTEX>(m_map.phi1(d)) == EMBNULL)
m_map.template embedNewCell<VERTEX>(d) ;
}
m_map.cutEdge(d) ;
travE.skip(d) ;
travE.skip(m_map.phi1(d)) ;
// When importing MR files : activated for DEBUG
// if(embedNewVertices)
// embedNewCell<VERTEX>(phi1(d)) ;
if(embedNewVertices)
m_map.template embedNewCell<VERTEX>(m_map.phi1(d)) ;
}
std::cout << "current Level = " << m_map.getCurrentLevel() << std::endl;
//2. split faces - quadrangule faces
TraversorF<typename PFP::MAP> travF(m_map) ;
......@@ -412,9 +415,8 @@ void Map3MR<PFP>::addNewLevelHexa(bool embedNewVertices)
m_map.cutEdge(ne) ; // cut the new edge to insert the central vertex
travF.skip(dd) ;
// When importing MR files : activated for DEBUG
// if(embedNewVertices)
// embedNewCell<VERTEX>(phi1(ne)) ;
if(embedNewVertices)
m_map.template embedNewCell<VERTEX>(m_map.phi1(ne)) ;