Commit dde45350 authored by untereiner's avatar untereiner

begin volumetric progressive meshes

parent aae843c0
......@@ -81,7 +81,6 @@ void decimate(
//Next Operator to perform
Operator<PFP> *op;
//if(!selector->nextOperator(&op))
if((op = selector->nextOperator()) == NULL)
break;
......@@ -98,7 +97,7 @@ void decimate(
//Perform the topological operation and
//compute the number of resulting cells
nbVertices -= op->perform(map, position);
nbVertices -= op->collapse(map, position);
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
(*it)->affectApprox(op); // affect data to the resulting vertex
......
......@@ -77,15 +77,17 @@ public:
Operator() {}
~Operator() {};
~Operator() {}
Dart getEdge() {return m_edge;}
void setEdge(Dart d) { m_edge = d; }
virtual OperatorType getType() = 0;
virtual unsigned int perform(MAP& m, VertexAttribute<typename PFP::VEC3>& position) = 0;
virtual bool canPerform(MAP &m ,Dart d, VertexAttribute<typename PFP::VEC3>& position) = 0;
virtual unsigned int collapse(MAP& m, VertexAttribute<typename PFP::VEC3>& position) = 0;
virtual bool canCollapse(MAP &m ,Dart d, VertexAttribute<typename PFP::VEC3>& position) = 0;
virtual void split(MAP& m, VertexAttribute<typename PFP::VEC3>& position) = 0;
void setFirstIncidentEdge(Dart d) { d2 = d; }
......@@ -111,7 +113,7 @@ public:
Operator<PFP>(d)//, approx)
{}
~CollapseOperator() {};
~CollapseOperator() {}
};
......@@ -135,9 +137,42 @@ public:
{ }
OperatorType getType() { return O_CEdge; }
unsigned int perform(MAP &m, VertexAttribute<typename PFP::VEC3>& position);
bool canPerform(MAP &m ,Dart d, VertexAttribute<typename PFP::VEC3>& position);
//collapse
unsigned int collapse(MAP& m, VertexAttribute<typename PFP::VEC3>& position);
bool canCollapse(MAP& m ,Dart d, VertexAttribute<typename PFP::VEC3>& position);
//split
void split(MAP& m, VertexAttribute<typename PFP::VEC3>& position);
};
template <typename PFP>
class OperatorList
{
public:
typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3;
protected:
MAP& m_map;
//list of operations made on the mesh
typename std::vector<Operator<PFP>* > m_ops;
//iterator to save the position in the operations list
typename std::vector<Operator<PFP>* >::iterator m_cur;
public:
OperatorList(MAP& m) : m_map(m) {}
~OperatorList();
void coarsen(VertexAttribute<typename PFP::VEC3>& position);
void refine(VertexAttribute<typename PFP::VEC3>& position);
void initIndex() { m_cur = m_ops.end(); }
unsigned int size() { return m_ops.size(); }
void add(Operator<PFP> *o) { m_ops.push_back(o); }
};
......
......@@ -35,7 +35,7 @@ namespace DecimationVolumes
* Collapse Edge Operator *
************************************************************************************/
template <typename PFP>
unsigned int CollapseEdgeOperator<PFP>::perform(MAP& m, VertexAttribute<typename PFP::VEC3>& position)
unsigned int CollapseEdgeOperator<PFP>::collapse(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& position)
{
unsigned int nbCell = 0;
......@@ -46,7 +46,7 @@ unsigned int CollapseEdgeOperator<PFP>::perform(MAP& m, VertexAttribute<typename
}
template <typename PFP>
bool CollapseEdgeOperator<PFP>::canPerform(MAP &m ,Dart d, VertexAttribute<typename PFP::VEC3>& position)
bool CollapseEdgeOperator<PFP>::canCollapse(typename PFP::MAP &m ,Dart d, VertexAttribute<typename PFP::VEC3>& position)
{
bool canCollapse = true;
......@@ -102,6 +102,62 @@ bool CollapseEdgeOperator<PFP>::canPerform(MAP &m ,Dart d, VertexAttribute<typen
}
template <typename PFP>
void CollapseEdgeOperator<PFP>::split(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& position)
{
// Dart d = vs->getEdge() ;
// Dart dd = m_map.phi2(d) ; // get some darts
// Dart dd2 = vs->getRightEdge() ;
// Dart d2 = vs->getLeftEdge() ;
// Dart d1 = m_map.phi2(d2) ;
// Dart dd1 = m_map.phi2(dd2) ;
//
// unsigned int v1 = m_map.template getEmbedding<VERTEX>(d) ; // get the embedding
// unsigned int v2 = m_map.template getEmbedding<VERTEX>(dd) ; // of the new vertices
// unsigned int e1 = m_map.template getEmbedding<EDGE>(m_map.phi1(d)) ;
// unsigned int e2 = m_map.template getEmbedding<EDGE>(m_map.phi_1(d)) ; // and new edges
// unsigned int e3 = m_map.template getEmbedding<EDGE>(m_map.phi1(dd)) ;
// unsigned int e4 = m_map.template getEmbedding<EDGE>(m_map.phi_1(dd)) ;
//
// //vertexSplit(vs) ; // split vertex
// //map.vertexSplit()
//
// m_map.template embedOrbit<VERTEX>(d, v1) ; // embed the
// m_map.template embedOrbit<VERTEX>(dd, v2) ; // new vertices
// m_map.template embedOrbit<EDGE>(d1, e1) ;
// m_map.template embedOrbit<EDGE>(d2, e2) ; // and new edges
// m_map.template embedOrbit<EDGE>(dd1, e3) ;
// m_map.template embedOrbit<EDGE>(dd2, e4) ;
}
/****************************************************************************************************
* Operator List *
****************************************************************************************************/
template <typename PFP>
OperatorList<PFP>::~OperatorList()
{
// for(typename std::list<CollapseSplitOperator<PFP>*>::iterator it= m_ops.begin() ; it != m_ops.end() ; ++it)
// {
// delete *it;
// }
}
template <typename PFP>
void OperatorList<PFP>::coarsen(VertexAttribute<typename PFP::VEC3>& position)
{
(*m_cur)->collapse(m_map, position);
++m_cur; // ou ++ ça dépend dans quel sens c'est stocké
}
template <typename PFP>
void OperatorList<PFP>::refine(VertexAttribute<typename PFP::VEC3>& position)
{
--m_cur; // ou -- ça dépend dans quel sens c'est stocké
(*m_cur)->split(m_map, position);
}
} //end namespace DecimationVolumes
} //end namespace Algo
......
......@@ -95,16 +95,16 @@ template <typename PFP>
void tetrahedrizeVolume(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position)
{
//mark bad edges
DartMarker me(map);
DartMarker mBadEdge(map);
int i = 0;
// unsignzed int i = 0;
TraversorE<typename PFP::MAP> travE(map);
DartMarkerStore mEdge(map);
for(Dart dit = travE.begin() ; dit != travE.end() ; dit = travE.next())
for(Dart dit = map.begin() ; dit != map.end() ; map.next(dit))
{
//check if this edge is an "ear-edge"
if(!me.isMarked(dit))
if(!mBadEdge.isMarked(dit))
{
//search three positions
typename PFP::VEC3 tris1[3];
......@@ -143,10 +143,11 @@ void tetrahedrizeVolume(typename PFP::MAP& map, VertexAttribute<typename PFP::VE
if(intersection)
{
me.markOrbit<EDGE>(dit);
mBadEdge.markOrbit<EDGE>(dit);
}
else //cut a tetrahedron
{
std::cout << "cut cut " << std::endl;
Dart dring = map.phi_1(dit);
std::vector<Dart> vPath;
......@@ -157,13 +158,15 @@ void tetrahedrizeVolume(typename PFP::MAP& map, VertexAttribute<typename PFP::VE
map.splitVolume(vPath);
//map.splitFace(map.phi2(map.phi1(dit)), map.phi2(map.phi1(map.phi2(dit))));
}
++i;
map.splitFace(map.phi2(map.phi1(dring)), map.phi2(map.phi1(map.phi2(dring))));
if(i == 16)
return;
}
// ++i;
//
// if(i == 16)
// return;
}
}
}
......
/*******************************************************************************
* 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 __VPMESH__
#define __VPMESH__
#include "Algo/DecimationVolumes/operator.h"
#include "Algo/DecimationVolumes/selector.h"
#include "Algo/DecimationVolumes/edgeSelector.h"
#include "Algo/DecimationVolumes/geometryApproximator.h"
//#include "Algo/DecimationVolumes/geometryPredictor.h"
#include "Utils/quantization.h"
namespace CGoGN
{
namespace Algo
{
namespace VPMesh
{
template <typename PFP>
class VolumetricProgressiveMesh
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
private:
MAP& m_map ;
VertexAttribute<typename PFP::VEC3>& positionsTable ;
DartMarker& inactiveMarker ;
SelectorUnmarked dartSelect ;
Algo::DecimationVolumes::EdgeSelector<PFP>* m_selector ;
std::vector<Algo::DecimationVolumes::ApproximatorGen<PFP>*> m_approximators ;
std::vector<Algo::DecimationVolumes::PredictorGen<PFP>*> m_predictors ;
Algo::DecimationVolumes::OperatorList<PFP>* m_nodes;
unsigned int m_level ;
Algo::DecimationVolumes::Approximator<PFP, VEC3>* m_positionApproximator ;
bool m_initOk ;
public:
VolumetricProgressiveMesh(
MAP& map, DartMarker& inactive,
Algo::DecimationVolumes::SelectorType s, Algo::DecimationVolumes::ApproximatorType a,
VertexAttribute<typename PFP::VEC3>& position
) ;
~VolumetricProgressiveMesh() ;
bool initOk() { return m_initOk ; }
void createPM(unsigned int percentWantedVertices) ;
void gotoLevel(unsigned int l) ;
unsigned int& currentLevel() { return m_level ; }
unsigned int nbSplits() { return m_nodes.size() ; }
} ;
} //namespace PMesh
} //namespace Algo
} //namespace CGoGN
#include "Algo/VolumetricProgressiveMesh/vpmesh.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 "Algo/Geometry/localFrame.h"
namespace CGoGN
{
namespace Algo
{
namespace VPMesh
{
template <typename PFP>
VolumetricProgressiveMesh<PFP>::VolumetricProgressiveMesh(
MAP& map, DartMarker& inactive,
Algo::DecimationVolumes::SelectorType s, Algo::DecimationVolumes::ApproximatorType a,
VertexAttribute<typename PFP::VEC3>& position
) :
m_map(map), positionsTable(position), inactiveMarker(inactive), dartSelect(inactiveMarker)
{
CGoGNout << " creating approximator and predictor.." << CGoGNflush ;
switch(a)
{
case Algo::DecimationVolumes::A_QEM :
m_approximators.push_back(new Algo::DecimationVolumes::Approximator_QEM<PFP>(m_map, positionsTable)) ;
break ;
default :
CGoGNout << "not yet implemented" << CGoGNendl;
break;
}
CGoGNout << "..done" << CGoGNendl ;
CGoGNout << " creating selector.." << CGoGNflush ;
switch(s)
{
case Algo::DecimationVolumes::S_QEM :
m_selector = new Algo::DecimationVolumes::EdgeSelector_QEM<PFP>(m_map, positionsTable, m_approximators, dartSelect) ;
break ;
default:
CGoGNout << "not yet implemented" << CGoGNendl;
break;
}
CGoGNout << "..done" << CGoGNendl ;
m_initOk = true ;
CGoGNout << " initializing approximators.." << CGoGNflush ;
for(typename std::vector<Algo::DecimationVolumes::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
{
if(! (*it)->init())
m_initOk = false ;
if((*it)->getApproximatedAttributeName() == "position")
m_positionApproximator = reinterpret_cast<Algo::DecimationVolumes::Approximator<PFP, VEC3>*>(*it) ;
}
CGoGNout << "..done" << CGoGNendl ;
CGoGNout << " initializing predictors.." << CGoGNflush ;
for(typename std::vector<Algo::DecimationVolumes::PredictorGen<PFP>*>::iterator it = m_predictors.begin(); it != m_predictors.end(); ++it)
if(! (*it)->init())
m_initOk = false ;
CGoGNout << "..done" << CGoGNendl ;
CGoGNout << " initializing selector.." << CGoGNflush ;
m_initOk = m_selector->init() ;
CGoGNout << "..done" << CGoGNendl ;
m_nodes = new Algo::DecimationVolumes::OperatorList<PFP>(m_map);
}
template <typename PFP>
VolumetricProgressiveMesh<PFP>::~VolumetricProgressiveMesh()
{
for(unsigned int i = 0; i < m_nodes.size(); ++i)
delete m_nodes[i] ;
if(m_selector)
delete m_selector ;
for(typename std::vector<Algo::DecimationVolumes::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
delete (*it) ;
for(typename std::vector<Algo::DecimationVolumes::PredictorGen<PFP>*>::iterator it = m_predictors.begin(); it != m_predictors.end(); ++it)
delete (*it) ;
}
template <typename PFP>
void VolumetricProgressiveMesh<PFP>::createPM(unsigned int percentWantedVertices)
{
unsigned int nbVertices = m_map.template getNbOrbits<VERTEX>() ;
unsigned int nbWantedVertices = nbVertices * percentWantedVertices / 100 ;
CGoGNout << " creating PM (" << nbVertices << " vertices).." << /* flush */ CGoGNendl ;
bool finished = false ;
Dart d ;
while(!finished)
{
//Next Operator to perform
Algo::DecimationVolumes::Operator<PFP> *op;
if((op = m_selector->nextOperator()) == NULL)
break;
m_nodes->add(op);
for(typename std::vector<Algo::DecimationVolumes::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
{
(*it)->approximate(op) ; // compute approximated attributes with its associated detail
(*it)->saveApprox(op) ;
}
//Update the selector before performing operation
if(!m_selector->updateBeforeOperation(op))
break;
nbVertices -= op->collapse(m_map, positionsTable);
for(typename std::vector<Algo::DecimationVolumes::ApproximatorGen<PFP>*>::iterator it = m_approximators.begin(); it != m_approximators.end(); ++it)
(*it)->affectApprox(op); // affect data to the resulting vertex
m_selector->updateAfterOperation(op) ; // update selector
if(nbVertices <= nbWantedVertices)
finished = true ;
}
m_selector->finish() ;
delete m_selector ;
m_selector = NULL ;
m_level = m_nodes->size() ;
CGoGNout << "..done (" << nbVertices << " vertices)" << CGoGNendl ;
}
template <typename PFP>
void VolumetricProgressiveMesh<PFP>::gotoLevel(unsigned int l)
{
unsigned int i=0;
if(l == m_level || l > m_nodes->size() || l < 0)
return ;
if(l > m_level)
for(i=m_level ; i<l ; i++)
m_nodes->coarsen(positionsTable);
else
for(i=l ; i<m_level ; i++)
m_nodes->refine(positionsTable);
m_level = i;
}
} //namespace VPMesh
} //namespace Algo
} //namespace CGoGN
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment