Commit 20c2f898 authored by Thomas's avatar Thomas

Merge branch 'master' of cgogn.unistra.fr:~cgogn/CGoGN

parents b5446e92 29f14458
......@@ -106,6 +106,15 @@ void MyQT::cb_combo6(int x)
CGoGNerr <<"undefined traversor" << CGoGNendl;
}
void MyQT::cb_explode(int x)
{
m_expl = float (x) /100.0f;
if (m_last==2)
traverse2();
if (m_last==3)
traverse3();
}
void MyQT::cb_initGL()
{
......@@ -154,6 +163,13 @@ void MyQT::cb_mousePress(int button, int x, int y)
}
void MyQT::cb_Save()
{
std::string filename = selectFileSave("Export SVG file ",".","(*.svg)");
Utils::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix());
m_drawer.toSVG(svg);
}
void MyQT::colorizeCell(Dart d, unsigned int orbit, float r,float g, float b)
{
TraversorDartsOfOrbit<PFP::MAP>doo (myMap,orbit,d);
......@@ -166,37 +182,37 @@ void MyQT::traverse2()
{
if (m_selected == NIL)
return;
m_last=2;
// int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2;
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_drawer.newList(GL_COMPILE);
m_drawer.lineWidth(3.0f);
m_drawer.pointSize(7.0f);
m_drawer.color3f(1.0f,1.0f,0.0f);
m_drawer.color3f(0.0f,0.7f,0.0f);
m_affDarts.clear();
if (m_ajd_or_inci2 == 0) // incident
{
Algo::Render::drawerCell<PFP>(VERTEX+m_second2, m_drawer,myMap,m_selected,position,0.7f);
Algo::Render::drawerCell<PFP>(VERTEX+m_second2, m_drawer,myMap,m_selected,position,m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createIncident(myMap,m_selected,VERTEX+m_second2,VERTEX+m_first2);
for (Dart d=tra->begin(); d != tra->end(); d= tra->next())
m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,0.7f);
Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,m_expl);
}
else // adjacent
{
Algo::Render::drawerCell<PFP>(VERTEX+m_first2, m_drawer,myMap,m_selected,position,0.7f);
Algo::Render::drawerCell<PFP>(VERTEX+m_first2, m_drawer,myMap,m_selected,position,m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createAdjacent(myMap,m_selected,VERTEX+m_first2,VERTEX+m_second2);
for (Dart d=tra->begin(); d != tra->end(); d= tra->next())
m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,0.7f);
Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap,m_affDarts,position,m_expl);
}
m_drawer.endList();
......@@ -207,35 +223,36 @@ void MyQT::traverse2()
void MyQT::traverse3()
{
// int code = (m_ajd_or_inci3)*100+m_first3*10+m_second3;
// std::cout << "CODE="<< code << std::endl;
if (m_selected == NIL)
return;
m_last=3;
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_affDarts.clear();
m_drawer.newList(GL_COMPILE);
m_drawer.lineWidth(3.0f);
m_drawer.pointSize(7.0f);
m_drawer.color3f(1.0f,1.0f,0.0f);
m_drawer.color3f(0.0f,0.7f,0.0f);
if (m_ajd_or_inci3 == 0) // incident
{
Algo::Render::drawerCell<PFP>(VERTEX+m_second3, m_drawer,myMap,m_selected,position,0.7f);
Algo::Render::drawerCell<PFP>(VERTEX+m_second3, m_drawer,myMap,m_selected,position,m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor3XY<PFP::MAP> tra(myMap,m_selected,VERTEX+m_second3,VERTEX+m_first3);
for (Dart d=tra.begin(); d != tra.end(); d= tra.next())
m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,0.7f);
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl);
}
else // adjacent
{
Algo::Render::drawerCell<PFP>(VERTEX+m_first3, m_drawer,myMap,m_selected,position,0.7f);
Algo::Render::drawerCell<PFP>(VERTEX+m_first3, m_drawer,myMap,m_selected,position,m_expl);
m_drawer.color3f(1.0f,0.0f,0.0f);
Traversor3XXaY<PFP::MAP> tra(myMap,m_selected,VERTEX+m_first3,VERTEX+m_second3);
for (Dart d=tra.begin(); d != tra.end(); d= tra.next())
m_affDarts.push_back(d);
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,0.7f);
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl);
}
m_drawer.endList();
......@@ -280,6 +297,7 @@ int main(int argc, char **argv)
sqt.setCallBack( dock.combo4, SIGNAL( activated(int)), SLOT(cb_combo4(int)) );
sqt.setCallBack( dock.combo5, SIGNAL( activated(int)), SLOT(cb_combo5(int)) );
sqt.setCallBack( dock.combo6, SIGNAL( activated(int)), SLOT(cb_combo6(int)) );
sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(cb_explode(int)) );
sqt.setCallBack( dock.checkTopo, SIGNAL( clicked(bool)), SLOT(cb_checkTopo(bool)) );
......
......@@ -96,6 +96,8 @@ class MyQT: public Utils::QT::SimpleQT
unsigned int m_first2;
unsigned int m_ajd_or_inci2;
unsigned int m_second2;
float m_expl;
unsigned int m_last;
public:
MyQT():
m_render_topo(NULL),
......@@ -106,6 +108,8 @@ public:
m_first2(0),
m_ajd_or_inci2(0),
m_second2(1),
m_expl(0.8f),
m_last(2),
m_selected(NIL)
{}
......@@ -122,6 +126,8 @@ protected:
void cb_initGL();
void cb_Save();
void cb_mousePress(int button, int x, int y);
void colorizeCell(Dart d, unsigned int orbit, float r,float g, float b);
......@@ -139,6 +145,8 @@ public slots:
void cb_combo5(int x);
void cb_combo6(int x);
void cb_checkTopo(bool b);
void cb_explode(int x);
};
#endif
......@@ -210,6 +210,29 @@
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="explodeSlider">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="sliderPosition">
<number>80</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkTopo">
<property name="focusPolicy">
......
......@@ -249,8 +249,11 @@ void MyQT::cb_keyPress(int code)
svg.setWidth(1.0f);
svg.setColor(Geom::Vec3f(0.0f,0.0f,0.5f));
Algo::Render::SVG::renderEdges<PFP>(svg,myMap,position);
svg.setColor(Geom::Vec3f(0.0f,0.8f,0.0f));
svg.setWidth(5.0f);
Algo::Render::SVG::renderVertices<PFP>(svg,myMap,position);
svg.setColor(Geom::Vec3f(1.0f,0.0f,0.0f));
m_strings->toSVG(svg);
//svg destruction close the file
}
if (code == 't')
......@@ -333,6 +336,7 @@ int main(int argc, char **argv)
sqt.m_selected = myMap.begin();
sqt.setGeometry(100,100,1024,1024);
sqt.show();
sqt.slider_balls(50);
......
......@@ -26,6 +26,9 @@
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Geometry/centroid.h"
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
using namespace CGoGN ;
......@@ -146,6 +149,17 @@ void MyQT::operation(int x)
m_selected=NIL;
}
break;
case 9:
CGoGNout <<"delete face"<<CGoGNendl;
if (m_selected != NIL)
{
myMap.deleteFace(m_selected);
updateMap();
m_selected=NIL;
m_selected2=NIL;
}
break;
default:
break;
}
......@@ -164,14 +178,10 @@ void MyQT::createMap(int n)
grid.grid_topo(n,n);
grid.embedGrid(1.,1.,0.);
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
// send BB info to interface for centering on GL screen
setParamObject(lWidthObj, lPosObj.data());
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f;
// first show for be sure that GL context is binded
show();
......@@ -296,16 +306,113 @@ void MyQT::cb_keyPress(int keycode)
}
}
break;
case Qt::Key_Up:
if (m_selected!=NIL)
position[m_selected][1] +=m_shift;
updateMap();
updateGL();
break;
case Qt::Key_Down:
if (m_selected!=NIL)
position[m_selected][1] -= m_shift;
updateMap();
updateGL();
break;
case Qt::Key_Left:
if (m_selected!=NIL)
position[m_selected][0] -= m_shift;
updateMap();
updateGL();
break;
case Qt::Key_Right:
if (m_selected!=NIL)
position[m_selected][0] += m_shift;
updateMap();
updateGL();
break;
}
updateGL();
}
void MyQT::svg()
{
if (m_selected!=NIL)
m_render_topo->setDartColor(m_selected,0.8f,0.0f,0.0f);
if (m_selected2!=NIL)
m_render_topo->setDartColor(m_selected2,0.0f,0.8f,0.0f);
std::string filename = selectFileSave("snapshot file", ".", "(*.svg)");
m_render_topo->svgout2D(filename, modelViewMatrix(),projectionMatrix());
}
void MyQT::cb_Open()
{
std::string filters("all (*.*);; trian (*.trian);; off (*.off);; ply (*.ply);; map (*.map)") ;
std::string filename = selectFile("Open Mesh", "", filters) ;
if (!filename.empty())
importMesh(filename);
updateGL();
}
void MyQT::cb_Save()
{
std::string filename = selectFileSave("Export SVG file ",".","(*.off)");
Algo::Export::exportOFF<PFP>(myMap,position,filename.c_str());
}
void MyQT::importMesh(std::string& filename)
{
myMap.clear(true) ;
size_t pos = filename.rfind("."); // position of "." in filename
std::string extension = filename.substr(pos);
if (extension == std::string(".map"))
{
myMap.loadMapBin(filename);
position = myMap.getAttribute<PFP::VEC3>(VERTEX, "position") ;
}
else
{
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, filename.c_str(), attrNames))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
position = myMap.getAttribute<PFP::VEC3>(VERTEX, attrNames[0]) ;
}
colorDarts = myMap.getAttribute<PFP::VEC3>(DART, "color");
if (!colorDarts.isValid())
{
colorDarts = myMap.addAttribute<PFP::VEC3>(DART, "color");
for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d))
{
if (dm.isMarked(d) && (!myMap.isBoundaryMarked(d)))
{
int n = random();
float r = float(n&0x7f)/255.0f + 0.25f;
float g = float((n>>8)&0x7f)/255.0f + 0.25f;
float b = float((n>>16)&0x7f)/255.0 + 0.25f;
colorDarts[d] = Geom::Vec3f(r,g,b);
m_render_topo->setDartColor(d,r,g,b);
}
}
}
m_selected = NIL;
m_selected2 = NIL;
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f;
updateMap();
updateGLMatrices() ;
}
void MyQT::width(int w)
{
m_render_topo->setDartWidth(w);
......
......@@ -67,12 +67,14 @@ class MyQT: public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap) {}
MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f) {}
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;
......@@ -90,6 +92,7 @@ protected:
Dart m_selected;
Dart m_selected2;
DartMarker dm;
float m_shift;
// just for more compact writing
inline Dart PHI1(Dart d) {return myMap.phi1(d);}
......@@ -102,6 +105,7 @@ public:
// example of simple map creation
void createMap(int n);
void updateMap();
void importMesh(std::string& filename);
public slots:
void operation(int x);
......
......@@ -94,6 +94,11 @@
<string>mergeFace</string>
</property>
</item>
<item>
<property name="text">
<string>deleteFace</string>
</property>
</item>
</widget>
</item>
<item>
......
......@@ -87,11 +87,11 @@ public:
Dart alpha_1(Dart d) ;
virtual Dart begin() ;
virtual Dart begin() const ;
virtual Dart end() ;
virtual Dart end() const ;
virtual void next(Dart& d) ;
virtual void next(Dart& d) const ;
virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) ;
......
......@@ -139,7 +139,7 @@ inline Dart ImplicitHierarchicalMap::alpha_1(Dart d)
return Map2::alpha_1(d) ;
}
inline Dart ImplicitHierarchicalMap::begin()
inline Dart ImplicitHierarchicalMap::begin() const
{
Dart d = Map2::begin() ;
while(d != Map2::end() && m_dartLevel[d] > m_curLevel)
......@@ -147,12 +147,12 @@ inline Dart ImplicitHierarchicalMap::begin()
return d ;
}
inline Dart ImplicitHierarchicalMap::end()
inline Dart ImplicitHierarchicalMap::end() const
{
return Map2::end() ;
}
inline void ImplicitHierarchicalMap::next(Dart& d)
inline void ImplicitHierarchicalMap::next(Dart& d) const
{
do
{
......
......@@ -360,11 +360,11 @@ public:
*************************************************************************/
//@{
virtual Dart begin() ;
virtual Dart begin() const;
virtual Dart end() ;
virtual Dart end() const;
virtual void next(Dart& d) ;
virtual void next(Dart& d) const ;
virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) ;
......
......@@ -200,7 +200,7 @@ inline Dart ImplicitHierarchicalMap3::alpha_2(Dart d)
return phi2(phi3(d));
}
inline Dart ImplicitHierarchicalMap3::begin()
inline Dart ImplicitHierarchicalMap3::begin() const
{
Dart d = Map3::begin() ;
while(m_dartLevel[d] > m_curLevel)
......@@ -208,12 +208,12 @@ inline Dart ImplicitHierarchicalMap3::begin()
return d ;
}
inline Dart ImplicitHierarchicalMap3::end()
inline Dart ImplicitHierarchicalMap3::end() const
{
return Map3::end() ;
}
inline void ImplicitHierarchicalMap3::next(Dart& d)
inline void ImplicitHierarchicalMap3::next(Dart& d) const
{
do
{
......
......@@ -298,7 +298,7 @@ bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<
do
{
std::getline (fp, ligne);
} while (ligne.size()==0);
} while (ligne.size() == 0);
std::stringstream oss(ligne);
oss >> m_nbVertices;
......@@ -344,10 +344,10 @@ bool MeshTablesSurface<PFP>::importOff(const std::string& filename, std::vector<
} while (ligne.size() == 0);
std::stringstream oss(ligne);
int n;
unsigned int n;
oss >> n;
m_nbEdges.push_back(n);
for (int j=0;j<n; ++j)
for (unsigned int j = 0; j < n; ++j)
{
int index; // index du plongement
oss >> index;
......@@ -455,7 +455,7 @@ bool MeshTablesSurface<PFP>::importObj(const std::string& filename, std::vector<
unsigned int ind = 0;
while ( (ind<str.length()) && (str[ind]!='/'))
while ((ind<str.length()) && (str[ind]!='/'))
ind++;
if (ind > 0)
......
/*******************************************************************************
* 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 __IMPORT_MR_DAT__
#define __IMPORT_MR_DAT__
namespace CGoGN
{
namespace Algo
{
namespace Import
{
class QuadTreeNode
{
public:
unsigned int indices[3] ;
QuadTreeNode* children[4] ;
QuadTreeNode* parent ;
unsigned int level ;
QuadTreeNode()
{
for(unsigned int i = 0; i < 3; ++i)
indices[i] = -1 ;
for(unsigned int i = 0; i < 4; ++i)
children[i] = NULL ;
parent = NULL ;
level = 0 ;
}
~QuadTreeNode()
{
for(unsigned int i = 0; i < 4; ++i)
if(children[i] != NULL)
delete children[i] ;
}
void subdivide()
{
assert(!isSubdivided()) ;
for(unsigned int i = 0; i < 4; ++i)
{
children[i] = new QuadTreeNode() ;
children[i]->parent = this ;
children[i]->level = level + 1 ;
}
}
bool isSubdivided()
{
return children[0] != NULL ;
}
template <typename PFP>
void embed(typename PFP::MAP& map, Dart d, std::vector<unsigned int>& vID)
{
assert(map.getCurrentLevel() == level) ;
if(isSubdivided())
{
unsigned int v0 = vID[indices[0]] ;
unsigned int v1 = vID[indices[1]] ;
unsigned int v2 = vID[indices[2]] ;
Dart it = d ;
do
{
Dart next = map.phi1(it) ;
unsigned int emb = map.getEmbedding(VERTEX, it) ;
unsigned int idx = emb == v0 ? 0 : emb == v1 ? 1 : 2 ;
map.incCurrentLevel() ;
Dart dd = map.phi1(next) ;
unsigned int oldEmb = map.getEmbedding(VERTEX, dd) ;
unsigned int newEmb = vID[children[0]->indices[idx]] ;
if(oldEmb == EMBNULL)
{
map.embedOrbit(VERTEX, dd, newEmb) ;
map.pushLevel() ;
for(unsigned int i = map.getCurrentLevel() + 1; i <= map.getMaxLevel(); ++i)
{
map.setCurrentLevel(i) ;
map.embedOrbit(VERTEX, dd, newEmb) ;
}
map.popLevel() ;
}
else
assert(oldEmb == newEmb) ;
map.decCurrentLevel() ;
it = next ;
} while(it != d) ;
map.incCurrentLevel() ;
Dart d0 = map.phi2(map.phi1(d)) ;
children[0]->embed<PFP>(map, d0, vID) ;
map.decCurrentLevel() ;
do
{
unsigned int emb = map.getEmbedding(VERTEX, it) ;
unsigned int idx = emb == v0 ? 0 : emb == v1 ? 1 : 2 ;
map.incCurrentLevel() ;
children[idx+1]->embed<PFP>(map, it, vID) ;
map.decCurrentLevel() ;
it = map.phi1(it) ;
} while(it != d) ;
}
else
{
if(map.getCurrentLevel() < map.getMaxLevel())
std::cout << "adaptive subdivision not managed yet" << std::endl ;
}
}
void print()
{
std::cout << indices[0] << " " << indices[1] << " " << indices[2] << std::endl ;
if(isSubdivided())
{
for(unsigned int i = 0; i < 4; ++i)
children[i]->print() ;
}