Commit 60532b3e authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

Merge cgogn.u-strasbg.fr:~cgogn/CGoGN

parents 2c03ba24 e664bed6
......@@ -297,12 +297,20 @@ void MyQT::cb_keyPress(int code)
if (m_lastPickedObject)
m_frame->setTransformation(m_lastPickedObject->transfo());
break;
case 'x':
if (m_frame->locked(Utils::FrameManipulator::Xt))
m_frame->unlock(Utils::FrameManipulator::Xt);
else
m_frame->lock(Utils::FrameManipulator::Xt);
break;
case 'w':
if (m_frame->locked(Utils::FrameManipulator::Xt))
m_frame->unlock(Utils::FrameManipulator::Translations);
else
m_frame->lock(Utils::FrameManipulator::Translations);
break;
case 'y':
if (m_frame->locked(Utils::FrameManipulator::Yt))
m_frame->unlock(Utils::FrameManipulator::Yt);
......@@ -370,7 +378,7 @@ int main(int argc, char **argv)
sqt.NBP = atoi(argv[1]);
sqt.setHelpMsg("Param :size of grid (number of objects)\nMpuse:\n"
sqt.setHelpMsg("Param :size of grid (number of objects)\nMpuse (with shift):\n"
" -click on object: selection\n -left click on frame: constraint 3d Rotation/Translation/Scale\n"
" -right click on frame :free 2D Rotation/Translation\nKeys:\n x/y/z lock/unlock translation\n a/b/c lock/unlock rotation\n s/t/u lock/unlock scaling");
......
......@@ -21,8 +21,8 @@
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef POLYHEDRONSVIEW_H_
#define POLYHEDRONSVIEW_H_
#ifndef FRAME_MANIP_EX_H_
#define FRAME_MANIP_EX_H_
#include <iostream>
......
......@@ -28,7 +28,6 @@
#include "Utils/vbo.h"
#include "glm/glm.hpp"
//#include "Utils/Shaders/shaderColorPerVertex.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/pickables.h"
......@@ -39,276 +38,11 @@ namespace Utils
{
//
//
//class LineDrawable
//{
//protected:
//
// /**
// * VBO for position
// */
// Utils::VBO* m_vboPos;
//
// /**
// * Shader
// */
// Utils::ShaderSimpleColor* m_shader;
//
// /**
// * number of indices in vbo
// */
// unsigned int m_nb;
//
//public:
// /**
// * constructor
// */
// LineDrawable();
//
// /**
// * destructor
// */
// virtual ~LineDrawable();
//
// /**
// * set the color of drawing
// */
// void setColor(const Geom::Vec4f& col);
//
// /**
// * draw the Drawable at origin with size=1
// */
// virtual void draw();
//
// /**
// * picking
// * @param P camera point
// * @param V vector ray direction
// * @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;
//
//};
//
//
//class Pickable
//{
//protected:
// /**
// * type of drawable
// */
// LineDrawable* m_drawable;
//
// /**
// * transformation matrix
// */
// glm::mat4 m_transfo;
//
// /**
// * id of pickable
// */
// unsigned int m_id;
//
//public:
// /**
// * constructor
// * @param ld LineDrawable to use for drawing & picking
// */
// Pickable(LineDrawable* ld, unsigned int id):
// m_drawable(ld),m_transfo(1.0f), m_id(id)
// {}
//
// /**
// * picking
// * @param P camera point
// * @param V vector ray direction
// * @param epsilon distance epsilon for picking
// * @return code picking (0: nothing picked / != 0 something picked)
// */
// unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//
// /**
// * apply inverse transfo on picking ray
// */
// static void invertPV(const Geom::Vec3f& P, const Geom::Vec3f& V, const glm::mat4& transfo, Geom::Vec3f& PP, Geom::Vec3f& VV);
//
// /**
// * draw
// */
// void draw() { m_drawable->draw();}
//
// /**
// * return a ref on the transformation matrix
// */
// glm::mat4& transfo();
//
// void rotate(float angle, const Geom::Vec3f& Axis);
//
// void translate(const Geom::Vec3f& P);
//
// void scale(const Geom::Vec3f& S);
//
// /**
// * pick a vector of pickable and return the closest
// */
// static unsigned int pick(const std::vector<Pickable*>& picks,const Geom::Vec3f& P, const Geom::Vec3f& V, Pickable*& res);
//
// float distancefrom(const Geom::Vec3f& P);
//
//
//};
//
//
///**
// * Grid (-1,-1,0 ; 1,1,0)
// */
//class Grid: public LineDrawable
//{
//public:
// /**
// * constructor
// * @param sub number of subdivision of grig
// */
// Grid(unsigned int sub=5);
//
// /**
// * change topo subdivision
// */
// void changeTopo(unsigned int sub);
//
// /**
// * picking
// */
// unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
//
///**
// * Sphere of radius 1 drawon with lines
// */
//class Sphere: public LineDrawable
//{
//protected:
// GLuint m_ind;
//public:
// /**
// * constructor
// * @param par number of parallels
// * @param mer number of meridians
// */
// Sphere(unsigned int par=5, unsigned int mer=5);
//
// /**
// * change topo subdivision
// */
// void changeTopo(unsigned int par, unsigned int mer);
//
// /**
// * specific drawing function for sphere (with indexed vbos)
// */
// void draw();
//
// /**
// * picking
// */
// unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
//
///**
// * Cone of radius 1 drawon with lines
// */
//class Cone: public Sphere
//{
//public:
// /**
// * constructor
// * @param par number of parallels
// * @param mer number of meridians
// */
// Cone(unsigned int par=5, unsigned int mer=5);
//
// /**
// * change topo subdivision
// */
// void changeTopo(unsigned int par, unsigned int mer);
//
// /**
// * picking
// */
// unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
///**
// * Cone of radius 1 drawon with lines
// */
//class Cylinder: public Sphere
//{
//public:
// /**
// * constructor
// * @param par number of parallels
// * @param mer number of meridians
// */
// Cylinder(unsigned int par=5, unsigned int mer=5);
//
// /**
// * change topo subdivision
// */
// void changeTopo(unsigned int par, unsigned int mer);
//
// /**
// * picking
// */
// unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
//
///**
// * Sphere of radius 1 drawon with lines
// */
//class Cube: public LineDrawable
//{
//protected:
// GLuint m_ind;
//public:
// /**
// * constructor
// * @param par number of parallels
// * @param mer number of meridians
// */
// Cube(unsigned int sub=0);
//
// /**
// * destructor
// */
// ~Cube();
//
// /**
// * change topo subdivision
// */
// void changeTopo(unsigned int sub);
//
// /**
// * specific drawing function for sphere (with indexed vbos)
// */
// void draw();
//
// /**
// * picking
// */
// unsigned int pick(const Geom::Vec3f& P, const Geom::Vec3f& V, float epsilon=0.0f);
//};
//
//
class FrameManipulator//: public Pickable
{
public:
enum AXIS {NONE=0, CENTER, Xt, Yt, Zt, Xr, Yr, Zr, Xs, Ys, Zs};
enum AXIS {NONE=0, CENTER, Xt, Yt, Zt, Xr, Yr, Zr, Xs, Ys, Zs, Translations, Rotations, Scales};
protected:
......@@ -325,6 +59,11 @@ protected:
*/
bool m_locked_axis[11];
/**
* pinking only locking table
*/
bool m_lockedPicking_axis[11];
/**
* VBO for position
*/
......@@ -389,6 +128,8 @@ protected:
*/
glm::mat4 transfoRenderFrame();
bool axisPickable(unsigned int a) { return (!m_locked_axis[a]) && (!m_lockedPicking_axis[a]);}
public:
FrameManipulator();
......@@ -419,20 +160,55 @@ public:
/**
* lock an axis
* lock an axis (drawing & picking are disabled)
* @param axis the axis Xt/Yt/Zt/Xs/Yx/Zs/Xr/Yr/Zr or group Translations/Scales/Rotations)
*/
void lock(unsigned int axis);
/**
* unlock an axis
* @param axis the axis Xt/Yt/Zt/Xs/Yx/Zs/Xr/Yr/Zr or group Translations/Scales/Rotations)
*/
void unlock(unsigned int axis);
/**
* is an axis locked
* @param axis the axis to test
*/
bool locked(unsigned int axis);
/**
* lock an axis only for pinking
*/
void lockPicking(unsigned int axis);
/// lock translations for picking only
void lockPickingTranslations();
/// lock rotations for picking only
void lockPickingRotations();
/// lock scales for picking only
void lockPickingScales();
/**
* unlock an axis (only for pinking)
*/
void unlockPicking(unsigned int axis);
/// unlock translations for picking only
void unlockPickingTranslations();
/// unlock rotations for picking only
void unlockPickingRotations();
/// unlock scales for picking only
void unlockPickingScales();
/**
* is an axis locked (only for pinking)
*/
bool lockedPicking(unsigned int axis);
/**
* higlight an axis (change width rendering).
* To unhighlight, just highlight NONE or highlight a already highlighted axis
......
......@@ -763,13 +763,12 @@ bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
DartMarkerStore mv(*this,thread); // Lock a marker
bool found = false; // Last functor return value
std::vector<Dart> darts_list; //Darts that are traversed
darts_list.reserve(50);
std::list<Dart> darts_list; //Darts that are traversed
darts_list.push_back(d); //Start with the dart d
mv.mark(d);
for(std::vector<Dart>::iterator darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
for(std::list<Dart>::iterator darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
{
Dart dc = *darts;
......@@ -799,6 +798,7 @@ bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
return found;
}
bool Map3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread)
{
Dart dNext = d;
......
......@@ -32,7 +32,7 @@
//#include "glm/gtc/type_precision.hpp"
//#include "glm/gtc/type_ptr.hpp"
#include <cmath>
//#include <cmath>
namespace CGoGN
{
......@@ -49,7 +49,10 @@ FrameManipulator::FrameManipulator():
{
for (unsigned int i=0; i<11; ++i)
{
m_locked_axis[i]=false;
m_lockedPicking_axis[i]=false;
}
m_vboPos = new VBO();
m_vboPos->setDataSize(3);
......@@ -315,7 +318,8 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
// click on center
if (dist2 < 0.02f*0.02f)
{
if (! m_locked_axis[CENTER])
// if (! m_locked_axis[CENTER])
if (axisPickable(CENTER))
return CENTER;
else
return NONE;
......@@ -335,74 +339,90 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
Geom::Vec3f Qx;
Geom::Intersection inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(1.0f,0.0f,0.0f), Qx);
if (inter == Geom::FACE_INTERSECTION)
dist_target[3] = Qx.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[3] = sqrtf(dist2) - 1.0f;
if (axisPickable(Xr))
{
if (inter == Geom::FACE_INTERSECTION)
dist_target[3] = Qx.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[3] = sqrt(dist2) - 1.0f;
if (fabs(dist_target[3]) < ring_half_width )
dist_cam[3] = (P-Qx)*(P-Qx);
if (fabs(dist_target[3]) < ring_half_width )
dist_cam[3] = (P-Qx)*(P-Qx);
}
// plane Y=0
Geom::Vec3f Qy;
inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(0.0f,1.0f,0.0f), Qy);
if (inter == Geom::FACE_INTERSECTION)
dist_target[4] = Qy.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[4] = sqrtf(dist2) - 1.0f;
if (axisPickable(Yr))
{
if (inter == Geom::FACE_INTERSECTION)
dist_target[4] = Qy.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[4] = sqrt(dist2) - 1.0f;
if (fabs(dist_target[4]) < ring_half_width )
dist_cam[4] = (P-Qy)*(P-Qy);
if (fabs(dist_target[4]) < ring_half_width )
dist_cam[4] = (P-Qy)*(P-Qy);
}
// plane Z=0
Geom::Vec3f Qz;
inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(0.0f,0.0f,1.0f), Qz);
if (inter == Geom::FACE_INTERSECTION)
dist_target[5] = Qz.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[5] = sqrtf(dist2) - 1.0f;
if (fabs(dist_target[5]) < ring_half_width )
dist_cam[5] = (P-Qz)*(P-Qz);
if (axisPickable(Zr))
{
if (inter == Geom::FACE_INTERSECTION)
dist_target[5] = Qz.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
dist_target[5] = sqrt(dist2) - 1.0f;
if (fabs(dist_target[5]) < ring_half_width )
dist_cam[5] = (P-Qz)*(P-Qz);
}
// axes:
Geom::Vec3f PX(1.0f,0.0f,0.0f);
dist_target[0] = sqrtf(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PX)) ;
if (fabs(dist_target[0]) < 0.02f)
if (axisPickable(Xt) || axisPickable(Xs))
{
if ( (Qz - origin).norm() > m_lengthAxes[0])
dist_cam[0] = (P-PX)*(P-PX);
else
dist_cam[6] = (P-origin)*(P-origin);
}
Geom::Vec3f PX(1.0f,0.0f,0.0f);
dist_target[0] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PX)) ;
if (fabs(dist_target[0]) < 0.02f)
{
if ( (Qz - origin).norm() > m_lengthAxes[0])
dist_cam[0] = (P-PX)*(P-PX);
else
dist_cam[6] = (P-origin)*(P-origin);
}
}
Geom::Vec3f PY(0.0f,1.0f,0.0f);
dist_target[1] = sqrtf(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PY)) ;
if (fabs(dist_target[1]) < 0.02f )
if (axisPickable(Yt) || axisPickable(Ys))
{
if ((Qz - origin).norm() > m_lengthAxes[1])
dist_cam[1] = (P-PY)*(P-PY);
else
dist_cam[7] = (P-origin)*(P-origin);
Geom::Vec3f PY(0.0f,1.0f,0.0f);
dist_target[1] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PY)) ;
if (fabs(dist_target[1]) < 0.02f )
{
if ((Qz - origin).norm() > m_lengthAxes[1])
dist_cam[1] = (P-PY)*(P-PY);
else
dist_cam[7] = (P-origin)*(P-origin);
}
}
Geom::Vec3f PZ(0.0f,0.0f,1.0f);
dist_target[2] = sqrtf(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PZ));
if (fabs(dist_target[2]) < 0.02f )
if (axisPickable(Zt) || axisPickable(Zs))
{
if ((Qx - origin).norm() > m_lengthAxes[2])
dist_cam[2] = (P-PZ)*(P-PZ);
else
dist_cam[8] = (P-origin)*(P-origin);
Geom::Vec3f PZ(0.0f,0.0f,1.0f);
dist_target[2] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PZ));
if (fabs(dist_target[2]) < 0.02f )
{
if ((Qx - origin).norm() > m_lengthAxes[2])
dist_cam[2] = (P-PZ)*(P-PZ);
else
dist_cam[8] = (P-origin)*(P-origin);
}
}
// find min dist_cam value;
unsigned int min_index=0;
float min_val = dist_cam[0];
......@@ -417,7 +437,8 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
if (min_val < std::numeric_limits<float>::max())
{
if (! m_locked_axis[Xt+min_index])
// if (! m_locked_axis[Xt+min_index])
if (axisPickable(Xt+min_index))
return Xt+min_index;
}
......@@ -454,13 +475,17 @@ void FrameManipulator::setLengthAxes()
float sc1 = m_scale[1]/avgScale;
float sc2 = m_scale[2]/avgScale;
positions[ind] = 0.23f*sc0;
ind+=7;
positions[ind] = 0.23f*sc1;
ind+=7;
positions[ind] = 0.23f*sc2;
ind++;
positions[ind] = 0.27f*sc0;
if (m_locked_axis[Xs])
positions[ind] = 0.0f;
else
positions[ind] = 0.27f*sc0;
ind+=3;
positions[ind] = 0.75f*sc0;
ind+=3;
......@@ -478,7 +503,10 @@ void FrameManipulator::setLengthAxes()
positions[ind] = le;
ind+=4;
positions[ind] = 0.27f*sc1;
if (m_locked_axis[Ys])
positions[ind] = 0.0f;
else
positions[ind] = 0.27f*sc1;
ind+=3;
positions[ind] = 0.75f*sc1;
ind+=3;
......@@ -496,7 +524,10 @@ void FrameManipulator::setLengthAxes()
positions[ind] = le;
ind+=4;
positions[ind] = 0.27f*sc2;
if (m_locked_axis[Zs])
positions[ind] = 0.0f;
else
positions[ind] = 0.27f*sc2;
ind+=3;
positions[ind] = 0.75f*sc2;
ind+=3;
......@@ -620,20 +651,131 @@ void FrameManipulator::setTransformation( const glm::mat4& transfo)
void FrameManipulator::lock(unsigned int axis)
{
m_locked_axis[axis] = true;
assert(axis <=Scales);
switch (axis)
{
case Translations:
m_locked_axis[Xt] = true;
m_locked_axis[Yt] = true;
m_locked_axis[Zt] = true;
break;
case Rotations:
m_locked_axis[Xr] = true;
m_locked_axis[Yr] = true;
m_locked_axis[Zr] = true;
break;
case Scales:
m_locked_axis[Xs] = true;
m_locked_axis[Ys] = true;
m_locked_axis[Zs] = true;
break;
default:
m_locked_axis[axis] = true;
break;
}
setLengthAxes();
}
void FrameManipulator::unlock(unsigned int axis)
{
m_locked_axis[axis] = false;
assert(axis <=Scales);
switch (axis)
{
case Translations:
m_locked_axis[Xt] = false;
m_locked_axis[Yt] = false;
m_locked_axis[Zt] = false;
break;
case Rotations:
m_locked_axis[Xr] = false;
m_locked_axis[Yr] = false;
m_locked_axis[Zr] = false;
break;
case Scales:
m_locked_axis[Xs] = false;
m_locked_