Commit e1f0767d authored by Maire Nicolas's avatar Maire Nicolas

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

Conflicts:
	src/Topology/map/map3.cpp
parents 4259b169 bcb99dac
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "glm/gtc/type_precision.hpp" #include "glm/gtc/type_precision.hpp"
#include "glm/gtc/type_ptr.hpp" #include "glm/gtc/type_ptr.hpp"
#include "Utils/textures.h"
using namespace CGoGN; using namespace CGoGN;
...@@ -297,12 +298,20 @@ void MyQT::cb_keyPress(int code) ...@@ -297,12 +298,20 @@ void MyQT::cb_keyPress(int code)
if (m_lastPickedObject) if (m_lastPickedObject)
m_frame->setTransformation(m_lastPickedObject->transfo()); m_frame->setTransformation(m_lastPickedObject->transfo());
break; break;
case 'x': case 'x':
if (m_frame->locked(Utils::FrameManipulator::Xt)) if (m_frame->locked(Utils::FrameManipulator::Xt))
m_frame->unlock(Utils::FrameManipulator::Xt); m_frame->unlock(Utils::FrameManipulator::Xt);
else else
m_frame->lock(Utils::FrameManipulator::Xt); m_frame->lock(Utils::FrameManipulator::Xt);
break; 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': case 'y':
if (m_frame->locked(Utils::FrameManipulator::Yt)) if (m_frame->locked(Utils::FrameManipulator::Yt))
m_frame->unlock(Utils::FrameManipulator::Yt); m_frame->unlock(Utils::FrameManipulator::Yt);
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
* Contact information: cgogn@unistra.fr * * Contact information: cgogn@unistra.fr *
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef POLYHEDRONSVIEW_H_ #ifndef FRAME_MANIP_EX_H_
#define POLYHEDRONSVIEW_H_ #define FRAME_MANIP_EX_H_
#include <iostream> #include <iostream>
......
...@@ -308,7 +308,7 @@ namespace Utils ...@@ -308,7 +308,7 @@ namespace Utils
class FrameManipulator//: public Pickable class FrameManipulator//: public Pickable
{ {
public: 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: protected:
...@@ -325,6 +325,11 @@ protected: ...@@ -325,6 +325,11 @@ protected:
*/ */
bool m_locked_axis[11]; bool m_locked_axis[11];
/**
* pinking only locking table
*/
bool m_lockedPicking_axis[11];
/** /**
* VBO for position * VBO for position
*/ */
...@@ -389,6 +394,8 @@ protected: ...@@ -389,6 +394,8 @@ protected:
*/ */
glm::mat4 transfoRenderFrame(); glm::mat4 transfoRenderFrame();
bool axisPickable(unsigned int a) { return (!m_locked_axis[a]) && (!m_lockedPicking_axis[a]);}
public: public:
FrameManipulator(); FrameManipulator();
...@@ -419,20 +426,55 @@ public: ...@@ -419,20 +426,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); void lock(unsigned int axis);
/** /**
* unlock an 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); void unlock(unsigned int axis);
/** /**
* is an axis locked * is an axis locked
* @param axis the axis to test
*/ */
bool locked(unsigned int axis); 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). * higlight an axis (change width rendering).
* To unhighlight, just highlight NONE or highlight a already highlighted axis * To unhighlight, just highlight NONE or highlight a already highlighted axis
......
...@@ -764,12 +764,13 @@ bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) ...@@ -764,12 +764,13 @@ bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
bool found = false; // Last functor return value bool found = false; // Last functor return value
std::list<Dart> darts_list; //Darts that are traversed std::list<Dart> darts_list; //Darts that are traversed
darts_list.push_back(d); //Start with the dart d darts_list.push_back(d); //Start with the dart d
std::list<Dart>::iterator darts;
mv.mark(d); mv.mark(d);
for(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; Dart dc = *darts;
...@@ -796,6 +797,7 @@ bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) ...@@ -796,6 +797,7 @@ bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
return found; return found;
} }
bool Map3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread) bool Map3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread)
{ {
Dart dNext = d; Dart dNext = d;
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
//#include "glm/gtc/type_precision.hpp" //#include "glm/gtc/type_precision.hpp"
//#include "glm/gtc/type_ptr.hpp" //#include "glm/gtc/type_ptr.hpp"
#include <cmath> //#include <cmath>
namespace CGoGN namespace CGoGN
{ {
...@@ -49,7 +49,10 @@ FrameManipulator::FrameManipulator(): ...@@ -49,7 +49,10 @@ FrameManipulator::FrameManipulator():
{ {
for (unsigned int i=0; i<11; ++i) for (unsigned int i=0; i<11; ++i)
{
m_locked_axis[i]=false; m_locked_axis[i]=false;
m_lockedPicking_axis[i]=false;
}
m_vboPos = new VBO(); m_vboPos = new VBO();
m_vboPos->setDataSize(3); m_vboPos->setDataSize(3);
...@@ -315,7 +318,8 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV ...@@ -315,7 +318,8 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
// click on center // click on center
if (dist2 < 0.02f*0.02f) if (dist2 < 0.02f*0.02f)
{ {
if (! m_locked_axis[CENTER]) // if (! m_locked_axis[CENTER])
if (axisPickable(CENTER))
return CENTER; return CENTER;
else else
return NONE; return NONE;
...@@ -335,74 +339,90 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV ...@@ -335,74 +339,90 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV
Geom::Vec3f Qx; Geom::Vec3f Qx;
Geom::Intersection inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(1.0f,0.0f,0.0f), 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) if (axisPickable(Xr))
dist_target[3] = Qx.norm() - 1.0f; {
else if (inter == Geom::EDGE_INTERSECTION) if (inter == Geom::FACE_INTERSECTION)
dist_target[3] = sqrtf(dist2) - 1.0f; 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 ) if (fabs(dist_target[3]) < ring_half_width )
dist_cam[3] = (P-Qx)*(P-Qx); dist_cam[3] = (P-Qx)*(P-Qx);
}
// plane Y=0 // plane Y=0
Geom::Vec3f Qy; Geom::Vec3f Qy;
inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(0.0f,1.0f,0.0f), Qy); inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(0.0f,1.0f,0.0f), Qy);
if (inter == Geom::FACE_INTERSECTION) if (axisPickable(Yr))
dist_target[4] = Qy.norm() - 1.0f; {
else if (inter == Geom::EDGE_INTERSECTION) if (inter == Geom::FACE_INTERSECTION)
dist_target[4] = sqrtf(dist2) - 1.0f; 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 ) if (fabs(dist_target[4]) < ring_half_width )
dist_cam[4] = (P-Qy)*(P-Qy); dist_cam[4] = (P-Qy)*(P-Qy);
}
// plane Z=0 // plane Z=0
Geom::Vec3f Qz; Geom::Vec3f Qz;
inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(0.0f,0.0f,1.0f), Qz); inter = Geom::intersectionLinePlane<Geom::Vec3f>(P,V,origin, Geom::Vec3f(0.0f,0.0f,1.0f), Qz);
if (inter == Geom::FACE_INTERSECTION) if (axisPickable(Zr))
dist_target[5] = Qz.norm() - 1.0f; {
else if (inter == Geom::EDGE_INTERSECTION) if (inter == Geom::FACE_INTERSECTION)
dist_target[5] = sqrtf(dist2) - 1.0f; dist_target[5] = Qz.norm() - 1.0f;
else if (inter == Geom::EDGE_INTERSECTION)
if (fabs(dist_target[5]) < ring_half_width ) dist_target[5] = sqrt(dist2) - 1.0f;
dist_cam[5] = (P-Qz)*(P-Qz);
if (fabs(dist_target[5]) < ring_half_width )
dist_cam[5] = (P-Qz)*(P-Qz);
}
// axes: // axes:
Geom::Vec3f PX(1.0f,0.0f,0.0f); if (axisPickable(Xt) || axisPickable(Xs))
dist_target[0] = sqrtf(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PX)) ;
if (fabs(dist_target[0]) < 0.02f)
{ {
if ( (Qz - origin).norm() > m_lengthAxes[0]) Geom::Vec3f PX(1.0f,0.0f,0.0f);
dist_cam[0] = (P-PX)*(P-PX); dist_target[0] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PX)) ;
else
dist_cam[6] = (P-origin)*(P-origin);
}
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); if (axisPickable(Yt) || axisPickable(Ys))
dist_target[1] = sqrtf(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PY)) ;
if (fabs(dist_target[1]) < 0.02f )
{ {
if ((Qz - origin).norm() > m_lengthAxes[1]) Geom::Vec3f PY(0.0f,1.0f,0.0f);
dist_cam[1] = (P-PY)*(P-PY); dist_target[1] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PY)) ;
else if (fabs(dist_target[1]) < 0.02f )
dist_cam[7] = (P-origin)*(P-origin); {
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 (axisPickable(Zt) || axisPickable(Zs))
if (fabs(dist_target[2]) < 0.02f )
{ {
if ((Qx - origin).norm() > m_lengthAxes[2]) Geom::Vec3f PZ(0.0f,0.0f,1.0f);
dist_cam[2] = (P-PZ)*(P-PZ); dist_target[2] = sqrt(Geom::squaredDistanceLine2Seg(P, V, V*V, origin, PZ));
else if (fabs(dist_target[2]) < 0.02f )
dist_cam[8] = (P-origin)*(P-origin); {
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; // find min dist_cam value;
unsigned int min_index=0; unsigned int min_index=0;
float min_val = dist_cam[0]; float min_val = dist_cam[0];
...@@ -417,7 +437,8 @@ unsigned int FrameManipulator::pick(const Geom::Vec3f& PP, const Geom::Vec3f& VV ...@@ -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 (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; return Xt+min_index;
} }
...@@ -454,13 +475,17 @@ void FrameManipulator::setLengthAxes() ...@@ -454,13 +475,17 @@ void FrameManipulator::setLengthAxes()
float sc1 = m_scale[1]/avgScale; float sc1 = m_scale[1]/avgScale;
float sc2 = m_scale[2]/avgScale; float sc2 = m_scale[2]/avgScale;
positions[ind] = 0.23f*sc0; positions[ind] = 0.23f*sc0;
ind+=7; ind+=7;
positions[ind] = 0.23f*sc1; positions[ind] = 0.23f*sc1;
ind+=7; ind+=7;
positions[ind] = 0.23f*sc2; positions[ind] = 0.23f*sc2;
ind++; ind++;
positions[ind] = 0.27f*sc0; if (m_locked_axis[Xs])
positions[ind] = 0.0f;
else
positions[ind] = 0.27f*sc0;
ind+=3; ind+=3;
positions[ind] = 0.75f*sc0; positions[ind] = 0.75f*sc0;
ind+=3; ind+=3;
...@@ -478,7 +503,10 @@ void FrameManipulator::setLengthAxes() ...@@ -478,7 +503,10 @@ void FrameManipulator::setLengthAxes()
positions[ind] = le; positions[ind] = le;
ind+=4; ind+=4;
positions[ind] = 0.27f*sc1; if (m_locked_axis[Ys])
positions[ind] = 0.0f;
else
positions[ind] = 0.27f*sc1;
ind+=3; ind+=3;
positions[ind] = 0.75f*sc1; positions[ind] = 0.75f*sc1;
ind+=3; ind+=3;
...@@ -496,7 +524,10 @@ void FrameManipulator::setLengthAxes() ...@@ -496,7 +524,10 @@ void FrameManipulator::setLengthAxes()
positions[ind] = le; positions[ind] = le;
ind+=4; ind+=4;
positions[ind] = 0.27f*sc2; if (m_locked_axis[Zs])
positions[ind] = 0.0f;
else
positions[ind] = 0.27f*sc2;
ind+=3; ind+=3;
positions[ind] = 0.75f*sc2; positions[ind] = 0.75f*sc2;
ind+=3; ind+=3;
...@@ -620,20 +651,131 @@ void FrameManipulator::setTransformation( const glm::mat4& transfo) ...@@ -620,20 +651,131 @@ void FrameManipulator::setTransformation( const glm::mat4& transfo)
void FrameManipulator::lock(unsigned int axis) 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) 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_axis[Ys] = false;
m_locked_axis[Zs] = false;
break;
default:
m_locked_axis[axis] = false;
break;
}
setLengthAxes();
} }
bool FrameManipulator::locked(unsigned int axis) bool FrameManipulator::locked(unsigned int axis)
{ {
assert(axis <=Zs);
return m_locked_axis[axis]; return m_locked_axis[axis];
} }
void FrameManipulator::lockPicking(unsigned int axis)
{
assert(axis <=Scales);
switch (axis)
{
case Translations:
m_lockedPicking_axis[Xt] = true;
m_lockedPicking_axis[Yt] = true;
m_lockedPicking_axis[Zt] = true;
break;
case Rotations:
m_lockedPicking_axis[Xr] = true;
m_lockedPicking_axis[Yr] = true;
m_lockedPicking_axis[Zr] = true;
break;
case Scales:
m_lockedPicking_axis[Xs] = true;
m_lockedPicking_axis[Ys] = true;
m_lockedPicking_axis[Zs] = true;
break;
default:
m_lockedPicking_axis[axis] = true;
break;
}
setLengthAxes();
}
void FrameManipulator::unlockPicking(unsigned int axis)
{
assert(axis <=Scales);
switch (axis)
{
case Translations:
m_lockedPicking_axis[Xt] = false;
m_lockedPicking_axis[Yt] = false;
m_lockedPicking_axis[Zt] = false;
break;
case Rotations:
m_lockedPicking_axis[Xr] = false;
m_lockedPicking_axis[Yr] = false;
m_lockedPicking_axis[Zr] = false;
break;
case Scales:
m_lockedPicking_axis[Xs] = false;
m_lockedPicking_axis[Ys] = false;
m_lockedPicking_axis[Zs] = false;
break;
default:
m_lockedPicking_axis[axis] = false;
break;
}
setLengthAxes();
}
bool FrameManipulator::lockedPicking(unsigned int axis)
{
return m_lockedPicking_axis[axis];
}
Geom::Vec3f FrameManipulator::getAxis(unsigned int ax) Geom::Vec3f FrameManipulator::getAxis(unsigned int ax)
{ {
unsigned int i = (ax-Xt)%3; unsigned int i = (ax-Xt)%3;
...@@ -726,7 +868,7 @@ void FrameManipulator::rotateInScreen(int dx, int dy) ...@@ -726,7 +868,7 @@ void FrameManipulator::rotateInScreen(int dx, int dy)
Geom::Vec3f axisRotation(P[0]-m_trans[0], P[1]-m_trans[1], P[2]-m_trans[2]); Geom::Vec3f axisRotation(P[0]-m_trans[0], P[1]-m_trans[1], P[2]-m_trans[2]);
axisRotation.normalize(); axisRotation.normalize();
glm::mat4 tr = glm::rotate(glm::mat4(1.0f),float(sqrtf(dx*dx+dy*dy))/2.0f,glm::vec3(axisRotation[0],axisRotation[1],axisRotation[2])); glm::mat4 tr = glm::rotate(glm::mat4(1.0f),float(sqrt(dx*dx+dy*dy))/2.0f,glm::vec3(axisRotation[0],axisRotation[1],axisRotation[2]));
m_rotations = tr*m_rotations;