Commit 1ff6b8b3 authored by untereiner's avatar untereiner
Browse files

Regular Refinement ok - lerp filters

parent 88a0b0c1
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "Algo/Geometry/boundingbox.h" #include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h" #include "Algo/Geometry/normal.h"
#include "Algo/Geometry/convexity.h"
using namespace CGoGN ; using namespace CGoGN ;
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library 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 Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __ALGO_GEOMETRY_CONVEXITY_H__
#define __ALGO_GEOMETRY_CONVEXITY_H__
namespace CGoGN
{
namespace Algo
{
namespace Geometry
{
/**
* Test if an edge bounded by 2 faces is convex or concave
*/
template <typename PFP>
bool isEdgeConvexe(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ;
} // namespace Geometry
} // namespace Algo
} // namespace CGoGN
#include "Algo/Geometry/convexity.hpp"
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library 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 Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Geometry/basic.h"
#include "Algo/Geometry/normal.h"
#include <limits>
namespace CGoGN
{
namespace Algo
{
namespace Geometry
{
template <typename PFP>
bool isEdgeConvexe(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
{
typedef typename PFP::VEC3 VEC3 ;
const VEC3 n = faceNormal<PFP>(map, d, position);
const VEC3 e = Algo::Geometry::vectorOutOfDart<PFP>(map, map.phi1(map.phi2(d)), position) ;
if((e * n) > 0)
return false;
else
return true;
}
} // namespace Geometry
} // namespace Algo
} // namespace CGoGN
...@@ -125,6 +125,20 @@ Dart createQuadrangularPyramid(typename PFP::MAP& map, bool withBoundary = true) ...@@ -125,6 +125,20 @@ Dart createQuadrangularPyramid(typename PFP::MAP& map, bool withBoundary = true)
template <typename PFP> template <typename PFP>
Dart createOctahedron(typename PFP::MAP& map, bool withBoundary = true); Dart createOctahedron(typename PFP::MAP& map, bool withBoundary = true);
//TODO optimize
template <typename PFP>
bool isPyra(typename PFP::MAP& map, Dart d, unsigned int thread = 0);
//TODO optimize
template <typename PFP>
bool isPrism(typename PFP::MAP& map, Dart d, unsigned int thread = 0);
/** /**
......
...@@ -201,6 +201,62 @@ Dart createOctahedron(typename PFP::MAP& map, bool withBoundary) ...@@ -201,6 +201,62 @@ Dart createOctahedron(typename PFP::MAP& map, bool withBoundary)
template <typename PFP>
bool isPyra(typename PFP::MAP& map, Dart d, unsigned int thread)
{
unsigned int nbFacesT = 0;
unsigned int nbFacesQ = 0;
//Test the number of faces end its valency
Traversor3WF<typename PFP::MAP> travWF(map, d, false, thread);
for(Dart dit = travWF.begin() ; dit != travWF.end(); dit = travWF.next())
{
//increase the number of faces
if(map.faceDegree(dit) == 3)
nbFacesT++;
else if(map.faceDegree(dit) == 4)
nbFacesQ++;
else
return false;
}
if((nbFacesT != 4) || (nbFacesQ != 1)) //too much faces
return false;
return true;
}
template <typename PFP>
bool isPrism(typename PFP::MAP& map, Dart d, unsigned int thread)
{
unsigned int nbFacesT = 0;
unsigned int nbFacesQ = 0;
//Test the number of faces end its valency
Traversor3WF<typename PFP::MAP> travWF(map, d, false, thread);
for(Dart dit = travWF.begin() ; dit != travWF.end(); dit = travWF.next())
{
//increase the number of faces
if(map.faceDegree(dit) == 3)
nbFacesT++;
else if(map.faceDegree(dit) == 4)
nbFacesQ++;
else
return false;
}
if((nbFacesT != 2) || (nbFacesQ != 3)) //too much faces
return false;
return true;
}
template <typename PFP> template <typename PFP>
void explodPolyhedron(typename PFP::MAP& map, Dart d, VertexAttribute<typename PFP::VEC3>& position) void explodPolyhedron(typename PFP::MAP& map, Dart d, VertexAttribute<typename PFP::VEC3>& position)
{ {
......
...@@ -46,64 +46,232 @@ namespace Filters ...@@ -46,64 +46,232 @@ namespace Filters
/********************************************************************************* /*********************************************************************************
* SYNTHESIS FILTERS * SYNTHESIS FILTERS
*********************************************************************************/ *********************************************************************************/
// Quad refinement
template <typename PFP> template <typename PFP>
class LerpEdgeSynthesisFilter : public Filter class LerpQuadOddSynthesisFilter : public Filter
{ {
protected: protected:
typename PFP::MAP& m_map ; typename PFP::MAP& m_map ;
VertexAttribute<typename PFP::VEC3>& m_position ; VertexAttribute<typename PFP::VEC3>& m_position ;
public: public:
LerpEdgeSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p) LerpQuadOddSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
{} {}
void operator() () void operator() ()
{ {
TraversorE<typename PFP::MAP> trav(m_map) ; TraversorF<typename PFP::MAP> travF(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
{
typename PFP::VEC3 vf(0.0);
typename PFP::VEC3 ef(0.0);
unsigned int count = 0;
Traversor2FE<typename PFP::MAP> travFE(m_map, d);
for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
{ {
typename PFP::VEC3 p = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5); vf += m_position[dit];
m_map.incCurrentLevel();
ef += m_position[m_map.phi1(dit)];
m_map.decCurrentLevel();
++count;
}
ef /= count;
ef *= 2.0;
vf /= count;
m_map.incCurrentLevel() ; m_map.incCurrentLevel() ;
Dart midF = m_map.phi1(m_map.phi1(d));
m_position[midF] += vf + ef ;
m_map.decCurrentLevel() ;
}
TraversorE<typename PFP::MAP> travE(m_map) ;
for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
{
typename PFP::VEC3 ve = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);
m_map.incCurrentLevel() ;
Dart midV = m_map.phi1(d) ; Dart midV = m_map.phi1(d) ;
m_position[midV] = p ; m_position[midV] += ve ;
m_map.decCurrentLevel() ;
}
}
};
// Tri/quad refinement
template <typename PFP>
class LerpTriQuadOddSynthesisFilter : public Filter
{
protected:
typename PFP::MAP& m_map ;
VertexAttribute<typename PFP::VEC3>& m_position ;
public:
LerpTriQuadOddSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
{}
void operator() ()
{
TraversorF<typename PFP::MAP> travF(m_map) ;
for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
{
if(m_map.faceDegree(d) != 3)
{
typename PFP::VEC3 vf(0.0);
typename PFP::VEC3 ef(0.0);
unsigned int count = 0;
Traversor2FE<typename PFP::MAP> travFE(m_map, d);
for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
{
vf += m_position[dit];
m_map.incCurrentLevel();
ef += m_position[m_map.phi1(dit)];
m_map.decCurrentLevel();
++count;
}
ef /= count;
ef *= 2.0;
vf /= count;
m_map.incCurrentLevel() ;
Dart midF = m_map.phi1(m_map.phi1(d));
m_position[midF] += vf + ef ;
m_map.decCurrentLevel() ; m_map.decCurrentLevel() ;
} }
} }
} ;
TraversorE<typename PFP::MAP> travE(m_map) ;
for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
{
typename PFP::VEC3 ve = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);
m_map.incCurrentLevel() ;
Dart midV = m_map.phi1(d) ;
m_position[midV] += ve ;
m_map.decCurrentLevel() ;
}
}
};
/*********************************************************************************
* ANALYSIS FILTERS
*********************************************************************************/
// Quad refinement
template <typename PFP> template <typename PFP>
class LerpFaceSynthesisFilter : public Filter class LerpQuadOddAnalysisFilter : public Filter
{ {
protected: protected:
typename PFP::MAP& m_map ; typename PFP::MAP& m_map ;
VertexAttribute<typename PFP::VEC3>& m_position ; VertexAttribute<typename PFP::VEC3>& m_position ;
public: public:
LerpFaceSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p) LerpQuadOddAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
{} {}
void operator() () void operator() ()
{ {
TraversorF<typename PFP::MAP> trav(m_map) ; TraversorE<typename PFP::MAP> travE(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
{ {
typename PFP::VEC3 p = Algo::Geometry::faceCentroid<PFP>(m_map, d, m_position); typename PFP::VEC3 ve = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);
m_map.incCurrentLevel() ; m_map.incCurrentLevel() ;
if(m_map.faceDegree(d) != 3) Dart midV = m_map.phi1(d) ;
m_position[midV] -= ve ;
m_map.decCurrentLevel() ;
}
TraversorF<typename PFP::MAP> travF(m_map) ;
for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
{ {
Dart midF = m_map.phi1(m_map.phi1(d)); typename PFP::VEC3 vf(0.0);
m_position[midF] = p ; typename PFP::VEC3 ef(0.0);
unsigned int count = 0;
Traversor2FE<typename PFP::MAP> travFE(m_map, d);
for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
{
vf += m_position[dit];
m_map.incCurrentLevel();
ef += m_position[m_map.phi1(dit)];
m_map.decCurrentLevel();
++count;
} }
ef /= count;
ef *= 2.0;
vf /= count;
m_map.incCurrentLevel() ;
Dart midF = m_map.phi1(m_map.phi1(d));
m_position[midF] -= vf + ef ;
m_map.decCurrentLevel() ; m_map.decCurrentLevel() ;
}
}
};
// Tri/quad refinement
template <typename PFP>
class LerpTriQuadOddAnalysisFilter : public Filter
{
protected:
typename PFP::MAP& m_map ;
VertexAttribute<typename PFP::VEC3>& m_position ;
public:
LerpTriQuadOddAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
{}
void operator() ()
{
TraversorE<typename PFP::MAP> travE(m_map) ;
for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
{
typename PFP::VEC3 ve = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);
m_map.incCurrentLevel() ;
Dart midV = m_map.phi1(d) ;
m_position[midV] -= ve ;
m_map.decCurrentLevel() ;
} }
TraversorF<typename PFP::MAP> travF(m_map) ;
for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
{
if(m_map.faceDegree(d) != 3)
{
typename PFP::VEC3 vf(0.0);
typename PFP::VEC3 ef(0.0);
unsigned int count = 0;
Traversor2FE<typename PFP::MAP> travFE(m_map, d);
for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
{
vf += m_position[dit];
m_map.incCurrentLevel();
ef += m_position[m_map.phi1(dit)];
m_map.decCurrentLevel();
++count;
} }
} ; ef /= count;
ef *= 2.0;
vf /= count;
m_map.incCurrentLevel() ;
Dart midF = m_map.phi1(m_map.phi1(d));
m_position[midF] -= vf + ef ;
m_map.decCurrentLevel() ;
}
}
}
};
} // namespace Filters } // namespace Filters
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <cmath> #include <cmath>
#include "Algo/Geometry/centroid.h" #include "Algo/Geometry/centroid.h"
#include "Algo/Modelisation/tetrahedralization.h" #include "Algo/Modelisation/tetrahedralization.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Multiresolution/filter.h" #include "Algo/Multiresolution/filter.h"
namespace CGoGN namespace CGoGN
...@@ -51,6 +52,69 @@ namespace Filters ...@@ -51,6 +52,69 @@ namespace Filters
/* Linear Interpolation /* Linear Interpolation
*********************************************************************************/ *********************************************************************************/
template <typename PFP>
class LerpOddSynthesisFilter : public Filter
{
protected:
typename PFP::MAP& m_map ;
VertexAttribute<typename PFP::VEC3>& m_position ;
public:
LerpOddSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
{}
void operator() ()
{
TraversorE<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
typename PFP::VEC3 p = (m_position[d] + m_position[m_map.phi2(d)]) * typename PFP::REAL(0.5);
m_map.incCurrentLevel() ;
Dart midV = m_map.phi2(d) ;
m_position[midV] += p ;
m_map.decCurrentLevel() ;
}
TraversorF<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
typename PFP::VEC3 p = Algo::Geometry::faceCentroid<PFP>(m_map, d, m_position);
m_map.incCurrentLevel() ;
Dart midF = m_map.phi2(m_map.phi1(d));
m_position[midF] += p ;
m_map.decCurrentLevel() ;
}
TraversorW<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
if(!Algo::Modelisation::Tetrahedralization::isTetrahedron<PFP>(m_map,d) && !Algo::Modelisation::isPrism<PFP>(m_map,d) && !Algo::Modelisation::isPyra<PFP>(m_map,d))
{
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(m_map.phi1(d)));
m_position[midV] += p ;
m_map.decCurrentLevel() ;
}
}
}
};
template <typename PFP> template <typename PFP>
class LerpEdgeSynthesisFilter : public Filter class LerpEdgeSynthesisFilter : public Filter
{ {
...@@ -155,21 +219,18 @@ public: ...@@ -155,21 +219,18 @@ public:
{ {
TraversorW<typename PFP::MAP> trav(m_map) ; TraversorW<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next()) for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{