Commit 50dba34d authored by Sylvain Thery's avatar Sylvain Thery

MAJ MC

rm vieux Viewer.cpp
MAJ ear Algo
parent 1262e060
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include "Algo/Render/SVG/mapSVGRender.h" #include "Algo/Render/SVG/mapSVGRender.h"
#include "Algo/Modelisation/triangulation.h"
using namespace CGoGN ; using namespace CGoGN ;
...@@ -156,7 +158,7 @@ void MyQT::cb_initGL() ...@@ -156,7 +158,7 @@ void MyQT::cb_initGL()
void MyQT::cb_redraw() void MyQT::cb_redraw()
{ {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
if (m_shader) if (m_shader)
{ {
...@@ -170,7 +172,7 @@ void MyQT::cb_redraw() ...@@ -170,7 +172,7 @@ void MyQT::cb_redraw()
m_render->draw(m_shader, Algo::Render::GL2::LINES); m_render->draw(m_shader, Algo::Render::GL2::LINES);
glPolygonOffset(0.8f, 0.8f); glPolygonOffset(0.8f, 0.8f);
m_shader->setColor(Geom::Vec4f(1.0,0.,0.,0.)); m_shader->setColor(Geom::Vec4f(0.0,0.,0.,0.));
glLineWidth(1.0f); glLineWidth(1.0f);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
m_render->drawSub(m_shader, Algo::Render::GL2::TRIANGLES, nb_ears); m_render->drawSub(m_shader, Algo::Render::GL2::TRIANGLES, nb_ears);
...@@ -185,32 +187,58 @@ void MyQT::cb_redraw() ...@@ -185,32 +187,58 @@ void MyQT::cb_redraw()
void MyQT::cb_keyPress(int code) void MyQT::cb_keyPress(int code)
{ {
if (code == '+') switch(code)
{ {
case '+':
nb_ears++; nb_ears++;
// born sup dans drawing // born sup dans drawing
updateGL(); updateGL();
} break;
case '-':
if (code == '-')
{
if (nb_ears>=1) if (nb_ears>=1)
nb_ears--; nb_ears--;
updateGL(); updateGL();
} break;
case 'n':
if (code == 'n')
{
nb_ears=0; nb_ears=0;
updateGL(); updateGL();
} break;
if (code == 'a') case 'a':
{
nb_ears=99999999; nb_ears=99999999;
updateGL(); updateGL();
} break;
case 't':
{
Algo::Modelisation::EarTriangulation<PFP> triangulation(myMap);
triangulation.triangule();
SelectorTrue allDarts;
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
updateGL();
}
break;
// case 'u':
// {
// Dart d=myMap.begin();
// while (d != myMap.end())
// {
// if (myMap.phi2(d) != d)
// {
// Dart e = d;
// myMap.next(d);
// if (d== myMap.phi2(e))
// myMap.next(d);
// myMap.mergeFaces(e);
// }
// else
// myMap.next(d);
// }
// }
// break;
}
} }
int main(int argc, char **argv) int main(int argc, char **argv)
...@@ -218,7 +246,6 @@ int main(int argc, char **argv) ...@@ -218,7 +246,6 @@ int main(int argc, char **argv)
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position"); position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
Dart d0 = myMap.newFace(12); Dart d0 = myMap.newFace(12);
position[d0] = PFP::VEC3(0, 20, 0); position[d0] = PFP::VEC3(0, 20, 0);
d0 = myMap.phi1(d0); d0 = myMap.phi1(d0);
...@@ -241,7 +268,7 @@ int main(int argc, char **argv) ...@@ -241,7 +268,7 @@ int main(int argc, char **argv)
position[d0] = PFP::VEC3(5, 30, 0); position[d0] = PFP::VEC3(5, 30, 0);
d0 = myMap.phi1(d0); d0 = myMap.phi1(d0);
position[d0] = PFP::VEC3(0, 30, 0); position[d0] = PFP::VEC3(0, 30, 0);
d0 = myMap.phi1(d0);
d0 = myMap.newFace(4); d0 = myMap.newFace(4);
...@@ -382,7 +409,6 @@ int main(int argc, char **argv) ...@@ -382,7 +409,6 @@ int main(int argc, char **argv)
for (int i=0; i<174;++i) for (int i=0; i<174;++i)
{ {
float a = float(rand()-RAND_MAX/2)/float(RAND_MAX) * 0.25f; float a = float(rand()-RAND_MAX/2)/float(RAND_MAX) * 0.25f;
position[d9] = PFP::VEC3(60.0,60.0,0.0f) + Gfont[2*i] * V1 + Gfont[2*i+1]*V2 + a*V3; position[d9] = PFP::VEC3(60.0,60.0,0.0f) + Gfont[2*i] * V1 + Gfont[2*i+1]*V2 + a*V3;
d9 = myMap.phi1(d9); d9 = myMap.phi1(d9);
} }
...@@ -417,8 +443,10 @@ int main(int argc, char **argv) ...@@ -417,8 +443,10 @@ int main(int argc, char **argv)
SelectorTrue allDarts; SelectorTrue allDarts;
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES); 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, allDarts, Algo::Render::GL2::LINES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS);
// show final pour premier redraw // show final pour premier redraw
sqt.show(); sqt.show();
// et on attend la fin. // et on attend la fin.
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, 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.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <iostream>
#include "Utils/os_spec.h"
#include "Utils/GLSLShader.h"
#include "Utils/glutwin.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Algo/Import/import.h"
#include "Algo/Render/map_glRender.h"
#include "Algo/Render/vbo_MapRender.h"
#include "Algo/Geometry/normal.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/area.h"
#include "Algo/Geometry/intersection.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Modelisation/extrusion.h"
#include "Algo/MC/marchingcubeGen.h"
#include "Topology/generic/ecell.h"
#include "Algo/Export/export.h"
using namespace CGoGN;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2<Map2> MAP;
};
PFP::MAP myMap;
SelectorTrue allDarts;
PFP::TVEC3 position;
PFP::TVEC3 normal;
class myGlutWin: public Utils::SimpleGlutWin
{
public:
Geom::Vec4f colDif;
Geom::Vec4f colSpec;
Geom::Vec4f colClear;
Geom::Vec4f colNormal;
float shininess;
/**
* position of object
*/
Geom::Vec3f gPosObj;
/**
* width of object
*/
float gWidthObj;
/**
* factor to apply to normal drawing
*/
float normalScaleFactor;
/**
* redraw CB
*/
void myRedraw();
/**
* keyboard CB
*/
void myKeyboard(unsigned char keycode, int x, int y);
/**
* inverse the normal when computing normal
*/
bool invertedNormals;
/**
* inverse object for culling
*/
bool invertedObject;
/**
* rendering normals ?
*/
bool renderNormal;
/**
* rendering lines ?
*/
bool renderLines;
/**
* aide affichee
*/
bool aff_help;
/**
* style of rendering
*/
int renderStyle;
Algo::Render::GL2::MapRender_VBO* m_render;
/**
* render mode enum
*/
enum { CLEAR=1, LINE, FLAT, GOURAUD, PHONG, NORMAL,NONE };
myGlutWin( int* argc, char **argv, int winX, int winY) :
SimpleGlutWin(argc,argv,winX,winY),
renderNormal(false),
renderLines(false),
aff_help(true)
{
if (this->shaderOk) shaders[0].loadShaders("phong_vs.txt","phong_ps.txt");
// m_cb = new Algo::Render::GL2::GL2_CB_PositionNormal<PFP>(myMap);
// m_render = new Algo::Render::GL2::MapRender_VBO(myMap, allDarts, m_cb);
//
// m_render->initBuffers();
// m_render->updateData(Algo::Render::GL2::POSITIONS, position );
// m_render->updateData(Algo::Render::GL2::NORMALS, normal );
// m_render->initPrimitives<PFP>(myMap, good, Algo::Render::GL2::TRIANGLES);
// m_render->initPrimitives<PFP>(myMap, good, Algo::Render::GL2::LINES);
}
};
void myGlutWin::myRedraw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
float sc = 50./gWidthObj;
glScalef(sc,sc,sc);
glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
glColor3f(0.7f,0.8f,1.0f);
glMaterialfv(GL_FRONT,GL_SPECULAR,colSpec.data());
glMaterialf( GL_FRONT, GL_SHININESS, shininess );
Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
// m_render->draw(Algo::Render::GL2::TRIANGLES);
Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::FLAT, 0.9 , position, normal, normal);
glDisable(GL_LIGHTING);
glColor3f(0.0f,0.0f,0.0f);
// m_render->draw(Algo::Render::GL2::LINES);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::LINE, 1.0, position, normal);
// glPointSize(5.0f);
// glColor3f(1.0f,.0f,.0f);
// glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
// Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::LINE, 0.9, position, normal);
// Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::FLAT, 0.9, position, normal);
// TESTED OK
glPopMatrix();
// a faire en dernier pour que ca dessine au dessus
if (aff_help) {
glColor3f(1.0f,1.0f,1.0f);
printString2D(10,20,"Keys:\n----\nf : flat (DL)\ng: gouraud (DL) \np: phong ( strip DL)\na: dual\nu: simplification (nbfaces/2)\nC : catmullclark\nR : square3\nL: Loop\nO: inverse objet\nn: affiche normales\nZ/z: shininess\nD/d: focale\nv: calcul fps\nh: affiche l'aide");
}
}
void myGlutWin::myKeyboard(unsigned char keycode, int, int)
{
switch (keycode)
{
case 'a':
{
unsigned int end = position.end();
for(unsigned int it = position.begin(); it != end; position.next(it))
{
position[it] += normal[it] * 0.1;
}
m_render->updateData(Algo::Render::GL2::POSITIONS, position );
}
break;
case 'z':
{
unsigned int end = normal.end();
for(unsigned int it = normal.begin(); it != end; normal.next(it))
{
normal[it] *= -1.0f;
}
m_render->updateData(Algo::Render::GL2::NORMALS, normal );
}
break;
case 's':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::CatmullClarkSubdivision<PFP>(myMap, position);
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
CGoGNout << "catmull-clark: "<< seconds << "sec" << CGoGNendl;
Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
break;
}
case 'l':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
CGoGNout << "loop: "<< seconds << "sec" << CGoGNendl;
Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal, allDarts) ;
break;
}
case 'd':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::Sqrt3Subdivision<PFP>(myMap, position);
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
CGoGNout << "dual: "<< seconds << "sec" << CGoGNendl;
Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal, allDarts) ;
break;
}
}
glutPostRedisplay();
}
class Scal3D
{
protected:
int m_size;
int m_mid;
public:
Scal3D(int size) : m_size(size), m_mid(size/2) {}
float getVoxSizeX() {return 1.0f;}
float getVoxSizeY() {return 1.0f;}
float getVoxSizeZ() {return 1.0f;}
long getWidthX() { return m_size;}
long getWidthY() { return m_size;}
long getWidthZ() { return m_size;}
float getVoxel(long x, long y, long z)
{
float rad = sqrt(float((x-m_mid)*(x-m_mid) + (y-m_mid)*(y-m_mid) + (z-m_mid)*(z-m_mid)));
float radx = sqrt(float((y-m_mid)*(y-m_mid) + (z-m_mid)*(z-m_mid)));
float rady = sqrt(float((x-m_mid)*(x-m_mid) + (z-m_mid)*(z-m_mid)));
float radz = sqrt(float((x-m_mid)*(x-m_mid) + (y-m_mid)*(y-m_mid)));
float val = 1.0f - rad/m_mid;
if ((val <0.0f) || (radz < m_size/10)||(rady < m_size/8)||(radx < m_size/6))
return 0.0f;
return val;
}
};
int main(int argc, char **argv)
{
// GLint t1 = glutGet(GLUT_ELAPSED_TIME);
if (argc == 1)
{
position = myMap.addAttribute<Geom::Vec3f>(VERTEX, "position");
CGoGNout <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"<<CGoGNendl;
// typedef uint8 DATATYPE;
// Algo::MC::Image<DATATYPE> myImg;
// myImg.loadPNG3D("liver.png");
//
// CGoGNout << "Image chargee"<<CGoGNendl;
// CGoGNout << myImg.getWidthX() <<"x"<< myImg.getWidthY() <<"x"<< myImg.getWidthZ() << "voxels"<<CGoGNendl;
//
// // ajouté pour vérifier que ça marche sur les images non bool
//// myImg.Blur3();
//// CGoGNout << "Image lissee"<<CGoGNendl;
//
// // fonction de fenetrage de type superieur à ...
// Algo::MC::WindowingGreater<DATATYPE> myWindFunc;
//
// // valeur utilisee 0 (donc objet = tout ce qui est diff de 0)
// myWindFunc.setIsoValue(DATATYPE(127));
//
// // instanciation du mc
// CGoGNout << "mc init"<<CGoGNendl;
// Algo::MC::MarchingCube<DATATYPE,Algo::MC::WindowingGreater,PFP> mc(&myImg, &myMap, position, myWindFunc, false);
// // MarchingCube<DATATYPE,WindowingDiff> mc(&myImg, &myMap, myWindFunc, false);
//
// // realisation du maillage
// mc.simpleMeshing();
// CGoGNout << "mc ok"<<CGoGNendl;
// typedef float DATATYPE;
//
// // fonction de fenetrage de type superieur à ...
// Algo::MC::WindowingGreater<DATATYPE> myWindFunc;
//
// // valeur utilisee 0 (donc objet = tout ce qui est diff de 0)
// myWindFunc.setIsoValue(DATATYPE(0.32f));
//
// Scal3D myImg(256);
//
// CGoGNout << "mc init"<<CGoGNendl;
// Algo::MC::MarchingCubeGen<DATATYPE, Scal3D, Algo::MC::WindowingGreater,PFP> mc(&myImg, &myMap, position, myWindFunc, false);
//
// //realisation du maillage
// mc.simpleMeshing();
std::vector<Geom::Vec3f> objV;
objV.push_back(Geom::Vec3f(-1,-1,37));
objV.push_back(Geom::Vec3f(-1,-2,37));
objV.push_back(Geom::Vec3f(+1,-2,37));
objV.push_back(Geom::Vec3f(+1,-1,37));
objV.push_back(Geom::Vec3f(+2,-1,37));
objV.push_back(Geom::Vec3f(+2,+1,37));
objV.push_back(Geom::Vec3f(+1,+1,37));
objV.push_back(Geom::Vec3f(+1,+2,37));
objV.push_back(Geom::Vec3f(-1,+2,37));
objV.push_back(Geom::Vec3f(-1,+1,37));
objV.push_back(Geom::Vec3f(-2,+1,37));
objV.push_back(Geom::Vec3f(-2,-1,37));
std::vector<Geom::Vec3f> pathV;
std::vector<float> pathRadius;
pathV.push_back(Geom::Vec3f(0,0,0)); pathRadius.push_back(1.);
pathV.push_back(Geom::Vec3f(0,0,10)); pathRadius.push_back(1.5);
pathV.push_back(Geom::Vec3f(10,0,10)); pathRadius.push_back(1.9);
pathV.push_back(Geom::Vec3f(10,10,10)); pathRadius.push_back(2.5);
pathV.push_back(Geom::Vec3f(10,10,20)); pathRadius.push_back(3.0);
pathV.push_back(Geom::Vec3f(10,11,25)); pathRadius.push_back(1.0);
pathV.push_back(Geom::Vec3f(11,13,30)); pathRadius.push_back(1.5);
pathV.push_back(Geom::Vec3f(0,0,40)); pathRadius.push_back(.5);
pathV.push_back(Geom::Vec3f(-20,-10,0.0)); pathRadius.push_back(1.9);
pathV.push_back(Geom::Vec3f(-10,0 ,-20)); pathRadius.push_back(1.3);
pathV.push_back(Geom::Vec3f(5,0 ,-10)); pathRadius.push_back(1.);
// Algo::Modelisation::extrusion<PFP>(myMap, objV, Geom::Vec3f(0.0,0.0,37.0), Geom::Vec3f(0.0,0.0,1.0),false, pathV, false);
Algo::Modelisation::extrusion_scale_prim<PFP>(myMap, position, objV, Geom::Vec3f(0.0,0.0,37.0), Geom::Vec3f(0.0,0.0,1.0),false, pathV, false, pathRadius);
}
// {
// Algo::Modelisation::Primitive<PFP> prim(myMap,position);
//
// prim.grid_topo(2,2);
//
// prim.embedGrid(8.0f,8.0f);
//
// Algo::Modelisation::Primitive<PFP> prim2(myMap,position);
//
// prim2.tore_topo(7,4);
// prim2.embedTore(25.0f,5.0f);
//
// GLint t1 = glutGet(GLUT_ELAPSED_TIME);
//
// myMap.getAttributeContainer(VERTEX).toggleProcess(position);
//// myMap.getAttributeContainer(VERTEX).toggleProcess(idPipo);
//
// PFP::MAP::EVertex::setContainer(myMap.getAttributeContainer(VERTEX));
// PFP::MAP::EVertex::setMap(myMap);
// PFP::MAP::EVertex ec(0);
//
// GLint t2 = glutGet(GLUT_ELAPSED_TIME);
// GLfloat seconds = (t2 - t1) / 1000.0f;
// CGoGNout << "triangulation: "<< seconds << "sec" << CGoGNendl;
//
// Marker m = myMap.getNewMarker(VERTEX);
// myMap.markEmbVertex(myMap.begin(),m);
//
// Dart xd = myMap.alpha1(myMap.begin());
// if (myMap.isMarkedEmbVertex(xd,m))
// {
// CGoGNout << "Marke"<< CGoGNendl;
// }
// xd = myMap.phi2(xd);
// if (myMap.isMarkedEmbVertex(xd,m))
// {
// CGoGNout << "Marke aussi"<< CGoGNendl;
// }
//
// myMap.clearEmbMarkers(m,VERTEX);
// myMap.releaseEmbMarker(m,VERTEX);
//
// }
else
{
SelectorTrue allDarts;
// GLint t1 = glutGet(GLUT_ELAPSED_TIME);
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, std::string(argv[1]), attrNames))