Commit fb7e74c5 authored by Anatoly Baksheev's avatar Anatoly Baksheev

iteractor work

parent 03bd8279
......@@ -130,6 +130,7 @@
#include <vtkElevationFilter.h>
#include <vtkColorTransferFunction.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include "vtkCallbackCommand.h"
#if !defined(_WIN32) || defined(__CYGWIN__)
# include <unistd.h> /* unlink */
......@@ -145,6 +146,7 @@
#include <vtk/vtkTrajectorySource.h>
#include <vtk/vtkImageMatSource.h>
#include <opencv2/core/core.hpp>
#include <opencv2/viz/vizcore.hpp>
#include <opencv2/viz/widget_accessor.hpp>
......@@ -332,8 +334,7 @@ namespace cv
}
}
#include "interactor_style.hpp"
#include "vtk/vtkVizInteractorStyle.hpp"
#include "vizimpl.hpp"
#endif
......@@ -87,6 +87,7 @@ cv::Affine3d cv::viz::makeCameraPose(const Vec3d& position, const Vec3d& focal_p
#else
void register_console_handler();
void register_console_handler() {}
#endif
......
......@@ -60,10 +60,9 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name) : spin_once_state_(false),
window_->AddRenderer(renderer_);
// Create the interactor style
style_ = vtkSmartPointer<InteractorStyle>::New();
style_ = vtkSmartPointer<vtkVizInteractorStyle>::New();
style_->setWidgetActorMap(widget_actor_map_);
style_->UseTimersOn();
style_->Initialize();
timer_callback_ = vtkSmartPointer<TimerCallback>::New();
exit_callback_ = vtkSmartPointer<ExitCallback>::New();
......
......@@ -128,7 +128,7 @@ private:
vtkSmartPointer<ExitCallback> exit_callback_;
vtkSmartPointer<vtkRenderer> renderer_;
vtkSmartPointer<InteractorStyle> style_;
vtkSmartPointer<vtkVizInteractorStyle> style_;
Ptr<WidgetActorMap> widget_actor_map_;
bool removeActorFromRenderer(vtkSmartPointer<vtkProp> actor);
......
......@@ -40,8 +40,7 @@
// Authors:
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
// This workaround code was taken from PCL library(www.pointclouds.org)
//
//M*/
......
......@@ -84,7 +84,7 @@ void cv::viz::vtkOBJWriter::WriteData()
std::ostream& outfile = *outfilep;
//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;
// write out the points
......
......@@ -46,64 +46,101 @@
#ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__
#define __OPENCV_VIZ_INTERACTOR_STYLE_H__
#include <vtkInteractorStyle.h>
namespace cv
{
namespace viz
{
class InteractorStyle : public vtkInteractorStyleTrackballCamera
class vtkVizInteractorStyle : public vtkInteractorStyle
{
public:
static InteractorStyle *New();
virtual ~InteractorStyle() {}
static vtkVizInteractorStyle *New();
vtkTypeMacro(vtkVizInteractorStyle, vtkInteractorStyle)
void PrintSelf(ostream& os, vtkIndent indent);
// this macro defines Superclass, the isA functionality and the safe downcast method
vtkTypeMacro(InteractorStyle, vtkInteractorStyleTrackballCamera)
virtual void OnChar();
virtual void OnKeyDown();
virtual void OnKeyUp();
/** \brief Initialization routine. Must be called before anything else. */
virtual void Initialize();
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();
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 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 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:
/** \brief Set to true after initialization is complete. */
bool init_;
Ptr<WidgetActorMap> widget_actor_map_;
Vec2i win_size_;
Vec2i win_pos_;
Vec2i max_win_size_;
/** \brief Interactor style internal method. Gets called whenever a key is pressed. */
virtual void OnChar();
void zoomIn();
void zoomOut();
// Keyboard events
virtual void OnKeyDown();
virtual void OnKeyUp();
protected:
vtkVizInteractorStyle();
~vtkVizInteractorStyle();
// mouse button events
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();
virtual void Dolly(double factor);
/** \brief Interactor style internal method. Gets called periodically if a timer is set. */
virtual void OnTimer();
void Fly();
void FlyByMouse();
void FlyByKey();
void SetupMotionVars();
void MotionAlongVector(const Vec3d& vector, double amount, vtkCamera* cam);
void zoomIn();
void zoomOut();
private:
vtkVizInteractorStyle(const vtkVizInteractorStyle&);
vtkVizInteractorStyle& operator=(const vtkVizInteractorStyle&);
/** \brief True if we're using red-blue colors for anaglyphic stereo, false if magenta-green. */
bool stereo_anaglyph_mask_default_;
//! True for red-blue colors, false for magenta-green.
bool stereo_anaglyph_redblue_;
void (*keyboardCallback_)(const KeyboardEvent&, void*);
void *keyboard_callback_cookie_;
......@@ -111,7 +148,20 @@ namespace cv
void (*mouseCallback_)(const MouseEvent&, void*);
void *mouse_callback_cookie_;
bool FlyMode;
double MotionFactor;
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