Commit 3908de25 authored by untereiner's avatar untereiner

Merge cgogn:~thery/CGoGN

Conflicts:
	include/Algo/Modelisation/subdivision3.hpp
parents 1d99adf6 498aabac
......@@ -138,21 +138,21 @@ void Clipping::slot_drawFaces(bool b)
void Clipping::slot_explodTopoPhi1(double c)
{
m_coeffTopoExplod[0] = (float)c;
m_render_topo->updateData<PFP>(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2], allDarts);
m_render_topo->updateData<PFP>(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]);
updateGL();
}
void Clipping::slot_explodTopoPhi2(double c)
{
m_coeffTopoExplod[1] = (float)c;
m_render_topo->updateData<PFP>(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2], allDarts);
m_render_topo->updateData<PFP>(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]);
updateGL();
}
void Clipping::slot_explodTopoPhi3(double c)
{
m_coeffTopoExplod[2] = (float)c;
m_render_topo->updateData<PFP>(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2], allDarts);
m_render_topo->updateData<PFP>(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]);
updateGL();
}
......@@ -823,7 +823,7 @@ void Clipping::importMesh(std::string& filename)
updateVBOprimitives(Algo::Render::GL2::TRIANGLES | Algo::Render::GL2::LINES | Algo::Render::GL2::POINTS) ;
m_render_topo->updateData<PFP>(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2], allDarts);
m_render_topo->updateData<PFP>(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]);
m_bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
gPosObj = m_bb.center() ;
......@@ -883,13 +883,13 @@ void Clipping::cb_initGL()
void Clipping::updateVBOprimitives(int upType)
{
if(upType & Algo::Render::GL2::TRIANGLES)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES) ;
if(upType & Algo::Render::GL2::LINES)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES,false) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES,false) ;
if(upType & Algo::Render::GL2::POINTS)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS) ;
}
void Clipping::cb_redraw()
......
......@@ -216,8 +216,8 @@ void MyQT::cb_keyPress(int code)
Algo::Surface::Modelisation::EarTriangulation<PFP> triangulation(myMap);
triangulation.triangule();
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES);
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES);
updateGL();
}
break;
......@@ -431,9 +431,9 @@ int main(int argc, char **argv)
sqt.m_positionVBO->updateData(position);
// update des primitives du renderer
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES, &position);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES, &position);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS, &position);
sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES, &position);
sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES, &position);
sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS, &position);
// show final pour premier redraw
sqt.show();
......
......@@ -150,8 +150,8 @@ int main(int argc, char **argv)
sqt.m_positionVBO->updateData(position);
// update render primitives
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES);
sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES);
sqt.show();
return app.exec();
......
......@@ -155,8 +155,9 @@ void MCMesh::MC()
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);
//TODO add Browser for no border
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES);
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES);
m_positionVBO->updateData(position);
......
......@@ -91,7 +91,7 @@ void SimpleMap3::cb_redraw()
{
glDisable(GL_LIGHTING);
glLineWidth(1.0f);
Algo::Render::GL1::renderTopoMD3<PFP>(myMap, position, true, true, true, 0.9f, 0.9f, 0.9f,allDarts);
Algo::Render::GL1::renderTopoMD3<PFP>(myMap, position, true, true, true, 0.9f, 0.9f, 0.9f);
}
/**********************************************************************************************
......
......@@ -28,18 +28,18 @@
#include "Utils/vbo.h"
TexView::TexView():
m_render(NULL),
m_obj(myMap),
m_positionVBO(NULL),
m_texcoordVBO(NULL),
m_nbIndices(0),
m_texture(NULL),
m_shader(NULL),
m_modeMask(false),
m_fileName("")
m_shader2(NULL),
m_phong(true)
{}
TexView::~TexView()
{
delete m_render;
delete m_shader;
delete m_positionVBO;
delete m_texcoordVBO;
......@@ -51,21 +51,21 @@ void TexView::cb_initGL()
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
// create the render
m_render = new Algo::Render::GL2::MapRender();
// create VBO for position
m_positionVBO = new Utils::VBO;
m_texcoordVBO = new Utils::VBO;
m_normalVBO = new Utils::VBO;
m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
computeImage();
m_texture->update();
m_mask = new Utils::Texture<2,float>(GL_FLOAT);
m_mask->create(Geom::Vec2ui(256,256));
createMask(8);
m_mask->update();
if (m_texture->load(m_fileNameTex))
m_texture->update();
else
computeImage();
// CGoGNerr << "Problem loading image"<< CGoGNendl;
m_texture->setWrapping(GL_CLAMP_TO_EDGE);
m_texture->update();
m_shader = new Utils::ShaderSimpleTexture();
m_shader->setAttributePosition(m_positionVBO);
......@@ -74,125 +74,115 @@ void TexView::cb_initGL()
m_shader->setTexture(m_texture);
registerShader(m_shader);
m_shader2 = new Utils::ShaderTextureMask();
m_shader2 = new Utils::ShaderPhongTexture();
m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setAttributeTexCoord(m_texcoordVBO);
m_shader2->setTextureUnits(GL_TEXTURE0,GL_TEXTURE1);
m_shader2->setTextures(m_texture,m_mask);
m_shader2->setAttributeNormal(m_normalVBO);
m_shader2->setTextureUnit(GL_TEXTURE1);
m_shader2->setTexture(m_texture);
m_shader2->setShininess(10.0f);
m_shader2->setAmbient(0.1f);
m_shader2->setSpecular(Geom::Vec4f(0.5));
registerShader(m_shader2);
glEnable(GL_TEXTURE_2D);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
if (!m_obj.hasNormals())
{
VertexAttribute<Geom::Vec3f> normal = myMap.getAttribute<VEC3, VERTEX>("normal") ;
if(!normal.isValid())
normal = myMap.addAttribute<VEC3, VERTEX>("normal") ;
Algo::Surface::Geometry::computeNormalVertices<PFP>(myMap, m_obj.m_positions, normal) ;
m_obj.setNormalAttribute(normal);
}
m_nbIndices = m_obj.createSimpleVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO);
}
void TexView::cb_redraw()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
if (m_shader)
if (m_phong)
{
if (m_modeMask)
{
m_shader2->activeTextures();
m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES);
}
else
{
m_shader->activeTexture();
m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
}
m_shader2->activeTexture();
m_shader2->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, 0, m_nbIndices);
m_shader2->disableVertexAttribs();
}
else
{
m_shader->activeTexture();
m_shader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, 0, m_nbIndices);
m_shader->disableVertexAttribs();
}
}
void TexView::cb_keyPress(int code)
{
switch(code)
{
case 'p':
m_phong = !m_phong;
case 'l':
m_texture->setFiltering(GL_LINEAR);
break;
case 'n':
m_texture->setFiltering(GL_NEAREST);
break;
case 'm':
m_modeMask = !m_modeMask;
if (m_modeMask)
{
createMask(16);
m_mask->update();
}
case '1':
m_shader2->setShininess(10.0f);
break;
case 'M':
m_modeMask = !m_modeMask;
if (m_modeMask)
{
createMask(8);
m_mask->update();
}
case '2':
m_shader2->setShininess(100.0f);
break;
case 's':
m_texture->subSample2<Geom::Vec3d>();
m_texture->update();
case '3':
m_shader2->setShininess(500.0f);
break;
case 't':
m_texture->rotate90(3);
m_texture->update();
case '4':
m_shader2->setShininess(25000.0f);
break;
case 'r':
m_texture->load(m_fileName);
m_texture->update();
case '5':
m_shader2->setShininess(1.0f);
m_shader2->setSpecular(Geom::Vec4f(0));
break;
}
updateGL();
}
void TexView::cb_Open()
void TexView::init(char *fnm, char* fnt)
{
std::string filename = selectFile("Open Image","/tmp");
if (!filename.empty())
if (fnm == NULL)
{
m_fileName = filename;
if (m_texture->load(filename))
{
m_texture->update();
updateGL();
}
else
CGoGNerr << "Problem loading image"<< CGoGNendl;
computeTore();
m_fileNameTex = std::string(fnt);
}
else
{
computeImage();
m_texture->update();
updateGL();
m_fileNameMesh = std::string(fnm);
m_fileNameTex = std::string(fnt);
std::vector<std::string> attrNames;
m_obj.import(m_fileNameMesh,attrNames);
}
}
void TexView::createMask(unsigned int nb)
{
if (nb ==0)
return;
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, m_obj.m_positions);
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);
unsigned int sz0 = m_mask->size()[0]/nb;
unsigned int sz1 = m_mask->size()[1]/nb;
// send BB info to interface for centering on GL screen
setParamObject(lWidthObj, lPosObj.data());
for (unsigned int j=0; j<m_mask->size()[1]; ++j)
{
for (unsigned int i=0; i<m_mask->size()[0]; ++i)
{
bool b1 = (i/sz0)%2 ==0;
bool b2 = (j/sz1)%2 ==0;
if (b1!=b2)
(*m_mask)(i,j)=1.0f;
else
(*m_mask)(i,j)= 0.0f;
}
}
}
void TexView::computeImage()
{
std::vector<Geom::Vec3f> colorTable;
......@@ -219,23 +209,15 @@ void TexView::computeImage()
#undef WIDTHCHECKER
}
int main(int argc, char**argv)
void TexView::computeTore()
{
// interface:
QApplication app(argc, argv);
TexView tv;
PFP::MAP& m = tv.myMap;
VertexAttribute<VEC3> position = m.addAttribute<VEC3, VERTEX>("position");
VertexAttribute<Geom::Vec2f> texcoord = m.addAttribute<Geom::Vec2f, VERTEX>("texcoord");
#define NB 96
Algo::Surface::Modelisation::Polyhedron<PFP> prim(m, position);
VertexAttribute<VEC3> position = myMap.addAttribute<VEC3, VERTEX>("position");
VertexAttribute<Geom::Vec2f> texcoord = myMap.addAttribute<Geom::Vec2f, VERTEX>("texcoord");
Algo::Surface::Modelisation::Polyhedron<PFP> prim(myMap, position);
prim.tore_topo(NB, NB);
prim.embedTore(40.0f,20.0f);
Dart d = prim.getDart();
for(unsigned int i=0; i<NB; ++i)
{
......@@ -253,30 +235,42 @@ int main(int argc, char**argv)
b =(2.0f/NB)*(NB-j);
texcoord[d] = Geom::Vec2f(a,b);
d = m.phi<121>(d);
d = myMap.phi<121>(d);
}
d = m.phi<211>(d);
d = myMap.phi<211>(d);
}
#undef NB
// bounding box
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(m, 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);
m_obj.setPositionAttribute(position);
m_obj.setTexCoordAttribute(texcoord);
}
// envoit info BB a l'interface
tv.setParamObject(lWidthObj, lPosObj.data());
// show 1 pour GL context
tv.show();
// update des VBO (position et texture coord)
tv.m_positionVBO->updateData(position);
tv.m_texcoordVBO->updateData(texcoord);
// show final pour premier redraw
int main(int argc, char**argv)
{
// interface:
QApplication app(argc, argv);
TexView tv;
if (argc == 3)
{
tv.init(argv[1], argv[2]);
}
else if (argc == 2)
{
tv.init(NULL, argv[1]);
}
else
{
tv.init(NULL,"x");
}
tv.show();
// et on attend la fin.
return app.exec();
}
......@@ -30,17 +30,17 @@
#include "Utils/Qt/qtSimple.h"
#include "Utils/textures.h"
#include "Utils/Shaders/shaderSimpleTexture.h"
#include "Utils/Shaders/shaderTextureMask.h"
#include "Utils/Shaders/shaderPhongTexture.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Import/importObjTex.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; }}}}
namespace CGoGN { namespace Utils { class VBO; } }
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
......@@ -59,36 +59,38 @@ class TexView: public Utils::QT::SimpleQT
{
Q_OBJECT
protected:
void createMask(unsigned int nb);
void computeImage();
void computeTore();
public:
MAP myMap ;
// render
Algo::Render::GL2::MapRender* m_render;
Algo::Surface::Import::OBJModel<PFP> m_obj;
// VBO
Utils::VBO* m_positionVBO;
Utils::VBO* m_texcoordVBO;
Utils::VBO* m_normalVBO;
unsigned int m_nbIndices;
Utils::Texture<2,Geom::Vec3uc>* m_texture;
Utils::Texture<2,float>* m_mask;
//2 shaders
// shader simple texture
Utils::ShaderSimpleTexture* m_shader;
Utils::ShaderTextureMask* m_shader2;
Utils::ShaderPhongTexture* m_shader2;
//with mask or not
bool m_modeMask;
bool m_phong;
/// filename of last loaded texture
std::string m_fileName;
/// filename of loaded mesh
std::string m_fileNameMesh;
/// filename of loaded texture
std::string m_fileNameTex;
TexView();
~TexView();
void init(char* fnm, char* fnt);
// callbacks of simpleQT to overdefine:
void cb_redraw();
......@@ -96,7 +98,6 @@ public:
void cb_keyPress(int code);
void cb_Open();
};
#endif
......@@ -229,9 +229,9 @@ void Viewer::importMesh(std::string& filename)
myMap.enableQuickTraversal<VERTEX>() ;
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS) ;
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::POINTS) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES) ;
m_topoRender->updateData<PFP>(myMap, position, 0.85f, 0.85f) ;
......@@ -258,7 +258,7 @@ void Viewer::exportMesh(std::string& filename, bool askExportMode)
std::string extension = filename.substr(pos) ;
if (extension == std::string(".off"))
Algo::Surface::Export::exportOFF<PFP>(myMap, position, filename.c_str(), allDarts) ;
Algo::Surface::Export::exportOFF<PFP>(myMap, position, filename.c_str()) ;
else if (extension.compare(0, 4, std::string(".ply")) == 0)
{
int ascii = 0 ;
......@@ -267,7 +267,7 @@ void Viewer::exportMesh(std::string& filename, bool askExportMode)
std::vector<VertexAttribute<VEC3>*> attributes ;
attributes.push_back(&position) ;
Algo::Surface::Export::exportPLYnew<PFP>(myMap, attributes, filename.c_str(), !ascii, allDarts) ;
Algo::Surface::Export::exportPLYnew<PFP>(myMap, attributes, filename.c_str(), !ascii) ;
}
else if (extension == std::string(".map"))
myMap.saveMapBin(filename) ;
......
......@@ -55,8 +55,9 @@ void MyQT::topo_onoff(bool x)
render_topo = !render_topo;
if (render_topo)
{
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, m_explode_factorf-0.05f, m_explode_factor, nb);
// SelectorDartNoBoundary<PFP::MAP> nb(myMap);
//TODO MapBrowser
m_topo_render->updateData<PFP>(myMap, position, 0.8f, m_explode_factorf-0.05f, m_explode_factor);
}
updateGL();
......@@ -123,8 +124,9 @@ void MyQT::slider_released()
render_topo = render_topoTemp;
if (render_topo)
{
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, m_explode_factorf-0.05f, m_explode_factor, nb);
// SelectorDartNoBoundary<PFP::MAP> nb(myMap);
//TODO MapBrowser
m_topo_render->updateData<PFP>(myMap, position, 0.8f, m_explode_factorf-0.05f, m_explode_factor );
}
updateGL();
}
......@@ -185,8 +187,8 @@ void MyQT::cb_Open()
color[i][2] = 1.0f - color[i][0];
}
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, 0.8f, nb);
// SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, 0.8f);
m_explode_render->updateData<PFP>(myMap, position, color);
updateGL() ;
......@@ -202,8 +204,8 @@ void MyQT::cb_initGL()
m_topo_render = new Algo::Render::GL2::Topo3Render();
m_explode_render = new Algo::Render::GL2::ExplodeVolumeRender(true,true,false);
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, 0.8f, nb);
// SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_topo_render->updateData<PFP>(myMap, position, 0.8f, 0.8f, 0.8f);
m_explode_render->updateData<PFP>(myMap, position, color);
m_explode_render->setExplodeVolumes(0.8f);
m_explode_render->setExplodeFaces(0.9f);
......
......@@ -118,8 +118,8 @@ void MyQT::cb_initGL()
m_render_topo = new Algo::Render::GL2::Topo3Render();
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f, nb);
// SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f);
m_dm_topo = new DartMarker(myMap);
}
......@@ -145,8 +145,8 @@ void MyQT::cb_mousePress(int button, int x, int y)
{
if (Shift())
{
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
Dart d = m_render_topo->picking<PFP>(myMap, x, y, nb);
// SelectorDartNoBoundary<PFP::MAP> nb(myMap);
Dart d = m_render_topo->picking<PFP>(myMap, x, y);
if (d != Dart::nil())
{
CGoGNout << "Dart " << d << " clicked" << CGoGNendl;
......@@ -229,8 +229,8 @@ void MyQT::traverse2()
m_drawer.endList();
SelectorMarked sm(*m_dm_topo);