Commit ac0562e7 authored by untereiner's avatar untereiner

Merge cgogn:~cgogn/CGoGN

parents 79d29457 d1df0aeb
......@@ -38,6 +38,16 @@ add_executable( polyhedronsViewD ../polyhedronsView.cpp ${polyhedronsView_moc})
target_link_libraries( polyhedronsViewD
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(frame_manip_moc ../frame_manip.h)
add_executable( frame_manipD ../frame_manip.cpp ${frame_manip_moc})
target_link_libraries( frame_manipD
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(texturesExample_moc ../texturesExample.h)
add_executable( texturesExampleD ../texturesExample.cpp ${texturesExample_moc} )
target_link_libraries( texturesExampleD
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(extrusionView_moc ../extrusionView.h)
add_executable( extrusionViewD ../extrusionView.cpp ${extrusionView_moc})
target_link_libraries( extrusionViewD
......
......@@ -42,6 +42,16 @@ add_executable( polyhedronsView ../polyhedronsView.cpp ${polyhedronsView_moc})
target_link_libraries( polyhedronsView
${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(frame_manip_moc ../frame_manip.h)
add_executable( frame_manip ../frame_manip.cpp ${frame_manip_moc})
target_link_libraries( frame_manip
${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(texturesExample_moc ../texturesExample.h)
add_executable( texturesExample ../texturesExample.cpp ${texturesExample_moc} )
target_link_libraries( texturesExample
${CGoGN_LIBS_R} ${COMMON_LIBS} ${QT_LIBRARIES} )
QT4_WRAP_CPP(extrusionView_moc ../extrusionView.h)
add_executable( extrusionView ../extrusionView.cpp ${extrusionView_moc})
target_link_libraries( extrusionView
......
This diff is collapsed.
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
#ifndef FRAME_MANIP_EX_H_
#define FRAME_MANIP_EX_H_
#include <iostream>
#include "Utils/qtSimple.h"
#include "Utils/frameManipulator.h"
#include "Utils/drawer.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; }}}}
namespace CGoGN { namespace Utils { class VBO; } }
namespace CGoGN { namespace Utils { class ShaderFlat; } }
namespace CGoGN { namespace Utils { class ShaderSimpleColor; } }
using namespace CGoGN ;
/**
* A class for a little interface and rendering
*/
class MyQT: public Utils::QT::SimpleQT
{
Q_OBJECT
public:
// render
Algo::Render::GL2::MapRender* m_render;
// VBO
Utils::VBO* m_positionVBO;
Utils::FrameManipulator* m_frame;
unsigned int m_pickedAxis;
///vector of six drawables
std::vector<Utils::LineDrawable*> m_ld;
/// precision of drawing (number of subdivisions)
unsigned int m_precDraw;
std::vector<Utils::Pickable*> m_pickables;
Utils::Pickable* m_lastPickedObject;
// width of cube of pickable
unsigned int NBP;
MyQT():m_render(NULL), m_positionVBO(NULL),NBP(2){}
// callbacks of simpleQT to overdefine:
void cb_redraw();
void cb_initGL();
void cb_mousePress(int button, int x, int y);
void cb_wheelEvent(int delta, int x, int y);
void cb_keyPress(int code);
void cb_mouseMove(int button, int x, int y);
int m_begX;
int m_begY;
Geom::Vec3f m_projAxis;
Geom::Vec3f m_projCenter;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DockWidget</class>
<widget class="QDockWidget" name="DockWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>209</width>
<height>345</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>250</height>
</size>
</property>
<property name="windowTitle">
<string>Interface</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>200</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>2</number>
</property>
<property name="spacing">
<number>4</number>
</property>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
/*
* texture.cpp
*
* Created on: Jul 25, 2011
* Author: thery
*/
/*
* texturesExample.cpp
*
* Created on: Jul 21, 2011
* Author: thery
*/
#include "texturesExample.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Modelisation/polyhedron.h"
TexView::TexView():
m_render(NULL), m_positionVBO(NULL), m_texcoordVBO(NULL), m_texture(NULL), m_shader(NULL),m_modeMask(false),m_fileName("")
{
}
TexView::~TexView()
{
delete m_render;
delete m_shader;
delete m_positionVBO;
delete m_texcoordVBO;
delete m_texture;
}
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_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();
m_shader = new Utils::ShaderSimpleTexture();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setAttributeTexCoord(m_texcoordVBO);
m_shader->setTextureUnit(GL_TEXTURE0);
m_shader->setTexture(m_texture);
registerShader(m_shader);
m_shader2 = new Utils::ShaderTextureMask();
m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setAttributeTexCoord(m_texcoordVBO);
m_shader2->setTextureUnits(GL_TEXTURE0,GL_TEXTURE1);
m_shader2->setTextures(m_texture,m_mask);
registerShader(m_shader2);
glEnable(GL_TEXTURE_2D);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
}
void TexView::cb_redraw()
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
if (m_shader)
{
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);
}
}
}
void TexView::cb_keyPress(int code)
{
switch(code)
{
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();
}
break;
case 'M':
m_modeMask = !m_modeMask;
if (m_modeMask)
{
createMask(8);
m_mask->update();
}
break;
case 's':
m_texture->subSample2<Geom::Vec3d>();
m_texture->update();
break;
case 't':
m_texture->rotate90(3);
m_texture->update();
break;
case 'r':
m_texture->load(m_fileName);
m_texture->update();
break;
}
updateGL();
}
void TexView::cb_Open()
{
std::string filename = selectFile("Open Image","/tmp");
if (!filename.empty())
{
m_fileName = filename;
if (m_texture->load(filename))
{
m_texture->update();
updateGL();
}
else
CGoGNerr << "Problem loading image"<< CGoGNendl;
}
else
{
computeImage();
m_texture->update();
updateGL();
}
}
void TexView::createMask(unsigned int nb)
{
if (nb ==0)
return;
unsigned int sz0 = m_mask->size()[0]/nb;
unsigned int sz1 = m_mask->size()[1]/nb;
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;
colorTable.push_back(Geom::Vec3uc(255,0,0));
colorTable.push_back(Geom::Vec3uc(0,255,0));
colorTable.push_back(Geom::Vec3uc(0,0,255));
colorTable.push_back(Geom::Vec3uc(255,255,0));
colorTable.push_back(Geom::Vec3uc(255,0,255));
colorTable.push_back(Geom::Vec3uc(0,255,255));
colorTable.push_back(Geom::Vec3uc(255,255,255));
m_texture->create(Geom::Vec2ui(512,512));
#define WIDTHCHECKER 20
for (unsigned int ki = 0; ki < m_texture->size()[0]; ++ki)
{
for (unsigned int kj = 0; kj < m_texture->size()[1]; ++kj)
{
unsigned int kc = ((kj/WIDTHCHECKER)*m_texture->size()[0] + (ki/WIDTHCHECKER))%7;
(*m_texture)(ki,kj) =colorTable[kc];
}
}
#undef WIDTHCHECKER
}
int main(int argc, char**argv)
{
ilInit();
// interface:
QApplication app(argc, argv);
TexView tv;
PFP::MAP& m = tv.myMap;
AttributeHandler<PFP::VEC3> position = m.addAttribute<PFP::VEC3>(VERTEX, "position");
AttributeHandler<Geom::Vec2f> texcoord = m.addAttribute<Geom::Vec2f>(VERTEX, "texcoord");
#define NB 96
Algo::Modelisation::Polyhedron<PFP> prim(m, position);
prim.tore_topo(NB, NB);
prim.embedTore(40.0f,20.0f);
Dart d = prim.getDart();
for(unsigned int i=0; i<NB; ++i)
{
for(unsigned int j=0; j<NB; ++j)
{
float a;
if (i<=NB/2)
a = (2.0f/NB)*i;
else
a = (2.0f/NB)*(NB-i);
float b;
if (j<=NB/2)
b = (2.0f/NB)*j;
else
b =(2.0f/NB)*(NB-j);
texcoord[d] = Geom::Vec2f(a,b);
d = m.phi<121>(d);
}
d = m.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);
// 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
tv.show();
// et on attend la fin.
return app.exec();
}
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
#ifndef _TEXTURE_EXAMPLE_
#define _TEXTURE_EXAMPLE_
#include <iostream>
#include "Utils/qtSimple.h"
#include "Utils/textures.h"
#include "Utils/Shaders/shaderSimpleTexture.h"
#include "Utils/Shaders/shaderTextureMask.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"
#include "Algo/Render/GL2/mapRender.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
{
// definition of the map
typedef EmbeddedMap2<Map2> MAP ;
};
typedef PFP::MAP MAP ;
/**
* A class for a little interface and rendering
*/
class TexView: public Utils::QT::SimpleQT
{
Q_OBJECT
protected:
void createMask(unsigned int nb);
void computeImage();
public:
MAP myMap ;
SelectorTrue allDarts ;
// render
Algo::Render::GL2::MapRender* m_render;
// VBO
Utils::VBO* m_positionVBO;
Utils::VBO* m_texcoordVBO;
Utils::Texture<2,Geom::Vec3uc>* m_texture;
Utils::Texture<2,float>* m_mask;
//2 shaders
Utils::ShaderSimpleTexture* m_shader;
Utils::ShaderTextureMask* m_shader2;
//with mask or not
bool m_modeMask;
/// filename of last loaded texture
std::string m_fileName;
TexView();
~TexView();
// callbacks of simpleQT to overdefine:
void cb_redraw();
void cb_initGL();
void cb_keyPress(int code);
void cb_Open();
};
#endif
......@@ -23,6 +23,7 @@
*******************************************************************************/
#include "stage_shader.h"
#include "Utils/static_assert.h"
/*******************************************************************************
* SLOTS
......@@ -292,7 +293,7 @@ void StageShader::cb_mousePress(int button, int x, int y)
}
/**********************************************************************************************
* MAIN FUNCTION *
* MAIN FUNCTION *
**********************************************************************************************/
int main(int argc, char** argv)
......
......@@ -334,13 +334,13 @@ void MyQT::cb_initGL()
m_shader = new Utils::ShaderPhong();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setAttributeNormal(m_normalVBO);
m_shader->setDiffuse(Geom::Vec4f(0.,0.6,0.,0.));
m_shader->setSpecular(Geom::Vec4f(0.,0.0,0.,0.)); // no specular
m_shader->setDiffuse(Geom::Vec4f(0.0f,0.6f,0.0f,0.0f));
m_shader->setSpecular(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); // no specular
// using simple shader with color
m_shader2 = new Utils::ShaderSimpleColor();
m_shader2->setAttributePosition(m_positionVBO);
m_shader2->setColor(Geom::Vec4f(0.,0.1,0.,0.));