Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/viz/src/vizimpl.cpp
16354 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of the copyright holders may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
// Authors:
41
// * Ozan Tonkal, [email protected]
42
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
43
//
44
//M*/
45
46
#include "precomp.hpp"
47
48
49
/////////////////////////////////////////////////////////////////////////////////////////////
50
cv::viz::Viz3d::VizImpl::VizImpl(const String &name) : spin_once_state_(false),
51
window_position_(Vec2i(std::numeric_limits<int>::min())), widget_actor_map_(new WidgetActorMap)
52
{
53
renderer_ = vtkSmartPointer<vtkRenderer>::New();
54
window_name_ = VizStorage::generateWindowName(name);
55
56
// Create render window
57
window_ = vtkSmartPointer<vtkRenderWindow>::New();
58
cv::Vec2i window_size = cv::Vec2i(window_->GetScreenSize()) / 2;
59
window_->SetSize(window_size.val);
60
window_->AddRenderer(renderer_);
61
62
// Create the interactor style
63
style_ = vtkSmartPointer<vtkVizInteractorStyle>::New();
64
style_->setWidgetActorMap(widget_actor_map_);
65
style_->UseTimersOn();
66
67
timer_callback_ = vtkSmartPointer<TimerCallback>::New();
68
exit_callback_ = vtkSmartPointer<ExitCallback>::New();
69
exit_callback_->viz = this;
70
71
offScreenMode_ = false;
72
73
setBackgroundMeshLab();
74
}
75
76
cv::viz::Viz3d::VizImpl::~VizImpl() { close(); }
77
78
/////////////////////////////////////////////////////////////////////////////////////////////
79
void cv::viz::Viz3d::VizImpl::TimerCallback::Execute(vtkObject* caller, unsigned long event_id, void* cookie)
80
{
81
if (event_id == vtkCommand::TimerEvent && timer_id == *reinterpret_cast<int*>(cookie))
82
{
83
vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkRenderWindowInteractor::SafeDownCast(caller);
84
interactor->TerminateApp();
85
}
86
}
87
88
void cv::viz::Viz3d::VizImpl::ExitCallback::Execute(vtkObject*, unsigned long event_id, void*)
89
{
90
if (event_id == vtkCommand::ExitEvent && viz->interactor_)
91
{
92
viz->interactor_->TerminateApp();
93
viz->interactor_ = 0;
94
}
95
}
96
97
/////////////////////////////////////////////////////////////////////////////////////////////
98
99
bool cv::viz::Viz3d::VizImpl::wasStopped() const
100
{
101
bool stopped = spin_once_state_ ? interactor_ == 0 : false;
102
spin_once_state_ &= !stopped;
103
return stopped;
104
}
105
106
void cv::viz::Viz3d::VizImpl::close()
107
{
108
if (!interactor_)
109
return;
110
interactor_->GetRenderWindow()->Finalize();
111
interactor_->TerminateApp(); // This tends to close the window...
112
interactor_ = 0;
113
}
114
115
void cv::viz::Viz3d::VizImpl::recreateRenderWindow()
116
{
117
#if !defined _MSC_VER && !defined __APPLE__
118
//recreating is workaround for Ubuntu -- a crash in x-server
119
Vec2i window_size(window_->GetSize());
120
int fullscreen = window_->GetFullScreen();
121
122
window_->Finalize();
123
window_ = vtkSmartPointer<vtkRenderWindow>::New();
124
if (window_position_[0] != std::numeric_limits<int>::min()) //also workaround
125
window_->SetPosition(window_position_.val);
126
127
window_->SetSize(window_size.val);
128
window_->SetFullScreen(fullscreen);
129
window_->AddRenderer(renderer_);
130
#endif
131
}
132
133
/////////////////////////////////////////////////////////////////////////////////////////////
134
void cv::viz::Viz3d::VizImpl::spin()
135
{
136
recreateRenderWindow();
137
#if defined __APPLE__
138
interactor_ = vtkCocoaRenderWindowInteractorNew();
139
#else
140
interactor_ = vtkSmartPointer<vtkRenderWindowInteractor>::New();
141
#endif
142
interactor_->SetRenderWindow(window_);
143
interactor_->SetInteractorStyle(style_);
144
window_->AlphaBitPlanesOff();
145
window_->PointSmoothingOff();
146
window_->LineSmoothingOff();
147
window_->PolygonSmoothingOff();
148
window_->SwapBuffersOn();
149
window_->SetStereoTypeToAnaglyph();
150
window_->Render();
151
window_->SetWindowName(window_name_.c_str());
152
interactor_->Start();
153
interactor_ = 0;
154
}
155
156
/////////////////////////////////////////////////////////////////////////////////////////////
157
void cv::viz::Viz3d::VizImpl::spinOnce(int time, bool force_redraw)
158
{
159
if (interactor_ == 0)
160
{
161
spin_once_state_ = true;
162
recreateRenderWindow();
163
#if defined __APPLE__
164
interactor_ = vtkCocoaRenderWindowInteractorNew();
165
#else
166
interactor_ = vtkSmartPointer<vtkRenderWindowInteractor>::New();
167
#endif
168
interactor_->SetRenderWindow(window_);
169
interactor_->SetInteractorStyle(style_);
170
interactor_->AddObserver(vtkCommand::TimerEvent, timer_callback_);
171
interactor_->AddObserver(vtkCommand::ExitEvent, exit_callback_);
172
window_->AlphaBitPlanesOff();
173
window_->PointSmoothingOff();
174
window_->LineSmoothingOff();
175
window_->PolygonSmoothingOff();
176
window_->SwapBuffersOn();
177
window_->SetStereoTypeToAnaglyph();
178
window_->Render();
179
window_->SetWindowName(window_name_.c_str());
180
}
181
182
vtkSmartPointer<vtkRenderWindowInteractor> local = interactor_;
183
184
if (force_redraw)
185
local->Render();
186
187
timer_callback_->timer_id = local->CreateRepeatingTimer(std::max(1, time));
188
local->Start();
189
local->DestroyTimer(timer_callback_->timer_id);
190
}
191
192
/////////////////////////////////////////////////////////////////////////////////////////////
193
void cv::viz::Viz3d::VizImpl::setOffScreenRendering()
194
{
195
window_->SetOffScreenRendering(1);
196
offScreenMode_ = true;
197
}
198
199
/////////////////////////////////////////////////////////////////////////////////////////////
200
void cv::viz::Viz3d::VizImpl::removeAllLights()
201
{
202
renderer_->RemoveAllLights();
203
}
204
205
/////////////////////////////////////////////////////////////////////////////////////////////
206
void cv::viz::Viz3d::VizImpl::addLight(Vec3d position, Vec3d focalPoint, Color color, Color diffuseColor, Color ambientColor, Color specularColor)
207
{
208
Color color_ = vtkcolor(color);
209
Color diffuseColor_ = vtkcolor(diffuseColor);
210
Color ambientColor_ = vtkcolor(ambientColor);
211
Color specularColor_ = vtkcolor(specularColor);
212
213
vtkSmartPointer<vtkLight> light = vtkSmartPointer<vtkLight>::New();
214
light->SetPosition(position.val);
215
light->SetFocalPoint(focalPoint.val);
216
light->SetColor(color_.val);
217
light->SetDiffuseColor(diffuseColor_.val);
218
light->SetAmbientColor(ambientColor_.val);
219
light->SetSpecularColor(specularColor_.val);
220
221
renderer_->AddLight(light);
222
}
223
224
/////////////////////////////////////////////////////////////////////////////////////////////
225
void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, const Affine3d &pose)
226
{
227
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id);
228
bool exists = wam_itr != widget_actor_map_->end();
229
if (exists)
230
{
231
// Remove it if it exists and add it again
232
removeActorFromRenderer(wam_itr->second);
233
}
234
// Get the actor and set the user matrix
235
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(widget));
236
if (actor)
237
{
238
// If the actor is 3D, apply pose
239
vtkSmartPointer<vtkMatrix4x4> matrix = vtkmatrix(pose.matrix);
240
actor->SetUserMatrix(matrix);
241
actor->Modified();
242
}
243
// If the actor is a vtkFollower, then it should always face the camera
244
vtkFollower *follower = vtkFollower::SafeDownCast(actor);
245
if (follower)
246
{
247
follower->SetCamera(renderer_->GetActiveCamera());
248
}
249
250
renderer_->AddActor(WidgetAccessor::getProp(widget));
251
(*widget_actor_map_)[id] = WidgetAccessor::getProp(widget);
252
}
253
254
/////////////////////////////////////////////////////////////////////////////////////////////
255
void cv::viz::Viz3d::VizImpl::removeWidget(const String &id)
256
{
257
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id);
258
bool exists = wam_itr != widget_actor_map_->end();
259
CV_Assert("Widget does not exist." && exists);
260
CV_Assert("Widget could not be removed." && removeActorFromRenderer(wam_itr->second));
261
widget_actor_map_->erase(wam_itr);
262
}
263
264
/////////////////////////////////////////////////////////////////////////////////////////////
265
cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const
266
{
267
WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id);
268
bool exists = wam_itr != widget_actor_map_->end();
269
CV_Assert("Widget does not exist." && exists);
270
271
Widget widget;
272
WidgetAccessor::setProp(widget, wam_itr->second);
273
return widget;
274
}
275
276
/////////////////////////////////////////////////////////////////////////////////////////////
277
void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3d &pose)
278
{
279
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id);
280
bool exists = wam_itr != widget_actor_map_->end();
281
CV_Assert("Widget does not exist." && exists);
282
283
vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second);
284
CV_Assert("Widget is not 3D." && actor);
285
286
vtkSmartPointer<vtkMatrix4x4> matrix = vtkmatrix(pose.matrix);
287
actor->SetUserMatrix(matrix);
288
actor->Modified();
289
}
290
291
/////////////////////////////////////////////////////////////////////////////////////////////
292
void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3d &pose)
293
{
294
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id);
295
bool exists = wam_itr != widget_actor_map_->end();
296
CV_Assert("Widget does not exist." && exists);
297
298
vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second);
299
CV_Assert("Widget is not 3D." && actor);
300
301
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
302
if (!matrix)
303
{
304
setWidgetPose(id, pose);
305
return ;
306
}
307
Affine3d updated_pose = pose * Affine3d(*matrix->Element);
308
matrix = vtkmatrix(updated_pose.matrix);
309
310
actor->SetUserMatrix(matrix);
311
actor->Modified();
312
}
313
314
/////////////////////////////////////////////////////////////////////////////////////////////
315
cv::Affine3d cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const
316
{
317
WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id);
318
bool exists = wam_itr != widget_actor_map_->end();
319
CV_Assert("Widget does not exist." && exists);
320
321
vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second);
322
CV_Assert("Widget is not 3D." && actor);
323
324
return Affine3d(*actor->GetUserMatrix()->Element);
325
}
326
327
/////////////////////////////////////////////////////////////////////////////////////////////
328
void cv::viz::Viz3d::VizImpl::saveScreenshot(const String &file) { style_->saveScreenshot(file.c_str()); }
329
330
/////////////////////////////////////////////////////////////////////////////////////////////
331
cv::Mat cv::viz::Viz3d::VizImpl::getScreenshot() const
332
{
333
vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
334
vtkSmartPointer<vtkWindowToImageFilter>::New();
335
windowToImageFilter->SetInput(window_);
336
windowToImageFilter->ReadFrontBufferOff(); // read from the back buffer
337
windowToImageFilter->Update();
338
339
vtkImageData *resultImage = windowToImageFilter->GetOutput();
340
int * dim = resultImage->GetDimensions();
341
cv::Mat image(dim[1], dim[0], CV_8UC3);
342
343
Vec3b* dptr = reinterpret_cast<Vec3b*>(resultImage->GetScalarPointer());
344
size_t elem_step = resultImage->GetIncrements()[1]/sizeof(Vec3b);
345
346
for (int y = 0; y < image.rows; ++y)
347
{
348
const Vec3b* drow = dptr + elem_step * y;
349
unsigned char *srow = image.ptr<unsigned char>(image.rows - y - 1);
350
for (int x = 0; x < image.cols; ++x, srow += image.channels())
351
{
352
srow[0] = drow[x][2];
353
srow[1] = drow[x][1];
354
srow[2] = drow[x][0];
355
}
356
}
357
358
resultImage = 0;
359
360
return image;
361
}
362
363
/////////////////////////////////////////////////////////////////////////////////////////////
364
void cv::viz::Viz3d::VizImpl::registerMouseCallback(MouseCallback callback, void* cookie)
365
{ style_->registerMouseCallback(callback, cookie); }
366
367
void cv::viz::Viz3d::VizImpl::registerKeyboardCallback(KeyboardCallback callback, void* cookie)
368
{ style_->registerKeyboardCallback(callback, cookie); }
369
370
371
//////////////////////////////////////////////////////////////////////////////////////////
372
void cv::viz::Viz3d::VizImpl::removeAllWidgets()
373
{
374
widget_actor_map_->clear();
375
renderer_->RemoveAllViewProps();
376
}
377
/////////////////////////////////////////////////////////////////////////////////////////////
378
void cv::viz::Viz3d::VizImpl::showImage(InputArray image, const Size& window_size)
379
{
380
removeAllWidgets();
381
if (window_size.width > 0 && window_size.height > 0)
382
setWindowSize(window_size);
383
384
showWidget("showImage", WImageOverlay(image, Rect(Point(0,0), getWindowSize())));
385
}
386
387
/////////////////////////////////////////////////////////////////////////////////////////////
388
bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer(vtkSmartPointer<vtkProp> actor)
389
{
390
vtkPropCollection* actors = renderer_->GetViewProps();
391
actors->InitTraversal();
392
vtkProp* current_actor = NULL;
393
while ((current_actor = actors->GetNextProp()) != NULL)
394
if (current_actor == actor)
395
{
396
renderer_->RemoveActor(actor);
397
return true;
398
}
399
return false;
400
}
401
402
//////////////////////////////////////////////////////////////////////////////////////////////
403
void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color, const Color& color2)
404
{
405
Color c = vtkcolor(color), c2 = vtkcolor(color2);
406
bool gradient = color2[0] >= 0 && color2[1] >= 0 && color2[2] >= 0;
407
408
if (gradient)
409
{
410
renderer_->SetBackground(c2.val);
411
renderer_->SetBackground2(c.val);
412
renderer_->GradientBackgroundOn();
413
}
414
else
415
{
416
renderer_->SetBackground(c.val);
417
renderer_->GradientBackgroundOff();
418
}
419
}
420
421
void cv::viz::Viz3d::VizImpl::setBackgroundMeshLab()
422
{ setBackgroundColor(Color(2, 1, 1), Color(240, 120, 120)); }
423
424
//////////////////////////////////////////////////////////////////////////////////////////////
425
void cv::viz::Viz3d::VizImpl::setBackgroundTexture(InputArray image)
426
{
427
if (image.empty())
428
{
429
renderer_->SetBackgroundTexture(0);
430
renderer_->TexturedBackgroundOff();
431
return;
432
}
433
434
vtkSmartPointer<vtkImageMatSource> source = vtkSmartPointer<vtkImageMatSource>::New();
435
source->SetImage(image);
436
437
vtkSmartPointer<vtkImageFlip> image_flip = vtkSmartPointer<vtkImageFlip>::New();
438
image_flip->SetFilteredAxis(1); // Vertical flip
439
image_flip->SetInputConnection(source->GetOutputPort());
440
441
vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
442
texture->SetInputConnection(image_flip->GetOutputPort());
443
//texture->Update();
444
445
renderer_->SetBackgroundTexture(texture);
446
renderer_->TexturedBackgroundOn();
447
}
448
449
/////////////////////////////////////////////////////////////////////////////////////////////
450
void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
451
{
452
vtkSmartPointer<vtkCamera> active_camera = renderer_->GetActiveCamera();
453
454
// Set the intrinsic parameters of the camera
455
window_->SetSize(camera.getWindowSize().width, camera.getWindowSize().height);
456
double aspect_ratio = static_cast<double>(camera.getWindowSize().width)/static_cast<double>(camera.getWindowSize().height);
457
458
Matx44d proj_mat;
459
camera.computeProjectionMatrix(proj_mat);
460
461
// Use the intrinsic parameters of the camera to simulate more realistically
462
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = active_camera->GetProjectionTransformMatrix(aspect_ratio, -1.0, 1.0);
463
Matx44d old_proj_mat(*vtk_matrix->Element);
464
465
// This is a hack around not being able to set Projection Matrix
466
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
467
transform->SetMatrix(vtkmatrix(proj_mat * old_proj_mat.inv()));
468
active_camera->SetUserTransform(transform);
469
470
renderer_->ResetCameraClippingRange();
471
renderer_->Render();
472
}
473
474
/////////////////////////////////////////////////////////////////////////////////////////////
475
cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
476
{
477
vtkSmartPointer<vtkCamera> active_camera = renderer_->GetActiveCamera();
478
479
Size window_size(renderer_->GetRenderWindow()->GetSize()[0],
480
renderer_->GetRenderWindow()->GetSize()[1]);
481
double aspect_ratio = window_size.width / (double)window_size.height;
482
483
vtkSmartPointer<vtkMatrix4x4> proj_matrix = active_camera->GetProjectionTransformMatrix(aspect_ratio, -1.0f, 1.0f);
484
return Camera(Matx44d(*proj_matrix->Element), window_size);
485
}
486
487
/////////////////////////////////////////////////////////////////////////////////////////////
488
void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3d &pose)
489
{
490
vtkCamera& camera = *renderer_->GetActiveCamera();
491
492
// Position = extrinsic translation
493
cv::Vec3d pos_vec = pose.translation();
494
495
// Rotate the view vector
496
cv::Matx33d rotation = pose.rotation();
497
cv::Vec3d y_axis(0.0, -1.0, 0.0); // In Computer Vision Camera Y-axis is oriented down
498
cv::Vec3d up_vec(rotation * y_axis);
499
500
// Compute the new focal point
501
cv::Vec3d z_axis(0.0, 0.0, 1.0);
502
cv::Vec3d focal_vec = pose * z_axis;
503
504
camera.SetPosition(pos_vec.val);
505
camera.SetFocalPoint(focal_vec.val);
506
camera.SetViewUp(up_vec.val);
507
508
renderer_->ResetCameraClippingRange();
509
}
510
511
/////////////////////////////////////////////////////////////////////////////////////////////
512
cv::Affine3d cv::viz::Viz3d::VizImpl::getViewerPose() const
513
{
514
vtkCamera& camera = *renderer_->GetActiveCamera();
515
516
Vec3d pos(camera.GetPosition());
517
Vec3d view_up(camera.GetViewUp());
518
Vec3d focal(camera.GetFocalPoint());
519
520
Vec3d y_axis = normalized(-view_up); // In Computer Vision Camera Y-axis is oriented down
521
Vec3d z_axis = normalized(focal - pos);
522
Vec3d x_axis = normalized(y_axis.cross(z_axis));
523
524
return makeTransformToGlobal(x_axis, y_axis, z_axis, pos);
525
}
526
527
/////////////////////////////////////////////////////////////////////////////////////////////
528
void cv::viz::Viz3d::VizImpl::convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord)
529
{
530
Vec3d window_pt;
531
vtkInteractorObserver::ComputeWorldToDisplay(renderer_, pt.x, pt.y, pt.z, window_pt.val);
532
window_coord = window_pt;
533
}
534
535
/////////////////////////////////////////////////////////////////////////////////////////////
536
void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction)
537
{
538
Vec4d world_pt;
539
vtkInteractorObserver::ComputeDisplayToWorld(renderer_, window_coord.x, window_coord.y, window_coord.z, world_pt.val);
540
Vec3d cam_pos(renderer_->GetActiveCamera()->GetPosition());
541
origin = cam_pos;
542
direction = normalize(Vec3d(world_pt.val) - cam_pos);
543
}
544
545
/////////////////////////////////////////////////////////////////////////////////////////////
546
void cv::viz::Viz3d::VizImpl::resetCameraViewpoint(const String &id)
547
{
548
vtkSmartPointer<vtkMatrix4x4> camera_pose;
549
static WidgetActorMap::iterator it = widget_actor_map_->find(id);
550
if (it != widget_actor_map_->end())
551
{
552
vtkProp3D *actor = vtkProp3D::SafeDownCast(it->second);
553
CV_Assert("Widget is not 3D." && actor);
554
camera_pose = actor->GetUserMatrix();
555
}
556
else
557
return;
558
559
// Prevent a segfault
560
if (!camera_pose) return;
561
562
vtkSmartPointer<vtkCamera> cam = renderer_->GetActiveCamera();
563
cam->SetPosition(camera_pose->GetElement(0, 3),
564
camera_pose->GetElement(1, 3),
565
camera_pose->GetElement(2, 3));
566
567
cam->SetFocalPoint(camera_pose->GetElement(0, 3) - camera_pose->GetElement(0, 2),
568
camera_pose->GetElement(1, 3) - camera_pose->GetElement(1, 2),
569
camera_pose->GetElement(2, 3) - camera_pose->GetElement(2, 2));
570
571
cam->SetViewUp(camera_pose->GetElement(0, 1),
572
camera_pose->GetElement(1, 1),
573
camera_pose->GetElement(2, 1));
574
575
renderer_->SetActiveCamera(cam);
576
renderer_->ResetCameraClippingRange();
577
renderer_->ResetCamera();
578
renderer_->Render();
579
}
580
581
///////////////////////////////////////////////////////////////////////////////////
582
void cv::viz::Viz3d::VizImpl::resetCamera()
583
{
584
renderer_->ResetCamera();
585
}
586
587
///////////////////////////////////////////////////////////////////////////////////
588
void cv::viz::Viz3d::VizImpl::setRepresentation(int representation)
589
{
590
vtkActorCollection * actors = renderer_->GetActors();
591
actors->InitTraversal();
592
vtkActor * actor;
593
switch (representation)
594
{
595
case REPRESENTATION_POINTS:
596
{
597
while ((actor = actors->GetNextActor()) != NULL)
598
actor->GetProperty()->SetRepresentationToPoints();
599
break;
600
}
601
case REPRESENTATION_SURFACE:
602
{
603
while ((actor = actors->GetNextActor()) != NULL)
604
actor->GetProperty()->SetRepresentationToSurface();
605
break;
606
}
607
case REPRESENTATION_WIREFRAME:
608
{
609
while ((actor = actors->GetNextActor()) != NULL)
610
actor->GetProperty()->SetRepresentationToWireframe();
611
break;
612
}
613
}
614
}
615
616
//////////////////////////////////////////////////////////////////////////////////////////////
617
cv::String cv::viz::Viz3d::VizImpl::getWindowName() const { return window_name_; }
618
void cv::viz::Viz3d::VizImpl::setFullScreen(bool mode) { window_->SetFullScreen(mode); }
619
void cv::viz::Viz3d::VizImpl::setWindowPosition(const Point& position) { window_position_ = position; window_->SetPosition(position.x, position.y); }
620
void cv::viz::Viz3d::VizImpl::setWindowSize(const Size& window_size) { window_->SetSize(window_size.width, window_size.height); }
621
cv::Size cv::viz::Viz3d::VizImpl::getWindowSize() const { return Size(Point(Vec2i(window_->GetSize()))); }
622
623