From d7ca0bb757c38d4f54f5c8e565f211fdaa7dab66 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sat, 18 Jan 2014 22:25:40 +0400 Subject: [PATCH] merged background color with background gradient methods, updated tests to show description of scene --- modules/viz/include/opencv2/viz/types.hpp | 4 +++ modules/viz/include/opencv2/viz/viz3d.hpp | 3 +-- modules/viz/src/shapes.cpp | 6 +++-- modules/viz/src/viz3d.cpp | 3 +-- modules/viz/src/vizimpl.cpp | 30 ++++++++++++----------- modules/viz/src/vizimpl.hpp | 3 +-- modules/viz/test/test_viz3d.cpp | 3 ++- modules/viz/test/tests_simple.cpp | 25 ++++++++++++++++--- 8 files changed, 51 insertions(+), 26 deletions(-) diff --git a/modules/viz/include/opencv2/viz/types.hpp b/modules/viz/include/opencv2/viz/types.hpp index e61c837be..3c3571b83 100644 --- a/modules/viz/include/opencv2/viz/types.hpp +++ b/modules/viz/include/opencv2/viz/types.hpp @@ -102,6 +102,8 @@ namespace cv static Color turquoise(); static Color celestial_blue(); static Color amethyst(); + + static Color not_set(); }; class CV_EXPORTS Mesh @@ -229,4 +231,6 @@ inline cv::viz::Color cv::viz::Color::turquoise() { return Color(208, 224, inline cv::viz::Color cv::viz::Color::celestial_blue() { return Color(208, 151, 73); } inline cv::viz::Color cv::viz::Color::amethyst() { return Color(204, 102, 153); } +inline cv::viz::Color cv::viz::Color::not_set() { return Color(-1, -1, -1); } + #endif diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index 090c8b14e..a83d8e8fc 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -98,9 +98,8 @@ namespace cv void saveScreenshot(const String &file); void setWindowPosition(const Point& window_position); void setFullScreen(bool mode = true); - void setBackgroundColor(const Color& color = Color::black()); + void setBackgroundColor(const Color& color = Color::black(), const Color& color2 = Color::not_set()); void setBackgroundTexture(InputArray image = noArray()); - void setBackgroundGradient(const Color& up, const Color& down); void setBackgroundMeshLab(); void spin(); diff --git a/modules/viz/src/shapes.cpp b/modules/viz/src/shapes.cpp index 323482fa4..9011d0b18 100644 --- a/modules/viz/src/shapes.cpp +++ b/modules/viz/src/shapes.cpp @@ -549,12 +549,14 @@ template<> cv::viz::WText3D cv::viz::Widget::cast() cv::viz::WText::WText(const String &text, const Point &pos, int font_size, const Color &color) { vtkSmartPointer actor = vtkSmartPointer::New(); - actor->SetPosition(pos.x, pos.y); + actor->SetDisplayPosition(pos.x, pos.y); actor->SetInput(text.c_str()); + actor->GetProperty()->SetDisplayLocationToForeground(); + vtkSmartPointer tprop = actor->GetTextProperty(); tprop->SetFontSize(font_size); - tprop->SetFontFamilyToArial(); + tprop->SetFontFamilyToCourier(); tprop->SetJustificationToLeft(); tprop->BoldOn(); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 237ef87c9..2d4aefc0b 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -136,8 +136,7 @@ cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName() void cv::viz::Viz3d::saveScreenshot(const String &file) { impl_->saveScreenshot(file); } void cv::viz::Viz3d::setWindowPosition(const Point& window_position) { impl_->setWindowPosition(window_position); } void cv::viz::Viz3d::setFullScreen(bool mode) { impl_->setFullScreen(mode); } -void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); } -void cv::viz::Viz3d::setBackgroundGradient(const Color& up, const Color& down) { impl_->setBackgroundGradient(up, down); } +void cv::viz::Viz3d::setBackgroundColor(const Color& color, const Color& color2) { impl_->setBackgroundColor(color, color2); } void cv::viz::Viz3d::setBackgroundTexture(InputArray image) { impl_->setBackgroundTexture(image); } void cv::viz::Viz3d::setBackgroundMeshLab() {impl_->setBackgroundMeshLab(); } diff --git a/modules/viz/src/vizimpl.cpp b/modules/viz/src/vizimpl.cpp index e66b53823..e50666ec8 100644 --- a/modules/viz/src/vizimpl.cpp +++ b/modules/viz/src/vizimpl.cpp @@ -143,10 +143,9 @@ void cv::viz::Viz3d::VizImpl::spinOnce(int time, bool force_redraw) if (force_redraw) local->Render(); - timer_callback_->timer_id = local->CreateOneShotTimer(std::max(1, time)); + timer_callback_->timer_id = local->CreateRepeatingTimer(std::max(1, time)); local->Start(); local->DestroyTimer(timer_callback_->timer_id); - } ///////////////////////////////////////////////////////////////////////////////////////////// @@ -295,23 +294,26 @@ bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer(vtkSmartPointer a } ////////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color) +void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color, const Color& color2) { - Color c = vtkcolor(color); - renderer_->SetBackground(c.val); - renderer_->GradientBackgroundOff(); -} + Color c = vtkcolor(color), c2 = vtkcolor(color2); + bool gradient = color2[0] >= 0 && color2[1] >= 0 && color2[2] >= 0; -void cv::viz::Viz3d::VizImpl::setBackgroundGradient(const Color& up, const Color& down) -{ - Color vtkup = vtkcolor(up), vtkdown = vtkcolor(down); - renderer_->SetBackground(vtkdown.val); - renderer_->SetBackground2(vtkup.val); - renderer_->GradientBackgroundOn(); + if (gradient) + { + renderer_->SetBackground(c2.val); + renderer_->SetBackground2(c.val); + renderer_->GradientBackgroundOn(); + } + else + { + renderer_->SetBackground(c.val); + renderer_->GradientBackgroundOff(); + } } void cv::viz::Viz3d::VizImpl::setBackgroundMeshLab() -{ setBackgroundGradient(Color(2, 1, 1), Color(240, 120, 120)); } +{ setBackgroundColor(Color(2, 1, 1), Color(240, 120, 120)); } ////////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::setBackgroundTexture(InputArray image) diff --git a/modules/viz/src/vizimpl.hpp b/modules/viz/src/vizimpl.hpp index 1b9abea64..11e22ee5d 100644 --- a/modules/viz/src/vizimpl.hpp +++ b/modules/viz/src/vizimpl.hpp @@ -95,8 +95,7 @@ public: void setWindowSize(const Size& window_size); void setFullScreen(bool mode); String getWindowName() const; - void setBackgroundColor(const Color& color); - void setBackgroundGradient(const Color& up, const Color& down); + void setBackgroundColor(const Color& color, const Color& color2); void setBackgroundTexture(InputArray image); void setBackgroundMeshLab(); diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index bdfda6d9b..45d3cdc3c 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -43,7 +43,7 @@ using namespace cv; -TEST(Viz_viz3d, develop) +TEST(Viz_viz3d, DISABLED_develop) { cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path()); @@ -59,5 +59,6 @@ TEST(Viz_viz3d, develop) //cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path()); //---->>>>> + viz.spin(); } diff --git a/modules/viz/test/tests_simple.cpp b/modules/viz/test/tests_simple.cpp index dad4aacca..46f0e59b5 100644 --- a/modules/viz/test/tests_simple.cpp +++ b/modules/viz/test/tests_simple.cpp @@ -54,6 +54,8 @@ TEST(Viz, show_cloud_bluberry) Viz3d viz("show_cloud_bluberry"); viz.showWidget("coosys", WCoordinateSystem()); viz.showWidget("dragon", WCloud(dragon_cloud, Color::bluberry()), pose); + + viz.showWidget("text2d", WText("Bluberry cloud", Point(20, 20), 20, Color::green())); viz.spin(); } @@ -70,6 +72,7 @@ TEST(Viz, show_cloud_random_color) viz.setBackgroundMeshLab(); 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(); } @@ -87,6 +90,7 @@ TEST(Viz, show_cloud_masked) Viz3d 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(); } @@ -100,8 +104,10 @@ TEST(Viz, show_cloud_collection) ccol.addCloud(cloud, Color::red(), Affine3d().translate(Vec3d(2, 0, 0))); Viz3d viz("show_cloud_collection"); + viz.setBackgroundColor(Color::mlab()); viz.showWidget("coosys", WCoordinateSystem()); viz.showWidget("ccol", ccol); + viz.showWidget("text2d", WText("Cloud collection", Point(20, 20), 20, Color::green())); viz.spin(); } @@ -116,6 +122,7 @@ TEST(Viz, show_painted_clouds) viz.showWidget("cloud2", WPaintedCloud(cloud, Vec3d(0.0, -0.75, -1.0), Vec3d(0.0, 0.75, 0.0)), Affine3d(Vec3d(0.0, CV_PI/2, 0.0), Vec3d(1.5, 0.0, 0.0))); 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(); } @@ -128,6 +135,7 @@ TEST(Viz, show_mesh) Viz3d 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(); } @@ -142,6 +150,7 @@ TEST(Viz, show_mesh_random_colors) viz.showWidget("coosys", WCoordinateSystem()); 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(); } @@ -178,6 +187,7 @@ TEST(Viz, show_textured_mesh) viz.showWidget("coosys", WCoordinateSystem()); 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(); } @@ -190,6 +200,7 @@ TEST(Viz, show_polyline) Viz3d viz("show_polyline"); viz.showWidget("polyline", WPolyLine(Mat(polyline), Color::apricot())); viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("text2d", WText("Polyline", Point(20, 20), 20, Color::green())); viz.spin(); } @@ -204,6 +215,7 @@ TEST(Viz, show_sampled_normals) viz.showWidget("mesh", WMesh(mesh), pose); 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(); } @@ -227,6 +239,7 @@ TEST(Viz, show_trajectories) viz.showWidget("sub3", WTrajectory(sub3, WTrajectory::BOTH, 0.2, Color::green())); viz.showWidget("sub4", WTrajectoryFrustums(sub4, K, 0.3, Color::yellow())); viz.showWidget("sub5", WTrajectoryFrustums(sub5, Vec2d(0.78, 0.78), 0.15)); + viz.showWidget("text2d", WText("Different kinds of supported trajectories", Point(20, 20), 20, Color::green())); int i = 0; while(!viz.wasStopped()) @@ -236,6 +249,7 @@ TEST(Viz, show_trajectories) 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.resetCamera(); viz.spin(); } @@ -246,6 +260,7 @@ TEST(Viz, show_trajectory_reposition) Viz3d viz("show_trajectory_reposition_to_origin"); viz.showWidget("coos", WCoordinateSystem()); viz.showWidget("sub3", WTrajectory(Mat(path).rowRange(0, 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(); } @@ -269,6 +284,7 @@ TEST(Viz, show_camera_positions) viz.showWidget("pos2", WCameraPosition(Vec2d(0.78, 0.78), lena, 2.2, Color::green()), poses[0]); 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(); } @@ -289,6 +305,7 @@ TEST(Viz, show_overlay_image) viz.showWidget("img2", WImageOverlay(gray, Rect(Point(vsz.width-10-lena.cols/2, 10), half_lsize))); viz.showWidget("img3", WImageOverlay(gray, Rect(Point(10, vsz.height-10-lena.rows/2), half_lsize))); viz.showWidget("img5", WImageOverlay(lena, Rect(Point(vsz.width-10-lena.cols/2, vsz.height-10-lena.rows/2), half_lsize))); + viz.showWidget("text2d", WText("Overlay images", Point(20, 20), 20, Color::green())); int i = 0; while(!viz.wasStopped()) @@ -299,7 +316,6 @@ TEST(Viz, show_overlay_image) viz.getWidget("img1").cast().setImage(lena * pow(sin(i*10*CV_PI/180) * 0.5 + 0.5, 1.0)); viz.spinOnce(1, true); } - viz.spin(); } @@ -332,6 +348,8 @@ TEST(Viz, show_image_3d) viz.showWidget("arr3", WArrow(Vec3d::all(-0.5), Vec3d::all(0.5), 0.009, Color::raspberry())); + viz.showWidget("text2d", WText("Images in 3D", Point(20, 20), 20, Color::green())); + int i = 0; while(!viz.wasStopped()) { @@ -357,7 +375,7 @@ TEST(Viz, show_simple_widgets) viz.showWidget("con0", WCone(0.25, 0.125, 6, Color::azure())); viz.showWidget("con1", WCone(0.125, Point3d(0.5, -0.5, 0.5), Point3d(0.5, -1.0, 0.5), 6, Color::turquoise())); - viz.showWidget("text2d", WText("Simple text", Point(20, 20), 20, Color::green())); + viz.showWidget("text2d", WText("Different simple widgets", Point(20, 20), 20, Color::green())); viz.showWidget("text3d", WText3D("Simple 3D text", Point3d( 0.5, 0.5, 0.5), 0.125, false, Color::green())); viz.showWidget("plane1", WPlane(Size2d(0.25, 0.75))); @@ -366,7 +384,7 @@ 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.getWidget("text2d").cast().setText("New simple text"); + viz.getWidget("text2d").cast().setText("Different simple widgets (updated)"); viz.getWidget("text3d").cast().setText("Updated text 3D"); viz.spin(); } @@ -378,6 +396,7 @@ TEST(Viz, show_follower) viz.showWidget("coos", WCoordinateSystem()); viz.showWidget("cube", WCube()); 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.getWidget("t3d_2").cast().setText("Updated follower 3D");