1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
--- a/cmake/OpenCVDetectVTK.cmake
+++ b/cmake/OpenCVDetectVTK.cmake
@@ -1,12 +1,30 @@
+# VTK 9.0
+if(NOT VTK_FOUND)
+ find_package(VTK 9 QUIET NAMES vtk COMPONENTS
+ FiltersExtraction
+ FiltersSources
+ FiltersTexture
+ IOExport
+ IOGeometry
+ IOPLY
+ InteractionStyle
+ RenderingCore
+ RenderingLOD
+ RenderingOpenGL2
+ NO_MODULE)
+endif()
+
# VTK 6.x components
-find_package(VTK QUIET COMPONENTS vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
-IF(VTK_FOUND)
- IF(VTK_RENDERING_BACKEND) #in vtk 7, the rendering backend is exported as a var.
+if(NOT VTK_FOUND)
+ find_package(VTK QUIET COMPONENTS vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
+ IF(VTK_FOUND)
+ IF(VTK_RENDERING_BACKEND) #in vtk 7, the rendering backend is exported as a var.
find_package(VTK QUIET COMPONENTS vtkRendering${VTK_RENDERING_BACKEND} vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport vtkIOGeometry NO_MODULE)
- ELSE(VTK_RENDERING_BACKEND)
+ ELSE(VTK_RENDERING_BACKEND)
find_package(VTK QUIET COMPONENTS vtkRenderingOpenGL vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
- ENDIF(VTK_RENDERING_BACKEND)
-ENDIF(VTK_FOUND)
+ ENDIF(VTK_RENDERING_BACKEND)
+ ENDIF(VTK_FOUND)
+endif()
# VTK 5.x components
if(NOT VTK_FOUND)
diff --git a/modules/viz/CMakeLists.txt b/modules/viz/CMakeLists.txt
index 256b464..92698c3 100644
--- a/modules/viz/CMakeLists.txt
+++ b/modules/viz/CMakeLists.txt
@@ -3,7 +3,6 @@ if(NOT HAVE_VTK)
endif()
set(the_description "Viz")
-include(${VTK_USE_FILE})
if(NOT BUILD_SHARED_LIBS)
# We observed conflict between builtin 3rdparty libraries and
@@ -27,7 +26,14 @@ endif()
ocv_warnings_disable(CMAKE_CXX_FLAGS -Winconsistent-missing-override -Wsuggest-override)
ocv_define_module(viz opencv_core WRAP python)
-ocv_target_link_libraries(${the_module} PRIVATE ${VTK_LIBRARIES})
+
+if (VTK_VERSION VERSION_LESS "8.90.0")
+ include(${VTK_USE_FILE})
+ ocv_target_link_libraries(${the_module} PRIVATE ${VTK_LIBRARIES})
+else ()
+ ocv_target_link_libraries(${the_module} PRIVATE ${VTK_LIBRARIES})
+ vtk_module_autoinit(TARGETS ${the_module} MODULES ${VTK_LIBRARIES})
+endif()
if(APPLE AND BUILD_opencv_viz)
ocv_target_link_libraries(${the_module} PRIVATE "-framework Cocoa")
diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp
index f92fdb6..4c4bf7c 100644
--- a/modules/viz/src/precomp.hpp
+++ b/modules/viz/src/precomp.hpp
@@ -133,7 +133,8 @@
#include <vtkColorTransferFunction.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkLight.h>
-#include "vtkCallbackCommand.h"
+#include <vtkCallbackCommand.h>
+#include <vtkVersion.h>
#if !defined(_WIN32) || defined(__CYGWIN__)
# include <unistd.h> /* unlink */
@@ -149,6 +150,11 @@
#include "vtk/vtkTrajectorySource.h"
#include "vtk/vtkImageMatSource.h"
+#if VTK_MAJOR_VERSION >= 9
+typedef vtkIdType const * CellIterT;
+#else
+typedef vtkIdType * CellIterT;
+#endif
#include <opencv2/core.hpp>
#include <opencv2/viz.hpp>
diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp
index 65571a1..e9a470c 100644
--- a/modules/viz/src/types.cpp
+++ b/modules/viz/src/types.cpp
@@ -97,10 +97,12 @@ cv::viz::Mesh cv::viz::Mesh::load(const String& file, int type)
// Now handle the polygons
vtkSmartPointer<vtkCellArray> polygons = polydata->GetPolys();
mesh.polygons.create(1, polygons->GetSize(), CV_32SC1);
+ mesh.polygons = 0;
int* poly_ptr = mesh.polygons.ptr<int>();
polygons->InitTraversal();
- vtkIdType nr_cell_points, *cell_points;
+ vtkIdType nr_cell_points;
+ CellIterT cell_points;
while (polygons->GetNextCell(nr_cell_points, cell_points))
{
*poly_ptr++ = nr_cell_points;
--- a/modules/viz/src/vizimpl.cpp
+++ b/modules/viz/src/vizimpl.cpp
@@ -55,8 +55,17 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name) : spin_once_state_(false),
// Create render window
window_ = vtkSmartPointer<vtkRenderWindow>::New();
- cv::Vec2i window_size = cv::Vec2i(window_->GetScreenSize()) / 2;
- window_->SetSize(window_size.val);
+ int * sz = window_->GetScreenSize();
+ if (sz)
+ {
+ cv::Vec2i window_size = cv::Vec2i(sz) / 2;
+ window_->SetSize(window_size.val);
+ }
+ else
+ {
+ int new_sz[2] = { 640, 480 };
+ window_->SetSize(new_sz);
+ }
window_->AddRenderer(renderer_);
// Create the interactor style
--- a/modules/viz/src/vtk/vtkOBJWriter.cpp
+++ b/modules/viz/src/vtk/vtkOBJWriter.cpp
@@ -72,7 +72,7 @@ void cv::viz::vtkOBJWriter::WriteData()
}
vtkDebugMacro(<<"Opening vtk file for writing...");
- ostream *outfilep = new ofstream(this->FileName, ios::out);
+ std::ostream *outfilep = new std::ofstream(this->FileName, ios::out);
if (outfilep->fail())
{
vtkErrorMacro(<< "Unable to open file: "<< this->FileName);
@@ -127,7 +127,8 @@ void cv::viz::vtkOBJWriter::WriteData()
// write out verts if any
if (input->GetNumberOfVerts() > 0)
{
- vtkIdType npts = 0, *index = 0;
+ vtkIdType npts = 0;
+ CellIterT index = 0;
vtkCellArray *cells = input->GetVerts();
for (cells->InitTraversal(); cells->GetNextCell(npts, index); )
{
@@ -141,7 +142,8 @@ void cv::viz::vtkOBJWriter::WriteData()
// write out lines if any
if (input->GetNumberOfLines() > 0)
{
- vtkIdType npts = 0, *index = 0;
+ vtkIdType npts = 0;
+ CellIterT index = 0;
vtkCellArray *cells = input->GetLines();
for (cells->InitTraversal(); cells->GetNextCell(npts, index); )
{
@@ -162,7 +164,8 @@ void cv::viz::vtkOBJWriter::WriteData()
// write out polys if any
if (input->GetNumberOfPolys() > 0)
{
- vtkIdType npts = 0, *index = 0;
+ vtkIdType npts = 0;
+ CellIterT index = 0;
vtkCellArray *cells = input->GetPolys();
for (cells->InitTraversal(); cells->GetNextCell(npts, index); )
{
@@ -191,7 +194,8 @@ void cv::viz::vtkOBJWriter::WriteData()
// write out tstrips if any
if (input->GetNumberOfStrips() > 0)
{
- vtkIdType npts = 0, *index = 0;
+ vtkIdType npts = 0;
+ CellIterT index = 0;
vtkCellArray *cells = input->GetStrips();
for (cells->InitTraversal(); cells->GetNextCell(npts, index); )
{
--- a/modules/viz/src/vtk/vtkXYZReader.cpp
+++ b/modules/viz/src/vtk/vtkXYZReader.cpp
@@ -77,7 +77,7 @@ int cv::viz::vtkXYZReader::RequestData(vtkInformation*, vtkInformationVector**,
}
// Open the input file.
- ifstream fin(this->FileName);
+ std::ifstream fin(this->FileName);
if(!fin)
{
vtkErrorMacro("Error opening file " << this->FileName);
--- a/modules/viz/src/vtk/vtkXYZWriter.cpp
+++ b/modules/viz/src/vtk/vtkXYZWriter.cpp
@@ -69,7 +69,7 @@ void cv::viz::vtkXYZWriter::WriteData()
}
vtkDebugMacro(<<"Opening vtk file for writing...");
- ostream *outfilep = new ofstream(this->FileName, ios::out);
+ std::ostream *outfilep = new std::ofstream(this->FileName, ios::out);
if (outfilep->fail())
{
vtkErrorMacro(<< "Unable to open file: "<< this->FileName);
--- a/modules/viz/test/test_tutorial2.cpp
+++ b/modules/viz/test/test_tutorial2.cpp
@@ -28,7 +28,7 @@ static void tutorial2()
/// Rodrigues vector
Vec3d rot_vec = Vec3d::all(0);
double translation_phase = 0.0, translation = 0.0;
- while(!myWindow.wasStopped())
+ for(unsigned num = 0; num < 50; ++num)
{
/* Rotation using rodrigues */
/// Rotate around (1,1,1)
@@ -45,7 +45,7 @@ static void tutorial2()
myWindow.setWidgetPose("Cube Widget", pose);
- myWindow.spinOnce(1, true);
+ myWindow.spinOnce(100, true);
}
}
--- a/modules/viz/test/test_tutorial3.cpp
+++ b/modules/viz/test/test_tutorial3.cpp
@@ -48,7 +48,7 @@ static void tutorial3(bool camera_pov)
myWindow.setViewerPose(camera_pose);
/// Start event loop.
- myWindow.spin();
+ myWindow.spinOnce(500, true);
}
TEST(Viz, tutorial3_global_view)
--- a/modules/viz/test/test_viz3d.cpp
+++ b/modules/viz/test/test_viz3d.cpp
@@ -59,7 +59,7 @@ TEST(Viz_viz3d, DISABLED_develop)
//cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path());
//---->>>>> </to_test_in_future>
- viz.spin();
+ viz.spinOnce(500, true);
}
}} // namespace
--- a/modules/viz/test/tests_simple.cpp
+++ b/modules/viz/test/tests_simple.cpp
@@ -56,7 +56,7 @@ TEST(Viz, show_cloud_bluberry)
viz.showWidget("dragon", WCloud(dragon_cloud, Color::bluberry()), pose);
viz.showWidget("text2d", WText("Bluberry cloud", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_cloud_random_color)
@@ -73,7 +73,7 @@ TEST(Viz, show_cloud_random_color)
viz.showWidget("coosys", WCoordinateSystem());
viz.showWidget("dragon", WCloud(dragon_cloud, colors), pose);
viz.showWidget("text2d", WText("Random color cloud", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_cloud_masked)
@@ -91,7 +91,7 @@ TEST(Viz, show_cloud_masked)
viz.showWidget("coosys", WCoordinateSystem());
viz.showWidget("dragon", WCloud(dragon_cloud), pose);
viz.showWidget("text2d", WText("Nan masked cloud", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_cloud_collection)
@@ -109,7 +109,7 @@ TEST(Viz, show_cloud_collection)
viz.showWidget("coosys", WCoordinateSystem());
viz.showWidget("ccol", ccol);
viz.showWidget("text2d", WText("Cloud collection", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_painted_clouds)
@@ -124,7 +124,7 @@ TEST(Viz, show_painted_clouds)
viz.showWidget("cloud3", WPaintedCloud(cloud, Vec3d(0.0, 0.0, -1.0), Vec3d(0.0, 0.0, 1.0), Color::blue(), Color::red()));
viz.showWidget("arrow", WArrow(Vec3d(0.0, 1.0, -1.0), Vec3d(0.0, 1.0, 1.0), 0.009, Color::raspberry()));
viz.showWidget("text2d", WText("Painted clouds", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_mesh)
@@ -137,7 +137,7 @@ TEST(Viz, show_mesh)
viz.showWidget("coosys", WCoordinateSystem());
viz.showWidget("mesh", WMesh(mesh), pose);
viz.showWidget("text2d", WText("Just mesh", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_mesh_random_colors)
@@ -152,7 +152,7 @@ TEST(Viz, show_mesh_random_colors)
viz.showWidget("mesh", WMesh(mesh), pose);
viz.setRenderingProperty("mesh", SHADING, SHADING_PHONG);
viz.showWidget("text2d", WText("Random color mesh", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_widget_merger)
@@ -173,7 +173,7 @@ TEST(Viz, show_widget_merger)
viz.showWidget("coo", WCoordinateSystem());
viz.showWidget("merger", merger);
viz.showWidget("text2d", WText("Widget merger", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_textured_mesh)
@@ -210,7 +210,7 @@ TEST(Viz, show_textured_mesh)
viz.showWidget("mesh", WMesh(mesh));
viz.setRenderingProperty("mesh", SHADING, SHADING_PHONG);
viz.showWidget("text2d", WText("Textured mesh", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_polyline)
@@ -229,7 +229,7 @@ TEST(Viz, show_polyline)
viz.showWidget("polyline", WPolyLine(polyline, colors));
viz.showWidget("coosys", WCoordinateSystem());
viz.showWidget("text2d", WText("Polyline", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_sampled_normals)
@@ -244,7 +244,7 @@ TEST(Viz, show_sampled_normals)
viz.showWidget("normals", WCloudNormals(mesh.cloud, mesh.normals, 30, 0.1f, Color::green()), pose);
viz.setRenderingProperty("normals", LINE_WIDTH, 2.0);
viz.showWidget("text2d", WText("Cloud or mesh normals", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_cloud_shaded_by_normals)
@@ -260,7 +260,7 @@ TEST(Viz, show_cloud_shaded_by_normals)
Viz3d viz("show_cloud_shaded_by_normals");
viz.showWidget("cloud", cloud, pose);
viz.showWidget("text2d", WText("Cloud shaded by normals", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_trajectories)
@@ -287,15 +287,15 @@ TEST(Viz, show_trajectories)
viz.showWidget("text2d", WText("Different kinds of supported trajectories", Point(20, 20), 20, Color::green()));
int i = 0;
- while(!viz.wasStopped())
+ for(unsigned num = 0; num < 50; ++num)
{
double a = --i % 360;
Vec3d pose(sin(a * CV_PI/180), 0.7, cos(a * CV_PI/180));
viz.setViewerPose(makeCameraPose(pose * 7.5, Vec3d(0.0, 0.5, 0.0), Vec3d(0.0, 0.1, 0.0)));
- viz.spinOnce(20, true);
+ viz.spinOnce(100, true);
}
viz.resetCamera();
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_trajectory_reposition)
@@ -306,7 +306,7 @@ TEST(Viz, show_trajectory_reposition)
viz.showWidget("coos", WCoordinateSystem());
viz.showWidget("sub3", WTrajectory(Mat(path).rowRange(0, (int)path.size()/3), WTrajectory::BOTH, 0.2, Color::brown()), path.front().inv());
viz.showWidget("text2d", WText("Trajectory resposition to origin", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_camera_positions)
@@ -330,7 +330,7 @@ TEST(Viz, show_camera_positions)
viz.showWidget("pos3", WCameraPosition(0.75), poses[1]);
viz.showWidget("pos4", WCameraPosition(K, gray, 3, Color::indigo()), poses[1]);
viz.showWidget("text2d", WText("Camera positions with images", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_overlay_image)
@@ -353,16 +353,16 @@ TEST(Viz, show_overlay_image)
viz.showWidget("text2d", WText("Overlay images", Point(20, 20), 20, Color::green()));
int i = 0;
- while(!viz.wasStopped())
+ for(unsigned num = 0; num < 50; ++num)
{
double a = ++i % 360;
Vec3d pose(sin(a * CV_PI/180), 0.7, cos(a * CV_PI/180));
viz.setViewerPose(makeCameraPose(pose * 3, Vec3d(0.0, 0.5, 0.0), Vec3d(0.0, 0.1, 0.0)));
viz.getWidget("img1").cast<WImageOverlay>().setImage(lena * pow(sin(i*10*CV_PI/180) * 0.5 + 0.5, 1.0));
- viz.spinOnce(1, true);
+ viz.spinOnce(100, true);
}
viz.showWidget("text2d", WText("Overlay images (stopped)", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
@@ -376,7 +376,7 @@ TEST(Viz, show_image_method)
viz.showImage(lena, lena.size());
viz.spinOnce(1500, true);
- cv::viz::imshow("show_image_method", make_gray(lena)).spin();
+ cv::viz::imshow("show_image_method", make_gray(lena)).spinOnce(500, true);
}
TEST(Viz, show_image_3d)
@@ -398,13 +398,13 @@ TEST(Viz, show_image_3d)
viz.showWidget("text2d", WText("Images in 3D", Point(20, 20), 20, Color::green()));
int i = 0;
- while(!viz.wasStopped())
+ for(unsigned num = 0; num < 50; ++num)
{
viz.getWidget("img0").cast<WImage3D>().setImage(lena * pow(sin(i++*7.5*CV_PI/180) * 0.5 + 0.5, 1.0));
- viz.spinOnce(1, true);
+ viz.spinOnce(100, true);
}
viz.showWidget("text2d", WText("Images in 3D (stopped)", Point(20, 20), 20, Color::green()));
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_simple_widgets)
@@ -431,10 +431,10 @@ TEST(Viz, show_simple_widgets)
viz.showWidget("grid1", WGrid(Vec2i(7,7), Vec2d::all(0.75), Color::gray()), Affine3d().translate(Vec3d(0.0, 0.0, -1.0)));
- viz.spin();
+ viz.spinOnce(500, true);
viz.getWidget("text2d").cast<WText>().setText("Different simple widgets (updated)");
viz.getWidget("text3d").cast<WText3D>().setText("Updated text 3D");
- viz.spin();
+ viz.spinOnce(500, true);
}
TEST(Viz, show_follower)
@@ -446,9 +446,9 @@ TEST(Viz, show_follower)
viz.showWidget("t3d_2", WText3D("Simple 3D follower", Point3d(-0.5, -0.5, 0.5), 0.125, true, Color::green()));
viz.showWidget("text2d", WText("Follower: text always facing camera", Point(20, 20), 20, Color::green()));
viz.setBackgroundMeshLab();
- viz.spin();
+ viz.spinOnce(500, true);
viz.getWidget("t3d_2").cast<WText3D>().setText("Updated follower 3D");
- viz.spin();
+ viz.spinOnce(500, true);
}
}} // namespace
|