Commit cd46a2be authored by Sylvain Thery's avatar Sylvain Thery
Browse files

Merge cgogn:~untereiner/CGoGN

parents 692b13d0 b5d8570a
......@@ -234,7 +234,135 @@ Dart createOctahedron(typename PFP::MAP& map, bool withBoundary)
return createDiamond<PFP>(map,4, withBoundary);
}
template <typename PFP>
Dart embedPrism(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, unsigned int n, bool withBoundary, float bottom_radius, float top_radius, float height)
{
typedef typename PFP::VEC3 VEC3 ;
unsigned int m_nz = 1;
Dart dres = Dart::nil();
unsigned int nb = n*2;
std::vector<Dart> m_tableVertDarts;
m_tableVertDarts.reserve(nb);
// creation of quads around circunference and storing vertices
for (unsigned int i = 0; i < n; ++i)
{
Dart d = map.newFace(4, false);
m_tableVertDarts.push_back(d);
}
// storing a dart from the vertex pointed by phi1(phi1(d))
for (unsigned int i = 0; i < n; ++i)
{
//m_tableVertDarts.push_back(map.phi1(map.phi1(m_tableVertDarts[i])));
m_tableVertDarts.push_back(map.phi_1(m_tableVertDarts[i]));
}
// sewing the quads
for (unsigned int i = 0; i < n-1; ++i)
{
Dart d = m_tableVertDarts[i];
d = map.phi_1(d);
Dart e = m_tableVertDarts[i+1];
e = map.phi1(e);
map.sewFaces(d, e, false);
}
//sewing the last with the first
map.sewFaces(map.phi1(m_tableVertDarts[0]), map.phi_1(m_tableVertDarts[n-1]), false);
//sewing the top & bottom faces
Dart top = map.newFace(n, false);
Dart bottom = map.newFace(n, false);
dres = top;
for(unsigned int i = 0; i < n ; ++i)
{
map.sewFaces(m_tableVertDarts[i], top, false);
map.sewFaces(map.phi_1(m_tableVertDarts[n+i]), bottom, false);
top = map.phi1(top);
bottom = map.phi_1(bottom);
}
if(map.dimension() == 3 && withBoundary)
map.closeMap();
float alpha = float(2.0*M_PI/n);
float dz = height/float(m_nz);
for(unsigned int i = 0; i <= m_nz; ++i)
{
float a = float(i)/float(m_nz);
float radius = a*top_radius + (1.0f-a)*bottom_radius;
for(unsigned int j = 0; j < n; ++j)
{
float x = radius*cos(alpha*float(j));
float y = radius*sin(alpha*float(j));
position[ m_tableVertDarts[i*n+j] ] = VEC3(x, y, -height/2 + dz*float(i));
}
}
return dres;
}
template <typename PFP>
Dart embedPyramid(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position, unsigned int n, bool withBoundary, float radius, float height)
{
typedef typename PFP::VEC3 VEC3 ;
Dart dres = Dart::nil();
std::vector<Dart> m_tableVertDarts;
m_tableVertDarts.reserve(n);
// creation of triangles around circunference and storing vertices
for (unsigned int i = 0; i < n; ++i)
{
Dart d = map.newFace(3, false);
m_tableVertDarts.push_back(d);
}
// sewing the triangles
for (unsigned int i = 0; i < n-1; ++i)
{
Dart d = m_tableVertDarts[i];
d = map.phi_1(d);
Dart e = m_tableVertDarts[i+1];
e = map.phi1(e);
map.sewFaces(d, e, false);
}
//sewing the last with the first
map.sewFaces(map.phi1(m_tableVertDarts[0]), map.phi_1(m_tableVertDarts[n-1]), false);
//sewing the bottom face
Dart base = map.newFace(n, false);
dres = base;
for(unsigned int i = 0; i < n ; ++i)
{
map.sewFaces(m_tableVertDarts[i], base, false);
base = map.phi1(base);
}
if(map.dimension() == 3 && withBoundary)
map.closeMap();
float alpha = float(2.0*M_PI/n);
for(unsigned int j = 0; j < n; ++j)
{
float rad = radius;
float h = -height/2;
float x = rad*cos(alpha*float(j));
float y = rad*sin(alpha*float(j));
position[ m_tableVertDarts[j] ] = VEC3(x, y, h);
}
// top always closed in cone
position[ map.phi_1(m_tableVertDarts[0]) ] = VEC3(0.0f, 0.0f, height/2 );
//return a dart from the base
return dres;
}
......
......@@ -65,14 +65,14 @@ private:
bool m_initOk ;
Algo::Decimation::EdgeSelector<PFP>* m_selector ;
std::vector<Algo::Decimation::ApproximatorGen<PFP>*> m_approximators ;
std::vector<Algo::Decimation::PredictorGen<PFP>*> m_predictors ;
Algo::Surface::Decimation::EdgeSelector<PFP>* m_selector ;
std::vector<Algo::Surface::Decimation::ApproximatorGen<PFP>*> m_approximators ;
std::vector<Algo::Surface::Decimation::PredictorGen<PFP>*> m_predictors ;
Algo::Decimation::Approximator<PFP, VEC3>* m_positionApproximator ;
Algo::Surface::Decimation::Approximator<PFP, VEC3, EDGE>* m_positionApproximator ;
std::vector<Filter*> synthesisFilters ;
std::vector<Filter*> analysisFilters ;
std::vector<Algo::MR::Filter*> synthesisFilters ;
std::vector<Algo::MR::Filter*> analysisFilters ;
public:
Map2MR_PM(MAP& map, VertexAttribute<VEC3>& position);
......@@ -80,7 +80,7 @@ public:
~Map2MR_PM();
//create a progressive mesh (a coarser level)
void createPM(Algo::Decimation::SelectorType s, Algo::Decimation::ApproximatorType a) ;
void createPM(Algo::Surface::Decimation::SelectorType s, Algo::Surface::Decimation::ApproximatorType a) ;
void addNewLevel(unsigned int percentWantedVertices);
......@@ -94,8 +94,8 @@ public:
bool initOk() { return m_initOk; }
void addSynthesisFilter(Filter* f) { synthesisFilters.push_back(f) ; }
void addAnalysisFilter(Filter* f) { analysisFilters.push_back(f) ; }
void addSynthesisFilter(Algo::MR::Filter* f) { synthesisFilters.push_back(f) ; }
void addAnalysisFilter(Algo::MR::Filter* f) { analysisFilters.push_back(f) ; }
void clearSynthesisFilters() { synthesisFilters.clear() ; }
void clearAnalysisFilters() { analysisFilters.clear() ; }
......
......@@ -123,7 +123,7 @@ void Map2MR_PM<PFP>::createPM(Algo::Surface::Decimation::SelectorType s, Algo::S
if(! (*it)->init())
m_initOk = false ;
if((*it)->getApproximatedAttributeName() == "position")
m_positionApproximator = reinterpret_cast<Algo::Surface::Decimation::Approximator<PFP, VEC3>*>(*it) ;
m_positionApproximator = reinterpret_cast<Algo::Surface::Decimation::Approximator<PFP, VEC3, EDGE>*>(*it) ;
}
CGoGNout << "..done" << CGoGNendl ;
......
......@@ -103,12 +103,7 @@ public:
m_map.incCurrentLevel() ;
Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
if(m_position[midV] != typename PFP::VEC3(0.0f,0.0f,0.0f))
{
std::cout << "position[midV] = " << m_position[midV] << std::endl;
}
else
m_position[midV] += vc + ec + fc;
m_position[midV] += vc + ec + fc;
m_map.decCurrentLevel() ;
}
......@@ -135,13 +130,7 @@ public:
m_map.incCurrentLevel() ;
Dart midF = m_map.phi1(m_map.phi1(d));
if(m_position[midF] != typename PFP::VEC3(0.0f,0.0f,0.0f))
{
std::cout << "position[midF] = " << m_position[midF] << std::endl;
//m_position[midF] = vf + ef ;
}
else
m_position[midF] += vf + ef ;
m_position[midF] += vf + ef ;
m_map.decCurrentLevel() ;
}
......@@ -152,13 +141,7 @@ public:
m_map.incCurrentLevel() ;
Dart midE = m_map.phi1(d) ;
if(m_position[midE] != typename PFP::VEC3(0.0f,0.0f,0.0f))
{
std::cout << "position[midE] = " << m_position[midE] << std::endl;
//m_position[midE] = ve;
}
else
m_position[midE] += ve;
m_position[midE] += ve;
m_map.decCurrentLevel() ;
}
}
......
......@@ -430,6 +430,196 @@ public:
}
} ;
//template <typename PFP>
//class SHW04OddSynthesisFilter : public Algo::MR::Filter
//{
//protected:
// typename PFP::MAP& m_map;
// VertexAttribute<typename PFP::VEC3>& m_position;
//
//public:
// SHW04OddSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
// {}
//
// void operator() ()
// {
// TraversorW<typename PFP::MAP> travW(m_map) ;
// for (Dart d = travW.begin(); d != travW.end(); d = travW.next())
// {
// if(!Algo::Volume::Modelisation::Tetrahedralization::isTetrahedron<PFP>(m_map,d))
// {
// typename PFP::VEC3 vc = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
//
// unsigned int count = 0;
// typename PFP::VEC3 ec(0.0);
// Traversor3WE<typename PFP::MAP> travWE(m_map, d);
// for (Dart dit = travWE.begin(); dit != travWE.end(); dit = travWE.next())
// {
// m_map.incCurrentLevel();
// ec += m_position[m_map.phi1(dit)];
// m_map.decCurrentLevel();
// ++count;
// }
// ec /= count;
// ec *= 3;
//
// count = 0;
// typename PFP::VEC3 fc(0.0);
// Traversor3WF<typename PFP::MAP> travWF(m_map, d);
// for (Dart dit = travWF.begin(); dit != travWF.end(); dit = travWF.next())
// {
// m_map.incCurrentLevel();
// fc += m_position[m_map.phi1(m_map.phi1(dit))];
// m_map.decCurrentLevel();
// ++count;
// }
// fc /= count;
// fc *= 3;
//
// m_map.incCurrentLevel() ;
// Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
// m_position[midV] += vc + ec + fc;
// m_map.decCurrentLevel() ;
// }
// }
//
// TraversorE<typename PFP::MAP> trav(m_map) ;
// for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
// {
// if(m_map.isBoundaryEdge(d))
// {
// Dart db = m_map.findBoundaryFaceOfEdge(d);
// typename PFP::VEC3 p = loopOddVertex<PFP>(m_map, m_position, db) ;
//
// m_map.incCurrentLevel() ;
//
// Dart oddV = m_map.phi2(db) ;
// m_position[oddV] += p ;
//
// m_map.decCurrentLevel() ;
// }
// else
// {
// 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() ;
// }
// }
// }
//};
//
//template <typename PFP>
//class LoopNormalisationSynthesisFilter : public Algo::MR::Filter
//{
//protected:
// typename PFP::MAP& m_map ;
// VertexAttribute<typename PFP::VEC3>& m_position ;
//
//public:
// LoopNormalisationSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
// {}
//
// void operator() ()
// {
// TraversorV<typename PFP::MAP> trav(m_map) ;
// for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
// {
// if(m_map.isBoundaryVertex(d))
// {
// Dart db = m_map.findBoundaryFaceOfVertex(d);
//
// unsigned int degree = m_map.vertexDegreeOnBoundary(db) ;
// float n = 3.0/8.0 + 1.0/4.0 * cos(2.0 * M_PI / degree) ;
// n = 8.0/5.0 * (n * n) ;
//
// m_position[db] *= n ;
// }
// }
// }
//} ;
//
//template <typename PFP>
//class LoopEvenSynthesisFilter : public Algo::MR::Filter
//{
//protected:
// typename PFP::MAP& m_map ;
// VertexAttribute<typename PFP::VEC3>& m_position ;
//
//public:
// LoopEvenSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
// {}
//
// void operator() ()
// {
// TraversorV<typename PFP::MAP> trav(m_map) ;
// for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
// {
// if(m_map.isBoundaryVertex(d))
// {
// Dart db = m_map.findBoundaryFaceOfVertex(d);
// typename PFP::VEC3 p = loopEvenVertex<PFP>(m_map, m_position, db) ;
// m_position[db] += p ;
// }
// }
// }
//} ;
//
//
//template <typename PFP>
//class SHW04NormalisationSynthesisFilter : public Algo::MR::Filter
//{
//protected:
// typename PFP::MAP& m_map ;
// VertexAttribute<typename PFP::VEC3>& m_position ;
//
//public:
// SHW04NormalisationSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
// {}
//
// void operator() ()
// {
// m_map.incCurrentLevel() ;
// TraversorV<typename PFP::MAP> trav(m_map) ;
// for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
// {
// if(!m_map.isBoundaryVertex(d))
// {
// typename PFP::VEC3 p = typename PFP::VEC3(0);
// unsigned int degree = 0;
//
// Traversor3VW<typename PFP::MAP> travVW(m_map, d);
// for(Dart dit = travVW.begin() ; dit != travVW.end() ; dit = travVW.next())
// {
// p += SHW04Vertex<PFP>(m_map, m_position, dit);
// ++degree;
// }
//
// p /= degree;
//
// m_position[d] = p ;
// }
// }
// m_map.decCurrentLevel() ;
// }
//} ;
} // namespace Filters
} // namespace Primal
......
/*******************************************************************************
* 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 __MAP3MR_PM__
#define __MAP3MR_PM__
#include "Topology/map/embeddedMap3.h"
#include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor3.h"
#include "Container/attributeContainer.h"
#include "Algo/DecimationVolumes/selector.h"
#include "Algo/DecimationVolumes/edgeSelector.h"
#include "Algo/DecimationVolumes/geometryApproximator.h"
#include "Algo/Multiresolution/filter.h"
namespace CGoGN
{
namespace Algo
{
namespace Volume
{
namespace MR
{
template <typename PFP>
class Map3MR_PM
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
private:
MAP& m_map ;
VertexAttribute<VEC3>& m_position;
bool m_initOk ;
Algo::Volume::Decimation::EdgeSelector<PFP>* m_selector ;
std::vector<Algo::Volume::Decimation::ApproximatorGen<PFP>*> m_approximators ;
std::vector<Algo::Volume::Decimation::PredictorGen<PFP>*> m_predictors ;
Algo::Volume::Decimation::Approximator<PFP, VEC3>* m_positionApproximator ;
std::vector<Filter*> synthesisFilters ;
std::vector<Filter*> analysisFilters ;
public:
Map3MR_PM(MAP& map, VertexAttribute<VEC3>& position);
~Map3MR_PM();
//create a progressive mesh (a coarser level)
void createPM(Algo::Volume::Decimation::SelectorType s, Algo::Volume::Decimation::ApproximatorType a) ;
void addNewLevel(unsigned int percentWantedVertices);
void collapseEdge(Dart d);
//coarsen the mesh -> analysis
void coarsen() ;
//refine the mesh -> synthesis
void refine() ;
bool initOk() { return m_initOk; }
void addSynthesisFilter(Filter* f) { synthesisFilters.push_back(f) ; }
void addAnalysisFilter(Filter* f) { analysisFilters.push_back(f) ; }
void clearSynthesisFilters() { synthesisFilters.clear() ; }
void clearAnalysisFilters() { analysisFilters.clear() ; }
/**
* Given the vertex of d in the current level,
* return a dart of from the vertex of the current level
*/
Dart vertexOrigin(Dart d) ;
// /**
// * Return the level of the vertex of d in the current level map
// */
// unsigned int vertexLevel(Dart d);
} ;
} // namespace Multiresolution
} // namespace Surface
} // namespace Algo
} // namespace CGoGN
#include "Algo/Multiresolution/Map3MR/map3MR_PM.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 "Container/attributeMultiVector.h"
namespace CGoGN
{
namespace Algo
{
namespace Volume
{
namespace MR
{
template <typename PFP>
Map3MR_PM<PFP>::Map3MR_PM(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position) : m_map(map), m_position(position)
{
}
template <typename PFP>
Map3MR_PM<PFP>::~Map3MR_PM()
{
if(m_selector)
delete m_selector ;
for(typename std::vector<Algo::Volume::Decimation::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
delete (*it) ;
for(typename std::vector<Algo::Volume::Decimation::PredictorGen<PFP>*>::iterator it = m_predictors.begin(); it != m_predictors.end(); ++it)
delete (*it) ;
}