Commit d6e2b657 authored by Anatoly Baksheev's avatar Anatoly Baksheev

more refactoring

parent 512afe2a
...@@ -60,7 +60,30 @@ namespace cv ...@@ -60,7 +60,30 @@ namespace cv
//! takes coordiante frame data and builds transfrom to global coordinate frame //! takes coordiante frame data and builds transfrom to global coordinate frame
CV_EXPORTS Affine3f makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0)); CV_EXPORTS Affine3f makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0));
//! constructs camera pose from posiont, focal_point and up_vector (see gluLookAt() for more infromation
CV_EXPORTS Affine3f makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& up_vector); CV_EXPORTS Affine3f makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& up_vector);
//! checks float value for Nan
inline bool isNan(float x)
{
unsigned int *u = reinterpret_cast<unsigned int *>(&x);
return ((u[0] & 0x7f800000) == 0x7f800000) && (u[0] & 0x007fffff);
}
//! checks double value for Nan
inline bool isNan(double x)
{
unsigned int *u = reinterpret_cast<unsigned int *>(&x);
return (u[1] & 0x7ff00000) == 0x7ff00000 && (u[0] != 0 || (u[1] & 0x000fffff) != 0);
}
//! checks vectors for Nans
template<typename _Tp, int cn> inline bool isNan(const Vec<_Tp, cn>& v)
{ return isNan(v.val[0]) || isNan(v.val[1]) || isNan(v.val[2]); }
//! checks point for Nans
template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p)
{ return isNan(p.x) || isNan(p.y) || isNan(p.z); }
} }
} }
......
#pragma once
#include <string>
#include <opencv2/viz/types.hpp>
namespace cv
{
namespace viz
{
class KeyboardEvent
{
public:
static const unsigned int Alt = 1;
static const unsigned int Ctrl = 2;
static const unsigned int Shift = 4;
/** \brief Constructor
* \param[in] action true for key was pressed, false for released
* \param[in] key_sym the key-name that caused the action
* \param[in] key the key code that caused the action
* \param[in] alt whether the alt key was pressed at the time where this event was triggered
* \param[in] ctrl whether the ctrl was pressed at the time where this event was triggered
* \param[in] shift whether the shift was pressed at the time where this event was triggered
*/
KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift);
bool isAltPressed () const;
bool isCtrlPressed () const;
bool isShiftPressed () const;
unsigned char getKeyCode () const;
const String& getKeySym () const;
bool keyDown () const;
bool keyUp () const;
protected:
bool action_;
unsigned int modifiers_;
unsigned char key_code_;
String key_sym_;
};
class MouseEvent
{
public:
enum Type
{
MouseMove = 1,
MouseButtonPress,
MouseButtonRelease,
MouseScrollDown,
MouseScrollUp,
MouseDblClick
} ;
enum MouseButton
{
NoButton = 0,
LeftButton,
MiddleButton,
RightButton,
VScroll /*other buttons, scroll wheels etc. may follow*/
} ;
MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift);
Type type;
MouseButton button;
Point pointer;
unsigned int key_state;
};
}
}
////////////////////////////////////////////////////////////////////
/// Implementation
inline cv::viz::KeyboardEvent::KeyboardEvent (bool _action, const std::string& _key_sym, unsigned char key, bool alt, bool ctrl, bool shift)
: action_ (_action), modifiers_ (0), key_code_(key), key_sym_ (_key_sym)
{
if (alt)
modifiers_ = Alt;
if (ctrl)
modifiers_ |= Ctrl;
if (shift)
modifiers_ |= Shift;
}
inline bool cv::viz::KeyboardEvent::isAltPressed () const { return (modifiers_ & Alt) != 0; }
inline bool cv::viz::KeyboardEvent::isCtrlPressed () const { return (modifiers_ & Ctrl) != 0; }
inline bool cv::viz::KeyboardEvent::isShiftPressed () const { return (modifiers_ & Shift) != 0; }
inline unsigned char cv::viz::KeyboardEvent::getKeyCode () const { return key_code_; }
inline const cv::String& cv::viz::KeyboardEvent::getKeySym () const { return key_sym_; }
inline bool cv::viz::KeyboardEvent::keyDown () const { return action_; }
inline bool cv::viz::KeyboardEvent::keyUp () const { return !action_; }
inline cv::viz::MouseEvent::MouseEvent (const Type& _type, const MouseButton& _button, const Point& _p, bool alt, bool ctrl, bool shift)
: type(_type), button(_button), pointer(_p), key_state(0)
{
if (alt)
key_state = KeyboardEvent::Alt;
if (ctrl)
key_state |= KeyboardEvent::Ctrl;
if (shift)
key_state |= KeyboardEvent::Shift;
}
#pragma once #pragma once
#include <vector> #include <string>
#include <opencv2/core/cvdef.h> #include <opencv2/core/cvdef.h>
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
#include <opencv2/core/affine.hpp> #include <opencv2/core/affine.hpp>
...@@ -8,35 +8,7 @@ ...@@ -8,35 +8,7 @@
namespace cv namespace cv
{ {
typedef std::string String; typedef std::string String;
// //qt creator hack
// typedef cv::Scalar Scalar;
// typedef cv::Mat Mat;
// typedef std::string String;
// typedef cv::Vec3d Vec3d;
// typedef cv::Vec3f Vec3f;
// typedef cv::Vec4d Vec4d;
// typedef cv::Vec4f Vec4f;
// typedef cv::Vec2d Vec2d;
// typedef cv::Vec2i Vec2i;
// typedef cv::Vec3b Vec3b;
// typedef cv::Matx33d Matx33d;
// typedef cv::Affine3f Affine3f;
// typedef cv::Affine3d Affine3d;
// typedef cv::Point2i Point2i;
// typedef cv::Point3f Point3f;
// typedef cv::Point3d Point3d;
// typedef cv::Matx44d Matx44d;
// typedef cv::Matx44f Matx44f;
// typedef cv::Size Size;
// typedef cv::Point Point;
// typedef cv::InputArray InputArray;
// using cv::Point3_;
// using cv::Vec;
// using cv::Mat_;
// using cv::DataDepth;
// using cv::DataType;
// using cv::Ptr;
namespace viz namespace viz
{ {
class CV_EXPORTS Color : public Scalar class CV_EXPORTS Color : public Scalar
...@@ -79,35 +51,58 @@ namespace cv ...@@ -79,35 +51,58 @@ namespace cv
}; };
///////////////////////////////////////////////////////////////////////////// class CV_EXPORTS KeyboardEvent
/// Utility functions {
public:
static const unsigned int Alt = 1;
static const unsigned int Ctrl = 2;
static const unsigned int Shift = 4;
/** \brief Constructor
* \param[in] action true for key was pressed, false for released
* \param[in] key_sym the key-name that caused the action
* \param[in] key the key code that caused the action
* \param[in] alt whether the alt key was pressed at the time where this event was triggered
* \param[in] ctrl whether the ctrl was pressed at the time where this event was triggered
* \param[in] shift whether the shift was pressed at the time where this event was triggered
*/
KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift);
bool isAltPressed () const;
bool isCtrlPressed () const;
bool isShiftPressed () const;
unsigned char getKeyCode () const;
const String& getKeySym () const;
bool keyDown () const;
bool keyUp () const;
protected:
bool action_;
unsigned int modifiers_;
unsigned char key_code_;
String key_sym_;
};
inline Color vtkcolor(const Color& color) class CV_EXPORTS MouseEvent
{ {
Color scaled_color = color * (1.0/255.0); public:
std::swap(scaled_color[0], scaled_color[2]); enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ;
return scaled_color; enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ;
}
inline Vec3d vtkpoint(const Point3f& point) { return Vec3d(point.x, point.y, point.z); } MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift);
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/cv::norm(v); }
Type type;
MouseButton button;
Point pointer;
unsigned int key_state;
};
} /* namespace viz */
} /* namespace cv */
inline bool isNan(float x)
{
unsigned int *u = reinterpret_cast<unsigned int *>(&x);
return ((u[0] & 0x7f800000) == 0x7f800000) && (u[0] & 0x007fffff);
}
inline bool isNan(double x)
{
unsigned int *u = reinterpret_cast<unsigned int *>(&x);
return (u[1] & 0x7ff00000) == 0x7ff00000 && (u[0] != 0 || (u[1] & 0x000fffff) != 0);
}
template<typename _Tp, int cn> inline bool isNan(const Vec<_Tp, cn>& v)
{ return isNan(v.val[0]) || isNan(v.val[1]) || isNan(v.val[2]); }
template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p)
{ return isNan(p.x) || isNan(p.y) || isNan(p.z); }
}
}
...@@ -4,14 +4,9 @@ ...@@ -4,14 +4,9 @@
//#error "Viz is in beta state now. Please define macro above to use it" //#error "Viz is in beta state now. Please define macro above to use it"
#endif #endif
#include <opencv2/core/cvdef.h>
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
#include <string>
#include <opencv2/viz/types.hpp> #include <opencv2/viz/types.hpp>
#include <opencv2/viz/widgets.hpp> #include <opencv2/viz/widgets.hpp>
#include <opencv2/viz/events.hpp>
namespace cv namespace cv
{ {
...@@ -20,28 +15,21 @@ namespace cv ...@@ -20,28 +15,21 @@ namespace cv
class CV_EXPORTS Viz3d class CV_EXPORTS Viz3d
{ {
public: public:
typedef cv::Ptr<Viz3d> Ptr; typedef cv::Ptr<Viz3d> Ptr;
typedef void (*KeyboardCallback)(const KeyboardEvent&, void*);
typedef void (*MouseCallback)(const MouseEvent&, void*);
Viz3d(const String& window_name = String()); Viz3d(const String& window_name = String());
~Viz3d(); ~Viz3d();
void setBackgroundColor(const Color& color = Color::black()); void setBackgroundColor(const Color& color = Color::black());
bool addPolygonMesh (const Mesh3d& mesh, const String& id = "polygon"); //to refactor
bool updatePolygonMesh (const Mesh3d& mesh, const String& id = "polygon"); bool addPolygonMesh(const Mesh3d& mesh, const String& id = "polygon");
bool updatePolygonMesh(const Mesh3d& mesh, const String& id = "polygon");
bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id = "polyline"); bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id = "polyline");
bool addPolygon(const Mat& cloud, const Color& color, const String& id = "polygon"); bool addPolygon(const Mat& cloud, const Color& color, const String& id = "polygon");
void spin ();
void spinOnce (int time = 1, bool force_redraw = false);
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie = 0);
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
bool wasStopped() const;
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void removeWidget(const String &id); void removeWidget(const String &id);
...@@ -50,6 +38,13 @@ namespace cv ...@@ -50,6 +38,13 @@ namespace cv
void setWidgetPose(const String &id, const Affine3f &pose); void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose); void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const; Affine3f getWidgetPose(const String &id) const;
void spin();
void spinOnce(int time = 1, bool force_redraw = false);
bool wasStopped() const;
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(MouseCallback callback, void* cookie = 0);
private: private:
Viz3d(const Viz3d&); Viz3d(const Viz3d&);
Viz3d& operator=(const Viz3d&); Viz3d& operator=(const Viz3d&);
...@@ -57,8 +52,9 @@ namespace cv ...@@ -57,8 +52,9 @@ namespace cv
struct VizImpl; struct VizImpl;
VizImpl* impl_; VizImpl* impl_;
}; };
}
} } /* namespace viz */
} /* namespace cv */
This diff is collapsed.
#include <common.h> #include <common.h>
#include <cstdlib> #include <cstdlib>
#include <opencv2/viz/types.hpp> #include <opencv2/viz/types.hpp>
#include "viz3d_impl.hpp"
/////////////////////////////////////////////////////////////////////////////////////////////
//Eigen::Matrix4d cv::viz::vtkToEigen (vtkMatrix4x4* vtk_matrix)
//{
// Eigen::Matrix4d eigen_matrix = Eigen::Matrix4d::Identity ();
// for (int i=0; i < 4; i++)
// for (int j=0; j < 4; j++)
// eigen_matrix (i, j) = vtk_matrix->GetElement (i, j);
// return eigen_matrix;
//}
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
//Eigen::Vector2i cv::viz::worldToView (const Eigen::Vector4d &world_pt, const Eigen::Matrix4d &view_projection_matrix, int width, int height) //Eigen::Vector2i cv::viz::worldToView (const Eigen::Vector4d &world_pt, const Eigen::Matrix4d &view_projection_matrix, int width, int height)
//{ //{
......
...@@ -222,7 +222,6 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -222,7 +222,6 @@ cv::viz::InteractorStyle::OnKeyDown ()
" ALT + s, S : turn stereo mode on/off\n" " ALT + s, S : turn stereo mode on/off\n"
" ALT + f, F : switch between maximized window mode and original size\n" " ALT + f, F : switch between maximized window mode and original size\n"
"\n" "\n"
" SHIFT + left click : select a point\n"
<< std::endl; << std::endl;
break; break;
} }
...@@ -676,9 +675,6 @@ void cv::viz::InteractorStyle::OnTimer () ...@@ -676,9 +675,6 @@ void cv::viz::InteractorStyle::OnTimer ()
} }
namespace cv namespace cv
{ {
namespace viz namespace viz
...@@ -687,4 +683,3 @@ namespace cv ...@@ -687,4 +683,3 @@ namespace cv
vtkStandardNewMacro(InteractorStyle) vtkStandardNewMacro(InteractorStyle)
} }
} }
#pragma once #pragma once
#include "viz_types.h" #include "viz_types.h"
#include <opencv2/viz/events.hpp> #include <opencv2/viz/types.hpp>
namespace cv namespace cv
{ {
namespace viz namespace viz
{ {
/** \brief PCLVisualizerInteractorStyle defines an unique, custom VTK /** \brief InteractorStyle defines an unique, custom VTK based interactory style Viz applications.
* based interactory style for PCL Visualizer applications. Besides * Besides defining the rendering style, we also create a list of custom actions
* defining the rendering style, we also create a list of custom actions
* that are triggered on different keys being pressed: * that are triggered on different keys being pressed:
* *
* - p, P : switch to a point-based representation * - p, P : switch to a point-based representation
...@@ -28,7 +27,6 @@ namespace cv ...@@ -28,7 +27,6 @@ namespace cv
* - SHIFT + left click : select a point * - SHIFT + left click : select a point
* *
* \author Radu B. Rusu * \author Radu B. Rusu
* \ingroup visualization
*/ */
class InteractorStyle : public vtkInteractorStyleTrackballCamera class InteractorStyle : public vtkInteractorStyleTrackballCamera
{ {
...@@ -43,41 +41,19 @@ namespace cv ...@@ -43,41 +41,19 @@ namespace cv
static InteractorStyle *New (); static InteractorStyle *New ();
InteractorStyle () {} InteractorStyle () {}
virtual ~InteractorStyle () {} virtual ~InteractorStyle () {}
// this macro defines Superclass, the isA functionality and the safe downcast method // this macro defines Superclass, the isA functionality and the safe downcast method
vtkTypeMacro (InteractorStyle, vtkInteractorStyleTrackballCamera); vtkTypeMacro (InteractorStyle, vtkInteractorStyleTrackballCamera)
/** \brief Initialization routine. Must be called before anything else. */ /** \brief Initialization routine. Must be called before anything else. */
virtual void Initialize (); virtual void Initialize ();
/** \brief Pass a pointer to the actor map
* \param[in] actors the actor map that will be used with this style
*/
inline void setCloudActorMap (const Ptr<CloudActorMap>& actors) { actors_ = actors; } inline void setCloudActorMap (const Ptr<CloudActorMap>& actors) { actors_ = actors; }
/** \brief Pass a set of renderers to the interactor style.
* \param[in] rens the vtkRendererCollection to use
*/
void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; } void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; }
/** \brief Register a callback function for mouse events
* \param[in] ccallback function that will be registered as a callback for a mouse event
* \param[in] cookie for passing user data to callback
*/
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
/** \brief Register a callback function for keyboard events
* \param[in] callback a function that will be registered as a callback for a keyboard event
* \param[in] cookie user data passed to the callback function
*/
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0);
/** \brief Save the current rendered image to disk, as a PNG screenshot.
* \param[in] file the name of the PNG file
*/
void saveScreenshot (const std::string &file); void saveScreenshot (const std::string &file);
/** \brief Change the default keyboard modified from ALT to a different special key. /** \brief Change the default keyboard modified from ALT to a different special key.
...@@ -134,24 +110,18 @@ namespace cv ...@@ -134,24 +110,18 @@ namespace cv
/** \brief Interactor style internal method. Gets called periodically if a timer is set. */ /** \brief Interactor style internal method. Gets called periodically if a timer is set. */
virtual void OnTimer (); virtual void OnTimer ();
void zoomIn (); void zoomIn ();
void zoomOut (); void zoomOut ();
/** \brief True if we're using red-blue colors for anaglyphic stereo, false if magenta-green. */ /** \brief True if we're using red-blue colors for anaglyphic stereo, false if magenta-green. */
bool stereo_anaglyph_mask_default_; bool stereo_anaglyph_mask_default_;
/** \brief The keyboard modifier to use. Default: Alt. */
KeyboardModifier modifier_; KeyboardModifier modifier_;
/** \brief KeyboardEvent callback function pointer*/
void (*keyboardCallback_)(const KeyboardEvent&, void*); void (*keyboardCallback_)(const KeyboardEvent&, void*);
/** \brief KeyboardEvent callback user data*/
void *keyboard_callback_cookie_; void *keyboard_callback_cookie_;
/** \brief MouseEvent callback function pointer */
void (*mouseCallback_)(const MouseEvent&, void*); void (*mouseCallback_)(const MouseEvent&, void*);
/** \brief MouseEvent callback user data */
void *mouse_callback_cookie_; void *mouse_callback_cookie_;
}; };
} }
......
...@@ -156,7 +156,6 @@ ...@@ -156,7 +156,6 @@
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
#include <opencv2/viz.hpp> #include <opencv2/viz.hpp>
#include "opencv2/viz/widget_accessor.hpp" #include "opencv2/viz/widget_accessor.hpp"
#include <opencv2/calib3d.hpp>
namespace cv namespace cv
{ {
......
...@@ -20,3 +20,42 @@ cv::viz::Color cv::viz::Color::white() { return Color(255, 255, 255); } ...@@ -20,3 +20,42 @@ cv::viz::Color cv::viz::Color::white() { return Color(255, 255, 255); }
cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); } cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); }
////////////////////////////////////////////////////////////////////
/// cv::viz::KeyboardEvent
cv::viz::KeyboardEvent::KeyboardEvent (bool _action, const std::string& _key_sym, unsigned char key, bool alt, bool ctrl, bool shift)
: action_ (_action), modifiers_ (0), key_code_(key), key_sym_ (_key_sym)
{
if (alt)
modifiers_ = Alt;
if (ctrl)
modifiers_ |= Ctrl;
if (shift)
modifiers_ |= Shift;
}
bool cv::viz::KeyboardEvent::isAltPressed () const { return (modifiers_ & Alt) != 0; }
bool cv::viz::KeyboardEvent::isCtrlPressed () const { return (modifiers_ & Ctrl) != 0; }
bool cv::viz::KeyboardEvent::isShiftPressed () const { return (modifiers_ & Shift) != 0; }
unsigned char cv::viz::KeyboardEvent::getKeyCode () const { return key_code_; }
const cv::String& cv::viz::KeyboardEvent::getKeySym () const { return key_sym_; }
bool cv::viz::KeyboardEvent::keyDown () const { return action_; }
bool cv::viz::KeyboardEvent::keyUp () const { return !action_; }
////////////////////////////////////////////////////////////////////
/// cv::viz::MouseEvent
cv::viz::MouseEvent::MouseEvent (const Type& _type, const MouseButton& _button, const Point& _p, bool alt, bool ctrl, bool shift)
: type(_type), button(_button), pointer(_p), key_state(0)
{
if (alt)
key_state = KeyboardEvent::Alt;
if (ctrl)
key_state |= KeyboardEvent::Ctrl;
if (shift)
key_state |= KeyboardEvent::Shift;
}
...@@ -2,20 +2,10 @@ ...@@ -2,20 +2,10 @@
#include "viz3d_impl.hpp" #include "viz3d_impl.hpp"
cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(new VizImpl(window_name)) cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(new VizImpl(window_name)) {}
{ cv::viz::Viz3d::~Viz3d() { delete impl_; }
}
cv::viz::Viz3d::~Viz3d() void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); }
{
delete impl_;
}
void cv::viz::Viz3d::setBackgroundColor(const Color& color)
{
impl_->setBackgroundColor(color);
}
bool cv::viz::Viz3d::addPolygonMesh (const Mesh3d& mesh, const String& id) bool cv::viz::Viz3d::addPolygonMesh (const Mesh3d& mesh, const String& id)
{ {
...@@ -37,54 +27,21 @@ bool cv::viz::Viz3d::addPolygon(const Mat& cloud, const Color& color, const Stri ...@@ -37,54 +27,21 @@ bool cv::viz::Viz3d::addPolygon(const Mat& cloud, const Color& color, const Stri
return impl_->addPolygon(cloud, color, id); return impl_->addPolygon(cloud, color, id);
} }
void cv::viz::Viz3d::spin() void cv::viz::Viz3d::spin() { impl_->spin(); }
{ void cv::viz::Viz3d::spinOnce (int time, bool force_redraw) { impl_->spinOnce(time, force_redraw); }
impl_->spin();
}
void cv::viz::Viz3d::spinOnce (int time, bool force_redraw)
{
impl_->spinOnce(time, force_redraw);
}
void cv::viz::Viz3d::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie)
{
impl_->registerKeyboardCallback(callback, cookie);
}
void cv::viz::Viz3d::registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie)
{
impl_->registerMouseCallback(callback, cookie);
}
bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); } bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); }
void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose) void cv::viz::Viz3d::registerKeyboardCallback(KeyboardCallback callback, void* cookie)
{ { impl_->registerKeyboardCallback(callback, cookie); }
impl_->showWidget(id, widget, pose);
}
void cv::viz::Viz3d::removeWidget(const String &id)
{
impl_->removeWidget(id);
}
cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie)
{ { impl_->registerMouseCallback(callback, cookie); }
return impl_->getWidget(id);
}
void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3f &pose)
{
impl_->setWidgetPose(id, pose);
}
void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3f &pose)
{
impl_->updateWidgetPose(id, pose);
}
cv::Affine3f cv::viz::Viz3d::getWidgetPose(const String &id) const void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose) { impl_->showWidget(id, widget, pose); }
{ void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); }
return impl_->getWidgetPose(id); cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); }
} void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3f &pose) { impl_->setWidgetPose(id, pose); }
void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3f &pose) { impl_->updateWidgetPose(id, pose); }
cv::Affine3f cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); }
#include "precomp.hpp" #include "precomp.hpp"
#include <opencv2/calib3d.hpp>
#include "viz3d_impl.hpp" #include "viz3d_impl.hpp"
#include <vtkRenderWindowInteractor.h> #include <vtkRenderWindowInteractor.h>
...@@ -95,16 +93,11 @@ cv::viz::Viz3d::VizImpl::~VizImpl () ...@@ -95,16 +93,11 @@ cv::viz::Viz3d::VizImpl::~VizImpl ()
void cv::viz::Viz3d::VizImpl::saveScreenshot (const std::string &file) { style_->saveScreenshot (file); } void cv::viz::Viz3d::VizImpl::saveScreenshot (const std::string &file) { style_->saveScreenshot (file); }
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie) void cv::viz::Viz3d::VizImpl::registerMouseCallback(MouseCallback callback, void* cookie)
{ { style_->registerMouseCallback(callback, cookie); }
style_->registerMouseCallback(callback, cookie);
}
///////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::registerKeyboardCallback(KeyboardCallback callback, void* cookie)
void cv::viz::Viz3d::VizImpl::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie) { style_->registerKeyboardCallback(callback, cookie); }
{
style_->registerKeyboardCallback(callback, cookie);
}
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::spin () void cv::viz::Viz3d::VizImpl::spin ()
...@@ -1018,13 +1011,6 @@ void cv::viz::convertToVtkMatrix (const Eigen::Vector4f &origin, const Eigen::Qu ...@@ -1018,13 +1011,6 @@ void cv::viz::convertToVtkMatrix (const Eigen::Vector4f &origin, const Eigen::Qu
vtk_matrix->SetElement (3, 3, 1.0f); vtk_matrix->SetElement (3, 3, 1.0f);
} }
void cv::viz::convertToVtkMatrix (const Matx44f &m, vtkSmartPointer<vtkMatrix4x4> &vtk_matrix)
{
for (int i = 0; i < 4; i++)
for (int k = 0; k < 4; k++)
vtk_matrix->SetElement (i, k, m (i, k));
}
vtkSmartPointer<vtkMatrix4x4> cv::viz::convertToVtkMatrix (const cv::Matx44f &m) vtkSmartPointer<vtkMatrix4x4> cv::viz::convertToVtkMatrix (const cv::Matx44f &m)
{ {
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New(); vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
...@@ -1034,14 +1020,6 @@ vtkSmartPointer<vtkMatrix4x4> cv::viz::convertToVtkMatrix (const cv::Matx44f &m) ...@@ -1034,14 +1020,6 @@ vtkSmartPointer<vtkMatrix4x4> cv::viz::convertToVtkMatrix (const cv::Matx44f &m)
return vtk_matrix; return vtk_matrix;
} }
void cv::viz::convertToCvMatrix (const vtkSmartPointer<vtkMatrix4x4> &vtk_matrix, cv::Matx44f &m)
{
for (int i = 0; i < 4; i++)
for (int k = 0; k < 4; k++)
m(i,k) = vtk_matrix->GetElement (i, k);
}
cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix) cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix)
{ {
cv::Matx44f m; cv::Matx44f m;
...@@ -1052,13 +1030,6 @@ cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matr ...@@ -1052,13 +1030,6 @@ cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matr
} }
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::convertToEigenMatrix (const vtkSmartPointer<vtkMatrix4x4> &vtk_matrix, Eigen::Matrix4f &m)
{
for (int i = 0; i < 4; i++)
for (int k = 0; k < 4; k++)
m (i,k) = static_cast<float> (vtk_matrix->GetElement (i, k));
}
void cv::viz::Viz3d::VizImpl::setFullScreen (bool mode) void cv::viz::Viz3d::VizImpl::setFullScreen (bool mode)
{ {
......
#pragma once #pragma once
#include <opencv2/core.hpp> #include <opencv2/viz.hpp>
#include <opencv2/viz/events.hpp>
#include "interactor_style.h" #include "interactor_style.h"
#include "viz_types.h" #include "viz_types.h"
#include "common.h" #include "common.h"
#include <opencv2/viz/types.hpp>
#include <opencv2/core/affine.hpp>
#include <opencv2/viz/viz3d.hpp>
struct cv::viz::Viz3d::VizImpl struct cv::viz::Viz3d::VizImpl
{ {
public: public:
typedef cv::Ptr<VizImpl> Ptr; typedef cv::Ptr<VizImpl> Ptr;
typedef Viz3d::KeyboardCallback KeyboardCallback;
typedef Viz3d::MouseCallback MouseCallback;
VizImpl (const String &name = String()); VizImpl (const String &name);
virtual ~VizImpl (); virtual ~VizImpl ();
void setFullScreen (bool mode); void setFullScreen (bool mode);
void setWindowName (const String &name); void setWindowName (const String &name);
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie = 0); void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); void registerMouseCallback(MouseCallback callback, void* cookie = 0);
void spin (); void spin ();
void spinOnce (int time = 1, bool force_redraw = false); void spinOnce (int time = 1, bool force_redraw = false);
...@@ -173,9 +170,7 @@ public: ...@@ -173,9 +170,7 @@ public:
void setWidgetPose(const String &id, const Affine3f &pose); void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose); void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const; Affine3f getWidgetPose(const String &id) const;
void all_data();
private: private:
vtkSmartPointer<vtkRenderWindowInteractor> interactor_; vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
...@@ -285,12 +280,6 @@ namespace cv ...@@ -285,12 +280,6 @@ namespace cv
namespace viz namespace viz
{ {
//void getTransformationMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternionf& orientation, Eigen::Matrix4f &transformation); //void getTransformationMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternionf& orientation, Eigen::Matrix4f &transformation);
//void convertToVtkMatrix (const Eigen::Matrix4f &m, vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);
void convertToVtkMatrix (const cv::Matx44f& m, vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);
void convertToCvMatrix (const vtkSmartPointer<vtkMatrix4x4> &vtk_matrix, cv::Matx44f &m);
vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix (const cv::Matx44f &m); vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix (const cv::Matx44f &m);
cv::Matx44f convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix); cv::Matx44f convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matrix);
...@@ -300,8 +289,6 @@ namespace cv ...@@ -300,8 +289,6 @@ namespace cv
* \param[out] vtk_matrix the resultant VTK 4x4 matrix * \param[out] vtk_matrix the resultant VTK 4x4 matrix
*/ */
void convertToVtkMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternion<float> &orientation, vtkSmartPointer<vtkMatrix4x4> &vtk_matrix); void convertToVtkMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternion<float> &orientation, vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);
void convertToEigenMatrix (const vtkSmartPointer<vtkMatrix4x4> &vtk_matrix, Eigen::Matrix4f &m);
struct NanFilter struct NanFilter
{ {
...@@ -366,6 +353,17 @@ namespace cv ...@@ -366,6 +353,17 @@ namespace cv
ApplyAffine(const ApplyAffine&); ApplyAffine(const ApplyAffine&);
ApplyAffine& operator=(const ApplyAffine&); ApplyAffine& operator=(const ApplyAffine&);
}; };
inline Color vtkcolor(const Color& color)
{
Color scaled_color = color * (1.0/255.0);
std::swap(scaled_color[0], scaled_color[2]);
return scaled_color;
}
inline Vec3d vtkpoint(const Point3f& point) { return Vec3d(point.x, point.y, point.z); }
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/cv::norm(v); }
} }
} }
......
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