Commit 5c229ffd authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps: allow to enable/disable camera fitting to views bounding box

parent 8d7b97a3
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "Algo/Topo/basic.h" #include "Algo/Topo/basic.h"
#include "camera.h"
#include <QKeyEvent> #include <QKeyEvent>
#include <QMouseEvent> #include <QMouseEvent>
...@@ -153,6 +155,7 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event) ...@@ -153,6 +155,7 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event)
m_dragging = true; m_dragging = true;
m_draginit = false; m_draginit = false;
view->setMouseTracking(true); view->setMouseTracking(true);
view->getCurrentCamera()->disableViewsBoundingBoxFitting();
} }
} }
else else
...@@ -160,6 +163,7 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event) ...@@ -160,6 +163,7 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event)
m_dragging = false; m_dragging = false;
m_draginit = false; m_draginit = false;
view->setMouseTracking(false); view->setMouseTracking(false);
view->getCurrentCamera()->enableViewsBoundingBoxFitting();
} }
} }
break; break;
...@@ -184,17 +188,17 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event) ...@@ -184,17 +188,17 @@ void Surface_Deformation_Plugin::keyPress(View* view, QKeyEvent* event)
void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event) void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event)
{ {
if(m_dragging) if (m_dragging)
{ {
MapHandlerGen* mh = m_schnapps->getSelectedMap(); MapHandlerGen* mh = m_schnapps->getSelectedMap();
MapParameters& p = h_parameterSet[mh]; MapParameters& p = h_parameterSet[mh];
const std::vector<Vertex>& handle = p.handleSelector->getSelectedCells(); const std::vector<Vertex>& handle = p.handleSelector->getSelectedCells();
if(!m_draginit) if (!m_draginit)
{ {
m_dragZ = 0; m_dragZ = 0;
for(std::vector<Vertex>::const_iterator it = handle.begin(); it != handle.end(); ++it) for (std::vector<Vertex>::const_iterator it = handle.begin(); it != handle.end(); ++it)
{ {
const PFP2::VEC3& pp = p.positionAttribute[*it]; const PFP2::VEC3& pp = p.positionAttribute[*it];
qglviewer::Vec q = view->camera()->projectedCoordinatesOf(qglviewer::Vec(pp[0],pp[1],pp[2])); qglviewer::Vec q = view->camera()->projectedCoordinatesOf(qglviewer::Vec(pp[0],pp[1],pp[2]));
...@@ -214,13 +218,13 @@ void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event) ...@@ -214,13 +218,13 @@ void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event)
qglviewer::Vec vec = qq - m_dragPrevious; qglviewer::Vec vec = qq - m_dragPrevious;
PFP2::VEC3 t(vec.x, vec.y, vec.z); PFP2::VEC3 t(vec.x, vec.y, vec.z);
for(std::vector<Vertex>::const_iterator it = handle.begin(); it != handle.end(); ++it) for (std::vector<Vertex>::const_iterator it = handle.begin(); it != handle.end(); ++it)
p.positionAttribute[*it] += t; p.positionAttribute[*it] += t;
m_dragPrevious = qq; m_dragPrevious = qq;
// matchDiffCoord(map); // matchDiffCoord(map);
if(p.initialized) if (p.initialized)
{ {
asRigidAsPossible(mh); asRigidAsPossible(mh);
mh->notifyAttributeModification(p.positionAttribute); mh->notifyAttributeModification(p.positionAttribute);
......
...@@ -37,8 +37,8 @@ public slots: ...@@ -37,8 +37,8 @@ public slots:
bool isShared() const { return l_views.size() > 1; } bool isShared() const { return l_views.size() > 1; }
qglviewer::Camera::Type getProjectionType() { return type(); } qglviewer::Camera::Type getProjectionType() { return type(); }
bool getDraw() const { return m_draw; } bool getDraw() const { return b_draw; }
bool getDrawPath() const { return m_drawPath; } bool getDrawPath() const { return b_drawPath; }
const QList<View*>& getLinkedViews() const { return l_views; } const QList<View*>& getLinkedViews() const { return l_views; }
bool isLinkedToView(View* view) const { return l_views.contains(view); } bool isLinkedToView(View* view) const { return l_views.contains(view); }
...@@ -47,13 +47,16 @@ public slots: ...@@ -47,13 +47,16 @@ public slots:
void setDraw(bool b); void setDraw(bool b);
void setDrawPath(bool b); void setDrawPath(bool b);
void enableViewsBoundingBoxFitting() { b_fitToViewsBoundingBox = true; }
void disableViewsBoundingBoxFitting() { b_fitToViewsBoundingBox = false; }
private: private:
void linkView(View* view); void linkView(View* view);
void unlinkView(View* view); void unlinkView(View* view);
private slots: private slots:
void frameModified(); void frameModified();
void updateParams(); void fitToViewsBoundingBox();
signals: signals:
void projectionTypeChanged(int); void projectionTypeChanged(int);
...@@ -66,8 +69,10 @@ protected: ...@@ -66,8 +69,10 @@ protected:
QList<View*> l_views; QList<View*> l_views;
bool m_draw; bool b_draw;
bool m_drawPath; bool b_drawPath;
bool b_fitToViewsBoundingBox;
}; };
} // namespace SCHNApps } // namespace SCHNApps
......
...@@ -50,19 +50,13 @@ public slots: ...@@ -50,19 +50,13 @@ public slots:
GenericMap* getGenericMap() const { return m_map; } GenericMap* getGenericMap() const { return m_map; }
const QList<View*>& getLinkedViews() const { return l_views; } /*********************************************************
bool isLinkedToView(View* view) const { return l_views.contains(view); } * MANAGE FRAME
*********************************************************/
float getBBdiagSize() const { return m_bbDiagSize; }
Utils::GLSLShader* getBBDrawerShader() const
{
if(m_bbDrawer)
return m_bbDrawer->getShader();
else
return NULL;
}
public slots:
qglviewer::ManipulatedFrame* getFrame() const { return m_frame; } qglviewer::ManipulatedFrame* getFrame() const { return m_frame; }
glm::mat4 getFrameMatrix() const glm::mat4 getFrameMatrix() const
{ {
GLdouble m[16]; GLdouble m[16];
...@@ -76,19 +70,27 @@ public slots: ...@@ -76,19 +70,27 @@ public slots:
return matrix; return matrix;
} }
private slots:
void frameModified() void frameModified()
{ {
DEBUG_EMIT("frameModified"); DEBUG_EMIT("frameModified");
emit(boundingBoxModified()); emit(boundingBoxModified());
} }
/*********************************************************
* MANAGE BOUNDING BOX
*********************************************************/
public slots:
void setBBVertexAttribute(const QString& name) void setBBVertexAttribute(const QString& name)
{ {
m_bbVertexAttribute = m_map->getAttributeVectorGen(VERTEX, name.toStdString()); m_bbVertexAttribute = m_map->getAttributeVectorGen(VERTEX, name.toStdString());
updateBB(); updateBB();
} }
AttributeMultiVectorGen* getBBVertexAttribute() { return m_bbVertexAttribute; }
QString getBBVertexAttributeName() AttributeMultiVectorGen* getBBVertexAttribute() const { return m_bbVertexAttribute; }
QString getBBVertexAttributeName() const
{ {
if (m_bbVertexAttribute) if (m_bbVertexAttribute)
return QString::fromStdString(m_bbVertexAttribute->getName()); return QString::fromStdString(m_bbVertexAttribute->getName());
...@@ -96,15 +98,29 @@ public slots: ...@@ -96,15 +98,29 @@ public slots:
return QString(); return QString();
} }
public: float getBBdiagSize() const { return m_bbDiagSize; }
virtual void draw(Utils::GLSLShader* shader, int primitive) = 0;
virtual void drawBB() = 0; Utils::GLSLShader* getBBDrawerShader() const
{
if(m_bbDrawer)
return m_bbDrawer->getShader();
else
return NULL;
}
virtual void transformedBB(qglviewer::Vec& bbMin, qglviewer::Vec& bbMax) = 0; virtual void transformedBB(qglviewer::Vec& bbMin, qglviewer::Vec& bbMax) = 0;
protected: protected:
virtual void updateBB() = 0; virtual void updateBB() = 0;
/*********************************************************
* MANAGE DRAWING
*********************************************************/
public: public:
virtual void draw(Utils::GLSLShader* shader, int primitive) = 0;
virtual void drawBB() = 0;
void setPrimitiveDirty(int primitive) { m_render->setPrimitiveDirty(primitive); } void setPrimitiveDirty(int primitive) { m_render->setPrimitiveDirty(primitive); }
/********************************************************* /*********************************************************
...@@ -171,11 +187,15 @@ private: ...@@ -171,11 +187,15 @@ private:
void linkView(View* view); void linkView(View* view);
void unlinkView(View* view); void unlinkView(View* view);
public slots:
const QList<View*>& getLinkedViews() const { return l_views; }
bool isLinkedToView(View* view) const { return l_views.contains(view); }
/********************************************************* /*********************************************************
* MANAGE TOPO_RENDERING * MANAGE TOPO_RENDERING
*********************************************************/ *********************************************************/
public:
public:
virtual void createTopoRender(CGoGN::Utils::GLSLShader* s) = 0; virtual void createTopoRender(CGoGN::Utils::GLSLShader* s) = 0;
void deleteTopoRender(); void deleteTopoRender();
virtual void updateTopoRender(const QString& positionAttributeName) = 0; virtual void updateTopoRender(const QString& positionAttributeName) = 0;
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include <QMap> #include <QMap>
#include <QString> #include <QString>
#include "Topology/generic/parameters.h" #include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Topology/generic/attributeHandler.h"
#include "Topology/map/embeddedMap2.h" #include "Topology/map/embeddedMap2.h"
#include "Topology/map/embeddedMap3.h" #include "Topology/map/embeddedMap3.h"
...@@ -17,12 +19,28 @@ class VBO; ...@@ -17,12 +19,28 @@ class VBO;
class GLSLShader; class GLSLShader;
} }
struct PFP2: public PFP_STANDARD struct PFP_SCHNAPPS
{
typedef float REAL;
typedef Geom::Vector<3,REAL> VEC3;
typedef Geom::Vector<4,REAL> VEC4;
typedef Geom::Vector<6,REAL> VEC6;
typedef Geom::Matrix<3,3,REAL> MATRIX33;
typedef Geom::Matrix<4,4,REAL> MATRIX44;
typedef Geom::Matrix<3,6,REAL> MATRIX36;
static inline Geom::Vec3f toVec3f(const VEC3& P)
{
return P;
}
};
struct PFP2 : public PFP_SCHNAPPS
{ {
typedef EmbeddedMap2 MAP; typedef EmbeddedMap2 MAP;
}; };
struct PFP3: public PFP_STANDARD struct PFP3 : public PFP_SCHNAPPS
{ {
typedef EmbeddedMap3 MAP; typedef EmbeddedMap3 MAP;
}; };
...@@ -39,7 +57,6 @@ class Camera; ...@@ -39,7 +57,6 @@ class Camera;
class MapHandlerGen; class MapHandlerGen;
class CellSelectorGen; class CellSelectorGen;
struct Texture; struct Texture;
class ObjectHandlerGen;
typedef QMap<QString, Plugin*> PluginSet; typedef QMap<QString, Plugin*> PluginSet;
typedef QMap<QString, View*> ViewSet; typedef QMap<QString, View*> ViewSet;
...@@ -49,11 +66,8 @@ typedef QMap<QString, Utils::VBO*> VBOSet; ...@@ -49,11 +66,8 @@ typedef QMap<QString, Utils::VBO*> VBOSet;
typedef QMap<QString, QString> AttributeSet; typedef QMap<QString, QString> AttributeSet;
typedef QMap<QString, CellSelectorGen*> CellSelectorSet; typedef QMap<QString, CellSelectorGen*> CellSelectorSet;
typedef QMap<QString, Utils::GLSLShader*> ShaderSet; typedef QMap<QString, Utils::GLSLShader*> ShaderSet;
typedef QMap<QString, Texture*> TextureSet; typedef QMap<QString, Texture*> TextureSet;
typedef QMap<QString, ObjectHandlerGen*> ObjectSet;
} // namespace SCHNApps } // namespace SCHNApps
} // namespace CGoGN } // namespace CGoGN
......
...@@ -14,8 +14,9 @@ unsigned int Camera::cameraCount = 0; ...@@ -14,8 +14,9 @@ unsigned int Camera::cameraCount = 0;
Camera::Camera(const QString& name, SCHNApps* s) : Camera::Camera(const QString& name, SCHNApps* s) :
m_name(name), m_name(name),
m_schnapps(s), m_schnapps(s),
m_draw(false), b_draw(false),
m_drawPath(false) b_drawPath(false),
b_fitToViewsBoundingBox(true)
{ {
++cameraCount; ++cameraCount;
connect(this->frame(), SIGNAL(modified()), this, SLOT(frameModified())); connect(this->frame(), SIGNAL(modified()), this, SLOT(frameModified()));
...@@ -35,7 +36,7 @@ void Camera::setProjectionType(int t) ...@@ -35,7 +36,7 @@ void Camera::setProjectionType(int t)
void Camera::setDraw(bool b) void Camera::setDraw(bool b)
{ {
m_draw = b; b_draw = b;
DEBUG_EMIT("drawChanged"); DEBUG_EMIT("drawChanged");
emit(drawChanged(b)); emit(drawChanged(b));
foreach(View* view, m_schnapps->getViewSet().values()) foreach(View* view, m_schnapps->getViewSet().values())
...@@ -44,7 +45,7 @@ void Camera::setDraw(bool b) ...@@ -44,7 +45,7 @@ void Camera::setDraw(bool b)
void Camera::setDrawPath(bool b) void Camera::setDrawPath(bool b)
{ {
m_drawPath = b; b_drawPath = b;
DEBUG_EMIT("drawPathChanged"); DEBUG_EMIT("drawPathChanged");
emit(drawPathChanged(b)); emit(drawPathChanged(b));
foreach(View* view, m_schnapps->getViewSet().values()) foreach(View* view, m_schnapps->getViewSet().values())
...@@ -56,8 +57,8 @@ void Camera::linkView(View* view) ...@@ -56,8 +57,8 @@ void Camera::linkView(View* view)
if(view && !l_views.contains(view)) if(view && !l_views.contains(view))
{ {
l_views.push_back(view); l_views.push_back(view);
updateParams(); fitToViewsBoundingBox();
connect(view, SIGNAL(boundingBoxChanged()), this, SLOT(updateParams())); connect(view, SIGNAL(boundingBoxChanged()), this, SLOT(fitToViewsBoundingBox()));
} }
} }
...@@ -65,14 +66,14 @@ void Camera::unlinkView(View* view) ...@@ -65,14 +66,14 @@ void Camera::unlinkView(View* view)
{ {
if (l_views.removeOne(view)) if (l_views.removeOne(view))
{ {
updateParams(); fitToViewsBoundingBox();
disconnect(view, SIGNAL(boundingBoxChanged()), this, SLOT(updateParams())); disconnect(view, SIGNAL(boundingBoxChanged()), this, SLOT(fitToViewsBoundingBox()));
} }
} }
void Camera::frameModified() void Camera::frameModified()
{ {
if(m_draw || m_drawPath) if(b_draw || b_drawPath)
{ {
foreach(View* view, m_schnapps->getViewSet().values()) foreach(View* view, m_schnapps->getViewSet().values())
view->updateGL(); view->updateGL();
...@@ -84,37 +85,40 @@ void Camera::frameModified() ...@@ -84,37 +85,40 @@ void Camera::frameModified()
} }
} }
void Camera::updateParams() void Camera::fitToViewsBoundingBox()
{ {
qglviewer::Vec bbMin; if (b_fitToViewsBoundingBox)
qglviewer::Vec bbMax;
if (!l_views.empty())
{ {
l_views.first()->getBB(bbMin, bbMax); qglviewer::Vec bbMin;
qglviewer::Vec bbMax;
foreach(View* v, l_views) if (!l_views.empty())
{ {
qglviewer::Vec minbb; l_views.first()->getBB(bbMin, bbMax);
qglviewer::Vec maxbb;
v->getBB(minbb, maxbb); foreach(View* v, l_views)
for(unsigned int dim = 0; dim < 3; ++dim)
{ {
if(minbb[dim] < bbMin[dim]) qglviewer::Vec minbb;
bbMin[dim] = minbb[dim]; qglviewer::Vec maxbb;
if(maxbb[dim] > bbMax[dim]) v->getBB(minbb, maxbb);
bbMax[dim] = maxbb[dim]; for(unsigned int dim = 0; dim < 3; ++dim)
{
if(minbb[dim] < bbMin[dim])
bbMin[dim] = minbb[dim];
if(maxbb[dim] > bbMax[dim])
bbMax[dim] = maxbb[dim];
}
} }
} }
} else
else {
{ bbMin.setValue(0, 0, 0);
bbMin.setValue(0, 0, 0); bbMax.setValue(0, 0, 0);
bbMax.setValue(0, 0, 0); }
}
this->setSceneBoundingBox(bbMin, bbMax); this->setSceneBoundingBox(bbMin, bbMax);
this->showEntireScene(); this->showEntireScene();
}
} }
} // namespace SCHNApps } // namespace SCHNApps
......
...@@ -289,7 +289,7 @@ void ControlDock_MapTab::updateSelectedMapInfo() ...@@ -289,7 +289,7 @@ void ControlDock_MapTab::updateSelectedMapInfo()
combo_bbVertexAttribute->clear(); combo_bbVertexAttribute->clear();
combo_bbVertexAttribute->addItem("- select attribute -"); combo_bbVertexAttribute->addItem("- select attribute -");
QString vec3TypeName = QString::fromStdString(nameOfType(PFP_STANDARD::VEC3())); QString vec3TypeName = QString::fromStdString(nameOfType(PFP_SCHNAPPS::VEC3()));
list_dartAttributes->clear(); list_dartAttributes->clear();
list_vertexAttributes->clear(); list_vertexAttributes->clear();
......
...@@ -201,7 +201,7 @@ void View::setCurrentCamera(Camera* c) ...@@ -201,7 +201,7 @@ void View::setCurrentCamera(Camera* c)
} }
} }
m_currentCamera->updateParams(); m_currentCamera->fitToViewsBoundingBox();
updateGL(); updateGL();
} }
} }
......
...@@ -43,10 +43,10 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIC") ...@@ -43,10 +43,10 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fPIC")
#SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}${BINARIES_RELATIVE_PATH}) #SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}${BINARIES_RELATIVE_PATH})
IF (EXISTS ${CMAKE_SOURCE_DIR}/OpenNL/CMakeOptions.txt) IF (EXISTS ${CMAKE_SOURCE_DIR}/ThirdParty/OpenNL/CMakeOptions.txt)
MESSAGE(INFO: "Using local options file: " ${CMAKE_SOURCE_DIR}/OpenNL/CMakeOptions.txt) MESSAGE(INFO: "Using local options file: " ${CMAKE_SOURCE_DIR}/ThirdParty/OpenNL/CMakeOptions.txt)
INCLUDE(${CMAKE_SOURCE_DIR}/OpenNL/CMakeOptions.txt) INCLUDE(${CMAKE_SOURCE_DIR}/ThirdParty/OpenNL/CMakeOptions.txt)
ENDIF(EXISTS ${CMAKE_SOURCE_DIR}/OpenNL/CMakeOptions.txt) ENDIF(EXISTS ${CMAKE_SOURCE_DIR}/ThirdParty/OpenNL/CMakeOptions.txt)
IF(USE_CNC) IF(USE_CNC)
ADD_DEFINITIONS(-DNL_USE_CNC) ADD_DEFINITIONS(-DNL_USE_CNC)
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
# plateforms. # plateforms.
################################################################## ##################################################################
SET(CMAKE_MODULE_PATH ${CGoGN_ROOT_DIR}/cmake_modules) SET(CMAKE_MODULE_PATH ${CGoGN_ROOT_DIR}/cmake_modules)
# build exemple programs # build exemple programs
...@@ -69,6 +68,7 @@ SET(USE_CHOLMOD TRUE) ...@@ -69,6 +68,7 @@ SET(USE_CHOLMOD TRUE)
IF (NOT WIN32) IF (NOT WIN32)
find_package(SuiteSparse REQUIRED) find_package(SuiteSparse REQUIRED)
ENDIF (NOT WIN32) ENDIF (NOT WIN32)
########### ###########
# CNC # CNC
########### ###########
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment