Commit bf5c4d2d authored by kenneth's avatar kenneth

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

Conflicts:
	include/Topology/generic/cellmarker.h
parents 9b52ecd2 6346fca0
......@@ -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
)
......
......@@ -246,7 +246,7 @@ void myGlutWin::myKeyboard(unsigned char keycode, int, int)
case 's':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::CatmullClarkSubdivision<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position);
Algo::Modelisation::CatmullClarkSubdivision<PFP>(myMap, position);
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "catmull-clark: "<< seconds << "sec" << std::endl;
......@@ -259,11 +259,11 @@ void myGlutWin::myKeyboard(unsigned char keycode, int, int)
case 'l':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::LoopSubdivision<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position);
Algo::Modelisation::LoopSubdivision<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position);
Algo::Modelisation::LoopSubdivision<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position);
Algo::Modelisation::LoopSubdivision<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position);
Algo::Modelisation::LoopSubdivision<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(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);
Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "loop: "<< seconds << "sec" << std::endl;
......@@ -276,7 +276,7 @@ void myGlutWin::myKeyboard(unsigned char keycode, int, int)
case 'd':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::Sqrt3Subdivision<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position);
Algo::Modelisation::Sqrt3Subdivision<PFP>(myMap, position);
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "dual: "<< seconds << "sec" << std::endl;
......
......@@ -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);
......
......@@ -433,7 +433,7 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
case 'l':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::LoopSubdivision<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position);
Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "loop: "<< seconds << "sec" << std::endl;
......@@ -454,7 +454,7 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
case 'c':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::CatmullClarkSubdivision<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position);
Algo::Modelisation::CatmullClarkSubdivision<PFP>(myMap, position);
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "catmull-clark: "<< seconds << "sec" << std::endl;
......@@ -475,7 +475,7 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
case 't':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::trianguleFaces<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position) ;
Algo::Modelisation::trianguleFaces<PFP>(myMap, position) ;
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "triangulation: "<< seconds << "sec" << std::endl;
......@@ -495,7 +495,7 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
case 'q':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::quadranguleFaces<PFP, AttributeHandler<PFP::VEC3>, PFP::VEC3>(myMap, position) ;
Algo::Modelisation::quadranguleFaces<PFP>(myMap, position) ;
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "quadrangulation: "<< seconds << "sec" << std::endl;
......@@ -534,6 +534,100 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
break ;
}
case 'd':
{
AttributeHandler<PFP::VEC3> positionF = myMap.getAttribute<PFP::VEC3>(FACE_ORBIT, "position") ;
if(!positionF.isValid())
positionF = myMap.addAttribute<PFP::VEC3>(FACE_ORBIT, "position") ;
Algo::Geometry::computeCentroidFaces<PFP>(myMap, position, positionF) ;
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::computeDual<PFP>(myMap) ;
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "dual computation: "<< seconds << "sec" << std::endl;
position = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, "position") ;
normal = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
laplacian = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, "laplacian") ;
if(!laplacian.isValid())
laplacian = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "laplacian") ;
t1 = glutGet(GLUT_ELAPSED_TIME);
updateVBOprimitives(Algo::Render::VBO::TRIANGLES | Algo::Render::VBO::LINES | Algo::Render::VBO::POINTS) ;
updateVBOdata(Algo::Render::VBO::POSITIONS | Algo::Render::VBO::NORMALS) ;
topo_render->updateData<PFP>(myMap, position, 0.9f, 0.9f) ;
t2 = glutGet(GLUT_ELAPSED_TIME);
seconds = (t2 - t1) / 1000.0f;
std::cout << "display update: "<< seconds << "sec" << std::endl;
glutPostRedisplay() ;
break ;
}
case '3':
{
CellMarker markVisit(myMap, VERTEX_CELL) ;
CellMarker markNoDelete(myMap, VERTEX_CELL) ;
std::vector<Dart> visited ;
visited.reserve(myMap.getNbCells(VERTEX_CELL)) ;
visited.push_back(myMap.begin()) ;
markVisit.mark(myMap.begin()) ;
for(std::vector<Dart>::iterator vertex = visited.begin(); vertex != visited.end(); ++vertex)
{
bool deleteV = true ;
if(markNoDelete.isMarked(*vertex))
deleteV = false ;
Dart vit = *vertex ;
do // add all vertex neighbors to the table
{
Dart nv = myMap.phi1(vit) ;
if(!markVisit.isMarked(nv))
{
visited.push_back(nv) ;
markVisit.mark(nv) ;
}
if(deleteV)
markNoDelete.mark(nv) ;
vit = myMap.alpha1(vit) ;
} while(vit != *vertex) ;
if(deleteV)
myMap.deleteVertex(*vertex) ;
}
// for(Dart d = myMap.begin(); d != myMap.end(); myMap.next(d))
// {
// if(!markVisit.isMarked(d))
// {
// Dart dd = myMap.phi1(d) ;
// myMap.deleteVertex(d) ;
// Dart fit = dd ;
// do
// {
// markVisit.mark(fit) ;
// fit = myMap.phi1(fit) ;
// } while(fit != dd) ;
// }
// }
updateVBOprimitives(Algo::Render::VBO::TRIANGLES | Algo::Render::VBO::LINES | Algo::Render::VBO::POINTS) ;
updateVBOdata(Algo::Render::VBO::POSITIONS | Algo::Render::VBO::NORMALS) ;
topo_render->updateData<PFP>(myMap, position, 0.9f, 0.9f) ;
glutPostRedisplay() ;
break ;
}
case 'a':
{
Algo::Geometry::computeLaplacianVertices<PFP>(myMap, Algo::Geometry::TOPOLOGICAL, position, laplacian) ;
......@@ -633,6 +727,7 @@ int main(int argc, char** argv)
std::cerr << "could not import " << filename << std::endl ;
return 1 ;
}
mgw->position = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, attrNames[0]) ;
GLint t2 = glutGet(GLUT_ELAPSED_TIME) ;
GLfloat seconds = (t2 - t1) / 1000.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);