Commit bab01f8a authored by untereiner's avatar untereiner

Map3::splitVertex again + tetrahedralization::splitVertex

parent 6126aa17
......@@ -25,6 +25,7 @@
#include "tuto_oper3.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/tetrahedralization.h"
#include "Algo/Modelisation/primitives3d.h"
#include "Algo/Geometry/centroid.h"
#include "Algo/Geometry/normal.h"
......@@ -149,8 +150,14 @@ void MyQT::operation(int x)
CGoGNout <<"split volume"<<CGoGNendl;
if (!m_selecteds.empty())
{
std::cout << "start" << std::endl;
for(std::vector<Dart>::iterator it = m_selecteds.begin() ; it != m_selecteds.end() ; ++it)
std::cout << *it << " et phi2() = " << myMap.phi2(*it) << std::endl;
std::cout << "end" << std::endl;
myMap.splitVolume(m_selecteds);
m_selecteds.clear();
dm.markAll();
updateMap();
}
......@@ -181,14 +188,17 @@ void MyQT::operation(int x)
break;
case 10:
CGoGNout <<"split vertex"<<CGoGNendl;
if (!m_selecteds.empty())
if (!m_selecteds.empty() && m_selected != NIL)
{
std::cout << "nb darts before = " << myMap.getNbDarts() << std::endl;
Dart dit = m_selecteds.front();
PFP::VEC3 c1 = Algo::Geometry::volumeCentroid<PFP>(myMap, dit, position);
Dart dres = myMap.splitVertex(m_selecteds);
position[dres] = position[dit]*0.5f - c1*0.5f;
PFP::VEC3 Q = (position[myMap.phi1(m_selected)] + position[m_selected])/2.0f;
//PFP::VEC3 c1 = Algo::Geometry::volumeCentroid<PFP>(myMap, dit, position);
//Dart dres = myMap.splitVertex(m_selecteds);
Dart dres = Algo::Modelisation::Tetrahedralization::splitVertex<PFP>(myMap, m_selecteds);
position[dres] = position[dit] + Q*0.25f;
//position[dit] = position[dit] - c1*0.5f;
m_selecteds.clear();
m_selected = NIL;
dm.markAll();
updateMap();
std::cout << "nb darts after = " << myMap.getNbDarts() << std::endl;
......@@ -212,6 +222,15 @@ void MyQT::createMap(int n)
prim.hexaGrid_topo(n,n,n);
prim.embedHexaGrid(1.0f,1.0f,1.0f);
// Dart d = Algo::Modelisation::createTetrahedron<PFP>(myMap);
// myMap.closeMap();
//
// position[d] = typename PFP::VEC3(0.0f, 0.0f, 0.0f);
// position[myMap.phi1(d)] = typename PFP::VEC3(0.0f, 1.0f, 0.0f);
// position[myMap.phi1(myMap.phi1(d))] = typename PFP::VEC3(1.0f, 0.5f, 0.0f);
// position[myMap.phi_1(myMap.phi2(d))] = typename PFP::VEC3(0.5f, 0.5f, 1.0f);
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
......
......@@ -71,7 +71,7 @@
</item>
<item>
<property name="text">
<string>collapsedge</string>
<string>collapseEdge</string>
</property>
</item>
<item>
......
......@@ -44,6 +44,13 @@ namespace Tetrahedralization
template <typename PFP>
void hexahedronToTetrahedron(typename PFP::MAP& map, Dart d);
/************************************************************************************************
* Collapse / Split Operators
************************************************************************************************/
template <typename PFP>
Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd);
/************************************************************************************************
* Tetrahedron functions *
************************************************************************************************/
......@@ -56,6 +63,14 @@ void hexahedronToTetrahedron(typename PFP::MAP& map, Dart d);
template <typename PFP>
bool isTetrahedron(typename PFP::MAP& the_map, Dart d);
/**
* test if a mesh (or submesh) is a tetrahedral mesh
* @param map
* @param selected
*/
template <typename PFP>
bool isTetrahedralization(typename PFP::MAP& map, const FunctorSelect& selected = allDarts);
/************************************************************************************************
* Swap Functions *
************************************************************************************************/
......
......@@ -55,7 +55,44 @@ void hexahedronToTetrahedron(typename PFP::MAP& map, Dart d)
/************************************************************************************************
* Tetrahedron functions *
* Collapse / Split Operators
************************************************************************************************/
template <typename PFP>
Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd)
{
//split the vertex
Dart dres = map.splitVertex(vd);
//split the faces incident to the new vertex
Dart dbegin = map.phi1(map.phi2(vd.front()));
Dart dit = dbegin;
do
{
map.splitFace(map.phi1(dit),map.phi_1(dit));
dit = map.alpha2(dit);
}
while(dbegin != dit);
//split the volumes incident to the new vertex
for(unsigned int i = 0; i < vd.size(); ++i)
{
Dart dit = vd[i];
std::vector<Dart> v;
v.push_back(map.phi1(map.phi1(map.phi2(dit))));
std::cout << "[" << v.back();
v.push_back(map.phi1(dit));
std::cout << " - " << v.back();
v.push_back(map.phi1(map.phi2(map.phi_1(dit))));
std::cout << " - " << v.back() << "]" << std::endl;
//map.splitVolume(v);
}
return dres;
}
/************************************************************************************************
* Tetrahedron functions *
************************************************************************************************/
template <typename PFP>
......@@ -80,8 +117,21 @@ bool isTetrahedron(typename PFP::MAP& the_map, Dart d)
return true;
}
template <typename PFP>
bool isTetrahedralization(typename PFP::MAP& map, const FunctorSelect& selected)
{
TraversorV<typename PFP::MAP> travV(map, selected);
for(Dart dit = travV.begin() ; dit != travV.end() ; dit = travV.next())
{
if(!isTetrahedron<PFP>(map, dit))
return false;
}
return true;
}
/************************************************************************************************
* Topological functions *
* Topological functions *
************************************************************************************************/
//sew a face into the edge
......@@ -380,7 +430,7 @@ void swap5To4(typename PFP::MAP& map, Dart d, typename PFP::TVEC3& positions)
}
/************************************************************************************************
* Flip Functions *
* Flip Functions *
************************************************************************************************/
template <typename PFP>
......
......@@ -547,45 +547,6 @@ public:
}
} ;
/*********************************************************************************
* MR PROGRESSIVE MESHES FUNCTOR
*********************************************************************************/
//template <typename PFP>
//class DecimateFilter
//{
//protected:
// typename PFP::MAP& m_map;
// typename PFP::TVEC3& m_position;
// //Algo::Decimation::SelectorType m_s;
// //Algo::Decimation::ApproximatorType m_a;
// unsigned int m_nbWantedVertices;
// FunctorSelect& m_selected;
//
//
//public:
// DecimateFilter(typename PFP::MAP& m, typename PFP::TVEC3& p,
// //Algo::Decimation::SelectorType s, Algo::Decimation::ApproximatorType a,
// unsigned int nbWantedVertices, const FunctorSelect& selected) :
// m_map(m), m_position(p), m_s(s), m_a(a), m_nbWantedVertices(nbWantedVertices), m_selected(selected) {}
//
// void decimate ()
// {
// // Algo::Decimation::decimate<PFP>(m_map, m_s, m_a, m_position, m_nbWantedVertices, m_selected);
// }
//
// void coarsen()
// {
//
// }
//
// void refine()
// {
//
// }
//} ;
} // namespace Multiresolution
......
/*******************************************************************************
* 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 __MAP2MR_PM__
#define __MAP2MR_PM__
#include "Topology/map/embeddedMap2.h"
#include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h"
#include "Topology/map/map2MR/filters_Primal.h"
namespace CGoGN
{
class SelectorCollapsingEdges : public FunctorSelect
{
protected:
const DartMarker& m_dm;
public:
SelectorCollapsingEdges(const DartMarker& dm): m_dm(dm) {}
bool operator()(Dart d) const { return m_dm.isMarked(d); }
FunctorSelect* copy() const { return new SelectorCollapsingEdges(m_dm);}
};
class Map2MR_PM : public EmbeddedMap2
{
protected:
bool shareVertexEmbeddings ;
//Multiresolution::DecimateFilter* filter ;
DartMarkerStore* selectedEdges;
public:
Map2MR_PM() ;
virtual std::string mapTypeName() const { return "Map2MR_PM" ; }
//add a coarse level
void addNewLevel(bool embedNewVertices = true) ;
//void addDecimationFilter(Multiresolution::DecimateFilter *f) { filter = f; }
void analysis() ;
void synthesis() ;
} ;
} // namespace CGoGN
#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 "Topology/map/map2MR/map2MR_PM.h"
namespace CGoGN
{
Map2MR_PM::Map2MR_PM() :
shareVertexEmbeddings(true)
{
initMR() ;
}
void Map2MR_PM::addNewLevel(bool embedNewVertices)
{
pushLevel() ;
//Add the current level higher
unsigned int newLevel = m_mrDarts.size() ;
std::stringstream ss ;
ss << "MRdart_"<< newLevel ;
AttributeMultiVector<unsigned int>* newAttrib = m_mrattribs.addAttribute<unsigned int>(ss.str()) ;
m_mrDarts.push_back(newAttrib) ;
m_mrNbDarts.push_back(0) ;
if(m_mrDarts.size() > 1)
{
for(unsigned int i = newLevel; i > 0 ; --i)
{
AttributeMultiVector<unsigned int>* currentAttrib = m_mrDarts[i] ;
AttributeMultiVector<unsigned int>* prevAttrib = m_mrDarts[i - 1] ; // copy the indices of
m_mrattribs.copyAttribute(currentAttrib->getIndex(), prevAttrib->getIndex()) ; // previous level into new level
}
}
popLevel() ;
setCurrentLevel(0);
selectedEdges = new DartMarkerStore(*this);
TraversorE<Map2MR_PM> travE(*this);
for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
{
if(!selectedEdges->isMarked(d))
{
if(edgeCanCollapse(d))
{
//interdire la contraction d'arete partageant un meme sommet
//interdire la contraction d'arete
//interdire la contraction d'une arete d'une face incidente au sommet de d
//=> mark incident edges of vertices adjacent to the vertex of d through a common face
Traversor2VVaF<Map2MR_PM> travVVaF(*this, d);
for (Dart dit = travVVaF.begin(); dit != travVVaF.end(); dit = travVVaF.next())
{
Dart ditV = dit;
do
{
if(!selectedEdges->isMarked(ditV))
selectedEdges->markOrbit(EDGE, ditV);
ditV = phi2(phi_1(ditV));
} while(ditV != dit);
}
//=> the same for the vertex phi2(d)
Traversor2VVaF<Map2MR_PM> travVVaF2(*this, phi2(d));
for (Dart dit = travVVaF2.begin(); dit != travVVaF2.end(); dit = travVVaF2.next())
{
Dart ditV = dit;
do
{
if(!selectedEdges->isMarked(ditV))
selectedEdges->markOrbit(EDGE, ditV);
ditV = phi2(phi_1(ditV));
} while(ditV != dit);
}
}
}
}
//(*filter).decimate() ;
}
void Map2MR_PM::analysis()
{
assert(getCurrentLevel() > 0 || !"analysis : called on level 0") ;
decCurrentLevel() ;
//(*filter).coarsen() ;
}
void Map2MR_PM::synthesis()
{
assert(getCurrentLevel() < getMaxLevel() || !"synthesis : called on max level") ;
//(*filter).refine() ;
incCurrentLevel() ;
}
} // namespace CGoGN
......@@ -131,44 +131,62 @@ void Map3::fillHole(Dart d)
Dart Map3::splitVertex(std::vector<Dart>& vd)
{
//assert(checkPathAroundVertex(vd)) ; assert(sameVertex(d,e));
//assert(checkPathAroundVertex(vd)) ;
//case BoundaryVertex ??
bool boundE = false;
Dart prev = vd.front(); //elt 0
Dart db1 = NIL;
if(isBoundaryFace(phi1(phi2(prev))))
{
db1 = phi2(phi3(phi1(phi2(prev))));
}
else if(isBoundaryEdge(prev))
{
boundE = true;
}
Dart fs = phi_1(phi2(phi_1(prev))); //first side
Dart ss = phi2(prev); //second side
//Dart ss = phi2(prev); //second side
Map2::splitVertex(prev, phi2(fs));
// Map1::cutEdge(fs); //comme un vertexSplit
// Map1::cutEdge(ss);
// phi2sew(phi1(ss), phi1(fs));
for(unsigned int i = 1; i < vd.size(); ++i)
{
Dart d3 = phi1(ss);
//Dart d3 = phi1(ss);
prev = vd[i];
Dart fs = phi_1(phi2(phi_1(prev))); //first side
Dart ss = phi2(prev); //second side
//Dart ss = phi2(prev); //second side
Map2::splitVertex(prev, phi2(fs));
// Map1::cutEdge(fs); //comme un vertexSplit
// Map1::cutEdge(ss);
// phi2sew(phi1(ss), phi1(fs));
Dart d1 = phi_1(phi2(phi_1(vd[i-1])));
Dart d2 = phi1(phi2(vd[i]));
phi3sew(d1, d2);
}
for(unsigned int i = 0 ; i < vd.size() ; ++i)
Dart db2 = NIL;
if(isBoundaryFace(phi2(phi_1(prev))))
{
Dart d1 = phi_1(phi2(phi_1(vd[i])));
Dart d2 = phi1(phi3(phi2(phi_1(vd[i]))));
phi3sew(d1, d2);
db2 = phi2(phi3(phi2(phi_1(prev))));
}
if(db1 != NIL && db2 != NIL)
{
Map2::splitVertex(db1, db2);
phi3sew(phi1(phi2(db2)), phi_1(phi3(phi2(db2))));
phi3sew(phi1(phi2(db1)), phi_1(phi3(phi2(db1))));
}
else if(!boundE)
{
Dart dbegin = phi1(phi2(vd.front()));
Dart dend = phi_1(phi2(phi_1(vd.back())));
phi3sew(dbegin, dend);
}
return phi_1(phi2(phi_1(prev)));
}
......
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