Commit 81c4b3e7 authored by Thomas's avatar Thomas

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

parents ed5a6193 fbf4fa5d
......@@ -77,4 +77,11 @@ QT4_WRAP_UI( volumeExplorer_ui ../volumeExplorer.ui )
QT4_WRAP_CPP( volumeExplorer_moc ../volumeExplorer.h )
add_executable( volumeExplorerD ../volumeExplorer.cpp ${volumeExplorer_ui} ${volumeExplorer_moc})
target_link_libraries( volumeExplorerD
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
\ No newline at end of file
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_UI( mcmesh_ui ../mcmesh.ui )
QT4_WRAP_CPP( mcmesh_moc ../mcmesh.h )
add_executable( mcmeshD ../mcmesh.cpp
${mcmesh_moc}
${mcmesh_ui} )
target_link_libraries( mcmeshD ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS})
......@@ -70,4 +70,12 @@ QT4_WRAP_CPP( volumeExplorer_moc ../volumeExplorer.h )
add_executable( volumeExplorer ../volumeExplorer.cpp ${volumeExplorer_ui} ${volumeExplorer_moc})
target_link_libraries( volumeExplorer
${CGoGN_LIBS_R} ${CGoGN_EXT_LIBS} )
\ No newline at end of file
QT4_WRAP_UI( mcmesh_ui ../mcmesh.ui )
QT4_WRAP_CPP( mcmesh_moc ../mcmesh.h )
add_executable( mcmesh
../mcmesh.cpp
${mcmesh_moc}
${mcmesh_ui} )
target_link_libraries( mcmesh ${CGoGN_LIBS_R} ${CGoGN_EXT_LIBS})
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "mcmesh.h"
MCMesh::MCMesh() :
m_drawEdges(true),
m_drawFaces(true),
m_render(NULL),
m_flatShader(NULL),
m_simpleColorShader(NULL)
{
}
void MCMesh::initGUI()
{
setDock(&dock);
dock.check_drawEdges->setChecked(true);
dock.check_drawFaces->setChecked(true);
setCallBack( dock.check_drawEdges, SIGNAL(toggled(bool)), SLOT(slot_drawEdges(bool)) );
setCallBack( dock.check_drawFaces, SIGNAL(toggled(bool)), SLOT(slot_drawFaces(bool)) );
}
void MCMesh::cb_initGL()
{
Geom::Vec4f colClear(0.2f, 0.2f, 0.2f, 0.1f);
Geom::Vec4f colDif(0.8f, 0.9f, 0.7f, 1.0f);
Geom::Vec4f colSpec(0.9f, 0.9f, 0.9f, 1.0f);
Utils::GLSLShader::setCurrentOGLVersion(2);
m_render = new Algo::Render::GL2::MapRender();
m_positionVBO = new Utils::VBO();
m_flatShader = new Utils::ShaderFlat();
m_flatShader->setAttributePosition(m_positionVBO);
m_flatShader->setAmbiant(colClear);
m_flatShader->setDiffuse(colDif);
m_flatShader->setExplode(1.0f);
m_simpleColorShader = new Utils::ShaderSimpleColor();
m_simpleColorShader->setAttributePosition(m_positionVBO);
registerShader(m_flatShader);
registerShader(m_simpleColorShader);
}
void MCMesh::cb_redraw()
{
if (m_drawEdges)
{
glLineWidth(1.0f);
if (m_drawFaces)
{
Geom::Vec4f c(0.0f, 0.0f, 0.0f, 0.0f);
m_simpleColorShader->setColor(c);
}
else
{
Geom::Vec4f c(1.0f, 1.0f, 0.0f, 0.0f);
m_simpleColorShader->setColor(c);
}
m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES);
}
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
if (m_drawFaces)
{
m_flatShader->setExplode(1.0f);
m_render->draw(m_flatShader, Algo::Render::GL2::TRIANGLES);
}
else
{
if (m_drawEdges)
{
Geom::Vec4f c(0.0f, 0.0f, 0.0f, 0.0f);
m_simpleColorShader->setColor(c);
m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
}
}
glDisable(GL_POLYGON_OFFSET_FILL);
}
void MCMesh::cb_Open()
{
// std::string filters("all (*.*);; trian (*.trian);; ctm (*.ctm);; off (*.off);; ply (*.ply)");
// std::string filename = selectFile("Open Mesh", "", filters);
// if (filename.empty())
// return;
//
// updateGL();
}
void MCMesh::slot_drawEdges(bool b)
{
m_drawEdges = b;
updateGL();
}
void MCMesh::slot_drawFaces(bool b)
{
m_drawFaces = b;
updateGL();
}
void MCMesh::MC()
{
myMap.clear(false);
// elargir l'image pour le calcul de la courbure
Algo::MC::Image<DATATYPE>* myImgFr = myImg->addFrame(1);
Algo::MC::WindowingGreater<DATATYPE> myWindFunc;
myWindFunc.setIsoValue(DATATYPE(127));
position = myMap.getAttribute<PFP::VEC3>(VERTEX, "position");
if (!position.isValid())
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
// instanciation du mc
Algo::MC::MarchingCube<DATATYPE, Algo::MC::WindowingGreater,PFP> mc(myImgFr, &myMap, position, myWindFunc, false);
mc.simpleMeshing();
delete myImgFr;
updateRender();
updateGL();
}
void MCMesh::updateRender()
{
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render->initPrimitives<PFP>(myMap, nb, Algo::Render::GL2::LINES);
m_render->initPrimitives<PFP>(myMap, nb, Algo::Render::GL2::TRIANGLES);
m_positionVBO->updateData(position);
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
setParamObject(bb.maxSize(), bb.center().data());
updateGLMatrices();
}
void MCMesh::fromFile(char* fname)
{
myImg = new Algo::MC::Image<DATATYPE>();
myImg->loadInrgz(fname);
CGoGNout << "Image chargee"<<CGoGNendl;
CGoGNout << myImg->getWidthX() <<"x"<< myImg->getWidthY() <<"x"<< myImg->getWidthZ() << "voxels"<<CGoGNendl;
}
void MCMesh::sphere()
{
DATATYPE *img = new DATATYPE[128*128*128];
DATATYPE *ptr = img;
for (int x=0; x<128; ++x)
for (int y=0; y<128; ++y)
for (int z=0; z<128; ++z)
{
Geom::Vec3f V(x-64, y-64, z-64);
if (V.norm() < 30)
*ptr++ = 255;
else
*ptr++ = 0;
}
myImg = new Algo::MC::Image<DATATYPE>(img,128,128,128,1.0f,1.0f,1.0f,false);
}
/**********************************************************************************************
* MAIN FUNCTION *
**********************************************************************************************/
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MCMesh sqt;
sqt.setGeometry(0, 0, 1000, 800);
sqt.show();
sqt.valLabel=DATATYPE(0);
if(argc == 2)
{
sqt.fromFile(argv[1]);
}
else
{
sqt.sphere();
}
sqt.initGUI();
sqt.show();
sqt.MC();
return app.exec();
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009, 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <iostream>
#include "Utils/Qt/qtSimple.h"
#include "ui_mcmesh.h"
#include "Utils/Qt/qtui.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/map/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/MC/marchingcube.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2 MAP ;
};
typedef PFP::MAP MAP ;
typedef unsigned char DATATYPE;
class MCMesh : public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MAP myMap ;
SelectorTrue allDarts ;
Utils::QT::uiDockInterface dock ;
float shininess ;
Geom::BoundingBox<PFP::VEC3> bb ;
bool m_drawEdges ;
bool m_drawFaces ;
PFP::TVEC3 position ;
Algo::Render::GL2::MapRender* m_render ;
Utils::VBO* m_positionVBO ;
Utils::ShaderFlat* m_flatShader ;
Utils::ShaderSimpleColor* m_simpleColorShader ;
DATATYPE valLabel;
Algo::MC::Image<DATATYPE>* myImg;
MCMesh() ;
void initGUI();
void updateRender();
void MC();
void cb_initGL() ;
void cb_redraw() ;
void cb_Open() ;
void fromFile(char* fname);
void sphere();
public slots:
void slot_drawEdges(bool b) ;
void slot_drawFaces(bool b) ;
};
<?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>134</width>
<height>513</height>
</rect>
</property>
<property name="windowTitle">
<string>DockWidget</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="check_drawEdges">
<property name="text">
<string>draw edges</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="check_drawFaces">
<property name="text">
<string>draw faces</string>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>2</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
......@@ -354,7 +354,7 @@ int main(int argc, char **argv)
{
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
Algo::Modelisation::Primitive3D<PFP> prim(myMap, position);
int nb = 32;
int nb = 8;
prim.hexaGrid_topo(nb,nb,nb);
prim.embedHexaGrid(1.0f,1.0f,1.0f);
......
......@@ -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})
target_link_libraries( tuto_oper2
${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_CPP(tuto_orbits_moc tuto_orbits.h)
......
......@@ -125,6 +125,7 @@ void MyQT::cb_initGL()
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f, nb);
m_dm_topo = new DartMarker(myMap);
}
......@@ -135,8 +136,8 @@ void MyQT::cb_redraw()
m_render_topo->drawTopo();
if (m_selected != NIL)
m_render_topo->overdrawDart(m_selected, 6, 1.0f, 0.0f, 1.0f);
m_render_topo->overdrawDart(m_selected, 7, 1.0f, 0.0f, 1.0f);
for (std::vector<Dart>::iterator it=m_affDarts.begin(); it!=m_affDarts.end(); ++it)
{
m_render_topo->overdrawDart(*it, 6, 1.0f, 1.0f, 1.0f);
......@@ -165,9 +166,33 @@ 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);
// m_render_topo->toSVG(svg);
Utils::SVG::SVGOut svg1(modelViewMatrix(),projectionMatrix());
m_drawer.toSVG(svg1);
svg1.addOpacityAnimation(1.0f);
svg1.addOpacityAnimation(1.0f);
svg1.addOpacityAnimation(0.0f);
Utils::SVG::SVGOut svg2(modelViewMatrix(),projectionMatrix());
m_render_topo->toSVG(svg2);
svg2.addOpacityAnimation(1.0f);
svg2.addOpacityAnimation(0.0f);
svg2.addOpacityAnimation(1.0f);
Utils::SVG::AnimatedSVGOut anim;
anim.add(&svg1);
anim.add(&svg2);
std::string filename = selectFileSave("Export SVG file ",".","(*.svg)");
Utils::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix());
m_drawer.toSVG(svg);
anim.write(filename, 2.0f);
}
void MyQT::colorizeCell(Dart d, unsigned int orbit, float r,float g, float b)
......@@ -187,8 +212,8 @@ void MyQT::traverse2()
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_drawer.newList(GL_COMPILE);
m_drawer.lineWidth(3.0f);
m_drawer.pointSize(7.0f);
m_drawer.lineWidth(7.0f);
m_drawer.pointSize(9.0f);
m_drawer.color3f(0.0f,0.7f,0.0f);
m_affDarts.clear();
......@@ -216,6 +241,10 @@ void MyQT::traverse2()
}
m_drawer.endList();
SelectorMarked sm(*m_dm_topo);
m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f, sm );
updateGL();
}
......@@ -232,30 +261,55 @@ void MyQT::traverse3()
m_affDarts.clear();
m_drawer.newList(GL_COMPILE);
m_drawer.lineWidth(3.0f);
m_drawer.pointSize(7.0f);
m_drawer.lineWidth(7.0f);
m_drawer.pointSize(9.0f);
m_drawer.color3f(0.0f,0.7f,0.0f);
m_dm_topo->unmarkAll();
SelectorMarked sm(*m_dm_topo);
if (m_ajd_or_inci3 == 0) // incident
{
Algo::Render::drawerCell<PFP>(VERTEX+m_second3, m_drawer,myMap,m_selected,position,m_expl);
m_dm_topo->markOrbit(VERTEX+m_second3,m_selected);
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);
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit(VERTEX+m_first3,d);
}
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl);
m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f, sm);
for (std::vector<Dart>::iterator id=m_affDarts.begin(); id != m_affDarts.end(); ++id)
m_render_topo->setDartColor(*id,0.7f,0.0f,0.0f);
m_render_topo->setDartColor(m_selected,0.0f,0.7f,0.0f);
}
else // adjacent
{
Algo::Render::drawerCell<PFP>(VERTEX+m_first3, m_drawer,myMap,m_selected,position,m_expl);
m_dm_topo->markOrbit(VERTEX+m_first3,m_selected);
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);
{
m_affDarts.push_back(d);
m_dm_topo->markOrbit(VERTEX+m_first3,d);
}
Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl);
m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f, sm);
for (std::vector<Dart>::iterator id=m_affDarts.begin(); id != m_affDarts.end(); ++id)
m_render_topo->setDartColor(*id,0.7f,0.0f,0.0f);
m_render_topo->setDartColor(m_selected,0.0f,0.7f,0.0f);
}
m_drawer.endList();
updateGL();
}
......
......@@ -110,7 +110,8 @@ public:
m_second2(1),
m_expl(0.8f),
m_last(2),
m_selected(NIL)
m_selected(NIL),
m_dm_topo(NULL)
{}
......@@ -119,6 +120,8 @@ public:
Utils::Drawer m_drawer;
DartMarker* m_dm_topo;
protected:
void storeVerticesInfo();
......
/*******************************************************************************
* 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 "tuto_oper3.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/primitives3d.h"
#include "Algo/Geometry/centroid.h"
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
using namespace CGoGN ;
int main(int argc, char **argv)
{
// // interface
QApplication app(argc, argv);
MyQT sqt;
sqt.setDock(& sqt.dock);
sqt.setCallBack( sqt.dock.listOper, SIGNAL(currentRowChanged(int)), SLOT(operation(int)) );
sqt.setCallBack( sqt.dock.svg, SIGNAL(clicked()), SLOT(svg()) );
sqt.setCallBack( sqt.dock.widthSlider, SIGNAL(valueChanged(int)), SLOT(width(int)) );
int n=3;
if (argc==2)
n = atoi(argv[1]);
// example code itself
sqt.createMap(n);
sqt.width(5);
// set help message in menu
sqt.setHelpMsg("First Tuto: \nCreate two faces\nsew them\nand affect positions");
// final show for redraw
sqt.show();
// and wait for the end
return app.exec();
}
void MyQT::operation(int x)
{
switch(x)
{
case 0:
CGoGNout <<"delete vertex"<<CGoGNendl;
if (m_selected != NIL)
{
dm.markAll();
m_selected=myMap.deleteVertex(m_selected);
m_selected = NIL;
updateMap();
}
break;
case 1:
CGoGNout <<"cut edge"<<CGoGNendl;
if (m_selected != NIL)
{
dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.cutEdge(m_selected);
position[myMap.phi1(m_selected)] = (position[m_selected] + Q)/2.0f;
updateMap();
}
break;
case 2:
CGoGNout <<"uncut edge"<<CGoGNendl;
if (m_selected != NIL)
{
dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.uncutEdge(m_selected);
updateMap();
}
break;
case 3:
CGoGNout <<"delete edge"<<CGoGNendl;
if (m_selected != NIL)
{
if (myMap.deleteEdgePreCond(m_selected))
{
dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.deleteEdge(m_selected);
m_selected = NIL;
updateMap();
}
else
{
CGoGNerr << "Could not delete this edge" << CGoGNendl;
}
}
break;
case 4:
CGoGNout <<"collapse edge"<<CGoGNendl;
if (m_selected != NIL)
{
PFP::VEC3 Q = (position[myMap.phi1(m_selected)] + position