Commit fb7e74c5 authored by Anatoly Baksheev's avatar Anatoly Baksheev

iteractor work

parent 03bd8279
...@@ -130,6 +130,7 @@ ...@@ -130,6 +130,7 @@
#include <vtkElevationFilter.h> #include <vtkElevationFilter.h>
#include <vtkColorTransferFunction.h> #include <vtkColorTransferFunction.h>
#include <vtkStreamingDemandDrivenPipeline.h> #include <vtkStreamingDemandDrivenPipeline.h>
#include "vtkCallbackCommand.h"
#if !defined(_WIN32) || defined(__CYGWIN__) #if !defined(_WIN32) || defined(__CYGWIN__)
# include <unistd.h> /* unlink */ # include <unistd.h> /* unlink */
...@@ -145,6 +146,7 @@ ...@@ -145,6 +146,7 @@
#include <vtk/vtkTrajectorySource.h> #include <vtk/vtkTrajectorySource.h>
#include <vtk/vtkImageMatSource.h> #include <vtk/vtkImageMatSource.h>
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include <opencv2/viz/vizcore.hpp> #include <opencv2/viz/vizcore.hpp>
#include <opencv2/viz/widget_accessor.hpp> #include <opencv2/viz/widget_accessor.hpp>
...@@ -332,8 +334,7 @@ namespace cv ...@@ -332,8 +334,7 @@ namespace cv
} }
} }
#include "interactor_style.hpp" #include "vtk/vtkVizInteractorStyle.hpp"
#include "vizimpl.hpp" #include "vizimpl.hpp"
#endif #endif
...@@ -87,6 +87,7 @@ cv::Affine3d cv::viz::makeCameraPose(const Vec3d& position, const Vec3d& focal_p ...@@ -87,6 +87,7 @@ cv::Affine3d cv::viz::makeCameraPose(const Vec3d& position, const Vec3d& focal_p
#else #else
void register_console_handler();
void register_console_handler() {} void register_console_handler() {}
#endif #endif
......
...@@ -60,10 +60,9 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name) : spin_once_state_(false), ...@@ -60,10 +60,9 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name) : spin_once_state_(false),
window_->AddRenderer(renderer_); window_->AddRenderer(renderer_);
// Create the interactor style // Create the interactor style
style_ = vtkSmartPointer<InteractorStyle>::New(); style_ = vtkSmartPointer<vtkVizInteractorStyle>::New();
style_->setWidgetActorMap(widget_actor_map_); style_->setWidgetActorMap(widget_actor_map_);
style_->UseTimersOn(); style_->UseTimersOn();
style_->Initialize();
timer_callback_ = vtkSmartPointer<TimerCallback>::New(); timer_callback_ = vtkSmartPointer<TimerCallback>::New();
exit_callback_ = vtkSmartPointer<ExitCallback>::New(); exit_callback_ = vtkSmartPointer<ExitCallback>::New();
......
...@@ -128,7 +128,7 @@ private: ...@@ -128,7 +128,7 @@ private:
vtkSmartPointer<ExitCallback> exit_callback_; vtkSmartPointer<ExitCallback> exit_callback_;
vtkSmartPointer<vtkRenderer> renderer_; vtkSmartPointer<vtkRenderer> renderer_;
vtkSmartPointer<InteractorStyle> style_; vtkSmartPointer<vtkVizInteractorStyle> style_;
Ptr<WidgetActorMap> widget_actor_map_; Ptr<WidgetActorMap> widget_actor_map_;
bool removeActorFromRenderer(vtkSmartPointer<vtkProp> actor); bool removeActorFromRenderer(vtkSmartPointer<vtkProp> actor);
......
...@@ -40,8 +40,7 @@ ...@@ -40,8 +40,7 @@
// Authors: // Authors:
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
// //
// OpenCV Viz module is complete rewrite of // This workaround code was taken from PCL library(www.pointclouds.org)
// PCL visualization module (www.pointclouds.org)
// //
//M*/ //M*/
......
...@@ -84,7 +84,7 @@ void cv::viz::vtkOBJWriter::WriteData() ...@@ -84,7 +84,7 @@ void cv::viz::vtkOBJWriter::WriteData()
std::ostream& outfile = *outfilep; std::ostream& outfile = *outfilep;
//write header //write header
outfile << "# wavefront obj file written by the visualization toolkit" << std::endl << std::endl; outfile << "# wavefront obj file written by opencv viz module" << std::endl << std::endl;
outfile << "mtllib NONE" << std::endl << std::endl; outfile << "mtllib NONE" << std::endl << std::endl;
// write out the points // write out the points
......
...@@ -46,64 +46,101 @@ ...@@ -46,64 +46,101 @@
#ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__ #ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__
#define __OPENCV_VIZ_INTERACTOR_STYLE_H__ #define __OPENCV_VIZ_INTERACTOR_STYLE_H__
#include <vtkInteractorStyle.h>
namespace cv namespace cv
{ {
namespace viz namespace viz
{ {
class InteractorStyle : public vtkInteractorStyleTrackballCamera class vtkVizInteractorStyle : public vtkInteractorStyle
{ {
public: public:
static InteractorStyle *New(); static vtkVizInteractorStyle *New();
virtual ~InteractorStyle() {} vtkTypeMacro(vtkVizInteractorStyle, vtkInteractorStyle)
void PrintSelf(ostream& os, vtkIndent indent);
// this macro defines Superclass, the isA functionality and the safe downcast method virtual void OnChar();
vtkTypeMacro(InteractorStyle, vtkInteractorStyleTrackballCamera) virtual void OnKeyDown();
virtual void OnKeyUp();
/** \brief Initialization routine. Must be called before anything else. */ virtual void OnMouseMove();
virtual void Initialize(); virtual void OnLeftButtonDown();
virtual void OnLeftButtonUp();
virtual void OnMiddleButtonDown();
virtual void OnMiddleButtonUp();
virtual void OnRightButtonDown();
virtual void OnRightButtonUp();
virtual void OnMouseWheelForward();
virtual void OnMouseWheelBackward();
virtual void OnTimer();
virtual void Rotate();
virtual void Spin();
virtual void Pan();
virtual void Dolly();
vtkSetMacro(FlyMode,bool)
vtkGetMacro(FlyMode,bool)
vtkSetMacro(MotionFactor, double)
vtkGetMacro(MotionFactor, double)
void setWidgetActorMap(const Ptr<WidgetActorMap>& actors) { widget_actor_map_ = actors; }
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0);
void setWidgetActorMap(const Ptr<WidgetActorMap>& actors) { widget_actor_map_ = actors; }
void saveScreenshot(const String &file); void saveScreenshot(const String &file);
void exportScene(const String &file); void exportScene(const String &file);
void exportScene();
void changePointsSize(float delta);
void setRepresentationToPoints();
void printCameraParams();
void toggleFullScreen();
void resetViewerPose();
void toggleStereo();
void printHelp();
// Set the basic unit step size : by default 1/250 of bounding diagonal
vtkSetMacro(MotionStepSize,double)
vtkGetMacro(MotionStepSize,double)
// Set acceleration factor when shift key is applied : default 10
vtkSetMacro(MotionAccelerationFactor,double)
vtkGetMacro(MotionAccelerationFactor,double)
// Set the basic angular unit for turning : efault 1 degree
vtkSetMacro(AngleStepSize,double)
vtkGetMacro(AngleStepSize,double)
private: private:
/** \brief Set to true after initialization is complete. */
bool init_;
Ptr<WidgetActorMap> widget_actor_map_; Ptr<WidgetActorMap> widget_actor_map_;
Vec2i win_size_; Vec2i win_size_;
Vec2i win_pos_; Vec2i win_pos_;
Vec2i max_win_size_; Vec2i max_win_size_;
/** \brief Interactor style internal method. Gets called whenever a key is pressed. */ void zoomIn();
virtual void OnChar(); void zoomOut();
// Keyboard events protected:
virtual void OnKeyDown(); vtkVizInteractorStyle();
virtual void OnKeyUp(); ~vtkVizInteractorStyle();
// mouse button events virtual void Dolly(double factor);
virtual void OnMouseMove();
virtual void OnLeftButtonDown();
virtual void OnLeftButtonUp();
virtual void OnMiddleButtonDown();
virtual void OnMiddleButtonUp();
virtual void OnRightButtonDown();
virtual void OnRightButtonUp();
virtual void OnMouseWheelForward();
virtual void OnMouseWheelBackward();
/** \brief Interactor style internal method. Gets called periodically if a timer is set. */ void Fly();
virtual void OnTimer(); void FlyByMouse();
void FlyByKey();
void SetupMotionVars();
void MotionAlongVector(const Vec3d& vector, double amount, vtkCamera* cam);
void zoomIn(); private:
void zoomOut(); vtkVizInteractorStyle(const vtkVizInteractorStyle&);
vtkVizInteractorStyle& operator=(const vtkVizInteractorStyle&);
/** \brief True if we're using red-blue colors for anaglyphic stereo, false if magenta-green. */ //! True for red-blue colors, false for magenta-green.
bool stereo_anaglyph_mask_default_; bool stereo_anaglyph_redblue_;
void (*keyboardCallback_)(const KeyboardEvent&, void*); void (*keyboardCallback_)(const KeyboardEvent&, void*);
void *keyboard_callback_cookie_; void *keyboard_callback_cookie_;
...@@ -111,7 +148,20 @@ namespace cv ...@@ -111,7 +148,20 @@ namespace cv
void (*mouseCallback_)(const MouseEvent&, void*); void (*mouseCallback_)(const MouseEvent&, void*);
void *mouse_callback_cookie_; void *mouse_callback_cookie_;
bool FlyMode;
double MotionFactor;
int getModifiers(); int getModifiers();
// from fly
unsigned char KeysDown;
double DiagonalLength;
double MotionStepSize;
double MotionUserScale;
double MotionAccelerationFactor;
double AngleStepSize;
double DeltaYaw;
double DeltaPitch;
}; };
} }
} }
......
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