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
......
......@@ -41,42 +41,50 @@
// * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
//
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/
#include "precomp.hpp"
namespace cv { namespace viz
{
vtkStandardNewMacro(InteractorStyle)
vtkStandardNewMacro(vtkVizInteractorStyle)
}}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::Initialize()
cv::viz::vtkVizInteractorStyle::vtkVizInteractorStyle()
{
FlyMode = false;
MotionFactor = 10.0;
keyboardCallback_ = 0;
keyboard_callback_cookie_ = 0;
mouseCallback_ = 0;
mouse_callback_cookie_ = 0;
// Set windows size (width, height) to unknown (-1)
win_size_ = Vec2i(-1, -1);
win_pos_ = Vec2i(0, 0);
max_win_size_ = Vec2i(-1, -1);
init_ = true;
stereo_anaglyph_mask_default_ = true;
stereo_anaglyph_redblue_ = true;
// Initialize the keyboard event callback as none
keyboardCallback_ = 0;
keyboard_callback_cookie_ = 0;
//from fly
KeysDown = 0;
UseTimers = 1;
// Initialize the mouse event callback as none
mouseCallback_ = 0;
mouse_callback_cookie_ = 0;
DiagonalLength = 1.0;
MotionStepSize = 1.0/100.0;
MotionUserScale = 1.0; // +/- key adjustment
MotionAccelerationFactor = 10.0;
AngleStepSize = 1.0;
}
cv::viz::vtkVizInteractorStyle::~vtkVizInteractorStyle() {}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::saveScreenshot(const String &file)
void cv::viz::vtkVizInteractorStyle::saveScreenshot(const String &file)
{
FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]);
......@@ -92,7 +100,8 @@ void cv::viz::InteractorStyle::saveScreenshot(const String &file)
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::exportScene(const String &file)
void cv::viz::vtkVizInteractorStyle::exportScene(const String &file)
{
vtkSmartPointer<vtkExporter> exporter;
if (file.size() > 5 && file.substr(file.size() - 5) == ".vrml")
......@@ -112,8 +121,180 @@ void cv::viz::InteractorStyle::exportScene(const String &file)
cout << "Scene successfully exported (" << file.c_str() << ")" << endl;
}
void cv::viz::vtkVizInteractorStyle::exportScene()
{
// Export scene as in obj or vrml format
String format = Interactor->GetAltKey() ? "scene-%d.vrml" : "scene-%d";
exportScene(cv::format(format.c_str(), (unsigned int)time(0)));
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::changePointsSize(float delta)
{
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
vtkCollectionSimpleIterator ait;
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
{
vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp());
float psize = apart->GetProperty()->GetPointSize() + delta;
psize = std::max(1.f, std::min(63.f, psize));
apart->GetProperty()->SetPointSize(psize);
}
}
void cv::viz::vtkVizInteractorStyle::setRepresentationToPoints()
{
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
vtkCollectionSimpleIterator ait;
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
{
vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp());
apart->GetProperty()->SetRepresentationToPoints();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::printCameraParams()
{
vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera();
Vec2d clip(cam->GetClippingRange());
Vec3d focal(cam->GetFocalPoint()), pos(cam->GetPosition()), view(cam->GetViewUp());
Vec2i win_pos(Interactor->GetRenderWindow()->GetPosition());
Vec2i win_size(Interactor->GetRenderWindow()->GetSize());
double angle = cam->GetViewAngle () / 180.0 * CV_PI;
String data = cv::format("clip(%f,%f) focal(%f,%f,%f) pos(%f,%f,%f) view(%f,%f,%f) angle(%f) winsz(%d,%d) winpos(%d,%d)",
clip[0], clip[1], focal[0], focal[1], focal[2], pos[0], pos[1], pos[2], view[0], view[1], view[2],
angle, win_size[0], win_size[1], win_pos[0], win_pos[1]);
std::cout << data.c_str() << std::endl;
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::toggleFullScreen()
{
Vec2i screen_size(Interactor->GetRenderWindow()->GetScreenSize());
Vec2i win_size(Interactor->GetRenderWindow()->GetSize());
// Is window size = max?
if (win_size == max_win_size_)
{
Interactor->GetRenderWindow()->SetSize(win_size_.val);
Interactor->GetRenderWindow()->SetPosition(win_pos_.val);
Interactor->Render();
}
// Set to max
else
{
win_pos_ = Vec2i(Interactor->GetRenderWindow()->GetPosition());
win_size_ = win_size;
Interactor->GetRenderWindow()->SetSize(screen_size.val);
Interactor->Render();
max_win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize());
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::resetViewerPose()
{
WidgetActorMap::iterator it = widget_actor_map_->begin();
// it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault.
for (; it != widget_actor_map_->end(); ++it)
{
vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
if (actor && actor->GetUserMatrix())
break;
}
vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera();
// if a valid transformation was found, use it otherwise fall back to default view point.
if (it != widget_actor_map_->end())
{
vtkMatrix4x4* m = vtkProp3D::SafeDownCast(it->second)->GetUserMatrix();
cam->SetFocalPoint(m->GetElement(0, 3) - m->GetElement(0, 2),
m->GetElement(1, 3) - m->GetElement(1, 2),
m->GetElement(2, 3) - m->GetElement(2, 2));
cam->SetViewUp (m->GetElement(0, 1), m->GetElement(1, 1), m->GetElement(2, 1));
cam->SetPosition(m->GetElement(0, 3), m->GetElement(1, 3), m->GetElement(2, 3));
}
else
{
cam->SetPosition(0, 0, 0);
cam->SetFocalPoint(0, 0, 1);
cam->SetViewUp(0, -1, 0);
}
// go to the next actor for the next key-press event.
if (it != widget_actor_map_->end())
++it;
else
it = widget_actor_map_->begin();
CurrentRenderer->SetActiveCamera(cam);
CurrentRenderer->ResetCameraClippingRange();
Interactor->Render();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::zoomIn()
void cv::viz::vtkVizInteractorStyle::toggleStereo()
{
vtkSmartPointer<vtkRenderWindow> window = Interactor->GetRenderWindow();
if (!window->GetStereoRender())
{
static Vec2i red_blue(4, 3), magenta_green(2, 5);
window->SetAnaglyphColorMask (stereo_anaglyph_redblue_ ? red_blue.val : magenta_green.val);
stereo_anaglyph_redblue_ = !stereo_anaglyph_redblue_;
}
window->SetStereoRender(!window->GetStereoRender());
Interactor->Render();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::printHelp()
{
std::cout << "| Help:\n"
"-------\n"
" p, P : switch to a point-based representation\n"
" w, W : switch to a wireframe-based representation (where available)\n"
" s, S : switch to a surface-based representation (where available)\n"
"\n"
" j, J : take a .PNG snapshot of the current window view\n"
" k, K : export scene to Wavefront .obj format\n"
" ALT + k, K : export scene to VRML format\n"
" c, C : display current camera/window parameters\n"
" F5 : enable/disable fly mode (changes control style)\n"
"\n"
" e, E : exit the interactor\n"
" q, Q : stop and call VTK's TerminateApp\n"
"\n"
" +/- : increment/decrement overall point size\n"
" +/- [+ ALT] : zoom in/out \n"
"\n"
" r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]\n"
"\n"
" ALT + s, S : turn stereo mode on/off\n"
" ALT + f, F : switch between maximized window mode and original size\n"
"\n"
<< std::endl;
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::zoomIn()
{
FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]);
// Zoom in
......@@ -124,7 +305,7 @@ void cv::viz::InteractorStyle::zoomIn()
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::zoomOut()
void cv::viz::vtkVizInteractorStyle::zoomOut()
{
FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]);
// Zoom out
......@@ -135,12 +316,9 @@ void cv::viz::InteractorStyle::zoomOut()
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnChar()
void cv::viz::vtkVizInteractorStyle::OnChar()
{
// Make sure we ignore the same events we handle in OnKeyDown to avoid calling things twice
FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]);
if (Interactor->GetKeyCode() >= '0' && Interactor->GetKeyCode() <= '9')
return;
String key(Interactor->GetKeySym());
if (key.find("XF86ZoomIn") != String::npos)
......@@ -148,60 +326,48 @@ void cv::viz::InteractorStyle::OnChar()
else if (key.find("XF86ZoomOut") != String::npos)
zoomOut();
int keymod = Interactor->GetAltKey();
switch (Interactor->GetKeyCode())
{
// All of the options below simply exit
case 'h': case 'H':
case 'l': case 'L':
// // All of the options below simply exit
// case 'l': case 'L': case 'j': case 'J': case 'c': case 'C': case 'q': case 'Q':
// case 'f': case 'F': case 'g': case 'G': case 'o': case 'O': case 'u': case 'U':
case 'p': case 'P':
case 'j': case 'J':
case 'c': case 'C':
case 43: // KEY_PLUS
case 45: // KEY_MINUS
case 'f': case 'F':
case 'g': case 'G':
case 'o': case 'O':
case 'u': case 'U':
case 'q': case 'Q':
{
break;
}
// S and R have a special !ALT case
case 'r': case 'R':
case 's': case 'S':
{
if (!keymod)
case '+':
if (FlyMode)
MotionUserScale = std::min(16.0, MotionUserScale*2.0);
break;
case '-':
if (FlyMode)
MotionUserScale = std::max(MotionUserScale * 0.5, 0.0625);
break;
case 'r': case 'R': case 's': case 'S':
if (!Interactor->GetAltKey())
Superclass::OnChar();
break;
}
default:
{
Superclass::OnChar();
break;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie)
void cv::viz::vtkVizInteractorStyle::registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie)
{
// Register the callback function and store the user data
mouseCallback_ = callback;
mouse_callback_cookie_ = cookie;
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void *cookie)
void cv::viz::vtkVizInteractorStyle::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void *cookie)
{
// Register the callback function and store the user data
keyboardCallback_ = callback;
keyboard_callback_cookie_ = cookie;
}
//////////////////////////////////////////////////////////////////////////////////////////////
int cv::viz::InteractorStyle::getModifiers()
int cv::viz::vtkVizInteractorStyle::getModifiers()
{
int modifiers = KeyboardEvent::NONE;
......@@ -217,197 +383,67 @@ int cv::viz::InteractorStyle::getModifiers()
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnKeyDown()
void cv::viz::vtkVizInteractorStyle::OnKeyDown()
{
CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_);
FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]);
// Save the initial windows width/height
if (win_size_[0] == -1 || win_size_[1] == -1)
win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize());
bool alt = Interactor->GetAltKey() != 0;
std::string key(Interactor->GetKeySym());
if (key.find("XF86ZoomIn") != std::string::npos)
String key(Interactor->GetKeySym());
if (key.find("XF86ZoomIn") != String::npos)
zoomIn();
else if (key.find("XF86ZoomOut") != std::string::npos)
else if (key.find("XF86ZoomOut") != String::npos)
zoomOut();
switch (Interactor->GetKeyCode())
{
case 'h': case 'H':
{
std::cout << "| Help:\n"
"-------\n"
" p, P : switch to a point-based representation\n"
" w, W : switch to a wireframe-based representation (where available)\n"
" s, S : switch to a surface-based representation (where available)\n"
"\n"
" j, J : take a .PNG snapshot of the current window view\n"
" k, K : export scene to Wavefront .obj format\n"
" ALT + k, K : export scene to VRML format\n"
" c, C : display current camera/window parameters\n"
" f, F : fly to point mode, hold the key and move mouse where to fly\n"
"\n"
" e, E : exit the interactor\n"
" q, Q : stop and call VTK's TerminateApp\n"
"\n"
" +/- : increment/decrement overall point size\n"
" +/- [+ ALT] : zoom in/out \n"
"\n"
" r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]\n"
"\n"
" ALT + s, S : turn stereo mode on/off\n"
" ALT + f, F : switch between maximized window mode and original size\n"
"\n"
<< std::endl;
break;
}
// Switch representation to points
case 'p': case 'P':
else if (key.find("F5") != String::npos)
{
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
vtkCollectionSimpleIterator ait;
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
{
vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp());
apart->GetProperty()->SetRepresentationToPoints();
}
break;
FlyMode = !FlyMode;
std::cout << (FlyMode ? "Fly mode: on" : "Fly mode: off") << std::endl;
}
// Save a PNG snapshot
case 'j': case 'J':
saveScreenshot(cv::format("screenshot-%d.png", (unsigned int)time(0))); break;
// Export scene as in obj or vrml format
case 'k': case 'K':
{
String format = alt ? "scene-%d.vrml" : "scene-%d";
exportScene(cv::format(format.c_str(), (unsigned int)time(0)));
break;
}
// display current camera settings/parameters
case 'c': case 'C':
{
vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera();
Vec2d clip(cam->GetClippingRange());
Vec3d focal(cam->GetFocalPoint()), pos(cam->GetPosition()), view(cam->GetViewUp());
Vec2i win_pos(Interactor->GetRenderWindow()->GetPosition());
Vec2i win_size(Interactor->GetRenderWindow()->GetSize());
double angle = cam->GetViewAngle () / 180.0 * CV_PI;
String data = cv::format("clip(%f,%f) focal(%f,%f,%f) pos(%f,%f,%f) view(%f,%f,%f) angle(%f) winsz(%d,%d) winpos(%d,%d)",
clip[0], clip[1], focal[0], focal[1], focal[2], pos[0], pos[1], pos[2], view[0], view[1], view[2],
angle, win_size[0], win_size[1], win_pos[0], win_pos[1]);
std::cout << data.c_str() << std::endl;
// Save the initial windows width/height
if (win_size_[0] == -1 || win_size_[1] == -1)
win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize());
break;
}
case '=':
switch (Interactor->GetKeyCode())
{
zoomIn();
break;
}
case 'a': case 'A' : KeysDown |=16; break;
case 'z': case 'Z' : KeysDown |=32; break;
case 'h': case 'H' : printHelp(); break;
case 'p': case 'P' : setRepresentationToPoints(); break;
case 'k': case 'K' : exportScene(); break;
case 'j': case 'J' : saveScreenshot(cv::format("screenshot-%d.png", (unsigned int)time(0))); break;
case 'c': case 'C' : printCameraParams(); break;
case '=': zoomIn(); break;
case 43: // KEY_PLUS
{
if (alt)
if (FlyMode)
break;
if (Interactor->GetAltKey())
zoomIn();
else
{
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
vtkCollectionSimpleIterator ait;
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
{
vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp());
float psize = apart->GetProperty()->GetPointSize();
if (psize < 63.0f)
apart->GetProperty()->SetPointSize(psize + 1.0f);
}
}
changePointsSize(+1.f);
break;
}
case 45: // KEY_MINUS
{
if (alt)
if (FlyMode)
break;
if (Interactor->GetAltKey())
zoomOut();
else
{
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
vtkCollectionSimpleIterator ait;
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
{
vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp());
float psize = apart->GetProperty()->GetPointSize();
if (psize > 1.0f)
apart->GetProperty()->SetPointSize(psize - 1.0f);
}
}
changePointsSize(-1.f);
break;
}
// Switch between maximize and original window size
case 'f': case 'F':
{
if (alt)
{
Vec2i screen_size(Interactor->GetRenderWindow()->GetScreenSize());
Vec2i win_size(Interactor->GetRenderWindow()->GetSize());
// Is window size = max?
if (win_size == max_win_size_)
{
Interactor->GetRenderWindow()->SetSize(win_size_.val);
Interactor->GetRenderWindow()->SetPosition(win_pos_.val);
Interactor->Render();
}
// Set to max
else
{
win_pos_ = Vec2i(Interactor->GetRenderWindow()->GetPosition());
win_size_ = win_size;
Interactor->GetRenderWindow()->SetSize(screen_size.val);
Interactor->Render();
max_win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize());
}
}
else
{
AnimState = VTKIS_ANIM_ON;
Interactor->GetPicker()->Pick(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1], 0.0, CurrentRenderer);
vtkSmartPointer<vtkAbstractPropPicker> picker = vtkAbstractPropPicker::SafeDownCast(Interactor->GetPicker());
if (picker)
if (picker->GetPath())
Interactor->FlyTo(CurrentRenderer, picker->GetPickPosition());
AnimState = VTKIS_ANIM_OFF;
}
if (Interactor->GetAltKey())
toggleFullScreen();
break;
}
// 's'/'S' w/out ALT
case 's': case 'S':
{
if (alt)
{
vtkSmartPointer<vtkRenderWindow> window = Interactor->GetRenderWindow();
if (!window->GetStereoRender())
{
static Vec2i red_blue(4, 3), magenta_green(2, 5);
window->SetAnaglyphColorMask (stereo_anaglyph_mask_default_ ? red_blue.val : magenta_green.val);
stereo_anaglyph_mask_default_ = !stereo_anaglyph_mask_default_;
}
window->SetStereoRender(!window->GetStereoRender());
Interactor->Render();
}
else
Superclass::OnKeyDown();
if (Interactor->GetAltKey())
toggleStereo();
break;
}
......@@ -419,159 +455,271 @@ void cv::viz::InteractorStyle::OnKeyDown()
break;
}
// Overwrite the camera reset
// Overwrite the camera reset
case 'r': case 'R':
{
if (!alt)
{
Superclass::OnKeyDown();
break;
}
WidgetActorMap::iterator it = widget_actor_map_->begin();
// it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault.
for (; it != widget_actor_map_->end(); ++it)
{
vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
if (actor && actor->GetUserMatrix())
break;
}
vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera();
// if a valid transformation was found, use it otherwise fall back to default view point.
if (it != widget_actor_map_->end())
{
vtkMatrix4x4* m = vtkProp3D::SafeDownCast(it->second)->GetUserMatrix();
cam->SetFocalPoint(m->GetElement(0, 3) - m->GetElement(0, 2),
m->GetElement(1, 3) - m->GetElement(1, 2),
m->GetElement(2, 3) - m->GetElement(2, 2));
cam->SetViewUp (m->GetElement(0, 1), m->GetElement(1, 1), m->GetElement(2, 1));
cam->SetPosition(m->GetElement(0, 3), m->GetElement(1, 3), m->GetElement(2, 3));
}
else
{
cam->SetPosition(0, 0, 0);
cam->SetFocalPoint(0, 0, 1);
cam->SetViewUp(0, -1, 0);
}
// go to the next actor for the next key-press event.
if (it != widget_actor_map_->end())
++it;
else
it = widget_actor_map_->begin();
CurrentRenderer->SetActiveCamera(cam);
CurrentRenderer->ResetCameraClippingRange();
Interactor->Render();
if (Interactor->GetAltKey())
resetViewerPose();
break;
}
case 'q': case 'Q':
{
Interactor->ExitCallback();
return;
}
Interactor->ExitCallback(); return;
default:
{
Superclass::OnKeyDown();
break;
}
Superclass::OnKeyDown(); break;
}
KeyboardEvent event(KeyboardEvent::KEY_DOWN, Interactor->GetKeySym(), Interactor->GetKeyCode(), getModifiers());
if (keyboardCallback_)
keyboardCallback_(event, keyboard_callback_cookie_);
if (FlyMode && (KeysDown & (32+16)) == (32+16))
{
if (State == VTKIS_FORWARDFLY || State == VTKIS_REVERSEFLY)
StopState();
}
else if (FlyMode && (KeysDown & 32) == 32)
{
if (State == VTKIS_FORWARDFLY)
StopState();
if (State == VTKIS_NONE)
StartState(VTKIS_REVERSEFLY);
}
else if (FlyMode && (KeysDown & 16) == 16)
{
if (State == VTKIS_REVERSEFLY)
StopState();
if (State == VTKIS_NONE)
StartState(VTKIS_FORWARDFLY);
}
Interactor->Render();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnKeyUp()
void cv::viz::vtkVizInteractorStyle::OnKeyUp()
{
KeyboardEvent event(KeyboardEvent::KEY_UP, Interactor->GetKeySym(), Interactor->GetKeyCode(), getModifiers());
if (keyboardCallback_)
keyboardCallback_(event, keyboard_callback_cookie_);
switch (Interactor->GetKeyCode())
{
case 'a': case 'A' : KeysDown &= ~16; break;
case 'z': case 'Z' : KeysDown &= ~32; break;
}
if (State == VTKIS_FORWARDFLY && (KeysDown & 16) == 0)
StopState();
if (State == VTKIS_REVERSEFLY && (KeysDown & 32) == 0)
StopState();
Superclass::OnKeyUp();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnMouseMove()
void cv::viz::vtkVizInteractorStyle::OnMouseMove()
{
Vec2i p(Interactor->GetEventPosition());
MouseEvent event(MouseEvent::MouseMove, MouseEvent::NoButton, p, getModifiers());
if (mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_);
Superclass::OnMouseMove();
FindPokedRenderer(p[0], p[1]);
if (State == VTKIS_ROTATE || State == VTKIS_PAN || State == VTKIS_DOLLY || State == VTKIS_SPIN)
{
switch (State)
{
case VTKIS_ROTATE: Rotate(); break;
case VTKIS_PAN: Pan(); break;
case VTKIS_DOLLY: Dolly(); break;
case VTKIS_SPIN: Spin(); break;
}
InvokeEvent(vtkCommand::InteractionEvent, NULL);
}
if (State == VTKIS_FORWARDFLY || State == VTKIS_REVERSEFLY)
{
vtkCamera *cam = CurrentRenderer->GetActiveCamera();
Vec2i thispos(Interactor->GetEventPosition());
Vec2i lastpos(Interactor->GetLastEventPosition());
// we want to steer by an amount proportional to window viewangle and size
// compute dx and dy increments relative to last mouse click
Vec2i size(Interactor->GetSize());
double scalefactor = 5*cam->GetViewAngle()/size[0];
double dx = - (thispos[0] - lastpos[0])*scalefactor*AngleStepSize;
double dy = (thispos[1] - lastpos[1])*scalefactor*AngleStepSize;
// Temporary until I get smooth flight working
DeltaPitch = dy;
DeltaYaw = dx;
InvokeEvent(vtkCommand::InteractionEvent, NULL);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnLeftButtonDown()
void cv::viz::vtkVizInteractorStyle::OnLeftButtonDown()
{
Vec2i p(Interactor->GetEventPosition());
MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick;
MouseEvent event(type, MouseEvent::LeftButton, p, getModifiers());
if (mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_);
Superclass::OnLeftButtonDown();
FindPokedRenderer(p[0], p[1]);
if (!CurrentRenderer)
return;
GrabFocus(EventCallbackCommand);
if (FlyMode)
{
if(State == VTKIS_REVERSEFLY)
State = VTKIS_FORWARDFLY;
else
{
SetupMotionVars();
if (State == VTKIS_NONE)
StartState(VTKIS_FORWARDFLY);
}
}
else
{
if (Interactor->GetShiftKey())
{
if (Interactor->GetControlKey())
StartDolly();
else
StartPan();
}
else
{
if (Interactor->GetControlKey())
StartSpin();
else
StartRotate();
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnLeftButtonUp()
void cv::viz::vtkVizInteractorStyle::OnLeftButtonUp()
{
Vec2i p(Interactor->GetEventPosition());
MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::LeftButton, p, getModifiers());
if (mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_);
Superclass::OnLeftButtonUp();
switch (State)
{
case VTKIS_DOLLY: EndDolly(); break;
case VTKIS_PAN: EndPan(); break;
case VTKIS_SPIN: EndSpin(); break;
case VTKIS_ROTATE: EndRotate(); break;
case VTKIS_FORWARDFLY: StopState(); break;
}
if (Interactor )
ReleaseFocus();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnMiddleButtonDown()
void cv::viz::vtkVizInteractorStyle::OnMiddleButtonDown()
{
Vec2i p(Interactor->GetEventPosition());
MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick;
MouseEvent event(type, MouseEvent::MiddleButton, p, getModifiers());
if (mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_);
Superclass::OnMiddleButtonDown();
FindPokedRenderer(p[0], p[1]);
if (!CurrentRenderer)
return;
GrabFocus(EventCallbackCommand);
StartPan();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnMiddleButtonUp()
void cv::viz::vtkVizInteractorStyle::OnMiddleButtonUp()
{
Vec2i p(Interactor->GetEventPosition());
MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::MiddleButton, p, getModifiers());
if (mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_);
Superclass::OnMiddleButtonUp();
if (State == VTKIS_PAN)
{
EndPan();
if (Interactor)
ReleaseFocus();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnRightButtonDown()
void cv::viz::vtkVizInteractorStyle::OnRightButtonDown()
{
Vec2i p(Interactor->GetEventPosition());
MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick;
MouseEvent event(type, MouseEvent::RightButton, p, getModifiers());
if (mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_);
Superclass::OnRightButtonDown();
FindPokedRenderer(p[0], p[1]);
if (!CurrentRenderer)
return;
GrabFocus(EventCallbackCommand);
if (FlyMode)
{
if (State == VTKIS_FORWARDFLY)
State = VTKIS_REVERSEFLY;
else
{
SetupMotionVars();
if (State == VTKIS_NONE)
StartState(VTKIS_REVERSEFLY);
}
}
else
StartDolly();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnRightButtonUp()
void cv::viz::vtkVizInteractorStyle::OnRightButtonUp()
{
Vec2i p(Interactor->GetEventPosition());
MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::RightButton, p, getModifiers());
if (mouseCallback_)
mouseCallback_(event, mouse_callback_cookie_);
Superclass::OnRightButtonUp();
if(State == VTKIS_DOLLY)
{
EndDolly();
if (Interactor)
ReleaseFocus();
}
if (State == VTKIS_REVERSEFLY)
{
StopState();
if (Interactor)
ReleaseFocus();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnMouseWheelForward()
void cv::viz::vtkVizInteractorStyle::OnMouseWheelForward()
{
Vec2i p(Interactor->GetEventPosition());
MouseEvent event(MouseEvent::MouseScrollUp, MouseEvent::VScroll, p, getModifiers());
......@@ -595,11 +743,21 @@ void cv::viz::InteractorStyle::OnMouseWheelForward()
Interactor->Render();
}
else
Superclass::OnMouseWheelForward();
{
FindPokedRenderer(p[0], p[1]);
if (!CurrentRenderer)
return;
GrabFocus(EventCallbackCommand);
StartDolly();
Dolly(pow(1.1, MotionFactor * 0.2 * MouseWheelMotionFactor));
EndDolly();
ReleaseFocus();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnMouseWheelBackward()
void cv::viz::vtkVizInteractorStyle::OnMouseWheelBackward()
{
Vec2i p(Interactor->GetEventPosition());
MouseEvent event(MouseEvent::MouseScrollDown, MouseEvent::VScroll, p, getModifiers());
......@@ -624,12 +782,296 @@ void cv::viz::InteractorStyle::OnMouseWheelBackward()
Interactor->Render();
}
else
Superclass::OnMouseWheelBackward();
{
FindPokedRenderer(p[0], p[1]);
if (!CurrentRenderer)
return;
GrabFocus(EventCallbackCommand);
StartDolly();
Dolly(pow(1.1, MotionFactor * -0.2 * MouseWheelMotionFactor));
EndDolly();
ReleaseFocus();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::OnTimer()
{
if (State == VTKIS_FORWARDFLY || State == VTKIS_REVERSEFLY)
Fly();
Interactor->Render();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::Rotate()
{
if (!CurrentRenderer)
return;
Vec2i dxy = Vec2i(Interactor->GetEventPosition()) - Vec2i(Interactor->GetLastEventPosition());
Vec2i size(CurrentRenderer->GetRenderWindow()->GetSize());
double delta_elevation = -20.0 / size[1];
double delta_azimuth = -20.0 / size[0];
double rxf = dxy[0] * delta_azimuth * MotionFactor;
double ryf = dxy[1] * delta_elevation * MotionFactor;
vtkCamera *camera = CurrentRenderer->GetActiveCamera();
camera->Azimuth(rxf);
camera->Elevation(ryf);
camera->OrthogonalizeViewUp();
if (AutoAdjustCameraClippingRange)
CurrentRenderer->ResetCameraClippingRange();
if (Interactor->GetLightFollowCamera())
CurrentRenderer->UpdateLightsGeometryToFollowCamera();
Interactor->Render();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::Spin()
{
if (!CurrentRenderer)
return;
vtkRenderWindowInteractor *rwi = Interactor;
double *center = CurrentRenderer->GetCenter();
double newAngle = vtkMath::DegreesFromRadians( atan2( rwi->GetEventPosition()[1] - center[1], rwi->GetEventPosition()[0] - center[0] ) );
double oldAngle = vtkMath::DegreesFromRadians( atan2( rwi->GetLastEventPosition()[1] - center[1], rwi->GetLastEventPosition()[0] - center[0] ) );
vtkCamera *camera = CurrentRenderer->GetActiveCamera();
camera->Roll( newAngle - oldAngle );
camera->OrthogonalizeViewUp();
rwi->Render();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::InteractorStyle::OnTimer()
void cv::viz::vtkVizInteractorStyle::Pan()
{
CV_Assert("Interactor style not initialized." && init_);
if (!CurrentRenderer)
return;
vtkRenderWindowInteractor *rwi = Interactor;
double viewFocus[4], focalDepth, viewPoint[3];
double newPickPoint[4], oldPickPoint[4], motionVector[3];
// Calculate the focal depth since we'll be using it a lot
vtkCamera *camera = CurrentRenderer->GetActiveCamera();
camera->GetFocalPoint(viewFocus);
ComputeWorldToDisplay(viewFocus[0], viewFocus[1], viewFocus[2], viewFocus);
focalDepth = viewFocus[2];
ComputeDisplayToWorld(rwi->GetEventPosition()[0], rwi->GetEventPosition()[1], focalDepth, newPickPoint);
// Has to recalc old mouse point since the viewport has moved, so can't move it outside the loop
ComputeDisplayToWorld(rwi->GetLastEventPosition()[0], rwi->GetLastEventPosition()[1], focalDepth, oldPickPoint);
// Camera motion is reversed
motionVector[0] = oldPickPoint[0] - newPickPoint[0];
motionVector[1] = oldPickPoint[1] - newPickPoint[1];
motionVector[2] = oldPickPoint[2] - newPickPoint[2];
camera->GetFocalPoint(viewFocus);
camera->GetPosition(viewPoint);
camera->SetFocalPoint(motionVector[0] + viewFocus[0], motionVector[1] + viewFocus[1], motionVector[2] + viewFocus[2]);
camera->SetPosition( motionVector[0] + viewPoint[0], motionVector[1] + viewPoint[1], motionVector[2] + viewPoint[2]);
if (Interactor->GetLightFollowCamera())
CurrentRenderer->UpdateLightsGeometryToFollowCamera();
Interactor->Render();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::Dolly()
{
if (!CurrentRenderer)
return;
int dy = Interactor->GetEventPosition()[1] - Interactor->GetLastEventPosition()[1];
Dolly(pow(1.1, MotionFactor * dy / CurrentRenderer->GetCenter()[1]));
}
void cv::viz::vtkVizInteractorStyle::Dolly(double factor)
{
if (!CurrentRenderer)
return;
vtkCamera *camera = CurrentRenderer->GetActiveCamera();
if (camera->GetParallelProjection())
camera->SetParallelScale(camera->GetParallelScale() / factor);
else
{
camera->Dolly(factor);
if (AutoAdjustCameraClippingRange)
CurrentRenderer->ResetCameraClippingRange();
}
if (Interactor->GetLightFollowCamera())
CurrentRenderer->UpdateLightsGeometryToFollowCamera();
Interactor->Render();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::Fly()
{
if (CurrentRenderer == NULL)
return;
if (KeysDown)
FlyByKey();
else
FlyByMouse();
CurrentRenderer->GetActiveCamera()->OrthogonalizeViewUp();
if (AutoAdjustCameraClippingRange)
CurrentRenderer->ResetCameraClippingRange();
if (Interactor->GetLightFollowCamera())
CurrentRenderer->UpdateLightsGeometryToFollowCamera();
}
void cv::viz::vtkVizInteractorStyle::SetupMotionVars()
{
Vec6d bounds;
CurrentRenderer->ComputeVisiblePropBounds(bounds.val);
if ( !vtkMath::AreBoundsInitialized(bounds.val) )
DiagonalLength = 1.0;
else
DiagonalLength = norm(Vec3d(bounds[0], bounds[2], bounds[4]) - Vec3d(bounds[1], bounds[3], bounds[5]));
}
void cv::viz::vtkVizInteractorStyle::MotionAlongVector(const Vec3d& vector, double amount, vtkCamera* cam)
{
// move camera and focus along DirectionOfProjection
Vec3d campos = Vec3d(cam->GetPosition()) - amount * vector;
Vec3d camfoc = Vec3d(cam->GetFocalPoint()) - amount * vector;
cam->SetPosition(campos.val);
cam->SetFocalPoint(camfoc.val);
}
void cv::viz::vtkVizInteractorStyle::FlyByMouse()
{
vtkCamera* cam = CurrentRenderer->GetActiveCamera();
double speed = DiagonalLength * MotionStepSize * MotionUserScale;
speed = speed * ( Interactor->GetShiftKey() ? MotionAccelerationFactor : 1.0);
// Sidestep
if (Interactor->GetAltKey())
{
if (DeltaYaw!=0.0)
{
vtkMatrix4x4 *vtm = cam->GetViewTransformMatrix();
Vec3d a_vector(vtm->GetElement(0,0), vtm->GetElement(0,1), vtm->GetElement(0,2));
MotionAlongVector(a_vector, -DeltaYaw*speed, cam);
}
if (DeltaPitch!=0.0)
{
Vec3d a_vector(cam->GetViewUp());
MotionAlongVector(a_vector, DeltaPitch*speed, cam);
}
}
else
{
cam->Yaw(DeltaYaw);
cam->Pitch(DeltaPitch);
DeltaYaw = 0;
DeltaPitch = 0;
}
//
if (!Interactor->GetControlKey())
{
Vec3d a_vector(cam->GetDirectionOfProjection()); // reversed (use -speed)
switch (State)
{
case VTKIS_FORWARDFLY: MotionAlongVector(a_vector, -speed, cam); break;
case VTKIS_REVERSEFLY: MotionAlongVector(a_vector, speed, cam); break;
}
}
}
void cv::viz::vtkVizInteractorStyle::FlyByKey()
{
vtkCamera* cam = CurrentRenderer->GetActiveCamera();
double speed = DiagonalLength * MotionStepSize * MotionUserScale;
speed = speed * ( Interactor->GetShiftKey() ? MotionAccelerationFactor : 1.0);
// Left and right
if (Interactor->GetAltKey())
{ // Sidestep
vtkMatrix4x4 *vtm = cam->GetViewTransformMatrix();
Vec3d a_vector(vtm->GetElement(0,0), vtm->GetElement(0,1), vtm->GetElement(0,2));
if (KeysDown & 1)
MotionAlongVector(a_vector, -speed, cam);
if (KeysDown & 2)
MotionAlongVector(a_vector, speed, cam);
}
else
{
if (KeysDown & 1)
cam->Yaw( AngleStepSize);
if (KeysDown & 2)
cam->Yaw(-AngleStepSize);
}
// Up and Down
if (Interactor->GetControlKey())
{ // Sidestep
Vec3d a_vector = Vec3d(cam->GetViewUp());
if (KeysDown & 4)
MotionAlongVector(a_vector,-speed, cam);
if (KeysDown & 8)
MotionAlongVector(a_vector, speed, cam);
}
else
{
if (KeysDown & 4)
cam->Pitch(-AngleStepSize);
if (KeysDown & 8)
cam->Pitch( AngleStepSize);
}
// forward and backward
Vec3d a_vector(cam->GetDirectionOfProjection());
if (KeysDown & 16)
MotionAlongVector(a_vector, speed, cam);
if (KeysDown & 32)
MotionAlongVector(a_vector,-speed, cam);
}
//////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::vtkVizInteractorStyle::PrintSelf(ostream& os, vtkIndent indent)
{
Superclass::PrintSelf(os, indent);
os << indent << "MotionFactor: " << MotionFactor << "\n";
os << indent << "MotionStepSize: " << MotionStepSize << "\n";
os << indent << "MotionAccelerationFactor: "<< MotionAccelerationFactor << "\n";
os << indent << "AngleStepSize: " << AngleStepSize << "\n";
os << indent << "MotionUserScale: "<< MotionUserScale << "\n";
}
......@@ -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