|
@@ -5,11 +5,11 @@
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public License
|
|
|
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
-#ifndef IGL_MOUSECONTROLLER_H
|
|
|
-#define IGL_MOUSECONTROLLER_H
|
|
|
+#ifndef IGL_OPENGL2_MOUSECONTROLLER_H
|
|
|
+#define IGL_OPENGL2_MOUSECONTROLLER_H
|
|
|
// Needs to be included before others
|
|
|
#include <Eigen/StdVector>
|
|
|
-#include <igl/RotateWidget.h>
|
|
|
+#include "RotateWidget.h"
|
|
|
#include <Eigen/Core>
|
|
|
#include <Eigen/Geometry>
|
|
|
#include <vector>
|
|
@@ -17,135 +17,138 @@
|
|
|
// Class for control a skeletal FK rig with the mouse.
|
|
|
namespace igl
|
|
|
{
|
|
|
- class MouseController
|
|
|
+ namespace opengl2
|
|
|
{
|
|
|
- public:
|
|
|
- typedef Eigen::VectorXi VectorXb;
|
|
|
- // Propogate selection to descendants so that selected bones and their
|
|
|
- // subtrees are all selected.
|
|
|
- //
|
|
|
- // Input:
|
|
|
- // S #S list of whether selected
|
|
|
- // P #S list of bone parents
|
|
|
- // Output:
|
|
|
- // T #S list of whether selected
|
|
|
- static inline void propogate_to_descendants_if(
|
|
|
- const VectorXb & S,
|
|
|
- const Eigen::VectorXi & P,
|
|
|
- VectorXb & T);
|
|
|
- // Create a matrix of colors for the selection and their descendants.
|
|
|
- //
|
|
|
- // Inputs:
|
|
|
- // selection #S list of whether a bone is selected
|
|
|
- // selected_color color for selected bones
|
|
|
- // unselected_color color for unselected bones
|
|
|
- // Outputs:
|
|
|
- // C #P by 4 list of colors
|
|
|
- static inline void color_if(
|
|
|
- const VectorXb & S,
|
|
|
- const Eigen::Vector4f & selected_color,
|
|
|
- const Eigen::Vector4f & unselected_color,
|
|
|
- Eigen::MatrixXf & C);
|
|
|
- private:
|
|
|
- // m_is_selecting whether currently selecting
|
|
|
- // m_selection #m_rotations list of whether a bone is selected
|
|
|
- // m_down_x x-coordinate of mouse location at down
|
|
|
- // m_down_y y-coordinate 〃
|
|
|
- // m_drag_x x-coordinate of mouse location at drag
|
|
|
- // m_drag_y y-coordinate 〃
|
|
|
- // m_widget rotation widget for selected bone
|
|
|
- // m_width width of containing window
|
|
|
- // m_height height 〃
|
|
|
- // m_rotations list of rotations for each bone
|
|
|
- // m_rotations_at_selection list of rotations for each bone at time of
|
|
|
- // selection
|
|
|
- // m_fk_rotations_at_selection list of rotations for each bone at time of
|
|
|
- // selection
|
|
|
- // m_root_enabled Whether root is enabled
|
|
|
- bool m_is_selecting;
|
|
|
- VectorXb m_selection;
|
|
|
- int m_down_x,m_down_y,m_drag_x,m_drag_y;
|
|
|
- int m_width,m_height;
|
|
|
- igl::RotateWidget m_widget;
|
|
|
- Eigen::Quaterniond m_widget_rot_at_selection;
|
|
|
- typedef std::vector<
|
|
|
- Eigen::Quaterniond,
|
|
|
- Eigen::aligned_allocator<Eigen::Quaterniond> > RotationList;
|
|
|
- RotationList
|
|
|
- m_rotations,m_rotations_at_selection,m_fk_rotations_at_selection;
|
|
|
- bool m_root_enabled;
|
|
|
- public:
|
|
|
- MouseController();
|
|
|
- // Returns const reference to m_selection
|
|
|
- inline const VectorXb & selection() const{return m_selection;};
|
|
|
- // 〃 m_is_selecting
|
|
|
- inline const bool & is_selecting() const{return m_is_selecting;}
|
|
|
- inline bool is_widget_down() const{return m_widget.is_down();}
|
|
|
- // 〃 m_rotations
|
|
|
- inline const RotationList & rotations() const{return m_rotations;}
|
|
|
- // Returns non-const reference to m_root_enabled
|
|
|
- inline bool & root_enabled(){ return m_root_enabled;}
|
|
|
- inline void reshape(const int w, const int h);
|
|
|
- // Process down, drag, up mouse events
|
|
|
- //
|
|
|
- // Inputs:
|
|
|
- // x x-coordinate of mouse click with respect to container
|
|
|
- // y y-coordinate 〃
|
|
|
- // Returns true if accepted (action taken).
|
|
|
- inline bool down(const int x, const int y);
|
|
|
- inline bool drag(const int x, const int y);
|
|
|
- inline bool up(const int x, const int y);
|
|
|
- // Draw selection box and widget
|
|
|
- inline void draw() const;
|
|
|
- // Set `m_selection` based on the last drag selection and initialize
|
|
|
- // widget.
|
|
|
- //
|
|
|
- // Inputs:
|
|
|
- // C #C by dim list of joint positions at rest
|
|
|
- // BE #BE by 2 list of bone indices at rest
|
|
|
- // P #P list of bone parents
|
|
|
- inline void set_selection_from_last_drag(
|
|
|
- const Eigen::MatrixXd & C,
|
|
|
- const Eigen::MatrixXi & BE,
|
|
|
- const Eigen::VectorXi & P,
|
|
|
- const Eigen::VectorXi & RP);
|
|
|
- // Set from explicit selection
|
|
|
- inline void set_selection(
|
|
|
- const Eigen::VectorXi & S,
|
|
|
- const Eigen::MatrixXd & C,
|
|
|
- const Eigen::MatrixXi & BE,
|
|
|
- const Eigen::VectorXi & P,
|
|
|
- const Eigen::VectorXi & RP);
|
|
|
- // Set size of skeleton
|
|
|
- //
|
|
|
- // Inputs:
|
|
|
- // n number of bones
|
|
|
- inline void set_size(const int n);
|
|
|
- // Resets m_rotation elements to identity
|
|
|
- inline void reset_rotations();
|
|
|
- inline void reset_selected_rotations();
|
|
|
- inline bool set_rotations(const RotationList & vQ);
|
|
|
- // Sets all entries in m_selection to false
|
|
|
- inline void clear_selection();
|
|
|
- // Returns true iff some element in m_selection is true
|
|
|
- inline bool any_selection() const;
|
|
|
- public:
|
|
|
- EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
|
|
- };
|
|
|
+ class MouseController
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ typedef Eigen::VectorXi VectorXb;
|
|
|
+ // Propogate selection to descendants so that selected bones and their
|
|
|
+ // subtrees are all selected.
|
|
|
+ //
|
|
|
+ // Input:
|
|
|
+ // S #S list of whether selected
|
|
|
+ // P #S list of bone parents
|
|
|
+ // Output:
|
|
|
+ // T #S list of whether selected
|
|
|
+ static inline void propogate_to_descendants_if(
|
|
|
+ const VectorXb & S,
|
|
|
+ const Eigen::VectorXi & P,
|
|
|
+ VectorXb & T);
|
|
|
+ // Create a matrix of colors for the selection and their descendants.
|
|
|
+ //
|
|
|
+ // Inputs:
|
|
|
+ // selection #S list of whether a bone is selected
|
|
|
+ // selected_color color for selected bones
|
|
|
+ // unselected_color color for unselected bones
|
|
|
+ // Outputs:
|
|
|
+ // C #P by 4 list of colors
|
|
|
+ static inline void color_if(
|
|
|
+ const VectorXb & S,
|
|
|
+ const Eigen::Vector4f & selected_color,
|
|
|
+ const Eigen::Vector4f & unselected_color,
|
|
|
+ Eigen::MatrixXf & C);
|
|
|
+ private:
|
|
|
+ // m_is_selecting whether currently selecting
|
|
|
+ // m_selection #m_rotations list of whether a bone is selected
|
|
|
+ // m_down_x x-coordinate of mouse location at down
|
|
|
+ // m_down_y y-coordinate 〃
|
|
|
+ // m_drag_x x-coordinate of mouse location at drag
|
|
|
+ // m_drag_y y-coordinate 〃
|
|
|
+ // m_widget rotation widget for selected bone
|
|
|
+ // m_width width of containing window
|
|
|
+ // m_height height 〃
|
|
|
+ // m_rotations list of rotations for each bone
|
|
|
+ // m_rotations_at_selection list of rotations for each bone at time of
|
|
|
+ // selection
|
|
|
+ // m_fk_rotations_at_selection list of rotations for each bone at time of
|
|
|
+ // selection
|
|
|
+ // m_root_enabled Whether root is enabled
|
|
|
+ bool m_is_selecting;
|
|
|
+ VectorXb m_selection;
|
|
|
+ int m_down_x,m_down_y,m_drag_x,m_drag_y;
|
|
|
+ int m_width,m_height;
|
|
|
+ igl::opengl2::RotateWidget m_widget;
|
|
|
+ Eigen::Quaterniond m_widget_rot_at_selection;
|
|
|
+ typedef std::vector<
|
|
|
+ Eigen::Quaterniond,
|
|
|
+ Eigen::aligned_allocator<Eigen::Quaterniond> > RotationList;
|
|
|
+ RotationList
|
|
|
+ m_rotations,m_rotations_at_selection,m_fk_rotations_at_selection;
|
|
|
+ bool m_root_enabled;
|
|
|
+ public:
|
|
|
+ MouseController();
|
|
|
+ // Returns const reference to m_selection
|
|
|
+ inline const VectorXb & selection() const{return m_selection;};
|
|
|
+ // 〃 m_is_selecting
|
|
|
+ inline const bool & is_selecting() const{return m_is_selecting;}
|
|
|
+ inline bool is_widget_down() const{return m_widget.is_down();}
|
|
|
+ // 〃 m_rotations
|
|
|
+ inline const RotationList & rotations() const{return m_rotations;}
|
|
|
+ // Returns non-const reference to m_root_enabled
|
|
|
+ inline bool & root_enabled(){ return m_root_enabled;}
|
|
|
+ inline void reshape(const int w, const int h);
|
|
|
+ // Process down, drag, up mouse events
|
|
|
+ //
|
|
|
+ // Inputs:
|
|
|
+ // x x-coordinate of mouse click with respect to container
|
|
|
+ // y y-coordinate 〃
|
|
|
+ // Returns true if accepted (action taken).
|
|
|
+ inline bool down(const int x, const int y);
|
|
|
+ inline bool drag(const int x, const int y);
|
|
|
+ inline bool up(const int x, const int y);
|
|
|
+ // Draw selection box and widget
|
|
|
+ inline void draw() const;
|
|
|
+ // Set `m_selection` based on the last drag selection and initialize
|
|
|
+ // widget.
|
|
|
+ //
|
|
|
+ // Inputs:
|
|
|
+ // C #C by dim list of joint positions at rest
|
|
|
+ // BE #BE by 2 list of bone indices at rest
|
|
|
+ // P #P list of bone parents
|
|
|
+ inline void set_selection_from_last_drag(
|
|
|
+ const Eigen::MatrixXd & C,
|
|
|
+ const Eigen::MatrixXi & BE,
|
|
|
+ const Eigen::VectorXi & P,
|
|
|
+ const Eigen::VectorXi & RP);
|
|
|
+ // Set from explicit selection
|
|
|
+ inline void set_selection(
|
|
|
+ const Eigen::VectorXi & S,
|
|
|
+ const Eigen::MatrixXd & C,
|
|
|
+ const Eigen::MatrixXi & BE,
|
|
|
+ const Eigen::VectorXi & P,
|
|
|
+ const Eigen::VectorXi & RP);
|
|
|
+ // Set size of skeleton
|
|
|
+ //
|
|
|
+ // Inputs:
|
|
|
+ // n number of bones
|
|
|
+ inline void set_size(const int n);
|
|
|
+ // Resets m_rotation elements to identity
|
|
|
+ inline void reset_rotations();
|
|
|
+ inline void reset_selected_rotations();
|
|
|
+ inline bool set_rotations(const RotationList & vQ);
|
|
|
+ // Sets all entries in m_selection to false
|
|
|
+ inline void clear_selection();
|
|
|
+ // Returns true iff some element in m_selection is true
|
|
|
+ inline bool any_selection() const;
|
|
|
+ public:
|
|
|
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Implementation
|
|
|
-#include <igl/line_segment_in_rectangle.h>
|
|
|
-#include <igl/draw_rectangular_marquee.h>
|
|
|
-#include <igl/project.h>
|
|
|
-#include <igl/forward_kinematics.h>
|
|
|
-#include <igl/matlab_format.h>
|
|
|
-#include <igl/any_of.h>
|
|
|
+#include "../line_segment_in_rectangle.h"
|
|
|
+#include "draw_rectangular_marquee.h"
|
|
|
+#include "project.h"
|
|
|
+#include "../forward_kinematics.h"
|
|
|
+#include "../matlab_format.h"
|
|
|
+#include "../any_of.h"
|
|
|
#include <iostream>
|
|
|
#include <algorithm>
|
|
|
#include <functional>
|
|
|
|
|
|
-inline void igl::MouseController::propogate_to_descendants_if(
|
|
|
+inline void igl::opengl2::MouseController::propogate_to_descendants_if(
|
|
|
const VectorXb & S,
|
|
|
const Eigen::VectorXi & P,
|
|
|
VectorXb & T)
|
|
@@ -179,7 +182,7 @@ inline void igl::MouseController::propogate_to_descendants_if(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-inline void igl::MouseController::color_if(
|
|
|
+inline void igl::opengl2::MouseController::color_if(
|
|
|
const VectorXb & S,
|
|
|
const Eigen::Vector4f & selected_color,
|
|
|
const Eigen::Vector4f & unselected_color,
|
|
@@ -192,7 +195,7 @@ inline void igl::MouseController::color_if(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-inline igl::MouseController::MouseController():
|
|
|
+inline igl::opengl2::MouseController::MouseController():
|
|
|
m_is_selecting(false),
|
|
|
m_selection(),
|
|
|
m_down_x(-1),m_down_y(-1),m_drag_x(-1),m_drag_y(-1),
|
|
@@ -205,13 +208,13 @@ inline igl::MouseController::MouseController():
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-inline void igl::MouseController::reshape(const int w, const int h)
|
|
|
+inline void igl::opengl2::MouseController::reshape(const int w, const int h)
|
|
|
{
|
|
|
m_width = w;
|
|
|
m_height = h;
|
|
|
}
|
|
|
|
|
|
-inline bool igl::MouseController::down(const int x, const int y)
|
|
|
+inline bool igl::opengl2::MouseController::down(const int x, const int y)
|
|
|
{
|
|
|
using namespace std;
|
|
|
m_down_x = m_drag_x =x;
|
|
@@ -224,7 +227,7 @@ inline bool igl::MouseController::down(const int x, const int y)
|
|
|
return m_is_selecting || widget_down;
|
|
|
}
|
|
|
|
|
|
-inline bool igl::MouseController::drag(const int x, const int y)
|
|
|
+inline bool igl::opengl2::MouseController::drag(const int x, const int y)
|
|
|
{
|
|
|
using namespace std;
|
|
|
using namespace Eigen;
|
|
@@ -281,14 +284,14 @@ inline bool igl::MouseController::drag(const int x, const int y)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-inline bool igl::MouseController::up(const int x, const int y)
|
|
|
+inline bool igl::opengl2::MouseController::up(const int x, const int y)
|
|
|
{
|
|
|
m_is_selecting = false;
|
|
|
m_widget.up(x,m_height-y);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-inline void igl::MouseController::draw() const
|
|
|
+inline void igl::opengl2::MouseController::draw() const
|
|
|
{
|
|
|
using namespace igl;
|
|
|
if(any_selection())
|
|
@@ -331,7 +334,7 @@ inline void igl::MouseController::draw() const
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-inline void igl::MouseController::set_selection_from_last_drag(
|
|
|
+inline void igl::opengl2::MouseController::set_selection_from_last_drag(
|
|
|
const Eigen::MatrixXd & C,
|
|
|
const Eigen::MatrixXi & BE,
|
|
|
const Eigen::VectorXi & P,
|
|
@@ -368,7 +371,7 @@ inline void igl::MouseController::set_selection_from_last_drag(
|
|
|
return set_selection(m_selection,C,BE,P,RP);
|
|
|
}
|
|
|
|
|
|
-inline void igl::MouseController::set_selection(
|
|
|
+inline void igl::opengl2::MouseController::set_selection(
|
|
|
const Eigen::VectorXi & S,
|
|
|
const Eigen::MatrixXd & C,
|
|
|
const Eigen::MatrixXi & BE,
|
|
@@ -484,7 +487,7 @@ inline void igl::MouseController::set_selection(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-inline void igl::MouseController::set_size(const int n)
|
|
|
+inline void igl::opengl2::MouseController::set_size(const int n)
|
|
|
{
|
|
|
using namespace Eigen;
|
|
|
clear_selection();
|
|
@@ -493,7 +496,7 @@ inline void igl::MouseController::set_size(const int n)
|
|
|
m_selection = VectorXb::Zero(n);
|
|
|
}
|
|
|
|
|
|
-inline void igl::MouseController::reset_rotations()
|
|
|
+inline void igl::opengl2::MouseController::reset_rotations()
|
|
|
{
|
|
|
using namespace Eigen;
|
|
|
using namespace std;
|
|
@@ -502,7 +505,7 @@ inline void igl::MouseController::reset_rotations()
|
|
|
clear_selection();
|
|
|
}
|
|
|
|
|
|
-inline void igl::MouseController::reset_selected_rotations()
|
|
|
+inline void igl::opengl2::MouseController::reset_selected_rotations()
|
|
|
{
|
|
|
using namespace Eigen;
|
|
|
for(int e = 0;e<m_selection.size();e++)
|
|
@@ -514,7 +517,7 @@ inline void igl::MouseController::reset_selected_rotations()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-inline bool igl::MouseController::set_rotations(const RotationList & vQ)
|
|
|
+inline bool igl::opengl2::MouseController::set_rotations(const RotationList & vQ)
|
|
|
{
|
|
|
if(vQ.size() != m_rotations.size())
|
|
|
{
|
|
@@ -525,12 +528,12 @@ inline bool igl::MouseController::set_rotations(const RotationList & vQ)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-inline void igl::MouseController::clear_selection()
|
|
|
+inline void igl::opengl2::MouseController::clear_selection()
|
|
|
{
|
|
|
m_selection.setConstant(false);
|
|
|
}
|
|
|
|
|
|
-inline bool igl::MouseController::any_selection() const
|
|
|
+inline bool igl::opengl2::MouseController::any_selection() const
|
|
|
{
|
|
|
return igl::any_of(m_selection);
|
|
|
}
|