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) ...@@ -138,21 +138,21 @@ void Clipping::slot_drawFaces(bool b)
void Clipping::slot_explodTopoPhi1(double c) void Clipping::slot_explodTopoPhi1(double c)
{ {
m_coeffTopoExplod[0] = (float)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(); updateGL();
} }
void Clipping::slot_explodTopoPhi2(double c) void Clipping::slot_explodTopoPhi2(double c)
{ {
m_coeffTopoExplod[1] = (float)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(); updateGL();
} }
void Clipping::slot_explodTopoPhi3(double c) void Clipping::slot_explodTopoPhi3(double c)
{ {
m_coeffTopoExplod[2] = (float)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(); updateGL();
} }
...@@ -823,7 +823,7 @@ void Clipping::importMesh(std::string& filename) ...@@ -823,7 +823,7 @@ void Clipping::importMesh(std::string& filename)
updateVBOprimitives(Algo::Render::GL2::TRIANGLES | Algo::Render::GL2::LINES | Algo::Render::GL2::POINTS) ; 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) ; m_bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
gPosObj = m_bb.center() ; gPosObj = m_bb.center() ;
...@@ -883,13 +883,13 @@ void Clipping::cb_initGL() ...@@ -883,13 +883,13 @@ void Clipping::cb_initGL()
void Clipping::updateVBOprimitives(int upType) void Clipping::updateVBOprimitives(int upType)
{ {
if(upType & Algo::Render::GL2::TRIANGLES) 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) 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) 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() void Clipping::cb_redraw()
......
...@@ -216,8 +216,8 @@ void MyQT::cb_keyPress(int code) ...@@ -216,8 +216,8 @@ void MyQT::cb_keyPress(int code)
Algo::Surface::Modelisation::EarTriangulation<PFP> triangulation(myMap); Algo::Surface::Modelisation::EarTriangulation<PFP> triangulation(myMap);
triangulation.triangule(); triangulation.triangule();
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES); m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES); m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES);
updateGL(); updateGL();
} }
break; break;
...@@ -431,9 +431,9 @@ int main(int argc, char **argv) ...@@ -431,9 +431,9 @@ int main(int argc, char **argv)
sqt.m_positionVBO->updateData(position); sqt.m_positionVBO->updateData(position);
// update des primitives du renderer // update des primitives du renderer
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES, &position); sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES, &position);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES, &position); sqt.m_render->initPrimitives<PFP>(myMap, 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::POINTS, &position);
// show final pour premier redraw // show final pour premier redraw
sqt.show(); sqt.show();
......
...@@ -150,8 +150,8 @@ int main(int argc, char **argv) ...@@ -150,8 +150,8 @@ int main(int argc, char **argv)
sqt.m_positionVBO->updateData(position); sqt.m_positionVBO->updateData(position);
// update render primitives // update render primitives
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES); sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES); sqt.m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES);
sqt.show(); sqt.show();
return app.exec(); return app.exec();
......
...@@ -155,8 +155,9 @@ void MCMesh::MC() ...@@ -155,8 +155,9 @@ void MCMesh::MC()
void MCMesh::updateRender() void MCMesh::updateRender()
{ {
SelectorDartNoBoundary<PFP::MAP> nb(myMap); SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render->initPrimitives<PFP>(myMap, nb, Algo::Render::GL2::LINES); //TODO add Browser for no border
m_render->initPrimitives<PFP>(myMap, nb, Algo::Render::GL2::TRIANGLES); m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::LINES);
m_render->initPrimitives<PFP>(myMap, Algo::Render::GL2::TRIANGLES);
m_positionVBO->updateData(position); m_positionVBO->updateData(position);
......
...@@ -91,7 +91,7 @@ void SimpleMap3::cb_redraw() ...@@ -91,7 +91,7 @@ void SimpleMap3::cb_redraw()
{ {
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glLineWidth(1.0f); 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 @@ ...@@ -28,18 +28,18 @@
#include "Utils/vbo.h" #include "Utils/vbo.h"
TexView::TexView(): TexView::TexView():
m_render(NULL), m_obj(myMap),
m_positionVBO(NULL), m_positionVBO(NULL),
m_texcoordVBO(NULL), m_texcoordVBO(NULL),
m_nbIndices(0),
m_texture(NULL), m_texture(NULL),
m_shader(NULL), m_shader(NULL),
m_modeMask(false), m_shader2(NULL),
m_fileName("") m_phong(true)
{} {}
TexView::~TexView() TexView::~TexView()
{ {
delete m_render;
delete m_shader; delete m_shader;
delete m_positionVBO; delete m_positionVBO;
delete m_texcoordVBO; delete m_texcoordVBO;
...@@ -51,21 +51,21 @@ void TexView::cb_initGL() ...@@ -51,21 +51,21 @@ void TexView::cb_initGL()
// choose to use GL version 2 // choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2); Utils::GLSLShader::setCurrentOGLVersion(2);
// create the render
m_render = new Algo::Render::GL2::MapRender();
// create VBO for position // create VBO for position
m_positionVBO = new Utils::VBO; m_positionVBO = new Utils::VBO;
m_texcoordVBO = new Utils::VBO; m_texcoordVBO = new Utils::VBO;
m_normalVBO = new Utils::VBO;
m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE); m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
computeImage();
m_texture->update();
m_mask = new Utils::Texture<2,float>(GL_FLOAT); if (m_texture->load(m_fileNameTex))
m_mask->create(Geom::Vec2ui(256,256)); m_texture->update();
createMask(8); else
m_mask->update(); computeImage();
// CGoGNerr << "Problem loading image"<< CGoGNendl;
m_texture->setWrapping(GL_CLAMP_TO_EDGE);
m_texture->update();
m_shader = new Utils::ShaderSimpleTexture(); m_shader = new Utils::ShaderSimpleTexture();
m_shader->setAttributePosition(m_positionVBO); m_shader->setAttributePosition(m_positionVBO);
...@@ -74,125 +74,115 @@ void TexView::cb_initGL() ...@@ -74,125 +74,115 @@ void TexView::cb_initGL()
m_shader->setTexture(m_texture); m_shader->setTexture(m_texture);
registerShader(m_shader); registerShader(m_shader);
m_shader2 = new Utils::ShaderTextureMask(); m_shader2 = new Utils::ShaderPhongTexture();
m_shader2->setAttributePosition(m_positionVBO); m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setAttributeTexCoord(m_texcoordVBO); m_shader2->setAttributeTexCoord(m_texcoordVBO);
m_shader2->setTextureUnits(GL_TEXTURE0,GL_TEXTURE1); m_shader2->setAttributeNormal(m_normalVBO);
m_shader2->setTextures(m_texture,m_mask); 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); registerShader(m_shader2);
glEnable(GL_TEXTURE_2D); 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() void TexView::cb_redraw()
{ {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
if (m_shader) if (m_phong)
{ {
if (m_modeMask) m_shader2->activeTexture();
{ m_shader2->enableVertexAttribs();
m_shader2->activeTextures(); glDrawArrays(GL_TRIANGLES, 0, m_nbIndices);
m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES); m_shader2->disableVertexAttribs();
}
else
{
m_shader->activeTexture();
m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
}
} }
else
{
m_shader->activeTexture();
m_shader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, 0, m_nbIndices);
m_shader->disableVertexAttribs();
}
} }
void TexView::cb_keyPress(int code) void TexView::cb_keyPress(int code)
{ {
switch(code) switch(code)
{ {
case 'p':
m_phong = !m_phong;
case 'l': case 'l':
m_texture->setFiltering(GL_LINEAR); m_texture->setFiltering(GL_LINEAR);
break; break;
case 'n': case 'n':
m_texture->setFiltering(GL_NEAREST); m_texture->setFiltering(GL_NEAREST);
break; break;
case 'm': case '1':
m_modeMask = !m_modeMask; m_shader2->setShininess(10.0f);
if (m_modeMask)
{
createMask(16);
m_mask->update();
}
break; break;
case 'M': case '2':
m_modeMask = !m_modeMask; m_shader2->setShininess(100.0f);
if (m_modeMask)
{
createMask(8);
m_mask->update();
}
break; break;
case 's': case '3':
m_texture->subSample2<Geom::Vec3d>(); m_shader2->setShininess(500.0f);
m_texture->update();
break; break;
case 't': case '4':
m_texture->rotate90(3); m_shader2->setShininess(25000.0f);
m_texture->update();
break; break;
case '5':
m_shader2->setShininess(1.0f);
case 'r': m_shader2->setSpecular(Geom::Vec4f(0));
m_texture->load(m_fileName);
m_texture->update();
break; break;
} }
updateGL(); updateGL();
} }
void TexView::cb_Open() void TexView::init(char *fnm, char* fnt)
{ {
std::string filename = selectFile("Open Image","/tmp"); if (fnm == NULL)
if (!filename.empty())
{ {
m_fileName = filename; computeTore();
if (m_texture->load(filename)) m_fileNameTex = std::string(fnt);
{
m_texture->update();
updateGL();
}
else
CGoGNerr << "Problem loading image"<< CGoGNendl;
} }
else else
{ {
computeImage(); m_fileNameMesh = std::string(fnm);
m_texture->update(); m_fileNameTex = std::string(fnt);
updateGL(); std::vector<std::string> attrNames;
m_obj.import(m_fileNameMesh,attrNames);
} }
}
void TexView::createMask(unsigned int nb) 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));
if (nb ==0) Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
return;
unsigned int sz0 = m_mask->size()[0]/nb; // send BB info to interface for centering on GL screen
unsigned int sz1 = m_mask->size()[1]/nb; 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() void TexView::computeImage()
{ {
std::vector<Geom::Vec3f> colorTable; std::vector<Geom::Vec3f> colorTable;
...@@ -219,23 +209,15 @@ void TexView::computeImage() ...@@ -219,23 +209,15 @@ void TexView::computeImage()
#undef WIDTHCHECKER #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 #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.tore_topo(NB, NB);
prim.embedTore(40.0f,20.0f); prim.embedTore(40.0f,20.0f);
Dart d = prim.getDart(); Dart d = prim.getDart();
for(unsigned int i=0; i<NB; ++i) for(unsigned int i=0; i<NB; ++i)
{ {
...@@ -253,30 +235,42 @@ int main(int argc, char**argv) ...@@ -253,30 +235,42 @@ int main(int argc, char**argv)
b =(2.0f/NB)*(NB-j); b =(2.0f/NB)*(NB-j);
texcoord[d] = Geom::Vec2f(a,b); 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 #undef NB
// bounding box m_obj.setPositionAttribute(position);
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(m, position); m_obj.setTexCoordAttribute(texcoord);
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);
// 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(); tv.show();
// et on attend la fin. // et on attend la fin.
return app.exec(); return app.exec();
} }
...@@ -30,17 +30,17 @@ ...@@ -30,17 +30,17 @@
#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtSimple.h"
#include "Utils/textures.h" #include "Utils/textures.h"
#include "Utils/Shaders/shaderSimpleTexture.h" #include "Utils/Shaders/shaderSimpleTexture.h"
#include "Utils/Shaders/shaderTextureMask.h" #include "Utils/Shaders/shaderPhongTexture.h"
#include "Topology/generic/parameters.h" #include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h" #include "Topology/map/embeddedMap2.h"
#include "Algo/Render/GL2/mapRender.h" #include "Algo/Render/GL2/mapRender.h"
#include "Algo/Import/importObjTex.h"
// forward definitions (minimize includes) // forward definitions (minimize includes)