Commit cb0ca9b0 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge cgogn:~cgogn/CGoGN

parents d8a25512 c6088ade
......@@ -34,27 +34,31 @@ SimpleGMap3::SimpleGMap3()
normal = myMap.addAttribute<VEC3, VERTEX>("normal");
volume = myMap.addAttribute<VEC3, VOLUME>("volume");
CellMarker<EDGE> mE(myMap);
Algo::Modelisation::Primitive3D<PFP> primCat(myMap,position);
Dart d = primCat.hexaGrid_topo(3,1,1);
primCat.embedHexaGrid(2,1,1);
std::cout << "AAA"<< std::endl;
myMap.check();
std::cout << "AAA"<< std::endl;
DartMarker markOrient(myMap);
std::vector<Dart> orient;
FunctorStore fs(orient);
// DartMarker markOrient(myMap);
// std::vector<Dart> orient;
// FunctorStore fs(orient);
d = 49;
myMap.foreach_dart_of_oriented_volume(d, fs);
// d = 49;
// myMap.foreach_dart_of_oriented_volume(d, fs);
// for(std::vector<Dart>::iterator it = orient.begin() ; it != orient.end() ; ++it)
// markOrient.mark(*it);
std::cout << "AAA"<< std::endl;
// SelectorMarked sm(markOrient);
// std::cout << "AAA"<< std::endl;
// Algo::Modelisation::catmullClarkVol<PFP,PFP::TVEC3,PFP::VEC3>(myMap, position, sm);
for(std::vector<Dart>::iterator it = orient.begin() ; it != orient.end() ; ++it)
markOrient.mark(*it);
// Geom::Plane3D<PFP::REAL> pl(VEC3(0.5,0.14,0.5),VEC3(1.5,0.45,0.5),VEC3(0.5,0.15,1.5));
Geom::Plane3D<PFP::REAL> pl(VEC3(-1,-0.5,-0.5),VEC3(-1,-0.5,0.5),VEC3(1,0.5,0.5));
Algo::Modelisation::sliceConvexVolume<PFP>(myMap, position, d, pl);
SelectorMarked sm(markOrient);
std::cout << "AAA"<< std::endl;
//Algo::Modelisation::catmullClarkVol<PFP,PFP::TVEC3,PFP::VEC3>(myMap, position, sm);
myMap.check();
for(unsigned int i = position.begin() ; i != position.end() ; position.next(i))
position[i] += VEC3(2,0,0);
......@@ -77,6 +81,10 @@ SimpleGMap3::SimpleGMap3()
myMap.cutEdge(d);
position[myMap.phi1(d)] = mid;
myMap.splitFace(d,myMap.phi1(myMap.phi1(myMap.phi1(d))));
myMap.check();
for(unsigned int i = position.begin() ; i != position.end() ; position.next(i))
position[i] += VEC3(0,2,0);
......@@ -112,12 +120,13 @@ void SimpleGMap3::cb_redraw()
glDisable(GL_LIGHTING);
glLineWidth(1.0f);
Algo::Render::GL1::renderTopoGMD3<PFP>(myMap, position, true, true, true, true, 0.9f, 0.9f, 0.9f, 0.9f);
// Algo::Render::GL1::renderTopoMD3<PFP>(myMap, position, true, true, true, 0.9f, 0.9f, 0.9f);
glDisable(GL_LIGHTING);
glColor3f(1.0f, 1.0f, 1.0f);
glLineWidth(1.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Algo::Render::GL1::renderTriQuadPoly<PFP>(myMap, Algo::Render::GL1::LINE, 1.0,position, normal);
// glDisable(GL_LIGHTING);
// glColor3f(1.0f, 1.0f, 1.0f);
// glLineWidth(1.0f);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// Algo::Render::GL1::renderTriQuadPoly<PFP>(myMap, Algo::Render::GL1::LINE, 1.0,position, normal);
}
/**********************************************************************************************
......
......@@ -28,6 +28,7 @@
#include "Topology/generic/parameters.h"
#include "Topology/gmap/embeddedGMap3.h"
//#include "Topology/map/embeddedMap3.h"
#include "Geometry/vector_gen.h"
......@@ -40,6 +41,7 @@ struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedGMap3 MAP ;
// typedef EmbeddedMap3 MAP ;
};
typedef PFP::MAP MAP ;
......
......@@ -185,7 +185,7 @@ void Viewer::cb_Open()
void Viewer::cb_Save()
{
std::string filters("all (*.*);; map (*.map);; off (*.off);; ply (*.ply);; plygen (*.plygen)") ;
std::string filters("all (*.*);; map (*.map);; off (*.off);; ply (*.ply)") ;
std::string filename = selectFileSave("Save Mesh", "", filters) ;
exportMesh(filename) ;
......@@ -239,7 +239,7 @@ void Viewer::importMesh(std::string& filename)
updateGLMatrices() ;
}
void Viewer::exportMesh(std::string& filename)
void Viewer::exportMesh(std::string& filename, bool askExportMode)
{
size_t pos = filename.rfind(".") ; // position of "." in filename
std::string extension = filename.substr(pos) ;
......@@ -248,9 +248,13 @@ void Viewer::exportMesh(std::string& filename)
Algo::Export::exportOFF<PFP>(myMap, position, filename.c_str(), allDarts) ;
else if (extension.compare(0, 4, std::string(".ply")) == 0)
{
int ascii = 0 ;
if (askExportMode)
Utils::QT::inputValues(Utils::QT::VarCombo("binary mode;ascii mode",ascii,"Save in")) ;
std::vector<VertexAttribute<VEC3>*> attributes ;
attributes.push_back(&position) ;
Algo::Export::exportPLYnew<PFP>(myMap, attributes, filename.c_str(), true, allDarts) ;
Algo::Export::exportPLYnew<PFP>(myMap, attributes, filename.c_str(), !ascii, allDarts) ;
}
else if (extension == std::string(".map"))
myMap.saveMapBin(filename) ;
......@@ -307,6 +311,21 @@ void Viewer::slot_normalsSize(int i)
updateGL() ;
}
void Viewer::cb_keyPress(int keycode)
{
switch(keycode)
{
case 'c' :
myMap.check();
break;
default:
break;
}
updateGLMatrices() ;
updateGL();
}
/**********************************************************************************************
* MAIN FUNCTION *
**********************************************************************************************/
......@@ -327,7 +346,7 @@ int main(int argc, char **argv)
{
std::string filenameExp(argv[2]) ;
std::cout << "Exporting " << filename << " as " << filenameExp << " ... "<< std::flush ;
sqt.exportMesh(filenameExp) ;
sqt.exportMesh(filenameExp, false) ;
std::cout << "done!" << std::endl ;
return (0) ;
......
......@@ -46,6 +46,7 @@
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h"
#include "Utils/text3d.h"
#include "Utils/Qt/qtInputs.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h"
......@@ -117,8 +118,10 @@ public:
void cb_Open() ;
void cb_Save() ;
void cb_keyPress(int keycode);
void importMesh(std::string& filename) ;
void exportMesh(std::string& filename);
void exportMesh(std::string& filename, bool askExportMode = true);
public slots:
void slot_drawVertices(bool b) ;
......
......@@ -319,6 +319,18 @@ int main(int argc, char **argv)
position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
}
if(extension == std::string(".node"))
{
if(!Algo::Import::importMeshV<PFP>(myMap, argv[1], attrNames, Algo::Import::ImportVolumique::NODE))
{
std::cerr << "could not import " << argv[1] << std::endl ;
return 1;
}
else
position = myMap.getAttribute<PFP::VEC3,VERTEX>(attrNames[0]) ;
}
if(extension == std::string(".off"))
{
if(!Algo::Import::importMeshToExtrude<PFP>(myMap, argv[1], attrNames))
......
......@@ -27,7 +27,7 @@
#include <iostream>
#define WITH_GMAP 1
// #define WITH_GMAP 1
#include "Topology/generic/parameters.h"
#ifdef WITH_GMAP
......
......@@ -34,7 +34,7 @@ QT4_WRAP_UI( tuto2_ui tuto2.ui )
QT4_WRAP_CPP(tuto2_moc tuto2.h)
add_executable( tuto2 tuto2.cpp tuto2.h ${tuto2_ui} ${tuto2_moc})
target_link_libraries( tuto2
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} QtSvg)
QT4_WRAP_CPP(tuto3_moc tuto3.h)
add_executable( tuto3 tuto3.cpp ${tuto3_moc})
......@@ -86,6 +86,12 @@ add_executable( tp_master tp_master.cpp ${tp_master_moc})
target_link_libraries( tp_master
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} )
QT4_WRAP_CPP(tuto_histo_moc tuto_histo.h)
add_executable( tuto_histo tuto_histo.cpp tuto_histo.h ${tuto_histo_ui} ${tuto_histo_moc})
target_link_libraries( tuto_histo
${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} QtSvg)
#BOOST_LIBS macro: allow using compiled boost in windows (see readme)
# -first argument variable that will contain the libs
# -second argument list of boost libs separated by ; in " "
......
/*******************************************************************************
* 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_histo.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Import/import.h"
#include "Algo/Geometry/area.h"
#include "Topology/generic/traversorCell.h"
#include <cmath>
#include <sstream>
using namespace CGoGN ;
int main(int argc, char **argv)
{
// // interface
QApplication app(argc, argv);
MyQT sqt;
// copy output tout Qt console of application (shift enter)
CGoGNout.toConsole(&sqt);
// example code itself
sqt.createMap(std::string(argv[1]));
// set help message in menu
sqt.setHelpMsg("Tuto Histogram: \nLoad mesh & compute histogram & quantiles\n+/- increase/decrease \
number of classes\no/p increase/decrease number of quantiles\nw/x change \
min/max\nc center the histogram on 0\nh show/hide histogram\nq show/hide quantiles\
File/Save for exporting histogram in svg format");
// final show for redraw
sqt.show();
// and wait for the end
return app.exec();
}
void MyQT::createMap(const std::string& filename)
{
myMap.clear(true) ;
size_t pos = filename.rfind("."); // position of "." in filename
std::string extension = filename.substr(pos);
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, filename.c_str(), attrNames))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
VertexAttribute<VEC3> position = myMap.getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
// attribute on which we make the histogram
VertexAttribute<float> area = myMap.addAttribute<float, VERTEX>("area");
// attribute color to generate from histo
VertexAttribute<VEC3> colorF = myMap.addAttribute<PFP::VEC3, VERTEX>("colorF");
// compute the area attribute
Algo::Geometry::computeOneRingAreaVertices<PFP>(myMap,position,area);
// just some tricks to obtain relatives value
float amax=0;
for (unsigned int i=area.begin(); i != area.end(); area.next(i))
if (area[i] > amax) amax = area[i];
for (unsigned int i=area.begin(); i != area.end(); area.next(i))
area[i] -= amax/4;
// create a colormap class for histogram coloring
l_cm = new ColMap();
// create the histogram
l_histo = new Algo::Histogram::Histogram(*l_cm);
// init data with specific conversion (direction init is: l_histo->initData(area);)
AttConv ac(area);
l_histo->initDataConvert(ac);
// compute the histogram
l_nbc = 20;
l_histo->populateHisto(l_nbc);
//compute the quantiles
l_nbq = 10;
l_histo->populateQuantiles(l_nbq);
// compute color attribute from histogram (histogram can alsdo directly update a VBO see below)
// l_histo->histoColorize(colorF);
// create a popup window
l_popup = new Utils::QT::QtPopUp(this);
// create the widget to view histogram
l_histodraw = new Utils::QT::RenderHistogram(l_popup, *l_histo);
// some simple parameters
l_histodraw->setQuantilesDraw(true);
l_histodraw->setHistoPosition(true);
l_histodraw->setOpacity(0.6f);
// create a table of color
std::vector<Geom::Vec3f> colors;
Utils::createTableColor01(colors,10,Utils::color_map_blue_green_red);
// and us it to color the quantiles
l_histodraw->setQuantilesColors(colors);
// add the widget to the popup
l_popup->addWidget(l_histodraw,0,0);
l_popup->show();
// connect the clicked signal of histogram widget to a slot
QObject::connect( l_histodraw, SIGNAL( clicked(unsigned int,unsigned int) ), this, SLOT( clickHisto(unsigned int,unsigned int) ) );
// 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());
// first show for be sure that GL context is binded
show();
// update of position VBO (context GL necessary)
m_positionVBO->updateData(position);
// m_colorVBO2->updateData(colorF);
// histogram can directly update a VBO (warning GL context must be accessible, after the first show!)
l_histo->histoColorizeVBO(*m_colorVBO2);
// construct rendering primities
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
}
void MyQT::cb_keyPress(int keycode)
{
switch(keycode)
{
case '+' :
l_nbc++;
l_histo->populateHisto(l_nbc);
l_histodraw->repaint();
break;
case '-' :
if (l_nbc>0)
l_nbc--;
l_histo->populateHisto(l_nbc);
l_histodraw->repaint();
break;
case 'p' :
l_nbq++;
l_histo->populateQuantiles(l_nbq);
l_histodraw->repaint();
break;
case 'o' :
if (l_nbq>0)
l_nbq--;
l_histo->populateQuantiles(l_nbq);
l_histodraw->repaint();
break;
case 'q':
l_histodraw->setQuantilesDraw(!l_histodraw->getQuantilesDraw());
l_histodraw->repaint();
break;
case 'h':
l_histodraw->setHistoDraw(!l_histodraw->getHistoDraw());
l_histodraw->repaint();
break;
case 'c' :
l_histo->centerOnZero();
l_histo->populateHisto(l_nbc);
l_histodraw->repaint();
break;
case 'w' :
{
double av = (l_histo->getMin() + l_histo->getMax() )/2.0;
l_histo->setMin(av*0.1 + l_histo->getMin()*0.9);
l_histo->setMax(av*0.1 + l_histo->getMax()*0.9);
l_histo->populateHisto(l_nbc);
l_histodraw->repaint();
}
break;
case 'x' :
{
double av = (l_histo->getMin() + l_histo->getMax() )/2.0;
l_histo->setMin(-0.1*av + l_histo->getMin()*1.1);
l_histo->setMax(-0.1*av + l_histo->getMax()*1.1);
l_histo->populateHisto(l_nbc);
l_histodraw->repaint();
}
break;
default:
break;
}
}
void MyQT::cb_initGL()
{
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
// create the render
m_render = new Algo::Render::GL2::MapRender();
// VBOs
m_positionVBO = new Utils::VBO();
m_colorVBO2 = new Utils::VBO();
//shader
m_shader2 = new Utils::ShaderColorPerVertex();
m_shader2->setAttributePosition(m_positionVBO);
registerShader(m_shader2);
}
void MyQT::cb_redraw()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// draw faces with pervertex color rendering
m_shader2->setAttributeColor(m_colorVBO2);
m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES);
glDisable(GL_POLYGON_OFFSET_FILL);
}
void MyQT::clickHisto(unsigned int i,unsigned int j)
{
std::cout << "CLICK on column Histo: "<< i << " / Quantiles: "<< j <<std::endl;
if (i != Utils::QT::RenderHistogram::NONE)
{
std::vector<unsigned int > vc;
l_histo->cellsOfHistogramColumn(i,vc);
std::cout << "Cells of histo: "<< std::endl;
for (unsigned int k=0; k <vc.size(); ++k)
std::cout << vc[k]<<"/";
std::cout << std::endl;
CellMarker<VERTEX> cm(myMap);
std::cout << l_histo->markCellsOfHistogramColumn(i,cm) << " marked cells"<< std::endl;
}
if (j != Utils::QT::RenderHistogram::NONE)
{
std::vector<unsigned int > vc;
l_histo->cellsOfHistogramColumn(j,vc);
std::cout << "Cells of quantile: "<< std::endl;
for (unsigned int k=0; k <vc.size(); ++k)
std::cout << vc[k]<<"/";
std::cout << std::endl;
}
}
void MyQT::cb_Save()
{
std::string filename = selectFileSave("export svg",".","*.svg") ;
if (filename.empty())
return ;
l_histodraw->svgExport(filename);
}
void MyQT::cb_exit()
{
if (m_render != NULL)
delete m_render;
if (m_shader2 != NULL)
delete m_shader2;
if (m_positionVBO != NULL)
delete m_positionVBO;
if (l_cm != NULL)
delete l_cm;
if (l_histo != NULL)
delete l_histo;
if (l_histodraw != NULL)
delete l_histodraw;
if (l_popup != NULL)
delete l_popup;
}
/*******************************************************************************
* 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 _TUTO2_
#define _TUTO2_
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderColorPerVertex.h"
#include "Algo/Histogram/histogram.h"
#include "Utils/Qt/qthistodraw.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
typedef EmbeddedMap2 MAP;
};
typedef PFP::MAP MAP ;
typedef PFP::VEC3 VEC3 ;
/*
* color map class for histogram color
*/
class ColMap : public Algo::Histogram::HistoColorMap
{
public:
Geom::Vec3f color(double f) const { return Utils::color_map_BCGYR(float(f));}
};
/*
* Attribute conversion to double
*/
//class AttConv: public Algo::Histogram::AttributeConvert
//{
//// VertexAttribute<float>& m_va;
//public:
// /// constructor with attribute reference
// AttConv(VertexAttribute<float>& va): m_va(va){}
//
// /// just call begin of attribute handler
// unsigned int begin() const { return m_va.begin();}
//
// /// just call end of attribute handler
// unsigned int end() const { return m_va.end();}
//
// /// just call next of attribute handler
// void next(unsigned int& i) const { m_va.next(i);}
// unsigned int nbElements() const { return m_va.nbElements();}
// double operator[](unsigned int i) const { return double(m_va[i])*0.33;}
//};
class AttConv: public Algo::Histogram::AttributeConvert< VertexAttribute<float> >
{
public:
/// constructor with attribute reference
AttConv(VertexAttribute<float>& va): Algo::Histogram::AttributeConvert< VertexAttribute<float> >(va){}
double operator[](unsigned int i) const { return double(attrib[i])*0.33;}
};
class MyQT: public Utils::QT::SimpleQT
{
Q_OBJECT
public:
MyQT(): m_render(NULL), m_positionVBO(NULL), m_shader2(NULL),l_cm(NULL),l_histo(NULL),l_popup(NULL),l_histodraw(NULL) {}
void cb_redraw();
void cb_initGL();
protected:
MAP myMap;
// render, VBO & shader
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO; // position 3D
Utils::VBO* m_colorVBO2; // color per vertex for edge drawing
Utils::ShaderColorPerVertex* m_shader2;
// some ptr
ColMap* l_cm;
Algo::Histogram::Histogram* l_histo;
Utils::QT::QtPopUp* l_popup;
Utils::QT::RenderHistogram* l_histodraw;
unsigned int l_nbc;
unsigned int l_nbq;
public:
// example of simple map creation
void createMap(const std::string& filename);
void cb_Save();
void cb_exit();
void cb_keyPress(int keycode);