Commit 871ced88 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge cgogn:~thery/CGoGN

parents 93451db0 924c5ab5
...@@ -58,6 +58,13 @@ QT4_WRAP_CPP(tuto_oper2_moc tuto_oper2.h) ...@@ -58,6 +58,13 @@ QT4_WRAP_CPP(tuto_oper2_moc tuto_oper2.h)
add_executable( tuto_oper2 tuto_oper2.cpp ${tuto_oper2_ui} ${tuto_oper2_moc}) add_executable( tuto_oper2 tuto_oper2.cpp ${tuto_oper2_ui} ${tuto_oper2_moc})
target_link_libraries( tuto_oper2 target_link_libraries( tuto_oper2
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( tuto_oper3_ui tuto_oper3.ui )
QT4_WRAP_CPP(tuto_oper3_moc tuto_oper3.h)
add_executable( tuto_oper3 tuto_oper3.cpp ${tuto_oper3_ui} ${tuto_oper3_moc})
target_link_libraries( tuto_oper3
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( tuto_orbits_ui tuto_orbits.ui ) QT4_WRAP_UI( tuto_orbits_ui tuto_orbits.ui )
QT4_WRAP_CPP(tuto_orbits_moc tuto_orbits.h) QT4_WRAP_CPP(tuto_orbits_moc tuto_orbits.h)
......
This diff is collapsed.
/*******************************************************************************
* 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 _TUTO_OPER3_
#define _TUTO_OPER3_
//#define USE_GMAP
#include "Topology/generic/parameters.h"
#ifdef USE_GMAP
#include "Topology/gmap/embeddedGMap3.h"
#else
#include "Topology/map/embeddedMap3.h"
#endif
#include "Algo/Render/GL2/topo3Render.h"
#include "ui_tuto_oper3.h"
#include "Utils/Qt/qtui.h"
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the type of the map
#ifdef USE_GMAP
typedef EmbeddedGMap3 MAP;
#else
typedef EmbeddedMap3 MAP;
#endif
};
class MyQT: public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f),m_ex1(0.9f),m_ex2(0.9f),m_ex3(0.9f) {}
void cb_redraw();
void cb_initGL();
void cb_mousePress(int button, int x, int y);
void cb_keyPress(int code);
void cb_Open();
void cb_Save();
Utils::QT::uiDockInterface dock;
protected:
// declaration of the map
PFP::MAP myMap;
PFP::TVEC3 position;
// AttributeHandler<Geom::Vec3f> colorDarts;
SelectorDartNoBoundary<PFP::MAP> nb;
// render (for the topo)
Algo::Render::GL2::Topo3Render* m_render_topo;
Dart m_selected;
Dart m_selected2;
std::vector<Dart> m_selecteds;
DartMarker dm;
float m_shift;
float m_ex1,m_ex2,m_ex3;
// just for more compact writing
inline Dart PHI1(Dart d) {return myMap.phi1(d);}
inline Dart PHI_1(Dart d) {return myMap.phi_1(d);}
inline Dart PHI2(Dart d) {return myMap.phi2(d);}
inline Dart PHI3(Dart d) {return myMap.phi3(d);}
template<int X>
Dart PHI(Dart d) {return myMap.phi<X>(d);}
public:
// example of simple map creation
void createMap(int n);
void updateMap();
void importMesh(std::string& filename);
public slots:
void operation(int x);
void svg();
void width(int w);
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DockWidget</class>
<widget class="QDockWidget" name="DockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>227</width>
<height>369</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>250</height>
</size>
</property>
<property name="windowTitle">
<string>Interface</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>200</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>2</number>
</property>
<property name="spacing">
<number>4</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listOper">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<item>
<property name="text">
<string>deleteVertex</string>
</property>
</item>
<item>
<property name="text">
<string>cutEdge</string>
</property>
</item>
<item>
<property name="text">
<string>uncutEdge</string>
</property>
</item>
<item>
<property name="text">
<string>deleteEdge</string>
</property>
</item>
<item>
<property name="text">
<string>collapsedge</string>
</property>
</item>
<item>
<property name="text">
<string>splitFace</string>
</property>
</item>
<item>
<property name="text">
<string>mergeVolume</string>
</property>
</item>
<item>
<property name="text">
<string>splitVolume</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QSlider" name="widthSlider">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="singleStep">
<number>2</number>
</property>
<property name="value">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="svg">
<property name="text">
<string>SnapshotSVG</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
...@@ -105,20 +105,16 @@ template< typename DataType, template < typename D2 > class Windowing, typename ...@@ -105,20 +105,16 @@ template< typename DataType, template < typename D2 > class Windowing, typename
Dart MarchingCube<DataType, Windowing, PFP>::createTriEmb(unsigned int e1, unsigned int e2, unsigned int e3) Dart MarchingCube<DataType, Windowing, PFP>::createTriEmb(unsigned int e1, unsigned int e2, unsigned int e3)
{ {
L_DART d = m_map->newFace(3,false); L_DART d = m_map->newFace(3,false);
//TODO change this which work only with 2-maps
// m_map->setDartEmbedding(VERTEX,d,e1); d = m_map->phi1(d);
// m_map->setDartEmbedding(VERTEX,d,e2); d = m_map->phi1(d);
// m_map->setDartEmbedding(VERTEX,d,e3); d = m_map->phi1(d);
FunctorSetEmb<GenericMap> fsetemb(*m_map, VERTEX, e1); FunctorSetEmb<GenericMap> fsetemb(*m_map, VERTEX, e1);
m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb); m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb);
d = m_map->phi1(d); d = m_map->phi1(d);
fsetemb.changeEmb(e2); fsetemb.changeEmb(e2);
m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb); m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb);
d = m_map->phi1(d); d = m_map->phi1(d);
fsetemb.changeEmb(e3); fsetemb.changeEmb(e3);
m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb); m_map->foreach_dart_of_orbit(PFP::MAP::ORBIT_IN_PARENT(VERTEX), d, fsetemb);
d = m_map->phi1(d); d = m_map->phi1(d);
return d; return d;
} }
...@@ -220,11 +216,11 @@ void MarchingCube<DataType, Windowing, PFP>::simpleMeshing() ...@@ -220,11 +216,11 @@ void MarchingCube<DataType, Windowing, PFP>::simpleMeshing()
ucData = m_Image->getVoxelPtr(lX,lY,lZ); ucData = m_Image->getVoxelPtr(lX,lY,lZ);
createFaces_7(ucData++,lX++,lY,lZ,16); // TAG createFaces_7(ucData++,lX++,lY,lZ,16); // TAG
while (lX < lTxm) while (lX < lTxm-1)
{ {
createFaces_8(ucData++,lX++,lY,lZ,0); createFaces_8(ucData++,lX++,lY,lZ,0);
} }
createFaces_8(ucData++,lX++,lY,lZ,32); //TAG createFaces_8(ucData++,lX,lY,lZ,32); //TAG
lY++; lY++;
} }
......
...@@ -69,11 +69,10 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV ...@@ -69,11 +69,10 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV
if (m_attIndex.map() != &mapx) if (m_attIndex.map() != &mapx)
{
m_attIndex = mapx.template getAttribute<unsigned int>(DART, "dart_index"); m_attIndex = mapx.template getAttribute<unsigned int>(DART, "dart_index");
if (!m_attIndex.isValid())
m_attIndex = mapx.template addAttribute<unsigned int>(DART, "dart_index"); if (!m_attIndex.isValid())
} m_attIndex = mapx.template addAttribute<unsigned int>(DART, "dart_index");
m_nbDarts = 0; m_nbDarts = 0;
for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
...@@ -332,13 +331,10 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T ...@@ -332,13 +331,10 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T
typedef typename PFP::VEC3 VEC3; typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL;
if (m_attIndex.map() != &mapx) if (m_attIndex.map() != &mapx)
{
m_attIndex = mapx.template getAttribute<unsigned int>(DART, "dart_index"); m_attIndex = mapx.template getAttribute<unsigned int>(DART, "dart_index");
if (!m_attIndex.isValid()) if (!m_attIndex.isValid())
m_attIndex = mapx.template addAttribute<unsigned int>(DART, "dart_index"); m_attIndex = mapx.template addAttribute<unsigned int>(DART, "dart_index");
}
m_nbDarts = 0; m_nbDarts = 0;
for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
......
...@@ -67,7 +67,8 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC ...@@ -67,7 +67,8 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC
std::vector<Dart> vecDarts; std::vector<Dart> vecDarts;
vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory
m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index"); if (m_attIndex.map() != &map)
m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index");
if (!m_attIndex.isValid()) if (!m_attIndex.isValid())
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index"); m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index");
...@@ -212,7 +213,9 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE ...@@ -212,7 +213,9 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE
std::vector<Dart> vecDarts; std::vector<Dart> vecDarts;
vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory
m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index"); if (m_attIndex.map() != &map)
m_attIndex = map.template getAttribute<unsigned int>(DART, "dart_index");
if (!m_attIndex.isValid()) if (!m_attIndex.isValid())
m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index"); m_attIndex = map.template addAttribute<unsigned int>(DART, "dart_index");
......
...@@ -61,7 +61,8 @@ public: ...@@ -61,7 +61,8 @@ public:
~AutoAttributeHandler() ~AutoAttributeHandler()
{ {
reinterpret_cast<AttribMap*>(this->m_map)->removeAttribute<T>(*this) ; if (this->valid)
reinterpret_cast<AttribMap*>(this->m_map)->removeAttribute<T>(*this) ;
} }
} ; } ;
......
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
//! //!
/*! /*!
*/ */
virtual bool collapseDegeneratedFace(Dart d); // virtual bool collapseDegeneratedFace(Dart d);
//! //!
/*! /*!
......
...@@ -155,6 +155,12 @@ public: ...@@ -155,6 +155,12 @@ public:
*/ */
virtual bool uncutEdge(Dart d); virtual bool uncutEdge(Dart d);
/**
* Precondition for deleting edge
*/
bool deleteEdgePreCond(Dart d);
//! Delete the edge of d //! Delete the edge of d
/*! All the volumes around the edge are merged into one volume /*! All the volumes around the edge are merged into one volume
* @param d a dart of the edge to delete * @param d a dart of the edge to delete
...@@ -176,7 +182,14 @@ public: ...@@ -176,7 +182,14 @@ public:
* @param d a dart of the face * @param d a dart of the face
* @return true if the collapse has been executed, false otherwise * @return true if the collapse has been executed, false otherwise
*/ */
virtual bool collapseDegeneratedFace(Dart d); // virtual bool collapseDegeneratedFace(Dart d);
//! Split Face Pre-condition
/*!
* @param d dart of first vertex
* @param e dart of second vertex
*/
bool splitFacePreCond(Dart d, Dart e);
//! Split a face inserting an edge between two vertices //! Split a face inserting an edge between two vertices
/*! \pre Dart d and e should belong to the same face and be distinct /*! \pre Dart d and e should belong to the same face and be distinct
...@@ -193,6 +206,10 @@ public: ...@@ -193,6 +206,10 @@ public:
*/ */
bool collapseDegeneretedVolume(Dart d); bool collapseDegeneretedVolume(Dart d);
//!! sewVolumes Pre-condition
bool sewVolumesPreCond(Dart d, Dart e);
//! Sew two oriented volumes along their faces. //! Sew two oriented volumes along their faces.
/*! The oriented faces should not be phi3-linked and have the same degree /*! The oriented faces should not be phi3-linked and have the same degree
* @param d a dart of the first volume * @param d a dart of the first volume
...@@ -201,6 +218,9 @@ public: ...@@ -201,6 +218,9 @@ public:
*/ */
virtual void sewVolumes(Dart d, Dart e, bool withBoundary = true); virtual void sewVolumes(Dart d, Dart e, bool withBoundary = true);
//! Unsew volumes pre-condition
bool unsewVolumesPreCond(Dart d);
//! Unsew two oriented volumes along their faces. //! Unsew two oriented volumes along their faces.
/*! @param d a dart of one volume /*! @param d a dart of one volume
*/ */
......
...@@ -154,10 +154,10 @@ Dart EmbeddedMap3::collapseEdge(Dart d, bool delDegenerateVolumes) ...@@ -154,10 +154,10 @@ Dart EmbeddedMap3::collapseEdge(Dart d, bool delDegenerateVolumes)
return resV; return resV;
} }
bool EmbeddedMap3::collapseDegeneratedFace(Dart d) //bool EmbeddedMap3::collapseDegeneratedFace(Dart d)
{ //{
return Map3::collapseDegeneratedFace(d); // return Map3::collapseDegeneratedFace(d);
} //}
void EmbeddedMap3::splitFace(Dart d, Dart e) void EmbeddedMap3::splitFace(Dart d, Dart e)
{ {
......
...@@ -538,10 +538,10 @@ void Map2::splitSurface(std::vector<Dart>& vd, bool firstSideClosed, bool second ...@@ -538,10 +538,10 @@ void Map2::splitSurface(std::vector<Dart>& vd, bool firstSideClosed, bool second
unsewFaces(*it) ; unsewFaces(*it) ;
if(firstSideClosed) if(firstSideClosed)
fillHole(e) ; Map2::fillHole(e) ;
if(secondSideClosed) if(secondSideClosed)
fillHole(e2) ; Map2::fillHole(e2) ;
} }
/*! @name Topological Queries /*! @name Topological Queries
......
...@@ -234,8 +234,17 @@ bool Map3::uncutEdge(Dart d) ...@@ -234,8 +234,17 @@ bool Map3::uncutEdge(Dart d)
return false; return false;
} }
bool Map3::deleteEdgePreCond(Dart d)
{
unsigned int nb1 = vertexDegree(d);
unsigned int nb2 = vertexDegree(phi1(d));
return (nb1!=2) && (nb2!=2);
}
Dart Map3::deleteEdge(Dart d) Dart Map3::deleteEdge(Dart d)
{ {
assert(deleteEdgePreCond(d));
if(isBoundaryEdge(d)) if(isBoundaryEdge(d))
return NIL ; return NIL ;
...@@ -270,41 +279,65 @@ Dart Map3::deleteEdge(Dart d) ...@@ -270,41 +279,65 @@ Dart Map3::deleteEdge(Dart d)
return res ; return res ;
} }
//Dart Map3::collapseEdge(Dart d, bool delDegenerateVolumes)
//{
// Dart resV = NIL;
//
// Dart dit = d;
//
// do
// {
// Dart e = dit;
// dit = alpha2(dit);
//
// //test si un seul polyedre autour de l'arete
// if(e == dit)
// resV == phi3(phi2(phi1(e)));
//
// if(delDegenerateVolumes)
// {
// Map2::collapseEdge(e, true);
// collapseDegeneretedVolume(e);
// }
// else
// Map2::collapseEdge(e, false);
//
// if(resV == NIL)
// {
//
// }
//
// }while(d != dit);
//
// return resV;
//}
Dart Map3::collapseEdge(Dart d, bool delDegenerateVolumes) Dart Map3::collapseEdge(Dart d, bool delDegenerateVolumes)
{ {
Dart resV = NIL; Dart resV = NIL;
Dart dit = d; Dart dit = d;
std::vector<Dart> darts;
do do
{ {
Dart e = dit; darts.push_back(dit);
dit = alpha2(dit); dit = alpha2(dit);
}while(dit != d);
//test si un seul polyedre autour de l'arete for (std::vector<Dart>::iterator it = darts.begin(); it != darts.end(); ++it)
if(e == dit) {
resV == phi3(phi2(phi1(e))); Dart x = phi2(phi_1(*it));
resV = Map2::collapseEdge(*it, true);
if(delDegenerateVolumes) if (delDegenerateVolumes)
{ collapseDegeneretedVolume(x);
Map2::collapseEdge(e, true); }
collapseDegeneretedVolume(e);
}
else
Map2::collapseEdge(e, false);
if(resV == NIL)
{
}
}while(d != dit);
return resV; return resV;
} }
// Dart e = d; // Dart e = d;
// //
// // stocke un brin par volume autour de l'arete // // stocke un brin par volume autour de l'arete
...@@ -355,22 +388,44 @@ Dart Map3::collapseEdge(Dart d, bool delDegenerateVolumes) ...@@ -355,22 +388,44 @@ Dart Map3::collapseEdge(Dart d, bool delDegenerateVolumes)
// } // }
// } // }
bool Map3::collapseDegeneratedFace(Dart d) //bool Map3::collapseDegeneratedFace(Dart d)
//{
// Dart d3 = phi3(d);
//
// std::cout << "Map3::collapseDegeneratedFace"<< std::endl;
//
// if (!isDartValid(d))
// Map2::collapseDegeneratedFace(d);
// else
// std::cout << "Warning Coll1 invalid"<< std::endl;
//
//
// if (isDartValid(d3))
// Map2::collapseDegeneratedFace(d3);
// else
// std::cout << "Warning coll2 invalid"<< std::endl;
//
//
//
///*
// Map3::unsewVolumes(d);
//
// std::cout << Map2::collapseDegeneratedFace(d) << std::endl;
// std::cout << Map2::collapseDegeneratedFace(d3) << std::endl;
// std::cout << std::endl;
//*/
// return true;
//}
bool Map3::splitFacePreCond(Dart d, Dart e)
{ {
Dart d3 = phi3(d); return (d != e && sameOrientedFace(d, e)) ;
Map3::unsewVolumes(d);
std::cout << Map2::collapseDegeneratedFace(d) << std::endl;
std::cout << Map2::collapseDegeneratedFace(d3) << std::endl;
std::cout << std::endl;
return true;
} }
void Map3::splitFace(Dart d, Dart e) void Map3::splitFace(Dart d, Dart e)
{ {
assert(d != e && sameOrientedFace(d, e)) ; // assert(d != e && sameOrientedFace(d, e)) ;
assert(splitFacePreCond(d,e));
Dart dd = phi1(phi3(d)); Dart dd = phi1(phi3(d));
Dart ee = phi1(phi3(e)); Dart ee = phi1(phi3(e));
...@@ -382,31 +437,69 @@ void Map3::splitFace(Dart d, Dart e) ...@@ -382,31 +437,69 @@ void Map3::splitFace(Dart d, Dart e)
phi3sew(phi_1(e), phi_1(dd)); phi3sew(phi_1(e), phi_1(dd));
} }
//bool Map3::collapseDegeneretedVolume(Dart d)