diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 1f48686f4..5ca06800b 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -234,9 +234,9 @@ namespace cv { public: //! Creates grid at the origin - WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + WGrid(const Vec2i &dimensions, const Vec2f &spacing, const Color &color = Color::white()); //! Creates grid based on the plane equation - WGrid(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + WGrid(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2f &spacing, const Color &color = Color::white()); }; class CV_EXPORTS WCameraPosition : public Widget3D diff --git a/modules/viz/src/clouds.cpp b/modules/viz/src/clouds.cpp index 555da22d0..ce9acd346 100644 --- a/modules/viz/src/clouds.cpp +++ b/modules/viz/src/clouds.cpp @@ -63,12 +63,6 @@ cv::viz::WCloud::WCloud(InputArray _cloud, InputArray _colors) Mat cloud = _cloud.getMat(); Mat colors = _colors.getMat(); - if (cloud.isContinuous() && colors.isContinuous()) - { - cloud = cloud.reshape(cloud.channels(), 1); - colors = colors.reshape(colors.channels(), 1); - } - vtkSmartPointer cloud_source = vtkSmartPointer::New(); cloud_source->SetColorCloud(cloud, colors); @@ -268,12 +262,6 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors, CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4); CV_Assert(colors.depth() == CV_8U && cloud.size() == colors.size()); - if (cloud.isContinuous() && colors.isContinuous()) - { - cloud = cloud.reshape(cloud.channels(), 1); - colors = colors.reshape(colors.channels(), 1); - } - vtkIdType nr_points; vtkSmartPointer polydata = CloudCollectionUtils::create(cloud, nr_points); diff --git a/modules/viz/src/shapes.cpp b/modules/viz/src/shapes.cpp index 0450eb816..e9102b728 100644 --- a/modules/viz/src/shapes.cpp +++ b/modules/viz/src/shapes.cpp @@ -474,7 +474,7 @@ namespace cv { namespace viz { namespace { struct GridUtils { - static vtkSmartPointer createGrid(const Vec2i &dimensions, const Vec2d &spacing) + static vtkSmartPointer createGrid(const Vec2i &dimensions, const Vec2f &spacing) { // Create the grid using image data vtkSmartPointer grid = vtkSmartPointer::New(); @@ -500,7 +500,7 @@ namespace cv { namespace viz { namespace }; }}} -cv::viz::WGrid::WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color &color) +cv::viz::WGrid::WGrid(const Vec2i &dimensions, const Vec2f &spacing, const Color &color) { vtkSmartPointer grid = GridUtils::createGrid(dimensions, spacing); @@ -518,7 +518,7 @@ cv::viz::WGrid::WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color setColor(color); } -cv::viz::WGrid::WGrid(const Vec4f &coefs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color) +cv::viz::WGrid::WGrid(const Vec4f &coefs, const Vec2i &dimensions, const Vec2f &spacing, const Color &color) { vtkSmartPointer grid = GridUtils::createGrid(dimensions, spacing); @@ -1224,11 +1224,11 @@ cv::viz::WTrajectory::WTrajectory(const std::vector &path, int display vtkIdType nr_points = path.size(); vtkSmartPointer points = vtkSmartPointer::New(); - vtkSmartPointer polyData = vtkSmartPointer::New(); - vtkSmartPointer polyLine = vtkSmartPointer::New(); - points->SetDataTypeToFloat(); points->SetNumberOfPoints(nr_points); + + vtkSmartPointer polyData = vtkSmartPointer::New(); + vtkSmartPointer polyLine = vtkSmartPointer::New(); polyLine->GetPointIds()->SetNumberOfIds(nr_points); Vec3f *data_beg = vtkpoints_data(points); diff --git a/modules/viz/test/test_precomp.cpp b/modules/viz/test/test_precomp.cpp index 5956e13e3..c2673fee6 100644 --- a/modules/viz/test/test_precomp.cpp +++ b/modules/viz/test/test_precomp.cpp @@ -1 +1,24 @@ #include "test_precomp.hpp" + +cv::String cv::Path::combine(const String& item1, const String& item2) +{ + if (item1.empty()) + return item2; + + if (item2.empty()) + return item1; + + char last = item1[item1.size()-1]; + + bool need_append = last != '/' && last != '\\'; + return item1 + (need_append ? "/" : "") + item2; +} + +cv::String cv::Path::combine(const String& item1, const String& item2, const String& item3) +{ return combine(combine(item1, item2), item3); } + +cv::String cv::Path::change_extension(const String& file, const String& ext) +{ + String::size_type pos = file.find_last_of('.'); + return pos == String::npos ? file : file.substr(0, pos+1) + ext; +} diff --git a/modules/viz/test/test_precomp.hpp b/modules/viz/test/test_precomp.hpp index ff7606ed9..efc89b27f 100644 --- a/modules/viz/test/test_precomp.hpp +++ b/modules/viz/test/test_precomp.hpp @@ -63,5 +63,21 @@ #include #include #include +#include + +namespace cv +{ + struct Path + { + static String combine(const String& item1, const String& item2); + static String combine(const String& item1, const String& item2, const String& item3); + static String change_extension(const String& file, const String& ext); + }; + + inline cv::String get_dragon_ply_file_path() + { + return Path::combine(cvtest::TS::ptr()->get_data_path(), "dragon.ply"); + } +} #endif diff --git a/modules/viz/test/test_tutorial2.cpp b/modules/viz/test/test_tutorial2.cpp index 6e9189b8f..cba24638b 100644 --- a/modules/viz/test/test_tutorial2.cpp +++ b/modules/viz/test/test_tutorial2.cpp @@ -48,7 +48,7 @@ void tutorial2() } -TEST(Viz_viz3d, DISABLED_tutorial2_pose_of_widget) +TEST(Viz, DISABLED_tutorial2_pose_of_widget) { tutorial2(); } diff --git a/modules/viz/test/test_tutorial3.cpp b/modules/viz/test/test_tutorial3.cpp index 12eca311c..8b4321548 100644 --- a/modules/viz/test/test_tutorial3.cpp +++ b/modules/viz/test/test_tutorial3.cpp @@ -15,21 +15,21 @@ void tutorial3(bool camera_pov) myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); /// Let's assume camera has the following properties - Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f); + Point3f cam_pos(3.f, 3.f, 3.f), cam_focal_point(3.f, 3.f, 2.f), cam_y_dir(-1.f, 0.f, 0.f); /// We can get the pose of the cam using makeCameraPose Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir); /// We can get the transformation matrix from camera coordinate system to global using /// - makeTransformToGlobal. We need the axes of the camera - Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos); + Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.f, -1.f, 0.f), Vec3f(-1.f, 0.f, 0.f), Vec3f(0.f, 0.f, -1.f), cam_pos); /// Create a cloud widget. - Mat bunny_cloud = viz::readCloud("d:/cloud_dragon.ply"); - viz::WCloud cloud_widget(bunny_cloud, viz::Color::green()); + Mat dragon_cloud = viz::readCloud(get_dragon_ply_file_path()); + viz::WCloud cloud_widget(dragon_cloud, viz::Color::green()); /// Pose of the widget in camera frame - Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f)); + Affine3f cloud_pose = Affine3f().translate(Vec3f(0.f, 0.f, 3.f)); /// Pose of the widget in global frame Affine3f cloud_pose_global = transform * cloud_pose; @@ -37,7 +37,7 @@ void tutorial3(bool camera_pov) if (!camera_pov) { viz::WCameraPosition cpw(0.5); // Coordinate axes - viz::WCameraPosition cpw_frustum(Vec2f(0.889484, 0.523599)); // Camera frustum + viz::WCameraPosition cpw_frustum(Vec2f(0.889484f, 0.523599f)); // Camera frustum myWindow.showWidget("CPW", cpw, cam_pose); myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); } @@ -53,12 +53,12 @@ void tutorial3(bool camera_pov) myWindow.spin(); } -TEST(Viz_viz3d, DISABLED_tutorial3_global_view) +TEST(Viz, DISABLED_tutorial3_global_view) { tutorial3(false); } -TEST(Viz_viz3d, DISABLED_tutorial3_camera_view) +TEST(Viz, DISABLED_tutorial3_camera_view) { tutorial3(true); } diff --git a/modules/viz/test/tests_simple.cpp b/modules/viz/test/tests_simple.cpp new file mode 100644 index 000000000..1a2e9fc94 --- /dev/null +++ b/modules/viz/test/tests_simple.cpp @@ -0,0 +1,87 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. + // Copyright (C) 2008-2013, Willow Garage Inc., all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and / or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + +#include "test_precomp.hpp" + +using namespace cv; +using namespace cv::viz; + +TEST(Viz, DISABLED_show_cloud_bluberry) +{ + Mat dragon_cloud = readCloud(get_dragon_ply_file_path()); + + Viz3d viz("show_cloud_bluberry"); + viz.setBackgroundColor(); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("dragon", WCloud(dragon_cloud, Color::bluberry())); + viz.spin(); +} + +TEST(Viz, DISABLED_show_cloud_random_color) +{ + Mat dragon_cloud = readCloud(get_dragon_ply_file_path()); + + Mat colors(dragon_cloud.size(), CV_8UC3); + theRNG().fill(colors, RNG::UNIFORM, 0, 255); + + Viz3d viz("show_cloud_random_color"); + viz.setBackgroundColor(); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("dragon", WCloud(dragon_cloud, colors)); + viz.spin(); +} + +TEST(Viz, DISABLED_show_cloud_masked) +{ + Mat dragon_cloud = readCloud(get_dragon_ply_file_path()); + + Vec3f qnan = Vec3f::all(std::numeric_limits::quiet_NaN()); + for(size_t i = 0; i < dragon_cloud.total(); ++i) + if (i % 15 != 0) + dragon_cloud.at(i) = qnan; + + Viz3d viz("show_cloud_masked"); + viz.setBackgroundColor(); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("dragon", WCloud(dragon_cloud)); + viz.spin(); +}