Commit 6d915276 authored by Thomas's avatar Thomas

Merge branch 'master' of cgogn:~cgogn/CGoGN

parents 0a833f69 db4115a5
......@@ -15,6 +15,7 @@ include_directories(
${CGoGN_ROOT_DIR}/ThirdParty/AntTweakBar/include
${CGoGN_ROOT_DIR}/ThirdParty/OpenCTM
${CGoGN_ROOT_DIR}/ThirdParty/Assimp/include
${CGoGN_ROOT_DIR}/ThirdParty/glm
)
# define libs path
......
......@@ -16,6 +16,7 @@ include_directories(
${CGoGN_ROOT_DIR}/ThirdParty/AntTweakBar/include
${CGoGN_ROOT_DIR}/ThirdParty/OpenCTM
${CGoGN_ROOT_DIR}/ThirdParty/Assimp/include
${CGoGN_ROOT_DIR}/ThirdParty/glm
)
......
......@@ -118,7 +118,7 @@ void myGlutWin::init()
glClearColor(0.1f,0.1f,0.1f,0.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
// glEnable(GL_NORMALIZE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
......
......@@ -186,7 +186,7 @@ void myGlutWin::myRedraw(void)
// glEnable(GL_COLOR_MATERIAL);
// glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
// glColor3f(0.0f,0.0f,0.9f);
// m_render->draw(Algo::Render::VBO::FLAT_TRIANGLES) ;
// m_render->draw(Algo::Render::VBO::TRIANGLES) ;
//
// glDisable( GL_POLYGON_OFFSET_FILL );
......@@ -214,53 +214,83 @@ int main(int argc, char **argv)
mgw.position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position") ;
mgw.normal = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
glewInit();
if (! Utils::GLSLShader::areShadersSupported())
{
std::cerr << "Shaders not supported"<< std::endl;
exit(1);
}
Utils::GLSLShader* phong = new Utils::GLSLShader() ;
phong->loadShaders("phong_vs.txt", "phong_ps.txt") ;
Algo::Modelisation::Polyhedron<PFP> prim1(myMap, mgw.position);
prim1.cylinder_topo(16,15, true, true);
prim1.embedCylinder(30.0f,20.0f,50.0f);
CellMarker mark1(myMap,VERTEX_CELL);
prim1.mark(mark1);
// Algo::Modelisation::Polyhedron<PFP> prim1(myMap, mgw.position);
// prim1.cylinder_topo(16,16, true, true); // topo of sphere is a closed cylinder
// prim1.embedCylinder(40.0f,40.0f,30.0f);
//
// CellMarker mark1(myMap,VERTEX_CELL);
// prim1.mark(mark1);
//
// create a sphere
Algo::Modelisation::Polyhedron<PFP> prim2(myMap, mgw.position);
prim2.cylinder_topo(16,16, true, true); // topo of sphere is a closed cylinder
prim2.cylinder_topo(16,16, true, true);
prim2.embedSphere(40.0f);
//
// CellMarker mark2(myMap,VERTEX_CELL);
// prim2.mark(mark2);
//
// Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
//
// Algo::Render::VBO::MapRender_VBO render1 = new Algo::Render::VBO::MapRender_VBO() ;
//
// render1->updateData(Algo::Render::VBO::POSITIONS, position);
// render1->updateData(Algo::Render::VBO::NORMALS, normal);
// // update flat faces primtives (warning need position buffer)
// render1->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::FLAT_TRIANGLES);
// // update smooth faces primtives
// render1->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::TRIANGLES);
// // update lines primitives
// render1->initPrimitives<PFP>(myMap, allDarts, Algo::Render::VBO::LINES);
//
//
CellMarker mark2(myMap,VERTEX_CELL);
prim2.mark(mark2);
// create a sphere
Algo::Modelisation::Polyhedron<PFP> prim3(myMap, mgw.position);
prim3.tore_topo(12,48);
prim3.embedTore(50.0f,10.0f);
CellMarker mark3(myMap,VERTEX_CELL);
prim3.mark(mark3);
Algo::Geometry::computeNormalVertices<PFP>(myMap, mgw.position, mgw.normal) ;
Algo::Render::VBO::MapRender_VBO* render1 = new Algo::Render::VBO::MapRender_VBO() ;
render1->updateData(Algo::Render::VBO::POSITIONS, mgw.position);
render1->updateData(Algo::Render::VBO::NORMALS, mgw.normal);
SelectorCellMarked cm1(mark1);
render1->initPrimitives<PFP>(myMap, cm1, Algo::Render::VBO::TRIANGLES);
render1->initPrimitives<PFP>(myMap, cm1, Algo::Render::VBO::FLAT_TRIANGLES);
render1->initPrimitives<PFP>(myMap, cm1, Algo::Render::VBO::LINES);
Algo::Render::VBO::MapRender_VBO* render2 = new Algo::Render::VBO::MapRender_VBO(*render1) ;
SelectorCellMarked cm2(mark2);
render2->initPrimitives<PFP>(myMap, cm2, Algo::Render::VBO::TRIANGLES);
render2->initPrimitives<PFP>(myMap, cm2, Algo::Render::VBO::FLAT_TRIANGLES);
render2->initPrimitives<PFP>(myMap, cm2, Algo::Render::VBO::POINTS);
Algo::Render::VBO::MapRender_VBO* render3 = new Algo::Render::VBO::MapRender_VBO(*render1) ;
SelectorCellMarked cm3(mark3);
render3->initPrimitives<PFP>(myMap, cm3, Algo::Render::VBO::FLAT_TRIANGLES);
render3->initPrimitives<PFP>(myMap, cm3, Algo::Render::VBO::TRIANGLES);
render3->initPrimitives<PFP>(myMap, cm3, Algo::Render::VBO::LINES);
// update renderer
mgw.updateRender();
mgw.root = new Utils::SceneGraph::Group_Node();
Utils::SceneGraph::Material_Node* mater = new Utils::SceneGraph::Material_Node();
mater->setDiffuse(Geom::Vec4f(0.3f, 1.0f, 0.0f, 1.0f));
mater->setAmbient(Geom::Vec4f(0.1f, 0.1f, 0.1f, 1.0f));
mater->setSpecular(Geom::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
mater->setShininess(100.0f);
mater->setColor(Geom::Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
mater->setShader(phong);
mgw.root->setMaterial(mater);
Utils::SceneGraph::VBO_Node* vbon = new Utils::SceneGraph::VBO_Node(mgw.m_render);
Utils::SceneGraph::VBO_Node* vbon = new Utils::SceneGraph::VBO_Node(render1);
vbon->setPrimitives(Algo::Render::VBO::FLAT_TRIANGLES);
vbon->setPrimitives(Algo::Render::VBO::LINES);
mgw.root->addChild(vbon);
......@@ -272,11 +302,10 @@ int main(int argc, char **argv)
mgw.root->addChild(group1);
vbon = new Utils::SceneGraph::VBO_Node(mgw.m_render);
vbon->setPrimitives(Algo::Render::VBO::TRIANGLES);
vbon->setPrimitives(Algo::Render::VBO::LINES);
group1->addChild(vbon);
Utils::SceneGraph::VBO_Node* vbon2 = new Utils::SceneGraph::VBO_Node(render2);
vbon2->setPrimitives(Algo::Render::VBO::TRIANGLES);
vbon2->setPrimitives(Algo::Render::VBO::POINTS);
group1->addChild(vbon2);
Utils::SceneGraph::Group_Node* group2 = new Utils::SceneGraph::Group_Node();
......@@ -289,18 +318,21 @@ int main(int argc, char **argv)
mater = new Utils::SceneGraph::Material_Node();
mater->setDiffuse(Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f));
mater->setAmbient(Geom::Vec4f(0.1f, 0.1f, 0.1f, 1.0f));
mater->setSpecular(Geom::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
mater->setShininess(100.0f);
mater->setColor(Geom::Vec4f(1.0f, 1.0f, 0.0f, 1.0f));
mater->setNoShader();
group2->setMaterial(mater);
vbon = new Utils::SceneGraph::VBO_Node(mgw.m_render);
vbon->setPrimitives(Algo::Render::VBO::FLAT_TRIANGLES);
vbon = new Utils::SceneGraph::VBO_Node(render3);
vbon->setPrimitives(Algo::Render::VBO::TRIANGLES);
vbon->setPrimitives(Algo::Render::VBO::LINES);
group2->addChild(vbon);
// compute BB and store it for object positionning in screen
// Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap,mgw.position) ;
// not possible here to compute a BB !!
mgw.gWidthObj = 200.0f;
mgw.gPosObj = Geom::Vec3f(100.0f,0.0f,0.0f);
......
......@@ -4,6 +4,8 @@ project(Tutos)
#SET (COMMON_LIBS ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${DEVIL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBXML2_LIBRARIES} gzstream AntTweakBar openctm)
#SET (CMAKE_BUILD_TYPE Debug)
SET(CMAKE_BUILD_TYPE Release)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTOPOWARNING")
......@@ -14,6 +16,7 @@ include_directories(
${CGoGN_ROOT_DIR}/ThirdParty/gzstream
${CGoGN_ROOT_DIR}/ThirdParty/OpenCTM
${CGoGN_ROOT_DIR}/ThirdParty/Assimp/include
${CGoGN_ROOT_DIR}/ThirdParty/glm
${CGoGN_ROOT_DIR}/include
)
......@@ -49,3 +52,15 @@ target_link_libraries( tuto_subdivision
add_executable( tp_master tp_master.cpp)
target_link_libraries( tp_master
container topology utils algo ${COMMON_LIBS} )
add_executable( tuto_mt tuto_mt.cpp)
target_link_libraries( tuto_mt
container topology utils algo ${COMMON_LIBS} boost_thread-mt)
add_executable( tuto_ogl3 tuto_ogl3.cpp)
target_link_libraries( tuto_ogl3
container topology utils algo ${COMMON_LIBS} )
add_executable( tuto_ogl2 tuto_ogl2.cpp)
target_link_libraries( tuto_ogl2
container topology utils algo ${COMMON_LIBS} )
......@@ -100,6 +100,7 @@ Dart d_maison;
Dart Carre()
{
return Dart::nil();
}
......@@ -107,7 +108,7 @@ Dart Carre()
Dart Triangle()
{
return Dart::nil();
}
......@@ -141,7 +142,7 @@ void ColleMilieu(Dart d, Dart e)
Dart Maison()
{
return Dart::nil();
}
......@@ -634,7 +635,6 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
/// calcul du rayon
getOrthoScreenRay(x,y,rayA,rayB);
PFP::VEC3 AB = rayB-rayA;
float AB2 = AB.norm2();
d_faces.clear();
d_edges.clear();
......@@ -678,7 +678,6 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y)
/// Rayon
getOrthoScreenRay(x,y,rayA,rayB);
PFP::VEC3 AB = rayB-rayA;
float AB2 = AB.norm2();
d_faces.clear();
d_edges.clear();
......
/*******************************************************************************
* 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/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/Geometry/boundingbox.h"
#include "Algo/Render/vbo_MapRender.h"
#include "Algo/Geometry/area.h"
#include "Algo/Geometry/normal.h"
#include "Algo/Parallel/parallel_foreach.h"
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2<Map2> MAP;
};
/**
* A class for a little interface and rendering
*/
class MyGlutWin: public Utils::SimpleGlutWin
{
public:
void myRedraw();
PFP::REAL gWidthObj;
PFP::VEC3 gPosObj;
Algo::Render::VBO::MapRender_VBO* m_render;
MyGlutWin(int* argc, char **argv, int winX, int winY) : SimpleGlutWin(argc, argv, winX, winY), m_render(NULL) {}
~MyGlutWin()
{
if (m_render !=NULL)
delete m_render ;
}
};
// Routine d'affichage
void MyGlutWin::myRedraw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
// center the object
float sc = 50.0f / gWidthObj;
glScalef(sc, sc, sc);
glTranslatef(-gPosObj[0], -gPosObj[1], -gPosObj[2]);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_LIGHTING);
// draw the lines
glColor3f(1.0f, 1.0f, 0.0f);
m_render->draw(Algo::Render::VBO::LINES);
// draw the faces
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0f, 1.0f);
glColor3f(0.0f, 0.5f, 0.0f);
m_render->draw(Algo::Render::VBO::TRIANGLES);
glDisable(GL_POLYGON_OFFSET_FILL);
glPopMatrix();
}
template <typename XXX>
class ThreadArea: public Algo::Parallel::CGoGNThread<typename XXX::MAP>
{
protected:
const typename XXX::TVEC3& m_positions;
float area;
public:
ThreadArea(typename XXX::MAP& map, const typename XXX::TVEC3& pos, unsigned int th):
Algo::Parallel::CGoGNThread<typename XXX::MAP>(map,th),
m_positions(pos),
area(0.0f) {}
void operator()()
{
// 3 times just for fun !!!
area += Algo::Geometry::totalArea<XXX>(this->m_map, m_positions, SelectorTrue(), this->m_threadId);
area += Algo::Geometry::totalArea<XXX>(this->m_map, m_positions, SelectorTrue(), this->m_threadId);
area += Algo::Geometry::totalArea<XXX>(this->m_map, m_positions, SelectorTrue(), this->m_threadId);
}
float getTripleValue() { return area;}
};
template <typename XXX>
class ThreadNormals: public Algo::Parallel::CGoGNThread<typename XXX::MAP>
{
protected:
const typename XXX::TVEC3& m_positions;
typename XXX::TVEC3& m_normals;
public:
ThreadNormals(typename XXX::MAP& map, const typename XXX::TVEC3& pos, typename XXX::TVEC3& norm, unsigned int th):
Algo::Parallel::CGoGNThread<typename XXX::MAP>(map,th),
m_positions(pos),
m_normals(norm) {}
void operator()()
{
Algo::Geometry::computeNormalVertices<XXX>(this->m_map, m_positions, m_normals, SelectorTrue(), this->m_threadId);
}
};
//
//template<typename XXX>
//class Thread0
//{
//protected:
// typename XXX::MAP& m_map;
// MyGlutWin& m_mgw;
// unsigned int m_th;
// SelectorTrue m_selt;
//public:
// Thread0(typename XXX::MAP& map,MyGlutWin& mgw, unsigned int th):
// m_map(map), m_mgw(mgw), m_th(th) {}
//
// void operator()()
// {
// std::cout << "Begin render init"<<std::endl;
// m_mgw.useContext();
//
// // instanciation of the renderer (here using VBOs)
// m_mgw.m_render = new Algo::Render::VBO::MapRender_VBO();
//
// // update the renderer (geometry and primitives)
// m_mgw.m_render->updateData(Algo::Render::VBO::POSITIONS, position);
//
// m_mgw.m_render->initPrimitives<PFP>(m_map, m_selt, Algo::Render::VBO::TRIANGLES,m_th);
// m_mgw.m_render->initPrimitives<PFP>(m_map, m_selt, Algo::Render::VBO::LINES,m_th);
//
// m_mgw.releaseContext();
// std::cout<< "Render OK "<< std::endl;
//
// }
//};
template <typename XXX>
class calculFunctor1 : public Algo::Parallel::FunctorMapThreaded<typename XXX::MAP>
{
protected:
typename XXX::TVEC3& m_positions;
typename XXX::TVEC3& m_normals;
public:
calculFunctor1( typename XXX::MAP& map, typename XXX::TVEC3& pos, typename XXX::TVEC3& norm, unsigned int id=0):
Algo::Parallel::FunctorMapThreaded<typename XXX::MAP>(map,id), m_positions(pos), m_normals(norm) {}
bool operator()(Dart d)
{
typename XXX::VEC3 n1 = Algo::Geometry::vertexNormal<XXX>(this->m_map, d, m_positions);
typename XXX::VEC3 n2 = Algo::Geometry::vertexNormal<XXX>(this->m_map, this->m_map.phi1(d), m_positions);
typename XXX::VEC3 n3 = Algo::Geometry::vertexNormal<XXX>(this->m_map, this->m_map.phi_1(d), m_positions);
typename XXX::VEC3 n = n1+n2+n3;
n1 = Algo::Geometry::vertexNormal<XXX>(this->m_map, d, m_positions);
n2 = Algo::Geometry::vertexNormal<XXX>(this->m_map, this->m_map.phi1(d), m_positions);
n3 = Algo::Geometry::vertexNormal<XXX>(this->m_map, this->m_map.phi_1(d), m_positions);
n += n1+n2+n3;
n.normalize();
m_normals[d] = n;
// m_normals[d] = Algo::Geometry::vertexNormal<XXX>(this->m_map, d, m_positions);
return false;
}
Algo::Parallel::FunctorMapThreaded<typename XXX::MAP>* duplicate(unsigned int id)
{
calculFunctor1<XXX>* copy = new calculFunctor1<XXX>(this->m_map,m_positions,m_normals,id);
return reinterpret_cast<Algo::Parallel::FunctorMapThreaded<typename XXX::MAP>*>(copy);
}
};