Commit 78098284 authored by Sylvain Thery's avatar Sylvain Thery

amelioration try picking Pickable

ajout calcul normal parla methode de Newell (face quelconque)
ajout interSectionRayTriangleOpt ( en test avant remplacement)
ajout rendu face concave
ajout de VarFloat dans inputValues (qtinputs)
modification text3d.frag (attention pas "" dans les commentaires !)
parent c5958723
......@@ -25,6 +25,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
......@@ -46,3 +47,9 @@ target_link_libraries( Geom_inclusionD
add_executable( Geom_intersectionD ./Geom_intersection.cpp)
target_link_libraries( Geom_intersectionD
${CGoGN_LIBS_D} ${COMMON_LIBS} )
QT4_WRAP_CPP(concave_rendering_moc concave_rendering.h)
add_executable( concave_renderingD concave_rendering.cpp ${concave_rendering_moc})
target_link_libraries( concave_renderingD
${CGoGN_LIBS_D} ${COMMON_LIBS} ${QT_LIBRARIES} )
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 _TUTO1_
#define _TUTO1_
#include <iostream>
#include "Utils/qtSimple.h"
#include "Utils/cgognStream.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 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;
// shader basic
Utils::ShaderSimpleColor* m_shader;
MyQT() : m_render(NULL), m_positionVBO(NULL), m_shader(NULL)
{}
// callbacks of simpleQT to overdefine:
void cb_initGL();
void cb_redraw();
void cb_keyPress(int code);
void cb_New() { CGoGNout << "New ..." << CGoGNendl; }
void cb_Save() { CGoGNout << "Rien a sauver ..." << CGoGNendl; }
// callbacks (slots) locally defined
public slots:
void menu_slot1() { CGoGNout << "Exemple de menu" << CGoGNendl; }
};
#endif
......@@ -50,6 +50,27 @@ typename PFP::VEC3 triangleNormal(typename PFP::MAP& map, Dart d, const typename
return N ;
}
template<typename PFP>
typename PFP::VEC3 newellNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position)
{
Dart e=d;
typename PFP::VEC3 normal(0);
do
{
const typename PFP::VEC3& P = position[e];
e = map.phi1(e);
const typename PFP::VEC3& Q = position[e];
normal[0] += (P[1]-Q[1])*(P[2]+Q[2]);
normal[1] += (P[2]-Q[2])*(P[0]+Q[0]);
normal[2] += (P[0]-Q[0])*(P[1]+Q[1]);
}while (e !=d);
normal.normalize();
return normal;
}
template <typename PFP>
typename PFP::VEC3 faceNormal(typename PFP::MAP& map, Dart d, const typename PFP::TVEC3& position)
{
......
......@@ -28,6 +28,7 @@
#include <GL/glew.h>
#include <vector>
#include <list>
#include <set>
#include <utility>
#include "Topology/generic/dart.h"
......@@ -89,8 +90,14 @@ protected:
typedef std::pair<GLuint*, unsigned int> buffer_array;
// forward declaration
class VertexPoly;
// comparaison function for multiset
static bool cmpVP(VertexPoly* lhs, VertexPoly* rhs);
// multiset typedef for simple writing
typedef std::multiset< VertexPoly*,bool(*)(VertexPoly*,VertexPoly*)> VPMS;
class VertexPoly
{
......@@ -99,118 +106,33 @@ protected:
float value;
VertexPoly* prev;
VertexPoly* next;
VertexPoly* store_link;
VPMS::iterator ear;
VertexPoly(int i, float v, VertexPoly* p=NULL): id(i),value(v), prev(p), next(NULL),store_link(NULL)
VertexPoly(int i, float v, VertexPoly* p=NULL): id(i),value(v), prev(p), next(NULL)
{
if (prev!=NULL)
{
prev->next = this;
prev->store_link = this;
}
}
static void close(VertexPoly* first, VertexPoly* last)
{
last->next = first;
last->store_link = first;
first->prev = last;
}
VertexPoly* unlink()
static VertexPoly* erase(VertexPoly* vp)
{
this->prev->next = this->next;
this->next->prev = this->prev;
this->value = 20.0f;
return this->prev;
VertexPoly* tmp = vp->prev;
tmp->next = vp->next;
vp->next->prev = tmp;
vp->value = 20.0f; //??
delete vp;
return tmp;
}
static void erasePoly(VertexPoly* vp)
{
VertexPoly* curr = vp;
do
{
VertexPoly* tmp = curr;
curr = curr->store_link;
delete tmp;
}while (curr != vp);
}
};
// struct VertexPoly
// {
// int id;
// float value;
// unsigned int prev;
// unsigned int next;
// VertexPoly(int i, float v): id(i),value(v) {}
// };
//
// class Polygon
// {
// protected:
// std::vector<VertexPoly> m_vertices;
// public:
// Polygon()
// {
// m_vertices.reserve(256);
// }
//
// inline void addVertex(int id, float val)
// {
// m_vertices.push_back(VertexPoly(id,val));
// }
//
// inline void link_all()
// {
// unsigned int sz = m_vertices.size()-1;
// for (unsigned int i = 1; i<sz; ++i)
// {
// m_vertices[i].next = i+1;
// m_vertices[i].prev = i-1;
// }
// m_vertices[0].next = 1;
// m_vertices[0].prev = m_vertices.size();
// m_vertices[sz].next = 0;
// m_vertices[sz].prev = sz-1;
// }
//
// inline void unlink(unsigned int v)
// {
// m_vertices[ m_vertices[v].prev].next = m_vertices[v].next;
// m_vertices[ m_vertices[v].next].prev = m_vertices[v].prev;
// }
//
// inline const VertexPoly& prev(unsigned int v) const
// {
// return m_vertices[m_vertices[v].prev];
// }
//
// inline const VertexPoly& next(unsigned int v) const
// {
// return m_vertices[m_vertices[v].next];
// }
//
// inline unsigned int prevId(unsigned int v) const
// {
// return m_vertices[v].prev;
// }
//
// inline unsigned int nextId(unsigned int v) const
// {
// return m_vertices[v].next;
// }
//
// inline VertexPoly& operator()(unsigned int v)
// {
// return m_vertices[v];
// }
// };
public:
/**
......@@ -244,14 +166,17 @@ protected:
template<typename PFP>
inline void addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices);
// template<typename PFP>
// float computeEarAngle(AttributeHandler<typename PFP::VEC3>& position, const typename PFP::VEC3& normalPoly, unsigned int i, unsigned int j, unsigned int k);
template<typename PFP>
float computeEarAngle(AttributeHandler<typename PFP::VEC3>& position, const typename PFP::VEC3& normalPoly, unsigned int i, unsigned int j, unsigned int k);
float computeEarAngle(const typename PFP::VEC3& P1, const typename PFP::VEC3& P2, const typename PFP::VEC3& P3, const typename PFP::VEC3& normalPoly);
template<typename PFP>
bool computeEarIntersection(AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly);
template<typename PFP>
void recompute2Ears( AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, std::multimap<float, VertexPoly*>& ears, bool convex);
void recompute2Ears( AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex);
public:
......
This diff is collapsed.
......@@ -59,11 +59,59 @@ Intersection intersectionLinePlane(const VEC3& P, const VEC3& Dir, const VEC3& P
/**
* test the intersection between a ray and a triangle
* test the intersection between a ray and a triangle (optimized version with triple product
* @param P a point on the line
* @param Dir line direction
* @param Ta triangle point 1
* @param Tb triangle point 2
* @param Tc triangle point 3
* @param Inter store the intersection point
* @return the intersection ( FACE_INTERSECTION / EDGE_INTERSECTION / VERTEX_INTERSECTION / NO_INTERSECTION)
*/
template <typename VEC3>
Intersection intersectionRayTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ;
/**
* test the intersection between a ray and a triangle (optimized version with triple product
* @param P a point on the line
* @param Dir line direction
* @param Ta triangle point 1
* @param Tb triangle point 2
* @param Tc triangle point 3
* @param Inter store the intersection point
* @return the intersection ( FACE_INTERSECTION / EDGE_INTERSECTION / VERTEX_INTERSECTION / NO_INTERSECTION)
*/
template <typename VEC3>
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter);
/**
* test the intersection between a ray and a triangle (optimized version with triple product
* @param P a point on the line
* @param Dir line direction
* @param Ta triangle point 1
* @param Tb triangle point 2
* @param Tc triangle point 3
* @return the intersection ( FACE_INTERSECTION / EDGE_INTERSECTION / VERTEX_INTERSECTION / NO_INTERSECTION)
*/
template <typename VEC3>
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc);
/**
* test the intersection between a ray and a triangle, but test only face intersection and
* @param P a point on the line
* @param Dir line direction
* @param Ta triangle point 1
* @param Tb triangle point 2
* @param Tc triangle point 3
* @param Inter store the intersection point
* @return the intersection ( FACE_INTERSECTION / EDGE_INTERSECTION / VERTEX_INTERSECTION / NO_INTERSECTION)
*/
//template <typename VEC3>
//Intersection intersectionRayTriangleFaceOnly(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc)
/**
* test the intersection between a line and a triangle
* @param P a point on the line
......
......@@ -52,6 +52,146 @@ Intersection intersectionLinePlane(const VEC3& P, const VEC3& Dir, const VEC3& P
}
//template <typename VEC3>
//Intersection intersectionRayTriangleFaceOnly(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc)
//{
// typedef typename VEC3::DATA_TYPE T ;
//
// VEC3 u = Ta - P ;
// VEC3 v = Tb - P ;
// VEC3 w = Tc - P ;
// T x = tripleProduct(Dir, u, v) ;
// T y = tripleProduct(Dir, v, w) ;
// T z = tripleProduct(Dir, w, u) ;
// if((x < T(0) && y < T(0) && z < T(0)) || (x > T(0) && y > T(0) && z > T(0)))
// return FACE_INTERSECTION ;
// return NO_INTERSECTION ;
//}
template <typename VEC3>
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter)
{
typedef typename VEC3::DATA_TYPE T ;
VEC3 u = Ta - P ;
VEC3 v = Tb - P ;
VEC3 w = Tc - P ;
T x = tripleProduct(Dir, u, v) ;
T y = tripleProduct(Dir, v, w) ;
T z = tripleProduct(Dir, w, u) ;
unsigned int np=0;
unsigned int nn=0;
unsigned int nz=0;
if (x>T(0))
++np;
else
if (x<T(0))
++nn;
else ++nz;
if (y>T(0))
++np;
else
if (y<T(0))
++nn;
else ++nz;
if (z>T(0))
++np;
else
if (z<T(0))
++nn;
else ++nz;
if ((np !=0) && (nn!=0))
return NO_INTERSECTION;
T sum = x + y + z ;
T alpha = y / sum ;
T beta = z / sum ;
T gamma = T(1) - alpha - beta ;
Inter = Ta * alpha + Tb * beta + Tc * gamma ;
return Intersection(FACE_INTERSECTION-nz);
// switch(nz)
// {
// case 0:
// {
// T sum = x + y + z ;
// T alpha = y / sum ;
// T beta = z / sum ;
// T gamma = T(1) - alpha - beta ;
// Inter = Ta * alpha + Tb * beta + Tc * gamma ;
// return FACE_INTERSECTION ;
// }
// break;
// case 1:
// return EDGE_INTERSECTION;
// break;
// case 2:
// return VERTEX_INTERSECTION;
// break;
// default:
// return NO_INTERSECTION;
// break;
// }
// // just for no warning compilation
// return NO_INTERSECTION;
}
template <typename VEC3>
Intersection intersectionRayTriangleOpt(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc)
{
typedef typename VEC3::DATA_TYPE T ;
VEC3 u = Ta - P ;
VEC3 v = Tb - P ;
VEC3 w = Tc - P ;
T x = tripleProduct(Dir, u, v) ;
T y = tripleProduct(Dir, v, w) ;
T z = tripleProduct(Dir, w, u) ;
unsigned int np=0;
unsigned int nn=0;
unsigned int nz=0;
if (x>T(0))
++np;
else
if (x<T(0))
++nn;
else ++nz;
if (y>T(0))
++np;
else
if (y<T(0))
++nn;
else ++nz;
if (z>T(0))
++np;
else
if (z<T(0))
++nn;
else ++nz;
if ((np !=0) && (nn!=0))
return NO_INTERSECTION;
return Intersection(FACE_INTERSECTION-nz);
}
template <typename VEC3>
Intersection intersectionRayTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter)
......
......@@ -104,10 +104,11 @@ public:
* picking
* @param P camera point
* @param V vector ray direction
* @param I intersection point (out) for Z sorting
* @param epsilon distance epsilon for picking
* @return code picking (0: nothing picked / != 0 something picked)
*/
virtual unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f) = 0;
virtual unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, Geom::Vec3f& I, float epsilon=0.0f) = 0;
/**
* update the precision of drawing
......@@ -153,10 +154,11 @@ public:
* picking
* @param P camera point
* @param V vector ray direction
* @param I intersection point (out) for Z sorting
* @param epsilon distance epsilon for picking
// * @return picked ?
* @return picked
*/
bool pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
bool pick(const Geom::Vec3f& P, const Geom::Vec3f& V, Geom::Vec3f& I, float epsilon=0.0f);
/**
* apply inverse transfo on picking ray
......@@ -280,7 +282,7 @@ public:
/**
* picking
*/
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, Geom::Vec3f& I, float epsilon=0.0f);
/**
* return a string with shape of object
......@@ -323,7 +325,7 @@ public:
/**
* picking
*/
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, Geom::Vec3f& I, float epsilon=0.0f);
/**
* return a string with shape of object
......@@ -360,7 +362,7 @@ public:
/**
* picking
*/
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, Geom::Vec3f& I, float epsilon=0.0f);
/**
* return a string with shape of object
......@@ -397,7 +399,7 @@ public:
/**
* picking
*/
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, Geom::Vec3f& I, float epsilon=0.0f);
/**
* return a string with shape of object
......@@ -441,7 +443,7 @@ public:
/**
* picking
*/
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, Geom::Vec3f& I, float epsilon=0.0f);
/**
* return a string with shape of object
......
......@@ -114,6 +114,26 @@ public:
void updateFrom(QWidget* widg) const;
};
/**
* Class for double input in dialog window (with spinbox)
* Use: VarBool(min,max,ref_to_val, "label" [,nextVar])
*/
class VarFloat: public Var
{
public:
float m_min;
float m_max;
float& m_val;
public:
VarFloat(float min, float max, float& val, const std::string& label);
VarFloat(float min, float max, float& val, const std::string& label, const Var& var);
QWidget* createInput() const;
void updateFrom(QWidget* widg) const;
};
/**
* Class for integer input in dialog window (with slider)
* Use: VarBool(min,max,ref_to_val, "label" [,nextVar])
......
......@@ -7,4 +7,4 @@ FRAG_OUT_DEF;
void main (void)
{
float lum = texture2D(FontTexture, tex_coord).s;;
// no "}" because it is added in the shader class code (with other things)
// no '}' because it is added in the shader class code (with other things)
......@@ -37,6 +37,7 @@ namespace Render
namespace GL2
{
MapRender::MapRender()
{
glGenBuffersARB(4, m_indexBuffers) ;
......
......@@ -24,6 +24,7 @@
#include "Utils/pickables.h"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtx/norm.hpp"
#include "Geometry/distances.h"
#include "Geometry/intersection.h"
#include <algorithm>
......@@ -106,13 +107,13 @@ void Pickable::invertPV(const Geom::Vec3f& P, const Geom::Vec3f& V, const glm::m
bool Pickable::pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon)
bool Pickable::pick(const Geom::Vec3f& P, const Geom::Vec3f& V, Geom::Vec3f& I, float epsilon)
{
Geom::Vec3f PP;
Geom::Vec3f VV;
invertPV(P,V,m_transfo,PP,VV);
return m_drawable->pick(PP,VV,epsilon) != 0;